tuain-form-manager 1.4.20 → 1.5.1

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
- /* eslint-disable global-require */
3
1
  const crypto = require('crypto');
4
2
  const path = require('path');
5
3
  const modErrs = require('./module-errors');
@@ -175,8 +173,6 @@ class FormManager {
175
173
  errorObj = this.errMgr.get(modErrs.formActionExec.sessionNotFound, message);
176
174
  return [errorObj, null];
177
175
  }
178
- console.log('Se requiere sesión y si se tiene, sessionDetail:...');
179
- console.log(sessionDetail);
180
176
  }
181
177
  const formCustomObject = new FormClass(this.logger, this.errMgr, requestContext, formDefinition, requestData);
182
178
  if (!formCustomObject) {
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;
@@ -137,50 +185,136 @@ class Form {
137
185
  const checkSignature = crypto.createHmac('sha256', signatureKey).update(content).digest('hex');
138
186
  let requiredData = value;
139
187
  try {
140
- requiredData = (typeof value === 'object') ? JSON.parse(JSON.stringify(value)) : value;
188
+ requiredData = typeof value === 'object' ? JSON.parse(JSON.stringify(value)) : value;
141
189
  } catch (e) {
142
190
  requiredData = value;
143
191
  }
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; }
192
+ return signature === checkSignature ? requiredData : null;
193
+ }
194
+
195
+ get requestVersion() {
196
+ return this._requestData.requestVersion;
197
+ }
198
+
199
+ get actionSubject() {
200
+ return this._responseData.actionSubject ?? this._requestData.actionSubject;
201
+ }
202
+
203
+ set actionSubject(actionSubject) {
204
+ this._responseData.actionSubject = actionSubject;
205
+ }
206
+
207
+ get formSubject() {
208
+ return this._responseData.formSubject ?? this._requestData.formSubject;
209
+ }
210
+
211
+ set formSubject(formSubject) {
212
+ this._responseData.formSubject = formSubject;
213
+ }
214
+
215
+ getSubject() {
216
+ return this.formSubject;
217
+ }
218
+
219
+ getformSubject() {
220
+ return this.formSubject;
221
+ }
222
+
223
+ get state() {
224
+ return this._responseData.state ?? this._requestData.state;
225
+ }
226
+
227
+ set state(newState) {
228
+ this._responseData.state = newState;
229
+ }
230
+
231
+ get currentState() {
232
+ return this.state;
233
+ }
234
+
235
+ set currentState(state) {
236
+ this.state = state;
237
+ }
238
+
239
+ get mode() {
240
+ return this.state;
241
+ }
242
+
243
+ set mode(state) {
244
+ this.state = state;
245
+ }
246
+
247
+ get currentMode() {
248
+ return this.state;
249
+ }
250
+
251
+ set currentMode(state) {
252
+ this.state = state;
253
+ }
254
+
255
+ get formCode() {
256
+ return this._formDefinition.form.formCode;
257
+ }
258
+
259
+ get requireSession() {
260
+ return this._formDefinition.form.requireSession ?? false;
261
+ }
262
+
263
+ get globalFunctions() {
264
+ return this._formDefinition?.bussinesFunctionsRequired ?? [];
265
+ }
266
+
267
+ get responseData() {
268
+ return this._responseData;
269
+ }
270
+
271
+ set returnedFile(fileContent) {
272
+ this._responseData.returnedFile = fileContent;
273
+ }
274
+
275
+ get requestRef() {
276
+ return this._requestRef;
277
+ }
278
+
279
+ get requestContext() {
280
+ return this._requestContext;
281
+ }
282
+
283
+ get sessionCode() {
284
+ return this.getSessionAttribute(SESSION_ATTRIBUTES.sessionCode);
285
+ }
286
+
287
+ get profileCode() {
288
+ return this.getSessionAttribute(SESSION_ATTRIBUTES.profileCode);
289
+ }
290
+
291
+ get sessionDetail() {
292
+ return this._sessionDetail;
293
+ }
294
+
295
+ set error(errorObject) {
296
+ this._errorObject = errorObject;
297
+ }
298
+
299
+ get error() {
300
+ return this._errorObject;
301
+ }
176
302
 
