@apia/execution 4.0.44 → 4.0.46

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
@@ -4,13 +4,13 @@ import xml2js from 'xml2js';
4
4
  import he from 'he';
5
5
  import { parseBooleans, parseNumbers } from 'xml2js/lib/processors';
6
6
  import QueryString from 'qs';
7
- import { arrayOrArray, EventEmitter as EventEmitter$1, isTrue, toBoolean, downloadUrl, addBoundary, formatMessage, parseAsSize, shallowEqual as shallowEqual$1, Mutex, noNaN as noNaN$1, getDateFormat, decodeBase64ToUtf8 as decodeBase64ToUtf8$1, encodeStrToBase64Utf8, uniqueId, parseXMLRequestResponse, Url, postNavigation } from '@apia/util';
7
+ import { arrayOrArray, EventEmitter as EventEmitter$1, isTrue, toBoolean, downloadUrl, shallowEqual as shallowEqual$1, Mutex, noNaN as noNaN$1, getDateFormat, decodeBase64ToUtf8 as decodeBase64ToUtf8$1, encodeStrToBase64Utf8, uniqueId, parseXMLRequestResponse, Url, postNavigation } from '@apia/util';
8
8
  import { Cell, TableController, Row, FocusControllerPlugin } from '@apia/table2-controller';
9
+ import { UploaderApi as UploaderApi$1, parseFileDefinition } from '@apia/uploader-controller';
9
10
  import dayjs from 'dayjs';
10
11
  import customParseFormat from 'dayjs/plugin/customParseFormat';
11
12
  import { MobXTree } from '@apia/tree2-controller';
12
13
  import { Scheduler } from '@apia/scheduler-controller';
13
- export { Scheduler } from '@apia/scheduler-controller';
14
14
 
