@syncfusion/ej2-dropdowns 24.1.45-12082 → 24.1.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/.eslintrc.json +260 -0
  2. package/CHANGELOG.md +2107 -2101
  3. package/{ReadMe.md → README.md} +217 -217
  4. package/dist/ej2-dropdowns.min.js +10 -1
  5. package/dist/ej2-dropdowns.umd.min.js +10 -1
  6. package/dist/ej2-dropdowns.umd.min.js.map +1 -1
  7. package/dist/es6/ej2-dropdowns.es2015.js +127 -61
  8. package/dist/es6/ej2-dropdowns.es2015.js.map +1 -1
  9. package/dist/es6/ej2-dropdowns.es5.js +274 -203
  10. package/dist/es6/ej2-dropdowns.es5.js.map +1 -1
  11. package/dist/global/ej2-dropdowns.min.js +10 -1
  12. package/dist/global/ej2-dropdowns.min.js.map +1 -1
  13. package/dist/global/index.d.ts +9 -0
  14. package/helpers/e2e/autocomplete.js +13 -13
  15. package/helpers/e2e/combobox.js +13 -13
  16. package/helpers/e2e/dropdownlist.js +13 -13
  17. package/helpers/e2e/index.js +3 -3
  18. package/helpers/e2e/listboxHelper.js +13 -13
  19. package/helpers/e2e/multiselect.js +13 -13
  20. package/license +2 -2
  21. package/package.json +80 -80
  22. package/src/auto-complete/auto-complete-model.d.ts +188 -188
  23. package/src/auto-complete/auto-complete.d.ts +12 -12
  24. package/src/auto-complete/auto-complete.js +21 -21
  25. package/src/combo-box/combo-box-model.d.ts +224 -224
  26. package/src/combo-box/combo-box.d.ts +27 -27
  27. package/src/combo-box/combo-box.js +29 -29
  28. package/src/common/virtual-scroll.js +46 -46
  29. package/src/drop-down-base/drop-down-base-model.d.ts +200 -200
  30. package/src/drop-down-base/drop-down-base.d.ts +16 -16
  31. package/src/drop-down-base/drop-down-base.js +20 -20
  32. package/src/drop-down-list/drop-down-list-model.d.ts +202 -202
  33. package/src/drop-down-list/drop-down-list.d.ts +4 -4
  34. package/src/drop-down-list/drop-down-list.js +20 -20
  35. package/src/drop-down-tree/drop-down-tree-model.d.ts +468 -468
  36. package/src/drop-down-tree/drop-down-tree.d.ts +3 -0
  37. package/src/drop-down-tree/drop-down-tree.js +95 -24
  38. package/src/list-box/list-box-model.d.ts +193 -193
  39. package/src/list-box/list-box.d.ts +2 -2
  40. package/src/list-box/list-box.js +19 -19
  41. package/src/mention/mention-model.d.ts +261 -261
  42. package/src/mention/mention.js +19 -19
  43. package/src/multi-select/multi-select-model.d.ts +512 -512
  44. package/src/multi-select/multi-select.js +19 -19
  45. package/styles/auto-complete/_all.scss +1 -1
  46. package/styles/auto-complete/_bootstrap-dark-definition.scss +3 -3
  47. package/styles/auto-complete/_bootstrap-definition.scss +2 -2
  48. package/styles/auto-complete/_bootstrap4-definition.scss +11 -11
  49. package/styles/auto-complete/_bootstrap5-definition.scss +2 -2
  50. package/styles/auto-complete/_fabric-dark-definition.scss +2 -2
  51. package/styles/auto-complete/_fabric-definition.scss +2 -2
  52. package/styles/auto-complete/_fluent-definition.scss +2 -2
  53. package/styles/auto-complete/_fusionnew-definition.scss +2 -2
  54. package/styles/auto-complete/_highcontrast-definition.scss +2 -2
  55. package/styles/auto-complete/_highcontrast-light-definition.scss +2 -2
  56. package/styles/auto-complete/_material-dark-definition.scss +2 -2
  57. package/styles/auto-complete/_material-definition.scss +2 -2
  58. package/styles/auto-complete/_material3-definition.scss +2 -2
  59. package/styles/auto-complete/_tailwind-definition.scss +2 -2
  60. package/styles/auto-complete/material3-dark.scss +1 -1
  61. package/styles/auto-complete/material3.scss +1 -1
  62. package/styles/combo-box/_all.scss +1 -1
  63. package/styles/combo-box/_bootstrap-dark-definition.scss +2 -2
  64. package/styles/combo-box/_bootstrap-definition.scss +2 -2
  65. package/styles/combo-box/_bootstrap4-definition.scss +11 -11
  66. package/styles/combo-box/_bootstrap5-definition.scss +2 -2
  67. package/styles/combo-box/_fabric-dark-definition.scss +2 -2
  68. package/styles/combo-box/_fabric-definition.scss +2 -2
  69. package/styles/combo-box/_fluent-definition.scss +2 -2
  70. package/styles/combo-box/_fusionnew-definition.scss +2 -2
  71. package/styles/combo-box/_highcontrast-definition.scss +2 -2
  72. package/styles/combo-box/_highcontrast-light-definition.scss +3 -3
  73. package/styles/combo-box/_material-dark-definition.scss +2 -2
  74. package/styles/combo-box/_material-definition.scss +2 -2
  75. package/styles/combo-box/_material3-definition.scss +2 -2
  76. package/styles/combo-box/_tailwind-definition.scss +2 -2
  77. package/styles/combo-box/material3-dark.scss +1 -1
  78. package/styles/combo-box/material3.scss +1 -1
  79. package/styles/drop-down-base/_all.scss +2 -2
  80. package/styles/drop-down-base/_bootstrap-dark-definition.scss +83 -83
  81. package/styles/drop-down-base/_bootstrap-definition.scss +83 -83
  82. package/styles/drop-down-base/_bootstrap4-definition.scss +90 -90
  83. package/styles/drop-down-base/_bootstrap5-definition.scss +117 -117
  84. package/styles/drop-down-base/_definition.scss +23 -23
  85. package/styles/drop-down-base/_fabric-dark-definition.scss +86 -86
  86. package/styles/drop-down-base/_fabric-definition.scss +84 -84
  87. package/styles/drop-down-base/_fluent-definition.scss +121 -121
  88. package/styles/drop-down-base/_fusionnew-definition.scss +117 -117
  89. package/styles/drop-down-base/_highcontrast-definition.scss +105 -105
  90. package/styles/drop-down-base/_highcontrast-light-definition.scss +105 -105
  91. package/styles/drop-down-base/_layout.scss +192 -192
  92. package/styles/drop-down-base/_material-dark-definition.scss +86 -86
  93. package/styles/drop-down-base/_material-definition.scss +85 -85
  94. package/styles/drop-down-base/_material3-definition.scss +87 -87
  95. package/styles/drop-down-base/_tailwind-definition.scss +129 -129
  96. package/styles/drop-down-base/_theme.scss +391 -391
  97. package/styles/drop-down-base/material3-dark.scss +1 -1
  98. package/styles/drop-down-base/material3.scss +1 -1
  99. package/styles/drop-down-list/_all.scss +3 -3
  100. package/styles/drop-down-list/_bootstrap-dark-definition.scss +157 -157
  101. package/styles/drop-down-list/_bootstrap-definition.scss +156 -156
  102. package/styles/drop-down-list/_bootstrap4-definition.scss +202 -202
  103. package/styles/drop-down-list/_bootstrap5-definition.scss +201 -201
  104. package/styles/drop-down-list/_fabric-dark-definition.scss +128 -128
  105. package/styles/drop-down-list/_fabric-definition.scss +124 -124
  106. package/styles/drop-down-list/_fluent-definition.scss +185 -185
  107. package/styles/drop-down-list/_fusionnew-definition.scss +201 -201
  108. package/styles/drop-down-list/_highcontrast-definition.scss +142 -142
  109. package/styles/drop-down-list/_highcontrast-light-definition.scss +144 -144
  110. package/styles/drop-down-list/_layout.scss +315 -315
  111. package/styles/drop-down-list/_material-dark-definition.scss +143 -143
  112. package/styles/drop-down-list/_material-definition.scss +167 -167
  113. package/styles/drop-down-list/_material3-definition.scss +180 -180
  114. package/styles/drop-down-list/_tailwind-definition.scss +134 -134
  115. package/styles/drop-down-list/_theme.scss +10 -10
  116. package/styles/drop-down-list/icons/_bootstrap-dark.scss +14 -14
  117. package/styles/drop-down-list/icons/_bootstrap.scss +14 -14
  118. package/styles/drop-down-list/icons/_bootstrap4.scss +14 -14
  119. package/styles/drop-down-list/icons/_bootstrap5.scss +14 -14
  120. package/styles/drop-down-list/icons/_fabric-dark.scss +14 -14
  121. package/styles/drop-down-list/icons/_fabric.scss +14 -14
  122. package/styles/drop-down-list/icons/_fluent.scss +14 -14
  123. package/styles/drop-down-list/icons/_fusionnew.scss +14 -14
  124. package/styles/drop-down-list/icons/_highcontrast-light.scss +14 -14
  125. package/styles/drop-down-list/icons/_highcontrast.scss +14 -14
  126. package/styles/drop-down-list/icons/_material-dark.scss +14 -14
  127. package/styles/drop-down-list/icons/_material.scss +14 -14
  128. package/styles/drop-down-list/icons/_material3.scss +14 -14
  129. package/styles/drop-down-list/icons/_tailwind.scss +14 -14
  130. package/styles/drop-down-list/material3-dark.scss +1 -1
  131. package/styles/drop-down-list/material3.scss +1 -1
  132. package/styles/drop-down-tree/_all.scss +2 -2
  133. package/styles/drop-down-tree/_bootstrap-dark-definition.scss +71 -71
  134. package/styles/drop-down-tree/_bootstrap-definition.scss +70 -70
  135. package/styles/drop-down-tree/_bootstrap4-definition.scss +71 -71
  136. package/styles/drop-down-tree/_bootstrap5-definition.scss +59 -59
  137. package/styles/drop-down-tree/_fabric-dark-definition.scss +71 -71
  138. package/styles/drop-down-tree/_fabric-definition.scss +71 -71
  139. package/styles/drop-down-tree/_fluent-definition.scss +65 -65
  140. package/styles/drop-down-tree/_fusionnew-definition.scss +59 -59
  141. package/styles/drop-down-tree/_highcontrast-definition.scss +71 -71
  142. package/styles/drop-down-tree/_highcontrast-light-definition.scss +71 -71
  143. package/styles/drop-down-tree/_layout.scss +1423 -1423
  144. package/styles/drop-down-tree/_material-dark-definition.scss +72 -72
  145. package/styles/drop-down-tree/_material-definition.scss +72 -72
  146. package/styles/drop-down-tree/_material3-definition.scss +76 -76
  147. package/styles/drop-down-tree/_tailwind-definition.scss +61 -61
  148. package/styles/drop-down-tree/_theme.scss +132 -132
  149. package/styles/drop-down-tree/icons/_bootstrap-dark.scss +11 -11
  150. package/styles/drop-down-tree/icons/_bootstrap.scss +11 -11
  151. package/styles/drop-down-tree/icons/_bootstrap4.scss +11 -11
  152. package/styles/drop-down-tree/icons/_bootstrap5.scss +11 -11
  153. package/styles/drop-down-tree/icons/_fabric-dark.scss +11 -11
  154. package/styles/drop-down-tree/icons/_fabric.scss +11 -11
  155. package/styles/drop-down-tree/icons/_fluent.scss +11 -11
  156. package/styles/drop-down-tree/icons/_fusionnew.scss +11 -11
  157. package/styles/drop-down-tree/icons/_highcontrast-light.scss +11 -11
  158. package/styles/drop-down-tree/icons/_highcontrast.scss +11 -11
  159. package/styles/drop-down-tree/icons/_material-dark.scss +11 -11
  160. package/styles/drop-down-tree/icons/_material.scss +11 -11
  161. package/styles/drop-down-tree/icons/_material3.scss +11 -11
  162. package/styles/drop-down-tree/icons/_tailwind-dark.scss +11 -11
  163. package/styles/drop-down-tree/icons/_tailwind.scss +11 -11
  164. package/styles/drop-down-tree/material3-dark.scss +1 -1
  165. package/styles/drop-down-tree/material3.scss +1 -1
  166. package/styles/list-box/_all.scss +2 -2
  167. package/styles/list-box/_bootstrap-dark-definition.scss +126 -126
  168. package/styles/list-box/_bootstrap-definition.scss +119 -119
  169. package/styles/list-box/_bootstrap4-definition.scss +124 -124
  170. package/styles/list-box/_bootstrap5-definition.scss +120 -120
  171. package/styles/list-box/_fabric-dark-definition.scss +126 -126
  172. package/styles/list-box/_fabric-definition.scss +119 -119
  173. package/styles/list-box/_fluent-definition.scss +120 -120
  174. package/styles/list-box/_fusionnew-definition.scss +111 -111
  175. package/styles/list-box/_highcontrast-definition.scss +119 -119
  176. package/styles/list-box/_highcontrast-light-definition.scss +126 -126
  177. package/styles/list-box/_layout.scss +542 -542
  178. package/styles/list-box/_material-dark-definition.scss +126 -126
  179. package/styles/list-box/_material-definition.scss +119 -119
  180. package/styles/list-box/_material3-definition.scss +119 -119
  181. package/styles/list-box/_tailwind-definition.scss +119 -119
  182. package/styles/list-box/_theme.scss +382 -382
  183. package/styles/list-box/icons/_bootstrap-dark.scss +25 -25
  184. package/styles/list-box/icons/_bootstrap.scss +25 -25
  185. package/styles/list-box/icons/_bootstrap4.scss +25 -25
  186. package/styles/list-box/icons/_bootstrap5.scss +25 -25
  187. package/styles/list-box/icons/_fabric-dark.scss +25 -25
  188. package/styles/list-box/icons/_fabric.scss +25 -25
  189. package/styles/list-box/icons/_fluent.scss +25 -25
  190. package/styles/list-box/icons/_fusionnew.scss +25 -25
  191. package/styles/list-box/icons/_highcontrast-light.scss +25 -25
  192. package/styles/list-box/icons/_highcontrast.scss +25 -25
  193. package/styles/list-box/icons/_material-dark.scss +25 -25
  194. package/styles/list-box/icons/_material.scss +25 -25
  195. package/styles/list-box/icons/_material3.scss +25 -25
  196. package/styles/list-box/icons/_tailwind-dark.scss +25 -25
  197. package/styles/list-box/icons/_tailwind.scss +25 -25
  198. package/styles/list-box/material3-dark.scss +1 -1
  199. package/styles/list-box/material3.scss +1 -1
  200. package/styles/material3-dark.scss +1 -1
  201. package/styles/material3.scss +1 -1
  202. package/styles/mention/_all.scss +1 -1
  203. package/styles/mention/_bootstrap-dark-definition.scss +3 -3
  204. package/styles/mention/_bootstrap-definition.scss +3 -3
  205. package/styles/mention/_bootstrap4-definition.scss +3 -3
  206. package/styles/mention/_bootstrap5-definition.scss +1 -1
  207. package/styles/mention/_fabric-dark-definition.scss +2 -2
  208. package/styles/mention/_fabric-definition.scss +3 -3
  209. package/styles/mention/_fluent-definition.scss +1 -1
  210. package/styles/mention/_fusionnew-definition.scss +1 -1
  211. package/styles/mention/_highcontrast-definition.scss +3 -3
  212. package/styles/mention/_highcontrast-light-definition.scss +3 -3
  213. package/styles/mention/_layout.scss +6 -6
  214. package/styles/mention/_material-dark-definition.scss +3 -3
  215. package/styles/mention/_material-definition.scss +3 -3
  216. package/styles/mention/_material3-definition.scss +1 -1
  217. package/styles/mention/_tailwind-definition.scss +1 -1
  218. package/styles/mention/material3-dark.scss +1 -1
  219. package/styles/mention/material3.scss +1 -1
  220. package/styles/multi-select/_all.scss +2 -2
  221. package/styles/multi-select/_bootstrap-dark-definition.scss +203 -203
  222. package/styles/multi-select/_bootstrap-definition.scss +192 -192
  223. package/styles/multi-select/_bootstrap4-definition.scss +278 -278
  224. package/styles/multi-select/_bootstrap5-definition.scss +230 -230
  225. package/styles/multi-select/_fabric-dark-definition.scss +192 -192
  226. package/styles/multi-select/_fabric-definition.scss +183 -183
  227. package/styles/multi-select/_fluent-definition.scss +241 -241
  228. package/styles/multi-select/_fusionnew-definition.scss +227 -227
  229. package/styles/multi-select/_highcontrast-definition.scss +303 -303
  230. package/styles/multi-select/_highcontrast-light-definition.scss +297 -297
  231. package/styles/multi-select/_layout.scss +2199 -2199
  232. package/styles/multi-select/_material-dark-definition.scss +230 -230
  233. package/styles/multi-select/_material-definition.scss +223 -223
  234. package/styles/multi-select/_material3-definition.scss +246 -246
  235. package/styles/multi-select/_tailwind-definition.scss +235 -235
  236. package/styles/multi-select/_theme.scss +586 -586
  237. package/styles/multi-select/icons/_bootstrap-dark.scss +26 -26
  238. package/styles/multi-select/icons/_bootstrap.scss +26 -26
  239. package/styles/multi-select/icons/_bootstrap4.scss +37 -37
  240. package/styles/multi-select/icons/_bootstrap5.scss +26 -26
  241. package/styles/multi-select/icons/_fabric-dark.scss +26 -26
  242. package/styles/multi-select/icons/_fabric.scss +26 -26
  243. package/styles/multi-select/icons/_fluent.scss +55 -55
  244. package/styles/multi-select/icons/_fusionnew.scss +26 -26
  245. package/styles/multi-select/icons/_highcontrast-light.scss +26 -26
  246. package/styles/multi-select/icons/_highcontrast.scss +26 -26
  247. package/styles/multi-select/icons/_material-dark.scss +693 -693
  248. package/styles/multi-select/icons/_material.scss +693 -693
  249. package/styles/multi-select/icons/_material3.scss +692 -692
  250. package/styles/multi-select/icons/_tailwind.scss +26 -26
  251. package/styles/multi-select/material3-dark.scss +1 -1
  252. package/styles/multi-select/material3.scss +1 -1
  253. package/tslint.json +111 -0
  254. package/dist/ts/auto-complete/auto-complete.ts +0 -623
  255. package/dist/ts/combo-box/combo-box.ts +0 -1099
  256. package/dist/ts/common/highlight-search.ts +0 -57
  257. package/dist/ts/common/incremental-search.ts +0 -172
  258. package/dist/ts/common/interface.ts +0 -74
  259. package/dist/ts/common/virtual-scroll.ts +0 -388
  260. package/dist/ts/drop-down-base/drop-down-base.ts +0 -1986
  261. package/dist/ts/drop-down-list/drop-down-list.ts +0 -4261
  262. package/dist/ts/drop-down-tree/drop-down-tree.ts +0 -3747
  263. package/dist/ts/list-box/list-box.ts +0 -2772
  264. package/dist/ts/mention/mention.ts +0 -1875
  265. package/dist/ts/multi-select/checkbox-selection.ts +0 -550
  266. package/dist/ts/multi-select/float-label.ts +0 -176
  267. package/dist/ts/multi-select/interface.ts +0 -70
  268. package/dist/ts/multi-select/multi-select.ts +0 -4882
  269. package/styles/auto-complete/_bds-definition.scss +0 -2
  270. package/styles/combo-box/_bds-definition.scss +0 -2
  271. package/styles/drop-down-base/_bds-definition.scss +0 -129
  272. package/styles/drop-down-list/_bds-definition.scss +0 -134
  273. package/styles/drop-down-tree/_bds-definition.scss +0 -61
  274. package/styles/list-box/_bds-definition.scss +0 -119
  275. package/styles/mention/_bds-definition.scss +0 -1
  276. package/styles/multi-select/_bds-definition.scss +0 -235
