@syncfusion/ej2-filemanager 29.2.10 → 30.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/.eslintrc.json +2 -0
  2. package/dist/ej2-filemanager.min.js +2 -2
  3. package/dist/ej2-filemanager.umd.min.js +2 -2
  4. package/dist/ej2-filemanager.umd.min.js.map +1 -1
  5. package/dist/es6/ej2-filemanager.es2015.js +179 -20
  6. package/dist/es6/ej2-filemanager.es2015.js.map +1 -1
  7. package/dist/es6/ej2-filemanager.es5.js +180 -20
  8. package/dist/es6/ej2-filemanager.es5.js.map +1 -1
  9. package/dist/global/ej2-filemanager.min.js +2 -2
  10. package/dist/global/ej2-filemanager.min.js.map +1 -1
  11. package/dist/global/index.d.ts +1 -1
  12. package/dist/ts/file-manager/actions/breadcrumb-bar.d.ts +60 -0
  13. package/dist/ts/file-manager/actions/breadcrumb-bar.ts +423 -0
  14. package/dist/ts/file-manager/actions/index.d.ts +6 -0
  15. package/dist/ts/file-manager/actions/index.ts +6 -0
  16. package/dist/ts/file-manager/actions/toolbar.d.ts +54 -0
  17. package/dist/ts/file-manager/actions/toolbar.ts +609 -0
  18. package/dist/ts/file-manager/actions/virtualization.d.ts +93 -0
  19. package/dist/ts/file-manager/actions/virtualization.ts +324 -0
  20. package/dist/ts/file-manager/base/classes.d.ts +224 -0
  21. package/dist/ts/file-manager/base/classes.ts +225 -0
  22. package/dist/ts/file-manager/base/constant.d.ts +136 -0
  23. package/dist/ts/file-manager/base/constant.ts +137 -0
  24. package/dist/ts/file-manager/base/file-manager-model.d.ts +520 -0
  25. package/dist/ts/file-manager/base/file-manager.d.ts +867 -0
  26. package/dist/ts/file-manager/base/file-manager.ts +2061 -0
  27. package/dist/ts/file-manager/base/index.d.ts +8 -0
  28. package/dist/ts/file-manager/base/index.ts +8 -0
  29. package/dist/ts/file-manager/base/interface.d.ts +952 -0
  30. package/dist/ts/file-manager/base/interface.ts +931 -0
  31. package/dist/ts/file-manager/common/index.d.ts +5 -0
  32. package/dist/ts/file-manager/common/index.ts +5 -0
  33. package/dist/ts/file-manager/common/operations.d.ts +122 -0
  34. package/dist/ts/file-manager/common/operations.ts +1369 -0
  35. package/dist/ts/file-manager/common/utility.d.ts +644 -0
  36. package/dist/ts/file-manager/common/utility.ts +1728 -0
  37. package/dist/ts/file-manager/index.d.ts +9 -0
  38. package/dist/ts/file-manager/index.ts +9 -0
  39. package/dist/ts/file-manager/layout/details-view.d.ts +152 -0
  40. package/dist/ts/file-manager/layout/details-view.ts +1990 -0
  41. package/dist/ts/file-manager/layout/index.d.ts +6 -0
  42. package/dist/ts/file-manager/layout/index.ts +6 -0
  43. package/dist/ts/file-manager/layout/large-icons-view.d.ts +157 -0
  44. package/dist/ts/file-manager/layout/large-icons-view.ts +1684 -0
  45. package/dist/ts/file-manager/layout/navigation-pane.d.ts +104 -0
  46. package/dist/ts/file-manager/layout/navigation-pane.ts +919 -0
  47. package/dist/ts/file-manager/models/ajax-settings-model.d.ts +36 -0
  48. package/dist/ts/file-manager/models/ajax-settings.d.ts +30 -0
  49. package/dist/ts/file-manager/models/ajax-settings.ts +39 -0
  50. package/dist/ts/file-manager/models/column-model.d.ts +155 -0
  51. package/dist/ts/file-manager/models/column.d.ts +179 -0
  52. package/dist/ts/file-manager/models/column.ts +216 -0
  53. package/dist/ts/file-manager/models/contextMenu-settings-model.d.ts +36 -0
  54. package/dist/ts/file-manager/models/contextMenu-settings.d.ts +33 -0
  55. package/dist/ts/file-manager/models/contextMenu-settings.ts +44 -0
  56. package/dist/ts/file-manager/models/default-locale.d.ts +4 -0
  57. package/dist/ts/file-manager/models/default-locale.ts +101 -0
  58. package/dist/ts/file-manager/models/details-view-settings-model.d.ts +30 -0
  59. package/dist/ts/file-manager/models/details-view-settings.d.ts +31 -0
  60. package/dist/ts/file-manager/models/details-view-settings.ts +54 -0
  61. package/dist/ts/file-manager/models/index.d.ts +19 -0
  62. package/dist/ts/file-manager/models/index.ts +19 -0
  63. package/dist/ts/file-manager/models/navigation-pane-settings-model.d.ts +40 -0
  64. package/dist/ts/file-manager/models/navigation-pane-settings.d.ts +34 -0
  65. package/dist/ts/file-manager/models/navigation-pane-settings.ts +42 -0
  66. package/dist/ts/file-manager/models/search-settings-model.d.ts +42 -0
  67. package/dist/ts/file-manager/models/search-settings.d.ts +44 -0
  68. package/dist/ts/file-manager/models/search-settings.ts +53 -0
  69. package/dist/ts/file-manager/models/toolbar-settings-model.d.ts +197 -0
  70. package/dist/ts/file-manager/models/toolbar-settings.d.ts +174 -0
  71. package/dist/ts/file-manager/models/toolbar-settings.ts +198 -0
  72. package/dist/ts/file-manager/models/upload-settings-model.d.ts +70 -0
  73. package/dist/ts/file-manager/models/upload-settings.d.ts +61 -0
  74. package/dist/ts/file-manager/models/upload-settings.ts +75 -0
  75. package/dist/ts/file-manager/pop-up/context-menu.d.ts +64 -0
  76. package/dist/ts/file-manager/pop-up/context-menu.ts +693 -0
  77. package/dist/ts/file-manager/pop-up/dialog.d.ts +31 -0
  78. package/dist/ts/file-manager/pop-up/dialog.ts +1009 -0
  79. package/dist/ts/file-manager/pop-up/index.d.ts +5 -0
  80. package/dist/ts/file-manager/pop-up/index.ts +5 -0
  81. package/dist/ts/index.d.ts +4 -0
  82. package/dist/ts/index.ts +4 -0
  83. package/package.json +56 -21
  84. package/src/file-manager/base/interface.d.ts +10 -0
  85. package/src/file-manager/common/operations.d.ts +18 -1
  86. package/src/file-manager/common/operations.js +59 -0
  87. package/src/file-manager/common/utility.d.ts +3 -3
  88. package/src/file-manager/common/utility.js +20 -6
  89. package/src/file-manager/layout/details-view.js +4 -3
  90. package/src/file-manager/layout/large-icons-view.d.ts +3 -0
  91. package/src/file-manager/layout/large-icons-view.js +67 -9
  92. package/src/file-manager/pop-up/dialog.d.ts +3 -3
  93. package/src/file-manager/pop-up/dialog.js +34 -6
  94. package/styles/bds-lite.css +51 -1
  95. package/styles/bds.css +51 -1
  96. package/styles/bootstrap-dark-lite.css +51 -0
  97. package/styles/bootstrap-dark.css +51 -0
  98. package/styles/bootstrap-lite.css +51 -0
  99. package/styles/bootstrap.css +51 -0
  100. package/styles/bootstrap4-lite.css +51 -0
  101. package/styles/bootstrap4.css +51 -0
  102. package/styles/bootstrap5-dark-lite.css +51 -1
  103. package/styles/bootstrap5-dark.css +51 -1
  104. package/styles/bootstrap5-lite.css +51 -1
  105. package/styles/bootstrap5.3-lite.css +51 -0
  106. package/styles/bootstrap5.3.css +51 -0
  107. package/styles/bootstrap5.css +51 -1
  108. package/styles/fabric-dark-lite.css +51 -0
  109. package/styles/fabric-dark.css +51 -0
  110. package/styles/fabric-lite.css +51 -0
  111. package/styles/fabric.css +51 -0
  112. package/styles/file-manager/_bds-definition.scss +1 -0
  113. package/styles/file-manager/_bootstrap5-definition.scss +1 -0
  114. package/styles/file-manager/_layout.scss +46 -4
  115. package/styles/file-manager/_material3-definition.scss +2 -2
  116. package/styles/file-manager/_tailwind-definition.scss +1 -0
  117. package/styles/file-manager/_tailwind3-definition.scss +1 -0
  118. package/styles/file-manager/bds.css +51 -1
  119. package/styles/file-manager/bootstrap-dark.css +51 -0
  120. package/styles/file-manager/bootstrap.css +51 -0
  121. package/styles/file-manager/bootstrap4.css +51 -0
  122. package/styles/file-manager/bootstrap5-dark.css +51 -1
  123. package/styles/file-manager/bootstrap5.3.css +51 -0
  124. package/styles/file-manager/bootstrap5.css +51 -1
  125. package/styles/file-manager/fabric-dark.css +51 -0
  126. package/styles/file-manager/fabric.css +51 -0
  127. package/styles/file-manager/fluent-dark.css +51 -0
  128. package/styles/file-manager/fluent.css +51 -0
  129. package/styles/file-manager/fluent2.css +51 -0
  130. package/styles/file-manager/highcontrast-light.css +51 -0
  131. package/styles/file-manager/highcontrast.css +51 -0
  132. package/styles/file-manager/material-dark.css +51 -0
  133. package/styles/file-manager/material.css +51 -0
  134. package/styles/file-manager/material3-dark.css +53 -2
  135. package/styles/file-manager/material3.css +53 -2
  136. package/styles/file-manager/tailwind-dark.css +51 -1
  137. package/styles/file-manager/tailwind.css +51 -1
  138. package/styles/file-manager/tailwind3.css +51 -0
  139. package/styles/fluent-dark-lite.css +51 -0
  140. package/styles/fluent-dark.css +51 -0
  141. package/styles/fluent-lite.css +51 -0
  142. package/styles/fluent.css +51 -0
  143. package/styles/fluent2-lite.css +51 -0
  144. package/styles/fluent2.css +51 -0
  145. package/styles/highcontrast-light-lite.css +51 -0
  146. package/styles/highcontrast-light.css +51 -0
  147. package/styles/highcontrast-lite.css +51 -0
  148. package/styles/highcontrast.css +51 -0
  149. package/styles/material-dark-lite.css +51 -0
  150. package/styles/material-dark.css +51 -0
  151. package/styles/material-lite.css +51 -0
  152. package/styles/material.css +51 -0
  153. package/styles/material3-dark-lite.css +51 -0
  154. package/styles/material3-dark.css +53 -2
  155. package/styles/material3-lite.css +51 -0
  156. package/styles/material3.css +53 -2
  157. package/styles/tailwind-dark-lite.css +51 -1
  158. package/styles/tailwind-dark.css +51 -1
  159. package/styles/tailwind-lite.css +51 -1
  160. package/styles/tailwind.css +51 -1
  161. package/styles/tailwind3-lite.css +51 -0
  162. package/styles/tailwind3.css +51 -0