15
15
  const deepEqual = (a, b) => {
16
16
  if (Object.is(a, b))
@@ -48,16 +48,16 @@ const deepEqual = (a, b) => {
48
48
  return a === b;
49
49
  };
50
50
 
51
- var __defProp$t = Object.defineProperty;
52
- var __defNormalProp$t = (obj, key, value) => key in obj ? __defProp$t(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
53
- var __publicField$t = (obj, key, value) => {
54
- __defNormalProp$t(obj, key + "" , value);
51
+ var __defProp$s = Object.defineProperty;
52
+ var __defNormalProp$s = (obj, key, value) => key in obj ? __defProp$s(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
53
+ var __publicField$s = (obj, key, value) => {
54
+ __defNormalProp$s(obj, key + "" , value);
55
55
  return value;
56
56
  };
57
57
  class Notification {
58
58
  constructor(props) {
59
59
  this.props = props;
60
- __publicField$t(this, "state");
60
+ __publicField$s(this, "state");
61
61
  this.state = props;
62
62
  makeObservable(this, { state: observable });
63
63
  }
@@ -479,7 +479,7 @@ var ExecutionState = /* @__PURE__ */ ((ExecutionState2) => {
479
479
 
480
480
  function dispatchMessage(execution, type, message) {
481
481
  const definedType = message.type;
482
- const actualType = [null, "success", "warning", "error"][definedType || 0];
482
+ const actualType = [null, "success", "warning", "error", "modal"][definedType || 0];
483
483
  execution.notifications.add(
484
484
  new MessageNotification({
485
485
  message: message.text,
@@ -710,20 +710,20 @@ function makeApiaUrl(execution, props) {
710
710
  return `${contextWord ? "/" : ""}${contextWord}/${actualAjaxUrl}?${timestamp}${!props?.preventAsXmlParameter ? "asXml=true&" : ""}${props?.queryString ? `${props.queryString}&` : ""}${queryString ? `${queryString}&` : ""}${tabId}`;
711
711
  }
712
712
 
713
- var __defProp$s = Object.defineProperty;
714
- var __defNormalProp$s = (obj, key, value) => key in obj ? __defProp$s(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
715
- var __publicField$s = (obj, key, value) => {
716
- __defNormalProp$s(obj, typeof key !== "symbol" ? key + "" : key, value);
713
+ var __defProp$r = Object.defineProperty;
714
+ var __defNormalProp$r = (obj, key, value) => key in obj ? __defProp$r(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
715
+ var __publicField$r = (obj, key, value) => {
716
+ __defNormalProp$r(obj, typeof key !== "symbol" ? key + "" : key, value);
717
717
  return value;
718
718
  };
719
719
  class EventEmitter {
720
720
  constructor() {
721
- __publicField$s(this, "callbacks", {
721
+ __publicField$r(this, "callbacks", {
722
722
  on: {},
723
723
  once: {}
724
724
  });
725
- __publicField$s(this, "enabled", true);
726
- __publicField$s(this, "debugMode", false);
725
+ __publicField$r(this, "enabled", true);
726
+ __publicField$r(this, "debugMode", false);
727
727
  }
728
728
  debug(enable = true) {
729
729
  this.debugMode = enable;
@@ -789,10 +789,10 @@ class EventEmitter {
789
789
  }
790
790
  }
791
791
 
792
- var __defProp$r = Object.defineProperty;
793
- var __defNormalProp$r = (obj, key, value) => key in obj ? __defProp$r(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
794
- var __publicField$r = (obj, key, value) => {
795
- __defNormalProp$r(obj, key + "" , value);
792
+ var __defProp$q = Object.defineProperty;
793
+ var __defNormalProp$q = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
794
+ var __publicField$q = (obj, key, value) => {
795
+ __defNormalProp$q(obj, key + "" , value);
796
796
  return value;
797
797
  };
798
798
  function isSetter(data) {
@@ -801,7 +801,7 @@ function isSetter(data) {
801
801
  class StatefulEmitter extends EventEmitter {
802
802
  constructor(initialState) {
803
803
  super();
804
- __publicField$r(this, "state", {});
804
+ __publicField$q(this, "state", {});
805
805
  this.state = Object.assign({}, initialState);
806
806
  }
807
807
  emit(event, data) {
@@ -836,18 +836,18 @@ class StatefulEmitter extends EventEmitter {
836
836
  }
837
837
  }
838
838
 
839
- var __defProp$q = Object.defineProperty;
840
- var __defNormalProp$q = (obj, key, value) => key in obj ? __defProp$q(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
841
- var __publicField$q = (obj, key, value) => {
842
- __defNormalProp$q(obj, typeof key !== "symbol" ? key + "" : key, value);
839
+ var __defProp$p = Object.defineProperty;
840
+ var __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
841
+ var __publicField$p = (obj, key, value) => {
842
+ __defNormalProp$p(obj, typeof key !== "symbol" ? key + "" : key, value);
843
843
  return value;
844
844
  };
845
845
  const NullObject = Symbol("NullObject");
846
846
  class BouncingEmitter extends StatefulEmitter {
847
847
  constructor() {
848
848
  super(...arguments);
849
- __publicField$q(this, "bouncingTimeouts", {});
850
- __publicField$q(this, "defaultTiming", 100);
849
+ __publicField$p(this, "bouncingTimeouts", {});
850
+ __publicField$p(this, "defaultTiming", 100);
851
851
  /**
852
852
  * Throttles a event emit with the warranty that the data will be emitted at most every (timing)ms. Take the following event throttling, where each E is a call to this method and each character represents 20ms:
853
853
  *
@@ -859,8 +859,8 @@ class BouncingEmitter extends StatefulEmitter {
859
859
  *
860
860
  * @param configuration.emitOnStart - Emits an event on the first call to throttle when no pending throttle is stored. **If emitOnStart is true and an only call to throttle is made, it will emit an only event.**
861
861
  */
862
- __publicField$q(this, "throttleData", {});
863
- __publicField$q(this, "throttleEmittedOnInit", {});
862
+ __publicField$p(this, "throttleData", {});
863
+ __publicField$p(this, "throttleEmittedOnInit", {});
864
864
  }
865
865
  /**
866
866
  * Debounces a event emit with until there is no call to the emit methods by (timing)ms. Take the following event throttling, where each E is a call to this method and each character represents 20ms:
@@ -911,7 +911,7 @@ class BouncingEmitter extends StatefulEmitter {
911
911
  }
912
912
 
913
913
  function getLabel(execution, label, replacers) {
914
- const original = getWindow(execution)?.labels?.[label];
914
+ const original = getWindow(execution).labels[label];
915
915
  if (!original) {
916
916
  return {
917
917
  text: `LblNotPrealoded: ${label}`,
@@ -990,16 +990,16 @@ function parseFakeJSON$1(str) {
990
990
  return ret;
991
991
  }
992
992
 
993
- var __defProp$p = Object.defineProperty;
994
- var __defNormalProp$p = (obj, key, value) => key in obj ? __defProp$p(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
995
- var __publicField$p = (obj, key, value) => {
996
- __defNormalProp$p(obj, typeof key !== "symbol" ? key + "" : key, value);
993
+ var __defProp$o = Object.defineProperty;
994
+ var __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
995
+ var __publicField$o = (obj, key, value) => {
996
+ __defNormalProp$o(obj, typeof key !== "symbol" ? key + "" : key, value);
997
997
  return value;
998
998
  };
999
999
  class WithProperties {
1000
1000
  constructor(initialState) {
1001
- __publicField$p(this, "properties", {});
1002
- __publicField$p(this, "parentGrid", null);
1001
+ __publicField$o(this, "properties", {});
1002
+ __publicField$o(this, "parentGrid", null);
1003
1003
  if (initialState) {
1004
1004
  this.properties = initialState;
1005
1005
  }
@@ -1193,10 +1193,10 @@ const asyncCreateNewField = async (execution, fld) => {
1193
1193
  return creator(execution, fld);
1194
1194
  };
1195
1195
 
1196
- var __defProp$o = Object.defineProperty;
1197
- var __defNormalProp$o = (obj, key, value) => key in obj ? __defProp$o(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1198
- var __publicField$o = (obj, key, value) => {
1199
- __defNormalProp$o(obj, typeof key !== "symbol" ? key + "" : key, value);
1196
+ var __defProp$n = Object.defineProperty;
1197
+ var __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1198
+ var __publicField$n = (obj, key, value) => {
1199
+ __defNormalProp$n(obj, typeof key !== "symbol" ? key + "" : key, value);
1200
1200
  return value;
1201
1201
  };
1202
1202
  var __accessCheck$l = (obj, member, msg) => {
@@ -1230,9 +1230,9 @@ async function getApiaFunctions(execution) {
1230
1230
  class Field extends WithProperties {
1231
1231
  constructor({ properties, ...definition }) {
1232
1232
  super();
1233
- __publicField$o(this, "form", {});
1234
- __publicField$o(this, "definition");
1235
- __publicField$o(this, "state", {
1233
+ __publicField$n(this, "form", {});
1234
+ __publicField$n(this, "definition");
1235
+ __publicField$n(this, "state", {
1236
1236
  validation: { dirty: false, errorMessage: "", synchronizing: false }
1237
1237
  });
1238
1238
  __privateAdd$l(this, _hasInited$1, false);
@@ -1302,8 +1302,15 @@ class Field extends WithProperties {
1302
1302
  }).text
1303
1303
  );
1304
1304
  }
1305
+ const evtSrc = await asyncCreateNewField(
1306
+ this.form.execution,
1307
+ this
1308
+ );
1309
+ if (evtSrc.setValue) {
1310
+ evtSrc.setValue = (value) => evtSrc._setValue(value, { fireEvents: false });
1311
+ }
1305
1312
  result = await fn(
1306
- await asyncCreateNewField(this.form.execution, this),
1313
+ evtSrc,
1307
1314
  ...await this.getScriptEventParams(event.fncParams)
1308
1315
  );
1309
1316
  if (result === false) {
@@ -1453,16 +1460,16 @@ class Button extends Field {
1453
1460
  }
1454
1461
  }
1455
1462
 
1456
- var __defProp$n = Object.defineProperty;
1457
- var __defNormalProp$n = (obj, key, value) => key in obj ? __defProp$n(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1458
- var __publicField$n = (obj, key, value) => {
1459
- __defNormalProp$n(obj, typeof key !== "symbol" ? key + "" : key, value);
1463
+ var __defProp$m = Object.defineProperty;
1464
+ var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1465
+ var __publicField$m = (obj, key, value) => {
1466
+ __defNormalProp$m(obj, typeof key !== "symbol" ? key + "" : key, value);
1460
1467
  return value;
1461
1468
  };
1462
1469
  const _Captcha = class _Captcha extends Field {
1463
1470
  constructor(definition) {
1464
1471
  super(definition);
1465
- __publicField$n(this, "id", "");
1472
+ __publicField$m(this, "id", "");
1466
1473
  this.state.value = "";
1467
1474
  this.properties.name = "__captcha__";
1468
1475
  _Captcha.emitter.on("confirm", () => {
@@ -1513,8 +1520,8 @@ const _Captcha = class _Captcha extends Field {
1513
1520
  }
1514
1521
  }
1515
1522
  };
1516
- __publicField$n(_Captcha, "emitter", new EventEmitter$1());
1517
- __publicField$n(_Captcha, "confirmParams", {});
1523
+ __publicField$m(_Captcha, "emitter", new EventEmitter$1());
1524
+ __publicField$m(_Captcha, "confirmParams", {});
1518
1525
  let Captcha = _Captcha;
1519
1526
 
1520
1527
  class TooMuchRetriesException extends Error {
@@ -1587,10 +1594,10 @@ function isFieldShowAsText(f) {
1587
1594
  return isTrue(f.properties.disabled) || isTrue(f.getForm().definition.readonly) || isTrue(f.getForm().definition.readOnly) || isTrue(f.properties.inputAsText);
1588
1595
  }
1589
1596
 
1590
- var __defProp$m = Object.defineProperty;
1591
- var __defNormalProp$m = (obj, key, value) => key in obj ? __defProp$m(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1592
- var __publicField$m = (obj, key, value) => {
1593
- __defNormalProp$m(obj, typeof key !== "symbol" ? key + "" : key, value);
1597
+ var __defProp$l = Object.defineProperty;
1598
+ var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1599
+ var __publicField$l = (obj, key, value) => {
1600
+ __defNormalProp$l(obj, typeof key !== "symbol" ? key + "" : key, value);
1594
1601
  return value;
1595
1602
  };
1596
1603
  var __accessCheck$k = (obj, member, msg) => {
@@ -1631,8 +1638,8 @@ class FieldWithAttribute extends Field {
1631
1638
  }) {
1632
1639
  super(definition);
1633
1640
  __privateAdd$k(this, _lastOnChangeValue, null);
1634
- __publicField$m(this, "lastSynchronizationValue", null);
1635
- __publicField$m(this, "attribute");
1641
+ __publicField$l(this, "lastSynchronizationValue", null);
1642
+ __publicField$l(this, "attribute");
1636
1643
  this.attribute = new Attribute(attId, attName, attLabel, valueType);
1637
1644
  this.state.value = value;
1638
1645
  this.state.validation = {
@@ -1777,6 +1784,9 @@ class FieldWithAttribute extends Field {
1777
1784
  return await syncPromise;
1778
1785
  }
1779
1786
  hasValue() {
1787
+ return this.getValue() !== "";
1788
+ }
1789
+ isValidValue() {
1780
1790
  return !!this.getValue();
1781
1791
  }
1782
1792
  async validate() {
@@ -1786,7 +1796,7 @@ class FieldWithAttribute extends Field {
1786
1796
  return false;
1787
1797
  }
1788
1798
  }
1789
- const isValid = isFieldShowAsText(this) || this.hasValue() || !this.properties.required || this.properties.visibilityHidden || this.properties.disabled;
1799
+ const isValid = isFieldShowAsText(this) || this.isValidValue() || !this.properties.required || this.properties.visibilityHidden || this.properties.disabled;
1790
1800
  this.state.validation.errorMessage = isValid ? null : labels.errorFieldRequired(this.form.execution);
1791
1801
  return !this.state.validation.errorMessage;
1792
1802
  }
@@ -1829,16 +1839,16 @@ class Checkbox extends FieldWithAttribute {
1829
1839
  }
1830
1840
  }
1831
1841
 
1832
- var __defProp$l = Object.defineProperty;
1833
- var __defNormalProp$l = (obj, key, value) => key in obj ? __defProp$l(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1834
- var __publicField$l = (obj, key, value) => {
1835
- __defNormalProp$l(obj, key + "" , value);
1842
+ var __defProp$k = Object.defineProperty;
1843
+ var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1844
+ var __publicField$k = (obj, key, value) => {
1845
+ __defNormalProp$k(obj, key + "" , value);
1836
1846
  return value;
1837
1847
  };
1838
1848
  class Translation {
1839
1849
  constructor(execution, state) {
1840
1850
  this.execution = execution;
1841
- __publicField$l(this, "state");
1851
+ __publicField$k(this, "state");
1842
1852
  this.state = {
1843
1853
  ...state,
1844
1854
  hasChanged: false,
@@ -1903,19 +1913,19 @@ function parseFakeJSON(fakeJSON) {
1903
1913
  }));
1904
1914
  }
1905
1915
 
1906
- var __defProp$k = Object.defineProperty;
1907
- var __defNormalProp$k = (obj, key, value) => key in obj ? __defProp$k(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1908
- var __publicField$k = (obj, key, value) => {
1909
- __defNormalProp$k(obj, typeof key !== "symbol" ? key + "" : key, value);
1916
+ var __defProp$j = Object.defineProperty;
1917
+ var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1918
+ var __publicField$j = (obj, key, value) => {
1919
+ __defNormalProp$j(obj, typeof key !== "symbol" ? key + "" : key, value);
1910
1920
  return value;
1911
1921
  };
1912
1922
  class TranslatableField extends FieldWithAttribute {
1913
1923
  constructor(props) {
1914
1924
  super(props);
1915
- __publicField$k(this, "translations", /* @__PURE__ */ new Map());
1916
- __publicField$k(this, "selectedLanguageId", this.getLanguages()[0]?.id);
1917
- __publicField$k(this, "isTradLoading", false);
1918
- __publicField$k(this, "definitionTradParsed", {});
1925
+ __publicField$j(this, "translations", /* @__PURE__ */ new Map());
1926
+ __publicField$j(this, "selectedLanguageId", this.getLanguages()[0]?.id);
1927
+ __publicField$j(this, "isTradLoading", false);
1928
+ __publicField$j(this, "definitionTradParsed", {});
1919
1929
  makeObservable(this, {
1920
1930
  translations: observable,
1921
1931
  selectedLanguageId: observable,
@@ -1950,1645 +1960,142 @@ class TranslatableField extends FieldWithAttribute {
1950
1960
  isTranslated
1951
1961
  })
1952
1962
  );
1953
- });
1954
- this.selectedLanguageId = this.getLanguages()[0].id;
1955
- }
1956
- }
1957
- cancelTranslations() {
1958
- this.getTranslations().forEach((c) => {
1959
- c.reset();
1960
- });
1961
- }
1962
- deleteTranslations() {
1963
- this.getTranslations().forEach((c) => {
1964
- c.deleteTranslation();
1965
- });
1966
- }
1967
- async changeLanguage(langId) {
1968
- this.selectedLanguageId = langId;
1969
- this.syncTranslation();
1970
- }
1971
- getTranslation(id) {
1972
- return this.translations.get(id);
1973
- }
1974
- getCurrentTranslation() {
1975
- return this.translations.get(this.selectedLanguageId);
1976
- }
1977
- getTranslations() {
1978
- return this.translations;
1979
- }
1980
- submitTranslations() {
1981
- [...this.getTranslations().values()].filter((c) => c.state.hasChanged).forEach((c) => {
1982
- c.submitTranslation(
1983
- c.value,
1984
- this.getSynchronizeUrl({
1985
- react: true,
1986
- preventAsXmlParameter: true,
1987
- langId: c.langId
1988
- })
1989
- );
1990
- });
1991
- this.state.validation.errorMessage = null;
1992
- }
1993
- async syncTranslation() {
1994
- const langId = this.selectedLanguageId;
1995
- this.isTradLoading = true;
1996
- await this.getTranslation(langId)?.readTranslations(
1997
- await makeApiaUrl(this.form.execution, {
1998
- ajaxUrl: "/apia.execution.FormAction.run",
1999
- action: "getFieldTranslations",
2000
- frmId: this.getForm().definition.id,
2001
- frmParent: this.getForm().definition.frmParent,
2002
- fldId: this.definition.id,
2003
- attId: this.attribute.id,
2004
- langId,
2005
- react: true
2006
- })
2007
- );
2008
- this.isTradLoading = false;
2009
- }
2010
- async validate() {
2011
- const isSuperValid = await super.validate();
2012
- let isValid = isSuperValid;
2013
- const canValidate = isSuperValid && this.properties.reqTrad && this.hasValue() && (!this.properties.inputAsText || !this.properties.visibilityHidden || !this.properties.disabled);
2014
- if (canValidate) {
2015
- const translations = [...this.getTranslations().values()];
2016
- const tradNotValidated = translations.find((c) => !c.state.isTranslated);
2017
- if (tradNotValidated) {
2018
- this.state.validation.errorMessage = labels.errorTranslateRequired(
2019
- this.form.execution,
2020
- tradNotValidated.state.label
2021
- );
2022
- isValid = false;
2023
- } else {
2024
- this.state.validation.errorMessage = null;
2025
- }
2026
- }
2027
- return isValid;
2028
- }
2029
- setValue(newValue, options) {
2030
- if (newValue === "") {
2031
- this.deleteTranslations();
2032
- }
2033
- return super.setValue(newValue, options);
2034
- }
2035
- }
2036
-
2037
- class Editor extends TranslatableField {
2038
- fireEvent(eventName, options) {
2039
- return super.fireEvent(eventName, options);
2040
- }
2041
- hasValue() {
2042
- return !!String(this.getValue()).trim();
2043
- }
2044
- getSynchronizePostConfiguration(value) {
2045
- const conf = super.getSynchronizePostConfiguration(value);
2046
- conf.postData.clearValues = "true";
2047
- return conf;
2048
- }
2049
- }
2050
-
2051
- var __defProp$j = Object.defineProperty;
2052
- var __defNormalProp$j = (obj, key, value) => key in obj ? __defProp$j(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2053
- var __publicField$j = (obj, key, value) => {
2054
- __defNormalProp$j(obj, key + "" , value);
2055
- return value;
2056
- };
2057
- function getFileExtension(fileName) {
2058
- const parts = fileName.split(".");
2059
- return parts.length > 1 ? parts.pop().toLowerCase() : "";
2060
- }
2061
- const getInitialState = (execution) => Object.freeze({
2062
- metadata: {
2063
- metadataArray: [],
2064
- freeMetadataArray: [],
2065
- isFreeMetadata: false
2066
- },
2067
- fromDirectoryFile: null,
2068
- docFolder: void 0,
2069
- docPath: void 0,
2070
- docExpDate: void 0,
2071
- description: "",
2072
- isReadonly: false,
2073
- permissions: {
2074
- pools: [],
2075
- users: getWindow(execution).DOCUMENT_OWNER_PRIVILEGES ? [
2076
- {
2077
- canUpdate: true,
2078
- userId: getWindow(execution).CURRENT_USER_LOGIN,
2079
- userLogin: getWindow(execution).CURRENT_USER_LOGIN
2080
- }
2081
- ] : [],
2082
- allowAllType: getWindow(execution).DOCUMENT_EVERYONE_PERMISSION !== false ? "M" : ""
2083
- },
2084
- fileReqError: false
2085
- });
2086
- class UploaderModalController {
2087
- constructor(api, modalConfig, conf) {
2088
- this.api = api;
2089
- this.modalConfig = modalConfig;
2090
- this.conf = conf;
2091
- __publicField$j(this, "state");
2092
- makeObservable(this, {
2093
- state: observable
2094
- });
2095
- this.state = getInitialState(api.execution);
2096
- }
2097
- get allMetadata() {
2098
- return [
2099
- ...this.state.metadata.metadataArray,
2100
- ...this.state.metadata.freeMetadataArray
2101
- ];
2102
- }
2103
- get allowAllType() {
2104
- return this.state.permissions.allowAllType;
2105
- }
2106
- get description() {
2107
- return this.state.description;
2108
- }
2109
- get docFolder() {
2110
- return this.state.docFolder;
2111
- }
2112
- get docExpDate() {
2113
- return this.state.docExpDate;
2114
- }
2115
- get docTypes() {
2116
- return this.api.getDocTypes();
2117
- }
2118
- get freeMetadata() {
2119
- return this.state.metadata.freeMetadataArray;
2120
- }
2121
- get exitingFiles() {
2122
- return this.api.getExistingFiles();
2123
- }
2124
- get inProgressFiles() {
2125
- return this.api.getInProgressFiles();
2126
- }
2127
- get hiddenFiles() {
2128
- return this.api.getHiddenFiles();
2129
- }
2130
- get progress() {
2131
- return this.api.getProgress();
2132
- }
2133
- get metadata() {
2134
- return this.state.metadata.metadataArray;
2135
- }
2136
- get selectedDocTypeId() {
2137
- return this.api.getCurrentDocTypeId();
2138
- }
2139
- get selectedDocType() {
2140
- return this.api.getCurrentDocType();
2141
- }
2142
- addMetadata() {
2143
- this.state.metadata.freeMetadataArray.push({
2144
- free: "Y",
2145
- id: String(Math.random()),
2146
- name: "",
2147
- required: "Y",
2148
- title: "",
2149
- type: "S",
2150
- value: "",
2151
- errorMessage: "",
2152
- labelErrorMessage: ""
2153
- });
2154
- }
2155
- addFiles(files) {
2156
- this.state.fileReqError = false;
2157
- this.state.isReadonly = false;
2158
- this.api.saveDroppedFiles(files, this.conf);
2159
- }
2160
- addDirectoryFile(file) {
2161
- this.state.fileReqError = false;
2162
- this.api.state.inProgressFiles = [];
2163
- this.state.fromDirectoryFile = file;
2164
- }
2165
- async changeDocType(docTypeId) {
2166
- this.resetMetadata();
2167
- this.api.setCurrentDocTypeId(docTypeId);
2168
- this.onChangeExtension();
2169
- this.api.reloadMetadata({ docTypeId });
2170
- }
2171
- clearDirectoryFile() {
2172
- this.state.fromDirectoryFile = null;
2173
- this.state.isReadonly = false;
2174
- }
2175
- clearFile(name) {
2176
- this.api.clearFile(name);
2177
- }
2178
- clearFiles() {
2179
- this.api.clearFiles();
2180
- }
2181
- clearState() {
2182
- this.state = getInitialState(this.api.execution);
2183
- this.api.clearState();
2184
- }
2185
- clearPartialState() {
2186
- if (this.api.state.inProgressFiles.length === 0) {
2187
- this.state = getInitialState(this.api.execution);
2188
- }
2189
- }
2190
- onCloseModal() {
2191
- this.clearState();
2192
- }
2193
- async confirm() {
2194
- let isValid = this.validate();
2195
- if (isValid)
2196
- isValid = await this.api.confirmDropModal(this.conf);
2197
- return isValid;
2198
- }
2199
- deleteMetadata(indices) {
2200
- const deleteSet = new Set(indices);
2201
- const offset = this.state.metadata.metadataArray.length;
2202
- this.state.metadata.freeMetadataArray = this.state.metadata.freeMetadataArray.filter(
2203
- (_, localIndex) => (
2204
- // conservamos sólo los que NO estén en deleteSet
2205
- !deleteSet.has(localIndex + offset)
2206
- )
2207
- );
2208
- }
2209
- deletePermission(item) {
2210
- if (item && "userId" in item) {
2211
- this.state.permissions.users = this.state.permissions.users.filter(
2212
- (c) => c.userId !== item.userId
2213
- );
2214
- } else {
2215
- this.state.permissions.pools = this.state.permissions.pools.filter(
2216
- (c) => c.poolId !== item.poolId
2217
- );
2218
- }
2219
- }
2220
- onChangeExtension() {
2221
- const rawDocExts = this.api.getCurrentDocType()?.docExts || "";
2222
- let hideFileNames = "";
2223
- const allowedExtensions = rawDocExts.split(";").map((ext) => ext.trim()).filter((ext) => ext !== "");
2224
- if (rawDocExts === "") {
2225
- const allFiles = [...this.inProgressFiles, ...this.hiddenFiles];
2226
- const dedupedFiles = Array.from(
2227
- new Map(allFiles.map((file) => [file.name, file])).values()
2228
- );
2229
- this.api.state.inProgressFiles = dedupedFiles;
2230
- this.api.state.hiddenFiles = [];
2231
- return;
2232
- }
2233
- const allowedInProgress = [];
2234
- const toHide = [];
2235
- this.inProgressFiles.forEach((file) => {
2236
- const ext = getFileExtension(file.name);
2237
- if (allowedExtensions.includes(ext)) {
2238
- allowedInProgress.push(file);
2239
- } else {
2240
- toHide.push(file);
2241
- hideFileNames += ` ${file.name} `;
2242
- }
2243
- });
2244
- const allowedHidden = [];
2245
- const stillHidden = [];
2246
- this.api.state.hiddenFiles.forEach((file) => {
2247
- const ext = getFileExtension(file.name);
2248
- if (allowedExtensions.includes(ext)) {
2249
- allowedHidden.push(file);
2250
- } else {
2251
- stillHidden.push(file);
2252
- }
2253
- });
2254
- const combinedInProgress = [...allowedInProgress, ...allowedHidden];
2255
- const dedupedInProgress = Array.from(
2256
- new Map(
2257
- combinedInProgress.map((file) => [file.name, file])
2258
- ).values()
2259
- );
2260
- const combinedHidden = [...toHide, ...stillHidden];
2261
- const dedupedHidden = Array.from(
2262
- new Map(combinedHidden.map((file) => [file.name, file])).values()
2263
- );
2264
- this.api.state.inProgressFiles = dedupedInProgress;
2265
- this.api.state.hiddenFiles = dedupedHidden;
2266
- if (hideFileNames)
2267
- this.api.notify({
2268
- title: getLabel(this.api.execution, "msgFileWrngExt").text,
2269
- message: hideFileNames,
2270
- type: "warning"
2271
- });
2272
- }
2273
- async openModal() {
2274
- const a = "openUploaderModal";
2275
- import(
2276
- /* webpackInclude: /\.tsx?$/ */
2277
- `/src/static/files/${a}`
2278
- ).then((r) => {
2279
- r.default(this);
2280
- });
2281
- }
2282
- setDescription(desc) {
2283
- this.state.description = desc;
2284
- }
2285
- async resetMetadata() {
2286
- this.state.metadata = {
2287
- freeMetadataArray: [],
2288
- metadataArray: [],
2289
- isFreeMetadata: false
2290
- };
2291
- }
2292
- validate() {
2293
- let isValid = true;
2294
- this.state.fileReqError = false;
2295
- if (this.api.getInProgressFiles().length === 0 && !this.state.fromDirectoryFile) {
2296
- this.state.fileReqError = true;
2297
- isValid = false;
2298
- }
2299
- this.allMetadata.forEach((c) => {
2300
- if (c.required === "Y") {
2301
- if (c.name.trim() === "" && c.free === "Y") {
2302
- c.labelErrorMessage = getLabel(
2303
- this.api.execution,
2304
- "msgReqField"
2305
- ).text;
2306
- isValid = false;
2307
- }
2308
- if (c.value.trim() === "") {
2309
- if (!c.errorMessage)
2310
- c.errorMessage = getLabel(this.api.execution, "msgReqField").text;
2311
- isValid = false;
2312
- }
2313
- }
2314
- });
2315
- return isValid;
2316
- }
2317
- }
2318
-
2319
- var __defProp$i = Object.defineProperty;
2320
- var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2321
- var __publicField$i = (obj, key, value) => {
2322
- __defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
2323
- return value;
2324
- };
2325
- function returnExactlyTheSame(defaultParameters) {
2326
- return defaultParameters;
2327
- }
2328
- function isOneClickUploadEnabled(execution, oneClickUploadProp) {
2329
- return !getWindow(execution).avoidOneClickUpload && (getWindow(execution).forceOneClickUpload || oneClickUploadProp || false);
2330
- }
2331
- const parseFileDefinition = (execution, fileDefinition, isSignRequired) => {
2332
- const { lock, isLocked, lockedBy, userLocking, ...file } = fileDefinition;
2333
- return {
2334
- ...file,
2335
- isLocked: isLocked === "true" || isLocked === true || toBoolean(lock) || file.locked === true,
2336
- isLockedByMe: (lockedBy || userLocking) === getWindow(execution).CURRENT_USER_LOGIN,
2337
- isMarkedToSign: file.markedToSign || toBoolean(file.sign) || isSignRequired,
2338
- isVirtual: file.virtualDoc ?? false,
2339
- lockingUser: lockedBy || userLocking
2340
- };
2341
- };
2342
- class UploaderApi extends EventEmitter$1 {
2343
- constructor(execution, id, type, modalConfig) {
2344
- super();
2345
- this.execution = execution;
2346
- this.id = id;
2347
- this.type = type;
2348
- this.modalConfig = modalConfig;
2349
- __publicField$i(this, "maxFiles", Infinity);
2350
- __publicField$i(this, "modalController", null);
2351
- __publicField$i(this, "allowTranslations", false);
2352
- __publicField$i(this, "langs");
2353
- __publicField$i(this, "currentConfiguration");
2354
- __publicField$i(this, "docTypePermittedObjId");
2355
- __publicField$i(this, "state", {
2356
- progress: 0,
2357
- allowedTypes: [],
2358
- selectedDocTypeId: "1",
2359
- versioningFile: null,
2360
- inProgressFiles: [],
2361
- files: {},
2362
- selectedFiles: [],
2363
- hiddenFiles: [],
2364
- translatedFiles: /* @__PURE__ */ new Map(),
2365
- hasAllDocTypes: false
2366
- });
2367
- __publicField$i(this, "getCheckSignatureParameters", returnExactlyTheSame);
2368
- __publicField$i(this, "getAjaxUploadFileStatusParameters", returnExactlyTheSame);
2369
- __publicField$i(this, "getAjaxUploadStartParameters", returnExactlyTheSame);
2370
- __publicField$i(this, "getConfirmDropModalParameters", returnExactlyTheSame);
2371
- __publicField$i(this, "getCheckLockDocumentParameters", returnExactlyTheSame);
2372
- __publicField$i(this, "getCheckWebDavLockParameters", returnExactlyTheSame);
2373
- __publicField$i(this, "getConfirmDropModalPostdata", returnExactlyTheSame);
2374
- __publicField$i(this, "getConfirmDropModalMetadataString", ({
2375
- metadata
2376
- }) => {
2377
- return metadata?.filter?.((current) => !!current.value).map((current) => `${current.id}~${current.type}~${current.value}`).join(";") ?? [];
2378
- });
2379
- __publicField$i(this, "getConfirmDropModalPermissionsString", ({
2380
- poolsPermissions,
2381
- usersPermissions
2382
- }) => {
2383
- let returnString = "";
2384
- poolsPermissions.forEach(
2385
- (current) => returnString = `${returnString}${returnString.length > 0 ? "&" : ""}docPoolId=${current.poolId}&docPoolName=${current.poolName}&docPermType${current.poolId}=${String(current.canUpdate)}`
2386
- );
2387
- usersPermissions.forEach(
2388
- (current) => returnString = `${returnString}${returnString.length > 0 ? "&" : ""}docUserId=${current.userId}&docUsrLogin=${current.userLogin}&docPermType${current.userId}=${String(current.canUpdate)}`
2389
- );
2390
- return returnString;
2391
- });
2392
- __publicField$i(this, "getConfirmDropModalAdditionalMetadataString", (additionalMetadata) => {
2393
- return Object.values(additionalMetadata).filter((current) => !!current?.value).map((current) => `${current.name}~${current.value}`).join(";");
2394
- });
2395
- __publicField$i(this, "getDeleteDocumentParameters", returnExactlyTheSame);
2396
- __publicField$i(this, "getClearTempFilesParameters", returnExactlyTheSame);
2397
- __publicField$i(this, "getDocumentInfoParameters", returnExactlyTheSame);
2398
- __publicField$i(this, "getDownloadMultipleDocumentsParameters", returnExactlyTheSame);
2399
- __publicField$i(this, "getEditDocumentParameters", returnExactlyTheSame);
2400
- __publicField$i(this, "getLockDocumentParameters", returnExactlyTheSame);
2401
- __publicField$i(this, "getMarkFileToSignParameters", returnExactlyTheSame);
2402
- __publicField$i(this, "getProcessDroppedFilesParameters", returnExactlyTheSame);
2403
- __publicField$i(this, "getProcessDroppedFilesPostdata", returnExactlyTheSame);
2404
- __publicField$i(this, "getReloadMetadataParameters", returnExactlyTheSame);
2405
- __publicField$i(this, "getSaveDroppedFilesParameters", returnExactlyTheSame);
2406
- __publicField$i(this, "parseFileDefinition", (file) => {
2407
- return {
2408
- ...parseFileDefinition(this.execution, file, false),
2409
- canEdit: file.canEdit || file.canWrite,
2410
- canRead: file.canRead
2411
- };
2412
- });
2413
- if (!getWindow(this.execution).fileApi) {
2414
- getWindow(this.execution).fileApi = {};
2415
- }
2416
- getWindow(this.execution).fileApi[this.id] = this;
2417
- makeObservable(this, {
2418
- state: observable
2419
- });
2420
- this.allowTranslations = type === "E" && !!getWindow(this.execution).DOC_LANGS;
2421
- this.langs = getWindow(this.execution).DOC_LANGS;
2422
- try {
2423
- this.docTypePermittedObjId = type === "E" ? getWindow(this.execution).docTypePerEntId : getWindow(this.execution).docTypePerProId;
2424
- } catch (e) {
2425
- console.warn(e);
2426
- }
2427
- }
2428
- get filesArray() {
2429
- return Object.values(this.state.files);
2430
- }
2431
- async init() {
2432
- await this.ajaxUploadStart();
2433
- await this.reloadMetadata({
2434
- docTypeId: this.state.selectedDocTypeId
2435
- });
2436
- await this.loadCurrentDocuments();
2437
- }
2438
- async onStartUpload(files) {
2439
- if (this.modalConfig.oneClickUpload) {
2440
- await this.saveDroppedFiles(files ?? []);
2441
- } else {
2442
- if (files) {
2443
- const result = await this.saveDroppedFiles(files ?? []);
2444
- if (!result)
2445
- return;
2446
- }
2447
- this.modalController = new UploaderModalController(
2448
- this,
2449
- this.modalConfig
2450
- );
2451
- this.modalController.openModal();
2452
- }
2453
- }
2454
- async onTranslateUpload(conf, files) {
2455
- if (this.modalConfig.oneClickUpload) {
2456
- await this.saveDroppedFiles(files ?? [], conf);
2457
- } else {
2458
- await this.init();
2459
- let mustOpen = true;
2460
- if (files) {
2461
- const res = await this.saveDroppedFiles(files ?? [], conf);
2462
- if (!res) {
2463
- mustOpen = false;
2464
- }
2465
- }
2466
- if (mustOpen) {
2467
- this.modalController = new UploaderModalController(
2468
- this,
2469
- this.modalConfig,
2470
- conf
2471
- );
2472
- this.modalController.openModal();
2473
- }
2474
- }
2475
- }
2476
- async onVersionUpload(file, conf = { newFiles: [] }) {
2477
- this.version(file, conf);
2478
- }
2479
- async autoLock() {
2480
- return new Promise((resolve) => {
2481
- resolve(false);
2482
- });
2483
- }
2484
- notify(notification) {
2485
- this.execution.notifications.add(new MessageNotification(notification));
2486
- }
2487
- getAjaxUrl() {
2488
- return getWindow(this.execution).URL_REQUEST_AJAX;
2489
- }
2490
- getDocTypes() {
2491
- return this.state.allowedTypes;
2492
- }
2493
- getCurrentDocTypeId() {
2494
- return this.state.selectedDocTypeId;
2495
- }
2496
- getCurrentDocType() {
2497
- return this.state.allowedTypes.find(
2498
- (c) => c.id === this.state.selectedDocTypeId
2499
- );
2500
- }
2501
- getInProgressFiles() {
2502
- return this.state.inProgressFiles;
2503
- }
2504
- getHiddenFiles() {
2505
- return this.state.hiddenFiles;
2506
- }
2507
- getExistingFiles() {
2508
- return this.state.files;
2509
- }
2510
- getProgress() {
2511
- return this.state.progress;
2512
- }
2513
- getHasAllDocTypes() {
2514
- return this.state.hasAllDocTypes;
2515
- }
2516
- async getDocumentInfo({
2517
- docId: apiId,
2518
- downloadDocId: docId
2519
- }, newElem) {
2520
- const id = apiId ? this.getDocument(apiId).docId : docId;
2521
- const result = await post(
2522
- this.execution,
2523
- makeApiaUrl(
2524
- this.execution,
2525
- this.getDocumentInfoParameters({
2526
- action: "getDocumentInfo",
2527
- isAjax: true,
2528
- docId: id,
2529
- newElem,
2530
- prefix: this.type,
2531
- ajaxUrl: this.getAjaxUrl()
2532
- })
2533
- )
2534
- );
2535
- if (result?.data) {
2536
- return result.data;
2537
- }
2538
- return null;
2539
- }
2540
- /**
2541
- * This method searches for the provided id in several places:
2542
- *
2543
- * If it's found in the current files, returns it.
2544
- * If not, it searches the provided docId in the translations map of each uploaded file.
2545
- */
2546
- getDocument(docId) {
2547
- if (this.state.files[docId]) {
2548
- return this.state.files[docId];
2549
- } else {
2550
- for (const map of this.state.translatedFiles.values()) {
2551
- for (const file of map.values()) {
2552
- if (file.docId === docId) {
2553
- return file;
2554
- }
2555
- }
2556
- }
2557
- }
2558
- return void 0;
2559
- }
2560
- updateDocument(docId, newValue) {
2561
- if (this.state.files[docId]) {
2562
- this.state.files[docId] = { ...this.getDocument(docId), ...newValue };
2563
- } else {
2564
- this.state.translatedFiles.forEach((innerMap) => {
2565
- innerMap.forEach((doc, langKey) => {
2566
- if (doc.docId === docId) {
2567
- innerMap.set(langKey, { ...doc, ...newValue });
2568
- }
2569
- });
2570
- });
2571
- }
2572
- }
2573
- deleteDocument(docId) {
2574
- if (this.state.files[docId]) {
2575
- delete this.state.files[docId];
2576
- } else {
2577
- this.state.translatedFiles.forEach((innerMap) => {
2578
- innerMap.forEach((doc, langKey) => {
2579
- if (doc.docId === docId) {
2580
- innerMap.delete(langKey);
2581
- }
2582
- });
2583
- });
2584
- }
2585
- }
2586
- clearFile(name) {
2587
- if (this.modalController) {
2588
- this.modalController.state.isReadonly = false;
2589
- }
2590
- this.state.inProgressFiles = this.state.inProgressFiles.filter(
2591
- (c) => c.name !== name
2592
- );
2593
- }
2594
- clearFiles() {
2595
- if (this.modalController) {
2596
- this.modalController.state.isReadonly = false;
2597
- }
2598
- this.state.inProgressFiles = [];
2599
- this.state.versioningFile = null;
2600
- this.state.hiddenFiles = [];
2601
- }
2602
- clearState() {
2603
- if (this.modalController) {
2604
- this.modalController.state.isReadonly = false;
2605
- }
2606
- this.state.selectedDocTypeId = this.getDocTypes().find(
2607
- (c) => String(c.id) === "1"
2608
- ) ? "1" : this.getDocTypes()[0]?.id;
2609
- this.state.inProgressFiles = [];
2610
- this.state.versioningFile = null;
2611
- }
2612
- async checkLockDocument(id, shouldNotifyUnlocked = true) {
2613
- if (getWindow(this.execution).IN_MONITOR) {
2614
- return false;
2615
- }
2616
- const file = this.getDocument(id);
2617
- if (Number(file.docId) < 0)
2618
- return true;
2619
- const result = await post(
2620
- this.execution,
2621
- makeApiaUrl(
2622
- this.execution,
2623
- this.getCheckLockDocumentParameters({
2624
- action: "checkLockDocument",
2625
- docId: file.docId,
2626
- ajaxUrl: this.getAjaxUrl(),
2627
- prefix: this.type
2628
- })
2629
- )
2630
- );
2631
- const isLocked = result?.data?.success === "ok";
2632
- if (!isLocked && result?.data?.usr && result.data.usr !== getWindow(this.execution).CURRENT_USER_LOGIN) {
2633
- this.notify({
2634
- message: `${getWindow(this.execution).MSG_DOC_LOCKED_BY_USR.split(".")[0]}: ${result.data.usr}.`,
2635
- type: "warning"
2636
- });
2637
- return result.data.usr;
2638
- }
2639
- if (!isLocked && shouldNotifyUnlocked && !await this.autoLock())
2640
- this.notify({
2641
- message: getWindow(this.execution).MSG_DOC_MUST_BE_LOCKED,
2642
- type: "warning"
2643
- });
2644
- return isLocked;
2645
- }
2646
- setCurrentDocTypeId(docTypeId) {
2647
- this.state.selectedDocTypeId = docTypeId;
2648
- }
2649
- async ajaxUploadStart(newFiles = []) {
2650
- if (getWindow(this.execution).IN_MONITOR) {
2651
- return;
2652
- }
2653
- const versioningFile = this.state.versioningFile;
2654
- const res = await post(
2655
- this.execution,
2656
- makeApiaUrl(
2657
- this.execution,
2658
- this.getAjaxUploadStartParameters({
2659
- action: "ajaxUploadStart",
2660
- isAjax: true,
2661
- docId: versioningFile?.docId,
2662
- prefix: this.type,
2663
- docTypeId: newFiles.length === 1 ? versioningFile?.docTypeId || "1" : "1",
2664
- newDoc: !versioningFile,
2665
- useDocTypePermitted: true,
2666
- docTypePermittedObjType: this.type,
2667
- docTypePermittedObjId: this.docTypePermittedObjId,
2668
- ajaxUrl: this.getAjaxUrl()
2669
- })
2670
- )
2671
- );
2672
- if (res?.data) {
2673
- const docTypes = arrayOrArray(res?.data?.function?.docTypes?.docType);
2674
- const hasGeneric = !!docTypes.find((c) => String(c.id) === "1");
2675
- this.state.allowedTypes = docTypes;
2676
- this.state.selectedDocTypeId = hasGeneric ? "1" : docTypes[0].id;
2677
- if (newFiles.length > 0) {
2678
- await this.saveDroppedFiles(newFiles);
2679
- }
2680
- return res?.data?.function.name === "fncDocumentLoadInformation" ? true : false;
2681
- } else {
2682
- throw new Error("No files data");
2683
- }
2684
- }
2685
- async reloadMetadata(props, additionalProps) {
2686
- if (!this.modalController)
2687
- return;
2688
- const res = await post(
2689
- this.execution,
2690
- makeApiaUrl(
2691
- this.execution,
2692
- this.getReloadMetadataParameters({
2693
- ajaxUrl: this.getAjaxUrl(),
2694
- action: "reloadMetadata",
2695
- isAjax: true,
2696
- docId: props?.docId,
2697
- docTypeId: props?.docTypeId,
2698
- metadata: this.getConfirmDropModalMetadataString({
2699
- metadata: this.modalController?.allMetadata
2700
- }),
2701
- prefix: this.type,
2702
- ...additionalProps
2703
- })
2704
- )
2705
- );
2706
- if (res?.data && props?.docTypeId) {
2707
- const isFreeMetadata = this.state.allowedTypes.find(
2708
- (current) => current.id === props.docTypeId
2709
- )?.free ?? false;
2710
- this.modalController.state.metadata.metadataArray = arrayOrArray(
2711
- res.data.metadata
2712
- );
2713
- this.modalController.state.metadata.isFreeMetadata = isFreeMetadata;
2714
- }
2715
- }
2716
- async saveDroppedFiles(unprocessedFiles, conf) {
2717
- if (getWindow(this.execution).IN_MONITOR) {
2718
- return false;
2719
- }
2720
- const {
2721
- langId,
2722
- strictMode: isConfStrictMode = false,
2723
- translatingFile
2724
- } = conf ?? {};
2725
- const isStrictMode = isConfStrictMode || !!this.state.versioningFile || !!this.modalController?.state.fromDirectoryFile;
2726
- const docType = this.getCurrentDocTypeId();
2727
- if (!isStrictMode && !docType) {
2728
- this.notify({
2729
- message: `${getWindow(this.execution).LBL_DROP_FILE_DELETED}: ${unprocessedFiles.map((current) => current.name).join(", ")}.`,
2730
- type: "warning"
2731
- });
2732
- return false;
2733
- }
2734
- const allowedFiles = this.filterAlreadyUploadedFiles(
2735
- this.filterByFilesAmountLimit(
2736
- this.filterAcceptedFiles(
2737
- this.filterExistingFiles(
2738
- this.filterVersioningFiles(unprocessedFiles, conf),
2739
- conf
2740
- ),
2741
- true,
2742
- docType
2743
- )
2744
- ),
2745
- conf
2746
- );
2747
- if (allowedFiles.length > 0) {
2748
- const formData = new FormData();
2749
- allowedFiles.forEach(
2750
- (file) => formData.append("fileRepository", file, file.name)
2751
- );
2752
- await post(
2753
- this.execution,
2754
- makeApiaUrl(
2755
- this.execution,
2756
- this.getSaveDroppedFilesParameters({
2757
- action: "saveDroppedFiles",
2758
- docId: this.state.versioningFile?.docId,
2759
- ajaxUrl: this.getAjaxUrl(),
2760
- elemType: this.type,
2761
- elemId: `prmDocumentContainter${this.type}`,
2762
- frmOut: !this.modalController,
2763
- docTypeId: this.state.selectedDocTypeId,
2764
- langId
2765
- })
2766
- ),
2767
- {
2768
- postData: formData,
2769
- axiosConfig: {
2770
- onUploadProgress: (ev) => this.state.progress = ev.loaded * 100 / ((ev.total ?? ev.loaded) * 2)
2771
- }
2772
- }
2773
- );
2774
- const ajaxUploadFileStatusParameters = this.getAjaxUploadFileStatusParameters({
2775
- action: "ajaxUploadFileStatus",
2776
- ajaxUrl: this.getAjaxUrl(),
2777
- delayForDrop: true,
2778
- isAjax: true,
2779
- prefix: this.type
2780
- });
2781
- let tries = 0;
2782
- const checkUploadResult = async () => {
2783
- return new Promise(async (resolve) => {
2784
- tries += 1;
2785
- if (tries === 10) {
2786
- this.notify({
2787
- message: "Error while checking for uploadFileStatus, too many tries",
2788
- type: "error"
2789
- });
2790
- resolve(false);
2791
- return;
2792
- }
2793
- const response = await post(
2794
- this.execution,
2795
- makeApiaUrl(this.execution, ajaxUploadFileStatusParameters)
2796
- );
2797
- if (response && response.data) {
2798
- const hasMessages = arrayOrArray(
2799
- response.data?.sysMessages?.message ?? response.data?.sysExceptions?.exception ?? response.data?.exceptions?.exception ?? response.data.function.messages?.message
2800
- ).length > 0 || !!response.data.function.dropLastMessage;
2801
- const uploadMessage = arrayOrArray(
2802
- response.data.function.messages?.message
2803
- ).find((current) => current.name === "message");
2804
- if (uploadMessage)
2805
- this.notify({ message: uploadMessage.label, type: "warning" });
2806
- const method = response.data?.function.name;
2807
- this.state.progress = 44;
2808
- if (hasMessages) {
2809
- resolve(false);
2810
- return;
2811
- }
2812
- if (method === "fncProceedDocumentProcessing") {
2813
- resolve(true);
2814
- return;
2815
- }
2816
- if (tries === 10) {
2817
- resolve(method === "fncProceedDocumentProcessing");
2818
- }
2819
- setTimeout(() => {
2820
- checkUploadResult().then(resolve).catch(() => resolve(false));
2821
- }, 100);
2822
- } else {
2823
- resolve(false);
2824
- }
2825
- });
2826
- };
2827
- const hasUploadedCorrectly = await checkUploadResult();
2828
- this.state.progress = 66;
2829
- if (hasUploadedCorrectly) {
2830
- const shown = (this.state.inProgressFiles ?? []).map(
2831
- (file) => file.name
2832
- );
2833
- const postData = QueryString.stringify(
2834
- this.getProcessDroppedFilesPostdata({
2835
- useDocTypePermitted: true,
2836
- docTypePermittedObjId: this.docTypePermittedObjId?.toString(),
2837
- docTypePermittedObjType: this.type,
2838
- dropped: allowedFiles.map((file) => file.name).concat(shown),
2839
- shown
2840
- }),
2841
- { arrayFormat: "repeat" }
2842
- );
2843
- const secondResult = await post(
2844
- this.execution,
2845
- makeApiaUrl(
2846
- this.execution,
2847
- this.getProcessDroppedFilesParameters({
2848
- action: "processDroppedFiles",
2849
- elemType: this.type,
2850
- docId: this.state.versioningFile?.docId,
2851
- frmOut: !this.modalController,
2852
- ajaxUrl: this.getAjaxUrl()
2853
- })
2854
- ),
2855
- {
2856
- postData: postData.toString()
2857
- }
2858
- );
2859
- this.state.progress = 83;
2860
- if (secondResult?.data?.function?.principal?.docInfo) {
2861
- const acceptedByServerFiles = arrayOrArray(
2862
- secondResult.data.function?.principal?.docInfo
2863
- );
2864
- this.state.inProgressFiles = [
2865
- ...this.state.inProgressFiles ?? [],
2866
- ...acceptedByServerFiles.map(
2867
- (current) => [...this.state.inProgressFiles, ...unprocessedFiles].find(
2868
- (search) => search.name === current.docInfoName
2869
- )
2870
- ).filter((current) => !!current)
2871
- ];
2872
- this.state.progress = 100;
2873
- if (this.modalController)
2874
- this.modalController.state.fromDirectoryFile = null;
2875
- this.notify({
2876
- type: "success",
2877
- message: getWindow(this.execution).FILE_UPLOADED_SUCCESSFULLY
2878
- });
2879
- if (isOneClickUploadEnabled(
2880
- this.execution,
2881
- this.modalConfig.oneClickUpload
2882
- )) {
2883
- if (langId && translatingFile)
2884
- void this.confirmDropModal({ langId, translatingFile });
2885
- else
2886
- void this.confirmDropModal();
2887
- }
2888
- }
2889
- }
2890
- this.state.progress = 100;
2891
- return true;
2892
- } else {
2893
- return false;
2894
- }
2895
- }
2896
- async checkWebDavLock(docId) {
2897
- if (getWindow(this.execution).IN_MONITOR) {
2898
- return false;
2899
- }
2900
- return new Promise((resolve) => {
2901
- let tries = 10;
2902
- const checkLockAction = async () => {
2903
- const isLocked = await post(
2904
- this.execution,
2905
- makeApiaUrl(
2906
- this.execution,
2907
- this.getCheckWebDavLockParameters({
2908
- action: "isWebDavDocumentLocked",
2909
- docId,
2910
- ajaxUrl: getWindow(this.execution).URL_REQUEST_AJAX
2911
- })
2912
- )
2913
- );
2914
- if (isLocked?.data?.locked === true || isLocked?.data?.locked === void 0) {
2915
- if (--tries > 0) {
2916
- setTimeout(() => void checkLockAction(), 1e3);
2917
- } else {
2918
- this.notify({
2919
- message: getWindow(this.execution).MSG_FAIL_SYNC_DOCUMENT
2920
- });
2921
- resolve(false);
2922
- }
2923
- } else {
2924
- resolve(true);
2925
- }
2926
- };
2927
- void checkLockAction();
2928
- });
2929
- }
2930
- async checkSignature(file) {
2931
- let res = null;
2932
- if (Number(file.docId) >= 0)
2933
- res = await get(
2934
- this.execution,
2935
- makeApiaUrl(
2936
- this.execution,
2937
- this.getCheckSignatureParameters({
2938
- action: "viewDocSigns",
2939
- docId: file.docId,
2940
- lock: false,
2941
- isAjax: true,
2942
- prefix: this.type,
2943
- react: true
2944
- })
2945
- )
2946
- );
2947
- return res;
2948
- }
2949
- async editDocument(id) {
2950
- if (getWindow(this.execution).IN_MONITOR) {
2951
- return;
2952
- }
2953
- const file = this.getDocument(id);
2954
- if (await this.checkLockDocument(file.docId) === true) {
2955
- const result = await post(
2956
- this.execution,
2957
- makeApiaUrl(
2958
- this.execution,
2959
- this.getEditDocumentParameters({
2960
- action: "updateWebDavDocument",
2961
- docId: file.docId,
2962
- prefix: this.type,
2963
- isAjax: true
2964
- })
2965
- )
2966
- );
2967
- if (result?.data?.folderId) {
2968
- const sDocumentUrl = `${getWindow(this.execution).WEBDAV_SERVER}${result?.data?.folderId}/${file.docId}/${file.name || file.docName || ""}`;
2969
- const ProtocolInstallMessage = () => {
2970
- this.notify({
2971
- type: "warning",
2972
- message: getWindow(this.execution).MSG_NO_DOC_EDIT_PROTOCOL,
2973
- title: getWindow(this.execution).LBL_EDIT
2974
- });
2975
- };
2976
- getWindow(this.execution).avoidLoadEvents = true;
2977
- getWindow(this.execution).ITHit.WebDAV.Client.DavConstants.ProtocolTimeoutMs = 1e4;
2978
- await getWindow(this.execution).ITHit.WebDAV.Client.DocManager.DavProtocolEditDocument(
2979
- sDocumentUrl,
2980
- getWindow(this.execution).WEBDAV_SERVER,
2981
- ProtocolInstallMessage,
2982
- null,
2983
- "Current",
2984
- "ApiaWebDavCookie",
2985
- // Cookie(s) to copy.
2986
- "",
2987
- // URL to navigate to if any cookie from the list is not found.
2988
- "Edit"
2989
- );
2990
- }
2991
- }
2992
- }
2993
- async downloadVersion(fileId, version) {
2994
- const file = this.getDocument(fileId);
2995
- if (!file)
2996
- return;
2997
- if (getWindow(this.execution).IN_MONITOR || await this.checkWebDavLock(file.docId))
2998
- await downloadUrl(
2999
- makeApiaUrl(this.execution, {
3000
- action: "downloadDocument",
3001
- docId: file.downloadDocId,
3002
- version
3003
- })
3004
- );
3005
- }
3006
- async downloadDocument(id, version) {
3007
- const file = this.getDocument(id);
3008
- if (getWindow(this.execution).IN_MONITOR || await this.checkWebDavLock(file.docId)) {
3009
- await downloadUrl(
3010
- makeApiaUrl(this.execution, {
3011
- action: "downloadDocument",
3012
- prefix: this.type,
3013
- docId: file.downloadDocId,
3014
- ajaxUrl: this.getAjaxUrl(),
3015
- version
3016
- })
3017
- );
3018
- }
3019
- }
3020
- async ajaxDeleteDocument(id, langId) {
3021
- const file = this.getDocument(id);
3022
- const isLocked = await this.checkLockDocument(file.docId);
3023
- if (isLocked === true) {
3024
- const result = await post(
3025
- this.execution,
3026
- makeApiaUrl(
3027
- this.execution,
3028
- this.getDeleteDocumentParameters({
3029
- action: "ajaxRemoveDocument",
3030
- docId: file.docId,
3031
- isAjax: true,
3032
- prefix: this.type,
3033
- ajaxUrl: this.getAjaxUrl(),
3034
- langId
3035
- })
3036
- )
3037
- );
3038
- if (this.evaluateDeleteDocumentResult(result?.data))
3039
- this.deleteDocument(id);
3040
- }
3041
- }
3042
- async version(file, conf = { newFiles: [] }) {
3043
- const checkLock = await this.checkLockDocument(file.docId, true);
3044
- const isLocked = await this.checkWebDavLock(file.docId);
3045
- if (!(checkLock === true && isLocked))
3046
- return;
3047
- this.state.versioningFile = file;
3048
- const openVersionModal = () => {
3049
- if (!this.modalConfig.oneClickUpload) {
3050
- this.modalController = new UploaderModalController(
3051
- this,
3052
- this.modalConfig,
3053
- {
3054
- versionFile: file
3055
- }
3056
- );
3057
- this.modalController.openModal();
3058
- }
3059
- };
3060
- if (!conf.newFiles || conf.newFiles.length === 0) {
3061
- openVersionModal();
3062
- }
3063
- await this.ajaxUploadStart();
3064
- if (file.docTypeId)
3065
- this.state.selectedDocTypeId = file.docTypeId;
3066
- await this.versionFileInfo(file);
3067
- const hasNewFiles = !!(conf.newFiles && conf.newFiles.length > 0);
3068
- if (hasNewFiles) {
3069
- const res = await this.saveDroppedFiles(conf.newFiles, {
3070
- langId: conf.langId,
3071
- translatingFile: conf.translatingFile,
3072
- shouldReset: false,
3073
- strictMode: true
3074
- });
3075
- if (res) {
3076
- openVersionModal();
3077
- }
3078
- } else {
3079
- await this.reloadMetadata({
3080
- docId: file.docId,
3081
- docTypeId: file.docTypeId
3082
- });
3083
- }
3084
- }
3085
- async versionFileInfo(file) {
3086
- const documentInfo = await this.getDocumentInfo({ docId: file.docId });
3087
- if (documentInfo?.function) {
3088
- const {
3089
- data: { general },
3090
- metadatas
3091
- } = documentInfo.function;
3092
- const isFreeMetadata = this.state.allowedTypes.find((current) => current.id === file.docTypeId)?.free ?? false;
3093
- if (this.modalController) {
3094
- this.modalController.state = {
3095
- description: general.docDesc,
3096
- docFolder: general.docFolder === "" ? void 0 : Number(general.docFolder),
3097
- docPath: general.docFolderPath,
3098
- permissions: {
3099
- allowAllType: general.docAllPoolPerm,
3100
- users: arrayOrArray(
3101
- documentInfo.function.data.permissions?.user
3102
- ).map((current) => {
3103
- const returnObject = {
3104
- canUpdate: current.permType === "M",
3105
- userId: current.id,
3106
- userLogin: current.name
3107
- };
3108
- return returnObject;
3109
- }),
3110
- pools: arrayOrArray(
3111
- documentInfo.function.data.permissions?.pool
3112
- ).map((current) => {
3113
- const returnObject = {
3114
- canUpdate: current.permType === "M",
3115
- poolId: current.id,
3116
- poolName: current.name
3117
- };
3118
- return returnObject;
3119
- })
3120
- },
3121
- docExpDate: general.docExpDate,
3122
- fileReqError: false,
3123
- fromDirectoryFile: null,
3124
- metadata: {
3125
- metadataArray: arrayOrArray(metadatas?.metadata),
3126
- freeMetadataArray: [],
3127
- isFreeMetadata
3128
- }
3129
- };
3130
- }
3131
- }
3132
- }
3133
- async pickFileById(id) {
3134
- const documentInfo = await this.getDocumentInfo(
3135
- { downloadDocId: id },
3136
- true
3137
- );
3138
- if (documentInfo) {
3139
- const document = documentInfo.function.data.general;
3140
- const { permissions } = documentInfo.function.data;
3141
- if (this.modalController) {
3142
- this.setCurrentDocTypeId(document.docTypeId);
3143
- this.modalController.addDirectoryFile(document);
3144
- this.modalController.state.description = document.docDesc;
3145
- this.modalController.state.docExpDate = document.docExpDate;
3146
- this.modalController.state.permissions = {
3147
- pools: arrayOrArray(permissions?.pool).map((c) => {
3148
- return {
3149
- poolId: c.id,
3150
- poolName: c.name,
3151
- canUpdate: c.permType === "M"
3152
- };
3153
- }),
3154
- users: [
3155
- ...arrayOrArray(permissions?.user).map((c) => {
3156
- return {
3157
- userId: c.id,
3158
- userLogin: c.name,
3159
- canUpdate: c.permType === "M"
3160
- };
3161
- })
3162
- ],
3163
- allowAllType: document.docAllPoolPerm
3164
- };
3165
- this.modalController.changeDocType(document.docTypeId);
3166
- this.modalController.state.isReadonly = !documentInfo.function.currentUsrPems.usrCanModify;
3167
- }
3168
- void this.reloadMetadata(
3169
- { docId: document.docId, docTypeId: document.docTypeId },
3170
- {
3171
- docReuse: true
3172
- }
3173
- );
3174
- }
3175
- }
3176
- async markFileToSign(id, langId) {
3177
- if (getWindow(this.execution).IN_MONITOR) {
3178
- return;
3179
- }
3180
- const file = this.getDocument(id);
3181
- if (await this.checkLockDocument(file.docId) === true) {
3182
- const marked = await post(
3183
- this.execution,
3184
- makeApiaUrl(
3185
- this.execution,
3186
- this.getMarkFileToSignParameters({
3187
- action: "markDocTosign",
3188
- docId: file.docId,
3189
- isAjax: true,
3190
- prefix: this.type,
3191
- ajaxUrl: this.getAjaxUrl(),
3192
- langId
3193
- })
3194
- )
3195
- );
3196
- if (marked?.data?.markedToSign !== void 0) {
3197
- if (this.state.files[id]) {
3198
- this.state.files[id].markedToSign = marked.data.markedToSign;
3199
- } else {
3200
- this.state.translatedFiles.forEach((innerMap) => {
3201
- innerMap.forEach((doc, langKey) => {
3202
- if (doc.docId === id) {
3203
- innerMap.set(langKey, {
3204
- ...doc,
3205
- markedToSign: marked?.data?.markedToSign ?? false
3206
- });
3207
- }
3208
- });
3209
- });
3210
- }
3211
- }
3212
- }
3213
- }
3214
- /**
3215
- * Por el momento realiza la descarga de todos los archivos
3216
- * que estén subidos.
3217
- */
3218
- downloadMultipleDocuments() {
3219
- const files = this.filesArray;
3220
- if (files.length === 0)
3221
- return;
3222
- const docIds = this.state.selectedFiles;
3223
- const selectedFiles = files.filter(
3224
- (current) => docIds.find((search) => search === current.docId)
3225
- );
3226
- const ids = (selectedFiles.length > 0 ? selectedFiles : files).map((current) => current.downloadDocId).join("-");
3227
- void downloadUrl(
3228
- makeApiaUrl(
3229
- this.execution,
3230
- this.getDownloadMultipleDocumentsParameters({
3231
- action: "multipleDownload",
3232
- docId: ids,
3233
- prefix: this.type
3234
- })
3235
- ),
3236
- "documents.zip"
3237
- );
3238
- }
3239
- async confirmDropModal(conf) {
3240
- if (getWindow(this.execution).IN_MONITOR) {
3241
- return false;
3242
- }
3243
- const { langId, translatingFile } = conf ?? {};
3244
- const cmbDocType = this.state.selectedDocTypeId;
3245
- const fromDirectoryFile = this.modalController?.state.fromDirectoryFile;
3246
- const docDesc = this.modalController?.description ?? "";
3247
- const docAllowAllType = this.modalConfig.oneClickUpload ? "M" : this.modalController?.allowAllType ?? "";
3248
- const docFolder = this.modalController?.docFolder;
3249
- const docExpDate = this.modalController?.docExpDate;
3250
- const metadata = this.modalController?.metadata ?? [];
3251
- const freeMetadata = this.modalController?.freeMetadata ?? [];
3252
- const poolsPermissions = this.modalController?.state.permissions.pools ?? [];
3253
- const usersPermissions = this.modalController?.state.permissions.users ?? [];
3254
- let postData = QueryString.stringify(
3255
- this.getConfirmDropModalPostdata({
3256
- cmbDocType,
3257
- docDesc,
3258
- docAllowAllType,
3259
- pe: this.docTypePermittedObjId?.toString(),
3260
- dropped: this.state.inProgressFiles.map((file) => file.name),
3261
- txtLangId: langId,
3262
- txtLangGroup: translatingFile?.docLangGroup,
3263
- docFolder
3264
- }),
3265
- { arrayFormat: "repeat" }
3266
- );
3267
- postData = `${postData}${postData.length > 0 ? "&" : ""}${this.getConfirmDropModalPermissionsString({
3268
- poolsPermissions,
3269
- usersPermissions
3270
- })}&txtFreeMetadata=${this.getConfirmDropModalAdditionalMetadataString(
3271
- freeMetadata
3272
- )}&txtMetadata=${this.getConfirmDropModalMetadataString({
3273
- metadata: Object.values(metadata || {})
3274
- })}&docExpDate=${docExpDate ?? ""}`;
3275
- const result = await post(
3276
- this.execution,
3277
- makeApiaUrl(
3278
- this.execution,
3279
- this.getConfirmDropModalParameters({
3280
- ajaxUrl: this.getAjaxUrl(),
3281
- docId: fromDirectoryFile ? fromDirectoryFile.docId : this.state.versioningFile?.docId,
3282
- action: fromDirectoryFile ? "associateExistingFile" : "confirmDropModal",
3283
- elemType: this.type,
3284
- fromForm: true,
3285
- ...fromDirectoryFile ? {
3286
- docId: fromDirectoryFile.docId,
3287
- fromReuse: true,
3288
- uploadDocument: false
3289
- } : null
3290
- })
3291
- ),
3292
- {
3293
- postData: postData.toString()
3294
- }
3295
- );
3296
- if (result?.data?.function) {
3297
- const currentFiles = { ...this.state.files };
3298
- const versioningFile = this.state.versioningFile;
3299
- if (versioningFile && versioningFile.name) {
3300
- delete currentFiles[versioningFile.name];
3301
- }
3302
- const newFiles = arrayOrArray(
3303
- result.data.function.general
3304
- ).map(
3305
- (current) => this.parseFileDefinition({
3306
- ...current,
3307
- canWrite: true,
3308
- canRead: true,
3309
- canEdit: true
3310
- })
3311
- ).filter((current) => !currentFiles[current.docId]).reduce((acc, current) => ({ ...acc, [current.docId]: current }), {});
3312
- if (langId && translatingFile) {
3313
- const firstFile = Object.values(newFiles)[0];
3314
- this.setTranslationFile(firstFile, translatingFile.docId, langId);
3315
- } else {
3316
- this.state.files = { ...currentFiles, ...newFiles };
3317
- }
3318
- this.clearFiles();
3319
- this.emit("fileUploaded", null);
3320
- return true;
3321
- }
3322
- return false;
3323
- }
3324
- async loadCurrentDocuments() {
3325
- const result = await post(
3326
- this.execution,
3327
- makeApiaUrl(this.execution, {
3328
- ajaxUrl: this.getAjaxUrl(),
3329
- action: "ajaxLoadCurrent",
3330
- isAjax: true,
3331
- readOnly: getWindow(this.execution).IS_READONLY,
3332
- allowLock: true,
3333
- allowSign: true,
3334
- allowMultiple: true,
3335
- prefix: this.type
3336
- }),
3337
- {}
3338
- );
3339
- if (result && result.data) {
3340
- const currentConfiguration = arrayOrArray(result.data.function.messages.message).reduce(
3341
- (prev, { name, label }) => ({ ...prev, [name]: Boolean(label) }),
3342
- {}
3343
- );
3344
- const currentFiles = result.data.function.general ? arrayOrArray(result.data.function.general).map(
3345
- this.parseFileDefinition
3346
- ) : [];
3347
- this.currentConfiguration = currentConfiguration;
3348
- const nonTranslationFiles = [];
3349
- const translationFiles = [];
3350
- currentFiles.forEach((current) => {
3351
- if (current.docLang === void 0)
3352
- nonTranslationFiles.push(current);
3353
- else
3354
- translationFiles.push(current);
3355
- });
3356
- nonTranslationFiles.forEach((c) => {
3357
- this.state.files[c.docId] = c;
3358
- });
3359
- translationFiles.forEach((current) => {
3360
- const originalFile = nonTranslationFiles.find(
3361
- (search) => search.docLangGroup === current.docLangGroup
3362
- );
3363
- if (originalFile && current.docLang !== void 0) {
3364
- this.setTranslationFile(
3365
- current,
3366
- originalFile.docId,
3367
- Number(current.docLang)
3368
- );
3369
- } else
3370
- console.warn(
3371
- `The following file is translated but has no orignal file`,
3372
- current,
3373
- nonTranslationFiles
3374
- );
3375
- });
3376
- }
3377
- }
3378
- async lockDocument(id) {
3379
- if (getWindow(this.execution).IN_MONITOR) {
3380
- return;
3381
- }
3382
- const file = this.getDocument(id);
3383
- if (file.markedToSign) {
3384
- this.notify({
3385
- message: getWindow(this.execution).CANT_UNLOCK_MARKED_TO_SIGN,
3386
- type: "warning"
3387
- });
3388
- return;
3389
- }
3390
- if (!file.isLocked || !file.isLockedByMe) {
3391
- const isLocked = await this.checkLockDocument(file.docId, false);
3392
- this.updateDocument(
3393
- id,
3394
- typeof isLocked === "string" ? this.parseFileDefinition({
3395
- ...file,
3396
- userLocking: isLocked,
3397
- lock: true,
3398
- isLocked: true,
3399
- lockedBy: isLocked
3400
- }) : { ...file, isLocked }
3401
- );
3402
- }
3403
- const result = await post(
3404
- this.execution,
3405
- makeApiaUrl(
3406
- this.execution,
3407
- this.getLockDocumentParameters({
3408
- action: "lockDocument",
3409
- ajaxUrl: this.getAjaxUrl(),
3410
- docId: file.docId,
3411
- lock: file.isLocked || file.locked,
3412
- isAjax: true,
3413
- prefix: this.type
3414
- })
3415
- )
3416
- );
3417
- if (result?.data) {
3418
- const resultFile = result.data.function?.data?.general;
3419
- if (resultFile)
3420
- this.updateDocument(
3421
- resultFile.docId,
3422
- this.parseFileDefinition({
3423
- ...file,
3424
- ...resultFile,
3425
- isLocked: resultFile.locked
3426
- })
3427
- );
1963
+ });
1964
+ this.selectedLanguageId = this.getLanguages()[0].id;
3428
1965
  }
3429
1966
  }
3430
- evaluateDeleteDocumentResult(result) {
3431
- return result?.function?.name === "fncDocumentRemove";
1967
+ cancelTranslations() {
1968
+ this.getTranslations().forEach((c) => {
1969
+ c.reset();
1970
+ });
3432
1971
  }
3433
- setTranslationFile(file, docId, langId) {
3434
- if (!this.state.translatedFiles.has(docId)) {
3435
- this.state.translatedFiles.set(docId, /* @__PURE__ */ new Map());
3436
- }
3437
- this.state.translatedFiles.get(docId)?.set(langId, file);
1972
+ deleteTranslations() {
1973
+ this.getTranslations().forEach((c) => {
1974
+ c.deleteTranslation();
1975
+ });
3438
1976
  }
3439
- filterAlreadyUploadedFiles(files, conf) {
3440
- const versioningFile = this.state.versioningFile;
3441
- if (versioningFile)
3442
- return files;
3443
- const uploadedFiles = Object.values(this.state.files).filter(
3444
- (file) => Number(file.docId) > 0
3445
- );
3446
- const existingFiles = [];
3447
- const nonExistingFiles = [];
3448
- if (conf?.langId) {
3449
- const docId = conf.translatingFile?.docId ?? Infinity;
3450
- const translationsMap = this.state.translatedFiles.get(String(docId));
3451
- const alreadyUploadedToTranslationsFile = translationsMap ? Array.from(translationsMap.values()).find(
3452
- (current) => (current.docName || current.name) === files[0]?.name
3453
- ) : void 0;
3454
- if (alreadyUploadedToTranslationsFile)
3455
- existingFiles.push(files[0]);
3456
- } else
3457
- files.forEach((file) => {
3458
- if (uploadedFiles.find((search) => search.docName === file.name)) {
3459
- existingFiles.push(file);
3460
- } else
3461
- nonExistingFiles.push(file);
3462
- });
3463
- if (existingFiles.length > 0) {
3464
- void this.notify({
3465
- message: `${getWindow(this.execution).LBL_DROP_FILE_REPEATED}: ${existingFiles.map((current) => current.name).join(", ")}`,
3466
- type: "warning"
3467
- });
3468
- return nonExistingFiles;
3469
- }
3470
- return files;
1977
+ async changeLanguage(langId) {
1978
+ this.selectedLanguageId = langId;
1979
+ this.syncTranslation();
3471
1980
  }
3472
- filterByFilesAmountLimit(files) {
3473
- return files.slice(
3474
- 0,
3475
- addBoundary(this.maxFiles - (this.state.inProgressFiles?.length ?? 0), 0)
1981
+ getTranslation(id) {
1982
+ return this.translations.get(id);
1983
+ }
1984
+ getCurrentTranslation() {
1985
+ return this.translations.get(this.selectedLanguageId);
1986
+ }
1987
+ getTranslations() {
1988
+ return this.translations;
1989
+ }
1990
+ submitTranslations() {
1991
+ [...this.getTranslations().values()].filter((c) => c.state.hasChanged).forEach((c) => {
1992
+ c.submitTranslation(
1993
+ c.value,
1994
+ this.getSynchronizeUrl({
1995
+ react: true,
1996
+ preventAsXmlParameter: true,
1997
+ langId: c.langId
1998
+ })
1999
+ );
2000
+ });
2001
+ this.state.validation.errorMessage = null;
2002
+ }
2003
+ async syncTranslation() {
2004
+ const langId = this.selectedLanguageId;
2005
+ this.isTradLoading = true;
2006
+ await this.getTranslation(langId)?.readTranslations(
2007
+ await makeApiaUrl(this.form.execution, {
2008
+ ajaxUrl: "/apia.execution.FormAction.run",
2009
+ action: "getFieldTranslations",
2010
+ frmId: this.getForm().definition.id,
2011
+ frmParent: this.getForm().definition.frmParent,
2012
+ fldId: this.definition.id,
2013
+ attId: this.attribute.id,
2014
+ langId,
2015
+ react: true
2016
+ })
3476
2017
  );
2018
+ this.isTradLoading = false;
3477
2019
  }
3478
- filterAcceptedFiles(files, shouldNotify = true, docTypeId) {
3479
- const docTypes = docTypeId !== void 0 ? this.state.allowedTypes.filter((c) => {
3480
- return typeof docTypeId === "string" ? c.id === docTypeId : c.id === docTypeId.id;
3481
- }) : this.state.allowedTypes;
3482
- if (!docTypes.find((c) => c.docExts === "")) {
3483
- const notAllowedFilesBecauseOfExtension = [];
3484
- const notAllowedFilesBecauseOfSize = [];
3485
- let maxSize = Infinity;
3486
- const allowedFiles = files.filter((currentFile) => {
3487
- const extension = (currentFile.name.match(/\.(\w+)$/) ?? [])[1];
3488
- let isAllowed = true;
3489
- if (!docTypes.find((currentDocType) => {
3490
- if (!currentDocType.docExts.split(";").map((current) => current.toLowerCase()).includes(extension.toLowerCase())) {
3491
- return false;
3492
- }
3493
- return true;
3494
- })) {
3495
- isAllowed = false;
3496
- notAllowedFilesBecauseOfExtension.push(currentFile);
3497
- }
3498
- if (isAllowed && !docTypes.find((currentDocType) => {
3499
- if (Number(currentDocType.maxSize) < currentFile.size) {
3500
- maxSize = Number(currentDocType.maxSize);
3501
- return false;
3502
- }
3503
- return true;
3504
- })) {
3505
- notAllowedFilesBecauseOfSize.push(currentFile);
3506
- isAllowed = false;
3507
- }
3508
- if (!isAllowed)
3509
- return false;
3510
- return true;
3511
- });
3512
- if (shouldNotify) {
3513
- let errorMessage = "";
3514
- if (notAllowedFilesBecauseOfExtension.length > 0) {
3515
- const filesNames = notAllowedFilesBecauseOfExtension.reduce(
3516
- (accumulated, current) => {
3517
- if (accumulated.length === 0)
3518
- return current.name;
3519
- return `${accumulated}, ${current.name}`;
3520
- },
3521
- ""
3522
- );
3523
- errorMessage = `<strong>${getWindow(this.execution).FILES_WRONG_EXT}</strong><br />${filesNames}`;
3524
- }
3525
- if (notAllowedFilesBecauseOfSize.length > 0) {
3526
- const filesNames = notAllowedFilesBecauseOfSize.reduce(
3527
- (accumulated, current) => {
3528
- if (accumulated.length === 0)
3529
- return current.name;
3530
- return `${accumulated}, ${current.name}`;
3531
- },
3532
- ""
3533
- );
3534
- if (errorMessage.length > 0)
3535
- errorMessage = `${errorMessage} <br /><br />`;
3536
- errorMessage = `${errorMessage}${formatMessage(
3537
- getWindow(this.execution).FILES_TOO_BIG,
3538
- {
3539
- TOK1: `<br />${filesNames}`,
3540
- TOK2: `${parseAsSize(maxSize)}`
3541
- }
3542
- )}`;
3543
- }
3544
- if (errorMessage.length > 0)
3545
- this.notify({
3546
- message: errorMessage,
3547
- type: "warning"
3548
- });
2020
+ async validate() {
2021
+ const isSuperValid = await super.validate();
2022
+ let isValid = isSuperValid;
2023
+ const canValidate = isSuperValid && this.properties.reqTrad && this.hasValue() && (!this.properties.inputAsText || !this.properties.visibilityHidden || !this.properties.disabled);
2024
+ if (canValidate) {
2025
+ const translations = [...this.getTranslations().values()];
2026
+ const tradNotValidated = translations.find((c) => !c.state.isTranslated);
2027
+ if (tradNotValidated) {
2028
+ this.state.validation.errorMessage = labels.errorTranslateRequired(
2029
+ this.form.execution,
2030
+ tradNotValidated.state.label
2031
+ );
2032
+ isValid = false;
2033
+ } else {
2034
+ this.state.validation.errorMessage = null;
3549
2035
  }
3550
- return allowedFiles;
3551
2036
  }
3552
- return files;
2037
+ return isValid;
3553
2038
  }
3554
- filterExistingFiles(files, conf) {
3555
- if (conf?.langId)
3556
- return files;
3557
- const currentFiles = this.state.inProgressFiles;
3558
- const alreadyUploadedFiles = Object.values(this.state.files).filter(
3559
- (current) => Number(current.docId) < 0
3560
- );
3561
- let alreadyIncludedFileNames = "";
3562
- const filteredFiles = files.filter((current) => {
3563
- const isIncluded = currentFiles.findIndex((search) => search.name === current.name) !== -1 || alreadyUploadedFiles.findIndex(
3564
- (search) => search.docName === current.name
3565
- ) !== -1;
3566
- if (isIncluded)
3567
- alreadyIncludedFileNames = `${alreadyIncludedFileNames}${alreadyIncludedFileNames.length > 0 ? ", " : ""}${current.name}`;
3568
- return !isIncluded;
3569
- });
3570
- if (alreadyIncludedFileNames.length > 0)
3571
- this.notify({
3572
- message: `${getWindow(this.execution).LBL_DROP_FILE_REPEATED}: ${alreadyIncludedFileNames}`,
3573
- type: "warning"
3574
- });
3575
- return filteredFiles;
2039
+ setValue(newValue, options) {
2040
+ if (newValue === "") {
2041
+ this.deleteTranslations();
2042
+ }
2043
+ return super.setValue(newValue, options);
3576
2044
  }
3577
- filterVersioningFiles(files, conf) {
3578
- const versioningFile = this.state.versioningFile;
3579
- if (versioningFile) {
3580
- const newFiles = files.filter(
3581
- (current) => current.name === versioningFile.docName || current.name === versioningFile.name
3582
- );
3583
- if (newFiles.length === 0) {
3584
- this.notify({
3585
- type: "warning",
3586
- message: getWindow(this.execution).LBL_DROP_FILE_NAMES_NOT_MATCH
3587
- });
2045
+ }
2046
+
2047
+ class Editor extends TranslatableField {
2048
+ fireEvent(eventName, options) {
2049
+ return super.fireEvent(eventName, options);
2050
+ }
2051
+ isValidValue() {
2052
+ return !!new DOMParser().parseFromString(this.getValue(), "text/html").documentElement.textContent;
2053
+ }
2054
+ getSynchronizePostConfiguration(value) {
2055
+ const conf = super.getSynchronizePostConfiguration(value);
2056
+ conf.postData.clearValues = "true";
2057
+ return conf;
2058
+ }
2059
+ }
2060
+
2061
+ var __defProp$i = Object.defineProperty;
2062
+ var __defNormalProp$i = (obj, key, value) => key in obj ? __defProp$i(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2063
+ var __publicField$i = (obj, key, value) => {
2064
+ __defNormalProp$i(obj, typeof key !== "symbol" ? key + "" : key, value);
2065
+ return value;
2066
+ };
2067
+ class UploaderApi extends UploaderApi$1 {
2068
+ constructor(execution, id, type, modalConfig) {
2069
+ super({
2070
+ id,
2071
+ modalConfig: { ...modalConfig, renderers: execution.renderers },
2072
+ context: {
2073
+ allowTranslation: type === "E" && !!getWindow(execution).DOC_LANGS,
2074
+ CONTEXT: getWindow(execution).CONTEXT,
2075
+ currentUserLogin: getWindow(execution).CURRENT_USER_LOGIN,
2076
+ docLangs: getWindow(execution).DOC_LANGS,
2077
+ everyoneCanUpdate: getWindow(execution).DOCUMENT_EVERYONE_PERMISSION !== false,
2078
+ IN_MONITOR: getWindow(execution).IN_MONITOR,
2079
+ ITHit: getWindow(execution).ITHit,
2080
+ killSession: () => execution.kill(),
2081
+ labels: getWindow(execution).labels,
2082
+ notify: (n) => execution.notifications.add(new MessageNotification(n)),
2083
+ openModal: () => execution.environment.openUploaderModal?.(this.modalController),
2084
+ ownerCanUpdate: getWindow(execution).DOCUMENT_OWNER_PRIVILEGES,
2085
+ readonly: false,
2086
+ TAB_ID_REQUEST: getWindow(execution).TAB_ID_REQUEST,
2087
+ URL_REQUEST_AJAX: getWindow(execution).URL_REQUEST_AJAX,
2088
+ WEBDAV_INSTALLER_URL: getWindow(execution).WEBDAV_INSTALLER_URL,
2089
+ WEBDAV_SERVER: getWindow(execution).WEBDAV_SERVER
3588
2090
  }
3589
- return newFiles;
3590
- }
3591
- return files;
2091
+ });
2092
+ this.execution = execution;
2093
+ this.type = type;
2094
+ __publicField$i(this, "docTypePermittedObjId");
2095
+ __publicField$i(this, "getCheckLockDocumentParameters", (defaultParameters) => {
2096
+ return this.addPrefix(defaultParameters);
2097
+ });
2098
+ this.docTypePermittedObjId = type === "E" ? getWindow(execution).docTypePerEntId : getWindow(execution).docTypePerProId;
3592
2099
  }
3593
2100
  getLoadFileSystemStructureTree() {
3594
2101
  return {
@@ -3604,6 +2111,70 @@ class UploaderApi extends EventEmitter$1 {
3604
2111
  docTypePermittedObjType: this.type
3605
2112
  };
3606
2113
  }
2114
+ getAjaxUploadStartParameters(defaultParameters) {
2115
+ return {
2116
+ ...defaultParameters,
2117
+ prefix: this.type,
2118
+ useDocTypePermitted: true,
2119
+ docTypePermittedObjType: this.type,
2120
+ docTypePermittedObjId: this.docTypePermittedObjId
2121
+ };
2122
+ }
2123
+ addPrefix(defaultParameters) {
2124
+ return { ...defaultParameters, prefix: this.type };
2125
+ }
2126
+ getDocumentInfoParameters(defaultParameters) {
2127
+ return this.addPrefix(defaultParameters);
2128
+ }
2129
+ getReloadMetadataParameters(defaultParameters) {
2130
+ return this.addPrefix(defaultParameters);
2131
+ }
2132
+ getSaveDroppedFilesParameters(defaultParameters) {
2133
+ return {
2134
+ ...defaultParameters,
2135
+ elemType: this.type,
2136
+ elemId: `prmDocumentContainter${this.type}`
2137
+ };
2138
+ }
2139
+ getAjaxUploadFileStatusParameters(defaultParameters) {
2140
+ return this.addPrefix(defaultParameters);
2141
+ }
2142
+ getMarkFileToSignParameters(defaultParameters) {
2143
+ return this.addPrefix(defaultParameters);
2144
+ }
2145
+ getProcessDroppedFilesPostdata(defaultParameters) {
2146
+ return {
2147
+ ...defaultParameters,
2148
+ useDocTypePermitted: true,
2149
+ docTypePermittedObjId: this.docTypePermittedObjId?.toString(),
2150
+ docTypePermittedObjType: this.type
2151
+ };
2152
+ }
2153
+ getProcessDroppedFilesParameters(defaultParameters) {
2154
+ return { ...defaultParameters, elemType: this.type };
2155
+ }
2156
+ getConfirmDropModalParameters(defaultParameters) {
2157
+ return { ...defaultParameters, elemType: this.type };
2158
+ }
2159
+ getConfirmDropModalPostdata(defaultParameters) {
2160
+ return {
2161
+ ...defaultParameters,
2162
+ elemType: this.type,
2163
+ pe: this.docTypePermittedObjId?.toString()
2164
+ };
2165
+ }
2166
+ getCheckWebDavLockParameters(defaultParameters) {
2167
+ return this.addPrefix(defaultParameters);
2168
+ }
2169
+ getDownloadMultipleDocumentsParameters(defaultParameters) {
2170
+ return this.addPrefix(defaultParameters);
2171
+ }
2172
+ getLoadCurrentDocumentsParameters(defaultParameters) {
2173
+ return this.addPrefix(defaultParameters);
2174
+ }
2175
+ getDeleteDocumentParameters(defaultParameters) {
2176
+ return this.addPrefix(defaultParameters);
2177
+ }
3607
2178
  }
3608
2179
 
3609
2180
  var __defProp$h = Object.defineProperty;
@@ -3622,28 +2193,8 @@ class FormsUploader extends UploaderApi {
3622
2193
  );
3623
2194
  this.execution = execution;
3624
2195
  this.type = type;
3625
- this.modalConfig = modalConfig;
3626
2196
  this.field = field;
3627
2197
  __publicField$h(this, "isEditionMode");
3628
- __publicField$h(this, "getAjaxUploadFileStatusParameters", (defaultParameters) => {
3629
- return {
3630
- ...defaultParameters,
3631
- forceDocTypeId: this.field.properties.docType,
3632
- ...this.getFormParameters()
3633
- };
3634
- });
3635
- __publicField$h(this, "getAjaxUploadStartParameters", ({
3636
- useDocTypePermitted,
3637
- docTypePermittedObjType,
3638
- docTypePermittedObjId,
3639
- ...defaultParameters
3640
- }) => {
3641
- return {
3642
- ...defaultParameters,
3643
- forceDocTypeId: this.field.properties.docType,
3644
- ...this.getFormParameters()
3645
- };
3646
- });
3647
2198
  __publicField$h(this, "getCheckLockDocumentParameters", ({
3648
2199
  prefix,
3649
2200
  ...parameters
@@ -3674,15 +2225,6 @@ class FormsUploader extends UploaderApi {
3674
2225
  index
3675
2226
  };
3676
2227
  });
3677
- __publicField$h(this, "getConfirmDropModalParameters", (defaultParameters) => {
3678
- const { frmParent } = this.getFormParameters();
3679
- return {
3680
- ...defaultParameters,
3681
- elemType: frmParent,
3682
- forceDocTypeId: this.field.properties.docType,
3683
- ...this.getFormParameters()
3684
- };
3685
- });
3686
2228
  __publicField$h(this, "getConfirmDropModalPostdata", ({
3687
2229
  pe,
3688
2230
  ...parameters
@@ -3704,12 +2246,6 @@ class FormsUploader extends UploaderApi {
3704
2246
  ...rest
3705
2247
  };
3706
2248
  });
3707
- __publicField$h(this, "getDocumentInfoParameters", (parameters) => {
3708
- return {
3709
- ...parameters,
3710
- ajaxUrl: getWindow(this.execution).URL_REQUEST_AJAX
3711
- };
3712
- });
3713
2249
  __publicField$h(this, "getEditDocumentParameters", ({ action, docId }) => {
3714
2250
  const { prefix, editionMode, ...rest } = this.getFormParameters();
3715
2251
  return {
@@ -3748,7 +2284,7 @@ class FormsUploader extends UploaderApi {
3748
2284
  ...defaultParameters
3749
2285
  }) => {
3750
2286
  return {
3751
- ...defaultParameters,
2287
+ ...super.getMarkFileToSignParameters(defaultParameters),
3752
2288
  action: "sign",
3753
2289
  fldId: this.field.definition.id,
3754
2290
  ...this.getFormParameters()
@@ -3769,30 +2305,15 @@ class FormsUploader extends UploaderApi {
3769
2305
  docTypePermittedObjType,
3770
2306
  ...parameters
3771
2307
  }) => {
3772
- return { ...parameters, editionMode: this.getFormParameters().editionMode };
3773
- });
3774
- __publicField$h(this, "getReloadMetadataParameters", (defaultParameters) => {
3775
2308
  return {
3776
- ...defaultParameters,
3777
- ...getWindow(this.execution).IS_EDIT_GRID ? { editionMode: true } : null,
3778
- ...this.getFormParameters()
3779
- };
3780
- });
3781
- __publicField$h(this, "getSaveDroppedFilesParameters", (defaultParameters) => {
3782
- const elemId = this.elemId();
3783
- const { prefix, ...rest } = this.getFormParameters();
3784
- return {
3785
- ...defaultParameters,
3786
- fromFormElem: true,
3787
- elemType: elemId,
3788
- elemId,
3789
- ...rest
2309
+ ...super.getProcessDroppedFilesParameters(parameters),
2310
+ editionMode: this.getFormParameters().editionMode
3790
2311
  };
3791
2312
  });
3792
2313
  __publicField$h(this, "parseFileDefinition", (file) => {
3793
2314
  return {
3794
2315
  ...parseFileDefinition(
3795
- this.execution,
2316
+ this.context,
3796
2317
  file,
3797
2318
  this.field.properties.reqSign || false
3798
2319
  ),
@@ -3809,6 +2330,9 @@ class FormsUploader extends UploaderApi {
3809
2330
  elemId() {
3810
2331
  return `dropUpprDiv${this.field.getForm().definition.frmParent}_${this.field.getForm().definition.id}_${this.field.definition.id}_${this.index()}${getWindow(this.execution).IS_EDIT_GRID_MODAL ? "_true_Mdl" : ""}`;
3811
2332
  }
2333
+ buildModalController(conf) {
2334
+ return super.buildModalController(conf);
2335
+ }
3812
2336
  filterByFilesAmountLimit(files) {
3813
2337
  const inProgressFiles = this.state.inProgressFiles;
3814
2338
  if (inProgressFiles.length === 1 && files.length)
@@ -3849,6 +2373,64 @@ class FormsUploader extends UploaderApi {
3849
2373
  }
3850
2374
  };
3851
2375
  }
2376
+ getAjaxUploadFileStatusParameters(defaultParameters) {
2377
+ return {
2378
+ ...super.getAjaxUploadFileStatusParameters(defaultParameters),
2379
+ forceDocTypeId: this.field.properties.docType,
2380
+ ...this.getFormParameters()
2381
+ };
2382
+ }
2383
+ getAjaxUploadStartParameters({
2384
+ useDocTypePermitted,
2385
+ docTypePermittedObjType,
2386
+ docTypePermittedObjId,
2387
+ ...defaultParameters
2388
+ }) {
2389
+ const {
2390
+ docTypePermittedObjId: a,
2391
+ docTypePermittedObjType: b,
2392
+ useDocTypePermitted: c,
2393
+ ...rest
2394
+ } = super.getAjaxUploadStartParameters(defaultParameters);
2395
+ return {
2396
+ ...rest,
2397
+ forceDocTypeId: this.field.properties.docType,
2398
+ ...this.getFormParameters()
2399
+ };
2400
+ }
2401
+ getConfirmDropModalParameters(defaultParameters) {
2402
+ const { frmParent } = this.getFormParameters();
2403
+ return {
2404
+ ...super.getConfirmDropModalParameters(defaultParameters),
2405
+ elemType: frmParent,
2406
+ forceDocTypeId: this.field.properties.docType,
2407
+ ...this.getFormParameters()
2408
+ };
2409
+ }
2410
+ getDocumentInfoParameters(parameters) {
2411
+ return {
2412
+ ...super.getDocumentInfoParameters(parameters),
2413
+ ajaxUrl: getWindow(this.execution).URL_REQUEST_AJAX
2414
+ };
2415
+ }
2416
+ getReloadMetadataParameters(defaultParameters) {
2417
+ return {
2418
+ ...super.getReloadMetadataParameters(defaultParameters),
2419
+ ...getWindow(this.execution).IS_EDIT_GRID ? { editionMode: true } : null,
2420
+ ...this.getFormParameters()
2421
+ };
2422
+ }
2423
+ getSaveDroppedFilesParameters(defaultParameters) {
2424
+ const elemId = this.elemId();
2425
+ const { prefix, ...rest } = this.getFormParameters();
2426
+ return {
2427
+ ...super.getSaveDroppedFilesParameters(defaultParameters),
2428
+ fromFormElem: true,
2429
+ elemType: elemId,
2430
+ elemId,
2431
+ ...rest
2432
+ };
2433
+ }
3852
2434
  async downloadVersion(fileId, version) {
3853
2435
  const file = this.getDocument(fileId);
3854
2436
  if (!file)
@@ -4379,7 +2961,7 @@ class Grid extends Field {
4379
2961
  }));
4380
2962
  this.state.isLoading = false;
4381
2963
  this.state.isMaximized = false;
4382
- this.controller.on("columnSort", (col) => {
2964
+ this.controller.on("columnClick", (col) => {
4383
2965
  this.sortColumn(col.getState("properties").col.fldId);
4384
2966
  });
4385
2967
  }
@@ -4724,12 +3306,14 @@ class Grid extends Field {
4724
3306
  }
4725
3307
  refreshColumnsVisibilities() {
4726
3308
  const shownColumns = /* @__PURE__ */ new Set();
4727
- for (let i = 0; i < this.tableController.body.rows[0]?.cells.length || 0; i++) {
4728
- for (const row of this.tableController.body.rows) {
3309
+ this.tableController.head.rows[0]?.cells.forEach((c) => {
3310
+ shownColumns.add(c.getState("colName"));
3311
+ });
3312
+ for (let i = 0; i < this.tableController.head.rows[0]?.cells.length || 0; i++) {
3313
+ for (const row of this.tableController.head.rows) {
4729
3314
  const cell = row.cells[i];
4730
- const field = cell.getState("properties")?.field;
4731
- if (!(field && (field.properties.visibilityHidden || field instanceof Hidden))) {
4732
- shownColumns.add(cell.getState("colName"));
3315
+ if (cell instanceof HeaderCell && cell.getState("isHidden")) {
3316
+ shownColumns.delete(cell.getState("colName"));
4733
3317
  break;
4734
3318
  }
4735
3319
  }
@@ -5430,7 +4014,7 @@ class Input extends TranslatableField {
5430
4014
  return false;
5431
4015
  return super.validate();
5432
4016
  }
5433
- hasValue() {
4017
+ isValidValue() {
5434
4018
  return !!String(this.getValue()).trim();
5435
4019
  }
5436
4020
  }
@@ -5478,7 +4062,7 @@ class Multiple extends FieldWithAttribute {
5478
4062
  }
5479
4063
 
5480
4064
  class Password extends FieldWithAttribute {
5481
- hasValue() {
4065
+ isValidValue() {
5482
4066
  return !!String(this.getValue()).trim();
5483
4067
  }
5484
4068
  }
@@ -5535,7 +4119,7 @@ class Select extends FieldWithAttribute {
5535
4119
  }
5536
4120
 
5537
4121
  class Textarea extends TranslatableField {
5538
- hasValue() {
4122
+ isValidValue() {
5539
4123
  return !!String(this.getValue()).trim();
5540
4124
  }
5541
4125
  getSynchronizePostConfiguration(value) {
@@ -5644,6 +4228,9 @@ class Tree extends FieldWithAttribute {
5644
4228
  arrayOrArray(this.properties.possibleValue)
5645
4229
  );
5646
4230
  }
4231
+ isValidValue() {
4232
+ return this.state.value.length > 0;
4233
+ }
5647
4234
  async setValue(newValue, options) {
5648
4235
  const res = await super.setValue(newValue, options);
5649
4236
  if (res) {
@@ -5704,7 +4291,8 @@ class SchedulerField extends Field {
5704
4291
  loadWeek: this.loadWeek.bind(this),
5705
4292
  deleteDate: this.deleteDate.bind(this),
5706
4293
  markDay: this.markDay.bind(this),
5707
- loadInfo: this.loadInfo.bind(this)
4294
+ loadInfo: this.loadInfo.bind(this),
4295
+ selectDayHandler: this.selectDayHandler.bind(this)
5708
4296
  },
5709
4297
  "Scheduler",
5710
4298
  getWindow(this.getForm().execution)
@@ -5753,6 +4341,47 @@ class SchedulerField extends Field {
5753
4341
  })
5754
4342
  );
5755
4343
  }
4344
+ async selectDayHandler({
4345
+ cellId,
4346
+ currentDayDefinition,
4347
+ dayNumber,
4348
+ hour,
4349
+ weekDay
4350
+ }) {
4351
+ await get(
4352
+ this.form.execution,
4353
+ makeApiaUrl(this.form.execution, {
4354
+ ajaxUrl: "/apia.design.TaskSchedulerAction.run",
4355
+ action: "setExecutionSchedulerSelectedDay",
4356
+ weekDay,
4357
+ hour,
4358
+ dayNumber
4359
+ })
4360
+ ).then((response) => {
4361
+ if (response?.data?.success) {
4362
+ this._schedController?.setState({
4363
+ ...this._schedController.state,
4364
+ selectedCell: cellId,
4365
+ selectedDay: {
4366
+ hour: String(hour),
4367
+ day: dayjs(weekDay, getDateFormat()).add(Number(dayNumber) - 1, "day").format(getDateFormat()),
4368
+ mondayWeek: String(
4369
+ dayjs(weekDay, getDateFormat()).format(getDateFormat())
4370
+ ),
4371
+ dayNumber: Number(dayNumber),
4372
+ morningOrAfternoonSelected: Number(hour)
4373
+ }
4374
+ });
4375
+ if (currentDayDefinition) {
4376
+ this._schedController?.syncStage(
4377
+ currentDayDefinition,
4378
+ Number(hour)
4379
+ );
4380
+ }
4381
+ }
4382
+ }).catch(() => {
4383
+ });
4384
+ }
5756
4385
  get schedController() {
5757
4386
  return this._schedController;
5758
4387
  }
@@ -6804,7 +5433,6 @@ class GridField extends ApiaField {
6804
5433
  __privateAdd$6(this, _mutex, new Mutex());
6805
5434
  __privateSet$6(this, _execution$2, execution);
6806
5435
  __privateSet$6(this, _field$2, field);
6807
- __privateSet$6(this, _execution$2, execution);
6808
5436
  }
6809
5437
  async addRow() {
6810
5438
  try {
@@ -7135,7 +5763,7 @@ class ApiaForm {
7135
5763
  hideModal() {
7136
5764
  __privateGet$3(this, _execution$1).emit("hideFormModal", __privateGet$3(this, _form));
7137
5765
  }
7138
- showAsModal(size) {
5766
+ showAsModal(size = "finder") {
7139
5767
  __privateGet$3(this, _execution$1).emit("showFormAsModal", { form: __privateGet$3(this, _form), size });
7140
5768
  }
7141
5769
  }
@@ -8077,21 +6705,6 @@ class Form extends WithProperties {
8077
6705
  }
8078
6706
  return super.getProperty(propName);
8079
6707
  }
8080
- getErrorsList() {
8081
- const errors = [];
8082
- this.allFields.forEach((f) => {
8083
- if (f instanceof FieldWithAttribute) {
8084
- const fieldErrors = f.state.validation.errorMessage;
8085
- if (fieldErrors) {
8086
- errors.push({
8087
- id: `${f.getForm().definition.frmParent}_${f.getForm().definition.id}_${f.definition.id}`,
8088
- errorMessage: fieldErrors
8089
- });
8090
- }
8091
- }
8092
- });
8093
- return errors;
8094
- }
8095
6708
  }
8096
6709
 
8097
6710
  function decodeBase64ToUtf8(base64String) {
@@ -8551,7 +7164,7 @@ class Observations {
8551
7164
  makeApiaUrl(this.execution, {
8552
7165
  action: "getObservationsData",
8553
7166
  isAjax: true,
8554
- isTask: !window.isMonitor ? true : false
7167
+ isTask: !getWindow(this.execution).isMonitor ? true : false
8555
7168
  })
8556
7169
  );
8557
7170
  if (!res?.data?.obData) {
@@ -8706,6 +7319,7 @@ function buildPoolSelection(execution, status, poolForm) {
8706
7319
  function buildPathSelection(execution, status, form) {
8707
7320
  const modal = new ShowPathSelection(form, async function(result) {
8708
7321
  if (result.confirmed) {
7322
+ const unLock = execution.lock();
8709
7323
  const pathSelectionResult = await axios.post(
8710
7324
  makeApiaUrl(execution, {
8711
7325
  action: "confirmPath",
@@ -8717,6 +7331,8 @@ function buildPathSelection(execution, status, form) {
8717
7331
  const parsedRes = parseXMLRequestResponse(
8718
7332
  pathSelectionResult
8719
7333
  );
7334
+ if (parsedRes)
7335
+ unLock();
8720
7336
  if (parsedRes?.groupSelection) {
8721
7337
  return buildPoolSelection(execution, status, parsedRes.load.form);
8722
7338
  } else if (parsedRes?.actions?.action?.toDo === "functionTimedCall") {
@@ -8852,7 +7468,8 @@ async function defaultConfirm$1(execution, status) {
8852
7468
  if (key === "value" && typeof value === "string") {
8853
7469
  return value;
8854
7470
  }
8855
- return processStringObj(value, key);
7471
+ const parsed = processStringObj(value, key);
7472
+ return parsed;
8856
7473
  };
8857
7474
  const baseOptions = getDefaultXmlParserOptions();
8858
7475
  baseOptions.attrValueProcessors = [
@@ -8861,10 +7478,22 @@ async function defaultConfirm$1(execution, status) {
8861
7478
  processAjaxEventResponse
8862
7479
  ];
8863
7480
  const parser = new xml2js.Parser(baseOptions);
8864
- return getDefaultXmlPostProcessor()(
7481
+ let objJS = null;
7482
+ parser.parseString(
8865
7483
  xml,
8866
- parser
7484
+ (err, result) => {
7485
+ if (err) {
7486
+ console.warn("Error Parsing XML data", err);
7487
+ objJS = err;
7488
+ } else {
7489
+ if (result?.code === "-1" && result.exceptions) {
7490
+ throw new InvalidSessionException();
7491
+ }
7492
+ objJS = result;
7493
+ }
7494
+ }
8867
7495
  );
7496
+ return objJS;
8868
7497
  }
8869
7498
  }
8870
7499
  );
@@ -9224,13 +7853,14 @@ const unescapeMarkup = (str) => {
9224
7853
  return "";
9225
7854
  };
9226
7855
  class Execution extends EventEmitter$1 {
9227
- constructor(environment) {
7856
+ constructor(environment, renderers) {
9228
7857
  super();
9229
7858
  this.environment = environment;
7859
+ this.renderers = renderers;
9230
7860
  __publicField(this, "fieldsMapping");
9231
- __publicField(this, "entity", new Entity(this));
9232
- __publicField(this, "process", new Process(this));
9233
- __publicField(this, "observations", new Observations(this));
7861
+ __publicField(this, "entity");
7862
+ __publicField(this, "process");
7863
+ __publicField(this, "observations");
9234
7864
  __publicField(this, "executedOnLoadEvents", false);
9235
7865
  __publicField(this, "executionConfig", null);
9236
7866
  __publicField(this, "_steps", []);
@@ -9289,6 +7919,11 @@ class Execution extends EventEmitter$1 {
9289
7919
  this.fieldsMapping = { ...defaultFieldsMap, ...environment.fieldsMapping };
9290
7920
  this.notifications = new Notifications(this);
9291
7921
  makeObservable(this, { state: observable });
7922
+ setTimeout(() => {
7923
+ this.entity = new Entity(this);
7924
+ this.process = new Process(this);
7925
+ this.observations = new Observations(this);
7926
+ }, 0);
9292
7927
  }
9293
7928
  addPendingPromise(promise) {
9294
7929
  this._pendingPromises.add(promise);
@@ -9296,17 +7931,6 @@ class Execution extends EventEmitter$1 {
9296
7931
  this._pendingPromises.delete(promise);
9297
7932
  });
9298
7933
  }
9299
- getErrorsList() {
9300
- const entityErrors = [];
9301
- this.forms.E.forEach((form) => {
9302
- entityErrors.push(...form.getErrorsList());
9303
- });
9304
- const processErrors = [];
9305
- this.forms.P.forEach((form) => {
9306
- processErrors.push(...form.getErrorsList());
9307
- });
9308
- return [...entityErrors, ...processErrors];
9309
- }
9310
7934
  getAllForms() {
9311
7935
  return [...this.forms.E.values(), ...this.forms.P.values()];
9312
7936
  }
@@ -9774,5 +8398,5 @@ class Execution extends EventEmitter$1 {
9774
8398
  }
9775
8399
  }
9776
8400
 
9777
- export { ActionsController, AdditionalCell, ApiaAttribute, ApiaField, ApiaFieldWithAttribute, ApiaForm, ApiaFunctions, BouncingEmitter, Button, ButtonField, Captcha, CaptchaField, CheckField, Checkbox, CustomComponent, GridField as DataGridField, Editor, EditorField, EventEmitter, Execution, ExecutionState, Field, FieldWithAttribute, File, FileUploaderField, FlowModal$1 as FlowModal, Form, FormsUploader, Grid, GridCell, GridField, GridPaginated, HeaderCell, Hidden, HiddenField, IProperty, Image, ImageField, Input, InputField, InvalidSessionException, Label, Link, LinkField, MessageNotification, ModalInput, ModalInputField, Multiple, MultipleField, Notifications, Password, PasswordField, Radio, RadioField, SchedulerField, Select, SelectField, ShowConfirmMessage, ShowPathSelection, ShowPoolSelection, ShowSign$1 as ShowSign, ShowSignSelection$1 as ShowSignSelection, StatefulEmitter, StatusNotification, AreaField as TextAreaField, TextField, Textarea, Title, TranslatableField, Translation, Tree, TreeField, UploaderApi, UploaderModalController, createNewField, deepEqual, get, getLabel, isHtmlResponse, isJsonResponse, isOneClickUploadEnabled, isXmlResponse, makeApiaUrl, parseFakeJSON$1 as parseFakeJSON, parseFileDefinition, parseSuccessfulResponse, parseXml, post, returnExactlyTheSame, shallowEqual };
8401
+ export { ActionsController, AdditionalCell, ApiaAttribute, ApiaField, ApiaFieldWithAttribute, ApiaForm, ApiaFunctions, BouncingEmitter, Button, ButtonField, Captcha, CaptchaField, CheckField, Checkbox, CustomComponent, GridField as DataGridField, Editor, EditorField, EventEmitter, Execution, ExecutionState, Field, FieldWithAttribute, File, FileUploaderField, FlowModal$1 as FlowModal, Form, FormsUploader, Grid, GridCell, GridField, GridPaginated, HeaderCell, Hidden, HiddenField, IProperty, Image, ImageField, Input, InputField, InvalidSessionException, Label, Link, LinkField, MessageNotification, ModalInput, ModalInputField, Multiple, MultipleField, Notifications, Password, PasswordField, Radio, RadioField, SchedulerField, Select, SelectField, ShowConfirmMessage, ShowPathSelection, ShowPoolSelection, ShowSign$1 as ShowSign, ShowSignSelection$1 as ShowSignSelection, StatefulEmitter, StatusNotification, AreaField as TextAreaField, TextField, Textarea, Title, TranslatableField, Translation, Tree, TreeField, UploaderApi, createNewField, deepEqual, get, getLabel, isHtmlResponse, isJsonResponse, isXmlResponse, makeApiaUrl, parseFakeJSON$1 as parseFakeJSON, parseSuccessfulResponse, parseXml, post, shallowEqual };
9778
8402
  //# sourceMappingURL=index.js.map