@apia/uploader-controller 4.0.44 → 5.0.0

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
  }) => {
@@ -337,17 +557,6 @@ class UploaderApi extends EventEmitter {
337
557
  __publicField(this, "getConfirmDropModalAdditionalMetadataString", (additionalMetadata) => {
338
558
  return Object.values(additionalMetadata).filter((current) => !!current?.value).map((current) => `${current.name}~${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,16 +758,15 @@ 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";
@@ -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
  }
@@ -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 () => {
@@ -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
  );
@@ -902,7 +1111,7 @@ class UploaderApi extends EventEmitter {
902
1111
  const file = this.getDocument(fileId);
903
1112
  if (!file)
904
1113
  return;
905
- if (this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId))
1114
+ if (Number.parseInt(fileId) < 0 || this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId))
906
1115
  await downloadUrl(
907
1116
  ApiaApi.makeUrl(this.context, {
908
1117
  action: "downloadDocument",
@@ -913,11 +1122,10 @@ class UploaderApi extends EventEmitter {
913
1122
  }
914
1123
  async downloadDocument(id, version) {
915
1124
  const file = this.getDocument(id);
916
- if (this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId)) {
1125
+ if (Number.parseInt(id) < 0 || this.props.context.IN_MONITOR || await this.checkWebDavLock(file.docId)) {
917
1126
  await downloadUrl(
918
1127
  ApiaApi.makeUrl(this.context, {
919
1128
  action: "downloadDocument",
920
- prefix: this.props.type,
921
1129
  docId: file.downloadDocId,
922
1130
  ajaxUrl: this.getAjaxUrl(),
923
1131
  version
@@ -935,7 +1143,6 @@ class UploaderApi extends EventEmitter {
935
1143
  action: "ajaxRemoveDocument",
936
1144
  docId: file.docId,
937
1145
  isAjax: true,
938
- prefix: this.props.type,
939
1146
  ajaxUrl: this.getAjaxUrl(),
940
1147
  langId
941
1148
  })
@@ -955,7 +1162,7 @@ class UploaderApi extends EventEmitter {
955
1162
  this.modalController = this.buildModalController({
956
1163
  versionFile: file
957
1164
  });
958
- this.modalController.openModal();
1165
+ this.context.openModal();
959
1166
  }
960
1167
  };
961
1168
  if (!conf.newFiles || conf.newFiles.length === 0) {
@@ -1086,7 +1293,6 @@ class UploaderApi extends EventEmitter {
1086
1293
  action: "markDocTosign",
1087
1294
  docId: file.docId,
1088
1295
  isAjax: true,
1089
- prefix: this.props.type,
1090
1296
  ajaxUrl: this.getAjaxUrl(),
1091
1297
  langId
1092
1298
  })
@@ -1127,8 +1333,7 @@ class UploaderApi extends EventEmitter {
1127
1333
  this.context,
1128
1334
  this.getDownloadMultipleDocumentsParameters({
1129
1335
  action: "multipleDownload",
1130
- docId: ids,
1131
- prefix: this.props.type
1336
+ docId: ids
1132
1337
  })
1133
1338
  ),
1134
1339
  "documents.zip"
@@ -1154,7 +1359,6 @@ class UploaderApi extends EventEmitter {
1154
1359
  cmbDocType,
1155
1360
  docDesc,
1156
1361
  docAllowAllType,
1157
- // pe: this.docTypePermittedObjId?.toString(), // How do I get this?
1158
1362
  dropped: this.state.inProgressFiles.map((file) => file.name),
1159
1363
  txtLangId: langId,
1160
1364
  txtLangGroup: translatingFile?.docLangGroup,
@@ -1176,7 +1380,6 @@ class UploaderApi extends EventEmitter {
1176
1380
  ajaxUrl: this.getAjaxUrl(),
1177
1381
  docId: fromDirectoryFile ? fromDirectoryFile.docId : this.state.versioningFile?.docId,
1178
1382
  action: fromDirectoryFile ? "associateExistingFile" : "confirmDropModal",
1179
- elemType: this.props.type,
1180
1383
  fromForm: true,
1181
1384
  ...fromDirectoryFile ? {
1182
1385
  docId: fromDirectoryFile.docId,
@@ -1216,19 +1419,21 @@ class UploaderApi extends EventEmitter {
1216
1419
  }
1217
1420
  return false;
1218
1421
  }
1422
+ getLoadCurrentDocumentsParameters(params) {
1423
+ return params;
1424
+ }
1219
1425
  async loadCurrentDocuments() {
1220
1426
  const result = await ApiaApi.post(
1221
1427
  this.context,
1222
- {
1428
+ this.getLoadCurrentDocumentsParameters({
1223
1429
  ajaxUrl: this.getAjaxUrl(),
1224
1430
  action: "ajaxLoadCurrent",
1225
1431
  isAjax: true,
1226
1432
  readOnly: this.props.context.readonly,
1227
1433
  allowLock: true,
1228
1434
  allowSign: true,
1229
- allowMultiple: true,
1230
- prefix: this.props.type
1231
- },
1435
+ allowMultiple: true
1436
+ }),
1232
1437
  {}
1233
1438
  );
1234
1439
  if (result && result.data) {
@@ -1302,8 +1507,7 @@ class UploaderApi extends EventEmitter {
1302
1507
  ajaxUrl: this.getAjaxUrl(),
1303
1508
  docId: file.docId,
1304
1509
  lock: file.isLocked || file.locked,
1305
- isAjax: true,
1306
- prefix: this.props.type
1510
+ isAjax: true
1307
1511
  })
1308
1512
  );
1309
1513
  if (result?.data) {
@@ -1328,6 +1532,60 @@ class UploaderApi extends EventEmitter {
1328
1532
  }
1329
1533
  this.state.translatedFiles.get(docId)?.set(langId, file);
1330
1534
  }
1535
+ getCheckSignatureParameters(props) {
1536
+ return props;
1537
+ }
1538
+ getAjaxUploadFileStatusParameters(props) {
1539
+ return props;
1540
+ }
1541
+ getAjaxUploadStartParameters(props) {
1542
+ return props;
1543
+ }
1544
+ getConfirmDropModalParameters(props) {
1545
+ return props;
1546
+ }
1547
+ getCheckLockDocumentParameters(props) {
1548
+ return props;
1549
+ }
1550
+ getCheckWebDavLockParameters(props) {
1551
+ return props;
1552
+ }
1553
+ getConfirmDropModalPostdata(props) {
1554
+ return props;
1555
+ }
1556
+ getDeleteDocumentParameters(props) {
1557
+ return props;
1558
+ }
1559
+ getClearTempFilesParameters(props) {
1560
+ return props;
1561
+ }
1562
+ getDocumentInfoParameters(props) {
1563
+ return props;
1564
+ }
1565
+ getDownloadMultipleDocumentsParameters(props) {
1566
+ return props;
1567
+ }
1568
+ getEditDocumentParameters(props) {
1569
+ return props;
1570
+ }
1571
+ getLockDocumentParameters(props) {
1572
+ return props;
1573
+ }
1574
+ getMarkFileToSignParameters(props) {
1575
+ return props;
1576
+ }
1577
+ getProcessDroppedFilesParameters(props) {
1578
+ return props;
1579
+ }
1580
+ getProcessDroppedFilesPostdata(props) {
1581
+ return props;
1582
+ }
1583
+ getReloadMetadataParameters(props) {
1584
+ return props;
1585
+ }
1586
+ getSaveDroppedFilesParameters(props) {
1587
+ return props;
1588
+ }
1331
1589
  filterAlreadyUploadedFiles(files, conf) {
1332
1590
  const versioningFile = this.state.versioningFile;
1333
1591
  if (versioningFile)
@@ -1484,19 +1742,128 @@ class UploaderApi extends EventEmitter {
1484
1742
  }
1485
1743
  getLoadFileSystemStructureTree() {
1486
1744
  return {
1487
- useDocTypePermitted: true,
1488
- // docTypePermittedObjId: this.docTypePermittedObjId, // Get by inheritance
1489
- docTypePermittedObjType: this.props.type
1745
+ useDocTypePermitted: true
1490
1746
  };
1491
1747
  }
1492
1748
  getLoadFilesForFolderParameters() {
1493
1749
  return {
1494
- useDocTypePermitted: true,
1495
- // docTypePermittedObjId: this.docTypePermittedObjId, // Get by inheritance
1496
- docTypePermittedObjType: this.props.type
1750
+ useDocTypePermitted: true
1751
+ };
1752
+ }
1753
+ }
1754
+
1755
+ class FilePickerFolderNode extends DirectoryPickerFolderNode {
1756
+ constructor(parent, props, params = {}) {
1757
+ super(parent, props);
1758
+ this.params = params;
1759
+ this.state.isSelectable = false;
1760
+ }
1761
+ async loadMore(focus = true) {
1762
+ const res = await ApiaApi.post(
1763
+ this.getTree().api.context,
1764
+ {
1765
+ ajaxUrl: FilePickerActions.ajaxUrl,
1766
+ action: FilePickerActions.loadFilesForFolder,
1767
+ preventAsXmlParameter: true,
1768
+ isAjax: true
1769
+ },
1770
+ {
1771
+ postData: {
1772
+ txtFld: this.state.nodeProps.id,
1773
+ loadFolders: true,
1774
+ txtCantDoc: this.getChildren().length,
1775
+ offset: this.getChildren().length,
1776
+ docTypePermittedObjId: this.params.docTypePermittedObjId,
1777
+ docTypePermittedObjType: this.params.docTypePermittedObjType,
1778
+ useDocTypePermitted: this.params.useDocTypePermitted,
1779
+ docTypeForcedId: this.params.docTypeForcedId,
1780
+ ...this.params
1781
+ },
1782
+ postDataTreatement: "stringify",
1783
+ postDataStringifyOptions: {
1784
+ arrayFormat: "repeat"
1785
+ }
1786
+ }
1787
+ );
1788
+ if (res?.data) {
1789
+ const lastNode = this.getChildren()[this.getChildren().length - 1];
1790
+ arrayOrArray(res.data.folders?.folder).forEach((folder) => {
1791
+ if (!this.state.children.has(makeId(folder.id))) {
1792
+ this.getTree().createFolder({
1793
+ id: makeId(folder.id),
1794
+ label: folder.name,
1795
+ nodeProps: folder,
1796
+ parentId: this.id
1797
+ });
1798
+ }
1799
+ });
1800
+ arrayOrArray(res.data.documents?.document).forEach((document) => {
1801
+ if (!this.state.children.has(makeId(document.id))) {
1802
+ this.getTree().createDocument({
1803
+ id: makeId(document.id),
1804
+ label: document.name,
1805
+ nodeProps: document,
1806
+ parentId: this.id
1807
+ });
1808
+ }
1809
+ });
1810
+ if ((res?.data.documents?.documentInfo?.moreDocs ?? 0) > 0) {
1811
+ this.removeLoadMoreDocsNode();
1812
+ this.loadMoreDocsNode = this.getTree().createFolder({
1813
+ asyncNode: false,
1814
+ icon: void 0,
1815
+ isLeaf: true,
1816
+ label: getLabel("lblShwMoreEls").text,
1817
+ labelRenderer: this.getTree().renderers.LoadMoreRenderer,
1818
+ onClick: async () => {
1819
+ if (this.loadMoreDocsNode) {
1820
+ this.loadMoreDocsNode.state.nodeProps.isLoadingMore = true;
1821
+ }
1822
+ await this.loadMore();
1823
+ },
1824
+ parentId: this.id
1825
+ });
1826
+ if (focus) {
1827
+ this.tree.focusNode(this.loadMoreDocsNode);
1828
+ }
1829
+ } else {
1830
+ this.removeLoadMoreDocsNode();
1831
+ if (focus) {
1832
+ this.tree.focusNode(lastNode.getFollowingSibling() ?? lastNode);
1833
+ }
1834
+ }
1835
+ }
1836
+ }
1837
+ }
1838
+
1839
+ class FilePicker extends DirectoriesPicker {
1840
+ constructor(api) {
1841
+ super(api);
1842
+ }
1843
+ getNodeHandler(nodeProps) {
1844
+ return new FilePickerFolderNode(
1845
+ this,
1846
+ nodeProps,
1847
+ this.api.getLoadFilesForFolderParameters()
1848
+ );
1849
+ }
1850
+ getFolderStructureParams() {
1851
+ return {
1852
+ ajaxUrl: FilePickerActions.ajaxUrl,
1853
+ action: FilePickerActions.loadFileSystemStructureTree,
1854
+ preventAsXmlParameter: true,
1855
+ isAjax: true,
1856
+ isXml: true,
1857
+ txtFld: this.api.modalConfig.rootFolder
1497
1858
  };
1498
1859
  }
1860
+ parseStructureResponse(res) {
1861
+ const castRes = res;
1862
+ if (castRes.data?.folders.folder)
1863
+ return arrayOrArray(castRes.data?.folders.folder);
1864
+ return null;
1865
+ }
1499
1866
  }
1500
1867
 
1501
- export { UploaderApi, UploaderModalController, parseFileDefinition, returnExactlyTheSame };
1868
+ export { DirectoriesPicker, DirectoryPickerActions, DirectoryPickerFolderNode, DocumentNode, FilePicker, FilePickerActions, FilePickerFolderNode, UploaderApi, UploaderModalController, makeId, parseFileDefinition };
1502
1869
  //# sourceMappingURL=index.js.map