tuain-form-manager 1.4.21 → 1.5.2

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.
@@ -1,5 +1,3 @@
1
- /* eslint-disable import/no-dynamic-require */
2
-
3
1
  const crypto = require('crypto');
4
2
  const path = require('path');
5
3
  const modErrs = require('./module-errors');
package/lib/form-utils.js CHANGED
@@ -3,45 +3,19 @@ const COMPARISON_FUNCTIONS_FIELD = 'functionCode';
3
3
  function userAllowed(requiredFunctions, userFunctions, matchFld = null) {
4
4
  for (let index = 0; index < requiredFunctions?.length; index++) {
5
5
  const requiredFunction = requiredFunctions[index];
6
- const hasFunction = userFunctions
7
- ?.find(usrFnc => ((matchFld) ? usrFnc[matchFld] : usrFnc) === requiredFunction);
8
- if (!hasFunction) { return false; }
9
- }
10
- return true;
11
- }
12
-
13
- function supportedStates(formDefinition, states, userFunctions) {
14
- const formFunctions = formDefinition?.form?.functions;
15
- if (!formFunctions || formFunctions?.length === 0) { return states; }
16
- const functionsForStates = {};
17
- for (let index = 0; index < formFunctions.length; index++) {
18
- const functionDef = formFunctions[index];
19
- const { functionCode, modes } = functionDef;
20
- const statesFunction = modes?.split(',')?.map(state => state.trim()) ?? [];
21
- statesFunction.forEach((state) => {
22
- if (!functionsForStates[state]) { functionsForStates[state] = []; }
23
- functionsForStates[state].push(functionCode);
24
- });
25
- }
26
- const userStates = [];
27
- const allStates = Object.keys(functionsForStates);
28
- for (let index = 0; index < allStates.length; index++) {
29
- const state = allStates[index];
30
- if (userAllowed(functionsForStates[state], userFunctions)) {
31
- userStates.push(state);
6
+ const hasFunction = userFunctions?.find((usrFnc) => (matchFld ? usrFnc[matchFld] : usrFnc) === requiredFunction);
7
+ if (!hasFunction) {
8
+ return false;
32
9
  }
33
10
  }
34
- if (userStates.length === 0) { return null; }
35
- formDefinition.form.formModes = userStates;
36
- delete formDefinition.form.functions;
37
- return userStates;
11
+ return true;
38
12
  }
39
13
 
40
14
  function removeUnsupportedActions(actions, userFunctions) {
41
15
  const actIndexesToRemove = [];
42
16
  for (let index = 0; index < actions?.length; index++) {
43
17
  const actionFunctions = actions[index]?.functions ?? [];
44
- if (!actionFunctions.every(fnc => userFunctions?.includes(fnc))) {
18
+ if (!actionFunctions.every((fnc) => userFunctions?.includes(fnc))) {
45
19
  actIndexesToRemove.unshift(index);
46
20
  }
47
21
  delete actions[index].functions;
@@ -71,14 +45,25 @@ function removeUnsupportedTableActions(tables, userFunctions) {
71
45
  }
72
46
 
73
47
  function customizeFormDefinition(formDefinition, userFunctions) {
74
- const { transitions, actions, tables } = formDefinition;
75
- const states = formDefinition?.states?.map(state => state.name);
76
- const userStates = supportedStates(formDefinition, states, userFunctions);
77
- formDefinition.states = states?.filter(state => userStates?.includes(state)) ?? [];
78
- formDefinition.transitions = transitions?.map((transition) => {
79
- const { name, source, destination } = transition;
80
- return { name, source, destination };
81
- }).filter(trns => userStates?.includes(trns.source) && userStates?.includes(trns.destination)) ?? [];
48
+ const { transitions, actions, tables, states = [] } = formDefinition;
49
+ formDefinition.states = states.map((item) => item.name);
50
+ formDefinition.transitions =
51
+ transitions
52
+ ?.map((trns) => ({
53
+ name: trns.name,
54
+ source: trns.source,
55
+ destination: trns.destination,
56
+ functions: trns.functions ?? [],
57
+ }))
58
+ .filter((trns) => {
59
+ const { functions: transitionFunctions = [] } = trns;
60
+ for (let index = 0; index < transitionFunctions.length; index++) {
61
+ if (!userFunctions?.includes(transitionFunctions[index])) {
62
+ return false;
63
+ }
64
+ }
65
+ return true;
66
+ }) ?? [];
82
67
  formDefinition.actions = removeUnsupportedActions(actions, userFunctions) ?? [];
83
68
  formDefinition.tables = removeUnsupportedTableActions(tables, userFunctions);
84
69
  return formDefinition;
package/lib/form.js CHANGED
@@ -23,15 +23,45 @@ const DEFAULT_RECORDS_PAGE = 10;
23
23
  const RESTRICTED_ATTRIBUTES = ['actions', 'fields', 'recordTables', 'cookiesToSet', 'immutableData', 'returnedFile'];
24
24
 
25
25
  const FIELD_ASSIGN_ATTRIBUTES = [
26
- 'defaultEditable', 'defaultValue', 'alignment', 'required', 'errorCode', 'errorMessage', 'errorType',
27
- 'tooltip', 'info', 'format', 'intrinsicErrorMessage', 'outputOnly', 'captureType', 'title', 'type',
28
- 'maxLength', 'maxValue', 'minLength', 'minValue', 'validateOnServer', 'serverAction', 'visibleLabel',
29
- 'options', 'editable', 'visible', 'placeholder',
26
+ 'defaultEditable',
27
+ 'defaultValue',
28
+ 'alignment',
29
+ 'required',
30
+ 'errorCode',
31
+ 'errorMessage',
32
+ 'errorType',
33
+ 'tooltip',
34
+ 'info',
35
+ 'format',
36
+ 'intrinsicErrorMessage',
37
+ 'outputOnly',
38
+ 'captureType',
39
+ 'title',
40
+ 'type',
41
+ 'maxLength',
42
+ 'maxValue',
43
+ 'minLength',
44
+ 'minValue',
45
+ 'validateOnServer',
46
+ 'serverAction',
47
+ 'visibleLabel',
48
+ 'options',
49
+ 'editable',
50
+ 'visible',
51
+ 'placeholder',
30
52
  ];
31
53
 
32
54
  const TABLE_CONSTRAINTS = [
33
- 'visible', 'currentPage', 'requestedPage', 'recordsPerPage', 'sortingColumn', 'sortingDirection',
34
- 'totalRecordsNumber', 'recordsNumber', 'currentFilter', 'tableRecords',
55
+ 'visible',
56
+ 'currentPage',
57
+ 'requestedPage',
58
+ 'recordsPerPage',
59
+ 'sortingColumn',
60
+ 'sortingDirection',
61
+ 'totalRecordsNumber',
62
+ 'recordsNumber',
63
+ 'currentFilter',
64
+ 'tableRecords',
35
65
  ];
36
66
 
37
67
  const SESSION_ATTRIBUTES = {
@@ -90,23 +120,41 @@ class Form {
90
120
  this.onAction(TABLE_GET_DATA, () => this.executeTablePopulate());
91
121
  }
92
122
 
93
- // eslint-disable-next-line class-methods-use-this
94
- startOperation() { }
95
- // eslint-disable-next-line class-methods-use-this
96
- getData() { }
123
+ startOperation() {}
124
+
125
+ getData() {}
97
126
  async start() {
98
127
  const customizeDef = await this.startOperation();
99
- if (customizeDef) { return customizeDef; }
128
+ if (customizeDef) {
129
+ return customizeDef;
130
+ }
100
131
  return this.getData();
101
132
  }
102
133
 
103
- setCookie(name, value) { this._responseData.cookiesToSet.push({ [name]: value }); }
104
- getSessionAttribute(name) { return this._session?.[name] ?? null; }
105
- sessionDetailAttribute(name) { return this._sessionDetail?.[name] ?? null; }
134
+ setCookie(name, value) {
135
+ this._responseData.cookiesToSet.push({ [name]: value });
136
+ }
137
+
138
+ getSessionAttribute(name) {
139
+ return this._session?.[name] ?? null;
140
+ }
141
+
142
+ sessionDetailAttribute(name) {
143
+ return this._sessionDetail?.[name] ?? null;
144
+ }
145
+
146
+ addExtraInfo(name, value) {
147
+ this._responseData.extraInfo[name] = { value };
148
+ }
149
+
150
+ getExtraInfo(name) {
151
+ return this._responseData.extraInfo[name]?.value ?? null;
152
+ }
153
+
154
+ getAttribute(name) {
155
+ return this._responseData[name] ?? null;
156
+ }
106
157
 
107
- addExtraInfo(name, value) { this._responseData.extraInfo[name] = { value }; }
108
- getExtraInfo(name) { return this._responseData.extraInfo[name]?.value ?? null; }
109
- getAttribute(name) { return this._responseData[name] ?? null; }
110
158
  setAttribute(name, value) {
111
159
  if (!RESTRICTED_ATTRIBUTES.includes(name)) {
112
160
  this._responseData[name] = value;
@@ -115,6 +163,7 @@ class Form {
115
163
 
116
164
  setFormRequestAttributes(formCode, state, formSubject, actionCode, actionSubject, requestVersion) {
117
165
  Object.assign(this._requestData, { formCode, state, formSubject, actionCode, actionSubject, requestVersion });
166
+ this.state = state;
118
167
  }
119
168
 
120
169
  setImmutableElement(name, value, inputSignature = null) {
@@ -137,50 +186,136 @@ class Form {
137
186
  const checkSignature = crypto.createHmac('sha256', signatureKey).update(content).digest('hex');
138
187
  let requiredData = value;
139
188
  try {
140
- requiredData = (typeof value === 'object') ? JSON.parse(JSON.stringify(value)) : value;
189
+ requiredData = typeof value === 'object' ? JSON.parse(JSON.stringify(value)) : value;
141
190
  } catch (e) {
142
191
  requiredData = value;
143
192
  }
144
- return (signature === checkSignature) ? requiredData : null;
145
- }
146
-
147
- get requestVersion() { return this._requestData.requestVersion; }
148
- get actionSubject() { return this._responseData.actionSubject ?? this._requestData.actionSubject; }
149
- set actionSubject(actionSubject) { this._responseData.actionSubject = actionSubject; }
150
- get formSubject() { return this._responseData.formSubject ?? this._requestData.formSubject; }
151
- set formSubject(formSubject) { this._responseData.formSubject = formSubject; }
152
- getSubject() { return this.formSubject; }
153
- getformSubject() { return this.formSubject; }
154
-
155
- get state() { return this._responseData.state ?? this._requestData.state; }
156
- set state(newState) { this._responseData.state = newState; }
157
- get currentState() { return this.state; }
158
- set currentState(state) { this.state = state; }
159
- get mode() { return this.state; }
160
- set mode(state) { this.state = state; }
161
- get currentMode() { return this.state; }
162
- set currentMode(state) { this.state = state; }
163
-
164
- get formCode() { return this._formDefinition.form.formCode; }
165
- get requireSession() { return this._formDefinition.form.requireSession ?? false; }
166
- get globalFunctions() { return this._formDefinition?.bussinesFunctionsRequired ?? []; }
167
- get responseData() { return this._responseData; }
168
- set returnedFile(fileContent) { this._responseData.returnedFile = fileContent; }
169
- get requestRef() { return this._requestRef; }
170
- get requestContext() { return this._requestContext; }
171
- get sessionCode() { return this.getSessionAttribute(SESSION_ATTRIBUTES.sessionCode); }
172
- get profileCode() { return this.getSessionAttribute(SESSION_ATTRIBUTES.profileCode); }
173
- get sessionDetail() { return this._sessionDetail; }
174
- set error(errorObject) { this._errorObject = errorObject; }
175
- get error() { return this._errorObject; }
193
+ return signature === checkSignature ? requiredData : null;
194
+ }
195
+
196
+ get requestVersion() {
197
+ return this._requestData.requestVersion;
198
+ }
199
+
200
+ get actionSubject() {
201
+ return this._responseData.actionSubject ?? this._requestData.actionSubject;
202
+ }
203
+
204
+ set actionSubject(actionSubject) {
205
+ this._responseData.actionSubject = actionSubject;
206
+ }
207
+
208
+ get formSubject() {
209
+ return this._responseData.formSubject ?? this._requestData.formSubject;
210
+ }
211
+
212
+ set formSubject(formSubject) {
213
+ this._responseData.formSubject = formSubject;
214
+ }
215
+
216
+ getSubject() {
217
+ return this.formSubject;
218
+ }
219
+
220
+ getformSubject() {
221
+ return this.formSubject;
222
+ }
223
+
224
+ get state() {
225
+ return this._responseData.state ?? this._requestData.state;
226
+ }
227
+
228
+ set state(newState) {
229
+ this._responseData.state = newState;
230
+ }
231
+
232
+ get currentState() {
233
+ return this.state;
234
+ }
235
+
236
+ set currentState(state) {
237
+ this.state = state;
238
+ }
239
+
240
+ get mode() {
241
+ return this.state;
242
+ }
243
+
244
+ set mode(state) {
245
+ this.state = state;
246
+ }
247
+
248
+ get currentMode() {
249
+ return this.state;
250
+ }
251
+
252
+ set currentMode(state) {
253
+ this.state = state;
254
+ }
255
+
256
+ get formCode() {
257
+ return this._formDefinition.form.formCode;
258
+ }
259
+
260
+ get requireSession() {
261
+ return this._formDefinition.form.requireSession ?? false;
262
+ }
263
+
264
+ get globalFunctions() {
265
+ return this._formDefinition?.bussinesFunctionsRequired ?? [];
266
+ }
267
+
268
+ get responseData() {
269
+ return this._responseData;
270
+ }
271
+
272
+ set returnedFile(fileContent) {
273
+ this._responseData.returnedFile = fileContent;
274
+ }
275
+
276
+ get requestRef() {
277
+ return this._requestRef;
278
+ }
279
+
280
+ get requestContext() {
281
+ return this._requestContext;
282
+ }
283
+
284
+ get sessionCode() {
285
+ return this.getSessionAttribute(SESSION_ATTRIBUTES.sessionCode);
286
+ }
287
+
288
+ get profileCode() {
289
+ return this.getSessionAttribute(SESSION_ATTRIBUTES.profileCode);
290
+ }
291
+
292
+ get sessionDetail() {
293
+ return this._sessionDetail;
294
+ }
295
+
296
+ set error(errorObject) {
297
+ this._errorObject = errorObject;
298
+ }
299
+
300
+ get error() {
301
+ return this._errorObject;
302
+ }
176
303
 
177
304
  getExportData() {
178
305
  return exportExchange(this);
179
306
  }
180
307
 
181
- supportState(state) { return this._formDefinition.states.findIndex(st => st.name === state) >= 0; }
182
- supportMode(state) { return this.supportState(state); }
183
- getStates() { return this._formDefinition.states.map(stateDef => stateDef.name); }
308
+ supportState(state) {
309
+ return this._formDefinition.states.findIndex((st) => st.name === state) >= 0;
310
+ }
311
+
312
+ supportMode(state) {
313
+ return this.supportState(state);
314
+ }
315
+
316
+ getStates() {
317
+ return this._formDefinition.states.map((stateDef) => stateDef.name);
318
+ }
184
319
 
185
320
  changeState(newState) {
186
321
  if (!newState || !this.supportState(newState)) {
@@ -188,49 +323,70 @@ class Form {
188
323
  }
189
324
  if (!this.state) {
190
325
  this.state = newState;
191
- this.responseData.currentMode = newState;
192
326
  } else {
193
- const transitionToChange = this._formDefinition.transitions
194
- .find(trns => trns.source === this.state && trns.destination === newState);
327
+ const transitionToChange = this._formDefinition.transitions.find(
328
+ (trns) => trns.source === this.state && trns.destination === newState,
329
+ );
195
330
  if (transitionToChange) {
196
331
  this.state = newState;
197
- this.responseData.currentMode = newState;
198
332
  }
199
333
  }
200
- return (this.state === newState);
334
+ return this.state === newState;
201
335
  }
202
336
 
203
337
  /**
204
338
  * @deprecated Use changeState
205
339
  */
206
- changeFormMode(newState) { return this.changeState(newState); }
340
+ changeFormMode(newState) {
341
+ return this.changeState(newState);
342
+ }
207
343
 
208
- getActionDefinition(code) { return this._formDefinition?.actions?.find(act => act.actionCode === code) ?? null; }
209
- getAction(code) { return this._responseData?.actions?.find(act => act.actionCode === code) ?? null; }
210
- showAction(code) { this.setActionAttribute(code, VISIBLE, true); }
211
- hideAction(code) { this.setActionAttribute(code, VISIBLE, false); }
212
- enableAction(code) { this.setActionAttribute(code, DISABLED, false); }
213
- disableAction(code) { this.setActionAttribute(code, DISABLED, true); }
214
- onAction(code, callback) { this._formActions[code] = callback; }
344
+ getActionDefinition(code) {
345
+ return this._formDefinition?.actions?.find((act) => act.actionCode === code) ?? null;
346
+ }
347
+
348
+ getAction(code) {
349
+ return this._responseData?.actions?.find((act) => act.actionCode === code) ?? null;
350
+ }
351
+
352
+ showAction(code) {
353
+ this.setActionAttribute(code, VISIBLE, true);
354
+ }
355
+
356
+ hideAction(code) {
357
+ this.setActionAttribute(code, VISIBLE, false);
358
+ }
359
+
360
+ enableAction(code) {
361
+ this.setActionAttribute(code, DISABLED, false);
362
+ }
363
+
364
+ disableAction(code) {
365
+ this.setActionAttribute(code, DISABLED, true);
366
+ }
367
+
368
+ onAction(code, callback) {
369
+ this._formActions[code] = callback;
370
+ }
215
371
 
216
372
  showActions(actionArray) {
217
- const actionNames = (Array.isArray(actionArray)) ? actionArray : [actionArray];
218
- actionNames.forEach(code => this.showAction(code));
373
+ const actionNames = Array.isArray(actionArray) ? actionArray : [actionArray];
374
+ actionNames.forEach((code) => this.showAction(code));
219
375
  }
220
376
 
221
377
  hideActions(actionArray) {
222
- const actionNames = (Array.isArray(actionArray)) ? actionArray : [actionArray];
223
- actionNames.forEach(code => this.hideAction(code));
378
+ const actionNames = Array.isArray(actionArray) ? actionArray : [actionArray];
379
+ actionNames.forEach((code) => this.hideAction(code));
224
380
  }
225
381
 
226
382
  enableActions(actionArray) {
227
- const actionNames = (Array.isArray(actionArray)) ? actionArray : [actionArray];
228
- actionNames.forEach(code => this.enableAction(code));
383
+ const actionNames = Array.isArray(actionArray) ? actionArray : [actionArray];
384
+ actionNames.forEach((code) => this.enableAction(code));
229
385
  }
230
386
 
231
387
  disableActions(actionArray) {
232
- const actionNames = (Array.isArray(actionArray)) ? actionArray : [actionArray];
233
- actionNames.forEach(code => this.disableAction(code));
388
+ const actionNames = Array.isArray(actionArray) ? actionArray : [actionArray];
389
+ actionNames.forEach((code) => this.disableAction(code));
234
390
  }
235
391
 
236
392
  addInputField(fieldObj) {
@@ -239,20 +395,26 @@ class Form {
239
395
  }
240
396
 
241
397
  addTableRequest(tableRequest) {
242
- const {
243
- tableCode, visible, currentPage, requestedPage, currentFilter,
244
- recordsPerPage, sortingColumn, sortingDirection,
245
- } = tableRequest;
398
+ const { tableCode, visible, currentPage, requestedPage, currentFilter, recordsPerPage, sortingColumn, sortingDirection } =
399
+ tableRequest;
246
400
  this._requestData.formData.tables[tableCode] = tableRequest;
247
401
  const constraints = {
248
- visible, currentPage, requestedPage, recordsPerPage, sortingColumn, sortingDirection, currentFilter,
402
+ visible,
403
+ currentPage,
404
+ requestedPage,
405
+ recordsPerPage,
406
+ sortingColumn,
407
+ sortingDirection,
408
+ currentFilter,
249
409
  };
250
410
  this.setTableConstraints(tableCode, constraints);
251
411
  }
252
412
 
253
413
  touchField(code) {
254
414
  const actuallyAdded = this._responseData.fields[code];
255
- if (actuallyAdded) { return actuallyAdded; }
415
+ if (actuallyAdded) {
416
+ return actuallyAdded;
417
+ }
256
418
  const inputField = this._requestData.formData.fields[code];
257
419
  if (inputField) {
258
420
  this._responseData.fields[code] = inputField;
@@ -273,23 +435,59 @@ class Form {
273
435
 
274
436
  setFieldAttribute(fieldCode, attr, value) {
275
437
  const fieldObject = this.getField(fieldCode);
276
- if (fieldObject) { fieldObject[attr] = value; }
438
+ if (fieldObject) {
439
+ fieldObject[attr] = value;
440
+ }
277
441
  }
278
442
 
279
- getField(code) { return this.touchField(code); }
280
- setFieldValue(code, value) { this.setFieldAttribute(code, FIELDVALUE, value); }
281
- setFieldInfo(code, info) { this.setFieldAttribute(code, INFO, info); }
282
- showField(code) { this.setFieldAttribute(code, VISIBLE, true); }
283
- hideField(code) { this.setFieldAttribute(code, VISIBLE, false); }
284
- enableField(code) { this.setFieldAttribute(code, EDITABLE, true); }
285
- disableField(code) { this.setFieldAttribute(code, EDITABLE, false); }
286
- getFieldValue(code) { return this.getField(code)?.fieldValue ?? null; }
287
- demandField(code) { this.setFieldAttribute(code, REQUIRED, true); }
288
- giveUpField(code) { this.setFieldAttribute(code, REQUIRED, false); }
289
- onFieldValidation(code, callback) { this._fieldValidations[code] = callback; }
443
+ getField(code) {
444
+ return this.touchField(code);
445
+ }
446
+
447
+ setFieldValue(code, value) {
448
+ this.setFieldAttribute(code, FIELDVALUE, value);
449
+ }
450
+
451
+ setFieldInfo(code, info) {
452
+ this.setFieldAttribute(code, INFO, info);
453
+ }
454
+
455
+ showField(code) {
456
+ this.setFieldAttribute(code, VISIBLE, true);
457
+ }
458
+
459
+ hideField(code) {
460
+ this.setFieldAttribute(code, VISIBLE, false);
461
+ }
462
+
463
+ enableField(code) {
464
+ this.setFieldAttribute(code, EDITABLE, true);
465
+ }
466
+
467
+ disableField(code) {
468
+ this.setFieldAttribute(code, EDITABLE, false);
469
+ }
470
+
471
+ getFieldValue(code) {
472
+ return this.getField(code)?.fieldValue ?? null;
473
+ }
474
+
475
+ demandField(code) {
476
+ this.setFieldAttribute(code, REQUIRED, true);
477
+ }
478
+
479
+ giveUpField(code) {
480
+ this.setFieldAttribute(code, REQUIRED, false);
481
+ }
482
+
483
+ onFieldValidation(code, callback) {
484
+ this._fieldValidations[code] = callback;
485
+ }
290
486
 
291
487
  onFieldsValidation(fields, callback) {
292
- if (!Array.isArray(fields) || fields?.length === 0 || !callback) { return; }
488
+ if (!Array.isArray(fields) || fields?.length === 0 || !callback) {
489
+ return;
490
+ }
293
491
  fields?.forEach((code) => {
294
492
  this.onFieldValidation(code, callback);
295
493
  });
@@ -303,14 +501,15 @@ class Form {
303
501
 
304
502
  getFieldNames() {
305
503
  const names = new Set();
306
- Object.keys(this._requestData.formData.fields).forEach(name => names.add(name));
307
- Object.keys(this._responseData.fields).forEach(name => names.add(name));
504
+ Object.keys(this._requestData.formData.fields).forEach((name) => names.add(name));
505
+ Object.keys(this._responseData.fields).forEach((name) => names.add(name));
308
506
  return [...names];
309
507
  }
310
508
 
311
- // eslint-disable-next-line class-methods-use-this
312
509
  applyProcessToFieldSet(callback, fieldArray) {
313
- if (!fieldArray || !Array.isArray(fieldArray) || fieldArray?.length === 0 || !callback) { return; }
510
+ if (!fieldArray || !Array.isArray(fieldArray) || fieldArray?.length === 0 || !callback) {
511
+ return;
512
+ }
314
513
  for (let index = 0; index < fieldArray.length; index++) {
315
514
  callback(fieldArray[index]);
316
515
  }
@@ -318,28 +517,28 @@ class Form {
318
517
 
319
518
  cleanFields(fieldArray) {
320
519
  // return this.applyProcessToFieldSet(code => this.setFieldValue(code, ''), fieldArray);
321
- const codes = (Array.isArray(fieldArray)) ? fieldArray : [fieldArray];
322
- codes.forEach(code => this.setFieldValue(code, ''));
520
+ const codes = Array.isArray(fieldArray) ? fieldArray : [fieldArray];
521
+ codes.forEach((code) => this.setFieldValue(code, ''));
323
522
  }
324
523
 
325
524
  enableFields(fieldArray) {
326
- const codes = (Array.isArray(fieldArray)) ? fieldArray : [fieldArray];
327
- codes.forEach(code => this.enableField(code));
525
+ const codes = Array.isArray(fieldArray) ? fieldArray : [fieldArray];
526
+ codes.forEach((code) => this.enableField(code));
328
527
  }
329
528
 
330
529
  disableFields(fieldArray) {
331
- const codes = (Array.isArray(fieldArray)) ? fieldArray : [fieldArray];
332
- codes.forEach(code => this.disableField(code));
530
+ const codes = Array.isArray(fieldArray) ? fieldArray : [fieldArray];
531
+ codes.forEach((code) => this.disableField(code));
333
532
  }
334
533
 
335
534
  showFields(fieldArray) {
336
- const codes = (Array.isArray(fieldArray)) ? fieldArray : [fieldArray];
337
- codes.forEach(code => this.showField(code));
535
+ const codes = Array.isArray(fieldArray) ? fieldArray : [fieldArray];
536
+ codes.forEach((code) => this.showField(code));
338
537
  }
339
538
 
340
539
  hideFields(fieldArray) {
341
- const codes = (Array.isArray(fieldArray)) ? fieldArray : [fieldArray];
342
- codes.forEach(code => this.hideField(code));
540
+ const codes = Array.isArray(fieldArray) ? fieldArray : [fieldArray];
541
+ codes.forEach((code) => this.hideField(code));
343
542
  }
344
543
 
345
544
  showTable(code) {
@@ -357,21 +556,35 @@ class Form {
357
556
  }
358
557
 
359
558
  showTables(tableArray) {
360
- const codes = (Array.isArray(tableArray)) ? tableArray : [tableArray];
361
- codes.forEach(code => this.showTable(code));
559
+ const codes = Array.isArray(tableArray) ? tableArray : [tableArray];
560
+ codes.forEach((code) => this.showTable(code));
362
561
  }
363
562
 
364
563
  hideTables(tableArray) {
365
- const codes = (Array.isArray(tableArray)) ? tableArray : [tableArray];
366
- codes.forEach(code => this.hideTable(code));
564
+ const codes = Array.isArray(tableArray) ? tableArray : [tableArray];
565
+ codes.forEach((code) => this.hideTable(code));
566
+ }
567
+
568
+ getTableDefinition(code) {
569
+ return this._formDefinition?.tables.find((tbl) => tbl.tableCode === code) ?? null;
570
+ }
571
+
572
+ getTableConstraints(tableCode) {
573
+ return this._requestData.formData.tables[tableCode];
574
+ }
575
+
576
+ onTableRowSelection(code, callback) {
577
+ this.onTableAction(code, ROWSELECTION, callback);
578
+ }
579
+
580
+ onTablePopulate(code, callback) {
581
+ this._tablePopulate[code] = callback;
367
582
  }
368
583
 
369
- getTableDefinition(code) { return this._formDefinition?.tables.find(tbl => tbl.tableCode === code) ?? null; }
370
- getTableConstraints(tableCode) { return this._requestData.formData.tables[tableCode]; }
371
- onTableRowSelection(code, callback) { this.onTableAction(code, ROWSELECTION, callback); }
372
- onTablePopulate(code, callback) { this._tablePopulate[code] = callback; }
373
584
  onTableAction(tableCode, actionCode, callback) {
374
- if (!this._tableActions[tableCode]) { this._tableActions[tableCode] = {}; }
585
+ if (!this._tableActions[tableCode]) {
586
+ this._tableActions[tableCode] = {};
587
+ }
375
588
  this._tableActions[tableCode][actionCode] = callback;
376
589
  }
377
590
 
@@ -396,7 +609,9 @@ class Form {
396
609
 
397
610
  setTableConstraints(tableCode, constraints) {
398
611
  const responseTable = this.getResponseTable(tableCode);
399
- if (!responseTable || !constraints) { return; }
612
+ if (!responseTable || !constraints) {
613
+ return;
614
+ }
400
615
  Object.keys(constraints)?.forEach((constraint) => {
401
616
  switch (constraint) {
402
617
  case 'visible':
@@ -430,22 +645,28 @@ class Form {
430
645
  const generalFunctions = this.globalFunctions;
431
646
  for (let index = 0; index < generalFunctions.length; index++) {
432
647
  const functionRequired = generalFunctions[index];
433
- const locatedFunction = this._enabledFunctions.find(fnc => fnc.functionName === functionRequired.functionName);
434
- if (!locatedFunction) { return false; }
648
+ const locatedFunction = this._enabledFunctions.find((fnc) => fnc.functionName === functionRequired.functionName);
649
+ if (!locatedFunction) {
650
+ return false;
651
+ }
435
652
  }
436
653
  const actionDefinition = this.getActionDefinition(actionCode);
437
654
  const actionFunctions = actionDefinition?.bussinesFunctionsRequired?.split(',') ?? [];
438
655
  for (let index = 0; index < actionFunctions?.length; index++) {
439
656
  const functionRequired = actionFunctions[index];
440
- const locatedFunction = this._enabledFunctions.find(fnc => fnc.functionName === functionRequired);
441
- if (!locatedFunction) { return false; }
657
+ const locatedFunction = this._enabledFunctions.find((fnc) => fnc.functionName === functionRequired);
658
+ if (!locatedFunction) {
659
+ return false;
660
+ }
442
661
  }
443
662
  return true;
444
663
  }
445
664
 
446
665
  setActionAttribute(actionCode, attributeId, value) {
447
666
  const actionDefinition = this.getActionDefinition(actionCode);
448
- if (!actionDefinition) { return null; }
667
+ if (!actionDefinition) {
668
+ return null;
669
+ }
449
670
  const actionObject = this.getAction(actionCode);
450
671
  if (!actionObject) {
451
672
  this._responseData.actions.push({ actionCode: actionDefinition.actionCode, [attributeId]: value });
@@ -474,9 +695,11 @@ class Form {
474
695
 
475
696
  setFieldOptions(code, options, idField, valueField, saparator = '-') {
476
697
  const fieldObject = this.getField(code);
477
- if (!fieldObject) { return; }
698
+ if (!fieldObject) {
699
+ return;
700
+ }
478
701
  fieldObject.fieldOptions = [];
479
- const numSeparators = (Array.isArray(valueField)) ? (valueField.length - 1) : 0;
702
+ const numSeparators = Array.isArray(valueField) ? valueField.length - 1 : 0;
480
703
  for (let i = 0; i < options?.length; i++) {
481
704
  const optionObj = options[i];
482
705
  const fieldOptionId = optionObj?.[idField];
@@ -484,14 +707,12 @@ class Form {
484
707
  if (Array.isArray(valueField)) {
485
708
  for (let index = 0; index < valueField.length; index++) {
486
709
  const textPart = valueField[index];
487
- fieldOptionValue += (index < numSeparators)
488
- ? `${optionObj?.[textPart]} ${saparator} ` : optionObj?.[textPart];
710
+ fieldOptionValue += index < numSeparators ? `${optionObj?.[textPart]} ${saparator} ` : optionObj?.[textPart];
489
711
  }
490
712
  } else {
491
713
  fieldOptionValue = optionObj?.[valueField];
492
714
  }
493
- if (fieldOptionId !== undefined && fieldOptionId !== null
494
- && fieldOptionValue !== undefined && fieldOptionValue !== null) {
715
+ if (fieldOptionId !== undefined && fieldOptionId !== null && fieldOptionValue !== undefined && fieldOptionValue !== null) {
495
716
  fieldObject.fieldOptions.push({ fieldOptionId, fieldOptionValue });
496
717
  }
497
718
  }
@@ -557,8 +778,14 @@ class Form {
557
778
  return null;
558
779
  }
559
780
  const {
560
- visible = true, currentPage = 1, requestedPage = 1, totalRecordsNumber = 0, recordsNumber = 0,
561
- recordsPerPage = 10, sortingColumn = null, sortingDirection = null,
781
+ visible = true,
782
+ currentPage = 1,
783
+ requestedPage = 1,
784
+ totalRecordsNumber = 0,
785
+ recordsNumber = 0,
786
+ recordsPerPage = 10,
787
+ sortingColumn = null,
788
+ sortingDirection = null,
562
789
  } = tableDefinition?.constraints ?? {};
563
790
  responseTable = {
564
791
  tableCode,
@@ -578,7 +805,9 @@ class Form {
578
805
 
579
806
  getResponseTableAction(tableCode, actionCode) {
580
807
  const responseTable = this.getResponseTable(tableCode);
581
- if (!responseTable) { return null; }
808
+ if (!responseTable) {
809
+ return null;
810
+ }
582
811
  if (!responseTable?.actions) {
583
812
  responseTable.actions = { [actionCode]: {} };
584
813
  }
@@ -587,7 +816,9 @@ class Form {
587
816
 
588
817
  getResponseTableField(tableCode, fieldCode) {
589
818
  const responseTable = this.getResponseTable(tableCode);
590
- if (!responseTable) { return null; }
819
+ if (!responseTable) {
820
+ return null;
821
+ }
591
822
  if (!responseTable?.fields) {
592
823
  responseTable.fields = { [fieldCode]: {} };
593
824
  }
@@ -666,8 +897,8 @@ class Form {
666
897
  if (!tableAction.showOnStates) {
667
898
  tableAction.showOnStates = [];
668
899
  }
669
- const currentlyVisible = tableAction.showOnStates.findIndex(item => item === state);
670
- const correntlyHidden = tableAction.hideOnStates?.findIndex(item => item === state);
900
+ const currentlyVisible = tableAction.showOnStates.findIndex((item) => item === state);
901
+ const correntlyHidden = tableAction.hideOnStates?.findIndex((item) => item === state);
671
902
  if (currentlyVisible < 0) {
672
903
  tableAction.showOnStates.push(state);
673
904
  }
@@ -686,8 +917,8 @@ class Form {
686
917
  if (!tableAction.hideOnStates) {
687
918
  tableAction.hideOnStates = [];
688
919
  }
689
- const currentlyVisible = tableAction.showOnStates.findIndex(item => item === state);
690
- const correntlyHidden = tableAction.hideOnStates?.findIndex(item => item === state);
920
+ const currentlyVisible = tableAction.showOnStates.findIndex((item) => item === state);
921
+ const correntlyHidden = tableAction.hideOnStates?.findIndex((item) => item === state);
691
922
  if (correntlyHidden < 0) {
692
923
  tableAction.hideOnStates.push(state);
693
924
  }
@@ -706,8 +937,8 @@ class Form {
706
937
  if (!tableAction.enableOnStates) {
707
938
  tableAction.enableOnStates = [];
708
939
  }
709
- const currentlyEnabled = tableAction.enableOnStates.findIndex(item => item === state);
710
- const correntlyDisabled = tableAction.disableOnStates?.findIndex(item => item === state);
940
+ const currentlyEnabled = tableAction.enableOnStates.findIndex((item) => item === state);
941
+ const correntlyDisabled = tableAction.disableOnStates?.findIndex((item) => item === state);
711
942
  if (currentlyEnabled < 0) {
712
943
  tableAction.enableOnStates.push(state);
713
944
  }
@@ -726,8 +957,8 @@ class Form {
726
957
  if (!tableAction.disableOnStates) {
727
958
  tableAction.disableOnStates = [];
728
959
  }
729
- const currentlyEnabled = tableAction.enableOnStates.findIndex(item => item === state);
730
- const correntlyDisabled = tableAction.disableOnStates?.findIndex(item => item === state);
960
+ const currentlyEnabled = tableAction.enableOnStates.findIndex((item) => item === state);
961
+ const correntlyDisabled = tableAction.disableOnStates?.findIndex((item) => item === state);
731
962
  if (correntlyDisabled < 0) {
732
963
  tableAction.disableOnStates.push(state);
733
964
  }
@@ -836,32 +1067,44 @@ class Form {
836
1067
  /**
837
1068
  * @deprecated Use onAction
838
1069
  */
839
- addActionMethod(code, callback) { return this.onAction(code, callback); }
1070
+ addActionMethod(code, callback) {
1071
+ return this.onAction(code, callback);
1072
+ }
840
1073
 
841
1074
  /**
842
- * @deprecated Use onFieldValidation
843
- */
844
- addFieldValidation(code, callback) { return this.onFieldValidation(code, callback); }
1075
+ * @deprecated Use onFieldValidation
1076
+ */
1077
+ addFieldValidation(code, callback) {
1078
+ return this.onFieldValidation(code, callback);
1079
+ }
845
1080
 
846
1081
  /**
847
- * @deprecated Use onFieldsValidation
848
- */
849
- addFieldsValidation(fields, callback) { return this.onFieldsValidation(fields, callback); }
1082
+ * @deprecated Use onFieldsValidation
1083
+ */
1084
+ addFieldsValidation(fields, callback) {
1085
+ return this.onFieldsValidation(fields, callback);
1086
+ }
850
1087
 
851
1088
  /**
852
1089
  * @deprecated Use onTableRowSelection
853
1090
  */
854
- addTableRowSelection(code, callback) { return this.onTableRowSelection(code, callback); }
1091
+ addTableRowSelection(code, callback) {
1092
+ return this.onTableRowSelection(code, callback);
1093
+ }
855
1094
 
856
1095
  /**
857
- * @deprecated Use onTablePopulate
858
- */
859
- addTablePopulate(code, callback) { return this.onTablePopulate(code, callback); }
1096
+ * @deprecated Use onTablePopulate
1097
+ */
1098
+ addTablePopulate(code, callback) {
1099
+ return this.onTablePopulate(code, callback);
1100
+ }
860
1101
 
861
1102
  /**
862
- * @deprecated Use onTableAction
863
- */
864
- addTableAction(tableCode, actionCode, callback) { return this.onTableAction(tableCode, actionCode, callback); }
1103
+ * @deprecated Use onTableAction
1104
+ */
1105
+ addTableAction(tableCode, actionCode, callback) {
1106
+ return this.onTableAction(tableCode, actionCode, callback);
1107
+ }
865
1108
  }
866
1109
 
867
1110
  module.exports = Form;
@@ -20,12 +20,17 @@ function importExchange(inputExchangeData, form) {
20
20
  form.addInputField(internalField);
21
21
  });
22
22
  formData?.tables?.forEach((inputTableRequest) => {
23
- const {
24
- tableCode, visible, currentPage, requestedPage,
25
- recordsPerPage, currentFilter, sortingColumn, sortingDirection,
26
- } = inputTableRequest;
23
+ const { tableCode, visible, currentPage, requestedPage, recordsPerPage, currentFilter, sortingColumn, sortingDirection } =
24
+ inputTableRequest;
27
25
  const tableRequest = {
28
- tableCode, visible, currentPage, requestedPage, recordsPerPage, currentFilter, sortingColumn, sortingDirection,
26
+ tableCode,
27
+ visible,
28
+ currentPage,
29
+ requestedPage,
30
+ recordsPerPage,
31
+ currentFilter,
32
+ sortingColumn,
33
+ sortingDirection,
29
34
  };
30
35
  form.addTableRequest(tableRequest);
31
36
  });
@@ -45,7 +50,7 @@ function exportExchange(form) {
45
50
  exchangeFormInfo.immutableData = formExportData.immutableData;
46
51
  exchangeFormInfo.returnedFile = formExportData.returnedFile;
47
52
  exchangeFormInfo.extraInfo = formExportData.extraInfo;
48
- exchangeFormInfo.currentMode = formExportData.currentMode;
53
+ exchangeFormInfo.currentMode = formExportData.state;
49
54
  exchangeFormInfo.fields = [];
50
55
  const fieldNames = Object.keys(formExportData.fields);
51
56
  for (let index = 0; index < fieldNames.length; index++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tuain-form-manager",
3
- "version": "1.4.21",
3
+ "version": "1.5.2",
4
4
  "description": "Component library to perform operations on Tuain Development Framework forms to interchange information on web or mobile applications based on the data interchange of abstract forms making trnasformation on the data upon actions required on both sides (front and back)",
5
5
  "main": "index.js",
6
6
  "scripts": {