@apia/uploader-controller 4.0.44

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/dist/index.js ADDED
@@ -0,0 +1,1502 @@
1
+ import { getLabel, toBoolean, EventEmitter, arrayOrArray, downloadUrl, addBoundary, formatMessage, parseAsSize } from '@apia/util';
2
+ import { makeObservable, observable } from 'mobx';
3
+ import QueryString from 'qs';
4
+ import { ApiaApi } from '@apia/api2';
5
+
6
+ var __defProp$1 = Object.defineProperty;
7
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField$1 = (obj, key, value) => {
9
+ __defNormalProp$1(obj, key + "" , value);
10
+ return value;
11
+ };
12
+ function getFileExtension(fileName) {
13
+ const parts = fileName.split(".");
14
+ return parts.length > 1 ? parts.pop().toLowerCase() : "";
15
+ }
16
+ const getInitialState = (execution) => Object.freeze({
17
+ metadata: {
18
+ metadataArray: [],
19
+ freeMetadataArray: [],
20
+ isFreeMetadata: false
21
+ },
22
+ fromDirectoryFile: null,
23
+ docFolder: void 0,
24
+ docPath: void 0,
25
+ docExpDate: void 0,
26
+ description: "",
27
+ isReadonly: false,
28
+ permissions: {
29
+ pools: [],
30
+ users: execution.ownerCanUpdate ? [
31
+ {
32
+ canUpdate: true,
33
+ userId: execution.currentUserLogin,
34
+ userLogin: execution.currentUserLogin
35
+ }
36
+ ] : [],
37
+ allowAllType: execution.everyoneCanUpdate !== false ? "M" : ""
38
+ },
39
+ fileReqError: false
40
+ });
41
+ class UploaderModalController {
42
+ constructor(api, modalConfig, conf) {
43
+ this.api = api;
44
+ this.modalConfig = modalConfig;
45
+ this.conf = conf;
46
+ __publicField$1(this, "state");
47
+ makeObservable(this, {
48
+ state: observable
49
+ });
50
+ this.state = getInitialState(api.props.context);
51
+ }
52
+ get allMetadata() {
53
+ return [
54
+ ...this.state.metadata.metadataArray,
55
+ ...this.state.metadata.freeMetadataArray
56
+ ];
57
+ }
58
+ get allowAllType() {
59
+ return this.state.permissions.allowAllType;
60
+ }
61
+ get description() {
62
+ return this.state.description;
63
+ }
64
+ get docFolder() {
65
+ return this.state.docFolder;
66
+ }
67
+ get docExpDate() {
68
+ return this.state.docExpDate;
69
+ }
70
+ get docTypes() {
71
+ return this.api.getDocTypes();
72
+ }
73
+ get freeMetadata() {
74
+ return this.state.metadata.freeMetadataArray;
75
+ }
76
+ get exitingFiles() {
77
+ return this.api.getExistingFiles();
78
+ }
79
+ get inProgressFiles() {
80
+ return this.api.getInProgressFiles();
81
+ }
82
+ get hiddenFiles() {
83
+ return this.api.getHiddenFiles();
84
+ }
85
+ get progress() {
86
+ return this.api.getProgress();
87
+ }
88
+ get metadata() {
89
+ return this.state.metadata.metadataArray;
90
+ }
91
+ get selectedDocTypeId() {
92
+ return this.api.getCurrentDocTypeId();
93
+ }
94
+ get selectedDocType() {
95
+ return this.api.getCurrentDocType();
96
+ }
97
+ addMetadata() {
98
+ this.state.metadata.freeMetadataArray.push({
99
+ free: "Y",
100
+ id: String(Math.random()),
101
+ name: "",
102
+ required: "Y",
103
+ title: "",
104
+ type: "S",
105
+ value: "",
106
+ errorMessage: "",
107
+ labelErrorMessage: ""
108
+ });
109
+ }
110
+ addFiles(files) {
111
+ this.state.fileReqError = false;
112
+ this.state.isReadonly = false;
113
+ this.api.saveDroppedFiles(files, this.conf);
114
+ }
115
+ addDirectoryFile(file) {
116
+ this.state.fileReqError = false;
117
+ this.api.state.inProgressFiles = [];
118
+ this.state.fromDirectoryFile = file;
119
+ }
120
+ async changeDocType(docTypeId) {
121
+ this.resetMetadata();
122
+ this.api.setCurrentDocTypeId(docTypeId);
123
+ this.onChangeExtension();
124
+ this.api.reloadMetadata({ docTypeId });
125
+ }
126
+ clearDirectoryFile() {
127
+ this.state.fromDirectoryFile = null;
128
+ this.state.isReadonly = false;
129
+ }
130
+ clearFile(name) {
131
+ this.api.clearFile(name);
132
+ }
133
+ clearFiles() {
134
+ this.api.clearFiles();
135
+ }
136
+ clearState() {
137
+ this.state = getInitialState(this.api.props.context);
138
+ this.api.clearState();
139
+ }
140
+ clearPartialState() {
141
+ if (this.api.state.inProgressFiles.length === 0) {
142
+ this.state = getInitialState(this.api.props.context);
143
+ }
144
+ }
145
+ onCloseModal() {
146
+ this.clearState();
147
+ }
148
+ async confirm() {
149
+ let isValid = this.validate();
150
+ if (isValid)
151
+ isValid = await this.api.confirmDropModal(this.conf);
152
+ return isValid;
153
+ }
154
+ deleteMetadata(indices) {
155
+ const deleteSet = new Set(indices);
156
+ const offset = this.state.metadata.metadataArray.length;
157
+ this.state.metadata.freeMetadataArray = this.state.metadata.freeMetadataArray.filter(
158
+ (_, localIndex) => (
159
+ // conservamos sólo los que NO estén en deleteSet
160
+ !deleteSet.has(localIndex + offset)
161
+ )
162
+ );
163
+ }
164
+ deletePermission(item) {
165
+ if (item && "userId" in item) {
166
+ this.state.permissions.users = this.state.permissions.users.filter(
167
+ (c) => c.userId !== item.userId
168
+ );
169
+ } else {
170
+ this.state.permissions.pools = this.state.permissions.pools.filter(
171
+ (c) => c.poolId !== item.poolId
172
+ );
173
+ }
174
+ }
175
+ onChangeExtension() {
176
+ const rawDocExts = this.api.getCurrentDocType()?.docExts || "";
177
+ let hideFileNames = "";
178
+ const allowedExtensions = rawDocExts.split(";").map((ext) => ext.trim()).filter((ext) => ext !== "");
179
+ if (rawDocExts === "") {
180
+ const allFiles = [...this.inProgressFiles, ...this.hiddenFiles];
181
+ const dedupedFiles = Array.from(
182
+ new Map(allFiles.map((file) => [file.name, file])).values()
183
+ );
184
+ this.api.state.inProgressFiles = dedupedFiles;
185
+ this.api.state.hiddenFiles = [];
186
+ return;
187
+ }
188
+ const allowedInProgress = [];
189
+ const toHide = [];
190
+ this.inProgressFiles.forEach((file) => {
191
+ const ext = getFileExtension(file.name);
192
+ if (allowedExtensions.includes(ext)) {
193
+ allowedInProgress.push(file);
194
+ } else {
195
+ toHide.push(file);
196
+ hideFileNames += ` ${file.name} `;
197
+ }
198
+ });
199
+ const allowedHidden = [];
200
+ const stillHidden = [];
201
+ this.api.state.hiddenFiles.forEach((file) => {
202
+ const ext = getFileExtension(file.name);
203
+ if (allowedExtensions.includes(ext)) {
204
+ allowedHidden.push(file);
205
+ } else {
206
+ stillHidden.push(file);
207
+ }
208
+ });
209
+ const combinedInProgress = [...allowedInProgress, ...allowedHidden];
210
+ const dedupedInProgress = Array.from(
211
+ new Map(
212
+ combinedInProgress.map((file) => [file.name, file])
213
+ ).values()
214
+ );
215
+ const combinedHidden = [...toHide, ...stillHidden];
216
+ const dedupedHidden = Array.from(
217
+ new Map(combinedHidden.map((file) => [file.name, file])).values()
218
+ );
219
+ this.api.state.inProgressFiles = dedupedInProgress;
220
+ this.api.state.hiddenFiles = dedupedHidden;
221
+ if (hideFileNames)
222
+ this.api.notify({
223
+ title: getLabel("msgFileWrngExt").text,
224
+ message: hideFileNames,
225
+ type: "warning"
226
+ });
227
+ }
228
+ async openModal() {
229
+ const a = "openUploaderModal";
230
+ import(
231
+ /* webpackInclude: /\.tsx?$/ */
232
+ `/src/static/files/${a}`
233
+ ).then((r) => {
234
+ r.default(this);
235
+ });
236
+ }
237
+ setDescription(desc) {
238
+ this.state.description = desc;
239
+ }
240
+ async resetMetadata() {
241
+ this.state.metadata = {
242
+ freeMetadataArray: [],
243
+ metadataArray: [],
244
+ isFreeMetadata: false
245
+ };
246
+ }
247
+ validate() {
248
+ let isValid = true;
249
+ this.state.fileReqError = false;
250
+ if (this.api.getInProgressFiles().length === 0 && !this.state.fromDirectoryFile) {
251
+ this.state.fileReqError = true;
252
+ isValid = false;
253
+ }
254
+ this.allMetadata.forEach((c) => {
255
+ if (c.required === "Y") {
256
+ if (c.name.trim() === "" && c.free === "Y") {
257
+ c.labelErrorMessage = getLabel("msgReqField").text;
258
+ isValid = false;
259
+ }
260
+ if (c.value.trim() === "") {
261
+ if (!c.errorMessage)
262
+ c.errorMessage = getLabel("msgReqField").text;
263
+ isValid = false;
264
+ }
265
+ }
266
+ });
267
+ return isValid;
268
+ }
269
+ }
270
+
271
+ var __defProp = Object.defineProperty;
272
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
273
+ var __publicField = (obj, key, value) => {
274
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
275
+ return value;
276
+ };
277
+ function returnExactlyTheSame(defaultParameters) {
278
+ return defaultParameters;
279
+ }
280
+ const parseFileDefinition = (context, fileDefinition, isSignRequired) => {
281
+ const { lock, isLocked, lockedBy, userLocking, ...file } = fileDefinition;
282
+ return {
283
+ ...file,
284
+ isLocked: isLocked === "true" || isLocked === true || toBoolean(lock) || file.locked === true,
285
+ isLockedByMe: (lockedBy || userLocking) === context.currentUserLogin,
286
+ isMarkedToSign: file.markedToSign || toBoolean(file.sign) || isSignRequired,
287
+ isVirtual: file.virtualDoc ?? false,
288
+ lockingUser: lockedBy || userLocking
289
+ };
290
+ };
291
+ class UploaderApi extends EventEmitter {
292
+ constructor(props) {
293
+ super();
294
+ this.props = props;
295
+ __publicField(this, "maxFiles", Infinity);
296
+ __publicField(this, "modalController", null);
297
+ __publicField(this, "allowTranslations", false);
298
+ __publicField(this, "langs");
299
+ __publicField(this, "currentConfiguration");
300
+ __publicField(this, "state", {
301
+ progress: 0,
302
+ allowedTypes: [],
303
+ selectedDocTypeId: "1",
304
+ versioningFile: null,
305
+ inProgressFiles: [],
306
+ files: {},
307
+ selectedFiles: [],
308
+ hiddenFiles: [],
309
+ translatedFiles: /* @__PURE__ */ new Map(),
310
+ hasAllDocTypes: false
311
+ });
312
+ __publicField(this, "getCheckSignatureParameters", returnExactlyTheSame);
313
+ __publicField(this, "getAjaxUploadFileStatusParameters", returnExactlyTheSame);
314
+ __publicField(this, "getAjaxUploadStartParameters", returnExactlyTheSame);
315
+ __publicField(this, "getConfirmDropModalParameters", returnExactlyTheSame);
316
+ __publicField(this, "getCheckLockDocumentParameters", returnExactlyTheSame);
317
+ __publicField(this, "getCheckWebDavLockParameters", returnExactlyTheSame);
318
+ __publicField(this, "getConfirmDropModalPostdata", returnExactlyTheSame);
319
+ __publicField(this, "getConfirmDropModalMetadataString", ({
320
+ metadata
321
+ }) => {
322
+ return metadata?.filter?.((current) => !!current.value).map((current) => `${current.id}~${current.type}~${current.value}`).join(";") ?? [];
323
+ });
324
+ __publicField(this, "getConfirmDropModalPermissionsString", ({
325
+ poolsPermissions,
326
+ usersPermissions
327
+ }) => {
328
+ let returnString = "";
329
+ poolsPermissions.forEach(
330
+ (current) => returnString = `${returnString}${returnString.length > 0 ? "&" : ""}docPoolId=${current.poolId}&docPoolName=${current.poolName}&docPermType${current.poolId}=${String(current.canUpdate)}`
331
+ );
332
+ usersPermissions.forEach(
333
+ (current) => returnString = `${returnString}${returnString.length > 0 ? "&" : ""}docUserId=${current.userId}&docUsrLogin=${current.userLogin}&docPermType${current.userId}=${String(current.canUpdate)}`
334
+ );
335
+ return returnString;
336
+ });
337
+ __publicField(this, "getConfirmDropModalAdditionalMetadataString", (additionalMetadata) => {
338
+ return Object.values(additionalMetadata).filter((current) => !!current?.value).map((current) => `${current.name}~${current.value}`).join(";");
339
+ });
340
+ __publicField(this, "getDeleteDocumentParameters", returnExactlyTheSame);
341
+ __publicField(this, "getClearTempFilesParameters", returnExactlyTheSame);
342
+ __publicField(this, "getDocumentInfoParameters", returnExactlyTheSame);
343
+ __publicField(this, "getDownloadMultipleDocumentsParameters", returnExactlyTheSame);
344
+ __publicField(this, "getEditDocumentParameters", returnExactlyTheSame);
345
+ __publicField(this, "getLockDocumentParameters", returnExactlyTheSame);
346
+ __publicField(this, "getMarkFileToSignParameters", returnExactlyTheSame);
347
+ __publicField(this, "getProcessDroppedFilesParameters", returnExactlyTheSame);
348
+ __publicField(this, "getProcessDroppedFilesPostdata", returnExactlyTheSame);
349
+ __publicField(this, "getReloadMetadataParameters", returnExactlyTheSame);
350
+ __publicField(this, "getSaveDroppedFilesParameters", returnExactlyTheSame);
351
+ __publicField(this, "parseFileDefinition", (file) => {
352
+ return {
353
+ ...parseFileDefinition(this.props.context, file, false),
354
+ canEdit: file.canEdit || file.canWrite,
355
+ canRead: file.canRead
356
+ };
357
+ });
358
+ makeObservable(this, {
359
+ state: observable
360
+ });
361
+ this.allowTranslations = props.type === "E" && !!this.props.context.docLangs;
362
+ this.langs = this.props.context.docLangs;
363
+ }
364
+ get filesArray() {
365
+ return Object.values(this.state.files);
366
+ }
367
+ get context() {
368
+ return this.props.context;
369
+ }
370
+ async init() {
371
+ await this.ajaxUploadStart();
372
+ await this.reloadMetadata({
373
+ docTypeId: this.state.selectedDocTypeId
374
+ });
375
+ await this.loadCurrentDocuments();
376
+ }
377
+ buildModalController(conf) {
378
+ return new UploaderModalController(this, this.props.modalConfig, conf);
379
+ }
380
+ async onStartUpload(files) {
381
+ if (this.props.modalConfig.oneClickUpload) {
382
+ await this.saveDroppedFiles(files ?? []);
383
+ } else {
384
+ if (files) {
385
+ const result = await this.saveDroppedFiles(files ?? []);
386
+ if (!result)
387
+ return;
388
+ }
389
+ this.modalController = this.buildModalController();
390
+ this.modalController.openModal();
391
+ }
392
+ }
393
+ async onTranslateUpload(conf, files) {
394
+ if (this.props.modalConfig.oneClickUpload) {
395
+ await this.saveDroppedFiles(files ?? [], conf);
396
+ } else {
397
+ await this.init();
398
+ let mustOpen = true;
399
+ if (files) {
400
+ const res = await this.saveDroppedFiles(files ?? [], conf);
401
+ if (!res) {
402
+ mustOpen = false;
403
+ }
404
+ }
405
+ if (mustOpen) {
406
+ this.modalController = this.buildModalController(conf);
407
+ this.modalController.openModal();
408
+ }
409
+ }
410
+ }
411
+ async onVersionUpload(file, conf = { newFiles: [] }) {
412
+ this.version(file, conf);
413
+ }
414
+ async autoLock() {
415
+ return new Promise((resolve) => {
416
+ resolve(false);
417
+ });
418
+ }
419
+ notify(notification) {
420
+ this.props.context.notify(notification);
421
+ }
422
+ getAjaxUrl() {
423
+ return this.props.context.URL_REQUEST_AJAX;
424
+ }
425
+ getDocTypes() {
426
+ return this.state.allowedTypes;
427
+ }
428
+ getCurrentDocTypeId() {
429
+ return this.state.selectedDocTypeId;
430
+ }
431
+ getCurrentDocType() {
432
+ return this.state.allowedTypes.find(
433
+ (c) => c.id === this.state.selectedDocTypeId
434
+ );
435
+ }
436
+ getInProgressFiles() {
437
+ return this.state.inProgressFiles;
438
+ }
439
+ getHiddenFiles() {
440
+ return this.state.hiddenFiles;
441
+ }
442
+ getExistingFiles() {
443
+ return this.state.files;
444
+ }
445
+ getProgress() {
446
+ return this.state.progress;
447
+ }
448
+ getHasAllDocTypes() {
449
+ return this.state.hasAllDocTypes;
450
+ }
451
+ async getDocumentInfo({
452
+ docId: apiId,
453
+ downloadDocId: docId
454
+ }, newElem) {
455
+ const id = apiId ? this.getDocument(apiId).docId : docId;
456
+ const result = await ApiaApi.post(
457
+ this.context,
458
+ this.getDocumentInfoParameters({
459
+ action: "getDocumentInfo",
460
+ isAjax: true,
461
+ docId: id,
462
+ newElem,
463
+ prefix: this.props.type,
464
+ ajaxUrl: this.getAjaxUrl()
465
+ })
466
+ );
467
+ if (result?.data) {
468
+ return result.data;
469
+ }
470
+ return null;
471
+ }
472
+ /**
473
+ * This method searches for the provided id in several places:
474
+ *
475
+ * If it's found in the current files, returns it.
476
+ * If not, it searches the provided docId in the translations map of each uploaded file.
477
+ */
478
+ getDocument(docId) {
479
+ if (this.state.files[docId]) {
480
+ return this.state.files[docId];
481
+ } else {
482
+ for (const map of this.state.translatedFiles.values()) {
483
+ for (const file of map.values()) {
484
+ if (file.docId === docId) {
485
+ return file;
486
+ }
487
+ }
488
+ }
489
+ }
490
+ return void 0;
491
+ }
492
+ updateDocument(docId, newValue) {
493
+ if (this.state.files[docId]) {
494
+ this.state.files[docId] = { ...this.getDocument(docId), ...newValue };
495
+ } else {
496
+ this.state.translatedFiles.forEach((innerMap) => {
497
+ innerMap.forEach((doc, langKey) => {
498
+ if (doc.docId === docId) {
499
+ innerMap.set(langKey, { ...doc, ...newValue });
500
+ }
501
+ });
502
+ });
503
+ }
504
+ }
505
+ deleteDocument(docId) {
506
+ if (this.state.files[docId]) {
507
+ delete this.state.files[docId];
508
+ } else {
509
+ this.state.translatedFiles.forEach((innerMap) => {
510
+ innerMap.forEach((doc, langKey) => {
511
+ if (doc.docId === docId) {
512
+ innerMap.delete(langKey);
513
+ }
514
+ });
515
+ });
516
+ }
517
+ }
518
+ clearFile(name) {
519
+ if (this.modalController) {
520
+ this.modalController.state.isReadonly = false;
521
+ }
522
+ this.state.inProgressFiles = this.state.inProgressFiles.filter(
523
+ (c) => c.name !== name
524
+ );
525
+ }
526
+ clearFiles() {
527
+ if (this.modalController) {
528
+ this.modalController.state.isReadonly = false;
529
+ }
530
+ this.state.inProgressFiles = [];
531
+ this.state.versioningFile = null;
532
+ this.state.hiddenFiles = [];
533
+ }
534
+ clearState() {
535
+ if (this.modalController) {
536
+ this.modalController.state.isReadonly = false;
537
+ }
538
+ this.state.selectedDocTypeId = this.getDocTypes().find(
539
+ (c) => String(c.id) === "1"
540
+ ) ? "1" : this.getDocTypes()[0]?.id;
541
+ this.state.inProgressFiles = [];
542
+ this.state.versioningFile = null;
543
+ }
544
+ async checkLockDocument(id, shouldNotifyUnlocked = true) {
545
+ if (this.props.context.IN_MONITOR) {
546
+ return false;
547
+ }
548
+ const file = this.getDocument(id);
549
+ if (Number(file.docId) < 0)
550
+ return true;
551
+ const result = await ApiaApi.post(
552
+ this.context,
553
+ this.getCheckLockDocumentParameters({
554
+ action: "checkLockDocument",
555
+ docId: file.docId,
556
+ ajaxUrl: this.getAjaxUrl(),
557
+ prefix: this.props.type
558
+ })
559
+ );
560
+ const isLocked = result?.data?.success === "ok";
561
+ if (!isLocked && result?.data?.usr && result.data.usr !== this.props.context.currentUserLogin) {
562
+ this.notify({
563
+ message: `${getLabel("msgDocLockedByUsr", {}, this.props.context).text.split(".")[0]}: ${result.data.usr}.`,
564
+ type: "warning"
565
+ });
566
+ return result.data.usr;
567
+ }
568
+ if (!isLocked && shouldNotifyUnlocked && !await this.autoLock())
569
+ this.notify({
570
+ message: getLabel("msgDocMustBeLocked", {}, this.props.context).text,
571
+ type: "warning"
572
+ });
573
+ return isLocked;
574
+ }
575
+ setCurrentDocTypeId(docTypeId) {
576
+ this.state.selectedDocTypeId = docTypeId;
577
+ }
578
+ async ajaxUploadStart(newFiles = []) {
579
+ if (this.props.context.IN_MONITOR) {
580
+ return;
581
+ }
582
+ const versioningFile = this.state.versioningFile;
583
+ const res = await ApiaApi.post(
584
+ this.context,
585
+ this.getAjaxUploadStartParameters({
586
+ action: "ajaxUploadStart",
587
+ isAjax: true,
588
+ docId: versioningFile?.docId,
589
+ prefix: this.props.type,
590
+ docTypeId: newFiles.length === 1 ? versioningFile?.docTypeId || "1" : "1",
591
+ newDoc: !versioningFile,
592
+ useDocTypePermitted: true,
593
+ docTypePermittedObjType: this.props.type,
594
+ // docTypePermittedObjId: this.docTypePermittedObjId, // How do I find this?
595
+ ajaxUrl: this.getAjaxUrl()
596
+ })
597
+ );
598
+ if (res?.data) {
599
+ const docTypes = arrayOrArray(res?.data?.function?.docTypes?.docType);
600
+ const hasGeneric = !!docTypes.find((c) => String(c.id) === "1");
601
+ this.state.allowedTypes = docTypes;
602
+ this.state.selectedDocTypeId = hasGeneric ? "1" : docTypes[0].id;
603
+ if (newFiles.length > 0) {
604
+ await this.saveDroppedFiles(newFiles);
605
+ }
606
+ return res?.data?.function.name === "fncDocumentLoadInformation" ? true : false;
607
+ } else {
608
+ throw new Error("No files data");
609
+ }
610
+ }
611
+ async reloadMetadata(props, additionalProps) {
612
+ if (!this.modalController)
613
+ return;
614
+ const res = await ApiaApi.post(
615
+ this.context,
616
+ this.getReloadMetadataParameters({
617
+ ajaxUrl: this.getAjaxUrl(),
618
+ action: "reloadMetadata",
619
+ isAjax: true,
620
+ docId: props?.docId,
621
+ docTypeId: props?.docTypeId,
622
+ metadata: this.getConfirmDropModalMetadataString({
623
+ metadata: this.modalController?.allMetadata
624
+ }),
625
+ prefix: this.props.type,
626
+ ...additionalProps
627
+ })
628
+ );
629
+ if (res?.data && props?.docTypeId) {
630
+ const isFreeMetadata = this.state.allowedTypes.find(
631
+ (current) => current.id === props.docTypeId
632
+ )?.free ?? false;
633
+ this.modalController.state.metadata.metadataArray = arrayOrArray(
634
+ res.data.metadata
635
+ );
636
+ this.modalController.state.metadata.isFreeMetadata = isFreeMetadata;
637
+ }
638
+ }
639
+ async saveDroppedFiles(unprocessedFiles, conf) {
640
+ if (this.props.context.IN_MONITOR) {
641
+ return false;
642
+ }
643
+ const {
644
+ langId,
645
+ strictMode: isConfStrictMode = false,
646
+ translatingFile
647
+ } = conf ?? {};
648
+ const isStrictMode = isConfStrictMode || !!this.state.versioningFile || !!this.modalController?.state.fromDirectoryFile;
649
+ const docType = this.getCurrentDocTypeId();
650
+ if (!isStrictMode && !docType) {
651
+ this.notify({
652
+ message: `${getLabel("lblDropFileDeleted", {}, this.props.context).text}: ${unprocessedFiles.map((current) => current.name).join(", ")}.`,
653
+ type: "warning"
654
+ });
655
+ return false;
656
+ }
657
+ const allowedFiles = this.filterAlreadyUploadedFiles(
658
+ this.filterByFilesAmountLimit(
659
+ this.filterAcceptedFiles(
660
+ this.filterExistingFiles(
661
+ this.filterVersioningFiles(unprocessedFiles, conf),
662
+ conf
663
+ ),
664
+ true,
665
+ docType
666
+ )
667
+ ),
668
+ conf
669
+ );
670
+ if (allowedFiles.length > 0) {
671
+ const formData = new FormData();
672
+ allowedFiles.forEach(
673
+ (file) => formData.append("fileRepository", file, file.name)
674
+ );
675
+ await ApiaApi.post(
676
+ this.context,
677
+ this.getSaveDroppedFilesParameters({
678
+ action: "saveDroppedFiles",
679
+ docId: this.state.versioningFile?.docId,
680
+ ajaxUrl: this.getAjaxUrl(),
681
+ elemType: this.props.type,
682
+ elemId: `prmDocumentContainter${this.props.type}`,
683
+ frmOut: !this.modalController,
684
+ docTypeId: this.state.selectedDocTypeId,
685
+ langId
686
+ }),
687
+ {
688
+ postData: formData,
689
+ axiosConfig: {
690
+ onUploadProgress: (ev) => this.state.progress = ev.loaded * 100 / ((ev.total ?? ev.loaded) * 2)
691
+ }
692
+ }
693
+ );
694
+ const ajaxUploadFileStatusParameters = this.getAjaxUploadFileStatusParameters({
695
+ action: "ajaxUploadFileStatus",
696
+ ajaxUrl: this.getAjaxUrl(),
697
+ delayForDrop: true,
698
+ isAjax: true,
699
+ prefix: this.props.type
700
+ });
701
+ let tries = 0;
702
+ const checkUploadResult = async () => {
703
+ return new Promise(async (resolve) => {
704
+ tries += 1;
705
+ if (tries === 10) {
706
+ this.notify({
707
+ message: "Error while checking for uploadFileStatus, too many tries",
708
+ type: "error"
709
+ });
710
+ resolve(false);
711
+ return;
712
+ }
713
+ const response = await ApiaApi.post(
714
+ this.context,
715
+ ajaxUploadFileStatusParameters
716
+ );
717
+ if (response && response.data) {
718
+ const hasMessages = arrayOrArray(
719
+ response.data?.sysMessages?.message ?? response.data?.sysExceptions?.exception ?? response.data?.exceptions?.exception ?? response.data.function.messages?.message
720
+ ).length > 0 || !!response.data.function.dropLastMessage;
721
+ const uploadMessage = arrayOrArray(
722
+ response.data.function.messages?.message
723
+ ).find((current) => current.name === "message");
724
+ if (uploadMessage)
725
+ this.notify({ message: uploadMessage.label, type: "warning" });
726
+ const method = response.data?.function.name;
727
+ this.state.progress = 44;
728
+ if (hasMessages) {
729
+ resolve(false);
730
+ return;
731
+ }
732
+ if (method === "fncProceedDocumentProcessing") {
733
+ resolve(true);
734
+ return;
735
+ }
736
+ if (tries === 10) {
737
+ resolve(method === "fncProceedDocumentProcessing");
738
+ }
739
+ setTimeout(() => {
740
+ checkUploadResult().then(resolve).catch(() => resolve(false));
741
+ }, 100);
742
+ } else {
743
+ resolve(false);
744
+ }
745
+ });
746
+ };
747
+ const hasUploadedCorrectly = await checkUploadResult();
748
+ this.state.progress = 66;
749
+ if (hasUploadedCorrectly) {
750
+ const shown = (this.state.inProgressFiles ?? []).map(
751
+ (file) => file.name
752
+ );
753
+ const postData = QueryString.stringify(
754
+ this.getProcessDroppedFilesPostdata({
755
+ useDocTypePermitted: true,
756
+ // docTypePermittedObjId: this.docTypePermittedObjId?.toString(), // How do I get this?
757
+ docTypePermittedObjType: this.props.type,
758
+ dropped: allowedFiles.map((file) => file.name).concat(shown),
759
+ shown
760
+ }),
761
+ { arrayFormat: "repeat" }
762
+ );
763
+ const secondResult = await ApiaApi.post(
764
+ this.context,
765
+ this.getProcessDroppedFilesParameters({
766
+ action: "processDroppedFiles",
767
+ elemType: this.props.type,
768
+ docId: this.state.versioningFile?.docId,
769
+ frmOut: !this.modalController,
770
+ ajaxUrl: this.getAjaxUrl()
771
+ }),
772
+ {
773
+ postData: postData.toString()
774
+ }
775
+ );
776
+ this.state.progress = 83;
777
+ if (secondResult?.data?.function?.principal?.docInfo) {
778
+ const acceptedByServerFiles = arrayOrArray(
779
+ secondResult.data.function?.principal?.docInfo
780
+ );
781
+ this.state.inProgressFiles = [
782
+ ...this.state.inProgressFiles ?? [],
783
+ ...acceptedByServerFiles.map(
784
+ (current) => [...this.state.inProgressFiles, ...unprocessedFiles].find(
785
+ (search) => search.name === current.docInfoName
786
+ )
787
+ ).filter((current) => !!current)
788
+ ];
789
+ this.state.progress = 100;
790
+ if (this.modalController)
791
+ this.modalController.state.fromDirectoryFile = null;
792
+ this.notify({
793
+ type: "success",
794
+ message: getLabel(
795
+ "lblFileUploadedSuccessfully",
796
+ {},
797
+ this.props.context
798
+ ).text
799
+ });
800
+ if (this.props.modalConfig.oneClickUpload) {
801
+ if (langId && translatingFile)
802
+ void this.confirmDropModal({ langId, translatingFile });
803
+ else
804
+ void this.confirmDropModal();
805
+ }
806
+ }
807
+ }
808
+ this.state.progress = 100;
809
+ return true;
810
+ } else {
811
+ return false;
812
+ }
813
+ }
814
+ async checkWebDavLock(docId) {
815
+ if (this.props.context.IN_MONITOR) {
816
+ return false;
817
+ }
818
+ return new Promise((resolve) => {
819
+ let tries = 10;
820
+ const checkLockAction = async () => {
821
+ const isLocked = await ApiaApi.post(
822
+ this.context,
823
+ this.getCheckWebDavLockParameters({
824
+ action: "isWebDavDocumentLocked",
825
+ docId,
826
+ ajaxUrl: this.props.context.URL_REQUEST_AJAX
827
+ })
828
+ );
829
+ if (isLocked?.data?.locked === true || isLocked?.data?.locked === void 0) {
830
+ if (--tries > 0) {
831
+ setTimeout(() => void checkLockAction(), 1e3);
832
+ } else {
833
+ this.notify({
834
+ message: getLabel("msgFailSyncDocument", {}, this.props.context).text
835
+ });
836
+ resolve(false);
837
+ }
838
+ } else {
839
+ resolve(true);
840
+ }
841
+ };
842
+ void checkLockAction();
843
+ });
844
+ }
845
+ async checkSignature(file) {
846
+ let res = null;
847
+ if (Number(file.docId) >= 0)
848
+ res = await ApiaApi.get(
849
+ this.context,
850
+ this.getCheckSignatureParameters({
851
+ action: "viewDocSigns",
852
+ docId: file.docId,
853
+ lock: false,
854
+ isAjax: true,
855
+ prefix: this.props.type,
856
+ react: true
857
+ })
858
+ );
859
+ return res;
860
+ }
861
+ async editDocument(id) {
862
+ if (this.props.context.IN_MONITOR) {
863
+ return;
864
+ }
865
+ const file = this.getDocument(id);
866
+ if (await this.checkLockDocument(file.docId) === true) {
867
+ const result = await ApiaApi.post(
868
+ this.context,
869
+ this.getEditDocumentParameters({
870
+ action: "updateWebDavDocument",
871
+ docId: file.docId,
872
+ prefix: this.props.type,
873
+ isAjax: true
874
+ })
875
+ );
876
+ if (result?.data?.folderId) {
877
+ const sDocumentUrl = `${this.props.context.WEBDAV_SERVER}${result?.data?.folderId}/${file.docId}/${file.name || file.docName || ""}`;
878
+ const ProtocolInstallMessage = () => {
879
+ this.notify({
880
+ type: "warning",
881
+ message: getLabel("msgNoDocEditProtocol", {}, this.props.context).text,
882
+ title: getLabel("lblEdit", {}, this.props.context).text
883
+ });
884
+ };
885
+ this.props.context.ITHit.WebDAV.Client.DavConstants.ProtocolTimeoutMs = 1e4;
886
+ await this.props.context.ITHit.WebDAV.Client.DocManager.DavProtocolEditDocument(
887
+ sDocumentUrl,
888
+ this.props.context.WEBDAV_SERVER,
889
+ ProtocolInstallMessage,
890
+ null,
891
+ "Current",
892
+ "ApiaWebDavCookie",
893
+ // Cookie(s) to copy.
894
+ "",
895
+ // URL to navigate to if any cookie from the list is not found.
896
+ "Edit"
897
+ );
898
+ }
899
+ }
900
+ }
901
+ async downloadVersion(fileId, version) {
902
+ const file = this.getDocument(fileId);
903
+ if (!file)
904
+ return;
905
+ if (this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId))
906
+ await downloadUrl(
907
+ ApiaApi.makeUrl(this.context, {
908
+ action: "downloadDocument",
909
+ docId: file.downloadDocId,
910
+ version
911
+ })
912
+ );
913
+ }
914
+ async downloadDocument(id, version) {
915
+ const file = this.getDocument(id);
916
+ if (this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId)) {
917
+ await downloadUrl(
918
+ ApiaApi.makeUrl(this.context, {
919
+ action: "downloadDocument",
920
+ prefix: this.props.type,
921
+ docId: file.downloadDocId,
922
+ ajaxUrl: this.getAjaxUrl(),
923
+ version
924
+ })
925
+ );
926
+ }
927
+ }
928
+ async ajaxDeleteDocument(id, langId) {
929
+ const file = this.getDocument(id);
930
+ const isLocked = await this.checkLockDocument(file.docId);
931
+ if (isLocked === true) {
932
+ const result = await ApiaApi.post(
933
+ this.context,
934
+ this.getDeleteDocumentParameters({
935
+ action: "ajaxRemoveDocument",
936
+ docId: file.docId,
937
+ isAjax: true,
938
+ prefix: this.props.type,
939
+ ajaxUrl: this.getAjaxUrl(),
940
+ langId
941
+ })
942
+ );
943
+ if (this.evaluateDeleteDocumentResult(result?.data))
944
+ this.deleteDocument(id);
945
+ }
946
+ }
947
+ async version(file, conf = { newFiles: [] }) {
948
+ const checkLock = await this.checkLockDocument(file.docId, true);
949
+ const isLocked = await this.checkWebDavLock(file.docId);
950
+ if (!(checkLock === true && isLocked))
951
+ return;
952
+ this.state.versioningFile = file;
953
+ const openVersionModal = () => {
954
+ if (!this.props.modalConfig.oneClickUpload) {
955
+ this.modalController = this.buildModalController({
956
+ versionFile: file
957
+ });
958
+ this.modalController.openModal();
959
+ }
960
+ };
961
+ if (!conf.newFiles || conf.newFiles.length === 0) {
962
+ openVersionModal();
963
+ }
964
+ await this.ajaxUploadStart();
965
+ if (file.docTypeId)
966
+ this.state.selectedDocTypeId = file.docTypeId;
967
+ await this.versionFileInfo(file);
968
+ const hasNewFiles = !!(conf.newFiles && conf.newFiles.length > 0);
969
+ if (hasNewFiles) {
970
+ const res = await this.saveDroppedFiles(conf.newFiles, {
971
+ langId: conf.langId,
972
+ translatingFile: conf.translatingFile,
973
+ shouldReset: false,
974
+ strictMode: true
975
+ });
976
+ if (res) {
977
+ openVersionModal();
978
+ }
979
+ } else {
980
+ await this.reloadMetadata({
981
+ docId: file.docId,
982
+ docTypeId: file.docTypeId
983
+ });
984
+ }
985
+ }
986
+ async versionFileInfo(file) {
987
+ const documentInfo = await this.getDocumentInfo({ docId: file.docId });
988
+ if (documentInfo?.function) {
989
+ const {
990
+ data: { general },
991
+ metadatas
992
+ } = documentInfo.function;
993
+ const isFreeMetadata = this.state.allowedTypes.find((current) => current.id === file.docTypeId)?.free ?? false;
994
+ if (this.modalController) {
995
+ this.modalController.state = {
996
+ description: general.docDesc,
997
+ docFolder: general.docFolder === "" ? void 0 : Number(general.docFolder),
998
+ docPath: general.docFolderPath,
999
+ permissions: {
1000
+ allowAllType: general.docAllPoolPerm,
1001
+ users: arrayOrArray(
1002
+ documentInfo.function.data.permissions?.user
1003
+ ).map((current) => {
1004
+ const returnObject = {
1005
+ canUpdate: current.permType === "M",
1006
+ userId: current.id,
1007
+ userLogin: current.name
1008
+ };
1009
+ return returnObject;
1010
+ }),
1011
+ pools: arrayOrArray(
1012
+ documentInfo.function.data.permissions?.pool
1013
+ ).map((current) => {
1014
+ const returnObject = {
1015
+ canUpdate: current.permType === "M",
1016
+ poolId: current.id,
1017
+ poolName: current.name
1018
+ };
1019
+ return returnObject;
1020
+ })
1021
+ },
1022
+ docExpDate: general.docExpDate,
1023
+ fileReqError: false,
1024
+ fromDirectoryFile: null,
1025
+ metadata: {
1026
+ metadataArray: arrayOrArray(metadatas?.metadata),
1027
+ freeMetadataArray: [],
1028
+ isFreeMetadata
1029
+ }
1030
+ };
1031
+ }
1032
+ }
1033
+ }
1034
+ async pickFileById(id) {
1035
+ const documentInfo = await this.getDocumentInfo(
1036
+ { downloadDocId: id },
1037
+ true
1038
+ );
1039
+ if (documentInfo) {
1040
+ const document = documentInfo.function.data.general;
1041
+ const { permissions } = documentInfo.function.data;
1042
+ if (this.modalController) {
1043
+ this.setCurrentDocTypeId(document.docTypeId);
1044
+ this.modalController.addDirectoryFile(document);
1045
+ this.modalController.state.description = document.docDesc;
1046
+ this.modalController.state.docExpDate = document.docExpDate;
1047
+ this.modalController.state.permissions = {
1048
+ pools: arrayOrArray(permissions?.pool).map((c) => {
1049
+ return {
1050
+ poolId: c.id,
1051
+ poolName: c.name,
1052
+ canUpdate: c.permType === "M"
1053
+ };
1054
+ }),
1055
+ users: [
1056
+ ...arrayOrArray(permissions?.user).map((c) => {
1057
+ return {
1058
+ userId: c.id,
1059
+ userLogin: c.name,
1060
+ canUpdate: c.permType === "M"
1061
+ };
1062
+ })
1063
+ ],
1064
+ allowAllType: document.docAllPoolPerm
1065
+ };
1066
+ this.modalController.changeDocType(document.docTypeId);
1067
+ this.modalController.state.isReadonly = !documentInfo.function.currentUsrPems.usrCanModify;
1068
+ }
1069
+ void this.reloadMetadata(
1070
+ { docId: document.docId, docTypeId: document.docTypeId },
1071
+ {
1072
+ docReuse: true
1073
+ }
1074
+ );
1075
+ }
1076
+ }
1077
+ async markFileToSign(id, langId) {
1078
+ if (this.props.context.IN_MONITOR) {
1079
+ return;
1080
+ }
1081
+ const file = this.getDocument(id);
1082
+ if (await this.checkLockDocument(file.docId) === true) {
1083
+ const marked = await ApiaApi.post(
1084
+ this.context,
1085
+ this.getMarkFileToSignParameters({
1086
+ action: "markDocTosign",
1087
+ docId: file.docId,
1088
+ isAjax: true,
1089
+ prefix: this.props.type,
1090
+ ajaxUrl: this.getAjaxUrl(),
1091
+ langId
1092
+ })
1093
+ );
1094
+ if (marked?.data?.markedToSign !== void 0) {
1095
+ if (this.state.files[id]) {
1096
+ this.state.files[id].markedToSign = marked.data.markedToSign;
1097
+ } else {
1098
+ this.state.translatedFiles.forEach((innerMap) => {
1099
+ innerMap.forEach((doc, langKey) => {
1100
+ if (doc.docId === id) {
1101
+ innerMap.set(langKey, {
1102
+ ...doc,
1103
+ markedToSign: marked?.data?.markedToSign ?? false
1104
+ });
1105
+ }
1106
+ });
1107
+ });
1108
+ }
1109
+ }
1110
+ }
1111
+ }
1112
+ /**
1113
+ * Por el momento realiza la descarga de todos los archivos
1114
+ * que estén subidos.
1115
+ */
1116
+ downloadMultipleDocuments() {
1117
+ const files = this.filesArray;
1118
+ if (files.length === 0)
1119
+ return;
1120
+ const docIds = this.state.selectedFiles;
1121
+ const selectedFiles = files.filter(
1122
+ (current) => docIds.find((search) => search === current.docId)
1123
+ );
1124
+ const ids = (selectedFiles.length > 0 ? selectedFiles : files).map((current) => current.downloadDocId).join("-");
1125
+ void downloadUrl(
1126
+ ApiaApi.makeUrl(
1127
+ this.context,
1128
+ this.getDownloadMultipleDocumentsParameters({
1129
+ action: "multipleDownload",
1130
+ docId: ids,
1131
+ prefix: this.props.type
1132
+ })
1133
+ ),
1134
+ "documents.zip"
1135
+ );
1136
+ }
1137
+ async confirmDropModal(conf) {
1138
+ if (this.props.context.IN_MONITOR) {
1139
+ return false;
1140
+ }
1141
+ const { langId, translatingFile } = conf ?? {};
1142
+ const cmbDocType = this.state.selectedDocTypeId;
1143
+ const fromDirectoryFile = this.modalController?.state.fromDirectoryFile;
1144
+ const docDesc = this.modalController?.description ?? "";
1145
+ const docAllowAllType = this.props.modalConfig.oneClickUpload ? "M" : this.modalController?.allowAllType ?? "";
1146
+ const docFolder = this.modalController?.docFolder;
1147
+ const docExpDate = this.modalController?.docExpDate;
1148
+ const metadata = this.modalController?.metadata ?? [];
1149
+ const freeMetadata = this.modalController?.freeMetadata ?? [];
1150
+ const poolsPermissions = this.modalController?.state.permissions.pools ?? [];
1151
+ const usersPermissions = this.modalController?.state.permissions.users ?? [];
1152
+ let postData = QueryString.stringify(
1153
+ this.getConfirmDropModalPostdata({
1154
+ cmbDocType,
1155
+ docDesc,
1156
+ docAllowAllType,
1157
+ // pe: this.docTypePermittedObjId?.toString(), // How do I get this?
1158
+ dropped: this.state.inProgressFiles.map((file) => file.name),
1159
+ txtLangId: langId,
1160
+ txtLangGroup: translatingFile?.docLangGroup,
1161
+ docFolder
1162
+ }),
1163
+ { arrayFormat: "repeat" }
1164
+ );
1165
+ postData = `${postData}${postData.length > 0 ? "&" : ""}${this.getConfirmDropModalPermissionsString({
1166
+ poolsPermissions,
1167
+ usersPermissions
1168
+ })}&txtFreeMetadata=${this.getConfirmDropModalAdditionalMetadataString(
1169
+ freeMetadata
1170
+ )}&txtMetadata=${this.getConfirmDropModalMetadataString({
1171
+ metadata: Object.values(metadata || {})
1172
+ })}&docExpDate=${docExpDate ?? ""}`;
1173
+ const result = await ApiaApi.post(
1174
+ this.context,
1175
+ this.getConfirmDropModalParameters({
1176
+ ajaxUrl: this.getAjaxUrl(),
1177
+ docId: fromDirectoryFile ? fromDirectoryFile.docId : this.state.versioningFile?.docId,
1178
+ action: fromDirectoryFile ? "associateExistingFile" : "confirmDropModal",
1179
+ elemType: this.props.type,
1180
+ fromForm: true,
1181
+ ...fromDirectoryFile ? {
1182
+ docId: fromDirectoryFile.docId,
1183
+ fromReuse: true,
1184
+ uploadDocument: false
1185
+ } : null
1186
+ }),
1187
+ {
1188
+ postData: postData.toString()
1189
+ }
1190
+ );
1191
+ if (result?.data?.function) {
1192
+ const currentFiles = { ...this.state.files };
1193
+ const versioningFile = this.state.versioningFile;
1194
+ if (versioningFile && versioningFile.name) {
1195
+ delete currentFiles[versioningFile.name];
1196
+ }
1197
+ const newFiles = arrayOrArray(
1198
+ result.data.function.general
1199
+ ).map(
1200
+ (current) => this.parseFileDefinition({
1201
+ ...current,
1202
+ canWrite: true,
1203
+ canRead: true,
1204
+ canEdit: true
1205
+ })
1206
+ ).filter((current) => !currentFiles[current.docId]).reduce((acc, current) => ({ ...acc, [current.docId]: current }), {});
1207
+ if (langId && translatingFile) {
1208
+ const firstFile = Object.values(newFiles)[0];
1209
+ this.setTranslationFile(firstFile, translatingFile.docId, langId);
1210
+ } else {
1211
+ this.state.files = { ...currentFiles, ...newFiles };
1212
+ }
1213
+ this.clearFiles();
1214
+ this.emit("fileUploaded", null);
1215
+ return true;
1216
+ }
1217
+ return false;
1218
+ }
1219
+ async loadCurrentDocuments() {
1220
+ const result = await ApiaApi.post(
1221
+ this.context,
1222
+ {
1223
+ ajaxUrl: this.getAjaxUrl(),
1224
+ action: "ajaxLoadCurrent",
1225
+ isAjax: true,
1226
+ readOnly: this.props.context.readonly,
1227
+ allowLock: true,
1228
+ allowSign: true,
1229
+ allowMultiple: true,
1230
+ prefix: this.props.type
1231
+ },
1232
+ {}
1233
+ );
1234
+ if (result && result.data) {
1235
+ const currentConfiguration = arrayOrArray(result.data.function.messages.message).reduce(
1236
+ (prev, { name, label }) => ({ ...prev, [name]: Boolean(label) }),
1237
+ {}
1238
+ );
1239
+ const currentFiles = result.data.function.general ? arrayOrArray(result.data.function.general).map(
1240
+ this.parseFileDefinition
1241
+ ) : [];
1242
+ this.currentConfiguration = currentConfiguration;
1243
+ const nonTranslationFiles = [];
1244
+ const translationFiles = [];
1245
+ currentFiles.forEach((current) => {
1246
+ if (current.docLang === void 0)
1247
+ nonTranslationFiles.push(current);
1248
+ else
1249
+ translationFiles.push(current);
1250
+ });
1251
+ nonTranslationFiles.forEach((c) => {
1252
+ this.state.files[c.docId] = c;
1253
+ });
1254
+ translationFiles.forEach((current) => {
1255
+ const originalFile = nonTranslationFiles.find(
1256
+ (search) => search.docLangGroup === current.docLangGroup
1257
+ );
1258
+ if (originalFile && current.docLang !== void 0) {
1259
+ this.setTranslationFile(
1260
+ current,
1261
+ originalFile.docId,
1262
+ Number(current.docLang)
1263
+ );
1264
+ } else
1265
+ console.warn(
1266
+ `The following file is translated but has no orignal file`,
1267
+ current,
1268
+ nonTranslationFiles
1269
+ );
1270
+ });
1271
+ }
1272
+ }
1273
+ async lockDocument(id) {
1274
+ if (this.props.context.IN_MONITOR) {
1275
+ return;
1276
+ }
1277
+ const file = this.getDocument(id);
1278
+ if (file.markedToSign) {
1279
+ this.notify({
1280
+ message: getLabel("lblCantUnlockMarkedToSign", {}, this.props.context).text,
1281
+ type: "warning"
1282
+ });
1283
+ return;
1284
+ }
1285
+ if (!file.isLocked || !file.isLockedByMe) {
1286
+ const isLocked = await this.checkLockDocument(file.docId, false);
1287
+ this.updateDocument(
1288
+ id,
1289
+ typeof isLocked === "string" ? this.parseFileDefinition({
1290
+ ...file,
1291
+ userLocking: isLocked,
1292
+ lock: true,
1293
+ isLocked: true,
1294
+ lockedBy: isLocked
1295
+ }) : { ...file, isLocked }
1296
+ );
1297
+ }
1298
+ const result = await ApiaApi.post(
1299
+ this.context,
1300
+ this.getLockDocumentParameters({
1301
+ action: "lockDocument",
1302
+ ajaxUrl: this.getAjaxUrl(),
1303
+ docId: file.docId,
1304
+ lock: file.isLocked || file.locked,
1305
+ isAjax: true,
1306
+ prefix: this.props.type
1307
+ })
1308
+ );
1309
+ if (result?.data) {
1310
+ const resultFile = result.data.function?.data?.general;
1311
+ if (resultFile)
1312
+ this.updateDocument(
1313
+ resultFile.docId,
1314
+ this.parseFileDefinition({
1315
+ ...file,
1316
+ ...resultFile,
1317
+ isLocked: resultFile.locked
1318
+ })
1319
+ );
1320
+ }
1321
+ }
1322
+ evaluateDeleteDocumentResult(result) {
1323
+ return result?.function?.name === "fncDocumentRemove";
1324
+ }
1325
+ setTranslationFile(file, docId, langId) {
1326
+ if (!this.state.translatedFiles.has(docId)) {
1327
+ this.state.translatedFiles.set(docId, /* @__PURE__ */ new Map());
1328
+ }
1329
+ this.state.translatedFiles.get(docId)?.set(langId, file);
1330
+ }
1331
+ filterAlreadyUploadedFiles(files, conf) {
1332
+ const versioningFile = this.state.versioningFile;
1333
+ if (versioningFile)
1334
+ return files;
1335
+ const uploadedFiles = Object.values(this.state.files).filter(
1336
+ (file) => Number(file.docId) > 0
1337
+ );
1338
+ const existingFiles = [];
1339
+ const nonExistingFiles = [];
1340
+ if (conf?.langId) {
1341
+ const docId = conf.translatingFile?.docId ?? Infinity;
1342
+ const translationsMap = this.state.translatedFiles.get(String(docId));
1343
+ const alreadyUploadedToTranslationsFile = translationsMap ? Array.from(translationsMap.values()).find(
1344
+ (current) => (current.docName || current.name) === files[0]?.name
1345
+ ) : void 0;
1346
+ if (alreadyUploadedToTranslationsFile)
1347
+ existingFiles.push(files[0]);
1348
+ } else
1349
+ files.forEach((file) => {
1350
+ if (uploadedFiles.find((search) => search.docName === file.name)) {
1351
+ existingFiles.push(file);
1352
+ } else
1353
+ nonExistingFiles.push(file);
1354
+ });
1355
+ if (existingFiles.length > 0) {
1356
+ void this.notify({
1357
+ message: `${getLabel("lblDropFileRepeated", {}, this.props.context).text}: ${existingFiles.map((current) => current.name).join(", ")}`,
1358
+ type: "warning"
1359
+ });
1360
+ return nonExistingFiles;
1361
+ }
1362
+ return files;
1363
+ }
1364
+ filterByFilesAmountLimit(files) {
1365
+ return files.slice(
1366
+ 0,
1367
+ addBoundary(this.maxFiles - (this.state.inProgressFiles?.length ?? 0), 0)
1368
+ );
1369
+ }
1370
+ filterAcceptedFiles(files, shouldNotify = true, docTypeId) {
1371
+ const docTypes = docTypeId !== void 0 ? this.state.allowedTypes.filter((c) => {
1372
+ return typeof docTypeId === "string" ? c.id === docTypeId : c.id === docTypeId.id;
1373
+ }) : this.state.allowedTypes;
1374
+ if (!docTypes.find((c) => c.docExts === "")) {
1375
+ const notAllowedFilesBecauseOfExtension = [];
1376
+ const notAllowedFilesBecauseOfSize = [];
1377
+ let maxSize = Infinity;
1378
+ const allowedFiles = files.filter((currentFile) => {
1379
+ const extension = (currentFile.name.match(/\.(\w+)$/) ?? [])[1];
1380
+ let isAllowed = true;
1381
+ if (!docTypes.find((currentDocType) => {
1382
+ if (!currentDocType.docExts.split(";").map((current) => current.toLowerCase()).includes(extension.toLowerCase())) {
1383
+ return false;
1384
+ }
1385
+ return true;
1386
+ })) {
1387
+ isAllowed = false;
1388
+ notAllowedFilesBecauseOfExtension.push(currentFile);
1389
+ }
1390
+ if (isAllowed && !docTypes.find((currentDocType) => {
1391
+ if (Number(currentDocType.maxSize) < currentFile.size) {
1392
+ maxSize = Number(currentDocType.maxSize);
1393
+ return false;
1394
+ }
1395
+ return true;
1396
+ })) {
1397
+ notAllowedFilesBecauseOfSize.push(currentFile);
1398
+ isAllowed = false;
1399
+ }
1400
+ if (!isAllowed)
1401
+ return false;
1402
+ return true;
1403
+ });
1404
+ if (shouldNotify) {
1405
+ let errorMessage = "";
1406
+ if (notAllowedFilesBecauseOfExtension.length > 0) {
1407
+ const filesNames = notAllowedFilesBecauseOfExtension.reduce(
1408
+ (accumulated, current) => {
1409
+ if (accumulated.length === 0)
1410
+ return current.name;
1411
+ return `${accumulated}, ${current.name}`;
1412
+ },
1413
+ ""
1414
+ );
1415
+ errorMessage = `<strong>${getLabel("lblFilesWrongExt", {}, this.props.context).text}</strong><br />${filesNames}`;
1416
+ }
1417
+ if (notAllowedFilesBecauseOfSize.length > 0) {
1418
+ const filesNames = notAllowedFilesBecauseOfSize.reduce(
1419
+ (accumulated, current) => {
1420
+ if (accumulated.length === 0)
1421
+ return current.name;
1422
+ return `${accumulated}, ${current.name}`;
1423
+ },
1424
+ ""
1425
+ );
1426
+ if (errorMessage.length > 0)
1427
+ errorMessage = `${errorMessage} <br /><br />`;
1428
+ errorMessage = `${errorMessage}${formatMessage(
1429
+ getLabel("lblFilesTooBig", {}, this.props.context).text,
1430
+ {
1431
+ TOK1: `<br />${filesNames}`,
1432
+ TOK2: `${parseAsSize(maxSize)}`
1433
+ }
1434
+ )}`;
1435
+ }
1436
+ if (errorMessage.length > 0)
1437
+ this.notify({
1438
+ message: errorMessage,
1439
+ type: "warning"
1440
+ });
1441
+ }
1442
+ return allowedFiles;
1443
+ }
1444
+ return files;
1445
+ }
1446
+ filterExistingFiles(files, conf) {
1447
+ if (conf?.langId)
1448
+ return files;
1449
+ const currentFiles = this.state.inProgressFiles;
1450
+ const alreadyUploadedFiles = Object.values(this.state.files).filter(
1451
+ (current) => Number(current.docId) < 0
1452
+ );
1453
+ let alreadyIncludedFileNames = "";
1454
+ const filteredFiles = files.filter((current) => {
1455
+ const isIncluded = currentFiles.findIndex((search) => search.name === current.name) !== -1 || alreadyUploadedFiles.findIndex(
1456
+ (search) => search.docName === current.name
1457
+ ) !== -1;
1458
+ if (isIncluded)
1459
+ alreadyIncludedFileNames = `${alreadyIncludedFileNames}${alreadyIncludedFileNames.length > 0 ? ", " : ""}${current.name}`;
1460
+ return !isIncluded;
1461
+ });
1462
+ if (alreadyIncludedFileNames.length > 0)
1463
+ this.notify({
1464
+ message: `${getLabel("lblDropFileRepeated", {}, this.props.context).text}: ${alreadyIncludedFileNames}`,
1465
+ type: "warning"
1466
+ });
1467
+ return filteredFiles;
1468
+ }
1469
+ filterVersioningFiles(files, conf) {
1470
+ const versioningFile = this.state.versioningFile;
1471
+ if (versioningFile) {
1472
+ const newFiles = files.filter(
1473
+ (current) => current.name === versioningFile.docName || current.name === versioningFile.name
1474
+ );
1475
+ if (newFiles.length === 0) {
1476
+ this.notify({
1477
+ type: "warning",
1478
+ message: getLabel("lblDropFileNamesNotMatch", {}, this.props.context).text
1479
+ });
1480
+ }
1481
+ return newFiles;
1482
+ }
1483
+ return files;
1484
+ }
1485
+ getLoadFileSystemStructureTree() {
1486
+ return {
1487
+ useDocTypePermitted: true,
1488
+ // docTypePermittedObjId: this.docTypePermittedObjId, // Get by inheritance
1489
+ docTypePermittedObjType: this.props.type
1490
+ };
1491
+ }
1492
+ getLoadFilesForFolderParameters() {
1493
+ return {
1494
+ useDocTypePermitted: true,
1495
+ // docTypePermittedObjId: this.docTypePermittedObjId, // Get by inheritance
1496
+ docTypePermittedObjType: this.props.type
1497
+ };
1498
+ }
1499
+ }
1500
+
1501
+ export { UploaderApi, UploaderModalController, parseFileDefinition, returnExactlyTheSame };
1502
+ //# sourceMappingURL=index.js.map