1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290 | 1×
1×
1×
2311×
2311×
1100×
5×
2311×
2311×
1×
1×
23×
23×
1×
1×
4×
4×
4×
4×
1×
1×
45×
45×
45×
36×
36×
9×
9×
2×
2×
7×
7×
7×
45×
45×
1×
1×
116×
116×
116×
1×
1×
19×
19×
1×
1×
56×
56×
1×
1×
2473×
2473×
2473×
1×
2472×
4946×
2447×
2447×
2447×
2472×
1×
4024×
4024×
1×
1×
181×
45×
1×
14×
4×
1×
4993×
469×
1×
5440×
479×
1×
26×
26×
369×
369×
26×
26×
26×
26×
1×
27×
1×
23×
23×
23×
2×
2×
21×
3×
2×
2×
2×
1×
1×
1×
19×
19×
19×
1×
1×
18×
3×
3×
3×
3×
3×
22×
3×
1×
1×
1×
1×
45×
45×
45×
1×
1×
44×
6×
5×
5×
1×
1×
1×
116×
116×
116×
1×
1×
115×
28×
28×
28×
28×
28×
28×
28×
26×
10×
10×
10×
12×
5×
1×
1×
1×
1×
1×
1×
4×
7×
10×
5×
10×
16×
16×
16×
24×
24×
12×
8×
12×
5×
5×
5×
12×
12×
1×
1×
1×
1×
1×
1×
1×
1×
1×
12×
12×
12×
16×
8×
1×
292×
292×
292×
292×
1×
2866×
23×
23×
19×
19×
45×
45×
116×
116×
292×
292×
1×
2866×
2866×
2866×
2866×
2850×
2839×
2839×
572×
572×
572×
572×
572×
572×
424×
4381×
4381×
424×
424×
12×
12×
148×
118×
118×
32×
118×
30×
14×
14×
14×
18×
14×
14×
14×
572×
572×
2267×
2006×
1×
1×
1×
2005×
2005×
8×
8×
2267×
1×
14×
14×
14×
14×
1×
2577×
2577×
2577×
2114×
2114×
2114×
2114×
2100×
1448×
1448×
1448×
2100×
1477×
2577×
2577×
2473×
2473×
12139×
12139×
2473×
2092×
2092×
2577×
5×
5×
5×
5×
1×
1×
4×
5×
2577×
2577×
1768×
2577×
6×
1×
24×
24×
24×
24×
24×
19×
1×
9×
9×
9×
4×
1×
2135×
2135×
2092×
2092×
2092×
2092×
43×
8×
8×
8×
43×
43×
43×
2135×
16×
16×
16×
16×
1×
4×
4×
4×
4×
4×
1×
21×
21×
19×
19×
19×
19×
19×
19×
19×
19×
19×
19×
2×
1×
1×
1×
1×
1×
1×
1×
1×
2×
2×
2×
1×
1×
1×
1×
42×
42×
36×
35×
36×
36×
36×
36×
36×
36×
1×
1×
1×
1×
1×
1×
1×
1×
36×
36×
9×
27×
1×
27×
6×
5×
5×
5×
5×
5×
5×
1×
1×
1×
1×
1×
1×
1×
114×
114×
114×
114×
29×
29×
16×
16×
29×
29×
1×
85×
74×
74×
11×
1×
1×
1×
10×
1×
1×
18×
18×
18×
18×
18×
18×
18×
18×
18×
18×
1×
53×
53×
53×
53×
53×
1×
56×
56×
56×
1×
292×
292×
1×
1×
199×
199×
199×
199×
199×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/constant", "../pop-up/dialog", "../common/utility", "../common/utility", "@syncfusion/ej2-grids"], function (require, exports, ej2_base_1, ej2_base_2, events, dialog_1, utility_1, utility_2, ej2_grids_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Function to read the content from given path in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {string} event - specifies the event.
* @param {string} path - specifies the path.
* @returns {void}
* @private
*/
function read(parent, event, path) {
var itemData = parent.itemData;
for (var i = 0; i < itemData.length; i++) {
if (ej2_base_2.isNullOrUndefined(ej2_base_2.getValue('hasChild', itemData[i]))) {
ej2_base_2.setValue('hasChild', false, itemData[i]);
}
}
var data = { action: 'read', path: path, showHiddenItems: parent.showHiddenItems, data: itemData };
createAjax(parent, data, readSuccess, event);
}
exports.read = read;
/**
* Function to create new folder in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {string} itemName - specifies the item name.
* @returns {void}
* @private
*/
function createFolder(parent, itemName) {
var data = { action: 'create', path: parent.path, name: itemName, data: parent.itemData };
createAjax(parent, data, createSuccess, itemName);
}
exports.createFolder = createFolder;
/**
* Function to filter the files in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {string} event - specifies the event.
* @returns {void}
* @private
*/
function filter(parent, event) {
var data = { action: 'filter', path: parent.path, showHiddenItems: parent.showHiddenItems, data: [utility_1.getPathObject(parent)] };
var filterData;
var filterDataVal = parent.filterData ? ej2_base_1.extend(filterData, data, parent.filterData) : data;
createAjax(parent, filterDataVal, filterSuccess, event, ej2_base_2.getValue('action', filterDataVal));
}
exports.filter = filter;
/**
* Function to rename the folder/file in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {string} path - specifies the path.
* @param {string} itemNewName - specifies the item's new name.
* @returns {void}
* @private
*/
function rename(parent, path, itemNewName) {
var name;
var newName;
if (parent.breadcrumbbarModule.searchObj.element.value === '' && !parent.isFiltered) {
name = parent.currentItemText;
newName = itemNewName;
}
else {
var fPath = parent.filterPath;
if (parent.hasId) {
name = parent.currentItemText;
newName = itemNewName;
}
else {
fPath = fPath.replace(/\\/g, '/');
name = fPath.replace(path, '') + parent.currentItemText;
newName = fPath.replace(path, '') + itemNewName;
}
}
var data = {
action: 'rename', path: path, name: name, newName: newName, data: parent.itemData, showFileExtension: parent.showFileExtension
};
createAjax(parent, data, renameSuccess, path);
}
exports.rename = rename;
/**
* Function to paste file's and folder's in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {string} path - specifies the path.
* @param {string[]} names - specifies the names.
* @param {string} targetPath - specifies the target path.
* @param {string} pasteOperation - specifies the paste operation.
* @param {string[]} renameItems - specifies the rename items.
* @param {Object[]} actionRecords - specifies the action records.
* @returns {void}
* @private
*/
function paste(parent, path, names, targetPath, pasteOperation, renameItems, actionRecords) {
var data = {
action: pasteOperation, path: path, targetData: parent.itemData[0],
targetPath: targetPath, names: names, renameFiles: renameItems, data: actionRecords
};
parent.destinationPath = targetPath;
createAjax(parent, data, pasteSuccess, path, pasteOperation, targetPath);
}
exports.paste = paste;
/**
* Function to delete file's and folder's in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {string[]} items - specifies the items.
* @param {string} path - specifies the path.
* @param {string} operation - specifies the operation.
* @returns {void}
* @private
*/
function Delete(parent, items, path, operation) {
var data = { action: operation, path: path, names: items, data: parent.itemData };
createAjax(parent, data, deleteSuccess, path);
}
exports.Delete = Delete;
/* istanbul ignore next */
/**
* Function to get details of file's and folder's in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {string[]} names - specifies the names.
* @param {string} path - specifies the path.
* @param {string} operation - specifies the operation data.
* @returns {void}
* @private
*/
function GetDetails(parent, names, path, operation) {
var data = { action: operation, path: path, names: names, data: parent.itemData };
createAjax(parent, data, detailsSuccess, path, operation);
}
exports.GetDetails = GetDetails;
/**
* Function for getDateFormat in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @returns {void}
* @private
*/
function getDateFormat(parent) {
var columns = parent.detailsViewSettings.columns;
var dateFormat;
if (!columns) {
return null;
}
for (var i = 0; i < columns.length; i++) {
if (columns[i].field === '_fm_modified') {
Eif (!ej2_base_2.isNullOrUndefined(columns[i].format)) {
dateFormat = columns[i].format.toString();
}
break;
}
}
return dateFormat;
}
/**
* Checks whether fileSystemData is enabled.
*
* @param {IFileManager} parent - specifies the parent element.
* @returns {boolean} - returns the boolean value.
*/
function isFileSystemData(parent) {
var isFileSystemData = parent.fileSystemData.length >= 0 && ej2_base_2.isNullOrUndefined(parent.ajaxSettings.url);
return isFileSystemData;
}
exports.isFileSystemData = isFileSystemData;
/**
* Function to check whether file already exist or not.
*
* @param {Record<string, any>} fileSystemData - specifies the file data.
* @param {string} name - specifies the name.
* @returns {boolean} - returns the boolean value.
* @private
*/
function isFileExists(fileSystemData, name) {
var isExists = fileSystemData.some(function (item) { return item.name === name; });
return isExists;
}
/**
* Function to find the index value of a file or folder.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {number} id - specifies the id.
* @returns {number} - returns the index value.
* @private
*/
function findIndexById(parent, id) {
var index = parent.fileSystemData.findIndex(function (item) { return String(item.id) === String(id); });
return index;
}
/**
* Function to get the entire data of a file or folder using id value.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {number | string} id - specifies the id.
* @returns {Object} - returns the data.
* @private
*/
function filterById(parent, id) {
var data = parent.fileSystemData.filter(function (item) { return String(item.id) === String(id); })[0];
return data;
}
/**
* Function to get the entire data of a file or folder for a parent.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {number | string} parentId - specifies the parent id.
* @returns {Object[]} - returns the data.
* @private
*/
function filterByParent(parent, parentId) {
var data = parent.fileSystemData.filter(function (item) { return String(item.parentId) === String(parentId); });
return data;
}
/**
* Function to create a new copied file or folder.
*
* @param {Record<string, any>} data - specifies the file or folder data.
* @param {Record<string, any>} target - specifies the target data.
* @param {string} itemName - specifies the item name.
* @param {boolean} isCopy - specifies the copy operation.
* @returns {Record<string, Object>} - returns the data.
* @private
*/
function createNewItem(data, target, itemName, isCopy) {
var newItem = {};
//Construct the new folder details.
for (var key in data) {
Eif (Object.prototype.hasOwnProperty.call(data, key)) {
newItem[key] = null;
}
}
var currentDate = new Date();
var folderPath = target.id !== 0 ? target.filterPath + target.name : '\\';
Object.assign(newItem, {
dateCreated: currentDate,
dateModified: currentDate,
filterPath: folderPath,
hasChild: isCopy ? data.hasChild : false,
id: ej2_grids_1.getUid(itemName === null ? data.name : itemName),
isFile: isCopy ? data.isFile : false,
name: itemName === null ? data.name : itemName,
parentId: target.id,
size: isCopy ? data.size : 0,
type: isCopy ? data.type : ''
});
return newItem;
}
/**
* Function to create an error response.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {string} message - specifies the error message.
* @param {string} code - specifies the error code.
* @param {Object[]} fileName - specifies the file name.
* @returns {void}
* @private
*/
function createErrorObject(parent, message, code, fileName) {
parent.responseData = {
cwd: null,
details: null,
error: {
code: code,
message: message,
fileExists: fileName != null ? fileName : null
},
files: null
};
}
/**
* Function to trigger folder creation.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {Object} data - specifies the data.
* @param {BeforeSendEventArgs} eventArgs - specifies the eventArgs.
* @returns {void}
* @private
*/
function triggerFolderCreation(parent, data, eventArgs) {
var createEventArgs = {
folderName: ej2_base_2.getValue('name', data),
cancel: false,
path: ej2_base_2.getValue('path', data),
parentFolder: ej2_base_2.getValue('data', data)
};
parent.trigger('beforeFolderCreate', createEventArgs, function (args) {
if (args.cancel) {
eventArgs.cancel = true;
return;
}
if (isFileSystemData(parent)) {
if (!isFileExists(parent.fileSystemData, args.folderName)) {
var data_1 = args.parentFolder[0];
var newObject = createNewItem(data_1, data_1, args.folderName, false);
parent.fileSystemData.push(newObject);
}
else {
var message = 'A file or folder with the name ' + args.folderName + ' already exists.';
createErrorObject(parent, message, '400', null);
}
}
});
}
/**
* Function to trigger delete operation.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {Object} data - specifies the data.
* @param {BeforeSendEventArgs} eventArgs - specifies the eventArgs.
* @returns {void}
* @private
*/
function triggerDeleteOperation(parent, data, eventArgs) {
var deleteEventArgs = {
cancel: false,
itemData: ej2_base_2.getValue('data', data),
path: ej2_base_2.getValue('path', data)
};
parent.trigger('beforeDelete', deleteEventArgs, function (args) {
if (args.cancel) {
eventArgs.cancel = true;
return;
}
if (isFileSystemData(parent)) {
args.itemData.forEach(function (itemData) {
var index = findIndexById(parent, itemData.id);
Eif (index !== -1) {
parent.fileSystemData.splice(index, 1);
}
Eif (!itemData.isFile) {
var subItems = parent.fileSystemData.filter(function (obj) { return obj.filterPath.includes(itemData.name); });
subItems.forEach(function (subItem) {
var index = findIndexById(parent, subItem.id);
Eif (index !== -1) {
parent.fileSystemData.splice(index, 1);
}
});
}
});
}
});
}
/**
* Function to trigger rename operation.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {Object} data - specifies the data.
* @param {BeforeSendEventArgs} eventArgs - specifies the eventArgs.
* @returns {void}
* @private
*/
function triggerRenameOperation(parent, data, eventArgs) {
var renameEventArgs = {
cancel: false,
newName: ej2_base_2.getValue('newName', data),
itemData: ej2_base_2.getValue('data', data),
path: ej2_base_2.getValue('path', data)
};
parent.trigger('beforeRename', renameEventArgs, function (args) {
if (args.cancel) {
eventArgs.cancel = true;
return;
}
if (isFileSystemData(parent)) {
if (!isFileExists(parent.fileSystemData, args.newName)) {
var fileData = filterById(parent, args.itemData[0].id);
fileData.name = args.newName;
}
else {
var message = 'Cannot rename' + args.itemData[0].name + 'to' + args.newName + ': destination already exists.';
createErrorObject(parent, message, '400', null);
}
}
});
}
/**
* Function to trigger move or copy operation.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {Object} data - specifies the data.
* @param {BeforeSendEventArgs} eventArgs - specifies the eventArgs.
* @returns {void}
* @private
*/
function triggerMoveOrCopyOperation(parent, data, eventArgs) {
var moveEventArgs = {
cancel: false,
itemData: ej2_base_2.getValue('data', data),
isCopy: ej2_base_2.getValue('action', data) === 'copy' ? true : false,
path: ej2_base_2.getValue('path', data),
targetData: ej2_base_2.getValue('targetData', data),
targetPath: ej2_base_2.getValue('targetPath', data)
};
parent.trigger('beforeMove', moveEventArgs, function (args) {
if (args.cancel) {
eventArgs.cancel = true;
return;
}
if (isFileSystemData(parent)) {
var message = 'File Already Exists';
var action = ej2_base_2.getValue('action', data);
var itemPermission = utility_2.getAccessDetails(parent, args.itemData, action, false);
var pathPermission = utility_2.getAccessDetails(parent, [args.targetData], action, true);
var file_1 = [];
parent.pasteNodes = [];
if (itemPermission === '' && pathPermission === '') {
if (args.isCopy) {
var folderSubItems_1 = filterByParent(parent, args.targetData.id);
var copiedFolders = args.itemData;
copiedFolders.forEach(function (itemData) {
if (!isFileExists(folderSubItems_1, itemData.name) || ej2_base_2.getValue('renameFiles', data).length > 0) {
if (ej2_base_2.getValue('renameFiles', data).length > 0) {
var names = itemData.name.split('.');
var name_1 = itemData.name.includes('.') ? names[0] + '(' + parent.existingFileCount + ').' + names[1] : names[0] + '(' + parent.existingFileCount + ')';
copyFolderItems(parent, itemData, args.targetData, name_1);
parent.responseData.error = null;
parent.existingFileCount++;
return;
}
copyFolderItems(parent, itemData, args.targetData, null);
}
else {
file_1.push(itemData.name);
}
});
if (file_1.length > 0) {
createErrorObject(parent, message, '400', file_1);
}
return;
}
var target = args.targetData;
var getTargetFiles = filterByParent(parent, target.id);
for (var i = 0; i < args.itemData.length; i++) {
var currItem = args.itemData[i];
if (!isFileExists(getTargetFiles, currItem.name) || ej2_base_2.getValue('renameFiles', data).length > 0) {
if (!target.hasChild) {
target.hasChild = !currItem.isFile;
}
if (!currItem.isFile) {
//Check whether the source folder include other sub folders or not.
var subItems = currItem.parentId !== 0
? filterByParent(parent, currItem.parentID) : [];
var itemData = filterById(parent, currItem.parentId);
itemData.hasChild = subItems.length > 1 ? true : false;
}
var fileData = filterById(parent, currItem.id);
if (ej2_base_2.getValue('renameFiles', data).length > 0) {
var names = currItem.name.split('.');
currItem.name = currItem.name.includes('.') ? names[0] + '(' + parent.existingFileCount + ').' + names[1] : names[0] + '(' + parent.existingFileCount + ')';
fileData.name = currItem.name;
parent.responseData.error = null;
parent.existingFileCount++;
parent.dropData = target;
parent.dropPath = args.path;
var pathArray = args.targetPath.replace(/^\/|\/$/g, '').split('/');
target = filterById(parent, pathArray[pathArray.length - 1]);
}
fileData.parentId = target.id;
fileData.filterPath = target.id === 0 ? '\\' : target.filterPath + target.name + '\\';
}
else {
file_1.push(currItem.name);
}
}
if (file_1.length > 0) {
createErrorObject(parent, message, '400', file_1);
}
}
}
});
}
/**
* Function to trigger search operation.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {Object} data - specifies the data.
* @param {BeforeSendEventArgs} eventArgs - specifies the eventArgs.
* @returns {void}
* @private
*/
function triggerSearchOperation(parent, data, eventArgs) {
var searchEventArgs = {
searchResults: ej2_base_2.getValue('data', data),
cancel: false,
path: ej2_base_2.getValue('path', data),
searchText: ej2_base_2.getValue('searchString', data),
caseSensitive: ej2_base_2.getValue('caseSensitive', data),
showHiddenItems: ej2_base_2.getValue('showHiddenItems', data)
};
parent.trigger('search', searchEventArgs, function (args) {
ej2_base_2.setValue('data', args.searchResults, data);
Iif (args.cancel) {
eventArgs.cancel = true;
}
});
}
/**
* Function to trigger client side events.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {Object} data - specifies the data.
* @param {BeforeSendEventArgs} eventArgs - specifies the eventArgs.
* @returns {void}
* @private
*/
function triggerClientEvents(parent, data, eventArgs) {
switch (ej2_base_2.getValue('action', data)) {
case 'create': {
triggerFolderCreation(parent, data, eventArgs);
break;
}
case 'delete': {
triggerDeleteOperation(parent, data, eventArgs);
break;
}
case 'rename': {
triggerRenameOperation(parent, data, eventArgs);
break;
}
case 'move':
case 'copy': {
triggerMoveOrCopyOperation(parent, data, eventArgs);
break;
}
case 'search': {
triggerSearchOperation(parent, data, eventArgs);
break;
}
}
}
/**
* Creates an AJAX request for the file manager.
*
* @param {IFileManager} parent - The parent file manager instance.
* @param {Object} data - The data object for the AJAX request.
* @param {Function} fn - The callback function to be executed after the AJAX request.
* @param {string} [event] - The event type for the AJAX request.
* @param {string} [operation] - The operation type for the AJAX request.
* @param {string} [targetPath] - The target path for the AJAX request.
* @returns {void}
* @private
*/
function createAjax(parent, data, fn, event, operation, targetPath) {
var ajaxSettings = {
url: parent.ajaxSettings.url,
type: 'POST',
mode: true,
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify(data),
onSuccess: null,
onFailure: null,
beforeSend: null
};
var eventArgs = { action: ej2_base_2.getValue('action', data), ajaxSettings: ajaxSettings, cancel: false };
triggerClientEvents(parent, data, eventArgs);
parent.trigger('beforeSend', eventArgs, function (beforeSendArgs) {
if (!beforeSendArgs.cancel) {
parent.notify(events.beforeRequest, {});
if (isFileSystemData(parent)) {
var filePath = event === 'node-expand' || event === 'finalize-end' ? ej2_base_2.getValue('path', data) : parent.path;
var pathArray = filePath.replace(/^\/|\/$/g, '').split('/');
var idValue = event === 'rename-end-parent' || (event === 'path-changed' && ej2_base_2.getValue('data', data).length !== 0)
|| (event === 'paste-end' && (parent.targetModule === 'largeiconsview' || parent.targetModule === 'detailsview'))
? ej2_base_2.getValue('data', data)[0].id : pathArray[pathArray.length - 1];
var action = ej2_base_2.getValue('action', data);
var isFileOperation = (action === 'move' || action === 'rename' || action === 'copy' || action === 'delete' || action === 'search') && event !== 'rename-end';
if (action === 'read' || action === 'create' || event === 'rename-end') {
var rootId = parent.fileSystemData
.filter(function (item) { return ej2_base_2.isNullOrUndefined(item.parentId); })
.length > 0
? parent.fileSystemData
.filter(function (item) { return ej2_base_2.isNullOrUndefined(item.parentId); })[0].id
: 0;
parent.responseData = {
cwd: filterById(parent, parent.path === '/' && event !== 'node-expand' && event !== 'rename-end-parent' ? rootId : idValue),
details: null,
error: null,
files: filterByParent(parent, parent.path === '/' && event !== 'node-expand' && event !== 'rename-end-parent' ? rootId : idValue)
};
if (ej2_base_2.isNullOrUndefined(parent.responseData.cwd)) {
var message = 'Cannot load empty data within the File Manager.';
createErrorObject(parent, message, '400', null);
}
}
else if (isFileOperation && parent.responseData.error === null) {
var itemData = action === 'search' || action === 'delete' ? ej2_base_2.getValue('data', data) : [];
if (itemData.length === 0) {
itemData = ej2_base_2.getValue('data', data).map(function (item) { return filterById(parent, item.id); });
}
parent.responseData = {
cwd: null,
details: null,
error: null,
files: itemData
};
}
else if (ej2_base_2.getValue('action', data) === 'details') {
var itemData = ej2_base_2.getValue('data', data);
var details = itemData[0];
var isMultipleFiles = itemData.length > 1;
var itemNames = itemData.map(function (item) { return item.name; });
var totalSize = isMultipleFiles ? getSize(itemData.reduce(function (accumulator, currentObject) { return accumulator + (currentObject.size || 0); }, 0)) : getSize(details.size);
var path = (parent.pathNames.includes(details.name) ? parent.pathNames.join('/') : parent.pathNames.join('/') + '/' + details.name);
parent.responseData.details = Object.assign({
location: isMultipleFiles ? null : path,
multipleFiles: isMultipleFiles,
name: itemNames.join(', '),
size: totalSize
}, isMultipleFiles ? {} : {
created: details.dateCreated,
isFile: details.isFile,
modified: details.dateModified,
permission: details.permission
});
}
performReadOperation(parent, parent.responseData, fn, data, event, operation, targetPath, beforeSendArgs);
return;
}
var ajax = new ej2_base_1.Ajax({
url: ej2_base_2.getValue('url', beforeSendArgs.ajaxSettings),
type: ej2_base_2.getValue('type', beforeSendArgs.ajaxSettings),
mode: ej2_base_2.getValue('mode', beforeSendArgs.ajaxSettings),
dataType: ej2_base_2.getValue('dataType', beforeSendArgs.ajaxSettings),
contentType: ej2_base_2.getValue('contentType', beforeSendArgs.ajaxSettings),
data: ej2_base_2.getValue('data', beforeSendArgs.ajaxSettings),
beforeSend: ej2_base_2.getValue('beforeSend', beforeSendArgs.ajaxSettings),
onSuccess: function (result) {
if (ej2_base_2.isNullOrUndefined(result)) {
var result_1 = {
error: {
fileExists: null,
message: utility_1.getLocaleText(parent, 'Server-Error') + ' ' + parent.ajaxSettings.url,
code: '406'
},
files: null
};
triggerAjaxFailure(parent, beforeSendArgs, fn, result_1, event, operation, targetPath);
return;
}
Iif (typeof (result) === 'string') {
result = JSON.parse(result);
}
performReadOperation(parent, result, fn, data, event, operation, targetPath, beforeSendArgs);
},
onFailure: function () {
var result = {
files: null,
error: {
code: '404',
message: utility_1.getLocaleText(parent, 'Network-Error') + ' ' + parent.ajaxSettings.url,
fileExists: null
}
};
triggerAjaxFailure(parent, beforeSendArgs, fn, result, event, operation, targetPath);
}
});
ajax.send();
}
});
}
/**
* Function to get file size.
*
* @param {number} size - specifies the size.
* @returns {string} - returns the size.
* @private
*/
function getSize(size) {
var hz;
Eif (size < 1024) {
hz = size + ' B';
}
else if (size < 1024 * 1024) {
hz = (size / 1024).toFixed(2) + ' KB';
}
else if (size < 1024 * 1024 * 1024) {
hz = (size / 1024 / 1024).toFixed(2) + ' MB';
}
else {
hz = (size / 1024 / 1024 / 1024).toFixed(2) + ' GB';
}
return hz;
}
/**
* Function to perform read operation.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {ReadArgs} result - specifies the result.
* @param {Function} fn - specifies the function.
* @param {Object} data - specifies the data.
* @param {string} event - specifies the event.
* @param {string} operation - specifies the operation.
* @param {string} targetPath - specifies the targetPath.
* @param {BeforeSendEventArgs} beforeSendArgs - specifies the eventArgs.
* @returns {void}
* @private
*/
function performReadOperation(parent, result, fn, data, event, operation, targetPath, beforeSendArgs) {
parent.notify(events.afterRequest, { action: 'success' });
var id = parent.expandedId ? parent.expandedId : parent.pathId[parent.pathId.length - 1];
if (!ej2_base_2.isNullOrUndefined(result.cwd) && (ej2_base_2.getValue('action', data) === 'read')) {
result.cwd.name = (parent.pathId.length === 1) ? (parent.rootAliasName || result.cwd.name) : result.cwd.name;
ej2_base_2.setValue('_fm_id', id, result.cwd);
ej2_base_2.setValue(id, result.cwd, parent.feParent);
if (!ej2_base_2.isNullOrUndefined(result.files) || result.error.code === '401') {
if ((event === 'finalize-end' || event === 'initial-end') && parent.pathNames.length === 0) {
var root = ej2_base_2.getValue(parent.pathId[0], parent.feParent);
parent.pathNames[0] = ej2_base_2.getValue('name', root);
parent.hasId = !ej2_base_2.isNullOrUndefined(ej2_base_2.getValue('id', root));
}
if (event === 'finalize-end') {
utility_2.generatePath(parent);
}
}
}
var intl = new ej2_base_1.Internationalization(parent.locale);
if (!ej2_base_2.isNullOrUndefined(result.files)) {
utility_1.setDateObject(result.files, intl, getDateFormat(parent));
for (var i = 0, len = result.files.length; i < len; i++) {
var item = result.files[i];
ej2_base_2.setValue('_fm_iconClass', utility_1.fileType(item), item);
}
if (ej2_base_2.getValue('action', data) === 'read') {
utility_1.setNodeId(result, id);
ej2_base_2.setValue(id, result.files, parent.feFiles);
}
}
if (!ej2_base_2.isNullOrUndefined(result.details) && !ej2_base_2.isNullOrUndefined(parent.rootAliasName)) {
var rootName = parent.rootAliasName || ej2_base_2.getValue('name', result.details);
var location_1 = ej2_base_2.getValue('location', result.details).replace(new RegExp('/', 'g'), '\\');
Eif ((ej2_base_2.getValue('path', data) === '/') || (parent.hasId && ej2_base_2.getValue('path', data).match(/[/]/g).length === 1)) {
if (ej2_base_2.getValue('names', data).length === 0) {
ej2_base_2.setValue('name', rootName, result.details);
location_1 = rootName;
}
else {
location_1 = location_1.replace(location_1.substring(0, location_1.indexOf('\\')), rootName);
}
}
else {
location_1 = location_1.replace(location_1.substring(0, location_1.indexOf('\\')), rootName);
}
ej2_base_2.setValue('location', location_1, result.details);
}
fn(parent, result, event, operation, targetPath);
if (!ej2_base_2.isNullOrUndefined(result.files) && (event === 'path-changed' || event === 'finalize-end' || event === 'open-end' || event === 'drop-path')) {
parent.notify(events.searchTextChange, result);
}
if (typeof ej2_base_2.getValue('onSuccess', beforeSendArgs.ajaxSettings) === 'function') {
ej2_base_2.getValue('onSuccess', beforeSendArgs.ajaxSettings)();
}
}
/**
* Function to copy operation.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {Object} data - specifies the data.
* @param {string} target - specifies the target.
* @param {string} itemName - specifies the item name.
* @returns {void}
* @private
*/
function copyFolderItems(parent, data, target, itemName) {
var newObject = createNewItem(data, target, itemName, true);
parent.fileSystemData.push(newObject);
parent.pasteNodes.push(newObject.id);
var copiedItems = filterByParent(parent, data.id);
for (var i = 0; i < copiedItems.length; i++) {
copyFolderItems(parent, copiedItems[i], newObject, null);
}
}
/**
* Function for trigger Ajax failure in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {BeforeSendEventArgs} beforeSendArgs - specifies the beforeSendArgs.
* @param {Function} fn - specifies the function.
* @param {ReadArgs} result - specifies the result.
* @param {string} event - specifies the event.
* @param {string} operation - specifies the operation.
* @param {string} targetPath - specifies the targetPath.
* @returns {void}
* @private
*/
function triggerAjaxFailure(parent, beforeSendArgs, fn, result, event, operation, targetPath) {
parent.notify(events.afterRequest, { action: 'failure' });
fn(parent, result, event, operation, targetPath);
if (typeof ej2_base_2.getValue('onFailure', beforeSendArgs.ajaxSettings) === 'function') {
ej2_base_2.getValue('onFailure', beforeSendArgs.ajaxSettings)();
}
}
/**
* Function for read success in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {ReadArgs} result - specifies the result.
* @param {string} event - specifies the event.
* @returns {void}
* @private
*/
function readSuccess(parent, result, event) {
try {
if (!ej2_base_2.isNullOrUndefined(result.files)) {
parent.notify(event, result);
parent.notify(events.selectionChanged, {});
var args = { action: 'read', result: result };
parent.trigger('success', args);
}
else {
if (!ej2_base_2.isNullOrUndefined(result.error) && result.error.code === '401') {
result.files = [];
parent.notify(event, result);
parent.notify(events.selectionChanged, {});
}
onFailure(parent, result, 'read');
parent.setProperties({ path: parent.oldPath }, true);
parent.pathNames.pop();
}
}
catch (error) {
handleCatchError(parent, error, 'read');
parent.setProperties({ path: parent.oldPath }, true);
parent.pathNames.pop();
}
if (parent.isDragDrop && parent.isDropEnd) {
Eif (parent.droppedObjects.length !== 0) {
var args = { fileDetails: parent.droppedObjects };
parent.trigger('fileDropped', args);
}
parent.isDropEnd = parent.isDragDrop = false;
}
}
/**
* Function for filter success in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {ReadArgs} result - specifies the result.
* @param {string} event - specifies the event.
* @param {string} action - specifies the action.
* @returns {void}
* @private
*/
function filterSuccess(parent, result, event, action) {
try {
Eif (!ej2_base_2.isNullOrUndefined(result.files)) {
parent.notify(event, result);
var args = { action: action, result: result };
parent.trigger('success', args);
}
else {
onFailure(parent, result, action);
}
}
catch (error) {
handleCatchError(parent, error, action);
}
}
/* istanbul ignore next */
/**
* Function for create success in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {ReadArgs} result - specifies the result.
* @param {string} itemName - specifies the item name.
* @returns {void}
* @private
*/
function createSuccess(parent, result, itemName) {
try {
if (!ej2_base_2.isNullOrUndefined(result.files)) {
Eif (parent.dialogObj && parent.dialogObj.visible) {
parent.dialogObj.hide();
}
parent.createdItem = isFileSystemData(parent) ? result.files[result.files.length - 1] : result.files[0];
parent.breadcrumbbarModule.searchObj.value = '';
var createEventArgs = {
folderName: itemName,
path: parent.path,
parentFolder: parent.itemData
};
parent.trigger('folderCreate', createEventArgs);
var args = { action: 'create', result: result };
parent.trigger('success', args);
parent.itemData = [utility_1.getPathObject(parent)];
read(parent, events.createEnd, parent.path);
}
else {
Iif (result.error.code === '400') {
if (parent.dialogObj && parent.dialogObj.visible) {
var ele = ej2_base_1.select('#newname', parent.dialogObj.element);
var error = utility_1.getLocaleText(parent, 'Validation-NewFolder-Exists').replace('{0}', '"' + ele.value + '"');
ele.parentElement.nextElementSibling.innerHTML = error;
}
else {
var result_2 = {
files: null,
error: {
code: '400',
message: utility_1.getLocaleText(parent, 'Validation-NewFolder-Exists').replace('{0}', '"' + itemName + '"'),
fileExists: null
}
};
dialog_1.createDialog(parent, 'Error', result_2);
}
var args = { action: 'create', error: result.error };
parent.trigger('failure', args);
}
else {
Eif (parent.dialogObj && parent.dialogObj.visible) {
parent.dialogObj.hide();
}
onFailure(parent, result, 'create');
}
}
}
catch (error) {
if (parent.dialogObj && parent.dialogObj.visible) {
parent.dialogObj.hide();
}
handleCatchError(parent, error, 'create');
}
}
/* istanbul ignore next */
/**
* Function to rename the folder/file in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {ReadArgs} result - specifies the result.
* @returns {void}
* @private
*/
function renameSuccess(parent, result) {
try {
if (!ej2_base_2.isNullOrUndefined(result.files)) {
if (!ej2_base_2.isNullOrUndefined(parent.dialogObj)) {
parent.dialogObj.hide();
}
var args = { action: 'rename', result: result };
parent.trigger('success', args);
parent.renamedItem = Array.isArray(result.files) ? result.files[0] : result.files;
var renameEventArgs = {
newName: parent.renamedItem.name,
itemData: [parent.renamedItem],
path: parent.path
};
parent.trigger('rename', renameEventArgs);
Iif (parent.activeModule === 'navigationpane') {
parent.pathId.pop();
parent.itemData = [ej2_base_2.getValue(parent.pathId[parent.pathId.length - 1], parent.feParent)];
read(parent, events.renameEndParent, ej2_base_2.getValue('filterPath', parent.renamedItem).replace(/\\/g, '/'));
parent.itemData[0] = parent.renamedItem;
if (ej2_base_2.getValue('filterPath', parent.renamedItem) === ej2_base_2.getValue('filterPath', parent.itemData[0]) && parent.pathNames.length > 1) {
parent.pathNames[parent.pathNames.length - 1] = parent.renameText;
}
read(parent, events.pathChanged, parent.path === '/' ? parent.path : ej2_base_2.getValue('filterPath', parent.renamedItem).replace(/\\/g, '/') + parent.renamedItem.name + '/');
parent.renamedItem = null;
}
else {
parent.itemData = [utility_1.getPathObject(parent)];
if (parent.breadcrumbbarModule.searchObj.value !== '') {
Search(parent, events.renameEnd, parent.path, parent.searchWord, parent.showHiddenItems, !parent.searchSettings.ignoreCase);
}
else {
Iif (parent.isFiltered) {
filter(parent, events.renameEnd);
}
else {
read(parent, events.renameEnd, parent.path);
}
}
}
}
else {
if (result.error.code === '400' && parent.dialogObj && parent.dialogObj.visible) {
var ele = ej2_base_1.select('#rename', parent.dialogObj.element);
var error = utility_1.getLocaleText(parent, 'Validation-Rename-Exists').replace('{0}', '"' + parent.currentItemText + '"');
error = error.replace('{1}', '"' + ele.value + '"');
ele.parentElement.nextElementSibling.innerHTML = error;
var args = { action: 'rename', error: result.error };
parent.trigger('failure', args);
}
else {
Eif (!ej2_base_2.isNullOrUndefined(parent.dialogObj)) {
parent.dialogObj.hide();
}
onFailure(parent, result, 'rename');
}
}
}
catch (error) {
if (!ej2_base_2.isNullOrUndefined(parent.dialogObj)) {
parent.dialogObj.hide();
}
handleCatchError(parent, error, 'rename');
}
}
/* istanbul ignore next */
/**
* Function to create new folder in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {ReadArgs} result - specifies the result.
* @param {string} path - specifies the path.
* @param {string} operation - specifies the operation.
* @returns {void}
* @private
*/
function pasteSuccess(parent, result, path, operation) {
try {
var moveorcopyEventArgs = {
itemData: result.files,
isCopy: operation === 'copy' ? true : false,
path: path,
targetData: parent.itemData[0],
targetPath: parent.path
};
parent.trigger('move', moveorcopyEventArgs);
if (result.error && result.error.fileExists) {
parent.fileLength = 0;
if (!ej2_base_2.isNullOrUndefined(result.files)) {
parent.isPasteError = true;
utility_1.doPasteUpdate(parent, operation, result);
}
dialog_1.createExtDialog(parent, 'DuplicateItems', result.error.fileExists);
if (result.error.code === '404') {
dialog_1.createDialog(parent, 'Error', result);
}
}
else if (!result.error && !ej2_base_2.isNullOrUndefined(result.files)) {
parent.isPasteError = false;
utility_1.doPasteUpdate(parent, operation, result);
}
else if (result.error && !ej2_base_2.isNullOrUndefined(result.files)) {
parent.isPasteError = true;
utility_1.doPasteUpdate(parent, operation, result);
dialog_1.createDialog(parent, 'Error', result);
}
else {
onFailure(parent, result, operation);
}
}
catch (error) {
handleCatchError(parent, error, operation);
}
}
/**
* Function to delete success in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {ReadArgs} result - specifies the result.
* @param {string} path - specifies the path.
* @returns {void}
* @private
*/
function deleteSuccess(parent, result, path) {
try {
var deleteEventArgs = {
itemData: result.files,
path: path
};
parent.trigger('delete', deleteEventArgs);
Eif (!ej2_base_2.isNullOrUndefined(result.files)) {
parent.setProperties({ path: path }, true);
parent.itemData = [utility_1.getPathObject(parent)];
read(parent, events.deleteEnd, parent.path);
Iif (result.error) {
onFailure(parent, result, 'delete');
}
else {
var args = { action: 'delete', result: result };
parent.trigger('success', args);
}
}
else {
onFailure(parent, result, 'delete');
}
}
catch (error) {
handleCatchError(parent, error, 'delete');
}
}
/**
* Function for details success in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {ReadArgs} result - specifies the result.
* @param {string} path - specifies the path.
* @param {string} operation - specifies the operation.
* @returns {void}
* @private
*/
function detailsSuccess(
// eslint:disable-next-line
parent, result, path, operation) {
try {
Eif (!ej2_base_2.isNullOrUndefined(result.details)) {
dialog_1.createDialog(parent, operation, null, result.details);
var args = { action: 'details', result: result };
parent.trigger('success', args);
}
else {
onFailure(parent, result, 'details');
}
}
catch (error) {
handleCatchError(parent, error, 'details');
}
}
/**
* Function for on failure event in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {ReadArgs} result - specifies the result.
* @param {string} action - specifies the action.
* @returns {void}
* @private
*/
function onFailure(parent, result, action) {
dialog_1.createDialog(parent, 'Error', result);
var args = { action: action, error: result.error };
parent.trigger('failure', args);
}
/**
* Function for search in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {string} event - specifies the event.
* @param {string} path - specifies the path.
* @param {string} searchString - specifies the search string.
* @param {boolean} showHiddenItems - specifies the hidden items.
* @param {boolean} caseSensitive - specifies the casing of search text.
* @returns {void}
* @private
*/
function Search(parent, event, path, searchString, showHiddenItems, caseSensitive) {
var data = {
action: 'search', path: path, searchString: searchString, showHiddenItems: showHiddenItems, caseSensitive: caseSensitive,
data: parent.itemData
};
createAjax(parent, data, searchSuccess, event);
}
exports.Search = Search;
/* istanbul ignore next */
/**
* Function for search success in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {ReadArgs} result - specifies the result.
* @param {string} event - specifies the event.
* @returns {void}
* @private
*/
function searchSuccess(parent, result, event) {
try {
Eif (!ej2_base_2.isNullOrUndefined(result.files)) {
parent.notify(event, result);
var args = { action: 'search', result: result };
parent.trigger('success', args);
}
else {
onFailure(parent, result, 'search');
}
}
catch (error) {
handleCatchError(parent, error, 'search');
}
}
/* istanbul ignore next */
/**
* Function for download in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {string} path - specifies the path.
* @param {string[]} items - specifies the items.
* @returns {void}
* @private
*/
function Download(parent, path, items) {
var downloadUrl = parent.ajaxSettings.downloadUrl ? parent.ajaxSettings.downloadUrl : parent.ajaxSettings.url;
var data = { 'action': 'download', 'path': path, 'names': items, 'data': parent.itemData };
var ajaxSettings = {
url: downloadUrl,
type: 'POST',
contentType: 'application/json',
responseType: 'blob',
data: JSON.stringify(data),
onSuccess: null,
onFailure: null,
beforeSend: null
};
var eventArgs = { data: data, cancel: false, useFormPost: true, ajaxSettings: ajaxSettings };
parent.trigger('beforeDownload', eventArgs, function (downloadArgs) {
if (!downloadArgs.cancel) {
if (downloadArgs.useFormPost) {
var form = ej2_base_1.createElement('form', {
id: parent.element.id + '_downloadForm',
attrs: { action: downloadUrl, method: 'post', name: 'downloadForm', 'download': '' }
});
var input = ej2_base_1.createElement('input', {
id: parent.element.id + '_hiddenForm',
attrs: { name: 'downloadInput', value: JSON.stringify(downloadArgs.data), type: 'hidden' }
});
form.appendChild(input);
parent.element.appendChild(form);
document.forms.namedItem('downloadForm').submit();
parent.element.removeChild(form);
}
else {
try {
var contentDisposition_1;
var fileName_1;
var fetch_1 = new ej2_base_1.Fetch({
url: ej2_base_2.getValue('url', downloadArgs.ajaxSettings),
type: ej2_base_2.getValue('type', downloadArgs.ajaxSettings),
contentType: ej2_base_2.getValue('contentType', downloadArgs.ajaxSettings),
responseType: ej2_base_2.getValue('responseType', downloadArgs.ajaxSettings),
beforeSend: ej2_base_2.getValue('beforeSend', downloadArgs.ajaxSettings),
onLoad: function (e) {
contentDisposition_1 = e.headers.get('Content-Disposition');
if (contentDisposition_1) {
var filenameMatch = contentDisposition_1.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
var extractedFilename = filenameMatch && filenameMatch[1];
fileName_1 = extractedFilename ? extractedFilename.replace(/['"]/g, '') : fileName_1;
}
else {
fileName_1 = parent.itemData.length > 1 ? 'files.zip' : ej2_base_2.getValue('isFile', parent.itemData[0]) ? ej2_base_2.getValue('name', parent.itemData[0]) : ej2_base_2.getValue('name', parent.itemData[0]) + '.zip';
}
},
onSuccess: function (e) {
parent.trigger('success', downloadArgs);
var blob = e;
var blobUrl = URL.createObjectURL(blob);
var link = document.createElement('a');
link.href = blobUrl;
link.download = fileName_1;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
},
onFailure: function (e) {
var result = {
error: {
code: e.status.toString(),
message: utility_1.getLocaleText(parent, 'Network-Error') + ' ' + parent.ajaxSettings.downloadUrl
}
};
dialog_1.createDialog(parent, 'Error', result);
parent.trigger('failure', downloadArgs);
}
});
fetch_1.send(JSON.stringify(downloadArgs.data));
}
catch (error) {
handleCatchError(parent, error, 'download');
}
}
}
});
}
exports.Download = Download;
/**
* Function for on catch handler in File Manager.
*
* @param {IFileManager} parent - specifies the parent element.
* @param {any} error - specifies the catch error.
* @param {string} action - specifies the action.
* @returns {void}
* @private
*/
function handleCatchError(parent, error, action) {
var errorResult = {
files: null,
error: {
message: error.message,
fileExists: null
}
};
onFailure(parent, errorResult, action);
}
});
|