177
303
  getExportData() {
178
304
  return exportExchange(this);
179
305
  }
180
306
 
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); }
307
+ supportState(state) {
308
+ return this._formDefinition.states.findIndex((st) => st.name === state) >= 0;
309
+ }
310
+
311
+ supportMode(state) {
312
+ return this.supportState(state);
313
+ }
314
+
315
+ getStates() {
316
+ return this._formDefinition.states.map((stateDef) => stateDef.name);
317
+ }
184
318
 
185
319
  changeState(newState) {
186
320
  if (!newState || !this.supportState(newState)) {
@@ -188,49 +322,70 @@ class Form {
188
322
  }
189
323
  if (!this.state) {
190
324
  this.state = newState;
191
- this.responseData.currentMode = newState;
192
325
  } else {
193
- const transitionToChange = this._formDefinition.transitions
194
- .find(trns => trns.source === this.state && trns.destination === newState);
326
+ const transitionToChange = this._formDefinition.transitions.find(
327
+ (trns) => trns.source === this.state && trns.destination === newState,
328
+ );
195
329
  if (transitionToChange) {
196
330
  this.state = newState;
197
- this.responseData.currentMode = newState;
198
331
  }
199
332
  }
200
- return (this.state === newState);
333
+ return this.state === newState;
201
334
  }
202
335
 
203
336
  /**
204
337
  * @deprecated Use changeState
205
338
  */
206
- changeFormMode(newState) { return this.changeState(newState); }
339
+ changeFormMode(newState) {
340
+ return this.changeState(newState);
341
+ }
207
342
 
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; }
343
+ getActionDefinition(code) {
344
+ return this._formDefinition?.actions?.find((act) => act.actionCode === code) ?? null;
345
+ }
346
+
347
+ getAction(code) {
348
+ return this._responseData?.actions?.find((act) => act.actionCode === code) ?? null;
349
+ }
350
+
351
+ showAction(code) {
352
+ this.setActionAttribute(code, VISIBLE, true);
353
+ }
354
+
355
+ hideAction(code) {
356
+ this.setActionAttribute(code, VISIBLE, false);
357
+ }
358
+
359
+ enableAction(code) {
360
+ this.setActionAttribute(code, DISABLED, false);
361
+ }
362
+
363
+ disableAction(code) {
364
+ this.setActionAttribute(code, DISABLED, true);
365
+ }
366
+
367
+ onAction(code, callback) {
368
+ this._formActions[code] = callback;
369
+ }
215
370
 
216
371
  showActions(actionArray) {
217
- const actionNames = (Array.isArray(actionArray)) ? actionArray : [actionArray];
218
- actionNames.forEach(code => this.showAction(code));
372
+ const actionNames = Array.isArray(actionArray) ? actionArray : [actionArray];
373
+ actionNames.forEach((code) => this.showAction(code));
219
374
  }
220
375
 
221
376
  hideActions(actionArray) {
222
- const actionNames = (Array.isArray(actionArray)) ? actionArray : [actionArray];
223
- actionNames.forEach(code => this.hideAction(code));
377
+ const actionNames = Array.isArray(actionArray) ? actionArray : [actionArray];
378
+ actionNames.forEach((code) => this.hideAction(code));
224
379
  }
225
380
 
226
381
  enableActions(actionArray) {
227
- const actionNames = (Array.isArray(actionArray)) ? actionArray : [actionArray];
228
- actionNames.forEach(code => this.enableAction(code));
382
+ const actionNames = Array.isArray(actionArray) ? actionArray : [actionArray];
383
+ actionNames.forEach((code) => this.enableAction(code));
229
384
  }
230
385
 