@@ -0,0 +1,609 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { Toolbar as BaseToolbar, ItemModel, ClickEventArgs, MenuEventArgs, DisplayMode } from '@syncfusion/ej2-navigations';
3
+ import { select, isNullOrUndefined as isNOU, closest, selectAll } from '@syncfusion/ej2-base';
4
+ import { createDialog } from '../pop-up/dialog';
5
+ import * as events from '../base/constant';
6
+ import * as CLS from '../base/classes';
7
+ import { IFileManager, NotifyArgs, ToolbarClickEventArgs, ToolbarCreateEventArgs } from '../base/interface';
8
+ import { refresh, getPathObject, getLocaleText, getCssClass, sortbyClickHandler } from '../common/utility';
9
+ import { createDeniedDialog, updateLayout } from '../common/utility';
10
+ import { GetDetails } from '../common/operations';
11
+ import { DropDownButton, ItemModel as SplitButtonItemModel } from '@syncfusion/ej2-splitbuttons';
12
+ import { cutFiles, copyFiles, pasteHandler, hasEditAccess } from '../common/index';
13
+ import { doDownload, createNewFolder, uploadItem } from '../common/index';
14
+ import { ToolbarItem, ToolbarItemModel } from '../models';
15
+
16
+ /**
17
+ * Toolbar module
18
+ */
19
+ export class Toolbar {
20
+
21
+ /* Internal variables */
22
+ private parent: IFileManager;
23
+ private items: ItemModel[];
24
+ private buttonObj: DropDownButton;
25
+ private layoutBtnObj: DropDownButton;
26
+ private default: string[] = ['Delete', 'Rename', 'Download', 'Cut', 'Copy', 'Paste'];
27
+ private single: string[] = ['Delete', 'Rename', 'Download', 'Cut', 'Copy'];
28
+ private multiple: string[] = ['Delete', 'Download', 'Cut', 'Copy', 'Refresh'];
29
+ private selection: string[] = ['NewFolder', 'Upload', 'SortBy', 'Refresh'];
30
+
31
+ /* public variable */
32
+ public toolbarObj: BaseToolbar;
33
+
34
+ /**
35
+ * Constructor for the Toolbar module
36
+ *
37
+ * @hidden
38
+ * @param {IFileManager} parent - specifies the parent element.
39
+ * @private
40
+ */
41
+ constructor(parent?: IFileManager) {
42
+ this.parent = parent;
43
+ this.render();
44
+ this.addEventListener();
45
+ }
46
+
47
+ private render(): void {
48
+ this.items = this.toolbarItemData(this.getItems(this.parent.toolbarSettings.items.map((item: string) => item.trim())));
49
+ const eventArgs: ToolbarCreateEventArgs = { items: this.items };
50
+ this.parent.trigger('toolbarCreate', eventArgs, (toolbarCreateArgs: ToolbarCreateEventArgs) => {
51
+ this.items = toolbarCreateArgs.items;
52
+ this.toolbarObj = new BaseToolbar({
53
+ items: this.items,
54
+ created: this.toolbarCreateHandler.bind(this),
55
+ overflowMode: 'Popup',
56
+ clicked: this.onClicked.bind(this),
57
+ enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
58
+ enableRtl: this.parent.enableRtl
59
+ });
60
+ this.toolbarObj.isStringTemplate = true;
61
+ this.toolbarObj.root = this.parent.root ? this.parent.root : this.parent;
62
+ this.toolbarObj.appendTo('#' + this.parent.element.id + CLS.TOOLBAR_ID);
63
+ });
64
+ }
65
+
66
+ public getItemIndex(item: string): number {
67
+ const itemId: string = this.getId(item);
68
+ for (let i: number = 0; i < this.items.length; i++) {
69
+ if (this.items[i as number].id === itemId) {
70
+ return i;
71
+ }
72
+ }
73
+ return -1;
74
+ }
75
+
76
+ private getItems(items: string[]): string[] {
77
+ let currItems: string[] = items.slice();
78
+ if (this.parent.isDevice && this.parent.allowMultiSelection) { currItems.push('SelectAll'); }
79
+ if (this.parent.toolbarItems.length > 0) {
80
+ currItems = this.parent.toolbarItems.map((item: ToolbarItem) => item.name);
81
+ }
82
+ return currItems;
83
+ }
84
+ /* istanbul ignore next */
85
+ private onClicked(args: ClickEventArgs): void {
86
+ if (isNOU(args.item) || !args.item.id) { return; }
87
+ const tool: string = args.item.id.substr((this.parent.element.id + '_tb_').length);
88
+ let details: Object[];
89
+ if (tool === 'refresh' || tool === 'newfolder' || tool === 'upload') {
90
+ details = [getPathObject(this.parent)];
91
+ this.parent.itemData = details;
92
+ } else {
93
+ this.parent.notify(events.selectedData, {});
94
+ details = this.parent.itemData;
95
+ }
96
+ const eventArgs: ToolbarClickEventArgs = { cancel: false, fileDetails: details, item: args.item };
97
+ this.parent.trigger('toolbarClick', eventArgs, (toolbarClickArgs: ToolbarClickEventArgs) => {
98
+ let sItems: string[];
99
+ let target: Element;
100
+ if (!toolbarClickArgs.cancel) {
101
+ switch (tool) {
102
+ case 'sortby':
103
+ target = closest((args.originalEvent.target as Element), '.' + CLS.TB_ITEM);
104
+ if (target && target.classList.contains('e-toolbar-popup')) {
105
+ args.cancel = true;
106
+ }
107
+ break;
108
+ case 'newfolder':
109
+ createNewFolder(this.parent);
110
+ break;
111
+ case 'cut':
112
+ cutFiles(this.parent);
113
+ break;
114
+ case 'copy':
115
+ copyFiles(this.parent);
116
+ break;
117
+ case 'delete':
118
+ for (let i: number = 0; i < details.length; i++) {
119
+ if (!hasEditAccess(details[i as number])) {
120
+ createDeniedDialog(this.parent, details[i as number], events.permissionEdit);
121
+ return;
122
+ }
123
+ }
124
+ createDialog(this.parent, 'Delete');
125
+ break;
126
+ case 'details':
127
+ this.parent.notify(events.detailsInit, {});
128
+ sItems = this.parent.selectedItems;
129
+ if (this.parent.activeModule === 'navigationpane') {
130
+ sItems = [];
131
+ }
132
+ GetDetails(this.parent, sItems, this.parent.path, 'details');
133
+ break;
134
+ case 'paste':
135
+ this.parent.folderPath = '';
136
+ pasteHandler(this.parent);
137
+ break;
138
+ case 'refresh':
139
+ refresh(this.parent);
140
+ break;
141
+ case 'download':
142
+ doDownload(this.parent);
143
+ break;
144
+ case 'rename':
145
+ if (!hasEditAccess(details[0])) {
146
+ createDeniedDialog(this.parent, details[0], events.permissionEdit);
147
+ } else {
148
+ this.parent.notify(events.renameInit, {});
149
+ createDialog(this.parent, 'Rename');
150
+ }
151
+ break;
152
+ case 'upload':
153
+ uploadItem(this.parent);
154
+ break;
155
+ case 'selectall':
156
+ this.parent.notify(events.selectAllInit, {});
157
+ break;
158
+ case 'selection':
159
+ this.parent.notify(events.clearAllInit, {});
160
+ break;
161
+ }
162
+ }
163
+ });
164
+ }
165
+
166
+ private toolbarCreateHandler(): void {
167
+ if (!isNOU(select('#' + this.getId('SortBy'), this.parent.element))) {
168
+ const items: SplitButtonItemModel[] = [
169
+ { id: this.getPupupId('name'), text: getLocaleText(this.parent, 'Name'),
170
+ iconCss: this.parent.sortBy === 'name' ? CLS.TB_OPTION_DOT : '' },
171
+ { id: this.getPupupId('size'), text: getLocaleText(this.parent, 'Size'),
172
+ iconCss: this.parent.sortBy === 'size' ? CLS.TB_OPTION_DOT : '' },
173
+ { id: this.getPupupId('date'), text: getLocaleText(this.parent, 'DateModified'),
174
+ iconCss: this.parent.sortBy === '_fm_modified' ? CLS.TB_OPTION_DOT : '' },
175
+ { separator: true },
176
+ { id: this.getPupupId('ascending'), text: getLocaleText(this.parent, 'Ascending'),
177
+ iconCss: this.parent.sortOrder === 'Ascending' ? CLS.TB_OPTION_TICK : '' },
178
+ { id: this.getPupupId('descending'), text: getLocaleText(this.parent, 'Descending'),
179
+ iconCss: this.parent.sortOrder === 'Descending' ? CLS.TB_OPTION_TICK : '' },
180
+ { id: this.getPupupId('none'), text: getLocaleText(this.parent, 'None'),
181
+ iconCss: this.parent.sortOrder === 'None' ? CLS.TB_OPTION_TICK : '' }
182
+ ];
183
+ this.buttonObj = new DropDownButton({
184
+ items: items, cssClass: getCssClass(this.parent, CLS.ROOT_POPUP),
185
+ select: sortbyClickHandler.bind(this, this.parent as IFileManager),
186
+ enableHtmlSanitizer: this.parent.enableHtmlSanitizer,
187
+ enableRtl: this.parent.enableRtl, iconCss: CLS.ICON_SHORTBY
188
+ });
189
+ this.buttonObj.isStringTemplate = true;
190
+ this.buttonObj.appendTo('#' + this.getId('SortBy'));
191
+ }
192
+ if (!isNOU(select('#' + this.getId('View'), this.parent.element))) {
193
+ const gridSpan: string = '<span class="' + CLS.ICON_GRID + ' ' + CLS.MENU_ICON + '"></span>';
194
+ const largeIconSpan: string = '<span class="' + CLS.ICON_LARGE + ' ' + CLS.MENU_ICON + '"></span>';
195
+ const layoutItems: SplitButtonItemModel[] = [
196
+ {
197
+ id: this.getPupupId('large'), text: getLocaleText(this.parent, 'View-LargeIcons'),
198
+ iconCss: this.parent.view === 'Details' ? '' : CLS.TB_OPTION_TICK
199
+ },
200
+ {
201
+ id: this.getPupupId('details'), text: getLocaleText(this.parent, 'View-Details'),
202
+ iconCss: this.parent.view === 'Details' ? CLS.TB_OPTION_TICK : ''
203
+ }
204
+ ];
205
+ this.layoutBtnObj = new DropDownButton({
206
+ iconCss: this.parent.view === 'Details' ? CLS.ICON_GRID : CLS.ICON_LARGE,
207
+ cssClass: getCssClass(this.parent, 'e-caret-hide ' + CLS.ROOT_POPUP),
208
+ items: layoutItems, select: this.layoutChange.bind(this),
209
+ enableRtl: this.parent.enableRtl,
210
+ content: '<span class="e-tbar-btn-text">' + getLocaleText(this.parent, 'View') + '</span>',
211
+ beforeItemRender: (args: MenuEventArgs) => {
212
+ const tickIcon: string = args.item.iconCss;
213
+ const viewText: boolean = args.item.text === getLocaleText(this.parent, 'View-LargeIcons');
214
+ const iconClass: string = tickIcon ? ' e-menu-icon ' + tickIcon : '';
215
+ args.element.innerHTML = '<span class="' + iconClass + '"></span>' + (viewText ? largeIconSpan : gridSpan) + args.item.text;
216
+ const span: HTMLElement = args.element.firstChild as HTMLElement;
217
+ if (span && span.className === '') {
218
+ args.element.removeChild(span);
219
+ }
220
+ }
221
+ });
222
+ this.layoutBtnObj.isStringTemplate = true;
223
+ this.layoutBtnObj.appendTo('#' + this.getId('View'));
224
+ }
225
+ this.hideItems(this.default, true);
226
+ this.hideStatus();
227
+ if ((this as any).parent.portals && (this.toolbarObj as any).portals) {
228
+ (this as any).parent.portals = (this as any).parent.portals.concat((this.toolbarObj as any).portals);
229
+ (this.parent as any)['renderReactTemplates']();
230
+ }
231
+ const btnElement: HTMLInputElement[] = (selectAll('.e-btn', this.toolbarObj.element) as HTMLInputElement[]);
232
+ for (let btnCount: number = 0; btnCount < btnElement.length; btnCount++) {
233
+ /* istanbul ignore next */
234
+ btnElement[btnCount as number].onkeydown = (e: KeyboardEvent) => {
235
+ if (e.keyCode === 13 && !(<HTMLElement>e.target).classList.contains('e-fe-popup')) {
236
+ e.preventDefault();
237
+ }
238
+ };
239
+ btnElement[btnCount as number].onkeyup = (e: KeyboardEvent) => {
240
+ if (e.keyCode === 13 && !(<HTMLElement>e.target).classList.contains('e-fe-popup')) {
241
+ btnElement[btnCount as number].click();
242
+ }
243
+ };
244
+ }
245
+ this.parent.refreshLayout();
246
+ }
247
+
248
+ private updateSortByButton(): void {
249
+ if (this.buttonObj) {
250
+ const items: SplitButtonItemModel[] = this.buttonObj.items;
251
+ for (let itemCount: number = 0; itemCount < items.length; itemCount++) {
252
+ if (items[itemCount as number].id === this.getPupupId('name')) {
253
+ items[itemCount as number].iconCss = this.parent.sortBy === 'name' ? CLS.TB_OPTION_DOT : '';
254
+ } else if (items[itemCount as number].id === this.getPupupId('size')) {
255
+ items[itemCount as number].iconCss = this.parent.sortBy === 'size' ? CLS.TB_OPTION_DOT : '';
256
+ } else if (items[itemCount as number].id === this.getPupupId('date')) {
257
+ if (this.parent.sortBy === 'dateModified' || this.parent.sortBy === 'dateCreated') {
258
+ items[itemCount as number].iconCss = this.parent.sortBy === this.parent.sortBy ? CLS.TB_OPTION_DOT : '';
259
+ }
260
+ else {
261
+ items[itemCount as number].iconCss = this.parent.sortBy === '_fm_modified' ? CLS.TB_OPTION_DOT : '';
262
+ }
263
+ } else if (items[itemCount as number].id === this.getPupupId('ascending')) {
264
+ items[itemCount as number].iconCss = this.parent.sortOrder === 'Ascending' ? CLS.TB_OPTION_TICK : '';
265
+ } else if (items[itemCount as number].id === this.getPupupId('descending')) {
266
+ items[itemCount as number].iconCss = this.parent.sortOrder === 'Descending' ? CLS.TB_OPTION_TICK : '';
267
+ } else if (items[itemCount as number].id === this.getPupupId('none')) {
268
+ items[itemCount as number].iconCss = this.parent.sortOrder === 'None' ? CLS.TB_OPTION_TICK : '';
269
+ }
270
+ }
271
+ }
272
+ }
273
+
274
+ private getPupupId(id: string): string {
275
+ return this.parent.element.id + '_ddl_' + id.toLowerCase();
276
+ }
277
+
278
+ private layoutChange(args: MenuEventArgs): void {
279
+ if (this.parent.view === 'Details') {
280
+ if (args.item.id === this.getPupupId('large')) {
281
+ updateLayout(this.parent, 'LargeIcons');
282
+ }
283
+ } else {
284
+ if (args.item.id === this.getPupupId('details')) {
285
+ updateLayout(this.parent, 'Details');
286
+ }
287
+ }
288
+ }
289
+
290
+ private toolbarItemData(data: string[]): ItemModel[] {
291
+ const items: ItemModel[] = [];
292
+ let mode: DisplayMode = 'Both';
293
+ if (this.parent.isMobile) {
294
+ mode = 'Overflow';
295
+ }
296
+ for (let i: number = 0; i < data.length; i++) {
297
+ let item: ItemModel;
298
+ let propItem: ToolbarItemModel;
299
+ if (this.parent.toolbarItems.length > 0) {
300
+ propItem = this.getItemModel(this.parent.toolbarItems[parseInt(i.toString(), 10)]);
301
+ }
302
+ const itemId: string = this.getId(data[i as number]);
303
+ const itemText: string = getLocaleText(this.parent, data[i as number]);
304
+ const itemTooltip: string = getLocaleText(this.parent, 'Tooltip-' + data[i as number]);
305
+ switch (data[i as number]) {
306
+ case '|':
307
+ item = { type: 'Separator' };
308
+ break;
309
+ case 'Upload':
310
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, prefixIcon: CLS.ICON_UPLOAD, showTextOn: mode };
311
+ break;
312
+ case 'SortBy': {
313
+ let spanElement: string = '<span class="e-tbar-btn-text e-tbar-ddb-text">' + itemText + '</span>';
314
+ if (propItem && propItem.text) {
315
+ spanElement = '<span class="e-tbar-btn-text e-tbar-ddb-text">' + propItem.text + '</span>';
316
+ }
317
+ item = {
318
+ id: itemId, tooltipText: itemTooltip,
319
+ template: '<button id="' + itemId + '" class="e-tbar-btn e-tbtn-txt" tabindex="-1">' + spanElement + '</button>'
320
+ };
321
+ break;
322
+ }
323
+ case 'Refresh':
324
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, prefixIcon: CLS.ICON_REFRESH, showTextOn: mode };
325
+ break;
326
+ case 'Selection':
327
+ item = {
328
+ id: itemId, text: itemText, tooltipText: itemTooltip, suffixIcon: CLS.ICON_CLEAR, overflow: 'Show',
329
+ align: 'Right'
330
+ };
331
+ break;
332
+ case 'View': {
333
+ let viewText: string;
334
+ if (propItem && propItem.text) {
335
+ viewText = propItem.text;
336
+ } else {
337
+ viewText = getLocaleText(this.parent, 'View');
338
+ }
339
+ item = {
340
+ id: itemId, tooltipText: itemTooltip, prefixIcon: this.parent.view === 'Details' ? CLS.ICON_GRID : CLS.ICON_LARGE,
341
+ overflow: 'Show', align: 'Right', text: itemText, showTextOn: 'Overflow',
342
+ template: '<button id="' + itemId + '" class="e-tbar-btn e-tbtn-txt" tabindex="-1" aria-label=' +
343
+ viewText + '></button>'
344
+ };
345
+ break;
346
+ }
347
+ case 'Details':
348
+ item = {
349
+ id: itemId, tooltipText: itemTooltip, prefixIcon: CLS.ICON_DETAILS, overflow: 'Show', align: 'Right',
350
+ text: itemText, showTextOn: 'Overflow'
351
+ };
352
+ break;
353
+ case 'NewFolder':
354
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, prefixIcon: CLS.ICON_NEWFOLDER, showTextOn: mode };
355
+ break;
356
+ case 'Cut':
357
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, prefixIcon: CLS.ICON_CUT, showTextOn: mode };
358
+ break;
359
+ case 'Copy':
360
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, prefixIcon: CLS.ICON_COPY, showTextOn: mode };
361
+ break;
362
+ case 'Paste':
363
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, prefixIcon: CLS.ICON_PASTE, showTextOn: mode };
364
+ break;
365
+ case 'Delete':
366
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, prefixIcon: CLS.ICON_DELETE, showTextOn: mode };
367
+ break;
368
+ case 'Rename':
369
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, prefixIcon: CLS.ICON_RENAME, showTextOn: mode };
370
+ break;
371
+ case 'Download':
372
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, prefixIcon: CLS.ICON_DOWNLOAD, showTextOn: mode };
373
+ break;
374
+ case 'SelectAll':
375
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, prefixIcon: CLS.ICON_SELECTALL, showTextOn: mode };
376
+ break;
377
+ default:
378
+ item = { id: itemId, text: itemText, tooltipText: itemTooltip, template: '' };
379
+ break;
380
+ }
381
+ if (this.parent.toolbarItems.length > 0 && propItem) {
382
+ const mergedItems: ToolbarItemModel = Object.assign({}, item, propItem);
383
+ items.push(mergedItems);
384
+ }
385
+ else {
386
+ items.push(item);
387
+ }
388
+ }
389
+ return items;
390
+ }
391
+
392
+ private getItemModel(propItem: ToolbarItemModel): ToolbarItemModel {
393
+ const item: ToolbarItemModel = {};
394
+ if (propItem.id) {
395
+ item.id = propItem.id;
396
+ }
397
+ if (propItem.text) {
398
+ item.text = propItem.text;
399
+ }
400
+ if (propItem.tooltipText) {
401
+ item.tooltipText = propItem.tooltipText;
402
+ }
403
+ if (propItem.prefixIcon) {
404
+ item.prefixIcon = propItem.prefixIcon;
405
+ }
406
+ if (propItem.cssClass) {
407
+ item.cssClass = propItem.cssClass;
408
+ }
409
+ if (propItem.showTextOn !== 'Both') {
410
+ item.showTextOn = propItem.showTextOn;
411
+ }
412
+ if (propItem.template) {
413
+ item.template = propItem.template;
414
+ }
415
+ if (propItem.disabled) {
416
+ item.disabled = propItem.disabled;
417
+ }
418
+ if (propItem.width !== 'auto') {
419
+ item.width = propItem.width;
420
+ }
421
+ if (propItem.suffixIcon) {
422
+ item.suffixIcon = propItem.suffixIcon;
423
+ }
424
+ if (propItem.align !== 'Left') {
425
+ item.align = propItem.align;
426
+ }
427
+ if (propItem.overflow !== 'None') {
428
+ item.overflow = propItem.overflow;
429
+ }
430
+ if (propItem.htmlAttributes) {
431
+ item.htmlAttributes = propItem.htmlAttributes;
432
+ }
433
+ if (propItem.type !== 'Button') {
434
+ item.type = propItem.type;
435
+ }
436
+ if (propItem.visible !== true) {
437
+ item.visible = propItem.visible;
438
+ }
439
+ if (propItem.showAlwaysInPopup) {
440
+ item.showAlwaysInPopup = propItem.showAlwaysInPopup;
441
+ }
442
+ if (propItem.tabIndex !== -1) {
443
+ item.tabIndex = propItem.tabIndex;
444
+ }
445
+ return item;
446
+ }
447
+
448
+ private getId(id: string): string {
449
+ return this.parent.element.id + '_tb_' + id.toLowerCase();
450
+ }
451
+
452
+ private addEventListener(): void {
453
+ this.parent.on(events.modelChanged, this.onPropertyChanged, this);
454
+ this.parent.on(events.selectionChanged, this.onSelectionChanged, this);
455
+ this.parent.on(events.layoutChange, this.onLayoutChange, this);
456
+ this.parent.on(events.showPaste, this.showPaste, this);
457
+ this.parent.on(events.hidePaste, this.hidePaste, this);
458
+ this.parent.on(events.destroy, this.destroy, this);
459
+ this.parent.on(events.sortByChange, this.updateSortByButton, this);
460
+ }
461
+
462
+ private reRenderToolbar(e: NotifyArgs): void {
463
+ let itemsToProcess: string | string[] = [];
464
+ if (this.parent.toolbarItems.length > 0) {
465
+ itemsToProcess = this.parent.toolbarItems.map((item: ToolbarItem) => {
466
+ return item.name;
467
+ });
468
+ } else if (e.newProp.toolbarSettings.items !== undefined) {
469
+ itemsToProcess = e.newProp.toolbarSettings.items.map((item: string) => {
470
+ return item.trim();
471
+ });
472
+ }
473
+
474
+ if (itemsToProcess.length > 0) {
475
+ this.items = this.toolbarItemData(this.getItems(itemsToProcess));
476
+ const eventArgs: ToolbarCreateEventArgs = { items: this.items };
477
+ this.parent.trigger('toolbarCreate', eventArgs, (toolbarCreateArgs: ToolbarCreateEventArgs) => {
478
+ if (this.buttonObj) { this.buttonObj.destroy(); }
479
+ if (this.layoutBtnObj) { this.layoutBtnObj.destroy(); }
480
+ this.items = toolbarCreateArgs.items; this.toolbarObj.items = this.items;
481
+ this.toolbarObj.dataBind();
482
+ this.toolbarCreateHandler();
483
+ });
484
+ }
485
+ }
486
+
487
+ private onSelectionChanged(): void {
488
+ this.hideStatus();
489
+ this.hideItems(this.single, true);
490
+ this.hideItems(this.selection, false);
491
+ if (this.parent.selectedItems.length === 1) {
492
+ this.hideItems(this.single, false);
493
+ this.hideItems(this.selection, true);
494
+ } else if (this.parent.selectedItems.length > 1) {
495
+ this.hideItems(this.multiple, false);
496
+ this.hideItems(this.selection, true);
497
+ }
498
+ const ele: Element = select('#' + this.getId('Selection'), this.toolbarObj.element);
499
+ if (this.parent.selectedItems.length > 0 && ele && !this.parent.enableVirtualization) {
500
+ let txt: string;
501
+ if (this.parent.selectedItems.length === 1) {
502
+ txt = this.parent.selectedItems.length + ' ' + getLocaleText(this.parent, 'Item-Selection');
503
+ } else {
504
+ txt = this.parent.selectedItems.length + ' ' + getLocaleText(this.parent, 'Items-Selection');
505
+ }
506
+ select('.e-tbar-btn-text', ele).textContent = txt;
507
+ this.toolbarObj.hideItem(ele.parentElement, false);
508
+ }
509
+ }
510
+
511
+ private hideItems(tools: string[], toHide: boolean): void {
512
+ for (let i: number = 0; i < tools.length; i++) {
513
+ const ele: Element = select('#' + this.getId(tools[i as number]), this.parent.element);
514
+ if (ele) { this.toolbarObj.hideItem(ele.parentElement, toHide); }
515
+ }
516
+ }
517
+
518
+ private hideStatus(): void {
519
+ const ele: Element = select('#' + this.getId('Selection'), this.toolbarObj.element);
520
+ if (ele) { this.toolbarObj.hideItem(ele.parentElement, true); }
521
+ }
522
+
523
+ private showPaste(): void {
524
+ this.hideItems(['Paste'], false);
525
+ }
526
+
527
+ private hidePaste(): void {
528
+ this.hideItems(['Paste'], true);
529
+ }
530
+
531
+ private onLayoutChange(): void {
532
+ if (this.layoutBtnObj) {
533
+ this.layoutBtnObj.iconCss = this.parent.view === 'Details' ? CLS.ICON_GRID : CLS.ICON_LARGE;
534
+ const items: SplitButtonItemModel[] = this.layoutBtnObj.items;
535
+ for (let itemCount: number = 0; itemCount < items.length; itemCount++) {
536
+ if (items[itemCount as number].id === this.getPupupId('large')) {
537
+ items[itemCount as number].iconCss = this.parent.view === 'LargeIcons' ? CLS.TB_OPTION_TICK : '';
538
+ } else if (items[itemCount as number].id === this.getPupupId('details')) {
539
+ items[itemCount as number].iconCss = this.parent.view === 'Details' ? CLS.TB_OPTION_TICK : '';
540
+ }
541
+ }
542
+ }
543
+ }
544
+
545
+ private removeEventListener(): void {
546
+ this.parent.off(events.modelChanged, this.onPropertyChanged);
547
+ this.parent.off(events.selectionChanged, this.onSelectionChanged);
548
+ this.parent.off(events.layoutChange, this.onLayoutChange);
549
+ this.parent.off(events.showPaste, this.showPaste);
550
+ this.parent.off(events.hidePaste, this.hidePaste);
551
+ this.parent.off(events.destroy, this.destroy);
552
+ this.parent.off(events.sortByChange, this.updateSortByButton);
553
+ }
554
+
555
+ /**
556
+ * For internal use only - Get the module name.
557
+ *
558
+ * @returns {string} - returns module name.
559
+ * @private
560
+ */
561
+ private getModuleName(): string {
562
+ return 'toolbar';
563
+ }
564
+
565
+ private onPropertyChanged(e: NotifyArgs): void {
566
+ if (e.module !== this.getModuleName() && e.module !== 'common') {
567
+ /* istanbul ignore next */
568
+ return;
569
+ }
570
+ for (const prop of Object.keys(e.newProp)) {
571
+ switch (prop) {
572
+ case 'cssClass':
573
+ if (this.buttonObj) {
574
+ this.buttonObj.cssClass = getCssClass(this.parent, CLS.ROOT_POPUP);
575
+ }
576
+ if (this.layoutBtnObj) {
577
+ this.layoutBtnObj.cssClass = getCssClass(this.parent, 'e-caret-hide ' + CLS.ROOT_POPUP);
578
+ }
579
+ break;
580
+ case 'height':
581
+ case 'width':
582
+ this.toolbarObj.refreshOverflow();
583
+ break;
584
+ case 'toolbarSettings':
585
+ case 'toolbarItems':
586
+ this.reRenderToolbar(e);
587
+ break;
588
+ }
589
+ }
590
+ }
591
+
592
+ public destroy(): void {
593
+ if (this.parent.isDestroyed) { return; }
594
+ this.removeEventListener();
595
+ if (this.buttonObj) { this.buttonObj.destroy(); }
596
+ if (this.layoutBtnObj) { this.layoutBtnObj.destroy(); }
597
+ this.toolbarObj.destroy();
598
+ this.parent.refreshLayout();
599
+ }
600
+
601
+ public enableItems(items: string[], isEnable?: boolean): void {
602
+ for (let i: number = 0; i < items.length; i++) {
603
+ const ele: Element = select('#' + this.getId(items[i as number]), this.parent.element);
604
+ if (ele) {
605
+ this.toolbarObj.enableItems(ele.parentElement, isEnable);
606
+ }
607
+ }
608
+ }
609
+ }