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