@apia/execution 4.0.85 → 4.0.89

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.d.ts CHANGED
@@ -103,6 +103,8 @@ interface IApiaDataGridColumn {
103
103
  type TApiaGridField = TApiaFieldBaseDefinition<any> & {
104
104
  fieldValue?: Pick<TApiaFieldWithAttributeBaseProps<any>, 'value' | 'properties' | 'qry_show_value'>;
105
105
  row?: Pick<TApiaFieldWithAttributeBaseProps<any>, 'value' | 'properties'> & Pick<TApiaSelectProperties, 'possibleValue'>;
106
+ attLabel?: string;
107
+ valueType?: string;
106
108
  };
107
109
  type TApiaGridDefinition = TApiaFieldBaseDefinition<TApiaGridProperties> & {
108
110
  curPage?: number;
@@ -305,6 +307,7 @@ type TApiaGridProperties = TApiaFieldCommonProperties & {
305
307
  paged?: boolean;
306
308
  pagedGridSize?: number;
307
309
  hideMaximizeButton: boolean;
310
+ gridQuery?: string;
308
311
  };
309
312
  type TApiaHiddenProperties = TApiaFieldCommonProperties & TApiaGroupableFieldProperties & TApiaFieldWithAttributeProperties & {};
310
313
  type TApiaImageProperties = TApiaFieldCommonProperties & TApiaGroupableFieldProperties & {
@@ -2736,6 +2739,7 @@ type ConfirmStep = 'CHECK_LOCK' | 'CONFIRM' | 'CHECK_SIGN' | 'CHECK_WIZARD' | 'S
2736
2739
  type Status = {
2737
2740
  step?: ConfirmStep;
2738
2741
  error?: string;
2742
+ type?: string;
2739
2743
  finishedWithError?: boolean;
2740
2744
  };
2741
2745
  declare abstract class FlowModal<T extends {
@@ -2914,6 +2918,7 @@ declare class Execution extends EventEmitter$1<{
2914
2918
  readonly notifications: Notifications;
2915
2919
  private lastModalReturn;
2916
2920
  private _pendingPromises;
2921
+ private _pendingNoAjaxNavigation;
2917
2922
  constructor(environment: TExecutionEnvironment, renderers?: TModalConfig['renderers']);
2918
2923
  protected formsById: {
2919
2924
  E: Map<string, Form>;
@@ -2929,6 +2934,9 @@ declare class Execution extends EventEmitter$1<{
2929
2934
  hasChangedAnything: boolean;
2930
2935
  };
2931
2936
  addPendingPromise(promise: Promise<boolean>): void;
2937
+ markNoAjaxNavigationAsPending(): void;
2938
+ clearNoAjaxNavigationPendingState(): void;
2939
+ hasPendingNoAjaxNavigation(): boolean;
2932
2940
  getErrorsList(): FieldError[];
2933
2941
  getAllForms(): Form[];
2934
2942
  private hasInitializedFormsTabs;
@@ -3352,7 +3360,8 @@ declare class Grid extends Field<GridProps, GridDefinition, GridState> {
3352
3360
  definition: Omit<TApiaFieldBaseDefinition<TApiaFieldCommonProperties>, "properties">;
3353
3361
  }>[][];
3354
3362
  get startIndex(): number;
3355
- constructor({ properties, field, ...definition }: TApiaGridDefinition);
3363
+ protected static parseGridDefinition(xml: string | TApiaGridDefinition): TApiaGridDefinition;
3364
+ constructor(definition: TApiaGridDefinition);
3356
3365
  private resolveHeaderWidth;
3357
3366
  protected getGridActionFromEventName(eventName: GridEvents): "delete" | "add" | undefined;
3358
3367
  protected fireServerEvent(eventName: GridEvents, params?: FireEventParameters): Promise<boolean>;
package/dist/index.js CHANGED
@@ -1028,10 +1028,12 @@ function getDocument(execution) {
1028
1028
  return execution.environment.document;
1029
1029
  }
1030
1030
 
1031
- function getCurrentTabsString(execution) {
1031
+ function getCurrentTabsString(execution, avoidScroll) {
1032
1032
  const tabsList = getWindow(execution).tabsController?.tabsList;
1033
1033
  if (tabsList)
1034
- return `${tabsList.map((c) => c.state.isOpen ? c.id : -1).filter((c) => !(typeof c === "number")).join(",")}~${getDocument(execution).scrollingElement?.scrollTop ?? 0}`;
1034
+ return `${tabsList.map((c) => c.state.isOpen ? c.id : -1).filter((c) => !(typeof c === "number")).join(
1035
+ ","
1036
+ )}~${!avoidScroll ? getDocument(execution).scrollingElement?.scrollTop ?? 0 : 0}`;
1035
1037
  }
1036
1038
 
1037
1039
  const actions = {
@@ -1370,15 +1372,9 @@ class Field extends WithProperties {
1370
1372
  }
1371
1373
  async fireNoAjaxServerEvent(event, params) {
1372
1374
  const p = this.getServerEventParams(event.evtId, params);
1373
- if (getWindow(this.form.execution).config.execution.reloadOnNoAjaxEvents) {
1374
- getWindow(this.form.execution).location.assign(
1375
- await makeApiaUrl(this.form.execution, {
1376
- ...p,
1377
- currentTab: getCurrentTabsString(this.form.execution),
1378
- stringifyOptions: { arrayFormat: "repeat" }
1379
- })
1380
- );
1381
- } else {
1375
+ this.form.execution.markNoAjaxNavigationAsPending();
1376
+ const unlock = this.getForm().execution.lock();
1377
+ try {
1382
1378
  getWindow(this.form.execution).location.assign(
1383
1379
  await makeApiaUrl(this.form.execution, {
1384
1380
  ...p,
@@ -1386,10 +1382,18 @@ class Field extends WithProperties {
1386
1382
  stringifyOptions: { arrayFormat: "repeat" }
1387
1383
  })
1388
1384
  );
1385
+ } catch (e) {
1386
+ this.form.execution.clearNoAjaxNavigationPendingState();
1387
+ unlock();
1388
+ throw e;
1389
1389
  }
1390
1390
  return false;
1391
1391
  }
1392
1392
  async fireServerEvent(eventName, params) {
1393
+ if (this.form.execution.hasPendingNoAjaxNavigation()) {
1394
+ console.warn(`Server busy, firing event failed: ${eventName}`);
1395
+ return false;
1396
+ }
1393
1397
  let event = this.definition.serverEvents?.find(
1394
1398
  (c) => c.evtName === eventName
1395
1399
  );
@@ -1415,6 +1419,10 @@ class Field extends WithProperties {
1415
1419
  return true;
1416
1420
  }
1417
1421
  async fireEvent(eventName, params) {
1422
+ if (this.form.execution.hasPendingNoAjaxNavigation()) {
1423
+ console.warn(`Server busy, firing event failed: ${eventName}`);
1424
+ return false;
1425
+ }
1418
1426
  const unlock = this.form.execution.lock();
1419
1427
  try {
1420
1428
  let result = await this.fireScriptEvent(eventName);
@@ -1424,6 +1432,10 @@ class Field extends WithProperties {
1424
1432
  } catch (e) {
1425
1433
  console.warn("waitForPendingSyncs failed or timed out", e);
1426
1434
  }
1435
+ if (this.form.execution.hasPendingNoAjaxNavigation()) {
1436
+ console.warn(`Server busy, firing event failed: ${eventName}`);
1437
+ return false;
1438
+ }
1427
1439
  result = await this.fireServerEvent(eventName, params);
1428
1440
  }
1429
1441
  return result;
@@ -2107,6 +2119,7 @@ class UploaderApi extends UploaderApi$1 {
2107
2119
  return this.addPrefix(defaultParameters);
2108
2120
  });
2109
2121
  this.docTypePermittedObjId = type === "E" ? getWindow(execution).docTypePerEntId : getWindow(execution).docTypePerProId;
2122
+ this.showConfirmMessage = getWindow(execution).config?.components?.uploader?.showSuccessMessage;
2110
2123
  }
2111
2124
  getLoadFileSystemStructureTree() {
2112
2125
  return {
@@ -2916,14 +2929,16 @@ async function inlineTimeout(cb, _t) {
2916
2929
  return Promise.resolve(true);
2917
2930
  }
2918
2931
  class Grid extends Field {
2919
- constructor({ properties, field, ...definition }) {
2932
+ constructor(definition) {
2933
+ const parsedDefinition = Grid.parseGridDefinition(definition);
2934
+ const { properties, field, ...gridDefinition } = parsedDefinition;
2920
2935
  super({
2921
- ...definition,
2936
+ ...gridDefinition,
2922
2937
  properties: {
2923
- currentPage: noNaN(definition.curPage, 1),
2938
+ currentPage: noNaN(parsedDefinition.curPage, 1),
2924
2939
  maxRows: properties.maxRecords || Infinity,
2925
2940
  paged: false,
2926
- pages: noNaN(definition.pages, 1),
2941
+ pages: noNaN(parsedDefinition.pages, 1),
2927
2942
  pageSize: noNaN(
2928
2943
  properties.pagedGridSize,
2929
2944
  properties.paged ? 5 : Infinity
@@ -2961,15 +2976,17 @@ class Grid extends Field {
2961
2976
  return { ...current, properties: parseFakeJSON$1(properties2) };
2962
2977
  }
2963
2978
  );
2964
- this.state.header = arrayOrArray(definition.gridHeader.col).map((c) => ({
2965
- fldId: c.fldId,
2966
- label: c.colTitle,
2967
- title: c.title,
2968
- width: c.colWidth || this.resolveHeaderWidth(c),
2969
- hidden: false,
2970
- required: false,
2971
- fldType: c.fldType
2972
- }));
2979
+ this.state.header = arrayOrArray(parsedDefinition.gridHeader.col).map(
2980
+ (c) => ({
2981
+ fldId: c.fldId,
2982
+ label: c.colTitle,
2983
+ title: c.title,
2984
+ width: c.colWidth || this.resolveHeaderWidth(c),
2985
+ hidden: false,
2986
+ required: false,
2987
+ fldType: c.fldType
2988
+ })
2989
+ );
2973
2990
  this.state.isLoading = false;
2974
2991
  this.state.isMaximized = false;
2975
2992
  this.controller.on("columnClick", (col) => {
@@ -3024,6 +3041,35 @@ class Grid extends Field {
3024
3041
  const pageSize = this.properties.pageSize;
3025
3042
  return noNaN((this.properties.currentPage - 1) * pageSize, 0);
3026
3043
  }
3044
+ static parseGridDefinition(xml) {
3045
+ const definition = typeof xml === "string" ? parseXml(xml) : xml;
3046
+ if (!definition.properties?.gridQuery) {
3047
+ return definition;
3048
+ }
3049
+ const fields = arrayOrArray(definition.field);
3050
+ const columns = arrayOrArray(definition.gridHeader?.col);
3051
+ const totalColumns = Math.max(fields.length, columns.length);
3052
+ return {
3053
+ ...definition,
3054
+ gridHeader: {
3055
+ ...definition.gridHeader,
3056
+ col: new Array(totalColumns).fill(null).map((_, index) => {
3057
+ const column = columns[index] || {};
3058
+ const field = fields[index];
3059
+ return {
3060
+ ...column,
3061
+ colTitle: column.colTitle || field?.properties?.gridColTitle || field?.attLabel || field?.properties?.name || "",
3062
+ colWidth: column.colWidth || field?.colWidth || field?.properties?.colWidth || "",
3063
+ dataType: column.dataType || field?.valueType || "S",
3064
+ fldId: column.fldId || field?.id || String(index),
3065
+ fldType: column.fldType || "",
3066
+ hasQuery: typeof column.hasQuery === "boolean" ? column.hasQuery : !!field?.qryId,
3067
+ title: column.title || field?.attLabel || ""
3068
+ };
3069
+ })
3070
+ }
3071
+ };
3072
+ }
3027
3073
  resolveHeaderWidth(c) {
3028
3074
  if (c.fldType === "9" || c.fldType === "1" && c.dataType === "D" || c.fldType === "1" && c.hasQuery) {
3029
3075
  return "200px";
@@ -3065,7 +3111,7 @@ class Grid extends Field {
3065
3111
  });
3066
3112
  const response = await res;
3067
3113
  if (response?.data?.gridXml) {
3068
- const xml = parseXml(response.data.gridXml);
3114
+ const xml = Grid.parseGridDefinition(response.data.gridXml);
3069
3115
  const fieldsArray = arrayOrArray(xml.field);
3070
3116
  this.newRowStates = fieldsArray.map(
3071
3117
  (current) => current.fieldValue || current.row ? arrayOrArray(current.fieldValue || current.row) : void 0
@@ -3632,16 +3678,17 @@ class Grid extends Field {
3632
3678
  return this.tableController.body.getRowByIndex(index)?.cells.filter((c) => c instanceof GridCell).map((c) => c.getField());
3633
3679
  }
3634
3680
  async rebuildGrid(xmlString) {
3635
- const xml = typeof xmlString === "string" ? parseXml(xmlString) : xmlString;
3681
+ const xml = Grid.parseGridDefinition(xmlString);
3636
3682
  const fieldsArray = arrayOrArray(xml.field);
3637
3683
  const statesArray = fieldsArray.map(
3638
3684
  (field) => arrayOrArray(field.fieldValue || field.row)
3639
3685
  );
3686
+ const rowCount = statesArray[0]?.length || 0;
3640
3687
  this.properties.pages = xml.pages || this.properties.pages;
3641
3688
  this.properties.currentPage = xml.curPage || this.properties.currentPage;
3642
3689
  this.properties.visibilityHidden = xml.properties.visibilityHidden ?? this.properties.visibilityHidden;
3643
- if (statesArray[0].length > this.controller.body.rows.length) {
3644
- for (let i = this.controller.body.rows.length; i < statesArray[0].length; i++) {
3690
+ if (rowCount > this.controller.body.rows.length) {
3691
+ for (let i = this.controller.body.rows.length; i < rowCount; i++) {
3645
3692
  const parsedFieldGroups = fieldsArray.map((field, columnIndex) => {
3646
3693
  if (field.fieldType === "radio" || field.fieldType === "select") {
3647
3694
  const parsedField = {
@@ -3661,10 +3708,10 @@ class Grid extends Field {
3661
3708
  });
3662
3709
  await this.addRowFromDefinitions(false, parsedFieldGroups);
3663
3710
  }
3664
- } else if (statesArray[0].length < this.controller.body.rows.length) {
3711
+ } else if (rowCount < this.controller.body.rows.length) {
3665
3712
  const removeIndices = new Array(
3666
- this.controller.body.rows.length - statesArray[0].length
3667
- ).fill(0).map((_, i) => i + statesArray[0].length);
3713
+ this.controller.body.rows.length - rowCount
3714
+ ).fill(0).map((_, i) => i + rowCount);
3668
3715
  removeIndices.sort((a, b) => b - a).forEach((i) => {
3669
3716
  this.controller.body.getRowByIndex(i)?.remove();
3670
3717
  });
@@ -7661,7 +7708,10 @@ async function defaultConfirm$1(execution, status) {
7661
7708
  return {
7662
7709
  step: void 0,
7663
7710
  finishedWithError: true,
7664
- error: `Errors found: ${[
7711
+ type: String(
7712
+ arrayOrArray(confirmResponse?.data?.sysMessages?.message)[0]?.type
7713
+ ),
7714
+ error: `${[
7665
7715
  ...arrayOrArray(confirmResponse?.data?.sysMessages?.message).map(
7666
7716
  (c) => c.text || c.label
7667
7717
  ),
@@ -7804,9 +7854,25 @@ async function confirm(execution, status) {
7804
7854
  }
7805
7855
  result = checkerResult;
7806
7856
  if (result.error) {
7807
- execution.notifications.add(
7808
- new MessageNotification({ message: result.error, type: "error" })
7809
- );
7857
+ let notificationType = "error";
7858
+ switch (result.type) {
7859
+ case "1":
7860
+ notificationType = "success";
7861
+ break;
7862
+ case "2":
7863
+ notificationType = "warning";
7864
+ break;
7865
+ case "3":
7866
+ notificationType = "error";
7867
+ break;
7868
+ case "4":
7869
+ notificationType = "modal";
7870
+ break;
7871
+ default:
7872
+ notificationType = "error";
7873
+ break;
7874
+ }
7875
+ console.error(`Error: ${result.error}, type: ${notificationType}`);
7810
7876
  }
7811
7877
  if (result.error || result.finishedWithError) {
7812
7878
  return false;
@@ -7990,9 +8056,7 @@ async function confirmEntity(execution, status) {
7990
8056
  }
7991
8057
  result = checkerResult;
7992
8058
  if (result.error) {
7993
- execution.notifications.add(
7994
- new MessageNotification({ message: result.error, type: "error" })
7995
- );
8059
+ console.error(`Error: ${result.error}`);
7996
8060
  }
7997
8061
  if (result.error || result.finishedWithError) {
7998
8062
  return false;
@@ -8052,6 +8116,7 @@ class Execution extends EventEmitter$1 {
8052
8116
  __publicField(this, "notifications");
8053
8117
  __publicField(this, "lastModalReturn", []);
8054
8118
  __publicField(this, "_pendingPromises", /* @__PURE__ */ new Set());
8119
+ __publicField(this, "_pendingNoAjaxNavigation", false);
8055
8120
  __publicField(this, "formsById", {
8056
8121
  E: /* @__PURE__ */ new Map(),
8057
8122
  P: /* @__PURE__ */ new Map()
@@ -8114,6 +8179,15 @@ class Execution extends EventEmitter$1 {
8114
8179
  this._pendingPromises.delete(promise);
8115
8180
  });
8116
8181
  }
8182
+ markNoAjaxNavigationAsPending() {
8183
+ this._pendingNoAjaxNavigation = true;
8184
+ }
8185
+ clearNoAjaxNavigationPendingState() {
8186
+ this._pendingNoAjaxNavigation = false;
8187
+ }
8188
+ hasPendingNoAjaxNavigation() {
8189
+ return this._pendingNoAjaxNavigation;
8190
+ }
8117
8191
  getErrorsList() {
8118
8192
  const entityErrors = [];
8119
8193
  this.forms.E.forEach((form) => {
@@ -8304,6 +8378,7 @@ class Execution extends EventEmitter$1 {
8304
8378
  async doBack() {
8305
8379
  const canGoBack = this.executionConfig?.canGoBack;
8306
8380
  if (canGoBack) {
8381
+ const unlock = this.lock();
8307
8382
  try {
8308
8383
  const nextUrl = makeApiaUrl(this, {
8309
8384
  action: "gotoPrevStep",
@@ -8318,6 +8393,7 @@ class Execution extends EventEmitter$1 {
8318
8393
  };
8319
8394
  postNavigation(nextUrl, serverParams);
8320
8395
  } catch (error) {
8396
+ unlock();
8321
8397
  console.error("Confirmation process failed:", error);
8322
8398
  this.notifications.add(
8323
8399
  new MessageNotification({
@@ -8352,10 +8428,14 @@ class Execution extends EventEmitter$1 {
8352
8428
  }
8353
8429
  );
8354
8430
  if (result instanceof FlowModal) {
8431
+ if (!(result instanceof ShowConfirmMessage)) {
8432
+ unlock();
8433
+ }
8355
8434
  return result;
8356
8435
  }
8357
8436
  return result;
8358
8437
  } catch (error) {
8438
+ unlock();
8359
8439
  console.error("Confirmation process failed:", error);
8360
8440
  this.notifications.add(
8361
8441
  new MessageNotification({
@@ -8364,8 +8444,6 @@ class Execution extends EventEmitter$1 {
8364
8444
  })
8365
8445
  );
8366
8446
  return false;
8367
- } finally {
8368
- unlock();
8369
8447
  }
8370
8448
  } else {
8371
8449
  return isValid;
@@ -8410,6 +8488,9 @@ class Execution extends EventEmitter$1 {
8410
8488
  const canGoNext = this.executionConfig?.canGoForward && isValid === true;
8411
8489
  if (canGoNext) {
8412
8490
  const unlock = this.lock();
8491
+ if (result?.confirmed === false) {
8492
+ unlock();
8493
+ }
8413
8494
  try {
8414
8495
  const checkLocksRes = await post(
8415
8496
  this,
@@ -8446,6 +8527,7 @@ class Execution extends EventEmitter$1 {
8446
8527
  }
8447
8528
  const mustShowSignModal = checkSignableFormsRes?.data?.sign;
8448
8529
  if (mustShowSignModal && !result?.signed) {
8530
+ unlock();
8449
8531
  return new ShowSignSelection(
8450
8532
  checkSignableFormsRes?.data,
8451
8533
  async () => {
@@ -8459,7 +8541,7 @@ class Execution extends EventEmitter$1 {
8459
8541
  action: "gotoNextStep",
8460
8542
  asXML: true,
8461
8543
  react: true,
8462
- currentTab: getCurrentTabsString(this),
8544
+ currentTab: getCurrentTabsString(this, true),
8463
8545
  fromPanel: null
8464
8546
  });
8465
8547
  const serverParams = {
@@ -8471,6 +8553,7 @@ class Execution extends EventEmitter$1 {
8471
8553
  postNavigation(nextUrl, serverParams);
8472
8554
  return true;
8473
8555
  } catch (error) {
8556
+ unlock();
8474
8557
  console.error("Confirmation process failed:", error);
8475
8558
  this.notifications.add(
8476
8559
  new MessageNotification({
@@ -8479,8 +8562,6 @@ class Execution extends EventEmitter$1 {
8479
8562
  })
8480
8563
  );
8481
8564
  return false;
8482
- } finally {
8483
- unlock();
8484
8565
  }
8485
8566
  }
8486
8567
  }