@sankhyalabs/ezui 1.1.7 → 1.1.11

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.
@@ -2750,8 +2750,8 @@ const NavigationBar = ({ dataUnit: du, buttonProps }) => {
2750
2750
  return h("div", { class: "col col--sd-12 align--right" },
2751
2751
  buttonProps.previousVisible ? h("ez-button", { title: "Registro anterior", mode: "icon", enabled: du.hasPrevious(), onClick: () => du.previous(), image: "/themes/default/images/icons/actions-sprite.svg#previous-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2752
2752
  buttonProps.nextVisible ? h("ez-button", { title: "Pr\u00F3ximo registro", mode: "icon", enabled: du.hasNext(), onClick: () => du.next(), image: "/themes/default/images/icons/actions-sprite.svg#next-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2753
- buttonProps.removeVisible ? h("ez-button", { title: "Remover " + du.unitLabel, mode: "icon", enabled: du.hasCurrentRecord(), onClick: () => removeHandler(du), image: "/themes/default/images/icons/actions-sprite.svg#minus-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2754
- buttonProps.addVisible ? h("ez-button", { label: "Criar " + du.unitLabel, onClick: () => du.insert(), class: "button--secondary margin-right--medium" }) : null,
2753
+ buttonProps.removeVisible ? h("ez-button", { label: "Remover", enabled: du.hasCurrentRecord(), onClick: () => removeHandler(du), image: "/themes/default/images/icons/actions-sprite.svg#minus-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2754
+ buttonProps.addVisible ? h("ez-button", { label: "Adicionar", onClick: () => du.insert(), class: "button--secondary margin-right--medium" }) : null,
2755
2755
  buttonProps.reloadVisible ? h("ez-button", { title: "Recarregar", mode: "icon", onClick: () => du.load(), image: "/themes/default/images/icons/actions-sprite.svg#rotate", class: "button--secondary margin-right--medium" }) : null,
2756
2756
  buttonProps.cancelVisible ? h("ez-button", { label: "Cancelar", enabled: du.hasChanges(), onClick: () => du.cancel(), class: "button--secondary margin-right--medium" }) : null,
2757
2757
  buttonProps.saveVisible ? h("ez-button", { label: "Salvar", enabled: du.hasChanges(), onClick: () => du.save(), class: "button--primary margin-right--medium" }) : null);
@@ -2911,7 +2911,7 @@ const FormSheet = ({ store, parentName, source, parentDataUnit, dataUnitBuilder
2911
2911
  const selectedTab = selectCurrentTab(store.getState(), parentName);
2912
2912
  const tabs = source.length > 1 ? source.map(form => h("ez-tab", { label: form.label, tabKey: form.name })) : null;
2913
2913
  const { subForms, items, name } = source[selectedTab];
2914
- const dataUnit = dataUnitBuilder(source[selectedTab].dataUnit);
2914
+ const dataUnit = dataUnitBuilder(source[selectedTab].dataUnit, parentDataUnit);
2915
2915
  source[selectedTab].dataUnit = dataUnit;
2916
2916
  const hasSubForms = subForms && subForms.length > 0;
2917
2917
  const changeTabHandler = (index) => {
@@ -2935,10 +2935,16 @@ const FormSheet = ({ store, parentName, source, parentDataUnit, dataUnitBuilder
2935
2935
  };
2936
2936
 
2937
2937
  class DataUnit {
2938
- constructor(name, unitLabel, cardinality = '1') {
2938
+ constructor(name, unitLabel, cardinality = '1', parentDU = null) {
2939
2939
  this.name = name;
2940
2940
  this.unitLabel = unitLabel;
2941
2941
  this.cardinality = cardinality;
2942
+ this._children = [];
2943
+ if (parentDU != null) {
2944
+ parentDU._children.push(this);
2945
+ this.parentDU = parentDU;
2946
+ this.parentDUName = parentDU.name;
2947
+ }
2942
2948
  }
2943
2949
  set store(store) {
2944
2950
  this._store = store;
@@ -2996,21 +3002,57 @@ class DataUnit {
2996
3002
  insert() {
2997
3003
  const insertionIndex = this.records.length;
2998
3004
  const newRecordIndex = selectNewRecordIndex(this._store.getState(), this.name);
2999
- this.records.push({ record__id: 'NEW_' + (newRecordIndex + 1) });
3005
+ const newRecord = { record__id: 'NEW_' + (newRecordIndex + 1) };
3006
+ this.bindToParent(newRecord);
3007
+ this.records.push(newRecord);
3000
3008
  this._store.dispatch(insertRecord$1(this.name, insertionIndex));
3001
3009
  }
3002
- getChangesToSave() {
3010
+ buildChange(r) {
3003
3011
  const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
3004
- const changesByRecord = Object.keys(duChanges).map(record__id => {
3005
- const record = { record__id };
3006
- const recordChanges = duChanges[record__id];
3007
- Object.keys(recordChanges).forEach(fieldName => { record[fieldName] = recordChanges[fieldName]; });
3008
- return record;
3012
+ let recordChanges;
3013
+ if (duChanges) {
3014
+ recordChanges = duChanges[r.record__id];
3015
+ }
3016
+ let subChanges = [];
3017
+ this._children.forEach(duChild => {
3018
+ subChanges = subChanges.concat(duChild.getSubChanges(r.record__id));
3009
3019
  });
3010
- return [{
3011
- dataUnit: this.name,
3012
- records: changesByRecord
3013
- }];
3020
+ if (recordChanges || subChanges.length > 0) {
3021
+ const change = {
3022
+ "__data__unit": this.name,
3023
+ "__record__id": r.record__id,
3024
+ "__sub__changes": subChanges
3025
+ };
3026
+ if (recordChanges) {
3027
+ Object.keys(recordChanges).forEach(fieldName => { change[fieldName] = recordChanges[fieldName]; });
3028
+ }
3029
+ return change;
3030
+ }
3031
+ return undefined;
3032
+ }
3033
+ getSubChanges(id) {
3034
+ const result = [];
3035
+ if (this._records) {
3036
+ this._records.filter(r => r.parent__record__id === id).forEach(r => {
3037
+ const c = this.buildChange(r);
3038
+ if (c) {
3039
+ result.push(c);
3040
+ }
3041
+ });
3042
+ }
3043
+ return result;
3044
+ }
3045
+ getChangesToSave() {
3046
+ let result = [];
3047
+ if (this._records) {
3048
+ this._records.forEach(r => {
3049
+ const change = this.buildChange(r);
3050
+ if (change) {
3051
+ result.push(change);
3052
+ }
3053
+ });
3054
+ }
3055
+ return result;
3014
3056
  }
3015
3057
  save() {
3016
3058
  if (!this.validateRecords()) {
@@ -3100,6 +3142,17 @@ class DataUnit {
3100
3142
  }
3101
3143
  set records(records) {
3102
3144
  this._records = records;
3145
+ if (this.parentDU) {
3146
+ this._records.forEach(r => this.bindToParent(r));
3147
+ }
3148
+ }
3149
+ bindToParent(r) {
3150
+ if (this.parentDU) {
3151
+ const parentRecord = this.parentDU.getCurrentRecord();
3152
+ if (parentRecord) {
3153
+ r.parent__record__id = parentRecord.record__id;
3154
+ }
3155
+ }
3103
3156
  }
3104
3157
  get records() {
3105
3158
  if (!this._records) {
@@ -3124,7 +3177,7 @@ class DataUnit {
3124
3177
  const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
3125
3178
  const recordsToValidate = [];
3126
3179
  this.records.forEach((record, i) => {
3127
- const changes = duChanges[record.record__id];
3180
+ const changes = duChanges ? duChanges[record.record__id] : undefined;
3128
3181
  if (changes) {
3129
3182
  recordsToValidate.push(Object.assign(Object.assign(Object.assign({}, record), changes), { record__index: i, record__changedfields: Object.keys(changes) }));
3130
3183
  }
@@ -3143,20 +3196,36 @@ const EzForm$1 = class extends HTMLElement {
3143
3196
  constructor() {
3144
3197
  super();
3145
3198
  this.__registerHost();
3146
- this._dataUnits = [];
3199
+ this._dataUnits = new Map();
3200
+ this._duSources = new Map();
3147
3201
  this._requiredFieldsByDU = {};
3148
3202
  }
3149
3203
  async validate() {
3150
- for (let i = 0; i < this._dataUnits.length; i++) {
3151
- if (!this._dataUnits[i].validateRecords()) {
3204
+ for (let i = 0; i < this._duSources.size; i++) {
3205
+ const duName = Array.from(this._duSources.keys())[i];
3206
+ let du = this._dataUnits.get(duName);
3207
+ if (du === undefined) {
3208
+ const source = this._duSources.get(duName);
3209
+ du = this.buildDataUnit(source, source.parentDUName);
3210
+ }
3211
+ if (!du.validateRecords()) {
3152
3212
  return false;
3153
3213
  }
3154
3214
  }
3215
+ return true;
3155
3216
  }
3156
3217
  async getChanges() {
3218
+ debugger;
3157
3219
  let allChanges = [];
3158
- for (let i = 0; i < this._dataUnits.length; i++) {
3159
- allChanges = allChanges.concat(this._dataUnits[i].getChangesToSave());
3220
+ for (let i = 0; i < this._dataUnits.size; i++) {
3221
+ const du = Array.from(this._dataUnits.values())[i];
3222
+ //Só devemos buscar as alterações de DU raiz, pois os sub DUs serão enviados junto.
3223
+ if (!du.parentDU) {
3224
+ const duChanges = du.getChangesToSave();
3225
+ if (duChanges) {
3226
+ allChanges = allChanges.concat(duChanges);
3227
+ }
3228
+ }
3160
3229
  }
3161
3230
  return allChanges;
3162
3231
  }
@@ -3175,7 +3244,7 @@ const EzForm$1 = class extends HTMLElement {
3175
3244
  }
3176
3245
  });
3177
3246
  };
3178
- if (records.length == 0) {
3247
+ if (dataUnit.records.length == 0) {
3179
3248
  recordValidator({});
3180
3249
  }
3181
3250
  else {
@@ -3199,8 +3268,9 @@ const EzForm$1 = class extends HTMLElement {
3199
3268
  }
3200
3269
  }
3201
3270
  loadMDFromExecutor(callBack) {
3202
- if (this._loadMetadataFunction) {
3203
- const result = this._loadMetadataFunction();
3271
+ const loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
3272
+ if (loadMetadataFunction) {
3273
+ const result = loadMetadataFunction();
3204
3274
  if (result) {
3205
3275
  if (result instanceof Promise) {
3206
3276
  result.then(md => {
@@ -3253,13 +3323,20 @@ const EzForm$1 = class extends HTMLElement {
3253
3323
  }
3254
3324
  });
3255
3325
  (_a = form.subForms) === null || _a === void 0 ? void 0 : _a.forEach((subForm, index) => {
3256
- const subDU = subForm.dataUnit ? subForm.dataUnit.name : duName;
3257
- processFields(subDU, subForm, form.name, index);
3326
+ const subDu = subForm.dataUnit;
3327
+ if (subDu) {
3328
+ this._duSources.set(subDu.name, subDu);
3329
+ subDu.parentDUName = duName;
3330
+ }
3331
+ processFields(subDu ? subDu.name : duName, subForm, form.name, index);
3258
3332
  });
3259
3333
  };
3260
3334
  this.metadata = metadata;
3261
3335
  metadata.map((form, index) => {
3262
- processFields(form.dataUnit.name, form, "__MAIN__FORM__", index);
3336
+ const du = form.dataUnit;
3337
+ const duName = du.name;
3338
+ this._duSources.set(duName, du);
3339
+ processFields(duName, form, "__MAIN__FORM__", index);
3263
3340
  });
3264
3341
  this._store.dispatch(formLoad());
3265
3342
  }
@@ -3271,11 +3348,6 @@ const EzForm$1 = class extends HTMLElement {
3271
3348
  return null;
3272
3349
  }
3273
3350
  componentDidLoad() {
3274
- this._loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
3275
- this._loadDataFunction = this.parseExecutor(this.loadexecutor);
3276
- this._saveFunction = this.parseExecutor(this.saveexecutor);
3277
- this._removeFunction = this.parseExecutor(this.removeexecutor);
3278
- this._fieldSearchFunction = this.parseExecutor(this.fieldsearchexecutor);
3279
3351
  if (this.metadata) {
3280
3352
  this.updateMetadata(this.metadata);
3281
3353
  }
@@ -3286,27 +3358,34 @@ const EzForm$1 = class extends HTMLElement {
3286
3358
  }
3287
3359
  }
3288
3360
  }
3289
- buildDataUnit(dataUnit) {
3361
+ buildDataUnit(dataUnit, parentDataUnit) {
3290
3362
  if (dataUnit) {
3291
3363
  const { name, unitLabel, records, cardinality } = dataUnit;
3292
3364
  if (!(dataUnit instanceof DataUnit)) {
3293
- dataUnit = new DataUnit(name, unitLabel, cardinality);
3294
- this._dataUnits.push(dataUnit);
3365
+ let parent;
3366
+ if (parentDataUnit instanceof DataUnit) {
3367
+ parent = parentDataUnit;
3368
+ }
3369
+ else {
3370
+ parent = this._dataUnits.get(parentDataUnit);
3371
+ }
3372
+ dataUnit = new DataUnit(name, unitLabel, cardinality, parent);
3373
+ this._dataUnits.set(dataUnit.name, dataUnit);
3295
3374
  if (records) {
3296
3375
  dataUnit.records = records;
3297
3376
  }
3298
3377
  dataUnit.store = this._store;
3299
- dataUnit.loadExecutor = this._loadDataFunction;
3300
- dataUnit.saveExecutor = this._saveFunction;
3301
- dataUnit.removeExecutor = this._removeFunction;
3378
+ dataUnit.loadExecutor = this.parseExecutor(this.loadexecutor);
3379
+ dataUnit.saveExecutor = this.parseExecutor(this.saveexecutor);
3380
+ dataUnit.removeExecutor = this.parseExecutor(this.removeexecutor);
3302
3381
  dataUnit.recordsValidator = this;
3303
- dataUnit.fieldSearchExecutor = this._fieldSearchFunction;
3382
+ dataUnit.fieldSearchExecutor = this.parseExecutor(this.fieldsearchexecutor);
3304
3383
  }
3305
3384
  }
3306
3385
  return dataUnit;
3307
3386
  }
3308
3387
  render() {
3309
- return this.metadata ? h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du) => this.buildDataUnit(du) }) : null;
3388
+ return this.metadata ? h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du, parentDataUnit) => this.buildDataUnit(du, parentDataUnit) }) : null;
3310
3389
  }
3311
3390
  get _host() { return this; }
3312
3391
  static get style() { return ezFormCss; }
@@ -3478,7 +3557,6 @@ const EzModal$1 = class extends HTMLElement {
3478
3557
  console.log(ev === null || ev === void 0 ? void 0 : ev.key);
3479
3558
  if ((ev === null || ev === void 0 ? void 0 : ev.key) === 'Escape' && this.closeesc) {
3480
3559
  this.oppened = false;
3481
- debugger;
3482
3560
  this.ezChange.emit(this.oppened);
3483
3561
  }
3484
3562
  };
@@ -3487,7 +3565,6 @@ const EzModal$1 = class extends HTMLElement {
3487
3565
  ev === null || ev === void 0 ? void 0 : ev.stopPropagation();
3488
3566
  if (ev instanceof PointerEvent && this.closeoutsideclick) {
3489
3567
  this.oppened = false;
3490
- debugger;
3491
3568
  this.ezChange.emit(this.oppened);
3492
3569
  }
3493
3570
  }
@@ -170,10 +170,16 @@ const selectErrorMessage = (state, dataUnit, recordId, fieldName) => {
170
170
  const selectVisibleButtons = state => state.nonhist.visibleButtons;
171
171
 
172
172
  class DataUnit {
173
- constructor(name, unitLabel, cardinality = '1') {
173
+ constructor(name, unitLabel, cardinality = '1', parentDU = null) {
174
174
  this.name = name;
175
175
  this.unitLabel = unitLabel;
176
176
  this.cardinality = cardinality;
177
+ this._children = [];
178
+ if (parentDU != null) {
179
+ parentDU._children.push(this);
180
+ this.parentDU = parentDU;
181
+ this.parentDUName = parentDU.name;
182
+ }
177
183
  }
178
184
  set store(store) {
179
185
  this._store = store;
@@ -231,21 +237,57 @@ class DataUnit {
231
237
  insert() {
232
238
  const insertionIndex = this.records.length;
233
239
  const newRecordIndex = selectNewRecordIndex(this._store.getState(), this.name);
234
- this.records.push({ record__id: 'NEW_' + (newRecordIndex + 1) });
240
+ const newRecord = { record__id: 'NEW_' + (newRecordIndex + 1) };
241
+ this.bindToParent(newRecord);
242
+ this.records.push(newRecord);
235
243
  this._store.dispatch(insertRecord(this.name, insertionIndex));
236
244
  }
237
- getChangesToSave() {
245
+ buildChange(r) {
238
246
  const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
239
- const changesByRecord = Object.keys(duChanges).map(record__id => {
240
- const record = { record__id };
241
- const recordChanges = duChanges[record__id];
242
- Object.keys(recordChanges).forEach(fieldName => { record[fieldName] = recordChanges[fieldName]; });
243
- return record;
247
+ let recordChanges;
248
+ if (duChanges) {
249
+ recordChanges = duChanges[r.record__id];
250
+ }
251
+ let subChanges = [];
252
+ this._children.forEach(duChild => {
253
+ subChanges = subChanges.concat(duChild.getSubChanges(r.record__id));
244
254
  });
245
- return [{
246
- dataUnit: this.name,
247
- records: changesByRecord
248
- }];
255
+ if (recordChanges || subChanges.length > 0) {
256
+ const change = {
257
+ "__data__unit": this.name,
258
+ "__record__id": r.record__id,
259
+ "__sub__changes": subChanges
260
+ };
261
+ if (recordChanges) {
262
+ Object.keys(recordChanges).forEach(fieldName => { change[fieldName] = recordChanges[fieldName]; });
263
+ }
264
+ return change;
265
+ }
266
+ return undefined;
267
+ }
268
+ getSubChanges(id) {
269
+ const result = [];
270
+ if (this._records) {
271
+ this._records.filter(r => r.parent__record__id === id).forEach(r => {
272
+ const c = this.buildChange(r);
273
+ if (c) {
274
+ result.push(c);
275
+ }
276
+ });
277
+ }
278
+ return result;
279
+ }
280
+ getChangesToSave() {
281
+ let result = [];
282
+ if (this._records) {
283
+ this._records.forEach(r => {
284
+ const change = this.buildChange(r);
285
+ if (change) {
286
+ result.push(change);
287
+ }
288
+ });
289
+ }
290
+ return result;
249
291
  }
250
292
  save() {
251
293
  if (!this.validateRecords()) {
@@ -335,6 +377,17 @@ class DataUnit {
335
377
  }
336
378
  set records(records) {
337
379
  this._records = records;
380
+ if (this.parentDU) {
381
+ this._records.forEach(r => this.bindToParent(r));
382
+ }
383
+ }
384
+ bindToParent(r) {
385
+ if (this.parentDU) {
386
+ const parentRecord = this.parentDU.getCurrentRecord();
387
+ if (parentRecord) {
388
+ r.parent__record__id = parentRecord.record__id;
389
+ }
390
+ }
338
391
  }
339
392
  get records() {
340
393
  if (!this._records) {
@@ -359,7 +412,7 @@ class DataUnit {
359
412
  const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
360
413
  const recordsToValidate = [];
361
414
  this.records.forEach((record, i) => {
362
- const changes = duChanges[record.record__id];
415
+ const changes = duChanges ? duChanges[record.record__id] : undefined;
363
416
  if (changes) {
364
417
  recordsToValidate.push(Object.assign(Object.assign(Object.assign({}, record), changes), { record__index: i, record__changedfields: Object.keys(changes) }));
365
418
  }
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, h, c as createEvent, f as forceUpdate, H as Host, g as getElement } from './index-95bb3fd9.js';
2
2
  import { M as MaskFormatter } from './RequestMetadata-c265c9d5.js';
3
- import { s as selectIsCollapsedFieldSet, c as collapseExpandGroup, a as selectCurrentTab, b as selectVisibleButtons, d as changeTab$1, e as showHideNavigationButtons, f as formLoad, D as DataUnit, i as invalidField$1 } from './DataUnit-ac4cc054.js';
3
+ import { s as selectIsCollapsedFieldSet, c as collapseExpandGroup, a as selectCurrentTab, b as selectVisibleButtons, d as changeTab$1, e as showHideNavigationButtons, f as formLoad, D as DataUnit, i as invalidField$1 } from './DataUnit-ab1a3a4d.js';
4
4
 
5
5
  const ezButtonCss = ":host{--bt--min-width:100px;--bt--height:42px;--bt__icon--width:18px;--bt__inline__icon--padding:12px;--bt--padding-top:var(--space--medium, 12px);--bt--padding-bottom:var(--space--medium, 12px);--bt--padding-right:var(--space--large, 24px);--bt--padding-left:var(--space--large, 24px);--bt--color:var(--text--inverted, #FFF);--bt--font-size:var(--text--medium, 14px);--bt--font-family:var(--font-pattern, Arial);--bt--font-weight:var(--text-weight--large);--bt--background-color:var(--color--primary, #c0c0c0);--bt--border-radius:var(--border--radius-large, 12px);--bt--border:none;--bt--hover--background-color:var(--color--primary-700, var(--bt--background-color));--bt--disabled--color:var(--color--disable-primary, var(--bt--color));--bt--disabled--background-color:var(--color--disabled, var(--bt--background-color));--bt--focus--border:var(--bt--border);--bt--focus--box-shadow:none}button{display:flex;align-items:center;justify-content:center;margin:0;cursor:pointer;transition:background-color 0.2s linear;min-width:var(--bt--min-width);height:var(--bt--height);font-family:var(--bt--font-family);font-size:var(--bt--font-size);font-weight:var(--bt--font-weight);padding:var(--bt--padding-top) var(--bt--padding-right) var(--bt--padding-bottom) var(--bt--padding-left);border-radius:var(--bt--border-radius);background-color:var(--bt--background-color);color:var(--bt--color);fill:var(--bt--color);border:var(--bt--border)}button:hover{background-color:var(--bt--hover--background-color)}button:focus{outline:none;border:var(--bt--focus--border);box-shadow:var(--bt--focus--box-shadow)}button:disabled{background-color:var(--bt--disabled--background-color);color:var(--bt--disabled--color);fill:var(--bt--disabled--color);border:none;cursor:no-drop}button.icon{width:42px;min-width:42px;height:42px;padding:0px}a{font-family:var(--bt--font-family);font-size:var(--bt--font-size);font-weight:var(--bt--font-weight);cursor:pointer;display:flex;align-items:center;justify-content:center}";
6
6
 
@@ -2033,8 +2033,8 @@ const NavigationBar = ({ dataUnit: du, buttonProps }) => {
2033
2033
  return h("div", { class: "col col--sd-12 align--right" },
2034
2034
  buttonProps.previousVisible ? h("ez-button", { title: "Registro anterior", mode: "icon", enabled: du.hasPrevious(), onClick: () => du.previous(), image: "/themes/default/images/icons/actions-sprite.svg#previous-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2035
2035
  buttonProps.nextVisible ? h("ez-button", { title: "Pr\u00F3ximo registro", mode: "icon", enabled: du.hasNext(), onClick: () => du.next(), image: "/themes/default/images/icons/actions-sprite.svg#next-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2036
- buttonProps.removeVisible ? h("ez-button", { title: "Remover " + du.unitLabel, mode: "icon", enabled: du.hasCurrentRecord(), onClick: () => removeHandler(du), image: "/themes/default/images/icons/actions-sprite.svg#minus-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2037
- buttonProps.addVisible ? h("ez-button", { label: "Criar " + du.unitLabel, onClick: () => du.insert(), class: "button--secondary margin-right--medium" }) : null,
2036
+ buttonProps.removeVisible ? h("ez-button", { label: "Remover", enabled: du.hasCurrentRecord(), onClick: () => removeHandler(du), image: "/themes/default/images/icons/actions-sprite.svg#minus-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2037
+ buttonProps.addVisible ? h("ez-button", { label: "Adicionar", onClick: () => du.insert(), class: "button--secondary margin-right--medium" }) : null,
2038
2038
  buttonProps.reloadVisible ? h("ez-button", { title: "Recarregar", mode: "icon", onClick: () => du.load(), image: "/themes/default/images/icons/actions-sprite.svg#rotate", class: "button--secondary margin-right--medium" }) : null,
2039
2039
  buttonProps.cancelVisible ? h("ez-button", { label: "Cancelar", enabled: du.hasChanges(), onClick: () => du.cancel(), class: "button--secondary margin-right--medium" }) : null,
2040
2040
  buttonProps.saveVisible ? h("ez-button", { label: "Salvar", enabled: du.hasChanges(), onClick: () => du.save(), class: "button--primary margin-right--medium" }) : null);
@@ -2156,7 +2156,7 @@ const FormSheet = ({ store, parentName, source, parentDataUnit, dataUnitBuilder
2156
2156
  const selectedTab = selectCurrentTab(store.getState(), parentName);
2157
2157
  const tabs = source.length > 1 ? source.map(form => h("ez-tab", { label: form.label, tabKey: form.name })) : null;
2158
2158
  const { subForms, items, name } = source[selectedTab];
2159
- const dataUnit = dataUnitBuilder(source[selectedTab].dataUnit);
2159
+ const dataUnit = dataUnitBuilder(source[selectedTab].dataUnit, parentDataUnit);
2160
2160
  source[selectedTab].dataUnit = dataUnit;
2161
2161
  const hasSubForms = subForms && subForms.length > 0;
2162
2162
  const changeTabHandler = (index) => {
@@ -2184,20 +2184,36 @@ const ezFormCss = "ez-form{display:flex;flex-direction:column;width:100%}.form-s
2184
2184
  const EzForm = class {
2185
2185
  constructor(hostRef) {
2186
2186
  registerInstance(this, hostRef);
2187
- this._dataUnits = [];
2187
+ this._dataUnits = new Map();
2188
+ this._duSources = new Map();
2188
2189
  this._requiredFieldsByDU = {};
2189
2190
  }
2190
2191
  async validate() {
2191
- for (let i = 0; i < this._dataUnits.length; i++) {
2192
- if (!this._dataUnits[i].validateRecords()) {
2192
+ for (let i = 0; i < this._duSources.size; i++) {
2193
+ const duName = Array.from(this._duSources.keys())[i];
2194
+ let du = this._dataUnits.get(duName);
2195
+ if (du === undefined) {
2196
+ const source = this._duSources.get(duName);
2197
+ du = this.buildDataUnit(source, source.parentDUName);
2198
+ }
2199
+ if (!du.validateRecords()) {
2193
2200
  return false;
2194
2201
  }
2195
2202
  }
2203
+ return true;
2196
2204
  }
2197
2205
  async getChanges() {
2206
+ debugger;
2198
2207
  let allChanges = [];
2199
- for (let i = 0; i < this._dataUnits.length; i++) {
2200
- allChanges = allChanges.concat(this._dataUnits[i].getChangesToSave());
2208
+ for (let i = 0; i < this._dataUnits.size; i++) {
2209
+ const du = Array.from(this._dataUnits.values())[i];
2210
+ //Só devemos buscar as alterações de DU raiz, pois os sub DUs serão enviados junto.
2211
+ if (!du.parentDU) {
2212
+ const duChanges = du.getChangesToSave();
2213
+ if (duChanges) {
2214
+ allChanges = allChanges.concat(duChanges);
2215
+ }
2216
+ }
2201
2217
  }
2202
2218
  return allChanges;
2203
2219
  }
@@ -2216,7 +2232,7 @@ const EzForm = class {
2216
2232
  }
2217
2233
  });
2218
2234
  };
2219
- if (records.length == 0) {
2235
+ if (dataUnit.records.length == 0) {
2220
2236
  recordValidator({});
2221
2237
  }
2222
2238
  else {
@@ -2240,8 +2256,9 @@ const EzForm = class {
2240
2256
  }
2241
2257
  }
2242
2258
  loadMDFromExecutor(callBack) {
2243
- if (this._loadMetadataFunction) {
2244
- const result = this._loadMetadataFunction();
2259
+ const loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
2260
+ if (loadMetadataFunction) {
2261
+ const result = loadMetadataFunction();
2245
2262
  if (result) {
2246
2263
  if (result instanceof Promise) {
2247
2264
  result.then(md => {
@@ -2294,13 +2311,20 @@ const EzForm = class {
2294
2311
  }
2295
2312
  });
2296
2313
  (_a = form.subForms) === null || _a === void 0 ? void 0 : _a.forEach((subForm, index) => {
2297
- const subDU = subForm.dataUnit ? subForm.dataUnit.name : duName;
2298
- processFields(subDU, subForm, form.name, index);
2314
+ const subDu = subForm.dataUnit;
2315
+ if (subDu) {
2316
+ this._duSources.set(subDu.name, subDu);
2317
+ subDu.parentDUName = duName;
2318
+ }
2319
+ processFields(subDu ? subDu.name : duName, subForm, form.name, index);
2299
2320
  });
2300
2321
  };
2301
2322
  this.metadata = metadata;
2302
2323
  metadata.map((form, index) => {
2303
- processFields(form.dataUnit.name, form, "__MAIN__FORM__", index);
2324
+ const du = form.dataUnit;
2325
+ const duName = du.name;
2326
+ this._duSources.set(duName, du);
2327
+ processFields(duName, form, "__MAIN__FORM__", index);
2304
2328
  });
2305
2329
  this._store.dispatch(formLoad());
2306
2330
  }
@@ -2312,11 +2336,6 @@ const EzForm = class {
2312
2336
  return null;
2313
2337
  }
2314
2338
  componentDidLoad() {
2315
- this._loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
2316
- this._loadDataFunction = this.parseExecutor(this.loadexecutor);
2317
- this._saveFunction = this.parseExecutor(this.saveexecutor);
2318
- this._removeFunction = this.parseExecutor(this.removeexecutor);
2319
- this._fieldSearchFunction = this.parseExecutor(this.fieldsearchexecutor);
2320
2339
  if (this.metadata) {
2321
2340
  this.updateMetadata(this.metadata);
2322
2341
  }
@@ -2327,27 +2346,34 @@ const EzForm = class {
2327
2346
  }
2328
2347
  }
2329
2348
  }
2330
- buildDataUnit(dataUnit) {
2349
+ buildDataUnit(dataUnit, parentDataUnit) {
2331
2350
  if (dataUnit) {
2332
2351
  const { name, unitLabel, records, cardinality } = dataUnit;
2333
2352
  if (!(dataUnit instanceof DataUnit)) {
2334
- dataUnit = new DataUnit(name, unitLabel, cardinality);
2335
- this._dataUnits.push(dataUnit);
2353
+ let parent;
2354
+ if (parentDataUnit instanceof DataUnit) {
2355
+ parent = parentDataUnit;
2356
+ }
2357
+ else {
2358
+ parent = this._dataUnits.get(parentDataUnit);
2359
+ }
2360
+ dataUnit = new DataUnit(name, unitLabel, cardinality, parent);
2361
+ this._dataUnits.set(dataUnit.name, dataUnit);
2336
2362
  if (records) {
2337
2363
  dataUnit.records = records;
2338
2364
  }
2339
2365
  dataUnit.store = this._store;
2340
- dataUnit.loadExecutor = this._loadDataFunction;
2341
- dataUnit.saveExecutor = this._saveFunction;
2342
- dataUnit.removeExecutor = this._removeFunction;
2366
+ dataUnit.loadExecutor = this.parseExecutor(this.loadexecutor);
2367
+ dataUnit.saveExecutor = this.parseExecutor(this.saveexecutor);
2368
+ dataUnit.removeExecutor = this.parseExecutor(this.removeexecutor);
2343
2369
  dataUnit.recordsValidator = this;
2344
- dataUnit.fieldSearchExecutor = this._fieldSearchFunction;
2370
+ dataUnit.fieldSearchExecutor = this.parseExecutor(this.fieldsearchexecutor);
2345
2371
  }
2346
2372
  }
2347
2373
  return dataUnit;
2348
2374
  }
2349
2375
  render() {
2350
- return this.metadata ? h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du) => this.buildDataUnit(du) }) : null;
2376
+ return this.metadata ? h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du, parentDataUnit) => this.buildDataUnit(du, parentDataUnit) }) : null;
2351
2377
  }
2352
2378
  get _host() { return getElement(this); }
2353
2379
  };
@@ -22,7 +22,6 @@ const EzModal = class {
22
22
  console.log(ev === null || ev === void 0 ? void 0 : ev.key);
23
23
  if ((ev === null || ev === void 0 ? void 0 : ev.key) === 'Escape' && this.closeesc) {
24
24
  this.oppened = false;
25
- debugger;
26
25
  this.ezChange.emit(this.oppened);
27
26
  }
28
27
  };
@@ -31,7 +30,6 @@ const EzModal = class {
31
30
  ev === null || ev === void 0 ? void 0 : ev.stopPropagation();
32
31
  if (ev instanceof PointerEvent && this.closeoutsideclick) {
33
32
  this.oppened = false;
34
- debugger;
35
33
  this.ezChange.emit(this.oppened);
36
34
  }
37
35
  }
@@ -1,5 +1,5 @@
1
1
  import { r as registerInstance, h, g as getElement, H as Host } from './index-95bb3fd9.js';
2
- import { D as DataUnit } from './DataUnit-ac4cc054.js';
2
+ import { D as DataUnit } from './DataUnit-ab1a3a4d.js';
3
3
 
4
4
  const FormMetadata = class {
5
5
  constructor(hostRef) {
@@ -1 +1 @@
1
- import{p as e,b as a}from"./p-185c57f4.js";(()=>{const a=import.meta.url,l={};return""!==a&&(l.resourcesUrl=new URL(".",a).href),e(l)})().then((e=>a([["p-fa260f22",[[1,"ez-label-chip",{label:[513],enabled:[516],removable:[516],value:[1540],setFocus:[64],setBlur:[64]}]]],["p-dd4331b7",[[1,"ez-time-input",{label:[513],viewValue:[1537,"view-value"],value:[1026],enabled:[516],errormessage:[1537],showSeconds:[516,"show-seconds"],setFocus:[64],setBlur:[64]}]]],["p-22b82efb",[[1,"ez-action-chip",{label:[513],enabled:[516]}]]],["p-77fdb4fd",[[1,"ez-modal",{modalsize:[1537],align:[1537],oppened:[1540],closeesc:[1540],closeoutsideclick:[1540]}]]],["p-f6fd31ab",[[1,"ez-number-input",{strvalue:[1025],value:[1026],label:[513],enabled:[516],errormessage:[1537],precision:[1538],prettyprecision:[1538],textleft:[516],formatnumber:[513],setFocus:[64],setBlur:[64],handleFocusout:[64]}]]],["p-346050cf",[[1,"form-metadata",{name:[1],label:[1],dataunit:[1025],many:[4],autoload:[4],metadata:[1040]}]]],["p-f95e3c71",[[0,"ez-form",{metadataexecutor:[1],loadexecutor:[1],saveexecutor:[1],removeexecutor:[1],fieldsearchexecutor:[1],metadata:[1040],slavemode:[4],validate:[64],getChanges:[64]}],[1,"ez-combo-box",{value:[1537],label:[513],enabled:[516],showvalue:[516],options:[1040],errormessage:[1537],_inputLabelValue:[32],_criteria:[32],_preSelection:[32],_visibleOptions:[32],setFocus:[64],setBlur:[64]}],[1,"ez-date-input",{label:[513],value:[1040],enabled:[516],errormessage:[1537]}],[1,"ez-search",{value:[1537],label:[1537],enabled:[1540],qtdHotItems:[514,"qtd-hot-items"],showvalue:[516],errormessage:[1537],loadexecutor:[1],hotsearchid:[1],_preSelection:[32],_visibleOptions:[32],onInputTeste:[64]}],[1,"ez-button",{label:[513],enabled:[516],mode:[513],image:[513]}],[1,"ez-check",{value:[1540],enabled:[516],mode:[513],getMode:[64],setFocus:[64]}],[1,"ez-collapsable-box",{value:[1540],label:[513],showHide:[64]}],[1,"ez-tabselector",{selectedindex:[1537],selectedtab:[1537],tabs:[1]}],[1,"ez-text-area",{label:[513],value:[1537],enabled:[516],loading:[516],errormessage:[1537],rows:[1538],setFocus:[64],setBlur:[64]}],[1,"place-holder"],[1,"ez-calendar",{value:[1040],floating:[516],show:[64],hide:[64]}],[1,"ez-popover",{autoclose:[516],top:[1537],left:[1537],bottom:[1537],right:[1537],boxwidth:[513],isOpened:[1540,"is-opened"],updatePosition:[64],show:[64],hide:[64]}],[1,"ez-icon",{size:[513],href:[513]}],[1,"ez-text-input",{label:[513],value:[1537],enabled:[516],loading:[516],errormessage:[1537],onlynumber:[516],mask:[1],restrict:[1],setFocus:[64],setBlur:[64]}]]]],e)));
1
+ import{p as e,b as a}from"./p-185c57f4.js";(()=>{const a=import.meta.url,l={};return""!==a&&(l.resourcesUrl=new URL(".",a).href),e(l)})().then((e=>a([["p-fa260f22",[[1,"ez-label-chip",{label:[513],enabled:[516],removable:[516],value:[1540],setFocus:[64],setBlur:[64]}]]],["p-dd4331b7",[[1,"ez-time-input",{label:[513],viewValue:[1537,"view-value"],value:[1026],enabled:[516],errormessage:[1537],showSeconds:[516,"show-seconds"],setFocus:[64],setBlur:[64]}]]],["p-22b82efb",[[1,"ez-action-chip",{label:[513],enabled:[516]}]]],["p-77fdb4fd",[[1,"ez-modal",{modalsize:[1537],align:[1537],oppened:[1540],closeesc:[1540],closeoutsideclick:[1540]}]]],["p-f6fd31ab",[[1,"ez-number-input",{strvalue:[1025],value:[1026],label:[513],enabled:[516],errormessage:[1537],precision:[1538],prettyprecision:[1538],textleft:[516],formatnumber:[513],setFocus:[64],setBlur:[64],handleFocusout:[64]}]]],["p-b02e731e",[[1,"form-metadata",{name:[1],label:[1],dataunit:[1025],many:[4],autoload:[4],metadata:[1040]}]]],["p-83f1d308",[[0,"ez-form",{metadataexecutor:[1],loadexecutor:[1],saveexecutor:[1],removeexecutor:[1],fieldsearchexecutor:[1],metadata:[1040],slavemode:[4],validate:[64],getChanges:[64]}],[1,"ez-combo-box",{value:[1537],label:[513],enabled:[516],showvalue:[516],options:[1040],errormessage:[1537],_inputLabelValue:[32],_criteria:[32],_preSelection:[32],_visibleOptions:[32],setFocus:[64],setBlur:[64]}],[1,"ez-date-input",{label:[513],value:[1040],enabled:[516],errormessage:[1537]}],[1,"ez-search",{value:[1537],label:[1537],enabled:[1540],qtdHotItems:[514,"qtd-hot-items"],showvalue:[516],errormessage:[1537],loadexecutor:[1],hotsearchid:[1],_preSelection:[32],_visibleOptions:[32],onInputTeste:[64]}],[1,"ez-button",{label:[513],enabled:[516],mode:[513],image:[513]}],[1,"ez-check",{value:[1540],enabled:[516],mode:[513],getMode:[64],setFocus:[64]}],[1,"ez-collapsable-box",{value:[1540],label:[513],showHide:[64]}],[1,"ez-tabselector",{selectedindex:[1537],selectedtab:[1537],tabs:[1]}],[1,"ez-text-area",{label:[513],value:[1537],enabled:[516],loading:[516],errormessage:[1537],rows:[1538],setFocus:[64],setBlur:[64]}],[1,"place-holder"],[1,"ez-calendar",{value:[1040],floating:[516],show:[64],hide:[64]}],[1,"ez-popover",{autoclose:[516],top:[1537],left:[1537],bottom:[1537],right:[1537],boxwidth:[513],isOpened:[1540,"is-opened"],updatePosition:[64],show:[64],hide:[64]}],[1,"ez-icon",{size:[513],href:[513]}],[1,"ez-text-input",{label:[513],value:[1537],enabled:[516],loading:[516],errormessage:[1537],onlynumber:[516],mask:[1],restrict:[1],setFocus:[64],setBlur:[64]}]]]],e)));