@apia/uploader-controller 4.0.102 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/UploaderApi.d.ts +181 -0
  2. package/dist/UploaderApi.d.ts.map +1 -0
  3. package/dist/UploaderApi.js +1268 -0
  4. package/dist/UploaderApi.js.map +1 -0
  5. package/dist/UploaderModalController.d.ts +54 -0
  6. package/dist/UploaderModalController.d.ts.map +1 -0
  7. package/dist/UploaderModalController.js +269 -0
  8. package/dist/UploaderModalController.js.map +1 -0
  9. package/dist/directories/DirectoriesPicker.d.ts +29 -0
  10. package/dist/directories/DirectoriesPicker.d.ts.map +1 -0
  11. package/dist/directories/DirectoriesPicker.js +108 -0
  12. package/dist/directories/DirectoriesPicker.js.map +1 -0
  13. package/dist/directories/FilePicker.d.ts +14 -0
  14. package/dist/directories/FilePicker.d.ts.map +1 -0
  15. package/dist/directories/FilePicker.js +36 -0
  16. package/dist/directories/FilePicker.js.map +1 -0
  17. package/dist/directories/nodes/DirectoryPickerFolderNode.d.ts +16 -0
  18. package/dist/directories/nodes/DirectoryPickerFolderNode.d.ts.map +1 -0
  19. package/dist/directories/nodes/DirectoryPickerFolderNode.js +115 -0
  20. package/dist/directories/nodes/DirectoryPickerFolderNode.js.map +1 -0
  21. package/dist/directories/nodes/DocumentNode.d.ts +11 -0
  22. package/dist/directories/nodes/DocumentNode.d.ts.map +1 -0
  23. package/dist/directories/nodes/DocumentNode.js +16 -0
  24. package/dist/directories/nodes/DocumentNode.js.map +1 -0
  25. package/dist/directories/nodes/FilePickerFolderNode.d.ts +12 -0
  26. package/dist/directories/nodes/FilePickerFolderNode.d.ts.map +1 -0
  27. package/dist/directories/nodes/FilePickerFolderNode.js +91 -0
  28. package/dist/directories/nodes/FilePickerFolderNode.js.map +1 -0
  29. package/dist/directories/types.d.ts +57 -0
  30. package/dist/directories/types.d.ts.map +1 -0
  31. package/dist/directories/utils.d.ts +17 -0
  32. package/dist/directories/utils.d.ts.map +1 -0
  33. package/dist/directories/utils.js +17 -0
  34. package/dist/directories/utils.js.map +1 -0
  35. package/dist/index.d.ts +11 -618
  36. package/dist/index.js +9 -1893
  37. package/dist/index.js.map +1 -1
  38. package/dist/types.d.ts +285 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/util.d.ts +6 -0
  41. package/dist/util.d.ts.map +1 -0
  42. package/dist/util.js +25 -0
  43. package/dist/util.js.map +1 -0
  44. package/package.json +5 -6
  45. package/LICENSE.md +0 -6