@@ -1,2772 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/triple-slash-reference
2
- /// <reference path='../drop-down-base/drop-down-base-model.d.ts'/>
3
- import { Input, InputObject } from '@syncfusion/ej2-inputs';
4
- import { DropDownBase, dropDownBaseClasses, FilteringEventArgs, SelectEventArgs } from '../drop-down-base/drop-down-base';
5
- import { FieldSettingsModel } from '../drop-down-base/drop-down-base-model';
6
- import { EventHandler, closest, removeClass, addClass, Complex, Property, ChildProperty, BaseEventArgs, L10n } from '@syncfusion/ej2-base';
7
- import { ModuleDeclaration, NotifyPropertyChanges, getComponent, EmitType, Event, extend, detach, attributes } from '@syncfusion/ej2-base';
8
- import { getUniqueID, Browser, formatUnit, isNullOrUndefined, getValue } from '@syncfusion/ej2-base';
9
- import { prepend, append } from '@syncfusion/ej2-base';
10
- import { cssClass, Sortable, moveTo } from '@syncfusion/ej2-lists';
11
- import { SelectionSettingsModel, ListBoxModel, ToolbarSettingsModel } from './list-box-model';
12
- import { Button } from '@syncfusion/ej2-buttons';
13
- import { createSpinner, showSpinner, hideSpinner, getZindexPartial } from '@syncfusion/ej2-popups';
14
- import { DataManager, Query } from '@syncfusion/ej2-data';
15
- /**
16
- * Defines the selection mode in ListBox component.
17
- * ```props
18
- * Multiple :- Specifies that the ListBox should allow multiple item selection.
19
- * Single :- Specifies that the ListBox should allow single item selection.
20
- * ```
21
- */
22
- export type SelectionMode = 'Multiple' | 'Single';
23
- /**
24
- * Defines the position of the toolbar in ListBox component.
25
- * ```props
26
- * Left :- Specifies that the toolbar should be positioned to the left of the ListBox.
27
- * Right :- Specifies that the toolbar should be positioned to the right of the ListBox.
28
- * ```
29
- */
30
- export type ToolBarPosition = 'Left' | 'Right';
31
- /**
32
- * Defines the position of the checkbox in ListBox component.
33
- * ```props
34
- * Left :- Specifies that the checkbox should be positioned to the left of the ListBox.
35
- * Right :- Specifies that the checkbox should be positioned to the right of the ListBox.
36
- * ```
37
- */
38
- export type CheckBoxPosition = 'Left' | 'Right';
39
-
40
- type dataType = { [key: string]: object } | string | boolean | number;
41
- type obj = { [key: string]: object };
42
- const ITEMTEMPLATE_PROPERTY: string = 'ItemTemplate';
43
- /**
44
- * Defines the Selection settings of List Box.
45
- */
46
- export class SelectionSettings extends ChildProperty<SelectionSettings> {
47
- /**
48
- * Specifies the selection modes. The possible values are
49
- * * `Single`: Allows you to select a single item in the ListBox.
50
- * * `Multiple`: Allows you to select more than one item in the ListBox.
51
- *
52
- * @default 'Multiple'
53
- */
54
- @Property('Multiple')
55
- public mode: SelectionMode;
56
-
57
- /**
58
- * If 'showCheckbox' is set to true, then 'checkbox' will be visualized in the list item.
59
- *
60
- * @default false
61
- */
62
- @Property(false)
63
- public showCheckbox: boolean;
64
-
65
- /**
66
- * Allows you to either show or hide the selectAll option on the component.
67
- *
68
- * @default false
69
- */
70
- @Property(false)
71
- public showSelectAll: boolean;
72
-
73
- /**
74
- * Set the position of the checkbox.
75
- *
76
- * @default 'Left'
77
- */
78
- @Property('Left')
79
- public checkboxPosition: CheckBoxPosition;
80
- }
81
- /**
82
- * Defines the toolbar settings of List Box.
83
- */
84
- export class ToolbarSettings extends ChildProperty<ToolbarSettings> {
85
- /**
86
- * Specifies the list of tools for dual ListBox.
87
- * The predefined tools are 'moveUp', 'moveDown', 'moveTo', 'moveFrom', 'moveAllTo', and 'moveAllFrom'.
88
- *
89
- * @default []
90
- */
91
- @Property([])
92
- public items: string[];
93
-
94
- /**
95
- * Positions the toolbar before/after the ListBox.
96
- * The possible values are:
97
- * * Left: The toolbar will be positioned to the left of the ListBox.
98
- * * Right: The toolbar will be positioned to the right of the ListBox.
99
- *
100
- * @default 'Right'
101
- */
102
- @Property('Right')
103
- public position: ToolBarPosition;
104
- }
105
-
106
- /**
107
- * The ListBox is a graphical user interface component used to display a list of items.
108
- * Users can select one or more items in the list using a checkbox or by keyboard selection.
109
- * It supports sorting, grouping, reordering and drag and drop of items.
110
- * ```html
111
- * <select id="listbox">
112
- * <option value='1'>Badminton</option>
113
- * <option value='2'>Basketball</option>
114
- * <option value='3'>Cricket</option>
115
- * <option value='4'>Football</option>
116
- * <option value='5'>Tennis</option>
117
- * </select>
118
- * ```
119
- * ```typescript
120
- * <script>
121
- * var listObj = new ListBox();
122
- * listObj.appendTo("#listbox");
123
- * </script>
124
- * ```
125
- */
126
- @NotifyPropertyChanges
127
- export class ListBox extends DropDownBase {
128
- private prevSelIdx: number;
129
- private listCurrentOptions: FieldSettingsModel;
130
- private allowDragAll: boolean;
131
- private checkBoxSelectionModule: { onDocumentClick: Function, checkAllParent: HTMLElement, clearIconElement: HTMLElement };
132
- private tBListBox: ListBox;
133
- private initLoad: boolean;
134
- private spinner: HTMLElement;
135
- private initialSelectedOptions: string[] | number[] | boolean[];
136
- private showSelectAll: boolean;
137
- private selectAllText: string;
138
- private unSelectAllText: string;
139
- private popupWrapper: Element;
140
- private targetInputElement: HTMLInputElement | string;
141
- private isValidKey: boolean = false;
142
- private isFiltered: boolean;
143
- private clearFilterIconElem: Element;
144
- private remoteFilterAction: boolean;
145
- private mainList: HTMLElement;
146
- private remoteCustomValue: boolean;
147
- private filterParent: HTMLElement;
148
- protected inputString: string;
149
- protected filterInput: HTMLInputElement;
150
- protected isCustomFiltering: boolean;
151
- private jsonData: { [key: string]: Object }[] | string[] | boolean[] | number[];
152
- private toolbarAction: string;
153
- private isDataSourceUpdate: boolean = false;
154
- private dragValue: string;
155
- private customDraggedItem: Object[];
156
- private timer: number;
157
- private inputFormName: string;
158
- /**
159
- * Sets the CSS classes to root element of this component, which helps to customize the
160
- * complete styles.
161
- *
162
- * @default ''
163
- */
164
- @Property('')
165
- public cssClass: string;
166
-
167
- /**
168
- * Sets the specified item to the selected state or gets the selected item in the ListBox.
169
- *
170
- * @default []
171
- * @aspType object
172
- * @isGenericType true
173
- */
174
- @Property([])
175
- public value: string[] | number[] | boolean[];
176
-
177
- /**
178
- * Sets the height of the ListBox component.
179
- *
180
- * @default ''
181
- */
182
- @Property('')
183
- public height: number | string;
184
-
185
- /**
186
- * Specifies a value that indicates whether the component is enabled or not.
187
- *
188
- * @default true
189
- * @deprecated
190
- */
191
- @Property(true)
192
- public enabled: boolean;
193
-
194
- /**
195
- * Enable or disable persisting component's state between page reloads.
196
- * If enabled, following list of states will be persisted.
197
- * 1. value
198
- *
199
- * @default false
200
- * @deprecated
201
- */
202
- @Property(false)
203
- public enablePersistence: boolean;
204
-
205
- /**
206
- * If 'allowDragAndDrop' is set to true, then you can perform drag and drop of the list item.
207
- * ListBox contains same 'scope' property enables drag and drop between multiple ListBox.
208
- *
209
- * @default false
210
- */
211
- @Property(false)
212
- public allowDragAndDrop: boolean;
213
-
214
- /**
215
- * Sets limitation to the value selection.
216
- * based on the limitation, list selection will be prevented.
217
- *
218
- * @default 1000
219
- */
220
- @Property(1000)
221
- public maximumSelectionLength: number;
222
-
223
- /**
224
- * To enable the filtering option in this component.
225
- * Filter action performs when type in search box and collect the matched item through `filtering` event.
226
- * If searching character does not match, `noRecordsTemplate` property value will be shown.
227
- *
228
- * @default false
229
- */
230
- @Property(false)
231
- public allowFiltering: boolean;
232
-
233
- /**
234
- * Defines the scope value to group sets of draggable and droppable ListBox.
235
- * A draggable with the same scope value will be accepted by the droppable.
236
- *
237
- * @default ''
238
- */
239
- @Property('')
240
- public scope: string;
241
-
242
- /**
243
- * When set to ‘false’, consider the `case-sensitive` on performing the search to find suggestions.
244
- * By default consider the casing.
245
- *
246
- * @default true
247
- * @private
248
- */
249
- @Property(true)
250
- public ignoreCase: boolean;
251
-
252
- /**
253
- * Accepts the value to be displayed as a watermark text on the filter bar.
254
- *
255
- * @default null
256
- */
257
- @Property(null)
258
- public filterBarPlaceholder: string;
259
-
260
- /**
261
- * Triggers while rendering each list item.
262
- *
263
- * @event beforeItemRender
264
- * @blazorProperty 'OnItemRender'
265
- */
266
- @Event()
267
- public beforeItemRender: EmitType<BeforeItemRenderEventArgs>;
268
-
269
- /**
270
- * Triggers on typing a character in the component.
271
- *
272
- * @event filtering
273
- * @blazorProperty 'ItemSelected'
274
- */
275
- @Event()
276
- public filtering: EmitType<FilteringEventArgs>;
277
-
278
- /**
279
- * Triggers when an item in the popup is selected by the user either with mouse/tap or with keyboard navigation.
280
- *
281
- * @event select
282
- * @private
283
- */
284
- @Event()
285
- public select: EmitType<SelectEventArgs>;
286
-
287
- /**
288
- * Adds a new item to the popup list. By default, new item appends to the list as the last item,
289
- * but you can insert based on the index parameter.
290
- *
291
- * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
292
- * @param { number } itemIndex - Specifies the index to place the newly added item in the popup list.
293
- * @returns {void}.
294
- * @private
295
- */
296
- public addItem(
297
- items: { [key: string]: Object }[] | { [key: string]: Object } | string | boolean | number | string[] | boolean[] | number[],
298
- itemIndex?: number): void {
299
- super.addItem(items, itemIndex);
300
- }
301
-
302
- /**
303
- * Triggers while select / unselect the list item.
304
- *
305
- * @event change
306
- * @blazorProperty 'ValueChange'
307
- */
308
- @Event()
309
- public change: EmitType<ListBoxChangeEventArgs>;
310
-
311
- /**
312
- * Triggers before dropping the list item on another list item.
313
- *
314
- * @event beforeDrop
315
- * @blazorProperty 'OnDrop'
316
- */
317
- @Event()
318
- public beforeDrop: EmitType<DropEventArgs>;
319
-
320
- /**
321
- * Triggers after dragging the list item.
322
- *
323
- * @event dragStart
324
- * @blazorProperty 'DragStart'
325
- */
326
- @Event()
327
- public dragStart: EmitType<DragEventArgs>;
328
-
329
- /**
330
- * Triggers while dragging the list item.
331
- *
332
- * @event drag
333
- * @blazorProperty 'Dragging'
334
- */
335
- @Event()
336
- public drag: EmitType<DragEventArgs>;
337
-
338
- /**
339
- * Triggers before dropping the list item on another list item.
340
- *
341
- * @event drop
342
- * @blazorProperty 'Dropped'
343
- */
344
- @Event()
345
- public drop: EmitType<DragEventArgs>;
346
-
347
- /**
348
- * Triggers when data source is populated in the list.
349
- *
350
- * @event dataBound
351
- */
352
- @Event()
353
- public dataBound: EmitType<Object>;
354
-
355
- /**
356
- * Accepts the template design and assigns it to the group headers present in the list.
357
- *
358
- * @default null
359
- * @private
360
- */
361
- @Property(null)
362
- public groupTemplate: string;
363
- /**
364
- * Accepts the template and assigns it to the list content of the ListBox component
365
- * when the data fetch request from the remote server fails.
366
- *
367
- * @default 'Request Failed'
368
- * @private
369
- */
370
- @Property('Request failed')
371
- public actionFailureTemplate: string;
372
-
373
- /**
374
- * specifies the z-index value of the component popup element.
375
- *
376
- * @default 1000
377
- * @private
378
- */
379
- @Property(1000)
380
- public zIndex: number;
381
- /**
382
- * ignoreAccent set to true, then ignores the diacritic characters or accents when filtering.
383
- *
384
- * @private
385
- */
386
- @Property(false)
387
- public ignoreAccent: boolean;
388
-
389
- /**
390
- * Specifies the toolbar items and its position.
391
- *
392
- * @default { items: [], position: 'Right' }
393
- */
394
- @Complex<ToolbarSettingsModel>({}, ToolbarSettings)
395
- public toolbarSettings: ToolbarSettingsModel;
396
-
397
- /**
398
- * Specifies the selection mode and its type.
399
- *
400
- * @default { mode: 'Multiple', type: 'Default' }
401
- */
402
- @Complex<SelectionSettingsModel>({}, SelectionSettings)
403
- public selectionSettings: SelectionSettingsModel;
404
-
405
- /**
406
- * Constructor for creating the ListBox component.
407
- *
408
- * @param {ListBoxModel} options - Specifies ListBox model
409
- * @param {string | HTMLElement} element - Specifies the element.
410
- */
411
- constructor(options?: ListBoxModel, element?: string | HTMLElement) {
412
- super(options, element);
413
- }
414
-
415
- /**
416
- * Build and render the component.
417
- *
418
- * @private
419
- * @returns {void}
420
- */
421
- public render(): void {
422
- this.inputString = '';
423
- this.initLoad = true;
424
- this.isCustomFiltering = false;
425
- this.initialSelectedOptions = this.value;
426
- this.inputFormName = this.element.getAttribute('name');
427
- super.render();
428
- this.setEnabled();
429
- this.renderComplete();
430
- }
431
-
432
- private initWrapper(): void {
433
- const hiddenSelect: HTMLElement = this.createElement('select', { className: 'e-hidden-select', attrs: { 'multiple': '' } });
434
- hiddenSelect.style.visibility = 'hidden';
435
- this.list.classList.add('e-listbox-wrapper');
436
- (this.list.querySelector('.e-list-parent') as any).setAttribute('role', 'presentation');
437
- const groupHdrs: HTMLElement[] = <HTMLElement[] & NodeListOf<Element>>this.list.querySelectorAll('.e-list-group-item');
438
- for (let i: number = 0; i < groupHdrs.length; i++) {
439
- groupHdrs[i as number].removeAttribute('tabindex');
440
- groupHdrs[i as number].setAttribute('role', 'option');
441
- }
442
- if (this.itemTemplate) {
443
- this.list.classList.add('e-list-template');
444
- }
445
- this.list.classList.add('e-wrapper');
446
- this.list.classList.add('e-lib');
447
- if (this.element.tagName === 'EJS-LISTBOX') {
448
- this.element.setAttribute('tabindex', '0');
449
- if (this.initLoad) {
450
- this.element.appendChild(this.list);
451
- }
452
- } else {
453
- if (this.initLoad) {
454
- this.element.parentElement.insertBefore(this.list, this.element);
455
- }
456
- this.list.insertBefore(this.element, this.list.firstChild);
457
- this.element.style.display = 'none';
458
- }
459
- this.list.insertBefore(hiddenSelect, this.list.firstChild);
460
- if (this.list.getElementsByClassName('e-list-item')[0]) {
461
- this.list.getElementsByClassName('e-list-item')[0].classList.remove(dropDownBaseClasses.focus);
462
- }
463
- if (this.itemTemplate) { this.renderReactTemplates(); }
464
- removeClass([this.list], [dropDownBaseClasses.content, dropDownBaseClasses.root]);
465
- this.validationAttribute(this.element as HTMLInputElement, hiddenSelect as HTMLSelectElement);
466
- this.list.setAttribute('role', 'listbox');
467
- attributes(this.list, { 'role': 'listbox', 'aria-label': 'listbox', 'aria-multiselectable': this.selectionSettings.mode === 'Multiple' ? 'true' : 'false' });
468
- this.updateSelectionSettings();
469
- }
470
-
471
- private updateSelectionSettings(): void {
472
- if (this.selectionSettings.showCheckbox && this.selectionSettings.showSelectAll && this.liCollections.length) {
473
- const l10nSelect: L10n = new L10n(
474
- this.getModuleName(), { selectAllText: 'Select All', unSelectAllText: 'Unselect All' }, this.locale);
475
- this.showSelectAll = true;
476
- this.selectAllText = l10nSelect.getConstant('selectAllText');
477
- this.unSelectAllText = l10nSelect.getConstant('unSelectAllText');
478
- this.popupWrapper = this.list;
479
- this.checkBoxSelectionModule.checkAllParent = null;
480
- this.notify('selectAll', {});
481
- }
482
- }
483
-
484
- private initDraggable(): void {
485
- if (this.ulElement) {
486
- this.ulElement.id = this.element.id + '_parent';
487
- }
488
- if (this.allowDragAndDrop) {
489
- new Sortable(this.ulElement, {
490
- scope: this.scope,
491
- itemClass: 'e-list-item',
492
- dragStart: this.triggerDragStart.bind(this),
493
- drag: this.triggerDrag.bind(this),
494
- beforeDrop: this.beforeDragEnd.bind(this),
495
- drop: this.dragEnd.bind(this),
496
- placeHolder: () => { return this.createElement('span', { className: 'e-placeholder' }); },
497
- helper: (e: { sender: Element }) => {
498
- const wrapper: HTMLElement = this.list.cloneNode() as HTMLElement;
499
- const ele: HTMLElement = e.sender.cloneNode(true) as HTMLElement;
500
- wrapper.appendChild(ele);
501
- const refEle: HTMLElement = this.getItems()[0] as HTMLElement;
502
- wrapper.style.width = refEle.offsetWidth + 'px';
503
- wrapper.style.height = refEle.offsetHeight + 'px';
504
- if ((this.value && this.value.length) > 1 && this.isSelected(ele)) {
505
- ele.appendChild(this.createElement('span', {
506
- className: 'e-list-badge', innerHTML: this.value.length + ''
507
- }));
508
- }
509
- wrapper.style.zIndex = getZindexPartial(this.element) + '';
510
- return wrapper;
511
- }
512
- }
513
- );
514
- }
515
- }
516
-
517
- protected updateActionCompleteData(li: HTMLElement, item: { [key: string]: Object }, index: number): void {
518
- (this.jsonData as { [key: string]: Object }[]).splice(index, 0, item);
519
- }
520
-
521
- private initToolbar(): void {
522
- const pos: string = this.toolbarSettings.position;
523
- const prevScope: string = this.element.getAttribute('data-value');
524
- if (this.toolbarSettings.items.length) {
525
- const toolElem: Element = this.createElement('div', { className: 'e-listbox-tool', attrs: { 'role': 'toolbar' } });
526
- const wrapper: Element = this.createElement('div', {
527
- className: 'e-listboxtool-wrapper e-lib e-' + pos.toLowerCase()
528
- });
529
- this.list.parentElement.insertBefore(wrapper, this.list);
530
- wrapper.appendChild(pos === 'Right' ? this.list : toolElem);
531
- wrapper.appendChild(pos === 'Right' ? toolElem : this.list);
532
- this.createButtons(toolElem);
533
- if (!this.element.id) {
534
- this.element.id = getUniqueID('e-' + this.getModuleName());
535
- }
536
- if (this.scope) {
537
- document.querySelector(this.scope).setAttribute('data-value', this.element.id);
538
- } else {
539
- this.updateToolBarState();
540
- }
541
- }
542
- const scope: string = this.element.getAttribute('data-value');
543
- if (prevScope && scope && (prevScope !== scope)) {
544
- this.tBListBox = getComponent(document.getElementById(prevScope), this.getModuleName());
545
- this.tBListBox.updateToolBarState();
546
- } else if (scope) {
547
- this.tBListBox = getComponent(document.getElementById(scope), this.getModuleName());
548
- this.tBListBox.updateToolBarState();
549
- }
550
- }
551
-
552
- private createButtons(toolElem: Element): void {
553
- let btn: Button;
554
- let ele: HTMLButtonElement;
555
- let title: string;
556
- const l10n: L10n = new L10n(
557
- this.getModuleName(),
558
- {
559
- moveUp: 'Move Up', moveDown: 'Move Down', moveTo: 'Move To',
560
- moveFrom: 'Move From', moveAllTo: 'Move All To', moveAllFrom: 'Move All From'
561
- },
562
- this.locale
563
- );
564
- this.toolbarSettings.items.forEach((value: string) => {
565
- title = l10n.getConstant(value);
566
- ele = this.createElement('button', {
567
- attrs: {
568
- 'type': 'button',
569
- 'data-value': value,
570
- 'title': title,
571
- 'aria-label': title
572
- }
573
- }) as HTMLButtonElement;
574
- toolElem.appendChild(ele);
575
- btn = new Button({ iconCss: 'e-icons e-' + value.toLowerCase() }, ele);
576
- btn.createElement = this.createElement;
577
- });
578
- }
579
-
580
- protected validationAttribute(input: HTMLInputElement, hiddenSelect: HTMLSelectElement): void {
581
- if (this.inputFormName) { input.setAttribute('name', this.inputFormName); }
582
- super.validationAttribute(input, hiddenSelect);
583
- hiddenSelect.required = input.required;
584
- input.required = false;
585
- }
586
-
587
- private setHeight(): void {
588
- const ele: HTMLElement = this.toolbarSettings.items.length ? this.list.parentElement : this.list;
589
- ele.style.height = formatUnit(this.height);
590
- if (this.allowFiltering && this.height.toString().indexOf('%') < 0) {
591
- addClass([this.list], 'e-filter-list');
592
- } else {
593
- removeClass([this.list], 'e-filter-list');
594
- }
595
- }
596
-
597
- private setCssClass(): void {
598
- const wrap: Element = this.toolbarSettings.items.length ? this.list.parentElement : this.list;
599
- if (this.cssClass) {
600
- addClass([wrap], this.cssClass.replace(/\s+/g, ' ').trim().split(' '));
601
- }
602
- if (this.enableRtl) {
603
- addClass([this.list], 'e-rtl');
604
- }
605
- }
606
-
607
- private setEnable(): void {
608
- const ele: Element = this.toolbarSettings.items.length ? this.list.parentElement : this.list;
609
- if (this.enabled) {
610
- removeClass([ele], cssClass.disabled);
611
- } else {
612
- addClass([ele], cssClass.disabled);
613
- }
614
- }
615
-
616
- public showSpinner(): void {
617
- if (!this.spinner) {
618
- this.spinner = this.createElement('div', { className: 'e-listbox-wrapper' });
619
- }
620
- this.spinner.style.height = formatUnit(this.height);
621
- this.element.parentElement.insertBefore(this.spinner, this.element.nextSibling);
622
- createSpinner({ target: this.spinner }, this.createElement);
623
- showSpinner(this.spinner);
624
- }
625
-
626
- public hideSpinner(): void {
627
- if (this.spinner.querySelector('.e-spinner-pane')) {
628
- hideSpinner(this.spinner);
629
- }
630
- if (this.spinner.parentElement) {
631
- detach(this.spinner);
632
- }
633
- }
634
-
635
- private onInput(): void {
636
- this.isDataSourceUpdate = false;
637
- if (this.keyDownStatus) {
638
- this.isValidKey = true;
639
- } else {
640
- this.isValidKey = false;
641
- }
642
- this.keyDownStatus = false;
643
- this.refreshClearIcon();
644
- }
645
-
646
- private clearText(): void {
647
- this.filterInput.value = '';
648
- this.refreshClearIcon();
649
- const event: KeyboardEvent = document.createEvent('KeyboardEvent');
650
- this.isValidKey = true;
651
- this.KeyUp(event);
652
- }
653
-
654
- private refreshClearIcon(): void {
655
- if (this.filterInput.parentElement.querySelector('.' + listBoxClasses.clearIcon)) {
656
- const clearElement: HTMLElement = <HTMLElement>this.filterInput.parentElement.querySelector('.' + listBoxClasses.clearIcon);
657
- clearElement.style.visibility = this.filterInput.value === '' ? 'hidden' : 'visible';
658
- }
659
- }
660
-
661
- protected onActionComplete(
662
- ulElement: HTMLElement,
663
- list: obj[] | boolean[] | string[] | number[],
664
- e?: Object): void {
665
- let searchEle: Element; let filterElem: HTMLInputElement; let txtLength: number;
666
- if (this.allowFiltering && this.list.getElementsByClassName('e-filter-parent')[0]) {
667
- searchEle = this.list.getElementsByClassName('e-filter-parent')[0].cloneNode(true) as Element;
668
- }
669
- if (list.length === 0) {
670
- const noRecElem: Element = ulElement.childNodes[0] as Element;
671
- if (noRecElem) {
672
- ulElement.removeChild(noRecElem);
673
- }
674
- }
675
- if (this.allowFiltering) {
676
- filterElem = (this.list.getElementsByClassName('e-input-filter')[0] as HTMLInputElement);
677
- if (filterElem) {
678
- txtLength = filterElem.selectionStart;
679
- }
680
- }
681
- super.onActionComplete(ulElement, list, e);
682
- if (this.allowFiltering && !isNullOrUndefined(searchEle)) {
683
- this.list.insertBefore(searchEle, this.list.firstElementChild);
684
- this.filterParent = this.list.getElementsByClassName('e-filter-parent')[0] as HTMLElement;
685
- this.filterWireEvents(searchEle);
686
- }
687
- this.initWrapper();
688
- this.setSelection();
689
- this.initDraggable();
690
- this.mainList = this.ulElement;
691
- if (this.initLoad) {
692
- this.jsonData = []; extend(this.jsonData, list, []);
693
- this.initToolbarAndStyles();
694
- this.wireEvents();
695
- if (this.showCheckbox) {
696
- this.setCheckboxPosition();
697
- }
698
- if (this.allowFiltering) {
699
- this.setFiltering();
700
- }
701
- } else {
702
- if (this.isDataSourceUpdate) {
703
- this.jsonData = []; extend(this.jsonData, list, []);
704
- this.isDataSourceUpdate = false;
705
- }
706
- if (this.allowFiltering) {
707
- filterElem = (this.list.getElementsByClassName('e-input-filter')[0] as HTMLInputElement);
708
- filterElem.selectionStart = txtLength;
709
- filterElem.selectionEnd = txtLength;
710
- filterElem.focus();
711
- }
712
- }
713
- if (this.toolbarSettings.items.length && this.scope && this.scope.indexOf('#') > -1 && !isNullOrUndefined(e)) {
714
- const scope: string = this.scope.replace('#', '');
715
- const scopedLB: ListBox = getComponent(document.getElementById(scope), this.getModuleName());
716
- scopedLB.initToolbar();
717
- }
718
- this.initLoad = false;
719
- }
720
-
721
- private initToolbarAndStyles(): void {
722
- this.initToolbar();
723
- this.setCssClass();
724
- this.setEnable();
725
- this.setHeight();
726
- }
727
-
728
- private triggerDragStart(args: DragEventArgs ): void {
729
- let badge: Element;
730
- args = extend(this.getDragArgs(args), { dragSelected: true }) as DragEventArgs;
731
- if (Browser.isIos) {
732
- this.list.style.overflow = 'hidden';
733
- }
734
- this.trigger('dragStart', args, (dragEventArgs: DragEventArgs) => {
735
- this.allowDragAll = dragEventArgs.dragSelected;
736
- if (!this.allowDragAll) {
737
- badge = this.ulElement.getElementsByClassName('e-list-badge')[0];
738
- if (badge) { detach(badge); }
739
- }
740
- });
741
- }
742
-
743
- private triggerDrag(args: DragEventArgs): void {
744
- let scrollParent: HTMLElement; let boundRect: DOMRect; const scrollMoved: number = 36;
745
- let scrollHeight: number = 10;
746
- if (this.itemTemplate && args.target) {
747
- if (args.target && args.target.closest('.e-list-item')) {
748
- scrollHeight = args.target.closest('.e-list-item').scrollHeight;
749
- } else {
750
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
751
- const listItem: HTMLElement = (args as any).element.querySelector('.e-list-item');
752
- if (listItem) {
753
- scrollHeight = listItem.scrollHeight;
754
- }
755
- }
756
- }
757
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
758
- const event: any = (args as any).event; let wrapper: HTMLElement; this.stopTimer();
759
- if (args.target && (args.target.classList.contains('e-listbox-wrapper') || args.target.classList.contains('e-list-item')
760
- || args.target.classList.contains('e-filter-parent') || args.target.classList.contains('e-input-group')
761
- || args.target.closest('.e-list-item'))) {
762
- if (args.target.classList.contains('e-list-item') || args.target.classList.contains('e-filter-parent')
763
- || args.target.classList.contains('e-input-group')
764
- || args.target.closest('.e-list-item')) {
765
- wrapper = args.target.closest('.e-listbox-wrapper') as HTMLElement;
766
- } else {
767
- wrapper = args.target as HTMLElement;
768
- }
769
- if (this.allowFiltering) {
770
- scrollParent = wrapper.querySelector('.e-list-parent');
771
- } else {
772
- scrollParent = wrapper;
773
- }
774
- boundRect = scrollParent.getBoundingClientRect() as DOMRect;
775
- if ((boundRect.y + scrollParent.offsetHeight) - (event.clientY + scrollMoved) < 1) {
776
- this.timer = window.setInterval(() => { this.setScrollDown(scrollParent, scrollHeight, true); }, 70);
777
- }
778
- else if ((event.clientY - scrollMoved) - boundRect.y < 1) {
779
- this.timer = window.setInterval(() => { this.setScrollDown(scrollParent, scrollHeight, false); }, 70);
780
- }
781
- }
782
- if (args.target === null) {
783
- return;
784
- }
785
- this.trigger('drag', this.getDragArgs(args as DragEventArgs));
786
- }
787
-
788
- private setScrollDown(scrollElem: Element, scrollPixel: number, isScrollDown: boolean): void {
789
- if (isScrollDown) {
790
- scrollElem.scrollTop = scrollElem.scrollTop + scrollPixel;
791
- } else {
792
- scrollElem.scrollTop = scrollElem.scrollTop - scrollPixel;
793
- }
794
- }
795
-
796
- private stopTimer(): void {
797
- window.clearInterval(this.timer);
798
- }
799
-
800
- private beforeDragEnd(args: DropEventArgs): void {
801
- this.stopTimer();
802
- let items: object[] = [];
803
- this.dragValue = this.getFormattedValue(args.droppedElement.getAttribute('data-value')) as string;
804
- if ((this.value as string[]).indexOf(this.dragValue) > -1) {
805
- args.items = this.getDataByValues(this.value);
806
- } else {
807
- args.items = this.getDataByValues([this.dragValue]);
808
- }
809
- extend(items, args.items);
810
- this.trigger('beforeDrop', args);
811
- if (args.items !== items) {
812
- this.customDraggedItem = args.items;
813
- }
814
- }
815
-
816
- private dragEnd(args: DropEventArgs): void {
817
- let listData: dataType[]; let liColl: HTMLElement[]; let jsonData: dataType[]; let droppedData: dataType;
818
- let selectedOptions: (string | boolean | number)[]; let sortedData: dataType[];
819
- const dropValue: string | number | boolean = this.getFormattedValue(args.droppedElement.getAttribute('data-value'));
820
- const listObj: ListBox = this.getComponent(args.droppedElement);
821
- const getArgs: Object = this.getDragArgs({ target: args.droppedElement } as DragEventArgs , true);
822
- const sourceArgs: Object = { previousData: this.dataSource }; const destArgs: Object = { previousData: listObj.dataSource };
823
- let dragArgs: Object = extend({}, getArgs, { target: args.target, source: { previousData: this.dataSource },
824
- previousIndex: args.previousIndex, currentIndex: args.currentIndex });
825
- if (listObj !== this) {
826
- const sourceArgs1: Object = extend( sourceArgs, {currentData: this.listData});
827
- dragArgs = extend(dragArgs, { source: sourceArgs1, destination: destArgs} );
828
- }
829
- if (Browser.isIos) {
830
- this.list.style.overflow = '';
831
- }
832
- const targetListObj: ListBox = this.getComponent(args.target);
833
- if (targetListObj && targetListObj.listData.length === 0) {
834
- const noRecElem: Element = targetListObj.ulElement.childNodes[0] as Element;
835
- if (noRecElem) {
836
- targetListObj.ulElement.removeChild(noRecElem);
837
- }
838
- }
839
- if (listObj === this) {
840
- const ul: Element = this.ulElement;
841
- listData = [].slice.call(this.listData); liColl = [].slice.call(this.liCollections);
842
- jsonData = [].slice.call(this.jsonData); sortedData = [].slice.call(this.sortedData);
843
- const toSortIdx: number = args.currentIndex;
844
- let toIdx: number = args.currentIndex = this.getCurIdx(this, args.currentIndex);
845
- const rIdx: number = listData.indexOf(this.getDataByValue(dropValue));
846
- const jsonIdx: number = jsonData.indexOf(this.getDataByValue(dropValue));
847
- const sIdx: number = sortedData.indexOf(this.getDataByValue(dropValue));
848
- listData.splice(toIdx, 0, listData.splice(rIdx, 1)[0] as obj);
849
- sortedData.splice(toSortIdx, 0, sortedData.splice(sIdx, 1)[0] as obj);
850
- jsonData.splice(toIdx, 0, jsonData.splice(jsonIdx, 1)[0] as obj);
851
- liColl.splice(toIdx, 0, liColl.splice(rIdx, 1)[0] as HTMLElement);
852
- if (this.allowDragAll) {
853
- selectedOptions = this.value && Array.prototype.indexOf.call(this.value, dropValue) > -1 ? this.value : [dropValue];
854
- if (!isNullOrUndefined(this.customDraggedItem)) {
855
- selectedOptions = [];
856
- this.customDraggedItem.forEach((item: object) => {
857
- selectedOptions.push(getValue(this.fields.value, item));
858
- })
859
- }
860
- selectedOptions.forEach((value: string) => {
861
- if (value !== dropValue) {
862
- const idx: number = listData.indexOf(this.getDataByValue(value));
863
- const jsonIdx: number = jsonData.indexOf(this.getDataByValue(value));
864
- const sIdx: number = sortedData.indexOf(this.getDataByValue(value));
865
- if (idx > toIdx) {
866
- toIdx++;
867
- }
868
- jsonData.splice(toIdx, 0, jsonData.splice(jsonIdx, 1)[0] as obj);
869
- listData.splice(toIdx, 0, listData.splice(idx, 1)[0] as obj);
870
- sortedData.splice(toSortIdx, 0, sortedData.splice(sIdx, 1)[0] as obj);
871
- liColl.splice(toIdx, 0, liColl.splice(idx, 1)[0] as HTMLElement);
872
- ul.insertBefore(this.getItems()[this.getIndexByValue(value)], ul.getElementsByClassName('e-placeholder')[0]);
873
- }
874
- });
875
- }
876
- (this.listData as dataType[]) = listData; (this.jsonData as dataType[]) = jsonData;
877
- (this.sortedData as dataType[]) = sortedData; this.liCollections = liColl;
878
- } else {
879
- let li: Element; const fLiColl: HTMLElement[] = [].slice.call(this.liCollections);
880
- let currIdx: number = args.currentIndex = this.getCurIdx(listObj, args.currentIndex); const ul: Element = listObj.ulElement;
881
- listData = [].slice.call(listObj.listData); liColl = [].slice.call(listObj.liCollections);
882
- jsonData = [].slice.call(listObj.jsonData); sortedData = [].slice.call(listObj.sortedData);
883
- selectedOptions = (this.value && Array.prototype.indexOf.call(this.value, dropValue) > -1 && this.allowDragAll)
884
- ? this.value : [dropValue];
885
- if (!isNullOrUndefined(this.customDraggedItem)) {
886
- selectedOptions = [];
887
- this.customDraggedItem.forEach((item: object) => {
888
- selectedOptions.push(getValue(this.fields.value, item));
889
- })
890
- }
891
- const fListData: dataType[] = [].slice.call(this.listData); const fSortData: dataType[] = [].slice.call(this.sortedData);
892
- selectedOptions.forEach((value: string, index: number) => {
893
- droppedData = this.getDataByValue(value);
894
- const srcIdx: number = (this.listData as dataType[]).indexOf(droppedData);
895
- const jsonSrcIdx: number = (this.jsonData as dataType[]).indexOf(droppedData);
896
- const sortIdx: number = (this.sortedData as dataType[]).indexOf(droppedData);
897
- fListData.splice(srcIdx, 1); this.jsonData.splice(jsonSrcIdx, 1);
898
- fSortData.splice(sortIdx, 1); (this.listData as dataType[]) = fListData; (this.sortedData as dataType[]) = fSortData;
899
- const destIdx: number = value === dropValue ? args.currentIndex : currIdx;
900
- listData.splice(destIdx, 0, droppedData); jsonData.splice(destIdx, 0, droppedData);
901
- sortedData.splice(destIdx, 0, droppedData);
902
- liColl.splice(destIdx, 0, fLiColl.splice(srcIdx, 1)[0]);
903
- if (!value) {
904
- const liCollElem: Element[] = this.getItems();
905
- for (let i: number = 0; i < liCollElem.length; i++ ) {
906
- if (liCollElem[i as number].getAttribute('data-value') === null && liCollElem[i as number].classList.contains('e-list-item')) {
907
- li = liCollElem[i as number];
908
- break;
909
- }
910
- }
911
- } else {
912
- li = this.getItems()[this.getIndexByValue(value)];
913
- }
914
- if (!li) { li = args.helper; }
915
- this.removeSelected(this, value === dropValue ? [args.droppedElement] : [li]);
916
- ul.insertBefore(li, ul.getElementsByClassName('e-placeholder')[0]);
917
- currIdx++;
918
- });
919
- if (this.fields.groupBy) {
920
- const sourceElem: HTMLElement = this.renderItems(this.listData as obj[], this.fields);
921
- this.updateListItems(sourceElem, this.ulElement); this.setSelection();
922
- }
923
- if (listObj.sortOrder !== 'None' || this.selectionSettings.showCheckbox
924
- !== listObj.selectionSettings.showCheckbox || listObj.fields.groupBy || listObj.itemTemplate || this.itemTemplate) {
925
- const sortable: { placeHolderElement: Element } = getComponent(ul as HTMLElement, 'sortable');
926
- const sourceElem: HTMLElement = listObj.renderItems(listData as obj[], listObj.fields);
927
- listObj.updateListItems(sourceElem, ul as HTMLElement); this.setSelection();
928
- if (sortable.placeHolderElement) {
929
- ul.appendChild(sortable.placeHolderElement);
930
- }
931
- ul.appendChild(args.helper); listObj.setSelection();
932
- }
933
- this.liCollections = fLiColl; listObj.liCollections = liColl;
934
- (listObj.jsonData as dataType[]) = extend([], [], jsonData, false) as dataType[];
935
- (listObj.listData as dataType[]) = extend([], [], listData, false) as dataType[];
936
- (listObj.sortedData as dataType[]) = extend([], [], sortedData, false) as dataType[];
937
- if (this.listData.length === 0) {
938
- this.l10nUpdate();
939
- }
940
- }
941
- if (this === listObj) {
942
- const sourceArgs1: Object = extend( sourceArgs, {currentData: listData});
943
- dragArgs = extend(dragArgs, {source: sourceArgs1});
944
- } else {
945
- const dragArgs1: Object = extend(destArgs, {currentData: listData});
946
- dragArgs = extend(dragArgs, { destination: dragArgs1 });
947
- }
948
- if (!isNullOrUndefined(this.customDraggedItem)) {
949
- (dragArgs as DragEventArgs).items = this.customDraggedItem;
950
- }
951
- this.trigger('drop', dragArgs);
952
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
953
- const liCollElem: NodeListOf<Element> = (dragArgs as any).elements;
954
- if (liCollElem.length) {
955
- for (let i: number = 0; i < liCollElem.length; i++) {
956
- liCollElem[i as number].classList.remove('e-grabbed');
957
- }
958
- }
959
- }
960
-
961
- private updateListItems(sourceElem: HTMLElement, destElem: HTMLElement): void {
962
- const i: number = 0;
963
- destElem.innerHTML = '';
964
- while (i < sourceElem.childNodes.length) {
965
- destElem.appendChild(sourceElem.childNodes[i as number]);
966
- }
967
- }
968
-
969
- private removeSelected(listObj: ListBox, elems: Element[]): void {
970
- if (listObj.selectionSettings.showCheckbox) {
971
- elems.forEach((ele: Element) => { ele.getElementsByClassName('e-frame')[0].classList.remove('e-check'); });
972
- } else {
973
- removeClass(elems, cssClass.selected);
974
- }
975
- }
976
-
977
- private getCurIdx(listObj: ListBox, idx: number): number {
978
- if (listObj.fields.groupBy) {
979
- idx -= [].slice.call(listObj.ulElement.children).slice(0, idx)
980
- .filter((ele: Element) => ele.classList.contains(cssClass.group)).length;
981
- }
982
- return idx;
983
- }
984
-
985
- private getComponent(li: Element): ListBox {
986
- let listObj: ListBox;
987
- const ele: HTMLElement = (this.element.tagName === 'EJS-LISTBOX' ? closest(li, '.e-listbox')
988
- : closest(li, '.e-listbox-wrapper') && closest(li, '.e-listbox-wrapper').querySelector('.e-listbox')) as HTMLElement;
989
- if (ele) {
990
- listObj = getComponent(ele, this.getModuleName());
991
- }
992
- return listObj;
993
- }
994
-
995
- /**
996
- * Sets the enabled state to DropDownBase.
997
- *
998
- * @returns {void}
999
- */
1000
- protected setEnabled(): void {
1001
- this.element.setAttribute('aria-disabled', (this.enabled) ? 'false' : 'true');
1002
- }
1003
-
1004
- protected listOption(
1005
- dataSource: obj[] | string[] | number[] | boolean[],
1006
- fields: FieldSettingsModel): FieldSettingsModel {
1007
- this.listCurrentOptions = super.listOption(dataSource, fields);
1008
- this.listCurrentOptions = extend({}, this.listCurrentOptions, { itemCreated: this.triggerBeforeItemRender.bind(this) }, true);
1009
- this.notify('listoption', { module: 'CheckBoxSelection' });
1010
- return this.listCurrentOptions;
1011
- }
1012
-
1013
- private triggerBeforeItemRender(e: { item: Element, curData: obj }): void {
1014
- e.item.setAttribute('tabindex', '-1');
1015
- this.trigger('beforeItemRender', { element: e.item, item: e.curData });
1016
- }
1017
-
1018
- public requiredModules(): ModuleDeclaration[] {
1019
- const modules: ModuleDeclaration[] = [];
1020
- if (this.selectionSettings.showCheckbox) {
1021
- modules.push({
1022
- member: 'CheckBoxSelection',
1023
- args: [this]
1024
- });
1025
- }
1026
- return modules;
1027
- }
1028
-
1029
- /**
1030
- * This method is used to enable or disable the items in the ListBox based on the items and enable argument.
1031
- *
1032
- * @param {string[]} items - Text items that needs to be enabled/disabled.
1033
- * @param {boolean} enable - Set `true`/`false` to enable/disable the list items.
1034
- * @param {boolean} isValue - Set `true` if `items` parameter is a array of unique values.
1035
- * @returns {void}
1036
- */
1037
- public enableItems(items: string[], enable: boolean = true, isValue?: boolean): void {
1038
- let li: HTMLElement;
1039
- items.forEach((item: string) => {
1040
- const text: string = item;
1041
- li = this.findListElement(this.list, 'li', 'data-value', isValue ? text : this.getValueByText(text));
1042
- if (!li) { return; }
1043
- if (enable) {
1044
- removeClass([li], cssClass.disabled);
1045
- li.removeAttribute('aria-disabled');
1046
- } else {
1047
- addClass([li], cssClass.disabled);
1048
- li.setAttribute('aria-disabled', 'true');
1049
- }
1050
- });
1051
- }
1052
-
1053
- /**
1054
- * Based on the state parameter, specified list item will be selected/deselected.
1055
- *
1056
- * @param {string[]} items - Array of text value of the item.
1057
- * @param {boolean} state - Set `true`/`false` to select/un select the list items.
1058
- * @param {boolean} isValue - Set `true` if `items` parameter is a array of unique values.
1059
- * @returns {void}
1060
- */
1061
- public selectItems(items: string[], state: boolean = true, isValue?: boolean): void {
1062
- if (state && !this.selectionSettings.showCheckbox && this.selectionSettings.mode === 'Single') {
1063
- this.getSelectedItems().forEach((li: Element) => {
1064
- li.classList.remove('e-active');
1065
- li.removeAttribute('aria-selected');
1066
- removeClass([li], cssClass.selected);
1067
- });
1068
- }
1069
- this.setSelection(items, state, !isValue);
1070
- this.updateSelectedOptions();
1071
- let selElems: Element[] = [];
1072
- for (let i: number = 0; i < items.length; i++) {
1073
- const liColl: NodeListOf<Element> = this.list.querySelectorAll('[aria-selected="true"]');
1074
- for (let j: number = 0; j < liColl.length; j++) {
1075
- if (items[i as number] === this.getFormattedValue(liColl[j as number].getAttribute('data-value')) as string) {
1076
- selElems.push(liColl[j as number])
1077
- }
1078
- }
1079
- }
1080
- this.triggerChange(selElems, null);
1081
- }
1082
-
1083
- /**
1084
- * Based on the state parameter, entire list item will be selected/deselected.
1085
- *
1086
- * @param {boolean} state - Set `true`/`false` to select/un select the entire list items.
1087
- * @returns {void}
1088
- */
1089
- public selectAll(state: boolean = true): void {
1090
- this.selectAllItems(state);
1091
- }
1092
-
1093
- /**
1094
- * Adds a new item to the list. By default, new item appends to the list as the last item,
1095
- * but you can insert based on the index parameter.
1096
- *
1097
- * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
1098
- * @param { number } itemIndex - Specifies the index to place the newly added item in the list.
1099
- * @returns {void}.
1100
- */
1101
- public addItems(items: obj[] | obj, itemIndex?: number): void {
1102
- super.addItem(items, itemIndex);
1103
- }
1104
- /**
1105
- * Removes a item from the list. By default, removed the last item in the list,
1106
- * but you can remove based on the index parameter.
1107
- *
1108
- * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
1109
- * @param { number } itemIndex - Specifies the index to remove the item from the list.
1110
- * @returns {void}.
1111
- */
1112
- public removeItems(items?: obj[] | obj, itemIndex?: number): void {
1113
- this.removeItem(items, itemIndex);
1114
- }
1115
- /**
1116
- * Removes a item from the list. By default, removed the last item in the list,
1117
- * but you can remove based on the index parameter.
1118
- *
1119
- * @param { Object[] } items - Specifies an array of JSON data or a JSON data.
1120
- * @param { number } itemIndex - Specifies the index to remove the item from the list.
1121
- * @returns {void}.
1122
- */
1123
- public removeItem(
1124
- items?: { [key: string]: Object }[] | { [key: string]: Object } | string | boolean | number | string[] | boolean[] | number[],
1125
- itemIndex?: number): void {
1126
- const liCollections: HTMLElement[] = [];
1127
- const liElement: HTMLElement[] | NodeListOf<HTMLLIElement> = this.list.querySelectorAll('.' + dropDownBaseClasses.li);
1128
- if (items) {
1129
- items = (items instanceof Array ? items : [items]) as { [key: string]: Object }[] | string[] | boolean[] | number[];
1130
- const fields: FieldSettingsModel = this.fields; let dataValue: string; let objValue: string;
1131
- const dupData: {[key: string]: Object }[] = []; let itemIdx: number;
1132
- extend(dupData, [], this.jsonData as { [key: string]: Object }[]);
1133
- const removeIdxes: number [] = []; const removeLiIdxes: number [] = [];
1134
- for (let j: number = 0; j < items.length; j++) {
1135
- if (items[j as number] instanceof Object) {
1136
- dataValue = getValue(fields.value, items[j as number]);
1137
- } else {
1138
- dataValue = items[j as number].toString();
1139
- }
1140
- for (let i: number = 0, len: number = dupData.length; i < len; i++) {
1141
- if (dupData[i as number] instanceof Object) {
1142
- objValue = getValue(fields.value, dupData[i as number]);
1143
- } else {
1144
- objValue = dupData[i as number].toString();
1145
- }
1146
- if (objValue === dataValue) {
1147
- itemIdx = this.getIndexByValue(dataValue);
1148
- const idx: number = itemIdx === i ? itemIdx : i;
1149
- liCollections.push(liElement[idx as number]);
1150
- removeIdxes.push(idx);
1151
- removeLiIdxes.push(idx);
1152
- }
1153
- }
1154
- }
1155
- for (let k: number = removeIdxes.length - 1; k >= 0; k--) {
1156
- (this.listData as { [key: string]: Object }[]).splice(removeIdxes[k as number], 1);
1157
- }
1158
- for (let k: number = removeIdxes.length - 1; k >= 0; k--) {
1159
- (this.jsonData as { [key: string]: Object }[]).splice(removeIdxes[k as number], 1);
1160
- }
1161
- for (let k: number = removeLiIdxes.length - 1; k >= 0; k--) {
1162
- this.updateLiCollection(removeLiIdxes[k as number]);
1163
- }
1164
- } else {
1165
- itemIndex = itemIndex ? itemIndex : 0;
1166
- liCollections.push(liElement[itemIndex as number]);
1167
- (this.listData as { [key: string]: Object }[]).splice(itemIndex, 1);
1168
- (this.jsonData as { [key: string]: Object }[]).splice(itemIndex, 1);
1169
- this.updateLiCollection(itemIndex);
1170
- }
1171
- for (let i: number = 0; i < liCollections.length; i++) {
1172
- this.ulElement.removeChild(liCollections[i as number]);
1173
- }
1174
- if (this.listData.length === 0) {
1175
- this.l10nUpdate();
1176
- }
1177
- this.value = [];
1178
- this.updateToolBarState();
1179
- }
1180
- /**
1181
- * Gets the array of data Object that matches the given array of values.
1182
- *
1183
- * @param { string[] | number[] | boolean[] } value - Specifies the array value of the list item.
1184
- * @returns {object[]}.
1185
- */
1186
- public getDataByValues(value: string[] | number[] | boolean[] ): { [key: string]: Object }[] {
1187
- const data: string | number | boolean | { [key: string]: Object }[] = [];
1188
- for (let i: number = 0; i < value.length; i++) {
1189
- data.push(this.getDataByValue(value[i as number]) as { [key: string]: Object });
1190
- }
1191
- return data;
1192
- }
1193
- /**
1194
- * Moves the given value(s) / selected value(s) upwards.
1195
- *
1196
- * @param { string[] | number[] | boolean[] } value - Specifies the value(s).
1197
- * @returns {void}
1198
- */
1199
- public moveUp(value?: string[] | number[] | boolean[]): void {
1200
- const elem: Element[] = (value) ? this.getElemByValue(value) : this.getSelectedItems();
1201
- this.moveUpDown(true, false, elem);
1202
- }
1203
- /**
1204
- * Moves the given value(s) / selected value(s) downwards.
1205
- *
1206
- * @param { string[] | number[] | boolean[] } value - Specifies the value(s).
1207
- * @returns {void}
1208
- */
1209
- public moveDown(value?: string[] | number[] | boolean[]): void {
1210
- const elem: Element[] = (value) ? this.getElemByValue(value) : this.getSelectedItems();
1211
- this.moveUpDown(false, false, elem);
1212
- }
1213
- /**
1214
- * Moves the given value(s) / selected value(s) in Top of the list.
1215
- *
1216
- * @param { string[] | number[] | boolean[] } value - Specifies the value(s).
1217
- * @returns {void}
1218
- */
1219
- public moveTop(value?: string[] | number[] | boolean[]): void {
1220
- const elem: Element[] = (value) ? this.getElemByValue(value) : this.getSelectedItems();
1221
- this.moveUpDown(null, false, elem, true);
1222
- }
1223
- /**
1224
- * Moves the given value(s) / selected value(s) in bottom of the list.
1225
- *
1226
- * @param { string[] | number[] | boolean[] } value - Specifies the value(s).
1227
- * @returns {void}
1228
- */
1229
- public moveBottom(value?: string[] | number[] | boolean[]): void {
1230
- const elem: Element[] = (value) ? this.getElemByValue(value) : this.getSelectedItems();
1231
- this.moveUpDown(true, false, elem, false, true);
1232
- }
1233
- /**
1234
- * Moves the given value(s) / selected value(s) to the given / default scoped ListBox.
1235
- *
1236
- * @param { string[] | number[] | boolean[] } value - Specifies the value or array value of the list item.
1237
- * @param {number} index - Specifies the index.
1238
- * @param {string} targetId - Specifies the target id.
1239
- * @returns {void}
1240
- */
1241
- public moveTo(value?: string[] | number[] | boolean[], index?: number, targetId?: string): void {
1242
- const elem: Element[] = (value) ? this.getElemByValue(value) : this.getSelectedItems();
1243
- const tlistbox: ListBox = (targetId) ? getComponent(targetId, ListBox) : this.getScopedListBox();
1244
- this.moveData(this, tlistbox, false, elem, index);
1245
- }
1246
- /**
1247
- * Moves all the values from one ListBox to the scoped ListBox.
1248
- *
1249
- * @param { string } targetId - Specifies the scoped ListBox ID.
1250
- * @param { string } index - Specifies the index to where the items moved.
1251
- * @returns {void}
1252
- */
1253
- public moveAllTo(targetId?: string, index?: number): void {
1254
- if (this.listData.length > 0) {
1255
- const tlistbox: ListBox = (targetId) ? getComponent(targetId, ListBox) : this.getScopedListBox();
1256
- this.moveAllData(this, tlistbox, false, index);
1257
- }
1258
- }
1259
- /* eslint-disable */
1260
- /**
1261
- * Gets the updated dataSource in ListBox.
1262
- *
1263
- * @returns {{ [key: string]: Object }[] | string[] | boolean[] | number[]} - Updated DataSource.
1264
- */
1265
- /* eslint-enable */
1266
- public getDataList(): { [key: string]: Object }[] | string[] | boolean[] | number[] {
1267
- return this.jsonData;
1268
- }
1269
- /* eslint-disable */
1270
- /**
1271
- * Returns the sorted Data in ListBox.
1272
- *
1273
- * @returns {{ [key: string]: Object }[] | string[] | boolean[] | number[]} - Sorted data
1274
- */
1275
- /* eslint-enable */
1276
- public getSortedList(): { [key: string]: Object }[] | string[] | boolean[] | number[] {
1277
- let sortData: dataType[]; let tempData: { [key: string]: Object }[] | string[] | boolean[] | number[];
1278
- sortData = tempData = this.sortedData;
1279
- if (this.fields.groupBy) {
1280
- sortData = [];
1281
- for (let i: number = 0; i < tempData.length; i++) {
1282
- if ((tempData[i as number] as { [key: string]: Object }).isHeader) {
1283
- continue;
1284
- }
1285
- sortData.push(tempData[i as number]);
1286
- }
1287
- }
1288
- return sortData as { [key: string]: Object }[] | string[] | boolean[] | number[];
1289
- }
1290
- private getElemByValue(value: string[] | number[] | boolean[]): Element[] {
1291
- const elem: Element[] = [];
1292
- for (let i: number = 0; i < value.length; i++) {
1293
- elem.push(this.ulElement.querySelector('[data-value ="' + value[i as number] + '"]'));
1294
- }
1295
- return elem;
1296
- }
1297
- private updateLiCollection(index: number): void {
1298
- const tempLi: HTMLElement[] = [].slice.call(this.liCollections);
1299
- tempLi.splice(index, 1);
1300
- this.liCollections = tempLi;
1301
- }
1302
- private selectAllItems(state: boolean, event?: MouseEvent): void {
1303
- [].slice.call(this.getItems()).forEach((li: Element) => {
1304
- if (!li.classList.contains(cssClass.disabled)) {
1305
- if (this.selectionSettings.showCheckbox) {
1306
- const ele: Element = li.getElementsByClassName('e-check')[0];
1307
- if ((!ele && state) || (ele && !state)) {
1308
- this.notify('updatelist', { li: li, module: 'listbox' });
1309
- if (this.maximumSelectionLength >= this.list.querySelectorAll('.e-list-item span.e-check').length) {
1310
- this.checkMaxSelection();
1311
- }
1312
- }
1313
- } else {
1314
- if (state) {
1315
- li.classList.add(cssClass.selected);
1316
- } else {
1317
- li.classList.remove(cssClass.selected);
1318
- }
1319
- }
1320
- }
1321
- });
1322
- this.updateSelectedOptions();
1323
- if (this.allowFiltering && this.selectionSettings.showCheckbox) {
1324
- const liEle: HTMLCollectionOf<HTMLLIElement> = this.list.getElementsByTagName('li') as HTMLCollectionOf<HTMLLIElement>;
1325
- let index: number = 0;
1326
- if (state) {
1327
- for (index = 0; index < liEle.length; index++) {
1328
- const dataValue1: string = this.getFormattedValue(liEle[index as number].getAttribute('data-value')) as string;
1329
- if (!(this.value as string[]).some((e: string) => e === dataValue1)) {
1330
- (this.value as string[]).push(this.getFormattedValue(liEle[index as number].getAttribute('data-value')) as string);
1331
- }
1332
- }
1333
- } else {
1334
- for (index = 0; index < liEle.length; index++) {
1335
- const dataValue2: string = this.getFormattedValue(liEle[index as number].getAttribute('data-value')) as string;
1336
- this.value = (this.value as string[]).filter((e: string) => e !== dataValue2);
1337
- }
1338
- }
1339
- if (document.querySelectorAll('ul').length < 2) {
1340
- this.updateMainList();
1341
- }
1342
- }
1343
- this.triggerChange(this.getSelectedItems(), event);
1344
- }
1345
-
1346
- private updateMainList(): void {
1347
- const mainList: NodeListOf<Element> = this.mainList.querySelectorAll('.e-list-item');
1348
- const ulList: NodeListOf<Element> = this.ulElement.querySelectorAll('.e-list-item');
1349
- const mainCount: number = mainList.length; const ulEleCount: number = ulList.length;
1350
- if (this.selectionSettings.showCheckbox || (document.querySelectorAll('ul').length > 1 || mainCount !== ulEleCount)) {
1351
- let listindex: number = 0;
1352
- let valueindex: number = 0;
1353
- let count: number = 0;
1354
- for (listindex; listindex < mainCount; ) {
1355
- if (this.value) {
1356
- for (valueindex; valueindex < this.value.length; valueindex++) {
1357
- if (mainList[listindex as number].getAttribute('data-value') === this.value[valueindex as number]) {
1358
- count++;
1359
- }
1360
- }
1361
- }
1362
- if (!count && this.selectionSettings.showCheckbox) {
1363
- mainList[listindex as number].getElementsByClassName('e-frame')[0].classList.remove('e-check');
1364
- }
1365
- if (document.querySelectorAll('ul').length > 1 && count && mainCount !== ulEleCount) {
1366
- this.mainList.removeChild(this.mainList.getElementsByTagName('li')[listindex as number]);
1367
- listindex = 0;
1368
- } else {
1369
- listindex++;
1370
- }
1371
- count = 0;
1372
- valueindex = 0;
1373
- }
1374
- }
1375
- }
1376
-
1377
- private wireEvents(): void {
1378
- const form: Element = closest(this.element, 'form');
1379
- const wrapper: Element = this.element.tagName === 'EJS-LISTBOX' ? this.element : this.list;
1380
- EventHandler.add(this.list, 'click', this.clickHandler, this);
1381
- EventHandler.add(wrapper, 'keydown', this.keyDownHandler, this);
1382
- EventHandler.add(wrapper, 'focusout', this.focusOutHandler, this);
1383
- this.wireToolbarEvent();
1384
- if (this.selectionSettings.showCheckbox) {
1385
- EventHandler.remove(document, 'mousedown', this.checkBoxSelectionModule.onDocumentClick);
1386
- }
1387
- if (this.fields.groupBy || this.element.querySelector('select>optgroup')) {
1388
- EventHandler.remove(this.list, 'scroll', this.setFloatingHeader);
1389
- }
1390
- if (form) {
1391
- EventHandler.add(form, 'reset', this.formResetHandler, this);
1392
- }
1393
- }
1394
-
1395
- private wireToolbarEvent(): void {
1396
- if (this.toolbarSettings.items.length) {
1397
- EventHandler.add(this.getToolElem(), 'click', this.toolbarClickHandler, this);
1398
- }
1399
- }
1400
-
1401
- private unwireEvents(): void {
1402
- const form: Element = closest(this.element, 'form');
1403
- const wrapper: Element = this.element.tagName === 'EJS-LISTBOX' ? this.element : this.list;
1404
- EventHandler.remove(this.list, 'click', this.clickHandler);
1405
- EventHandler.remove(wrapper, 'keydown', this.keyDownHandler);
1406
- EventHandler.remove(wrapper, 'focusout', this.focusOutHandler);
1407
- if (this.allowFiltering && this.clearFilterIconElem) {
1408
- EventHandler.remove(this.clearFilterIconElem, 'click', this.clearText);
1409
- }
1410
- if (this.toolbarSettings.items.length) {
1411
- EventHandler.remove(this.getToolElem(), 'click', this.toolbarClickHandler);
1412
- }
1413
- if (form) {
1414
- EventHandler.remove(form, 'reset', this.formResetHandler);
1415
- }
1416
- }
1417
-
1418
- private clickHandler(e: MouseEvent): void {
1419
- this.selectHandler(e);
1420
- }
1421
-
1422
- private checkSelectAll(): void {
1423
- let searchCount: number = 0;
1424
- const liItems: NodeListOf<Element> = this.list.querySelectorAll('li.' + dropDownBaseClasses.li);
1425
- for (let i: number = 0; i < liItems.length; i++) {
1426
- if (!liItems[i as number].classList.contains('e-disabled')) {
1427
- searchCount++;
1428
- }
1429
- }
1430
- const len: number = this.getSelectedItems().length;
1431
- if (this.showSelectAll && searchCount) {
1432
- this.notify('checkSelectAll', { module: 'CheckBoxSelection',
1433
- value: (searchCount === len) ? 'check' : (len === 0) ? 'uncheck' : 'indeterminate'});
1434
- }
1435
- }
1436
-
1437
- protected getQuery(query: Query): Query {
1438
- let filterQuery: Query = query ? query.clone() : this.query ? this.query.clone() : new Query();
1439
- if (this.allowFiltering) {
1440
- const filterType: string = this.inputString === '' ? 'contains' : this.filterType;
1441
- let dataType: string = <string>this.typeOfData(this.dataSource as { [key: string]: Object; }[]).typeof;
1442
- if (dataType === null) {
1443
- dataType = <string>this.typeOfData(this.jsonData as { [key: string]: Object; }[]).typeof;
1444
- }
1445
- if (!(this.dataSource instanceof DataManager) && dataType === 'string' || dataType === 'number') {
1446
- filterQuery.where('', filterType, this.inputString, this.ignoreCase, this.ignoreAccent);
1447
- } else {
1448
- const fields: string = (this.fields.text) ? this.fields.text : '';
1449
- filterQuery.where(fields, filterType, this.inputString, this.ignoreCase, this.ignoreAccent);
1450
- }
1451
- } else {
1452
- filterQuery = query ? query : this.query ? this.query : new Query();
1453
- }
1454
- return filterQuery;
1455
- }
1456
-
1457
- private setFiltering(): InputObject | void {
1458
- let filterInputObj: InputObject;
1459
- if (this.initLoad || isNullOrUndefined(this.filterParent)) {
1460
- this.filterParent = this.createElement('span', {
1461
- className: listBoxClasses.filterParent
1462
- });
1463
- this.filterInput = <HTMLInputElement>this.createElement('input', {
1464
- attrs: { type: 'text' },
1465
- className: listBoxClasses.filterInput
1466
- });
1467
- this.element.parentNode.insertBefore(this.filterInput, this.element);
1468
- filterInputObj = Input.createInput(
1469
- {
1470
- element: this.filterInput,
1471
- buttons: [listBoxClasses.filterBarClearIcon],
1472
- properties: { placeholder: this.filterBarPlaceholder }
1473
- },
1474
- this.createElement
1475
- );
1476
- append([filterInputObj.container], this.filterParent);
1477
- prepend([this.filterParent], this.list);
1478
- attributes(this.filterInput, {
1479
- 'aria-disabled': 'false',
1480
- 'aria-label': 'search list item',
1481
- 'autocomplete': 'off',
1482
- 'autocorrect': 'off',
1483
- 'autocapitalize': 'off',
1484
- 'spellcheck': 'false',
1485
- 'role': 'textbox'
1486
- });
1487
- if (this.height.toString().indexOf('%') < 0) {
1488
- addClass([this.list], 'e-filter-list');
1489
- }
1490
- this.inputString = this.filterInput.value;
1491
- this.filterWireEvents();
1492
- return filterInputObj;
1493
- }
1494
- }
1495
-
1496
- private filterWireEvents(filterElem?: Element): void {
1497
- if (filterElem) {
1498
- this.filterInput = filterElem.querySelector('.e-input-filter');
1499
- }
1500
- this.clearFilterIconElem = this.filterInput.parentElement.querySelector('.' + listBoxClasses.clearIcon);
1501
- if (this.clearFilterIconElem) {
1502
- EventHandler.add(this.clearFilterIconElem, 'click', this.clearText, this);
1503
- if (!filterElem) {
1504
- (this.clearFilterIconElem as HTMLElement).style.visibility = 'hidden';
1505
- }
1506
- }
1507
- EventHandler.add(this.filterInput, 'input', this.onInput, this);
1508
- EventHandler.add(this.filterInput, 'keyup', this.KeyUp, this);
1509
- EventHandler.add(this.filterInput, 'keydown', this.onKeyDown, this);
1510
- }
1511
-
1512
- private selectHandler(e: MouseEvent | { target: EventTarget, ctrlKey?: boolean, shiftKey?: boolean,
1513
- metaKey?: boolean}, isKey?: boolean): void {
1514
- let isSelect: boolean = true;
1515
- let currSelIdx: number;
1516
- const li: Element = closest(e.target as Element, '.' + 'e-list-item');
1517
- let selectedLi: Element[] = [li];
1518
- if (li && li.parentElement) {
1519
- currSelIdx = [].slice.call(li.parentElement.children).indexOf(li);
1520
- if (!this.selectionSettings.showCheckbox) {
1521
- if ((e.ctrlKey || e.metaKey || Browser.isDevice) && this.isSelected(li)) {
1522
- li.classList.remove(cssClass.selected);
1523
- li.removeAttribute('aria-selected');
1524
- isSelect = false;
1525
- } else if (!(this.selectionSettings.mode === 'Multiple' && (e.ctrlKey || e.metaKey || Browser.isDevice))) {
1526
- this.getSelectedItems().forEach((ele: Element) => {
1527
- ele.removeAttribute('aria-selected');
1528
- });
1529
- removeClass(this.getSelectedItems(), cssClass.selected);
1530
- }
1531
- } else {
1532
- isSelect = !li.getElementsByClassName('e-frame')[0].classList.contains('e-check');
1533
- }
1534
- if (e.shiftKey && !this.selectionSettings.showCheckbox && this.selectionSettings.mode !== 'Single') {
1535
- selectedLi = [].slice.call(li.parentElement.children)
1536
- .slice(Math.min(currSelIdx, this.prevSelIdx), Math.max(currSelIdx, this.prevSelIdx) + 1)
1537
- .filter((ele: Element) => { return ele.classList.contains('e-list-item'); });
1538
- } else {
1539
- this.prevSelIdx = [].slice.call(li.parentElement.children).indexOf(li);
1540
- }
1541
- if (isSelect) {
1542
- if (!this.selectionSettings.showCheckbox) {
1543
- addClass(selectedLi, cssClass.selected);
1544
- }
1545
- selectedLi.forEach((ele: Element) => {
1546
- ele.setAttribute('aria-selected', 'true');
1547
- });
1548
- this.list.setAttribute('aria-activedescendant', li.id);
1549
- } else {
1550
- selectedLi.forEach((ele: Element) => {
1551
- ele.setAttribute('aria-selected', 'false');
1552
- });
1553
- }
1554
- if (!isKey && (this.maximumSelectionLength > (this.value && this.value.length) || !isSelect) &&
1555
- (this.maximumSelectionLength >= (this.value && this.value.length) || !isSelect) &&
1556
- !(this.maximumSelectionLength < (this.value && this.value.length))) {
1557
- this.notify('updatelist', { li: li, e: e, module: 'listbox' });
1558
- }
1559
- if (this.allowFiltering && !isKey) {
1560
- const liDataValue: string = this.getFormattedValue(li.getAttribute('data-value')) as string;
1561
- if (!isSelect) {
1562
- this.value = (this.value as string[]).filter((value1: string) =>
1563
- value1 !== liDataValue);
1564
- } else {
1565
- const values: string[] = [];
1566
- extend(values, this.value); values.push(liDataValue);
1567
- this.value = values;
1568
- }
1569
- if (document.querySelectorAll('ul').length < 2) {
1570
- this.updateMainList();
1571
- }
1572
- }
1573
- this.updateSelectedOptions();
1574
- this.triggerChange(this.getSelectedItems(), e as MouseEvent);
1575
- if (this.list) {
1576
- this.checkMaxSelection();
1577
- }
1578
- }
1579
- }
1580
-
1581
- private triggerChange(selectedLis: Element[], event: MouseEvent): void {
1582
- this.trigger('change', { elements: selectedLis, items: this.getDataByElements(selectedLis), value: this.value, event: event });
1583
- }
1584
-
1585
- private getDataByElems(elems: Element[]): Object[] {
1586
- const data: Object[] = [];
1587
- for (let i: number = 0, len: number = elems.length; i < len; i++) {
1588
- data.push(this.getDataByValue(this.getFormattedValue(elems[i as number].getAttribute('data-value'))));
1589
- }
1590
- return data;
1591
- }
1592
- private getDataByElements(elems: Element[]): Object[] {
1593
-
1594
- const data: Object[] = []; let value: string | number | boolean; let sIdx: number = 0;
1595
- if (!isNullOrUndefined(this.listData)) {
1596
- const type: string = this.typeOfData(this.listData).typeof as string;
1597
- if (type === 'string' || type === 'number' || type === 'boolean') {
1598
- for (const item of this.listData) {
1599
- for (let i: number = sIdx, len: number = elems.length; i < len; i++) {
1600
- value = this.getFormattedValue((elems[i as number] as Element).getAttribute('data-value'));
1601
- if (!isNullOrUndefined(item) && item === value as Object) {
1602
- sIdx = i; data.push(item); break;
1603
- }
1604
- }
1605
- if (elems.length === data.length) {
1606
- break;
1607
- }
1608
- }
1609
- } else {
1610
- for (const item of this.listData) {
1611
- for (let i: number = sIdx, len: number = elems.length; i < len; i++) {
1612
- value = this.getFormattedValue((elems[i as number] as Element).getAttribute('data-value'));
1613
- if (!isNullOrUndefined(item) && getValue((this.fields.value ? this.fields.value : 'value'), item) === value) {
1614
- sIdx = i; data.push(item); break;
1615
- }
1616
- }
1617
- if (elems.length === data.length) {
1618
- break;
1619
- }
1620
- }
1621
- }
1622
- return data;
1623
- }
1624
- return null;
1625
- }
1626
- private checkMaxSelection(): InputObject | void {
1627
- const limit: number = this.list.querySelectorAll('.e-list-item span.e-check').length;
1628
- if (this.selectionSettings.showCheckbox) {
1629
- let index: number = 0;
1630
- const liCollElem: HTMLCollectionOf<HTMLLIElement> = this.list.getElementsByClassName('e-list-item') as HTMLCollectionOf<HTMLLIElement>;
1631
- for (index; index < liCollElem.length; index++) {
1632
- if (!liCollElem[index as number].querySelector('.e-frame.e-check')) {
1633
- if (limit === this.maximumSelectionLength) {
1634
- liCollElem[index as number].classList.add('e-disable');
1635
- } else if (liCollElem[index as number].classList.contains('e-disable')) {
1636
- liCollElem[index as number].classList.remove('e-disable');
1637
- }
1638
- }
1639
- }
1640
- }
1641
- }
1642
-
1643
- private toolbarClickHandler(e: MouseEvent): void {
1644
- const btn: Element = closest(e.target as Element, 'button');
1645
- if (btn) {
1646
- this.toolbarAction = btn.getAttribute('data-value');
1647
- if ((btn as HTMLButtonElement).disabled) {
1648
- return;
1649
- }
1650
- switch (this.toolbarAction) {
1651
- case 'moveUp':
1652
- this.moveUpDown(true);
1653
- break;
1654
- case 'moveDown':
1655
- this.moveUpDown();
1656
- break;
1657
- case 'moveTo':
1658
- this.moveItemTo();
1659
- break;
1660
- case 'moveFrom':
1661
- this.moveItemFrom();
1662
- break;
1663
- case 'moveAllTo':
1664
- this.moveAllItemTo();
1665
- break;
1666
- case 'moveAllFrom':
1667
- this.moveAllItemFrom();
1668
- break;
1669
- default:
1670
- this.trigger('actionBegin', { cancel: false, items: this.getDataByElems(this.getSelectedItems()),
1671
- eventName: this.toolbarAction });
1672
- break;
1673
- }
1674
- }
1675
- }
1676
-
1677
- private moveUpDown(isUp?: boolean, isKey?: boolean, value?: Element[], isTop?: boolean, isBottom?: boolean): void {
1678
- let elems: Element[] = this.getSelectedItems();
1679
- if (value) {
1680
- elems = value;
1681
- }
1682
- if (((isUp && this.isSelected(this.ulElement.firstElementChild))
1683
- || (!isUp && this.isSelected(this.ulElement.lastElementChild))) && !value ) {
1684
- return;
1685
- }
1686
- const tempItems: Object[] = this.getDataByElems(elems);
1687
- const localDataArgs: { [key: string]: Object } = { cancel: false, items: tempItems, eventName: this.toolbarAction };
1688
- this.trigger('actionBegin', localDataArgs);
1689
- if (localDataArgs.cancel) {
1690
- return;
1691
- }
1692
- (isUp ? elems : elems.reverse()).forEach((ele: Element) => {
1693
- const jsonToIdx: number = Array.prototype.indexOf.call(this.ulElement.querySelectorAll('.e-list-item'), ele);
1694
- const idx: number = Array.prototype.indexOf.call(this.ulElement.children, ele);
1695
- if (isTop) {
1696
- moveTo(this.ulElement, this.ulElement, [idx], 0);
1697
- this.changeData(idx, 0 , jsonToIdx, ele);
1698
- }
1699
- else if(isBottom) {
1700
- moveTo(this.ulElement, this.ulElement, [idx], this.ulElement.querySelectorAll('.e-list-item').length);
1701
- this.changeData(idx, this.ulElement.querySelectorAll('.e-list-item').length, jsonToIdx, ele);
1702
- }
1703
- else {
1704
- moveTo(this.ulElement, this.ulElement, [idx], isUp ? idx - 1 : idx + 2);
1705
- this.changeData(idx, isUp ? idx - 1 : idx + 1, isUp ? jsonToIdx - 1 : jsonToIdx + 1, ele);
1706
- }
1707
- });
1708
- this.trigger('actionComplete', { items: tempItems, eventName: this.toolbarAction });
1709
- (elems[0] as HTMLElement).focus();
1710
- if (!isKey && this.toolbarSettings.items.length) {
1711
- (this.getToolElem().querySelector('[data-value=' + (isUp ? 'moveUp' : 'moveDown') + ']') as HTMLElement).focus();
1712
- }
1713
- this.updateToolBarState();
1714
- }
1715
-
1716
- private moveItemTo(): void {
1717
- this.moveData(this, this.getScopedListBox());
1718
- }
1719
-
1720
- private moveItemFrom(): void {
1721
- this.moveData(this.getScopedListBox(), this);
1722
- }
1723
-
1724
- /**
1725
- * Called internally if any of the property value changed.
1726
- *
1727
- * @param {ListBox} fListBox - Specifies the from listbox.
1728
- * @param {ListBox} tListBox - Specifies the to listbox.
1729
- * @param {boolean} isKey - Specifies the key.
1730
- * @param {Element[]} value - Specifies the value.
1731
- * @param {number} index - Specifies the index.
1732
- * @returns {void}
1733
- * @private
1734
- */
1735
- private moveData(fListBox: ListBox, tListBox: ListBox, isKey?: boolean, value?: Element[], index?: number): void {
1736
- const idx: number[] = []; const dataIdx: number[] = []; const jsonIdx: number[] = []; const sortIdx: number[] = [];
1737
- const listData: dataType[] = [].slice.call(fListBox.listData); const tListData: dataType[] = [].slice.call(tListBox.listData);
1738
- const sortData: dataType[] = [].slice.call(fListBox.sortedData); let tSortData: dataType[] = [].slice.call(tListBox.sortedData);
1739
- const fliCollections: HTMLElement[] = [].slice.call(fListBox.liCollections); const dataLiIdx: number[] = [];
1740
- const tliCollections: HTMLElement[] = [].slice.call(tListBox.liCollections);
1741
- const tempItems: dataType[] = [];
1742
- const data: dataType[] = []; let elems: Element[] = fListBox.getSelectedItems();
1743
- if (value) {
1744
- elems = value;
1745
- }
1746
- const isRefresh: boolean | string | Function = tListBox.sortOrder !== 'None' || (tListBox.selectionSettings.showCheckbox !==
1747
- fListBox.selectionSettings.showCheckbox) || tListBox.fields.groupBy || tListBox.itemTemplate || fListBox.itemTemplate;
1748
- fListBox.value = [];
1749
- if (elems.length) {
1750
- this.removeSelected(fListBox, elems);
1751
- elems.forEach((ele: Element) => {
1752
- idx.push(Array.prototype.indexOf.call(fListBox.ulElement.children, ele)); // update sortable elem
1753
- // To update lb view data
1754
- dataLiIdx.push(Array.prototype.indexOf.call(fListBox.ulElement.querySelectorAll('.e-list-item'), ele));
1755
- // To update lb listdata data
1756
- dataIdx.push(Array.prototype.indexOf.call(fListBox.listData, fListBox.getDataByElems([ele])[0]));
1757
- // To update lb sorted data
1758
- sortIdx.push(Array.prototype.indexOf.call(fListBox.sortedData, fListBox.getDataByElems([ele])[0]));
1759
- // To update lb original data
1760
- jsonIdx.push(Array.prototype.indexOf.call(fListBox.jsonData, fListBox.getDataByElems([ele])[0]));
1761
- });
1762
- if (this.sortOrder !== 'None') {
1763
- sortIdx.forEach((i: number) => {
1764
- tempItems.push(fListBox.sortedData[i as number]);
1765
- });
1766
- } else {
1767
- jsonIdx.forEach((i: number) => {
1768
- tempItems.push(fListBox.jsonData[i as number]);
1769
- });
1770
- }
1771
- const localDataArgs: { [key: string]: Object } = { cancel: false, items: tempItems, eventName: this.toolbarAction };
1772
- fListBox.trigger('actionBegin', localDataArgs);
1773
- if (localDataArgs.cancel) {
1774
- return;
1775
- }
1776
- const rLiCollection: HTMLElement[] = [];
1777
- dataLiIdx.sort((n1: number, n2: number) => n1 - n2).reverse().forEach((i: number) => {
1778
- rLiCollection.push(fliCollections.splice(i, 1)[0]);
1779
- });
1780
- fListBox.liCollections = fliCollections;
1781
- if (index) {
1782
- const toColl: HTMLElement[] = tliCollections.splice(0, index);
1783
- tListBox.liCollections = toColl.concat(rLiCollection.reverse()).concat(tliCollections);
1784
- } else {
1785
- tListBox.liCollections = tliCollections.concat(rLiCollection.reverse());
1786
- }
1787
- if (tListBox.listData.length === 0) {
1788
- const noRecElem: Element = tListBox.ulElement.childNodes[0] as Element;
1789
- if (noRecElem) {
1790
- tListBox.ulElement.removeChild(noRecElem);
1791
- }
1792
- }
1793
- dataIdx.sort((n1: number, n2: number) => n2 - n1).forEach((i: number) => {
1794
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
1795
- listData.splice(i, 1)[0];
1796
- });
1797
- sortIdx.sort((n1: number, n2: number) => n2 - n1).forEach((i: number) => {
1798
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
1799
- sortData.splice(i, 1)[0];
1800
- });
1801
- jsonIdx.slice().reverse().forEach((i: number) => {
1802
- data.push(fListBox.jsonData.splice(i, 1)[0]);
1803
- });
1804
- if (isRefresh) {
1805
- if (fListBox.fields.groupBy) {
1806
- const sourceElem: HTMLElement = fListBox.renderItems(listData as obj[], fListBox.fields);
1807
- fListBox.updateListItems(sourceElem, fListBox.ulElement);
1808
- } else {
1809
- elems.forEach((ele: Element) => { detach(ele); });
1810
- }
1811
- } else {
1812
- moveTo(fListBox.ulElement, tListBox.ulElement, idx, index);
1813
- fListBox.trigger('actionComplete', { items: tempItems, eventName: this.toolbarAction });
1814
- }
1815
- if (tListBox.mainList.childElementCount !== tListBox.jsonData.length) {
1816
- tListBox.mainList = tListBox.ulElement;
1817
- }
1818
- fListBox.updateMainList();
1819
- const tJsonData: dataType[] = [].slice.call(tListBox.jsonData);
1820
- tSortData = [].slice.call(tListBox.sortedData);
1821
- this.selectNextList(elems, dataLiIdx, dataIdx, fListBox);
1822
- if (isKey) { this.list.focus(); }
1823
- (fListBox.listData as dataType[]) = listData;
1824
- (fListBox.sortedData as dataType[]) = sortData;
1825
- index = (index) ? index : tListData.length;
1826
- for (let i: number = tempItems.length - 1; i >= 0; i--) {
1827
- tListData.splice(index, 0, tempItems[i as number]);
1828
- tJsonData.splice(index, 0, tempItems[i as number]);
1829
- tSortData.splice(index, 0, tempItems[i as number]);
1830
- }
1831
- (tListBox.listData as dataType[]) = tListData;
1832
- tListBox.jsonData = tJsonData as {[key: string]: object}[];
1833
- tListBox.sortedData = tSortData as {[key: string]: object}[];
1834
- if (isRefresh) {
1835
- const sourceElem: HTMLElement = tListBox.renderItems(tListData as obj[], tListBox.fields);
1836
- tListBox.updateListItems(sourceElem, tListBox.ulElement);
1837
- tListBox.setSelection();
1838
- fListBox.trigger('actionComplete', { items: tempItems, eventName: this.toolbarAction });
1839
- }
1840
- fListBox.updateSelectedOptions();
1841
- if (fListBox.listData.length === 0) {
1842
- fListBox.l10nUpdate();
1843
- }
1844
- }
1845
- if (fListBox.value.length === 1 && fListBox.getSelectedItems().length) {
1846
- fListBox.value[0] = fListBox.getFormattedValue(fListBox.getSelectedItems()[0].getAttribute('data-value'));
1847
- }
1848
- }
1849
-
1850
- private selectNextList(elems: Element[], dataLiIdx: number[], dataIdx: number[], inst: ListBox): void {
1851
- const childCnt: number = inst.ulElement.querySelectorAll('.e-list-item').length;
1852
- let ele: Element; let liIdx: number;
1853
- let validIdx: number = -1;
1854
- if (elems.length === 1 && childCnt && !inst.selectionSettings.showCheckbox) {
1855
- liIdx = childCnt <= dataLiIdx[0] ? childCnt - 1 : dataLiIdx[0];
1856
- ele = inst.ulElement.querySelectorAll('.e-list-item')[liIdx as number];
1857
- validIdx = inst.getValidIndex(ele, liIdx, childCnt === dataIdx[0] ? 38 : 40);
1858
- if (validIdx > -1) {
1859
- (inst.ulElement.querySelectorAll('.e-list-item')[validIdx as number].classList.add(cssClass.selected));
1860
- }
1861
- }
1862
- }
1863
-
1864
- private moveAllItemTo(): void {
1865
- this.moveAllData(this, this.getScopedListBox());
1866
- }
1867
-
1868
- private moveAllItemFrom(): void {
1869
- this.moveAllData(this.getScopedListBox(), this);
1870
- }
1871
-
1872
- private moveAllData(fListBox: ListBox, tListBox: ListBox, isKey?: boolean, index?: number): void {
1873
- type sortedType = dataType | { isHeader: boolean };
1874
- let listData: dataType[] = [].slice.call(tListBox.listData);
1875
- const jsonData: {[key: string]: object}[] = [].slice.call(tListBox.jsonData);
1876
- const isRefresh: boolean | string | Function = tListBox.sortOrder !== 'None' || (tListBox.selectionSettings.showCheckbox !==
1877
- fListBox.selectionSettings.showCheckbox) || tListBox.fields.groupBy || tListBox.itemTemplate || fListBox.itemTemplate;
1878
- this.removeSelected(fListBox, fListBox.getSelectedItems());
1879
- const tempItems: Object[] = [].slice.call(fListBox.listData);
1880
- const localDataArgs: { [key: string]: Object } = { cancel: false, items: tempItems, eventName: this.toolbarAction };
1881
- fListBox.trigger('actionBegin', localDataArgs);
1882
- if (localDataArgs.cancel) {
1883
- return;
1884
- }
1885
- if (tListBox.listData.length === 0) {
1886
- const noRecElem: Element = tListBox.ulElement.childNodes[0] as Element;
1887
- if (noRecElem) {
1888
- tListBox.ulElement.removeChild(noRecElem);
1889
- }
1890
- }
1891
- if (isRefresh) {
1892
- const noRecElem: Element = fListBox.ulElement.childNodes[0] as Element;
1893
- if (noRecElem) {
1894
- fListBox.ulElement.removeChild(noRecElem);
1895
- }
1896
- }
1897
- moveTo(
1898
- fListBox.ulElement, tListBox.ulElement,
1899
- // eslint-disable-next-line prefer-spread
1900
- Array.apply(null, { length: fListBox.ulElement.childElementCount }).map(Number.call, Number), index);
1901
- this.trigger('actionComplete', { items: tempItems, eventName: this.toolbarAction });
1902
- if (isKey) { this.list.focus(); }
1903
- index = (index) ? index : listData.length;
1904
- for (let i: number = 0; i < fListBox.listData.length; i++) {
1905
- listData.splice(index + i, 0, fListBox.listData[i as number]);
1906
- }
1907
- for (let i: number = 0; i < fListBox.jsonData.length; i++) {
1908
- jsonData.splice(index + i, 0, fListBox.jsonData[i as number] as {[key: string]: object});
1909
- }
1910
- const fliCollections: HTMLElement[] = [].slice.call(fListBox.liCollections);
1911
- const tliCollections: HTMLElement[] = [].slice.call(tListBox.liCollections);
1912
- fListBox.liCollections = [];
1913
- if (index) {
1914
- const toColl: HTMLElement[] = tliCollections.splice(0, index);
1915
- tListBox.liCollections = toColl.concat(fliCollections).concat(tliCollections);
1916
- } else {
1917
- tListBox.liCollections = tliCollections.concat(fliCollections);
1918
- }
1919
- fListBox.value = [];
1920
- (listData as sortedType[]) = (listData as sortedType[])
1921
- .filter((data: sortedType) => (data as { isHeader: boolean }).isHeader !== true);
1922
- const sortedData: dataType[] = listData.filter(function(val: dataType): dataType {
1923
- return (tListBox.jsonData as dataType[]).indexOf(val) === -1;
1924
- });
1925
- for (let i: number = 0; i < sortedData.length; i++) {
1926
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1927
- tListBox.jsonData.splice(index + i, 0, sortedData[i as number] as any);
1928
- }
1929
- (tListBox.listData as dataType[]) = listData;
1930
- if (fListBox.listData.length === fListBox.jsonData.length) {
1931
- fListBox.listData = fListBox.sortedData = fListBox.jsonData = [];
1932
- } else if (fListBox.allowFiltering) {
1933
- for (let i: number = 0; i < fListBox.listData.length; i++) {
1934
- for (let j: number = 0; j < fListBox.jsonData.length; j++) {
1935
- if (fListBox.listData[i as number] === fListBox.jsonData[j as number]) {
1936
- fListBox.jsonData.splice(j, 1);
1937
- }
1938
- }
1939
- }
1940
- fListBox.listData = fListBox.sortedData = [];
1941
- }
1942
- if (isRefresh) {
1943
- const sourceElem: HTMLElement = tListBox.renderItems(listData as obj[], tListBox.fields);
1944
- tListBox.updateListItems(sourceElem, tListBox.ulElement);
1945
- this.trigger('actionComplete', { items: tempItems, eventName: this.toolbarAction });
1946
- } else {
1947
- (tListBox.sortedData as dataType[]) = listData;
1948
- }
1949
- fListBox.updateSelectedOptions();
1950
- if (fListBox.listData.length === 0) {
1951
- fListBox.l10nUpdate();
1952
- }
1953
- }
1954
-
1955
- private changeData(fromIdx: number, toIdx: number, jsonToIdx: number, ele: Element): void {
1956
- const listData: obj[] = [].slice.call(this.listData);
1957
- const jsonData: obj[] = [].slice.call(this.jsonData);
1958
- const sortData: obj[] = [].slice.call(this.sortedData);
1959
- const jsonIdx: number = Array.prototype.indexOf.call(this.jsonData, this.getDataByElems([ele])[0]);
1960
- const sortIdx: number = Array.prototype.indexOf.call(this.sortedData, this.getDataByElems([ele])[0]);
1961
- const liColl: HTMLElement[] = [].slice.call(this.liCollections);
1962
- listData.splice(toIdx, 0, listData.splice(fromIdx, 1)[0] as obj);
1963
- jsonData.splice(jsonToIdx, 0, jsonData.splice(jsonIdx, 1)[0] as obj);
1964
- sortData.splice(toIdx, 0, sortData.splice(sortIdx, 1)[0] as obj);
1965
- liColl.splice(toIdx, 0, liColl.splice(fromIdx, 1)[0] as HTMLElement);
1966
- this.listData = listData;
1967
- this.jsonData = jsonData;
1968
- this.liCollections = liColl;
1969
- this.sortedData = sortData;
1970
- }
1971
-
1972
- private getSelectedItems(): Element[] {
1973
- let ele: Element[] = [];
1974
- if (this.selectionSettings.showCheckbox) {
1975
- [].slice.call(this.ulElement.getElementsByClassName('e-check')).forEach((cbox: Element) => {
1976
- ele.push(closest(cbox, '.' + 'e-list-item'));
1977
- });
1978
- } else {
1979
- ele = [].slice.call(this.ulElement.getElementsByClassName(cssClass.selected));
1980
- }
1981
- return ele;
1982
- }
1983
-
1984
- private getScopedListBox(): ListBox {
1985
- let listObj: ListBox;
1986
- if (this.scope) {
1987
- [].slice.call(document.querySelectorAll(this.scope)).forEach((ele: Element) => {
1988
- if (getComponent(ele as HTMLElement, this.getModuleName())) {
1989
- listObj = getComponent(ele as HTMLElement, this.getModuleName());
1990
- }
1991
- });
1992
- }
1993
- return listObj;
1994
- }
1995
-
1996
- private getGrabbedItems(args: DragEventArgs): Element[] {
1997
- let grabbItems : boolean = false;
1998
- for (let i: number = 0; i < this.value.length; i++) {
1999
- if (this.value[i as number] === this.getFormattedValue(args.target.getAttribute('data-value')) as string) {
2000
- grabbItems = true;
2001
- break;
2002
- }
2003
- }
2004
- if (grabbItems) {
2005
- for (let i: number = 0; i < this.value.length; i++) {
2006
- const liColl: NodeListOf<Element> = this.list.querySelectorAll('[aria-selected="true"]');
2007
- for (let j: number = 0; j < liColl.length; j++) {
2008
- if (this.value[i as number] === this.getFormattedValue(liColl[j as number].getAttribute('data-value')) as string) {
2009
- liColl[j as number].classList.add('e-grabbed');
2010
- }
2011
- }
2012
- }
2013
- }
2014
- let elems: Element[];
2015
- if (this.isAngular) {
2016
- elems = Array.prototype.slice.call(this.element.getElementsByClassName('e-list-parent')[0].querySelectorAll('.e-grabbed'));
2017
- } else {
2018
- elems = Array.prototype.slice.call(this.element.nextElementSibling.querySelectorAll('.e-grabbed'));
2019
- }
2020
- return elems;
2021
- }
2022
-
2023
- private getDragArgs(args: DragEventArgs , isDragEnd?: boolean): DragEventArgs {
2024
- let elems: Element[] = this.getGrabbedItems(args);
2025
- if (elems.length) {
2026
- if (isDragEnd) {
2027
- elems.push(args.target);
2028
- }
2029
- } else {
2030
- elems = [args.target];
2031
- }
2032
- return { elements: elems, items: this.getDataByElems(elems) } as DragEventArgs;
2033
- }
2034
-
2035
- private onKeyDown(e: KeyboardEvent): void {
2036
- this.keyDownHandler(e);
2037
- e.stopPropagation();
2038
- }
2039
-
2040
- private keyDownStatus: boolean = false;
2041
-
2042
- private keyDownHandler(e: KeyboardEvent): void {
2043
- if ([32, 35, 36, 37, 38, 39, 40, 65].indexOf(e.keyCode) > -1 && (!this.allowFiltering ||
2044
- (this.allowFiltering && e.target !== this.filterInput))) {
2045
- if (e.target && (e.target as Element).className.indexOf('e-edit-template') > -1) {
2046
- return;
2047
- }
2048
- e.preventDefault();
2049
- if (e.keyCode === 32 && this.ulElement.children.length) {
2050
- this.selectHandler({
2051
- target: this.ulElement.getElementsByClassName('e-focused')[0],
2052
- ctrlKey: e.ctrlKey, shiftKey: e.shiftKey
2053
- });
2054
- } else if (e.keyCode === 65 && e.ctrlKey) {
2055
- this.selectAll();
2056
- } else if ((e.keyCode === 38 || e.keyCode === 40) && e.ctrlKey && e.shiftKey) {
2057
- this.moveUpDown(e.keyCode === 38 ? true : false, true);
2058
- } else if ((this.toolbarSettings.items.length || this.tBListBox) && (e.keyCode === 39 || e.keyCode === 37) && e.ctrlKey) {
2059
- const listObj: ListBox = this.tBListBox || this.getScopedListBox();
2060
- if (e.keyCode === 39) {
2061
- if (e.shiftKey) {
2062
- this.moveAllData(this, listObj, true);
2063
- } else {
2064
- this.moveData(this, listObj, true);
2065
- }
2066
- } else {
2067
- if (e.shiftKey) {
2068
- this.moveAllData(listObj, this, true);
2069
- } else {
2070
- this.moveData(listObj, this, true);
2071
- }
2072
- }
2073
- } else if (e.keyCode !== 37 && e.keyCode !== 39 && e.code !== 'KeyA') {
2074
- this.upDownKeyHandler(e);
2075
- }
2076
- } else if (this.allowFiltering) {
2077
- if (e.keyCode === 40 || e.keyCode === 38) {
2078
- this.upDownKeyHandler(e);
2079
- }
2080
- }
2081
- }
2082
-
2083
- private upDownKeyHandler(e: KeyboardEvent): void {
2084
- const ul: Element = this.ulElement;
2085
- const defaultIdx: number = (e.keyCode === 40 || e.keyCode === 36) ? 0 : ul.childElementCount - 1;
2086
- let fliIdx: number = defaultIdx;
2087
- const fli: Element = ul.getElementsByClassName('e-focused')[0] || ul.getElementsByClassName(cssClass.selected)[0];
2088
- if (fli) {
2089
- if (e.keyCode !== 35 && e.keyCode !== 36) {
2090
- fliIdx = Array.prototype.indexOf.call(ul.children, fli);
2091
- if (e.keyCode === 40) {
2092
- fliIdx++;
2093
- } else {
2094
- fliIdx--;
2095
- }
2096
- if (fliIdx < 0 || fliIdx > ul.childElementCount - 1) {
2097
- return;
2098
- }
2099
- }
2100
- removeClass([fli], 'e-focused');
2101
- }
2102
- const cli: Element = ul.children[fliIdx as number];
2103
- if (cli) {
2104
- fliIdx = this.getValidIndex(cli, fliIdx, e.keyCode);
2105
- if (fliIdx === -1) {
2106
- addClass([fli], 'e-focused');
2107
- return;
2108
- }
2109
- (ul.children[fliIdx as number] as HTMLElement).focus();
2110
- ul.children[fliIdx as number].classList.add('e-focused');
2111
- if (!e.ctrlKey || !this.selectionSettings.showCheckbox && e.shiftKey && (e.keyCode === 36 || e.keyCode === 35)) {
2112
- this.selectHandler({ target: ul.children[fliIdx as number], ctrlKey: e.ctrlKey, shiftKey: e.shiftKey }, true);
2113
- }
2114
- if (this.selectionSettings.showCheckbox && e.ctrlKey && e.shiftKey && (e.keyCode === 36 || e.keyCode === 35)) {
2115
- const selectedidx : number = Array.prototype.indexOf.call(ul.children, fli);
2116
- const sidx : number = e.code === 'Home' ? 0 : selectedidx;
2117
- const eidx : number = e.code === 'Home' ? selectedidx : ul.children.length - 1;
2118
- for (let i: number = sidx; i <= eidx; i++) {
2119
- const item: Element = ul.children[i as number];
2120
- this.notify('updatelist', { li: item, e: {
2121
- target: this.ulElement.getElementsByClassName('e-focused')[0],
2122
- ctrlKey: e.ctrlKey, shiftKey: e.shiftKey
2123
- }, module: 'listbox' });
2124
- }
2125
- }
2126
- }
2127
- }
2128
-
2129
- private KeyUp(e: KeyboardEvent): void {
2130
- if (this.allowFiltering && e.ctrlKey && e.keyCode === 65) {
2131
- e.preventDefault(); return;
2132
- }
2133
- const char: string = String.fromCharCode(e.keyCode);
2134
- const isWordCharacter: Object = char.match(/\w/);
2135
- if (!isNullOrUndefined(isWordCharacter)) {
2136
- this.isValidKey = true;
2137
- }
2138
- this.isValidKey = (e.keyCode === 8) || (e.keyCode === 46) || this.isValidKey;
2139
- if (this.isValidKey) {
2140
- this.isValidKey = false;
2141
- switch (e.keyCode) {
2142
- default:
2143
- if (this.allowFiltering) {
2144
- const eventArgsData: { [key: string]: Object } = {
2145
- preventDefaultAction: false,
2146
- text: this.targetElement(),
2147
- updateData: (
2148
- dataSource: {
2149
- [key: string]: Object
2150
- }[] | DataManager | string[] | number[], query?: Query, fields?: FieldSettingsModel) => {
2151
- if (eventArgsData.cancel) { return; }
2152
- this.isFiltered = true;
2153
- this.remoteFilterAction = true;
2154
- this.dataUpdater(dataSource, query, fields);
2155
- },
2156
- event: e,
2157
- cancel: false
2158
- };
2159
- this.trigger('filtering', eventArgsData, (args: FilteringEventArgs) => {
2160
- this.isDataFetched = false;
2161
- if (args.cancel || (this.filterInput.value !== '' && this.isFiltered)) {
2162
- return;
2163
- }
2164
- if (!args.cancel && !this.isCustomFiltering && !args.preventDefaultAction) {
2165
- this.inputString = this.filterInput.value;
2166
- this.filteringAction(this.jsonData, new Query(), this.fields);
2167
- }
2168
- if (!this.isFiltered && !this.isCustomFiltering && !args.preventDefaultAction) {
2169
- this.dataUpdater(this.jsonData, new Query(), this.fields);
2170
- }
2171
- });
2172
- }
2173
- }
2174
- }
2175
- }
2176
- /**
2177
- * To filter the data from given data source by using query.
2178
- *
2179
- * @param {Object[] | DataManager } dataSource - Set the data source to filter.
2180
- * @param {Query} query - Specify the query to filter the data.
2181
- * @param {FieldSettingsModel} fields - Specify the fields to map the column in the data table.
2182
- * @returns {void}.
2183
- */
2184
- public filter(
2185
- dataSource: { [key: string]: Object }[] | DataManager | string[] | number[] | boolean[],
2186
- query?: Query, fields?: FieldSettingsModel): void {
2187
- this.isCustomFiltering = true;
2188
- this.filteringAction(dataSource, query, fields);
2189
- }
2190
-
2191
- private filteringAction(
2192
- dataSource: { [key: string]: Object }[] | DataManager | string[] | number[] | boolean[],
2193
- query?: Query, fields?: FieldSettingsModel): void {
2194
- this.resetList(dataSource, fields, query);
2195
- }
2196
-
2197
-
2198
- protected targetElement(): string {
2199
- this.targetInputElement = this.list.getElementsByClassName('e-input-filter')[0] as HTMLInputElement;
2200
- return this.targetInputElement.value;
2201
- }
2202
-
2203
- private dataUpdater(
2204
- dataSource: { [key: string]: Object }[] | DataManager | string[] | number[] | boolean[],
2205
- query?: Query, fields?: FieldSettingsModel): void {
2206
- this.isDataFetched = false;
2207
- const backCommand: boolean = true;
2208
- if (this.targetElement().trim() === '') {
2209
- let list: HTMLElement = this.mainList.cloneNode ? <HTMLElement>this.mainList.cloneNode(true) : this.mainList;
2210
- if (backCommand) {
2211
- this.remoteCustomValue = false;
2212
- if (this.isAngular && this.itemTemplate) {
2213
- list = this.renderItems(this.listData as obj[], fields);
2214
- }
2215
- this.onActionComplete(list, this.jsonData as { [key: string]: Object }[] | string[] | number[] | boolean[]);
2216
- this.notify('reOrder', { module: 'CheckBoxSelection', enable: this.selectionSettings.showCheckbox, e: this });
2217
- }
2218
- } else {
2219
- this.resetList(dataSource, fields, query);
2220
- }
2221
- }
2222
-
2223
- private focusOutHandler(): void {
2224
- const ele: Element = this.list.getElementsByClassName('e-focused')[0];
2225
- if (ele) {
2226
- ele.classList.remove('e-focused');
2227
- }
2228
- if (this.allowFiltering) {
2229
- this.refreshClearIcon();
2230
- }
2231
- }
2232
-
2233
- private getValidIndex(cli: Element, index: number, keyCode: number): number {
2234
- const cul: Element = this.ulElement;
2235
- if (cli.classList.contains('e-disabled') || cli.classList.contains(cssClass.group)) {
2236
- if (keyCode === 40 || keyCode === 36) {
2237
- index++;
2238
- } else {
2239
- index--;
2240
- }
2241
- }
2242
- if (index < 0 || index === cul.childElementCount) {
2243
- return -1;
2244
- }
2245
- cli = (cul.childNodes as NodeListOf<Element>)[index as number];
2246
- if (cli.classList.contains('e-disabled') || cli.classList.contains(cssClass.group)) {
2247
- index = this.getValidIndex(cli, index, keyCode);
2248
- }
2249
- return index;
2250
- }
2251
-
2252
- private updateSelectedOptions(): void {
2253
- const selectedOptions: string[] = [];
2254
- const values: string[] = [];
2255
- extend(values, this.value as string[]);
2256
- this.getSelectedItems().forEach((ele: Element) => {
2257
- if (!ele.classList.contains('e-grabbed')) {
2258
- selectedOptions.push(this.getFormattedValue(ele.getAttribute('data-value')) as string);
2259
- }
2260
- });
2261
- if (this.mainList.childElementCount === this.ulElement.childElementCount) {
2262
- if (this.allowFiltering && this.selectionSettings.showCheckbox) {
2263
- for (let i: number = 0; i < selectedOptions.length; i++) {
2264
- if (values.indexOf(selectedOptions[i as number]) > -1) {
2265
- continue;
2266
- } else {
2267
- values.push(selectedOptions[i as number]);
2268
- }
2269
- }
2270
- this.setProperties({ value: values }, true);
2271
- } else {
2272
- this.setProperties({ value: selectedOptions }, true);
2273
- }
2274
-
2275
- }
2276
- this.updateSelectTag();
2277
- this.updateToolBarState();
2278
- if (this.tBListBox) {
2279
- this.tBListBox.updateToolBarState();
2280
- }
2281
- }
2282
-
2283
- private clearSelection(values: (string | number | boolean)[] = this.value): void {
2284
- if (this.selectionSettings.showCheckbox) {
2285
- let dvalue: string | number | boolean;
2286
- this.getSelectedItems().forEach((li: Element) => {
2287
- dvalue = this.getFormattedValue(li.getAttribute('data-value'));
2288
- if (values.indexOf(dvalue) < 0) {
2289
- li.getElementsByClassName('e-check')[0].classList.remove('e-check');
2290
- li.removeAttribute('aria-selected');
2291
- }
2292
- });
2293
- }
2294
- }
2295
-
2296
- private setSelection(
2297
- values: (string | boolean | number | object)[] = this.value, isSelect: boolean = true, isText: boolean = false): void {
2298
- let li: Element;
2299
- let liselect: boolean;
2300
- if (values) {
2301
- values.forEach((value: string) => {
2302
- let text: string | number | boolean;
2303
- if (isText) {
2304
- text = this.getValueByText(value);
2305
- } else {
2306
- text = value;
2307
- }
2308
- if (typeof(text) === 'string') {
2309
- text = text.split('\\').join('\\\\');
2310
- li = this.list.querySelector('[data-value="' + text.replace(/"/g, '\\"') + '"]');
2311
- } else {
2312
- li = this.list.querySelector('[data-value="' + text + '"]');
2313
- }
2314
- if (li) {
2315
- if (this.selectionSettings.showCheckbox) {
2316
- liselect = li.getElementsByClassName('e-frame')[0].classList.contains('e-check');
2317
- } else {
2318
- liselect = li.classList.contains('e-selected');
2319
- }
2320
- if (!isSelect && liselect || isSelect && !liselect && li) {
2321
- if (this.selectionSettings.showCheckbox) {
2322
- this.notify('updatelist', { li: li, module: 'listbox' });
2323
- (li as HTMLElement).focus();
2324
- } else {
2325
- if (isSelect) {
2326
- li.classList.add(cssClass.selected);
2327
- li.setAttribute('aria-selected', 'true');
2328
- (li as HTMLElement).focus();
2329
- } else {
2330
- li.classList.remove(cssClass.selected);
2331
- li.removeAttribute('aria-selected');
2332
- }
2333
- }
2334
- }
2335
- }
2336
- });
2337
- }
2338
- this.updateSelectTag();
2339
- }
2340
-
2341
- private updateSelectTag(): void {
2342
- const ele: Element = this.getSelectTag(); let innerHTML: string = '';
2343
- ele.innerHTML = '';
2344
- if (this.value) {
2345
- for (let i: number = 0, len: number = this.value.length; i < len; i++) {
2346
- innerHTML += '<option selected>' + this.value[i as number] + '</option>';
2347
- }
2348
- ele.innerHTML += innerHTML;
2349
- for (let i: number = 0, len: number = ele.childNodes.length; i < len; i++) {
2350
- (ele.childNodes[i as number] as HTMLElement).setAttribute('value', this.value[i as number].toString());
2351
- }
2352
- }
2353
- this.checkSelectAll();
2354
- }
2355
-
2356
- private checkDisabledState(inst: ListBox): boolean {
2357
- return inst.ulElement.querySelectorAll('.' + cssClass.li).length === 0;
2358
- }
2359
-
2360
- private updateToolBarState(): void {
2361
- if (this.toolbarSettings.items.length) {
2362
- const listObj: ListBox = this.getScopedListBox();
2363
- const wrap: Element = this.list.parentElement.getElementsByClassName('e-listbox-tool')[0];
2364
- this.toolbarSettings.items.forEach((value: string) => {
2365
- const btn: HTMLButtonElement = wrap.querySelector('[data-value="' + value + '"]');
2366
- switch (value) {
2367
- case 'moveAllTo':
2368
- btn.disabled = this.checkDisabledState(this);
2369
- break;
2370
- case 'moveAllFrom':
2371
- btn.disabled = this.checkDisabledState(listObj);
2372
- break;
2373
- case 'moveFrom':
2374
- btn.disabled = listObj.value && listObj.value.length ? false : true;
2375
- break;
2376
- case 'moveUp':
2377
- btn.disabled = this.value && this.value.length
2378
- && !this.isSelected(this.ulElement.children[0]) ? false : true;
2379
- break;
2380
- case 'moveDown':
2381
- btn.disabled = this.value && this.value.length
2382
- && !this.isSelected(this.ulElement.children[this.ulElement.childElementCount - 1]) ? false : true;
2383
- break;
2384
- default:
2385
- btn.disabled = this.value && this.value.length ? false : true;
2386
- break;
2387
- }
2388
- });
2389
- }
2390
- }
2391
-
2392
- private setCheckboxPosition(): void {
2393
- const listWrap: HTMLElement = this.list;
2394
- if (!this.initLoad && this.selectionSettings.checkboxPosition === 'Left') {
2395
- listWrap.classList.remove('e-right');
2396
- }
2397
- if (this.selectionSettings.checkboxPosition === 'Right') {
2398
- listWrap.classList.add('e-right');
2399
- }
2400
- }
2401
-
2402
- private showCheckbox(showCheckbox: boolean): void {
2403
- let index: number = 0;
2404
- const liColl: NodeListOf<Element> = this.list.lastElementChild.querySelectorAll('li');
2405
- const liCollLen: number = this.list.lastElementChild.getElementsByClassName('e-list-item').length;
2406
- if (showCheckbox) {
2407
- this.ulElement = this.renderItems(this.listData as obj[], this.fields);
2408
- this.mainList = this.ulElement;
2409
- this.list.removeChild(this.list.getElementsByTagName('ul')[0]);
2410
- this.list.appendChild(this.ulElement);
2411
- if (this.selectionSettings.showSelectAll && !this.list.getElementsByClassName('e-selectall-parent')[0]) {
2412
- const l10nShow: L10n = new L10n(
2413
- this.getModuleName(), { selectAllText: 'Select All', unSelectAllText: 'Unselect All' }, this.locale);
2414
- this.showSelectAll = true;
2415
- this.selectAllText = l10nShow.getConstant('selectAllText');
2416
- this.unSelectAllText = l10nShow.getConstant('unSelectAllText');
2417
- this.popupWrapper = this.list;
2418
- this.checkBoxSelectionModule.checkAllParent = null;
2419
- this.notify('selectAll', {});
2420
- this.checkSelectAll();
2421
- }
2422
- } else {
2423
- if (this.list.getElementsByClassName('e-selectall-parent')[0]) {
2424
- this.list.removeChild(this.list.getElementsByClassName('e-selectall-parent')[0]);
2425
- }
2426
- for (index; index < liCollLen; index++) {
2427
- if (liColl[index as number].classList.contains('e-list-item')) {
2428
- liColl[index as number].removeChild(liColl[index as number].getElementsByClassName('e-checkbox-wrapper')[0]);
2429
- }
2430
- if (liColl[index as number].hasAttribute('aria-selected')) {
2431
- liColl[index as number].removeAttribute('aria-selected');
2432
- }
2433
- }
2434
- this.mainList = this.ulElement;
2435
- }
2436
- this.value = [];
2437
- }
2438
-
2439
- private isSelected(ele: Element): boolean {
2440
- if (!isNullOrUndefined(ele)) {
2441
- return ele.classList.contains(cssClass.selected) || ele.querySelector('.e-check') !== null;
2442
- } else {
2443
- return false;
2444
- }
2445
- }
2446
-
2447
- private getSelectTag(): Element {
2448
- return this.list.getElementsByClassName('e-hidden-select')[0];
2449
- }
2450
-
2451
- private getToolElem(): Element {
2452
- return this.list.parentElement.getElementsByClassName('e-listbox-tool')[0];
2453
- }
2454
-
2455
- private formResetHandler(): void {
2456
- this.value = this.initialSelectedOptions;
2457
- }
2458
-
2459
- /**
2460
- * Return the module name.
2461
- *
2462
- * @private
2463
- * @returns {string} - Module name
2464
- */
2465
- public getModuleName(): string {
2466
- return 'listbox';
2467
- }
2468
-
2469
- /**
2470
- * Get the properties to be maintained in the persisted state.
2471
- *
2472
- * @returns {string} - Persist data
2473
- */
2474
- protected getPersistData(): string {
2475
- return this.addOnPersist(['value']);
2476
- }
2477
-
2478
- protected getLocaleName(): string {
2479
- return 'listbox';
2480
- }
2481
-
2482
- public destroy(): void {
2483
- this.unwireEvents();
2484
- if (this.element.tagName === 'EJS-LISTBOX') {
2485
- this.element.innerHTML = '';
2486
- } else {
2487
- this.element.style.display = 'inline-block';
2488
- if (this.toolbarSettings.items.length) {
2489
- this.list.parentElement.parentElement.insertBefore(this.list, this.list.parentElement);
2490
- detach(this.list.nextElementSibling);
2491
- }
2492
- this.list.parentElement.insertBefore(this.element, this.list);
2493
- }
2494
- super.destroy();
2495
- this.enableRtlElements = []; this.liCollections = null; this.list = null; this.ulElement = null;
2496
- this.mainList = null; this.spinner = null; this.rippleFun = null;
2497
- if (this.itemTemplate) { this.clearTemplate(); }
2498
- }
2499
-
2500
- /**
2501
- * Called internally if any of the property value changed.
2502
- *
2503
- * @param {ListBoxModel} newProp - Specifies the new properties.
2504
- * @param {ListBoxModel} oldProp - Specifies the old properties.
2505
- * @returns {void}
2506
- * @private
2507
- */
2508
- public onPropertyChanged(newProp: ListBoxModel, oldProp: ListBoxModel): void {
2509
- const wrap: Element = this.toolbarSettings.items.length ? this.list.parentElement : this.list;
2510
- super.onPropertyChanged(newProp, oldProp);
2511
- this.setUpdateInitial(['fields', 'query', 'dataSource'], newProp as { [key: string]: string; });
2512
- for (const prop of Object.keys(newProp)) {
2513
- switch (prop) {
2514
- case 'cssClass':
2515
- if (oldProp.cssClass) {
2516
- removeClass([wrap], oldProp.cssClass.split(' '));
2517
- }
2518
- if (newProp.cssClass) {
2519
- addClass([wrap], newProp.cssClass.replace(/\s+/g, ' ').trim().split(' '));
2520
- }
2521
- break;
2522
- case 'enableRtl':
2523
- if (newProp.enableRtl) {
2524
- this.list.classList.add('e-rtl');
2525
- } else {
2526
- this.list.classList.remove('e-rtl');
2527
- }
2528
- break;
2529
- case 'value':
2530
- removeClass(this.list.querySelectorAll('.' + cssClass.selected), cssClass.selected);
2531
- this.clearSelection(this.value);
2532
- this.setSelection();
2533
- break;
2534
- case 'height':
2535
- this.setHeight();
2536
- break;
2537
- case 'enabled':
2538
- this.setEnable();
2539
- break;
2540
- case 'allowDragAndDrop':
2541
- if (newProp.allowDragAndDrop) {
2542
- this.initDraggable();
2543
- } else {
2544
- (getComponent(this.ulElement, 'sortable') as Sortable).destroy();
2545
- }
2546
- break;
2547
- case 'allowFiltering':
2548
- if (this.allowFiltering) {
2549
- this.setFiltering();
2550
- } else {
2551
- this.list.removeChild(this.list.getElementsByClassName('e-filter-parent')[0]);
2552
- this.filterParent = null;
2553
- removeClass([this.list], 'e-filter-list');
2554
- }
2555
- break;
2556
- case 'filterBarPlaceholder':
2557
- if (this.allowFiltering) {
2558
- if (this.filterInput) { Input.setPlaceholder(newProp.filterBarPlaceholder, this.filterInput as HTMLInputElement); }
2559
- }
2560
- break;
2561
- case 'scope':
2562
- if (this.allowDragAndDrop) {
2563
- (getComponent(this.ulElement, 'sortable') as Sortable).scope = newProp.scope;
2564
- }
2565
- if (this.toolbarSettings.items.length) {
2566
- if (oldProp.scope) {
2567
- (getComponent(document.querySelector(oldProp.scope) as HTMLElement, this.getModuleName()) as ListBox)
2568
- .tBListBox = null;
2569
- }
2570
- if (newProp.scope) {
2571
- (getComponent(document.querySelector(newProp.scope) as HTMLElement, this.getModuleName()) as ListBox)
2572
- .tBListBox = this;
2573
- }
2574
- }
2575
- break;
2576
- case 'toolbarSettings': {
2577
- let ele: Element;
2578
- const pos: string = newProp.toolbarSettings.position;
2579
- const toolElem: Element = this.getToolElem();
2580
- if (pos) {
2581
- removeClass([wrap], ['e-right', 'e-left']);
2582
- wrap.classList.add('e-' + pos.toLowerCase());
2583
- if (pos === 'Left') {
2584
- wrap.insertBefore(toolElem, this.list);
2585
- } else {
2586
- wrap.appendChild(toolElem);
2587
- }
2588
- }
2589
- if (newProp.toolbarSettings.items) {
2590
- if (oldProp.toolbarSettings && oldProp.toolbarSettings.items.length) {
2591
- ele = this.list.parentElement;
2592
- ele.parentElement.insertBefore(this.list, ele);
2593
- detach(ele);
2594
- }
2595
- this.initToolbarAndStyles();
2596
- this.wireToolbarEvent();
2597
- }
2598
- break;
2599
- }
2600
- case 'selectionSettings': {
2601
- const showSelectAll: boolean = newProp.selectionSettings.showSelectAll;
2602
- const showCheckbox: boolean = newProp.selectionSettings.showCheckbox;
2603
- if (!isNullOrUndefined(showSelectAll)) {
2604
- this.showSelectAll = showSelectAll;
2605
- if (this.showSelectAll) {
2606
- const l10nSel: L10n = new L10n(
2607
- this.getModuleName(), { selectAllText: 'Select All', unSelectAllText: 'Unselect All' }, this.locale);
2608
- this.checkBoxSelectionModule.checkAllParent = null;
2609
- this.showSelectAll = true;
2610
- this.selectAllText = l10nSel.getConstant('selectAllText');
2611
- this.unSelectAllText = l10nSel.getConstant('selectAllText');
2612
- this.popupWrapper = this.list;
2613
- }
2614
- this.notify('selectAll', {});
2615
- this.checkSelectAll();
2616
- }
2617
- if (!isNullOrUndefined(showCheckbox)) {
2618
- this.showCheckbox(showCheckbox);
2619
- }
2620
- if (this.selectionSettings.showCheckbox) {
2621
- this.setCheckboxPosition();
2622
- }
2623
- break;
2624
- }
2625
- case 'dataSource':
2626
- this.isDataSourceUpdate = true;
2627
- this.jsonData = [].slice.call(this.dataSource);
2628
- break;
2629
- }
2630
- }
2631
- }
2632
- }
2633
-
2634
- /**
2635
- * Interface for before item render event.
2636
- */
2637
- export interface BeforeItemRenderEventArgs extends BaseEventArgs {
2638
- /**
2639
- * Returns the list element before rendering.
2640
- */
2641
- element: Element;
2642
- /**
2643
- * Returns the list item before rendering.
2644
- */
2645
- item: { [key: string]: Object };
2646
- }
2647
-
2648
- /**
2649
- * Interface for drag and drop event args.
2650
- */
2651
- export interface SourceDestinationModel {
2652
- /**
2653
- * Specifies the list items before drag or drop in the ListBox.
2654
- */
2655
- previousData?: string[] | boolean[] | number[] | { [key: string]: Object; }[] | DataManager;
2656
- /**
2657
- * Specifies the list items after drag or drop in the ListBox.
2658
- */
2659
- currentData?: string[] | boolean[] | number[] | { [key: string]: Object; }[] | DataManager;
2660
- }
2661
-
2662
- /**
2663
- * Interface for drag and drop event.
2664
- */
2665
- export interface DragEventArgs {
2666
- /**
2667
- * Returns the previous index of the selected list item.
2668
- */
2669
- previousIndex?: number;
2670
- /**
2671
- * Returns the current index of the selected list item.
2672
- */
2673
- currentIndex?: number;
2674
- /**
2675
- * Returns the selected list element.
2676
- */
2677
- elements: Element[];
2678
- /**
2679
- * Returns the selected list items.
2680
- */
2681
- items: Object[];
2682
- /**
2683
- * Returns the target list element where the selected list element to be dropped.
2684
- */
2685
- target?: Element;
2686
- /**
2687
- * Returns true if the list element is dragged from ListBox. Otherwise, it remains false.
2688
- */
2689
- dragSelected?: boolean;
2690
- /**
2691
- * Returns the previous list item.
2692
- */
2693
- previousItem?: object[];
2694
- /**
2695
- * Returns the previous and current list items of the source list box.
2696
- */
2697
- source?: SourceDestinationModel;
2698
- /**
2699
- * Returns the previous and current list items of the destination list box.
2700
- */
2701
- destination?: SourceDestinationModel;
2702
- }
2703
-
2704
- /**
2705
- * Interface for change event args.
2706
- */
2707
- export interface ListBoxChangeEventArgs extends BaseEventArgs {
2708
- /**
2709
- * Returns the selected list elements.
2710
- */
2711
- elements: Element[];
2712
- /**
2713
- * Returns the selected list items.
2714
- */
2715
- items: Object[];
2716
- /**
2717
- * Returns the selected state or selected list item in the ListBox.
2718
- */
2719
- value: number | string | boolean;
2720
- /**
2721
- * Specifies the event.
2722
- */
2723
- event: Event;
2724
- }
2725
-
2726
- /**
2727
- * Interface for Drop event args.
2728
- */
2729
- export interface DropEventArgs {
2730
- /**
2731
- * Returns the previous index of the selected list item.
2732
- */
2733
- previousIndex: number;
2734
- /**
2735
- * Returns the current index of the selected list item.
2736
- */
2737
- currentIndex: number;
2738
- /**
2739
- * Returns the selected list element to be dropped.
2740
- */
2741
- droppedElement: Element;
2742
- /**
2743
- * Returns the target list element where the selected list element to be dropped.
2744
- */
2745
- target: Element;
2746
- /**
2747
- * Returns the dragged list element.
2748
- */
2749
- helper: Element;
2750
- /**
2751
- * Illustrates whether the current action needs to be prevented or not.
2752
- */
2753
- cancel?: boolean;
2754
- /**
2755
- * Returns the selected list items.
2756
- */
2757
- items?: Object[];
2758
- }
2759
- interface ListBoxClassList {
2760
- backIcon: string;
2761
- filterBarClearIcon: string;
2762
- filterInput: string;
2763
- filterParent: string;
2764
- clearIcon: string;
2765
- }
2766
- const listBoxClasses: ListBoxClassList = {
2767
- backIcon: 'e-input-group-icon e-back-icon e-icons',
2768
- filterBarClearIcon: 'e-input-group-icon e-clear-icon e-icons',
2769
- filterInput: 'e-input-filter',
2770
- filterParent: 'e-filter-parent',
2771
- clearIcon: 'e-clear-icon'
2772
- };