231
386
  disableActions(actionArray) {
232
- const actionNames = (Array.isArray(actionArray)) ? actionArray : [actionArray];
233
- actionNames.forEach(code => this.disableAction(code));
387
+ const actionNames = Array.isArray(actionArray) ? actionArray : [actionArray];
388
+ actionNames.forEach((code) => this.disableAction(code));
234
389
  }
235
390
 
236
391
  addInputField(fieldObj) {
@@ -239,20 +394,26 @@ class Form {
239
394
  }
240
395
 
241
396
  addTableRequest(tableRequest) {
242
- const {
243
- tableCode, visible, currentPage, requestedPage, currentFilter,
244
- recordsPerPage, sortingColumn, sortingDirection,
245
- } = tableRequest;
397
+ const { tableCode, visible, currentPage, requestedPage, currentFilter, recordsPerPage, sortingColumn, sortingDirection } =
398
+ tableRequest;
246
399
  this._requestData.formData.tables[tableCode] = tableRequest;
247
400
  const constraints = {
248
- visible, currentPage, requestedPage, recordsPerPage, sortingColumn, sortingDirection, currentFilter,
401
+ visible,
402
+ currentPage,
403
+ requestedPage,
404
+ recordsPerPage,
405
+ sortingColumn,
406
+ sortingDirection,
407
+ currentFilter,
249
408
  };
250
409
  this.setTableConstraints(tableCode, constraints);
251
410
  }
252
411
 
253
412
  touchField(code) {
254
413
  const actuallyAdded = this._responseData.fields[code];
255
- if (actuallyAdded) { return actuallyAdded; }
414
+ if (actuallyAdded) {
415
+ return actuallyAdded;
416
+ }
256
417
  const inputField = this._requestData.formData.fields[code];
257
418
  if (inputField) {
258
419
  this._responseData.fields[code] = inputField;
@@ -273,23 +434,59 @@ class Form {
273
434
 
274
435
  setFieldAttribute(fieldCode, attr, value) {
275
436
  const fieldObject = this.getField(fieldCode);
276
- if (fieldObject) { fieldObject[attr] = value; }
437
+ if (fieldObject) {
438
+ fieldObject[attr] = value;
439
+ }
277
440
  }
278
441
 
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; }
442
+ getField(code) {
443
+ return this.touchField(code);
444
+ }
445
+
446
+ setFieldValue(code, value) {
447
+ this.setFieldAttribute(code, FIELDVALUE, value);
448
+ }
449
+
450
+ setFieldInfo(code, info) {
451
+ this.setFieldAttribute(code, INFO, info);
452
+ }
453
+
454
+ showField(code) {
455
+ this.setFieldAttribute(code, VISIBLE, true);
456
+ }
457
+
458
+ hideField(code) {
459
+ this.setFieldAttribute(code, VISIBLE, false);
460
+ }
461
+
462
+ enableField(code) {
463
+ this.setFieldAttribute(code, EDITABLE, true);
464
+ }
465
+
466
+ disableField(code) {
467
+ this.setFieldAttribute(code, EDITABLE, false);
468
+ }
469
+
470
+ getFieldValue(code) {
471
+ return this.getField(code)?.fieldValue ?? null;
472
+ }
473
+
474
+ demandField(code) {
475
+ this.setFieldAttribute(code, REQUIRED, true);
476
+ }
477
+
478
+ giveUpField(code) {
479
+ this.setFieldAttribute(code, REQUIRED, false);
480
+ }
481
+
482
+ onFieldValidation(code, callback) {
483
+ this._fieldValidations[code] = callback;
484
+ }
290
485
 
291
486
  onFieldsValidation(fields, callback) {
292
- if (!Array.isArray(fields) || fields?.length === 0 || !callback) { return; }
487
+ if (!Array.isArray(fields) || fields?.length === 0 || !callback) {
488
+ return;
489
+ }
293
490
  fields?.forEach((code) => {
294
491
  this.onFieldValidation(code, callback);
295
492
  });
@@ -303,14 +500,15 @@ class Form {
303
500
 
304
501
  getFieldNames() {
305
502
  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));
503
+ Object.keys(this._requestData.formData.fields).forEach((name) => names.add(name));
504
+ Object.keys(this._responseData.fields).forEach((name) => names.add(name));
308
505
  return [...names];
309
506
  }
310
507
 
311
- // eslint-disable-next-line class-methods-use-this
312
508
  applyProcessToFieldSet(callback, fieldArray) {
313
- if (!fieldArray || !Array.isArray(fieldArray) || fieldArray?.length === 0 || !callback) { return; }
509
+ if (!fieldArray || !Array.isArray(fieldArray) || fieldArray?.length === 0 || !callback) {
510
+ return;
511
+ }
314
512
  for (let index = 0; index < fieldArray.length; index++) {
315
513
  callback(fieldArray[index]);
316
514
  }
@@ -318,28 +516,28 @@ class Form {
318
516
 
319
517
  cleanFields(fieldArray) {
320
518
  // return this.applyProcessToFieldSet(code => this.setFieldValue(code, ''), fieldArray);
321
- const codes = (Array.isArray(fieldArray)) ? fieldArray : [fieldArray];
322
- codes.forEach(code => this.setFieldValue(code, ''));
519
+ const codes = Array.isArray(fieldArray) ? fieldArray : [fieldArray];
520
+ codes.forEach((code) => this.setFieldValue(code, ''));
323
521
  }
324
522
 
325
523
  enableFields(fieldArray) {
326
- const codes = (Array.isArray(fieldArray)) ? fieldArray : [fieldArray];
327
- codes.forEach(code => this.enableField(code));
524
+ const codes = Array.isArray(fieldArray) ? fieldArray : [fieldArray];
525
+ codes.forEach((code) => this.enableField(code));
328
526
  }
329
527
 
330
528
  disableFields(fieldArray) {
331
- const codes = (Array.isArray(fieldArray)) ? fieldArray : [fieldArray];
332
- codes.forEach(code => this.disableField(code));
529
+ const codes = Array.isArray(fieldArray) ? fieldArray : [fieldArray];
530
+ codes.forEach((code) => this.disableField(code));
333
531
  }
334
532
 
335
533
  showFields(fieldArray) {
336
- const codes = (Array.isArray(fieldArray)) ? fieldArray : [fieldArray];
337
- codes.forEach(code => this.showField(code));
534
+ const codes = Array.isArray(fieldArray) ? fieldArray : [fieldArray];
535
+ codes.forEach((code) => this.showField(code));
338
536
  }
339
537
 
340
538
  hideFields(fieldArray) {
341
- const codes = (Array.isArray(fieldArray)) ? fieldArray : [fieldArray];
342
- codes.forEach(code => this.hideField(code));
539
+ const codes = Array.isArray(fieldArray) ? fieldArray : [fieldArray];
540
+ codes.forEach((code) => this.hideField(code));
343
541
  }
344
542
 
345
543
  showTable(code) {
@@ -357,21 +555,35 @@ class Form {
357
555
  }
358
556
 
359
557
  showTables(tableArray) {
360
- const codes = (Array.isArray(tableArray)) ? tableArray : [tableArray];
361
- codes.forEach(code => this.showTable(code));
558
+ const codes = Array.isArray(tableArray) ? tableArray : [tableArray];
559
+ codes.forEach((code) => this.showTable(code));
362
560
  }
363
561
 
364
562
  hideTables(tableArray) {
365
- const codes = (Array.isArray(tableArray)) ? tableArray : [tableArray];
366
- codes.forEach(code => this.hideTable(code));
563
+ const codes = Array.isArray(tableArray) ? tableArray : [tableArray];
564
+ codes.forEach((code) => this.hideTable(code));
565
+ }
566
+
567
+ getTableDefinition(code) {
568
+ return this._formDefinition?.tables.find((tbl) => tbl.tableCode === code) ?? null;
569
+ }
570
+
571
+ getTableConstraints(tableCode) {
572
+ return this._requestData.formData.tables[tableCode];
573
+ }
574
+
575
+ onTableRowSelection(code, callback) {
576
+ this.onTableAction(code, ROWSELECTION, callback);
577
+ }
578
+
579
+ onTablePopulate(code, callback) {
580
+ this._tablePopulate[code] = callback;
367
581
  }
368
582
 
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
583
  onTableAction(tableCode, actionCode, callback) {
374
- if (!this._tableActions[tableCode]) { this._tableActions[tableCode] = {}; }
584
+ if (!this._tableActions[tableCode]) {
585
+ this._tableActions[tableCode] = {};
586
+ }
375
587
  this._tableActions[tableCode][actionCode] = callback;
376
588
  }
377
589
 
@@ -396,7 +608,9 @@ class Form {
396
608
 
397
609
  setTableConstraints(tableCode, constraints) {
398
610
  const responseTable = this.getResponseTable(tableCode);
399
- if (!responseTable || !constraints) { return; }
611
+ if (!responseTable || !constraints) {
612
+ return;
613
+ }
400
614
  Object.keys(constraints)?.forEach((constraint) => {
401
615
  switch (constraint) {
402
616
  case 'visible':
@@ -430,22 +644,28 @@ class Form {
430
644
  const generalFunctions = this.globalFunctions;
431
645
  for (let index = 0; index < generalFunctions.length; index++) {
432
646
  const functionRequired = generalFunctions[index];
433
- const locatedFunction = this._enabledFunctions.find(fnc => fnc.functionName === functionRequired.functionName);
434
- if (!locatedFunction) { return false; }
647
+ const locatedFunction = this._enabledFunctions.find((fnc) => fnc.functionName === functionRequired.functionName);
648
+ if (!locatedFunction) {
649
+ return false;
650
+ }
435
651
  }
436
652
  const actionDefinition = this.getActionDefinition(actionCode);
437
653
  const actionFunctions = actionDefinition?.bussinesFunctionsRequired?.split(',') ?? [];
438
654
  for (let index = 0; index < actionFunctions?.length; index++) {
439
655
  const functionRequired = actionFunctions[index];
440
- const locatedFunction = this._enabledFunctions.find(fnc => fnc.functionName === functionRequired);
441
- if (!locatedFunction) { return false; }
656
+ const locatedFunction = this._enabledFunctions.find((fnc) => fnc.functionName === functionRequired);
657
+ if (!locatedFunction) {
658
+ return false;
659
+ }
442
660
  }
443
661
  return true;
444
662
  }
445
663
 
446
664
  setActionAttribute(actionCode, attributeId, value) {
447
665
  const actionDefinition = this.getActionDefinition(actionCode);
448
- if (!actionDefinition) { return null; }
666
+ if (!actionDefinition) {
667
+ return null;
668
+ }
449
669
  const actionObject = this.getAction(actionCode);
450
670
  if (!actionObject) {
451
671
  this._responseData.actions.push({ actionCode: actionDefinition.actionCode, [attributeId]: value });
@@ -474,9 +694,11 @@ class Form {
474
694
 
475
695
  setFieldOptions(code, options, idField, valueField, saparator = '-') {
476
696
  const fieldObject = this.getField(code);
477
- if (!fieldObject) { return; }
697
+ if (!fieldObject) {
698
+ return;
699
+ }
478
700
  fieldObject.fieldOptions = [];
479
- const numSeparators = (Array.isArray(valueField)) ? (valueField.length - 1) : 0;
701
+ const numSeparators = Array.isArray(valueField) ? valueField.length - 1 : 0;
480
702
  for (let i = 0; i < options?.length; i++) {
481
703
  const optionObj = options[i];
482
704
  const fieldOptionId = optionObj?.[idField];
@@ -484,14 +706,12 @@ class Form {
484
706
  if (Array.isArray(valueField)) {
485
707
  for (let index = 0; index < valueField.length; index++) {
486
708
  const textPart = valueField[index];
487
- fieldOptionValue += (index < numSeparators)
488
- ? `${optionObj?.[textPart]} ${saparator} ` : optionObj?.[textPart];
709
+ fieldOptionValue += index < numSeparators ? `${optionObj?.[textPart]} ${saparator} ` : optionObj?.[textPart];
489
710
  }
490
711
  } else {
491
712
  fieldOptionValue = optionObj?.[valueField];
492
713
  }
493
- if (fieldOptionId !== undefined && fieldOptionId !== null
494
- && fieldOptionValue !== undefined && fieldOptionValue !== null) {
714
+ if (fieldOptionId !== undefined && fieldOptionId !== null && fieldOptionValue !== undefined && fieldOptionValue !== null) {
495
715
  fieldObject.fieldOptions.push({ fieldOptionId, fieldOptionValue });
496
716
  }
497
717
  }
@@ -557,8 +777,14 @@ class Form {
557
777
  return null;
558
778
  }
559
779
  const {
560
- visible = true, currentPage = 1, requestedPage = 1, totalRecordsNumber = 0, recordsNumber = 0,
561
- recordsPerPage = 10, sortingColumn = null, sortingDirection = null,
780
+ visible = true,
781
+ currentPage = 1,
782
+ requestedPage = 1,
783
+ totalRecordsNumber = 0,
784
+ recordsNumber = 0,
785
+ recordsPerPage = 10,
786
+ sortingColumn = null,
787
+ sortingDirection = null,
562
788
  } = tableDefinition?.constraints ?? {};
563
789
  responseTable = {
564
790
  tableCode,
@@ -578,7 +804,9 @@ class Form {
578
804
 
579
805
  getResponseTableAction(tableCode, actionCode) {
580
806
  const responseTable = this.getResponseTable(tableCode);
581
- if (!responseTable) { return null; }
807
+ if (!responseTable) {
808
+ return null;
809
+ }
582
810
  if (!responseTable?.actions) {
583
811
  responseTable.actions = { [actionCode]: {} };
584
812
  }
@@ -587,7 +815,9 @@ class Form {
587
815
 
588
816
  getResponseTableField(tableCode, fieldCode) {
589
817
  const responseTable = this.getResponseTable(tableCode);
590
- if (!responseTable) { return null; }
818
+ if (!responseTable) {
819
+ return null;
820
+ }
591
821
  if (!responseTable?.fields) {
592
822
  responseTable.fields = { [fieldCode]: {} };
593
823
  }
@@ -666,8 +896,8 @@ class Form {
666
896
  if (!tableAction.showOnStates) {
667
897
  tableAction.showOnStates = [];
668
898
  }
669
- const currentlyVisible = tableAction.showOnStates.findIndex(item => item === state);
670
- const correntlyHidden = tableAction.hideOnStates?.findIndex(item => item === state);
899
+ const currentlyVisible = tableAction.showOnStates.findIndex((item) => item === state);
900
+ const correntlyHidden = tableAction.hideOnStates?.findIndex((item) => item === state);
671
901
  if (currentlyVisible < 0) {
672
902
  tableAction.showOnStates.push(state);
673
903
  }
@@ -686,8 +916,8 @@ class Form {
686
916
  if (!tableAction.hideOnStates) {
687
917
  tableAction.hideOnStates = [];
688
918
  }
689
- const currentlyVisible = tableAction.showOnStates.findIndex(item => item === state);
690
- const correntlyHidden = tableAction.hideOnStates?.findIndex(item => item === state);
919
+ const currentlyVisible = tableAction.showOnStates.findIndex((item) => item === state);
920
+ const correntlyHidden = tableAction.hideOnStates?.findIndex((item) => item === state);
691
921
  if (correntlyHidden < 0) {
692
922
  tableAction.hideOnStates.push(state);
693
923
  }
@@ -706,8 +936,8 @@ class Form {
706
936
  if (!tableAction.enableOnStates) {
707
937
  tableAction.enableOnStates = [];
708
938
  }
709
- const currentlyEnabled = tableAction.enableOnStates.findIndex(item => item === state);
710
- const correntlyDisabled = tableAction.disableOnStates?.findIndex(item => item === state);
939
+ const currentlyEnabled = tableAction.enableOnStates.findIndex((item) => item === state);
940
+ const correntlyDisabled = tableAction.disableOnStates?.findIndex((item) => item === state);
711
941
  if (currentlyEnabled < 0) {
712
942
  tableAction.enableOnStates.push(state);
713
943
  }
@@ -726,8 +956,8 @@ class Form {
726
956
  if (!tableAction.disableOnStates) {
727
957
  tableAction.disableOnStates = [];
728
958
  }
729
- const currentlyEnabled = tableAction.enableOnStates.findIndex(item => item === state);
730
- const correntlyDisabled = tableAction.disableOnStates?.findIndex(item => item === state);
959
+ const currentlyEnabled = tableAction.enableOnStates.findIndex((item) => item === state);
960
+ const correntlyDisabled = tableAction.disableOnStates?.findIndex((item) => item === state);
731
961
  if (correntlyDisabled < 0) {
732
962
  tableAction.disableOnStates.push(state);
733
963
  }
@@ -836,32 +1066,44 @@ class Form {
836
1066
  /**
837
1067
  * @deprecated Use onAction
838
1068
  */
839
- addActionMethod(code, callback) { return this.onAction(code, callback); }
1069
+ addActionMethod(code, callback) {
1070
+ return this.onAction(code, callback);
1071
+ }
840
1072
 
841
1073
  /**
842
- * @deprecated Use onFieldValidation
843
- */
844
- addFieldValidation(code, callback) { return this.onFieldValidation(code, callback); }
1074
+ * @deprecated Use onFieldValidation
1075
+ */
1076
+ addFieldValidation(code, callback) {
1077
+ return this.onFieldValidation(code, callback);
1078
+ }
845
1079
 
846
1080
  /**
847
- * @deprecated Use onFieldsValidation
848
- */
849
- addFieldsValidation(fields, callback) { return this.onFieldsValidation(fields, callback); }
1081
+ * @deprecated Use onFieldsValidation
1082
+ */
1083
+ addFieldsValidation(fields, callback) {
1084
+ return this.onFieldsValidation(fields, callback);
1085
+ }
850
1086
 
851
1087
  /**
852
1088
  * @deprecated Use onTableRowSelection
853
1089
  */
854
- addTableRowSelection(code, callback) { return this.onTableRowSelection(code, callback); }
1090
+ addTableRowSelection(code, callback) {
1091
+ return this.onTableRowSelection(code, callback);
1092
+ }
855
1093
 
856
1094
  /**
857
- * @deprecated Use onTablePopulate
858
- */
859
- addTablePopulate(code, callback) { return this.onTablePopulate(code, callback); }
1095
+ * @deprecated Use onTablePopulate
1096
+ */
1097
+ addTablePopulate(code, callback) {
1098
+ return this.onTablePopulate(code, callback);
1099
+ }
860
1100
 
861
1101
  /**
862
- * @deprecated Use onTableAction
863
- */
864
- addTableAction(tableCode, actionCode, callback) { return this.onTableAction(tableCode, actionCode, callback); }
1102
+ * @deprecated Use onTableAction
1103
+ */
1104
+ addTableAction(tableCode, actionCode, callback) {
1105
+ return this.onTableAction(tableCode, actionCode, callback);
1106
+ }
865
1107
  }
866
1108
 
867
1109
  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.20",
3
+ "version": "1.5.1",
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": {