@apia/uploader-controller 4.0.44 → 4.0.47

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 CHANGED
@@ -1,19 +1,251 @@
1
- import { getLabel, toBoolean, EventEmitter, arrayOrArray, downloadUrl, addBoundary, formatMessage, parseAsSize } from '@apia/util';
1
+ import { arrayOrArray, getLabel, toBoolean, EventEmitter, downloadUrl, addBoundary, formatMessage, parseAsSize } from '@apia/util';
2
2
  import { makeObservable, observable } from 'mobx';
3
- import QueryString from 'qs';
3
+ import { MobXTreeNode, MobXTree } from '@apia/tree2-controller';
4
+ import { uniqueId } from 'lodash-es';
4
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
+ }
5
237
 
6
238
  var __defProp$1 = Object.defineProperty;
7
239
  var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
240
  var __publicField$1 = (obj, key, value) => {
9
- __defNormalProp$1(obj, key + "" , value);
241
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
10
242
  return value;
11
243
  };
12
244
  function getFileExtension(fileName) {
13
245
  const parts = fileName.split(".");
14
246
  return parts.length > 1 ? parts.pop().toLowerCase() : "";
15
247
  }
16
- const getInitialState = (execution) => Object.freeze({
248
+ const getInitialState = (context) => Object.freeze({
17
249
  metadata: {
18
250
  metadataArray: [],
19
251
  freeMetadataArray: [],
@@ -27,14 +259,14 @@ const getInitialState = (execution) => Object.freeze({
27
259
  isReadonly: false,
28
260
  permissions: {
29
261
  pools: [],
30
- users: execution.ownerCanUpdate ? [
262
+ users: context.ownerCanUpdate ? [
31
263
  {
32
264
  canUpdate: true,
33
- userId: execution.currentUserLogin,
34
- userLogin: execution.currentUserLogin
265
+ userId: context.currentUserLogin,
266
+ userLogin: context.currentUserLogin
35
267
  }
36
268
  ] : [],
37
- allowAllType: execution.everyoneCanUpdate !== false ? "M" : ""
269
+ allowAllType: context.everyoneCanUpdate !== false ? "M" : ""
38
270
  },
39
271
  fileReqError: false
40
272
  });
@@ -43,11 +275,18 @@ class UploaderModalController {
43
275
  this.api = api;
44
276
  this.modalConfig = modalConfig;
45
277
  this.conf = conf;
278
+ __publicField$1(this, "directories", null);
46
279
  __publicField$1(this, "state");
47
280
  makeObservable(this, {
48
281
  state: observable
49
282
  });
50
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
+ }
51
290
  }
52
291
  get allMetadata() {
53
292
  return [
@@ -225,15 +464,6 @@ class UploaderModalController {
225
464
  type: "warning"
226
465
  });
227
466
  }
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
467
  setDescription(desc) {
238
468
  this.state.description = desc;
239
469
  }
@@ -252,8 +482,8 @@ class UploaderModalController {
252
482
  isValid = false;
253
483
  }
254
484
  this.allMetadata.forEach((c) => {
255
- if (c.required === "Y") {
256
- if (c.name.trim() === "" && c.free === "Y") {
485
+ if (c.free === "Y") {
486
+ if (c.title.trim() === "") {
257
487
  c.labelErrorMessage = getLabel("msgReqField").text;
258
488
  isValid = false;
259
489
  }
@@ -268,15 +498,6 @@ class UploaderModalController {
268
498
  }
269
499
  }
270
500
 
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
501
  const parseFileDefinition = (context, fileDefinition, isSignRequired) => {
281
502
  const { lock, isLocked, lockedBy, userLocking, ...file } = fileDefinition;
282
503
  return {
@@ -288,13 +509,19 @@ const parseFileDefinition = (context, fileDefinition, isSignRequired) => {
288
509
  lockingUser: lockedBy || userLocking
289
510
  };
290
511
  };
512
+
513
+ var __defProp = Object.defineProperty;
514
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
515
+ var __publicField = (obj, key, value) => {
516
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
517
+ return value;
518
+ };
291
519
  class UploaderApi extends EventEmitter {
292
520
  constructor(props) {
293
521
  super();
294
522
  this.props = props;
295
523
  __publicField(this, "maxFiles", Infinity);
296
524
  __publicField(this, "modalController", null);
297
- __publicField(this, "allowTranslations", false);
298
525
  __publicField(this, "langs");
299
526
  __publicField(this, "currentConfiguration");
300
527
  __publicField(this, "state", {
@@ -309,13 +536,6 @@ class UploaderApi extends EventEmitter {
309
536
  translatedFiles: /* @__PURE__ */ new Map(),
310
537
  hasAllDocTypes: false
311
538
  });
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
539
  __publicField(this, "getConfirmDropModalMetadataString", ({
320
540
  metadata
321
541
  }) => {
@@ -335,19 +555,8 @@ class UploaderApi extends EventEmitter {
335
555
  return returnString;
336
556
  });
337
557
  __publicField(this, "getConfirmDropModalAdditionalMetadataString", (additionalMetadata) => {
338
- return Object.values(additionalMetadata).filter((current) => !!current?.value).map((current) => `${current.name}~${current.value}`).join(";");
558
+ return Object.values(additionalMetadata).filter((current) => !!current?.value).map((current) => `${current.title}~${current.value}`).join(";");
339
559
  });
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
560
  __publicField(this, "parseFileDefinition", (file) => {
352
561
  return {
353
562
  ...parseFileDefinition(this.props.context, file, false),
@@ -358,12 +567,17 @@ class UploaderApi extends EventEmitter {
358
567
  makeObservable(this, {
359
568
  state: observable
360
569
  });
361
- this.allowTranslations = props.type === "E" && !!this.props.context.docLangs;
362
570
  this.langs = this.props.context.docLangs;
363
571
  }
364
572
  get filesArray() {
365
573
  return Object.values(this.state.files);
366
574
  }
575
+ get id() {
576
+ return this.props.id;
577
+ }
578
+ get modalConfig() {
579
+ return this.props.modalConfig;
580
+ }
367
581
  get context() {
368
582
  return this.props.context;
369
583
  }
@@ -387,7 +601,7 @@ class UploaderApi extends EventEmitter {
387
601
  return;
388
602
  }
389
603
  this.modalController = this.buildModalController();
390
- this.modalController.openModal();
604
+ this.context.openModal();
391
605
  }
392
606
  }
393
607
  async onTranslateUpload(conf, files) {
@@ -404,7 +618,7 @@ class UploaderApi extends EventEmitter {
404
618
  }
405
619
  if (mustOpen) {
406
620
  this.modalController = this.buildModalController(conf);
407
- this.modalController.openModal();
621
+ this.context.openModal();
408
622
  }
409
623
  }
410
624
  }
@@ -460,7 +674,6 @@ class UploaderApi extends EventEmitter {
460
674
  isAjax: true,
461
675
  docId: id,
462
676
  newElem,
463
- prefix: this.props.type,
464
677
  ajaxUrl: this.getAjaxUrl()
465
678
  })
466
679
  );
@@ -545,29 +758,28 @@ class UploaderApi extends EventEmitter {
545
758
  if (this.props.context.IN_MONITOR) {
546
759
  return false;
547
760
  }
548
- const file = this.getDocument(id);
549
- if (Number(file.docId) < 0)
761
+ if (Number(id) < 0)
550
762
  return true;
763
+ const file = this.getDocument(id);
551
764
  const result = await ApiaApi.post(
552
765
  this.context,
553
766
  this.getCheckLockDocumentParameters({
554
767
  action: "checkLockDocument",
555
768
  docId: file.docId,
556
- ajaxUrl: this.getAjaxUrl(),
557
- prefix: this.props.type
769
+ ajaxUrl: this.getAjaxUrl()
558
770
  })
559
771
  );
560
772
  const isLocked = result?.data?.success === "ok";
561
773
  if (!isLocked && result?.data?.usr && result.data.usr !== this.props.context.currentUserLogin) {
562
774
  this.notify({
563
- message: `${getLabel("msgDocLockedByUsr", {}, this.props.context).text.split(".")[0]}: ${result.data.usr}.`,
775
+ message: `${getLabel("msgDocLocOthUsr", {}, this.props.context).text.split(".")[0]}: ${result.data.usr}.`,
564
776
  type: "warning"
565
777
  });
566
778
  return result.data.usr;
567
779
  }
568
780
  if (!isLocked && shouldNotifyUnlocked && !await this.autoLock())
569
781
  this.notify({
570
- message: getLabel("msgDocMustBeLocked", {}, this.props.context).text,
782
+ message: getLabel("msgDocMusBeLocForUpd", {}, this.props.context).text,
571
783
  type: "warning"
572
784
  });
573
785
  return isLocked;
@@ -586,12 +798,9 @@ class UploaderApi extends EventEmitter {
586
798
  action: "ajaxUploadStart",
587
799
  isAjax: true,
588
800
  docId: versioningFile?.docId,
589
- prefix: this.props.type,
590
801
  docTypeId: newFiles.length === 1 ? versioningFile?.docTypeId || "1" : "1",
591
802
  newDoc: !versioningFile,
592
- useDocTypePermitted: true,
593
- docTypePermittedObjType: this.props.type,
594
- // docTypePermittedObjId: this.docTypePermittedObjId, // How do I find this?
803
+ useDocTypePermitted: false,
595
804
  ajaxUrl: this.getAjaxUrl()
596
805
  })
597
806
  );
@@ -622,7 +831,6 @@ class UploaderApi extends EventEmitter {
622
831
  metadata: this.getConfirmDropModalMetadataString({
623
832
  metadata: this.modalController?.allMetadata
624
833
  }),
625
- prefix: this.props.type,
626
834
  ...additionalProps
627
835
  })
628
836
  );
@@ -630,9 +838,15 @@ class UploaderApi extends EventEmitter {
630
838
  const isFreeMetadata = this.state.allowedTypes.find(
631
839
  (current) => current.id === props.docTypeId
632
840
  )?.free ?? false;
633
- this.modalController.state.metadata.metadataArray = arrayOrArray(
634
- res.data.metadata
635
- );
841
+ this.modalController.state.metadata.freeMetadataArray = [];
842
+ this.modalController.state.metadata.metadataArray = [];
843
+ arrayOrArray(res.data.metadata).forEach((c) => {
844
+ if (c.free === "Y") {
845
+ this.modalController.state.metadata.freeMetadataArray.push(c);
846
+ } else {
847
+ this.modalController.state.metadata.metadataArray.push(c);
848
+ }
849
+ });
636
850
  this.modalController.state.metadata.isFreeMetadata = isFreeMetadata;
637
851
  }
638
852
  }
@@ -649,7 +863,7 @@ class UploaderApi extends EventEmitter {
649
863
  const docType = this.getCurrentDocTypeId();
650
864
  if (!isStrictMode && !docType) {
651
865
  this.notify({
652
- message: `${getLabel("lblDropFileDeleted", {}, this.props.context).text}: ${unprocessedFiles.map((current) => current.name).join(", ")}.`,
866
+ message: `${getLabel("msgDropFileDel", {}, this.props.context).text}: ${unprocessedFiles.map((current) => current.name).join(", ")}.`,
653
867
  type: "warning"
654
868
  });
655
869
  return false;
@@ -678,8 +892,6 @@ class UploaderApi extends EventEmitter {
678
892
  action: "saveDroppedFiles",
679
893
  docId: this.state.versioningFile?.docId,
680
894
  ajaxUrl: this.getAjaxUrl(),
681
- elemType: this.props.type,
682
- elemId: `prmDocumentContainter${this.props.type}`,
683
895
  frmOut: !this.modalController,
684
896
  docTypeId: this.state.selectedDocTypeId,
685
897
  langId
@@ -695,8 +907,7 @@ class UploaderApi extends EventEmitter {
695
907
  action: "ajaxUploadFileStatus",
696
908
  ajaxUrl: this.getAjaxUrl(),
697
909
  delayForDrop: true,
698
- isAjax: true,
699
- prefix: this.props.type
910
+ isAjax: true
700
911
  });
701
912
  let tries = 0;
702
913
  const checkUploadResult = async () => {
@@ -753,8 +964,6 @@ class UploaderApi extends EventEmitter {
753
964
  const postData = QueryString.stringify(
754
965
  this.getProcessDroppedFilesPostdata({
755
966
  useDocTypePermitted: true,
756
- // docTypePermittedObjId: this.docTypePermittedObjId?.toString(), // How do I get this?
757
- docTypePermittedObjType: this.props.type,
758
967
  dropped: allowedFiles.map((file) => file.name).concat(shown),
759
968
  shown
760
969
  }),
@@ -764,7 +973,6 @@ class UploaderApi extends EventEmitter {
764
973
  this.context,
765
974
  this.getProcessDroppedFilesParameters({
766
975
  action: "processDroppedFiles",
767
- elemType: this.props.type,
768
976
  docId: this.state.versioningFile?.docId,
769
977
  frmOut: !this.modalController,
770
978
  ajaxUrl: this.getAjaxUrl()
@@ -815,6 +1023,9 @@ class UploaderApi extends EventEmitter {
815
1023
  if (this.props.context.IN_MONITOR) {
816
1024
  return false;
817
1025
  }
1026
+ if (Number.parseInt(docId) < 0) {
1027
+ return true;
1028
+ }
818
1029
  return new Promise((resolve) => {
819
1030
  let tries = 10;
820
1031
  const checkLockAction = async () => {
@@ -831,7 +1042,7 @@ class UploaderApi extends EventEmitter {
831
1042
  setTimeout(() => void checkLockAction(), 1e3);
832
1043
  } else {
833
1044
  this.notify({
834
- message: getLabel("msgFailSyncDocument", {}, this.props.context).text
1045
+ message: getLabel("msgFailSyncDoc", {}, this.props.context).text
835
1046
  });
836
1047
  resolve(false);
837
1048
  }
@@ -852,7 +1063,6 @@ class UploaderApi extends EventEmitter {
852
1063
  docId: file.docId,
853
1064
  lock: false,
854
1065
  isAjax: true,
855
- prefix: this.props.type,
856
1066
  react: true
857
1067
  })
858
1068
  );
@@ -869,7 +1079,6 @@ class UploaderApi extends EventEmitter {
869
1079
  this.getEditDocumentParameters({
870
1080
  action: "updateWebDavDocument",
871
1081
  docId: file.docId,
872
- prefix: this.props.type,
873
1082
  isAjax: true
874
1083
  })
875
1084
  );
@@ -878,7 +1087,16 @@ class UploaderApi extends EventEmitter {
878
1087
  const ProtocolInstallMessage = () => {
879
1088
  this.notify({
880
1089
  type: "warning",
881
- message: getLabel("msgNoDocEditProtocol", {}, this.props.context).text,
1090
+ message: getLabel(
1091
+ "msgNoDocEdiProto",
1092
+ {
1093
+ text: {
1094
+ TOK1: `<a href="${this.props.context.WEBDAV_INSTALLER_URL}" download>`,
1095
+ TOK2: `</a>`
1096
+ }
1097
+ },
1098
+ this.props.context
1099
+ ).text,
882
1100
  title: getLabel("lblEdit", {}, this.props.context).text
883
1101
  });
884
1102
  };
@@ -902,7 +1120,7 @@ class UploaderApi extends EventEmitter {
902
1120
  const file = this.getDocument(fileId);
903
1121
  if (!file)
904
1122
  return;
905
- if (this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId))
1123
+ if (Number.parseInt(fileId) < 0 || this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId))
906
1124
  await downloadUrl(
907
1125
  ApiaApi.makeUrl(this.context, {
908
1126
  action: "downloadDocument",
@@ -913,11 +1131,10 @@ class UploaderApi extends EventEmitter {
913
1131
  }
914
1132
  async downloadDocument(id, version) {
915
1133
  const file = this.getDocument(id);
916
- if (this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId)) {
1134
+ if (Number.parseInt(id) < 0 || this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId)) {
917
1135
  await downloadUrl(
918
1136
  ApiaApi.makeUrl(this.context, {
919
1137
  action: "downloadDocument",
920
- prefix: this.props.type,
921
1138
  docId: file.downloadDocId,
922
1139
  ajaxUrl: this.getAjaxUrl(),
923
1140
  version
@@ -935,7 +1152,6 @@ class UploaderApi extends EventEmitter {
935
1152
  action: "ajaxRemoveDocument",
936
1153
  docId: file.docId,
937
1154
  isAjax: true,
938
- prefix: this.props.type,
939
1155
  ajaxUrl: this.getAjaxUrl(),
940
1156
  langId
941
1157
  })
@@ -955,7 +1171,7 @@ class UploaderApi extends EventEmitter {
955
1171
  this.modalController = this.buildModalController({
956
1172
  versionFile: file
957
1173
  });
958
- this.modalController.openModal();
1174
+ this.context.openModal();
959
1175
  }
960
1176
  };
961
1177
  if (!conf.newFiles || conf.newFiles.length === 0) {
@@ -1086,7 +1302,6 @@ class UploaderApi extends EventEmitter {
1086
1302
  action: "markDocTosign",
1087
1303
  docId: file.docId,
1088
1304
  isAjax: true,
1089
- prefix: this.props.type,
1090
1305
  ajaxUrl: this.getAjaxUrl(),
1091
1306
  langId
1092
1307
  })
@@ -1127,8 +1342,7 @@ class UploaderApi extends EventEmitter {
1127
1342
  this.context,
1128
1343
  this.getDownloadMultipleDocumentsParameters({
1129
1344
  action: "multipleDownload",
1130
- docId: ids,
1131
- prefix: this.props.type
1345
+ docId: ids
1132
1346
  })
1133
1347
  ),
1134
1348
  "documents.zip"
@@ -1154,7 +1368,6 @@ class UploaderApi extends EventEmitter {
1154
1368
  cmbDocType,
1155
1369
  docDesc,
1156
1370
  docAllowAllType,
1157
- // pe: this.docTypePermittedObjId?.toString(), // How do I get this?
1158
1371
  dropped: this.state.inProgressFiles.map((file) => file.name),
1159
1372
  txtLangId: langId,
1160
1373
  txtLangGroup: translatingFile?.docLangGroup,
@@ -1176,7 +1389,6 @@ class UploaderApi extends EventEmitter {
1176
1389
  ajaxUrl: this.getAjaxUrl(),
1177
1390
  docId: fromDirectoryFile ? fromDirectoryFile.docId : this.state.versioningFile?.docId,
1178
1391
  action: fromDirectoryFile ? "associateExistingFile" : "confirmDropModal",
1179
- elemType: this.props.type,
1180
1392
  fromForm: true,
1181
1393
  ...fromDirectoryFile ? {
1182
1394
  docId: fromDirectoryFile.docId,
@@ -1216,19 +1428,21 @@ class UploaderApi extends EventEmitter {
1216
1428
  }
1217
1429
  return false;
1218
1430
  }
1431
+ getLoadCurrentDocumentsParameters(params) {
1432
+ return params;
1433
+ }
1219
1434
  async loadCurrentDocuments() {
1220
1435
  const result = await ApiaApi.post(
1221
1436
  this.context,
1222
- {
1437
+ this.getLoadCurrentDocumentsParameters({
1223
1438
  ajaxUrl: this.getAjaxUrl(),
1224
1439
  action: "ajaxLoadCurrent",
1225
1440
  isAjax: true,
1226
1441
  readOnly: this.props.context.readonly,
1227
1442
  allowLock: true,
1228
1443
  allowSign: true,
1229
- allowMultiple: true,
1230
- prefix: this.props.type
1231
- },
1444
+ allowMultiple: true
1445
+ }),
1232
1446
  {}
1233
1447
  );
1234
1448
  if (result && result.data) {
@@ -1277,7 +1491,7 @@ class UploaderApi extends EventEmitter {
1277
1491
  const file = this.getDocument(id);
1278
1492
  if (file.markedToSign) {
1279
1493
  this.notify({
1280
- message: getLabel("lblCantUnlockMarkedToSign", {}, this.props.context).text,
1494
+ message: getLabel("msgCantActFileMarkSign", {}, this.props.context).text,
1281
1495
  type: "warning"
1282
1496
  });
1283
1497
  return;
@@ -1302,8 +1516,7 @@ class UploaderApi extends EventEmitter {
1302
1516
  ajaxUrl: this.getAjaxUrl(),
1303
1517
  docId: file.docId,
1304
1518
  lock: file.isLocked || file.locked,
1305
- isAjax: true,
1306
- prefix: this.props.type
1519
+ isAjax: true
1307
1520
  })
1308
1521
  );
1309
1522
  if (result?.data) {
@@ -1328,6 +1541,60 @@ class UploaderApi extends EventEmitter {
1328
1541
  }
1329
1542
  this.state.translatedFiles.get(docId)?.set(langId, file);
1330
1543
  }
1544
+ getCheckSignatureParameters(props) {
1545
+ return props;
1546
+ }
1547
+ getAjaxUploadFileStatusParameters(props) {
1548
+ return props;
1549
+ }
1550
+ getAjaxUploadStartParameters(props) {
1551
+ return props;
1552
+ }
1553
+ getConfirmDropModalParameters(props) {
1554
+ return props;
1555
+ }
1556
+ getCheckLockDocumentParameters(props) {
1557
+ return props;
1558
+ }
1559
+ getCheckWebDavLockParameters(props) {
1560
+ return props;
1561
+ }
1562
+ getConfirmDropModalPostdata(props) {
1563
+ return props;
1564
+ }
1565
+ getDeleteDocumentParameters(props) {
1566
+ return props;
1567
+ }
1568
+ getClearTempFilesParameters(props) {
1569
+ return props;
1570
+ }
1571
+ getDocumentInfoParameters(props) {
1572
+ return props;
1573
+ }
1574
+ getDownloadMultipleDocumentsParameters(props) {
1575
+ return props;
1576
+ }
1577
+ getEditDocumentParameters(props) {
1578
+ return props;
1579
+ }
1580
+ getLockDocumentParameters(props) {
1581
+ return props;
1582
+ }
1583
+ getMarkFileToSignParameters(props) {
1584
+ return props;
1585
+ }
1586
+ getProcessDroppedFilesParameters(props) {
1587
+ return props;
1588
+ }
1589
+ getProcessDroppedFilesPostdata(props) {
1590
+ return props;
1591
+ }
1592
+ getReloadMetadataParameters(props) {
1593
+ return props;
1594
+ }
1595
+ getSaveDroppedFilesParameters(props) {
1596
+ return props;
1597
+ }
1331
1598
  filterAlreadyUploadedFiles(files, conf) {
1332
1599
  const versioningFile = this.state.versioningFile;
1333
1600
  if (versioningFile)
@@ -1354,7 +1621,7 @@ class UploaderApi extends EventEmitter {
1354
1621
  });
1355
1622
  if (existingFiles.length > 0) {
1356
1623
  void this.notify({
1357
- message: `${getLabel("lblDropFileRepeated", {}, this.props.context).text}: ${existingFiles.map((current) => current.name).join(", ")}`,
1624
+ message: `${getLabel("msgDropFileRep", {}, this.props.context).text}: ${existingFiles.map((current) => current.name).join(", ")}`,
1358
1625
  type: "warning"
1359
1626
  });
1360
1627
  return nonExistingFiles;
@@ -1412,7 +1679,7 @@ class UploaderApi extends EventEmitter {
1412
1679
  },
1413
1680
  ""
1414
1681
  );
1415
- errorMessage = `<strong>${getLabel("lblFilesWrongExt", {}, this.props.context).text}</strong><br />${filesNames}`;
1682
+ errorMessage = `<strong>${getLabel("msgFileWrngExt", {}, this.props.context).text}</strong><br />${filesNames}`;
1416
1683
  }
1417
1684
  if (notAllowedFilesBecauseOfSize.length > 0) {
1418
1685
  const filesNames = notAllowedFilesBecauseOfSize.reduce(
@@ -1426,7 +1693,7 @@ class UploaderApi extends EventEmitter {
1426
1693
  if (errorMessage.length > 0)
1427
1694
  errorMessage = `${errorMessage} <br /><br />`;
1428
1695
  errorMessage = `${errorMessage}${formatMessage(
1429
- getLabel("lblFilesTooBig", {}, this.props.context).text,
1696
+ getLabel("msgFileTooBig", {}, this.props.context).text,
1430
1697
  {
1431
1698
  TOK1: `<br />${filesNames}`,
1432
1699
  TOK2: `${parseAsSize(maxSize)}`
@@ -1461,7 +1728,7 @@ class UploaderApi extends EventEmitter {
1461
1728
  });
1462
1729
  if (alreadyIncludedFileNames.length > 0)
1463
1730
  this.notify({
1464
- message: `${getLabel("lblDropFileRepeated", {}, this.props.context).text}: ${alreadyIncludedFileNames}`,
1731
+ message: `${getLabel("msgDropFileRep", {}, this.props.context).text}: ${alreadyIncludedFileNames}`,
1465
1732
  type: "warning"
1466
1733
  });
1467
1734
  return filteredFiles;
@@ -1475,7 +1742,7 @@ class UploaderApi extends EventEmitter {
1475
1742
  if (newFiles.length === 0) {
1476
1743
  this.notify({
1477
1744
  type: "warning",
1478
- message: getLabel("lblDropFileNamesNotMatch", {}, this.props.context).text
1745
+ message: getLabel("msgDocDiffFilename", {}, this.props.context).text
1479
1746
  });
1480
1747
  }
1481
1748
  return newFiles;
@@ -1484,19 +1751,128 @@ class UploaderApi extends EventEmitter {
1484
1751
  }
1485
1752
  getLoadFileSystemStructureTree() {
1486
1753
  return {
1487
- useDocTypePermitted: true,
1488
- // docTypePermittedObjId: this.docTypePermittedObjId, // Get by inheritance
1489
- docTypePermittedObjType: this.props.type
1754
+ useDocTypePermitted: true
1490
1755
  };
1491
1756
  }
1492
1757
  getLoadFilesForFolderParameters() {
1493
1758
  return {
1494
- useDocTypePermitted: true,
1495
- // docTypePermittedObjId: this.docTypePermittedObjId, // Get by inheritance
1496
- docTypePermittedObjType: this.props.type
1759
+ useDocTypePermitted: true
1760
+ };
1761
+ }
1762
+ }
1763
+
1764
+ class FilePickerFolderNode extends DirectoryPickerFolderNode {
1765
+ constructor(parent, props, params = {}) {
1766
+ super(parent, props);
1767
+ this.params = params;
1768
+ this.state.isSelectable = false;
1769
+ }
1770
+ async loadMore(focus = true) {
1771
+ const res = await ApiaApi.post(
1772
+ this.getTree().api.context,
1773
+ {
1774
+ ajaxUrl: FilePickerActions.ajaxUrl,
1775
+ action: FilePickerActions.loadFilesForFolder,
1776
+ preventAsXmlParameter: true,
1777
+ isAjax: true
1778
+ },
1779
+ {
1780
+ postData: {
1781
+ txtFld: this.state.nodeProps.id,
1782
+ loadFolders: true,
1783
+ txtCantDoc: this.getChildren().length,
1784
+ offset: this.getChildren().length,
1785
+ docTypePermittedObjId: this.params.docTypePermittedObjId,
1786
+ docTypePermittedObjType: this.params.docTypePermittedObjType,
1787
+ useDocTypePermitted: this.params.useDocTypePermitted,
1788
+ docTypeForcedId: this.params.docTypeForcedId,
1789
+ ...this.params
1790
+ },
1791
+ postDataTreatement: "stringify",
1792
+ postDataStringifyOptions: {
1793
+ arrayFormat: "repeat"
1794
+ }
1795
+ }
1796
+ );
1797
+ if (res?.data) {
1798
+ const lastNode = this.getChildren()[this.getChildren().length - 1];
1799
+ arrayOrArray(res.data.folders?.folder).forEach((folder) => {
1800
+ if (!this.state.children.has(makeId(folder.id))) {
1801
+ this.getTree().createFolder({
1802
+ id: makeId(folder.id),
1803
+ label: folder.name,
1804
+ nodeProps: folder,
1805
+ parentId: this.id
1806
+ });
1807
+ }
1808
+ });
1809
+ arrayOrArray(res.data.documents?.document).forEach((document) => {
1810
+ if (!this.state.children.has(makeId(document.id))) {
1811
+ this.getTree().createDocument({
1812
+ id: makeId(document.id),
1813
+ label: document.name,
1814
+ nodeProps: document,
1815
+ parentId: this.id
1816
+ });
1817
+ }
1818
+ });
1819
+ if ((res?.data.documents?.documentInfo?.moreDocs ?? 0) > 0) {
1820
+ this.removeLoadMoreDocsNode();
1821
+ this.loadMoreDocsNode = this.getTree().createFolder({
1822
+ asyncNode: false,
1823
+ icon: void 0,
1824
+ isLeaf: true,
1825
+ label: getLabel("lblShwMoreEls").text,
1826
+ labelRenderer: this.getTree().renderers.LoadMoreRenderer,
1827
+ onClick: async () => {
1828
+ if (this.loadMoreDocsNode) {
1829
+ this.loadMoreDocsNode.state.nodeProps.isLoadingMore = true;
1830
+ }
1831
+ await this.loadMore();
1832
+ },
1833
+ parentId: this.id
1834
+ });
1835
+ if (focus) {
1836
+ this.tree.focusNode(this.loadMoreDocsNode);
1837
+ }
1838
+ } else {
1839
+ this.removeLoadMoreDocsNode();
1840
+ if (focus) {
1841
+ this.tree.focusNode(lastNode.getFollowingSibling() ?? lastNode);
1842
+ }
1843
+ }
1844
+ }
1845
+ }
1846
+ }
1847
+
1848
+ class FilePicker extends DirectoriesPicker {
1849
+ constructor(api) {
1850
+ super(api);
1851
+ }
1852
+ getNodeHandler(nodeProps) {
1853
+ return new FilePickerFolderNode(
1854
+ this,
1855
+ nodeProps,
1856
+ this.api.getLoadFilesForFolderParameters()
1857
+ );
1858
+ }
1859
+ getFolderStructureParams() {
1860
+ return {
1861
+ ajaxUrl: FilePickerActions.ajaxUrl,
1862
+ action: FilePickerActions.loadFileSystemStructureTree,
1863
+ preventAsXmlParameter: true,
1864
+ isAjax: true,
1865
+ isXml: true,
1866
+ txtFld: this.api.modalConfig.rootFolder
1497
1867
  };
1498
1868
  }
1869
+ parseStructureResponse(res) {
1870
+ const castRes = res;
1871
+ if (castRes.data?.folders.folder)
1872
+ return arrayOrArray(castRes.data?.folders.folder);
1873
+ return null;
1874
+ }
1499
1875
  }
1500
1876
 
1501
- export { UploaderApi, UploaderModalController, parseFileDefinition, returnExactlyTheSame };
1877
+ export { DirectoriesPicker, DirectoryPickerActions, DirectoryPickerFolderNode, DocumentNode, FilePicker, FilePickerActions, FilePickerFolderNode, UploaderApi, UploaderModalController, makeId, parseFileDefinition };
1502
1878
  //# sourceMappingURL=index.js.map