package/dist/index.js CHANGED
@@ -1,1894 +1,10 @@
1
- import { arrayOrArray, getLabel, toBoolean, EventEmitter, downloadUrl, addBoundary, formatMessage, parseAsSize } from '@apia/util';
2
- import { makeObservable, observable } from 'mobx';
3
- import { MobXTreeNode, MobXTree } from '@apia/tree2-controller';
4
- import { uniqueId } from 'lodash-es';
5
- import { ApiaApi } from '@apia/api2';
6
- import QueryString from 'qs';
7
-
8
- const DirectoryPickerActions = {
9
- ajaxUrl: (api) => api.context.URL_REQUEST_AJAX,
10
- loadFolderStructure: "loadFolderStructure",
11
- loadFilesForFolder: "loadFilesForFolder"
12
- };
13
- const FilePickerActions = {
14
- ajaxUrl: "apia.modals.FoldersAction.run",
15
- loadFileSystemStructureTree: "loadFileSystemStructureTree",
16
- loadFilesForFolder: "loadFilesForFolder",
17
- loadFolderStructure: "loadFolderStructure"
18
- };
19
- function makeId(str) {
20
- return str.replaceAll(/\W/g, "_");
21
- }
22
-
23
- class DocumentNode extends MobXTreeNode {
24
- constructor(parent, { parentId, id, ...props }) {
25
- const renderers = parent.tree.api.modalConfig.renderers;
26
- super(id ?? uniqueId("filepickertree"), parent, {
27
- icon: renderers.FileIconRenderer,
28
- isLeaf: true,
29
- ...props
30
- });
31
- }
32
- }
33
-
34
- var __defProp$3 = Object.defineProperty;
35
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
36
- var __publicField$3 = (obj, key, value) => {
37
- __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
38
- return value;
39
- };
40
- class DirectoryPickerFolderNode extends MobXTreeNode {
41
- constructor(parent, { parentId, id, ...props }) {
42
- const renderers = parent.tree.api.props.modalConfig.renderers;
43
- super(id ?? uniqueId("filepickertree"), parent, {
44
- asyncNode: true,
45
- icon: props.nodeProps?.canWrite === false ? renderers.LockedFolderIconRenderer : renderers.FolderIconRenderer,
46
- isSelectable: props.nodeProps?.canWrite !== false,
47
- ...props
48
- });
49
- __publicField$3(this, "loadMoreDocsNode", null);
50
- __publicField$3(this, "isLoadingMore", false);
51
- makeObservable(this, {
52
- isLoadingMore: observable
53
- });
54
- }
55
- removeLoadMoreDocsNode() {
56
- this.loadMoreDocsNode?.remove();
57
- this.loadMoreDocsNode = null;
58
- }
59
- getTree() {
60
- return this.tree;
61
- }
62
- async loadMore(focus = true) {
63
- const res = await ApiaApi.post(
64
- this.getTree().api.context,
65
- {
66
- ajaxUrl: DirectoryPickerActions.ajaxUrl(this.getTree().api),
67
- action: DirectoryPickerActions.loadFolderStructure,
68
- preventAsXmlParameter: true,
69
- isAjax: true
70
- },
71
- {
72
- postData: {
73
- txtFld: this.state.nodeProps.id,
74
- loadFolders: true,
75
- until: this.id
76
- },
77
- postDataTreatement: "stringify",
78
- postDataStringifyOptions: {
79
- arrayFormat: "repeat"
80
- }
81
- }
82
- );
83
- if (res?.data) {
84
- this.removeLoadMoreDocsNode();
85
- const lastNode = this.getChildren()[this.getChildren().length - 1];
86
- arrayOrArray(res.data.folder).forEach((folder) => {
87
- if (!this.state.children.has(folder.id)) {
88
- this.getTree().createFolder({
89
- id: makeId(folder.id),
90
- label: folder.name,
91
- nodeProps: folder,
92
- parentId: this.id
93
- });
94
- }
95
- });
96
- arrayOrArray(res.data.documents?.document).forEach((document) => {
97
- if (!this.state.children.has(document.id)) {
98
- this.getTree().createDocument({
99
- id: makeId(document.id),
100
- label: document.name,
101
- nodeProps: document,
102
- parentId: this.id
103
- });
104
- }
105
- });
106
- if ((res?.data.documents?.documentInfo?.moreDocs ?? 0) > 0) {
107
- this.loadMoreDocsNode = this.getTree().createFolder({
108
- asyncNode: false,
109
- icon: void 0,
110
- isLeaf: true,
111
- label: getLabel("lblShwMoreEls").text,
112
- labelRenderer: this.getTree().renderers.LoadMoreRenderer,
113
- onClick: async () => {
114
- if (this.loadMoreDocsNode) {
115
- this.loadMoreDocsNode.state.nodeProps.isLoadingMore = true;
116
- }
117
- await this.loadMore();
118
- },
119
- parentId: this.id
120
- });
121
- if (focus) {
122
- this.tree.focusNode(this.loadMoreDocsNode);
123
- }
124
- } else {
125
- if (focus) {
126
- this.tree.focusNode(lastNode.getFollowingSibling() ?? lastNode);
127
- }
128
- }
129
- }
130
- }
131
- async refresh() {
132
- this.removeAllChildren();
133
- this.loadMoreDocsNode = null;
134
- const res = this.loadMore(false);
135
- this.tree.focusNode(this.getFirstChildren(true) ?? this);
136
- return res;
137
- }
138
- }
139
-
140
- var __defProp$2 = Object.defineProperty;
141
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
142
- var __publicField$2 = (obj, key, value) => {
143
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
144
- return value;
145
- };
146
- class DirectoriesPicker extends MobXTree {
147
- constructor(api) {
148
- super({
149
- className: "FilePickerTree",
150
- isMultiple: false
151
- });
152
- this.api = api;
153
- __publicField$2(this, "isLoading", true);
154
- __publicField$2(this, "renderers");
155
- this.state.disableSelection = false;
156
- setTimeout(() => {
157
- this.initialLoad();
158
- }, 0);
159
- this.renderers = api.props.modalConfig.renderers;
160
- makeObservable(this, { isLoading: observable });
161
- }
162
- createDocument(nodeProps) {
163
- let parentNode = this.getNodeById(nodeProps.parentId);
164
- if (!parentNode) {
165
- console.warn("Cannot find parent node with id = ", nodeProps.parentId);
166
- parentNode = this;
167
- }
168
- const newNode = new DocumentNode(this, nodeProps);
169
- parentNode.append(newNode);
170
- return newNode;
171
- }
172
- createFolder(nodeProps) {
173
- let parentNode = this.getNodeById(nodeProps.parentId);
174
- if (!parentNode) {
175
- console.warn("Cannot find parent node with id = ", nodeProps.parentId);
176
- parentNode = this;
177
- }
178
- const newNode = this.getNodeHandler(nodeProps);
179
- parentNode.append(newNode);
180
- return newNode;
181
- }
182
- async initialLoad() {
183
- this.state.onLoadData = async (node) => {
184
- await node.refresh();
185
- };
186
- const res = await ApiaApi.post(
187
- this.api.context,
188
- this.getFolderStructureParams()
189
- );
190
- if (res?.data) {
191
- const foldersArray = this.parseStructureResponse(res);
192
- let selected = "";
193
- foldersArray?.forEach((folder) => {
194
- const newNode = this.createFolder({
195
- asyncNode: true,
196
- id: makeId(folder.id),
197
- label: folder.name,
198
- nodeProps: folder,
199
- parentId: folder.parent || "root"
200
- });
201
- if (folder.parent) {
202
- newNode.parent.expand();
203
- }
204
- if (folder.selectedFolder) {
205
- selected = makeId(folder.id);
206
- }
207
- if (String(this.api.props.modalConfig.defaultDirectory) === String(newNode.id)) {
208
- newNode.tree.setSelectedNodes(/* @__PURE__ */ new Set([newNode]));
209
- }
210
- });
211
- if (selected) {
212
- this.setSelectedNodes(/* @__PURE__ */ new Set([selected]));
213
- }
214
- }
215
- this.isLoading = false;
216
- }
217
- getFolderStructureParams() {
218
- return {
219
- ajaxUrl: DirectoryPickerActions.ajaxUrl(this.api),
220
- action: DirectoryPickerActions.loadFolderStructure,
221
- preventAsXmlParameter: true,
222
- isAjax: true,
223
- isXml: true,
224
- docId: this.api.state.versioningFile?.docId
225
- };
226
- }
227
- getNodeHandler(nodeProps) {
228
- return new DirectoryPickerFolderNode(this, nodeProps);
229
- }
230
- parseStructureResponse(res) {
231
- const castRes = res;
232
- if (castRes?.data?.folder)
233
- return arrayOrArray(castRes.data.folder);
234
- return null;
235
- }
236
- }
237
-
238
- var __defProp$1 = Object.defineProperty;
239
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
240
- var __publicField$1 = (obj, key, value) => {
241
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
242
- return value;
243
- };
244
- function getFileExtension(fileName) {
245
- const parts = fileName.split(".");
246
- return parts.length > 1 ? parts.pop().toLowerCase() : "";
247
- }
248
- const getInitialState = (context) => Object.freeze({
249
- metadata: {
250
- metadataArray: [],
251
- freeMetadataArray: [],
252
- isFreeMetadata: false
253
- },
254
- fromDirectoryFile: null,
255
- docFolder: void 0,
256
- docPath: void 0,
257
- docExpDate: void 0,
258
- description: "",
259
- isReadonly: false,
260
- permissions: {
261
- pools: [],
262
- users: context.ownerCanUpdate ? [
263
- {
264
- canUpdate: true,
265
- userId: context.currentUserLogin,
266
- userLogin: context.currentUserLogin
267
- }
268
- ] : [],
269
- allowAllType: context.everyoneCanUpdate !== false ? "M" : ""
270
- },
271
- fileReqError: false
272
- });
273
- class UploaderModalController {
274
- constructor(api, modalConfig, conf) {
275
- this.api = api;
276
- this.modalConfig = modalConfig;
277
- this.conf = conf;
278
- __publicField$1(this, "directories", null);
279
- __publicField$1(this, "state");
280
- makeObservable(this, {
281
- state: observable
282
- });
283
- this.state = getInitialState(api.props.context);
284
- if (modalConfig.showDirectoriesStructure) {
285
- if (!api.props.modalConfig.renderers) {
286
- throw new Error("If showDirectories is set, renderers are required");
287
- }
288
- this.directories = new DirectoriesPicker(this.api);
289
- }
290
- }
291
- get allMetadata() {
292
- return [
293
- ...this.state.metadata.metadataArray,
294
- ...this.state.metadata.freeMetadataArray
295
- ];
296
- }
297
- get allowAllType() {
298
- return this.state.permissions.allowAllType;
299
- }
300
- get description() {
301
- return this.state.description;
302
- }
303
- get docFolder() {
304
- return this.state.docFolder;
305
- }
306
- get docExpDate() {
307
- return this.state.docExpDate;
308
- }
309
- get docTypes() {
310
- return this.api.getDocTypes();
311
- }
312
- get freeMetadata() {
313
- return this.state.metadata.freeMetadataArray;
314
- }
315
- get exitingFiles() {
316
- return this.api.getExistingFiles();
317
- }
318
- get inProgressFiles() {
319
- return this.api.getInProgressFiles();
320
- }
321
- get hiddenFiles() {
322
- return this.api.getHiddenFiles();
323
- }
324
- get progress() {
325
- return this.api.getProgress();
326
- }
327
- get metadata() {
328
- return this.state.metadata.metadataArray;
329
- }
330
- get selectedDocTypeId() {
331
- return this.api.getCurrentDocTypeId();
332
- }
333
- get selectedDocType() {
334
- return this.api.getCurrentDocType();
335
- }
336
- addMetadata() {
337
- this.state.metadata.freeMetadataArray.push({
338
- free: "Y",
339
- id: String(Math.random()),
340
- name: "",
341
- required: "Y",
342
- title: "",
343
- type: "S",
344
- value: "",
345
- errorMessage: "",
346
- labelErrorMessage: ""
347
- });
348
- }
349
- addFiles(files) {
350
- this.state.fileReqError = false;
351
- this.state.isReadonly = false;
352
- this.api.saveDroppedFiles(files, this.conf);
353
- }
354
- addDirectoryFile(file) {
355
- this.state.fileReqError = false;
356
- this.api.state.inProgressFiles = [];
357
- this.state.fromDirectoryFile = file;
358
- }
359
- async changeDocType(docTypeId) {
360
- this.resetMetadata();
361
- this.api.setCurrentDocTypeId(docTypeId);
362
- this.onChangeExtension();
363
- this.api.reloadMetadata({ docTypeId });
364
- }
365
- clearDirectoryFile() {
366
- this.state.fromDirectoryFile = null;
367
- this.state.isReadonly = false;
368
- }
369
- clearFile(name) {
370
- this.api.clearFile(name);
371
- }
372
- clearFiles() {
373
- this.api.clearFiles();
374
- }
375
- clearState() {
376
- this.state = getInitialState(this.api.props.context);
377
- this.api.clearState();
378
- }
379
- clearPartialState() {
380
- if (this.api.state.inProgressFiles.length === 0) {
381
- this.state = getInitialState(this.api.props.context);
382
- }
383
- }
384
- onCloseModal() {
385
- this.clearState();
386
- }
387
- async confirm() {
388
- let isValid = this.validate();
389
- if (isValid)
390
- isValid = await this.api.confirmDropModal(this.conf);
391
- return isValid;
392
- }
393
- deleteMetadata(indices) {
394
- const deleteSet = new Set(indices);
395
- const offset = this.state.metadata.metadataArray.length;
396
- this.state.metadata.freeMetadataArray = this.state.metadata.freeMetadataArray.filter(
397
- (_, localIndex) => (
398
- // conservamos sólo los que NO estén en deleteSet
399
- !deleteSet.has(localIndex + offset)
400
- )
401
- );
402
- }
403
- deletePermission(item) {
404
- if (item && "userId" in item) {
405
- this.state.permissions.users = this.state.permissions.users.filter(
406
- (c) => c.userId !== item.userId
407
- );
408
- } else {
409
- this.state.permissions.pools = this.state.permissions.pools.filter(
410
- (c) => c.poolId !== item.poolId
411
- );
412
- }
413
- }
414
- onChangeExtension() {
415
- const rawDocExts = this.api.getCurrentDocType()?.docExts || "";
416
- let hideFileNames = "";
417
- const allowedExtensions = rawDocExts.split(";").map((ext) => ext.trim()).filter((ext) => ext !== "");
418
- if (rawDocExts === "") {
419
- const allFiles = [...this.inProgressFiles, ...this.hiddenFiles];
420
- const dedupedFiles = Array.from(
421
- new Map(allFiles.map((file) => [file.name, file])).values()
422
- );
423
- this.api.state.inProgressFiles = dedupedFiles;
424
- this.api.state.hiddenFiles = [];
425
- return;
426
- }
427
- const allowedInProgress = [];
428
- const toHide = [];
429
- this.inProgressFiles.forEach((file) => {
430
- const ext = getFileExtension(file.name);
431
- if (allowedExtensions.includes(ext)) {
432
- allowedInProgress.push(file);
433
- } else {
434
- toHide.push(file);
435
- hideFileNames += ` ${file.name} `;
436
- }
437
- });
438
- const allowedHidden = [];
439
- const stillHidden = [];
440
- this.api.state.hiddenFiles.forEach((file) => {
441
- const ext = getFileExtension(file.name);
442
- if (allowedExtensions.includes(ext)) {
443
- allowedHidden.push(file);
444
- } else {
445
- stillHidden.push(file);
446
- }
447
- });
448
- const combinedInProgress = [...allowedInProgress, ...allowedHidden];
449
- const dedupedInProgress = Array.from(
450
- new Map(
451
- combinedInProgress.map((file) => [file.name, file])
452
- ).values()
453
- );
454
- const combinedHidden = [...toHide, ...stillHidden];
455
- const dedupedHidden = Array.from(
456
- new Map(combinedHidden.map((file) => [file.name, file])).values()
457
- );
458
- this.api.state.inProgressFiles = dedupedInProgress;
459
- this.api.state.hiddenFiles = dedupedHidden;
460
- if (hideFileNames)
461
- this.api.notify({
462
- title: getLabel("msgFileWrngExt").text,
463
- message: hideFileNames,
464
- type: "warning"
465
- });
466
- }
467
- setDescription(desc) {
468
- this.state.description = desc;
469
- }
470
- async resetMetadata() {
471
- this.state.metadata = {
472
- freeMetadataArray: [],
473
- metadataArray: [],
474
- isFreeMetadata: false
475
- };
476
- }
477
- validate() {
478
- let isValid = true;
479
- this.state.fileReqError = false;
480
- if (this.api.getInProgressFiles().length === 0 && !this.state.fromDirectoryFile) {
481
- this.state.fileReqError = true;
482
- isValid = false;
483
- }
484
- this.allMetadata.forEach((c) => {
485
- if (c.free === "Y") {
486
- if (c.title.trim() === "") {
487
- c.labelErrorMessage = getLabel("msgReqField").text;
488
- isValid = false;
489
- }
490
- if (c.value.trim() === "") {
491
- if (!c.errorMessage)
492
- c.errorMessage = getLabel("msgReqField").text;
493
- isValid = false;
494
- }
495
- }
496
- });
497
- return isValid;
498
- }
499
- }
500
-
501
- const parseLockValue = (value) => {
502
- if (value === true || value === "true" || value === "me")
503
- return true;
504
- if (value === false || value === "false")
505
- return false;
506
- return void 0;
507
- };
508
- const parseFileDefinition = (context, fileDefinition, isSignRequired) => {
509
- const { lock, isLocked, lockedBy, userLocking, ...file } = fileDefinition;
510
- const normalizedLock = parseLockValue(lock) ?? parseLockValue(isLocked) ?? parseLockValue(file.locked) ?? false;
511
- return {
512
- ...file,
513
- isLocked: normalizedLock,
514
- locked: normalizedLock,
515
- isLockedByMe: (lockedBy || userLocking) === context.currentUserLogin,
516
- isMarkedToSign: file.markedToSign || toBoolean(file.sign) || isSignRequired,
517
- isVirtual: file.virtualDoc ?? false,
518
- lockingUser: lockedBy || userLocking
519
- };
520
- };
521
-
522
- var __defProp = Object.defineProperty;
523
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
524
- var __publicField = (obj, key, value) => {
525
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
526
- return value;
527
- };
528
- class UploaderApi extends EventEmitter {
529
- constructor(props) {
530
- super();
531
- this.props = props;
532
- __publicField(this, "maxFiles", Infinity);
533
- __publicField(this, "modalController", null);
534
- __publicField(this, "langs");
535
- __publicField(this, "currentConfiguration");
536
- __publicField(this, "showConfirmMessage", true);
537
- __publicField(this, "state", {
538
- progress: 0,
539
- allowedTypes: [],
540
- selectedDocTypeId: "1",
541
- versioningFile: null,
542
- inProgressFiles: [],
543
- files: {},
544
- selectedFiles: [],
545
- hiddenFiles: [],
546
- translatedFiles: /* @__PURE__ */ new Map(),
547
- hasAllDocTypes: false
548
- });
549
- __publicField(this, "getConfirmDropModalMetadataString", ({
550
- metadata
551
- }) => {
552
- return metadata?.filter?.((current) => !!current.value).map((current) => `${current.id}~${current.type}~${current.value}`).join(";") ?? [];
553
- });
554
- __publicField(this, "getConfirmDropModalPermissionsString", ({
555
- poolsPermissions,
556
- usersPermissions
557
- }) => {
558
- let returnString = "";
559
- poolsPermissions.forEach(
560
- (current) => returnString = `${returnString}${returnString.length > 0 ? "&" : ""}docPoolId=${current.poolId}&docPoolName=${current.poolName}&docPermType${current.poolId}=${String(current.canUpdate)}`
561
- );
562
- usersPermissions.forEach(
563
- (current) => returnString = `${returnString}${returnString.length > 0 ? "&" : ""}docUserId=${current.userId}&docUsrLogin=${current.userLogin}&docPermType${current.userId}=${String(current.canUpdate)}`
564
- );
565
- return returnString;
566
- });
567
- __publicField(this, "getConfirmDropModalAdditionalMetadataString", (additionalMetadata) => {
568
- return Object.values(additionalMetadata).filter((current) => !!current?.value).map((current) => `${current.title}~${current.value}`).join(";");
569
- });
570
- __publicField(this, "parseFileDefinition", (file) => {
571
- return {
572
- ...parseFileDefinition(this.props.context, file, false),
573
- canEdit: file.canEdit || file.canWrite,
574
- canRead: file.canRead
575
- };
576
- });
577
- makeObservable(this, {
578
- state: observable
579
- });
580
- this.langs = this.props.context.docLangs;
581
- }
582
- get filesArray() {
583
- return Object.values(this.state.files);
584
- }
585
- get id() {
586
- return this.props.id;
587
- }
588
- get modalConfig() {
589
- return this.props.modalConfig;
590
- }
591
- get context() {
592
- return this.props.context;
593
- }
594
- async init() {
595
- await this.ajaxUploadStart();
596
- await this.reloadMetadata({
597
- docTypeId: this.state.selectedDocTypeId
598
- });
599
- await this.loadCurrentDocuments();
600
- }
601
- buildModalController(conf) {
602
- return new UploaderModalController(this, this.props.modalConfig, conf);
603
- }
604
- async onStartUpload(files) {
605
- if (this.props.modalConfig.oneClickUpload) {
606
- await this.saveDroppedFiles(files ?? []);
607
- } else {
608
- if (files) {
609
- const result = await this.saveDroppedFiles(files ?? []);
610
- if (!result)
611
- return;
612
- }
613
- this.modalController = this.buildModalController();
614
- this.context.openModal();
615
- }
616
- }
617
- async onTranslateUpload(conf, files) {
618
- if (this.props.modalConfig.oneClickUpload) {
619
- await this.saveDroppedFiles(files ?? [], conf);
620
- } else {
621
- await this.init();
622
- let mustOpen = true;
623
- if (files) {
624
- const res = await this.saveDroppedFiles(files ?? [], conf);
625
- if (!res) {
626
- mustOpen = false;
627
- }
628
- }
629
- if (mustOpen) {
630
- this.modalController = this.buildModalController(conf);
631
- this.context.openModal();
632
- }
633
- }
634
- }
635
- async onVersionUpload(file, conf = { newFiles: [] }) {
636
- this.version(file, conf);
637
- }
638
- async autoLock() {
639
- return new Promise((resolve) => {
640
- resolve(false);
641
- });
642
- }
643
- notify(notification) {
644
- this.props.context.notify(notification);
645
- }
646
- getAjaxUrl() {
647
- return this.props.context.URL_REQUEST_AJAX;
648
- }
649
- getDocTypes() {
650
- return this.state.allowedTypes;
651
- }
652
- getCurrentDocTypeId() {
653
- return this.state.selectedDocTypeId;
654
- }
655
- getCurrentDocType() {
656
- return this.state.allowedTypes.find(
657
- (c) => c.id === this.state.selectedDocTypeId
658
- );
659
- }
660
- getInProgressFiles() {
661
- return this.state.inProgressFiles;
662
- }
663
- getHiddenFiles() {
664
- return this.state.hiddenFiles;
665
- }
666
- getExistingFiles() {
667
- return this.state.files;
668
- }
669
- getProgress() {
670
- return this.state.progress;
671
- }
672
- getHasAllDocTypes() {
673
- return this.state.hasAllDocTypes;
674
- }
675
- async getDocumentInfo({
676
- docId: apiId,
677
- downloadDocId: docId
678
- }, newElem) {
679
- const id = apiId ? this.getDocument(apiId).docId : docId;
680
- const result = await ApiaApi.post(
681
- this.context,
682
- this.getDocumentInfoParameters({
683
- action: "getDocumentInfo",
684
- isAjax: true,
685
- docId: id,
686
- newElem,
687
- ajaxUrl: this.getAjaxUrl()
688
- })
689
- );
690
- if (result?.data) {
691
- return result.data;
692
- }
693
- return null;
694
- }
695
- /**
696
- * This method searches for the provided id in several places:
697
- *
698
- * If it's found in the current files, returns it.
699
- * If not, it searches the provided docId in the translations map of each uploaded file.
700
- */
701
- getDocument(docId) {
702
- if (this.state.files[docId]) {
703
- return this.state.files[docId];
704
- } else {
705
- for (const map of this.state.translatedFiles.values()) {
706
- for (const file of map.values()) {
707
- if (file.docId === docId) {
708
- return file;
709
- }
710
- }
711
- }
712
- }
713
- return void 0;
714
- }
715
- updateDocument(docId, newValue) {
716
- if (this.state.files[docId]) {
717
- this.state.files[docId] = { ...this.getDocument(docId), ...newValue };
718
- } else {
719
- this.state.translatedFiles.forEach((innerMap) => {
720
- innerMap.forEach((doc, langKey) => {
721
- if (doc.docId === docId) {
722
- innerMap.set(langKey, { ...doc, ...newValue });
723
- }
724
- });
725
- });
726
- }
727
- }
728
- deleteDocument(docId) {
729
- if (this.state.files[docId]) {
730
- delete this.state.files[docId];
731
- } else {
732
- this.state.translatedFiles.forEach((innerMap) => {
733
- innerMap.forEach((doc, langKey) => {
734
- if (doc.docId === docId) {
735
- innerMap.delete(langKey);
736
- }
737
- });
738
- });
739
- }
740
- }
741
- clearFile(name) {
742
- if (this.modalController) {
743
- this.modalController.state.isReadonly = false;
744
- }
745
- this.state.inProgressFiles = this.state.inProgressFiles.filter(
746
- (c) => c.name !== name
747
- );
748
- }
749
- clearFiles() {
750
- if (this.modalController) {
751
- this.modalController.state.isReadonly = false;
752
- }
753
- this.state.inProgressFiles = [];
754
- this.state.versioningFile = null;
755
- this.state.hiddenFiles = [];
756
- }
757
- clearState() {
758
- if (this.modalController) {
759
- this.modalController.state.isReadonly = false;
760
- }
761
- this.state.selectedDocTypeId = this.getDocTypes().find(
762
- (c) => String(c.id) === "1"
763
- ) ? "1" : this.getDocTypes()[0]?.id;
764
- this.state.inProgressFiles = [];
765
- this.state.versioningFile = null;
766
- }
767
- async checkLockDocument(id, shouldNotifyUnlocked = true) {
768
- if (this.props.context.IN_MONITOR) {
769
- return false;
770
- }
771
- if (Number(id) < 0)
772
- return true;
773
- const file = this.getDocument(id);
774
- const result = await ApiaApi.post(
775
- this.context,
776
- this.getCheckLockDocumentParameters({
777
- action: "checkLockDocument",
778
- docId: file.docId,
779
- ajaxUrl: this.getAjaxUrl()
780
- })
781
- );
782
- const isLocked = result?.data?.success === "ok";
783
- if (!isLocked && result?.data?.usr && result.data.usr !== this.props.context.currentUserLogin) {
784
- this.notify({
785
- message: `${getLabel("msgDocLocOthUsr", {}, this.props.context).text.split(".")[0]}: ${result.data.usr}.`,
786
- type: "warning"
787
- });
788
- return result.data.usr;
789
- }
790
- if (!isLocked && shouldNotifyUnlocked && !await this.autoLock())
791
- this.notify({
792
- message: getLabel("msgDocMusBeLocForUpd", {}, this.props.context).text,
793
- type: "warning"
794
- });
795
- return isLocked;
796
- }
797
- setCurrentDocTypeId(docTypeId) {
798
- this.state.selectedDocTypeId = docTypeId;
799
- }
800
- async ajaxUploadStart(newFiles = []) {
801
- if (this.props.context.IN_MONITOR) {
802
- return;
803
- }
804
- const versioningFile = this.state.versioningFile;
805
- const res = await ApiaApi.post(
806
- this.context,
807
- this.getAjaxUploadStartParameters({
808
- action: "ajaxUploadStart",
809
- isAjax: true,
810
- docId: versioningFile?.docId,
811
- docTypeId: newFiles.length === 1 ? versioningFile?.docTypeId || "1" : "1",
812
- newDoc: !versioningFile,
813
- useDocTypePermitted: false,
814
- ajaxUrl: this.getAjaxUrl()
815
- })
816
- );
817
- if (res?.data) {
818
- const docTypes = arrayOrArray(res?.data?.function?.docTypes?.docType);
819
- const hasGeneric = !!docTypes.find((c) => String(c.id) === "1");
820
- this.state.allowedTypes = docTypes;
821
- this.state.selectedDocTypeId = hasGeneric ? "1" : docTypes[0].id;
822
- if (newFiles.length > 0) {
823
- await this.saveDroppedFiles(newFiles);
824
- }
825
- return res?.data?.function.name === "fncDocumentLoadInformation" ? true : false;
826
- } else {
827
- throw new Error("No files data");
828
- }
829
- }
830
- async reloadMetadata(props, additionalProps) {
831
- if (!this.modalController)
832
- return;
833
- const res = await ApiaApi.post(
834
- this.context,
835
- this.getReloadMetadataParameters({
836
- ajaxUrl: this.getAjaxUrl(),
837
- action: "reloadMetadata",
838
- isAjax: true,
839
- docId: props?.docId,
840
- docTypeId: props?.docTypeId,
841
- metadata: this.getConfirmDropModalMetadataString({
842
- metadata: this.modalController?.allMetadata
843
- }),
844
- ...additionalProps
845
- })
846
- );
847
- if (res?.data && props?.docTypeId) {
848
- const isFreeMetadata = this.state.allowedTypes.find(
849
- (current) => current.id === props.docTypeId
850
- )?.free ?? false;
851
- this.modalController.state.metadata.freeMetadataArray = [];
852
- this.modalController.state.metadata.metadataArray = [];
853
- arrayOrArray(res.data.metadata).forEach((c) => {
854
- if (c.free === "Y") {
855
- this.modalController.state.metadata.freeMetadataArray.push(c);
856
- } else {
857
- this.modalController.state.metadata.metadataArray.push(c);
858
- }
859
- });
860
- this.modalController.state.metadata.isFreeMetadata = isFreeMetadata;
861
- }
862
- }
863
- async saveDroppedFiles(unprocessedFiles, conf) {
864
- if (this.props.context.IN_MONITOR) {
865
- return false;
866
- }
867
- const {
868
- langId,
869
- strictMode: isConfStrictMode = false,
870
- translatingFile
871
- } = conf ?? {};
872
- const isStrictMode = isConfStrictMode || !!this.state.versioningFile || !!this.modalController?.state.fromDirectoryFile;
873
- const docType = this.getCurrentDocTypeId();
874
- if (!isStrictMode && !docType) {
875
- this.notify({
876
- message: `${getLabel("msgDropFileDel", {}, this.props.context).text}: ${unprocessedFiles.map((current) => current.name).join(", ")}.`,
877
- type: "warning"
878
- });
879
- return false;
880
- }
881
- const allowedFiles = this.filterAlreadyUploadedFiles(
882
- this.filterByFilesAmountLimit(
883
- this.filterAcceptedFiles(
884
- this.filterExistingFiles(
885
- this.filterVersioningFiles(unprocessedFiles, conf),
886
- conf
887
- ),
888
- true,
889
- docType
890
- )
891
- ),
892
- conf
893
- );
894
- if (allowedFiles.length > 0) {
895
- const formData = new FormData();
896
- allowedFiles.forEach(
897
- (file) => formData.append("fileRepository", file, file.name)
898
- );
899
- await ApiaApi.post(
900
- this.context,
901
- this.getSaveDroppedFilesParameters({
902
- action: "saveDroppedFiles",
903
- docId: this.state.versioningFile?.docId,
904
- ajaxUrl: this.getAjaxUrl(),
905
- frmOut: !this.modalController,
906
- docTypeId: this.state.selectedDocTypeId,
907
- langId
908
- }),
909
- {
910
- postData: formData,
911
- axiosConfig: {
912
- onUploadProgress: (ev) => this.state.progress = ev.loaded * 100 / ((ev.total ?? ev.loaded) * 2)
913
- }
914
- }
915
- );
916
- const ajaxUploadFileStatusParameters = this.getAjaxUploadFileStatusParameters({
917
- action: "ajaxUploadFileStatus",
918
- ajaxUrl: this.getAjaxUrl(),
919
- delayForDrop: true,
920
- isAjax: true
921
- });
922
- let tries = 0;
923
- const checkUploadResult = async () => {
924
- return new Promise(async (resolve) => {
925
- tries += 1;
926
- if (tries === 10) {
927
- this.notify({
928
- message: "Error while checking for uploadFileStatus, too many tries",
929
- type: "error"
930
- });
931
- resolve(false);
932
- return;
933
- }
934
- const response = await ApiaApi.post(
935
- this.context,
936
- ajaxUploadFileStatusParameters
937
- );
938
- if (response && response.data) {
939
- const hasMessages = arrayOrArray(
940
- response.data?.sysMessages?.message ?? response.data?.sysExceptions?.exception ?? response.data?.exceptions?.exception ?? response.data.function.messages?.message
941
- ).length > 0 || !!response.data.function.dropLastMessage;
942
- const uploadMessage = arrayOrArray(
943
- response.data.function.messages?.message
944
- ).find((current) => current.name === "message");
945
- if (uploadMessage)
946
- this.notify({ message: uploadMessage.label, type: "warning" });
947
- const method = response.data?.function.name;
948
- this.state.progress = 44;
949
- if (hasMessages) {
950
- resolve(false);
951
- return;
952
- }
953
- if (method === "fncProceedDocumentProcessing") {
954
- resolve(true);
955
- return;
956
- }
957
- if (tries === 10) {
958
- resolve(method === "fncProceedDocumentProcessing");
959
- }
960
- setTimeout(() => {
961
- checkUploadResult().then(resolve).catch(() => resolve(false));
962
- }, 100);
963
- } else {
964
- resolve(false);
965
- }
966
- });
967
- };
968
- const hasUploadedCorrectly = await checkUploadResult();
969
- this.state.progress = 66;
970
- if (hasUploadedCorrectly) {
971
- const shown = (this.state.inProgressFiles ?? []).map(
972
- (file) => file.name
973
- );
974
- const postData = QueryString.stringify(
975
- this.getProcessDroppedFilesPostdata({
976
- useDocTypePermitted: true,
977
- dropped: allowedFiles.map((file) => file.name).concat(shown),
978
- shown
979
- }),
980
- { arrayFormat: "repeat" }
981
- );
982
- const secondResult = await ApiaApi.post(
983
- this.context,
984
- this.getProcessDroppedFilesParameters({
985
- action: "processDroppedFiles",
986
- docId: this.state.versioningFile?.docId,
987
- frmOut: !this.modalController,
988
- ajaxUrl: this.getAjaxUrl()
989
- }),
990
- {
991
- postData: postData.toString()
992
- }
993
- );
994
- this.state.progress = 83;
995
- if (secondResult?.data?.function?.principal?.docInfo) {
996
- const acceptedByServerFiles = arrayOrArray(
997
- secondResult.data.function?.principal?.docInfo
998
- );
999
- this.state.inProgressFiles = [
1000
- ...this.state.inProgressFiles ?? [],
1001
- ...acceptedByServerFiles.map(
1002
- (current) => [...this.state.inProgressFiles, ...unprocessedFiles].find(
1003
- (search) => search.name === current.docInfoName
1004
- )
1005
- ).filter((current) => !!current)
1006
- ];
1007
- this.state.progress = 100;
1008
- if (this.modalController)
1009
- this.modalController.state.fromDirectoryFile = null;
1010
- if (this.showConfirmMessage) {
1011
- this.notify({
1012
- type: "success",
1013
- message: getLabel(
1014
- "lblFileUploadedSuccessfully",
1015
- {},
1016
- this.props.context
1017
- ).text
1018
- });
1019
- }
1020
- if (this.props.modalConfig.oneClickUpload) {
1021
- if (langId && translatingFile)
1022
- void this.confirmDropModal({ langId, translatingFile });
1023
- else
1024
- void this.confirmDropModal();
1025
- }
1026
- }
1027
- }
1028
- this.state.progress = 100;
1029
- return true;
1030
- } else {
1031
- return false;
1032
- }
1033
- }
1034
- async checkWebDavLock(docId) {
1035
- if (this.props.context.IN_MONITOR) {
1036
- return false;
1037
- }
1038
- if (Number.parseInt(docId) < 0) {
1039
- return true;
1040
- }
1041
- return new Promise((resolve) => {
1042
- let tries = 10;
1043
- const checkLockAction = async () => {
1044
- const isLocked = await ApiaApi.post(
1045
- this.context,
1046
- this.getCheckWebDavLockParameters({
1047
- action: "isWebDavDocumentLocked",
1048
- docId,
1049
- ajaxUrl: this.props.context.URL_REQUEST_AJAX
1050
- })
1051
- );
1052
- if (isLocked?.data?.locked === true || isLocked?.data?.locked === void 0) {
1053
- if (--tries > 0) {
1054
- setTimeout(() => void checkLockAction(), 1e3);
1055
- } else {
1056
- this.notify({
1057
- message: getLabel("msgFailSyncDoc", {}, this.props.context).text
1058
- });
1059
- resolve(false);
1060
- }
1061
- } else {
1062
- resolve(true);
1063
- }
1064
- };
1065
- void checkLockAction();
1066
- });
1067
- }
1068
- async checkSignature(file) {
1069
- let res = null;
1070
- if (Number(file.docId) >= 0)
1071
- res = await ApiaApi.get(
1072
- this.context,
1073
- this.getCheckSignatureParameters({
1074
- action: "viewDocSigns",
1075
- docId: file.docId,
1076
- lock: false,
1077
- isAjax: true,
1078
- react: true
1079
- })
1080
- );
1081
- return res;
1082
- }
1083
- async editDocument(id) {
1084
- if (this.props.context.IN_MONITOR) {
1085
- return;
1086
- }
1087
- const file = this.getDocument(id);
1088
- if (await this.checkLockDocument(file.docId) === true) {
1089
- const result = await ApiaApi.post(
1090
- this.context,
1091
- this.getEditDocumentParameters({
1092
- action: "updateWebDavDocument",
1093
- docId: file.docId,
1094
- isAjax: true
1095
- })
1096
- );
1097
- if (result?.data?.folderId) {
1098
- const sDocumentUrl = `${this.props.context.WEBDAV_SERVER}${result?.data?.folderId}/${file.docId}/${file.name || file.docName || ""}`;
1099
- const ProtocolInstallMessage = () => {
1100
- this.notify({
1101
- type: "warning",
1102
- message: getLabel(
1103
- "msgNoDocEdiProto",
1104
- {
1105
- text: {
1106
- TOK1: `<a href="${this.props.context.WEBDAV_INSTALLER_URL}" download>`,
1107
- TOK2: `</a>`
1108
- }
1109
- },
1110
- this.props.context
1111
- ).text,
1112
- title: getLabel("lblEdit", {}, this.props.context).text
1113
- });
1114
- };
1115
- this.props.context.ITHit.WebDAV.Client.DavConstants.ProtocolTimeoutMs = 1e4;
1116
- await this.props.context.ITHit.WebDAV.Client.DocManager.DavProtocolEditDocument(
1117
- sDocumentUrl,
1118
- this.props.context.WEBDAV_SERVER,
1119
- ProtocolInstallMessage,
1120
- null,
1121
- "Current",
1122
- "ApiaWebDavCookie",
1123
- // Cookie(s) to copy.
1124
- "",
1125
- // URL to navigate to if any cookie from the list is not found.
1126
- "Edit"
1127
- );
1128
- }
1129
- }
1130
- }
1131
- async downloadVersion(fileId, version) {
1132
- const file = this.getDocument(fileId);
1133
- if (!file)
1134
- return;
1135
- if (Number.parseInt(fileId) < 0 || this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId))
1136
- await downloadUrl(
1137
- ApiaApi.makeUrl(this.context, {
1138
- action: "downloadDocument",
1139
- docId: file.downloadDocId,
1140
- version
1141
- })
1142
- );
1143
- }
1144
- async downloadDocument(id, version) {
1145
- const file = this.getDocument(id);
1146
- if (Number.parseInt(id) < 0 || this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId)) {
1147
- await downloadUrl(
1148
- ApiaApi.makeUrl(this.context, {
1149
- action: "downloadDocument",
1150
- docId: file.downloadDocId,
1151
- ajaxUrl: this.getAjaxUrl(),
1152
- version
1153
- })
1154
- );
1155
- }
1156
- }
1157
- async ajaxDeleteDocument(id, langId) {
1158
- const file = this.getDocument(id);
1159
- const isLocked = await this.checkLockDocument(file.docId);
1160
- if (isLocked === true) {
1161
- const result = await ApiaApi.post(
1162
- this.context,
1163
- this.getDeleteDocumentParameters({
1164
- action: "ajaxRemoveDocument",
1165
- docId: file.docId,
1166
- isAjax: true,
1167
- ajaxUrl: this.getAjaxUrl(),
1168
- langId
1169
- })
1170
- );
1171
- if (this.evaluateDeleteDocumentResult(result?.data)) {
1172
- this.deleteDocument(id);
1173
- this.emit("fileUploaded", null);
1174
- }
1175
- }
1176
- }
1177
- async version(file, conf = { newFiles: [] }) {
1178
- const checkLock = await this.checkLockDocument(file.docId, true);
1179
- const isLocked = await this.checkWebDavLock(file.docId);
1180
- if (!(checkLock === true && isLocked))
1181
- return;
1182
- this.state.versioningFile = file;
1183
- const openVersionModal = () => {
1184
- if (!this.props.modalConfig.oneClickUpload) {
1185
- this.modalController = this.buildModalController({
1186
- versionFile: file
1187
- });
1188
- this.context.openModal();
1189
- }
1190
- };
1191
- if (!conf.newFiles || conf.newFiles.length === 0) {
1192
- openVersionModal();
1193
- }
1194
- await this.ajaxUploadStart();
1195
- if (file.docTypeId)
1196
- this.state.selectedDocTypeId = file.docTypeId;
1197
- await this.versionFileInfo(file);
1198
- const hasNewFiles = !!(conf.newFiles && conf.newFiles.length > 0);
1199
- if (hasNewFiles) {
1200
- const res = await this.saveDroppedFiles(conf.newFiles, {
1201
- langId: conf.langId,
1202
- translatingFile: conf.translatingFile,
1203
- shouldReset: false,
1204
- strictMode: true
1205
- });
1206
- if (res) {
1207
- openVersionModal();
1208
- }
1209
- } else {
1210
- await this.reloadMetadata({
1211
- docId: file.docId,
1212
- docTypeId: file.docTypeId
1213
- });
1214
- }
1215
- }
1216
- async versionFileInfo(file) {
1217
- const documentInfo = await this.getDocumentInfo({ docId: file.docId });
1218
- if (documentInfo?.function) {
1219
- const {
1220
- data: { general },
1221
- metadatas
1222
- } = documentInfo.function;
1223
- const isFreeMetadata = this.state.allowedTypes.find((current) => current.id === file.docTypeId)?.free ?? false;
1224
- if (this.modalController) {
1225
- this.modalController.state = {
1226
- description: general.docDesc,
1227
- docFolder: general.docFolder === "" ? void 0 : Number(general.docFolder),
1228
- docPath: general.docFolderPath,
1229
- permissions: {
1230
- allowAllType: general.docAllPoolPerm,
1231
- users: arrayOrArray(
1232
- documentInfo.function.data.permissions?.user
1233
- ).map((current) => {
1234
- const returnObject = {
1235
- canUpdate: current.permType === "M",
1236
- userId: current.id,
1237
- userLogin: current.name
1238
- };
1239
- return returnObject;
1240
- }),
1241
- pools: arrayOrArray(
1242
- documentInfo.function.data.permissions?.pool
1243
- ).map((current) => {
1244
- const returnObject = {
1245
- canUpdate: current.permType === "M",
1246
- poolId: current.id,
1247
- poolName: current.name
1248
- };
1249
- return returnObject;
1250
- })
1251
- },
1252
- docExpDate: general.docExpDate,
1253
- fileReqError: false,
1254
- fromDirectoryFile: null,
1255
- metadata: {
1256
- metadataArray: arrayOrArray(metadatas?.metadata),
1257
- freeMetadataArray: [],
1258
- isFreeMetadata
1259
- }
1260
- };
1261
- }
1262
- }
1263
- }
1264
- async pickFileById(id) {
1265
- const documentInfo = await this.getDocumentInfo(
1266
- { downloadDocId: id },
1267
- true
1268
- );
1269
- if (documentInfo) {
1270
- const document = documentInfo.function.data.general;
1271
- const { permissions } = documentInfo.function.data;
1272
- if (this.modalController) {
1273
- this.setCurrentDocTypeId(document.docTypeId);
1274
- this.modalController.addDirectoryFile(document);
1275
- this.modalController.state.description = document.docDesc;
1276
- this.modalController.state.docExpDate = document.docExpDate;
1277
- this.modalController.state.permissions = {
1278
- pools: arrayOrArray(permissions?.pool).map((c) => {
1279
- return {
1280
- poolId: c.id,
1281
- poolName: c.name,
1282
- canUpdate: c.permType === "M"
1283
- };
1284
- }),
1285
- users: [
1286
- ...arrayOrArray(permissions?.user).map((c) => {
1287
- return {
1288
- userId: c.id,
1289
- userLogin: c.name,
1290
- canUpdate: c.permType === "M"
1291
- };
1292
- })
1293
- ],
1294
- allowAllType: document.docAllPoolPerm
1295
- };
1296
- this.modalController.changeDocType(document.docTypeId);
1297
- this.modalController.state.isReadonly = !documentInfo.function.currentUsrPems.usrCanModify;
1298
- }
1299
- void this.reloadMetadata(
1300
- { docId: document.docId, docTypeId: document.docTypeId },
1301
- {
1302
- docReuse: true
1303
- }
1304
- );
1305
- }
1306
- }
1307
- async markFileToSign(id, langId) {
1308
- if (this.props.context.IN_MONITOR) {
1309
- return;
1310
- }
1311
- const file = this.getDocument(id);
1312
- if (await this.checkLockDocument(file.docId) === true) {
1313
- const marked = await ApiaApi.post(
1314
- this.context,
1315
- this.getMarkFileToSignParameters({
1316
- action: "markDocTosign",
1317
- docId: file.docId,
1318
- isAjax: true,
1319
- ajaxUrl: this.getAjaxUrl(),
1320
- langId
1321
- })
1322
- );
1323
- if (marked?.data?.markedToSign !== void 0) {
1324
- if (this.state.files[id]) {
1325
- this.state.files[id].markedToSign = marked.data.markedToSign;
1326
- } else {
1327
- this.state.translatedFiles.forEach((innerMap) => {
1328
- innerMap.forEach((doc, langKey) => {
1329
- if (doc.docId === id) {
1330
- innerMap.set(langKey, {
1331
- ...doc,
1332
- markedToSign: marked?.data?.markedToSign ?? false
1333
- });
1334
- }
1335
- });
1336
- });
1337
- }
1338
- }
1339
- }
1340
- }
1341
- /**
1342
- * Por el momento realiza la descarga de todos los archivos
1343
- * que estén subidos.
1344
- */
1345
- downloadMultipleDocuments() {
1346
- const files = this.filesArray;
1347
- if (files.length === 0)
1348
- return;
1349
- const docIds = this.state.selectedFiles;
1350
- const selectedFiles = files.filter(
1351
- (current) => docIds.find((search) => search === current.docId)
1352
- );
1353
- const ids = (selectedFiles.length > 0 ? selectedFiles : files).map((current) => current.downloadDocId).join("-");
1354
- void downloadUrl(
1355
- ApiaApi.makeUrl(
1356
- this.context,
1357
- this.getDownloadMultipleDocumentsParameters({
1358
- action: "multipleDownload",
1359
- docId: ids
1360
- })
1361
- ),
1362
- "documents.zip"
1363
- );
1364
- }
1365
- async confirmDropModal(conf) {
1366
- if (this.props.context.IN_MONITOR) {
1367
- return false;
1368
- }
1369
- const { langId, translatingFile } = conf ?? {};
1370
- const cmbDocType = this.state.selectedDocTypeId;
1371
- const fromDirectoryFile = this.modalController?.state.fromDirectoryFile;
1372
- const docDesc = this.modalController?.description ?? "";
1373
- const docAllowAllType = this.props.modalConfig.oneClickUpload ? "M" : this.modalController?.allowAllType ?? "";
1374
- const docFolder = this.modalController?.docFolder;
1375
- const docExpDate = this.modalController?.docExpDate;
1376
- const metadata = this.modalController?.metadata ?? [];
1377
- const freeMetadata = this.modalController?.freeMetadata ?? [];
1378
- const poolsPermissions = this.modalController?.state.permissions.pools ?? [];
1379
- const usersPermissions = this.modalController?.state.permissions.users ?? [];
1380
- let postData = QueryString.stringify(
1381
- this.getConfirmDropModalPostdata({
1382
- cmbDocType,
1383
- docDesc,
1384
- docAllowAllType,
1385
- dropped: this.state.inProgressFiles.map((file) => file.name),
1386
- txtLangId: langId,
1387
- txtLangGroup: translatingFile?.docLangGroup,
1388
- docFolder
1389
- }),
1390
- { arrayFormat: "repeat" }
1391
- );
1392
- postData = `${postData}${postData.length > 0 ? "&" : ""}${this.getConfirmDropModalPermissionsString({
1393
- poolsPermissions,
1394
- usersPermissions
1395
- })}&txtFreeMetadata=${this.getConfirmDropModalAdditionalMetadataString(
1396
- freeMetadata
1397
- )}&txtMetadata=${this.getConfirmDropModalMetadataString({
1398
- metadata: Object.values(metadata || {})
1399
- })}&docExpDate=${docExpDate ?? ""}`;
1400
- const result = await ApiaApi.post(
1401
- this.context,
1402
- this.getConfirmDropModalParameters({
1403
- ajaxUrl: this.getAjaxUrl(),
1404
- docId: fromDirectoryFile ? fromDirectoryFile.docId : this.state.versioningFile?.docId,
1405
- action: fromDirectoryFile ? "associateExistingFile" : "confirmDropModal",
1406
- fromForm: true,
1407
- ...fromDirectoryFile ? {
1408
- docId: fromDirectoryFile.docId,
1409
- fromReuse: true,
1410
- uploadDocument: false
1411
- } : null
1412
- }),
1413
- {
1414
- postData: postData.toString()
1415
- }
1416
- );
1417
- if (result?.data?.function) {
1418
- const currentFiles = { ...this.state.files };
1419
- const versioningFile = this.state.versioningFile;
1420
- if (versioningFile && versioningFile.name) {
1421
- delete currentFiles[versioningFile.name];
1422
- }
1423
- const newFiles = arrayOrArray(
1424
- result.data.function.general
1425
- ).map(
1426
- (current) => this.parseFileDefinition({
1427
- ...current,
1428
- canWrite: true,
1429
- canRead: true,
1430
- canEdit: true
1431
- })
1432
- ).filter((current) => !currentFiles[current.docId]).reduce((acc, current) => ({ ...acc, [current.docId]: current }), {});
1433
- if (langId && translatingFile) {
1434
- const firstFile = Object.values(newFiles)[0];
1435
- this.setTranslationFile(firstFile, translatingFile.docId, langId);
1436
- } else {
1437
- this.state.files = { ...currentFiles, ...newFiles };
1438
- }
1439
- this.clearFiles();
1440
- this.emit("fileUploaded", null);
1441
- return true;
1442
- }
1443
- return false;
1444
- }
1445
- getLoadCurrentDocumentsParameters(params) {
1446
- return params;
1447
- }
1448
- async loadCurrentDocuments() {
1449
- const result = await ApiaApi.post(
1450
- this.context,
1451
- this.getLoadCurrentDocumentsParameters({
1452
- ajaxUrl: this.getAjaxUrl(),
1453
- action: "ajaxLoadCurrent",
1454
- isAjax: true,
1455
- readOnly: this.props.context.readonly,
1456
- allowLock: true,
1457
- allowSign: true,
1458
- allowMultiple: true
1459
- }),
1460
- {}
1461
- );
1462
- if (result && result.data) {
1463
- const currentConfiguration = arrayOrArray(result.data.function.messages.message).reduce(
1464
- (prev, { name, label }) => ({ ...prev, [name]: Boolean(label) }),
1465
- {}
1466
- );
1467
- const currentFiles = result.data.function.general ? arrayOrArray(result.data.function.general).map(
1468
- this.parseFileDefinition
1469
- ) : [];
1470
- this.currentConfiguration = currentConfiguration;
1471
- const nonTranslationFiles = [];
1472
- const translationFiles = [];
1473
- currentFiles.forEach((current) => {
1474
- if (current.docLang === void 0)
1475
- nonTranslationFiles.push(current);
1476
- else
1477
- translationFiles.push(current);
1478
- });
1479
- nonTranslationFiles.forEach((c) => {
1480
- this.state.files[c.docId] = c;
1481
- });
1482
- translationFiles.forEach((current) => {
1483
- const originalFile = nonTranslationFiles.find(
1484
- (search) => search.docLangGroup === current.docLangGroup
1485
- );
1486
- if (originalFile && current.docLang !== void 0) {
1487
- this.setTranslationFile(
1488
- current,
1489
- originalFile.docId,
1490
- Number(current.docLang)
1491
- );
1492
- } else
1493
- console.warn(
1494
- `The following file is translated but has no orignal file`,
1495
- current,
1496
- nonTranslationFiles
1497
- );
1498
- });
1499
- }
1500
- }
1501
- async lockDocument(id) {
1502
- if (this.props.context.IN_MONITOR) {
1503
- return;
1504
- }
1505
- const file = this.getDocument(id);
1506
- if (file.markedToSign) {
1507
- this.notify({
1508
- message: getLabel("msgCantActFileMarkSign", {}, this.props.context).text,
1509
- type: "warning"
1510
- });
1511
- return;
1512
- }
1513
- if (!file.isLocked || !file.isLockedByMe) {
1514
- const isLocked = await this.checkLockDocument(file.docId, false);
1515
- this.updateDocument(
1516
- id,
1517
- typeof isLocked === "string" ? this.parseFileDefinition({
1518
- ...file,
1519
- userLocking: isLocked,
1520
- lock: true,
1521
- isLocked: true,
1522
- lockedBy: isLocked
1523
- }) : { ...file, isLocked }
1524
- );
1525
- }
1526
- const result = await ApiaApi.post(
1527
- this.context,
1528
- this.getLockDocumentParameters({
1529
- action: "lockDocument",
1530
- ajaxUrl: this.getAjaxUrl(),
1531
- docId: file.docId,
1532
- lock: file.isLocked,
1533
- isAjax: true
1534
- })
1535
- );
1536
- if (result?.data) {
1537
- const resultFile = result.data.function?.data?.general;
1538
- if (resultFile)
1539
- this.updateDocument(
1540
- resultFile.docId,
1541
- this.parseFileDefinition({
1542
- ...file,
1543
- ...resultFile,
1544
- isLocked: resultFile.locked,
1545
- locked: resultFile.locked,
1546
- lock: resultFile.locked
1547
- })
1548
- );
1549
- }
1550
- }
1551
- evaluateDeleteDocumentResult(result) {
1552
- return result?.function?.name === "fncDocumentRemove";
1553
- }
1554
- setTranslationFile(file, docId, langId) {
1555
- if (!this.state.translatedFiles.has(docId)) {
1556
- this.state.translatedFiles.set(docId, /* @__PURE__ */ new Map());
1557
- }
1558
- this.state.translatedFiles.get(docId)?.set(langId, file);
1559
- }
1560
- getCheckSignatureParameters(props) {
1561
- return props;
1562
- }
1563
- getAjaxUploadFileStatusParameters(props) {
1564
- return props;
1565
- }
1566
- getAjaxUploadStartParameters(props) {
1567
- return props;
1568
- }
1569
- getConfirmDropModalParameters(props) {
1570
- return props;
1571
- }
1572
- getCheckLockDocumentParameters(props) {
1573
- return props;
1574
- }
1575
- getCheckWebDavLockParameters(props) {
1576
- return props;
1577
- }
1578
- getConfirmDropModalPostdata(props) {
1579
- return props;
1580
- }
1581
- getDeleteDocumentParameters(props) {
1582
- return props;
1583
- }
1584
- getClearTempFilesParameters(props) {
1585
- return props;
1586
- }
1587
- getDocumentInfoParameters(props) {
1588
- return props;
1589
- }
1590
- getDownloadMultipleDocumentsParameters(props) {
1591
- return props;
1592
- }
1593
- getEditDocumentParameters(props) {
1594
- return props;
1595
- }
1596
- getLockDocumentParameters(props) {
1597
- return props;
1598
- }
1599
- getMarkFileToSignParameters(props) {
1600
- return props;
1601
- }
1602
- getProcessDroppedFilesParameters(props) {
1603
- return props;
1604
- }
1605
- getProcessDroppedFilesPostdata(props) {
1606
- return props;
1607
- }
1608
- getReloadMetadataParameters(props) {
1609
- return props;
1610
- }
1611
- getSaveDroppedFilesParameters(props) {
1612
- return props;
1613
- }
1614
- filterAlreadyUploadedFiles(files, conf) {
1615
- const versioningFile = this.state.versioningFile;
1616
- if (versioningFile)
1617
- return files;
1618
- const uploadedFiles = Object.values(this.state.files).filter(
1619
- (file) => Number(file.docId) > 0
1620
- );
1621
- const existingFiles = [];
1622
- const nonExistingFiles = [];
1623
- if (conf?.langId) {
1624
- const docId = conf.translatingFile?.docId ?? Infinity;
1625
- const translationsMap = this.state.translatedFiles.get(String(docId));
1626
- const alreadyUploadedToTranslationsFile = translationsMap ? Array.from(translationsMap.values()).find(
1627
- (current) => (current.docName || current.name) === files[0]?.name
1628
- ) : void 0;
1629
- if (alreadyUploadedToTranslationsFile)
1630
- existingFiles.push(files[0]);
1631
- } else
1632
- files.forEach((file) => {
1633
- if (uploadedFiles.find((search) => search.docName === file.name)) {
1634
- existingFiles.push(file);
1635
- } else
1636
- nonExistingFiles.push(file);
1637
- });
1638
- if (existingFiles.length > 0) {
1639
- void this.notify({
1640
- message: `${getLabel("msgDropFileRep", {}, this.props.context).text}: ${existingFiles.map((current) => current.name).join(", ")}`,
1641
- type: "warning"
1642
- });
1643
- return nonExistingFiles;
1644
- }
1645
- return files;
1646
- }
1647
- filterByFilesAmountLimit(files) {
1648
- return files.slice(
1649
- 0,
1650
- addBoundary(this.maxFiles - (this.state.inProgressFiles?.length ?? 0), 0)
1651
- );
1652
- }
1653
- filterAcceptedFiles(files, shouldNotify = true, docTypeId) {
1654
- const docTypes = docTypeId !== void 0 ? this.state.allowedTypes.filter((c) => {
1655
- return typeof docTypeId === "string" ? c.id === docTypeId : c.id === docTypeId.id;
1656
- }) : this.state.allowedTypes;
1657
- if (!docTypes.find((c) => c.docExts === "")) {
1658
- const notAllowedFilesBecauseOfExtension = [];
1659
- const notAllowedFilesBecauseOfSize = [];
1660
- let maxSize = Infinity;
1661
- const allowedFiles = files.filter((currentFile) => {
1662
- const extension = (currentFile.name.match(/\.(\w+)$/) ?? [])[1];
1663
- let isAllowed = true;
1664
- if (!docTypes.find((currentDocType) => {
1665
- if (!currentDocType.docExts.split(";").map((current) => current.toLowerCase()).includes(extension.toLowerCase())) {
1666
- return false;
1667
- }
1668
- return true;
1669
- })) {
1670
- isAllowed = false;
1671
- notAllowedFilesBecauseOfExtension.push(currentFile);
1672
- }
1673
- if (isAllowed && !docTypes.find((currentDocType) => {
1674
- if (Number(currentDocType.maxSize) < currentFile.size) {
1675
- maxSize = Number(currentDocType.maxSize);
1676
- return false;
1677
- }
1678
- return true;
1679
- })) {
1680
- notAllowedFilesBecauseOfSize.push(currentFile);
1681
- isAllowed = false;
1682
- }
1683
- if (!isAllowed)
1684
- return false;
1685
- return true;
1686
- });
1687
- if (shouldNotify) {
1688
- let errorMessage = "";
1689
- if (notAllowedFilesBecauseOfExtension.length > 0) {
1690
- const filesNames = notAllowedFilesBecauseOfExtension.reduce(
1691
- (accumulated, current) => {
1692
- if (accumulated.length === 0)
1693
- return current.name;
1694
- return `${accumulated}, ${current.name}`;
1695
- },
1696
- ""
1697
- );
1698
- errorMessage = `<strong>${getLabel("msgFileWrngExt", {}, this.props.context).text}</strong><br />${filesNames}`;
1699
- }
1700
- if (notAllowedFilesBecauseOfSize.length > 0) {
1701
- const filesNames = notAllowedFilesBecauseOfSize.reduce(
1702
- (accumulated, current) => {
1703
- if (accumulated.length === 0)
1704
- return current.name;
1705
- return `${accumulated}, ${current.name}`;
1706
- },
1707
- ""
1708
- );
1709
- if (errorMessage.length > 0)
1710
- errorMessage = `${errorMessage} <br /><br />`;
1711
- errorMessage = `${errorMessage}${formatMessage(
1712
- getLabel("msgFileTooBig", {}, this.props.context).text,
1713
- {
1714
- TOK1: `<br />${filesNames}`,
1715
- TOK2: `${parseAsSize(maxSize)}`
1716
- }
1717
- )}`;
1718
- }
1719
- if (errorMessage.length > 0)
1720
- this.notify({
1721
- message: errorMessage,
1722
- type: "warning"
1723
- });
1724
- }
1725
- return allowedFiles;
1726
- }
1727
- return files;
1728
- }
1729
- filterExistingFiles(files, conf) {
1730
- if (conf?.langId)
1731
- return files;
1732
- const currentFiles = this.state.inProgressFiles;
1733
- const alreadyUploadedFiles = Object.values(this.state.files).filter(
1734
- (current) => Number(current.docId) < 0
1735
- );
1736
- let alreadyIncludedFileNames = "";
1737
- const filteredFiles = files.filter((current) => {
1738
- const isIncluded = currentFiles.findIndex((search) => search.name === current.name) !== -1 || alreadyUploadedFiles.findIndex(
1739
- (search) => search.docName === current.name
1740
- ) !== -1;
1741
- if (isIncluded)
1742
- alreadyIncludedFileNames = `${alreadyIncludedFileNames}${alreadyIncludedFileNames.length > 0 ? ", " : ""}${current.name}`;
1743
- return !isIncluded;
1744
- });
1745
- if (alreadyIncludedFileNames.length > 0)
1746
- this.notify({
1747
- message: `${getLabel("msgDropFileRep", {}, this.props.context).text}: ${alreadyIncludedFileNames}`,
1748
- type: "warning"
1749
- });
1750
- return filteredFiles;
1751
- }
1752
- filterVersioningFiles(files, conf) {
1753
- const versioningFile = this.state.versioningFile;
1754
- if (versioningFile) {
1755
- const newFiles = files.filter(
1756
- (current) => current.name === versioningFile.docName || current.name === versioningFile.name
1757
- );
1758
- if (newFiles.length === 0) {
1759
- this.notify({
1760
- type: "warning",
1761
- message: getLabel("msgDocDiffFilename", {}, this.props.context).text
1762
- });
1763
- }
1764
- return newFiles;
1765
- }
1766
- return files;
1767
- }
1768
- getLoadFileSystemStructureTree() {
1769
- return {
1770
- useDocTypePermitted: true
1771
- };
1772
- }
1773
- getLoadFilesForFolderParameters() {
1774
- return {
1775
- useDocTypePermitted: true
1776
- };
1777
- }
1778
- }
1779
-
1780
- class FilePickerFolderNode extends DirectoryPickerFolderNode {
1781
- constructor(parent, props, params = {}) {
1782
- super(parent, props);
1783
- this.params = params;
1784
- this.state.isSelectable = false;
1785
- }
1786
- async loadMore(focus = true) {
1787
- const res = await ApiaApi.post(
1788
- this.getTree().api.context,
1789
- {
1790
- ajaxUrl: FilePickerActions.ajaxUrl,
1791
- action: FilePickerActions.loadFilesForFolder,
1792
- preventAsXmlParameter: true,
1793
- isAjax: true
1794
- },
1795
- {
1796
- postData: {
1797
- txtFld: this.state.nodeProps.id,
1798
- loadFolders: true,
1799
- txtCantDoc: this.getChildren().length,
1800
- offset: this.getChildren().length,
1801
- docTypePermittedObjId: this.params.docTypePermittedObjId,
1802
- docTypePermittedObjType: this.params.docTypePermittedObjType,
1803
- useDocTypePermitted: this.params.useDocTypePermitted,
1804
- docTypeForcedId: this.params.docTypeForcedId,
1805
- ...this.params
1806
- },
1807
- postDataTreatement: "stringify",
1808
- postDataStringifyOptions: {
1809
- arrayFormat: "repeat"
1810
- }
1811
- }
1812
- );
1813
- if (res?.data) {
1814
- const lastNode = this.getChildren()[this.getChildren().length - 1];
1815
- arrayOrArray(res.data.folders?.folder).forEach((folder) => {
1816
- if (!this.state.children.has(makeId(folder.id))) {
1817
- this.getTree().createFolder({
1818
- id: makeId(folder.id),
1819
- label: folder.name,
1820
- nodeProps: folder,
1821
- parentId: this.id
1822
- });
1823
- }
1824
- });
1825
- arrayOrArray(res.data.documents?.document).forEach((document) => {
1826
- if (!this.state.children.has(makeId(document.id))) {
1827
- this.getTree().createDocument({
1828
- id: makeId(document.id),
1829
- label: document.name,
1830
- nodeProps: document,
1831
- parentId: this.id
1832
- });
1833
- }
1834
- });
1835
- if ((res?.data.documents?.documentInfo?.moreDocs ?? 0) > 0) {
1836
- this.removeLoadMoreDocsNode();
1837
- this.loadMoreDocsNode = this.getTree().createFolder({
1838
- asyncNode: false,
1839
- icon: void 0,
1840
- isLeaf: true,
1841
- label: getLabel("lblShwMoreEls").text,
1842
- labelRenderer: this.getTree().renderers.LoadMoreRenderer,
1843
- onClick: async () => {
1844
- if (this.loadMoreDocsNode) {
1845
- this.loadMoreDocsNode.state.nodeProps.isLoadingMore = true;
1846
- }
1847
- await this.loadMore();
1848
- },
1849
- parentId: this.id
1850
- });
1851
- if (focus) {
1852
- this.tree.focusNode(this.loadMoreDocsNode);
1853
- }
1854
- } else {
1855
- this.removeLoadMoreDocsNode();
1856
- if (focus) {
1857
- this.tree.focusNode(lastNode.getFollowingSibling() ?? lastNode);
1858
- }
1859
- }
1860
- }
1861
- }
1862
- }
1863
-
1864
- class FilePicker extends DirectoriesPicker {
1865
- constructor(api) {
1866
- super(api);
1867
- }
1868
- getNodeHandler(nodeProps) {
1869
- return new FilePickerFolderNode(
1870
- this,
1871
- nodeProps,
1872
- this.api.getLoadFilesForFolderParameters()
1873
- );
1874
- }
1875
- getFolderStructureParams() {
1876
- return {
1877
- ajaxUrl: FilePickerActions.ajaxUrl,
1878
- action: FilePickerActions.loadFileSystemStructureTree,
1879
- preventAsXmlParameter: true,
1880
- isAjax: true,
1881
- isXml: true,
1882
- txtFld: this.api.modalConfig.rootFolder
1883
- };
1884
- }
1885
- parseStructureResponse(res) {
1886
- const castRes = res;
1887
- if (castRes.data?.folders.folder)
1888
- return arrayOrArray(castRes.data?.folders.folder);
1889
- return null;
1890
- }
1891
- }
1892
-
1893
- export { DirectoriesPicker, DirectoryPickerActions, DirectoryPickerFolderNode, DocumentNode, FilePicker, FilePickerActions, FilePickerFolderNode, UploaderApi, UploaderModalController, makeId, parseFileDefinition };
1
+ export { UploaderApi } from './UploaderApi.js';
2
+ export { UploaderModalController } from './UploaderModalController.js';
3
+ export { parseFileDefinition } from './util.js';
4
+ export { DirectoriesPicker } from './directories/DirectoriesPicker.js';
5
+ export { FilePicker } from './directories/FilePicker.js';
6
+ export { DirectoryPickerFolderNode } from './directories/nodes/DirectoryPickerFolderNode.js';
7
+ export { DocumentNode } from './directories/nodes/DocumentNode.js';
8
+ export { FilePickerFolderNode } from './directories/nodes/FilePickerFolderNode.js';
9
+ export { DirectoryPickerActions, FilePickerActions, makeId } from './directories/utils.js';
1894
10
  //# sourceMappingURL=index.js.map