@sumaris-net/ngx-components 1.20.18 → 1.20.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/sumaris-net.ngx-components.umd.js +535 -11
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +2 -2
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/doc/changelog.md +9 -0
- package/esm2015/public_api.js +2 -2
- package/esm2015/src/app/core/form/editor.class.js +8 -7
- package/esm2015/src/app/core/form/entity-editor-modal.class.js +417 -0
- package/esm2015/src/app/shared/material/latlong/material.latlong.js +9 -7
- package/fesm2015/sumaris-net.ngx-components.js +415 -12
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +1 -1
- package/src/app/core/form/editor.class.d.ts +2 -1
- package/src/app/core/form/entity-editor-modal.class.d.ts +118 -0
- package/src/app/shared/material/latlong/material.latlong.d.ts +0 -1
- package/src/theme/_ngx-components.scss +0 -4
- package/src/theme/_responsive.scss +5 -0
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -5476,8 +5476,8 @@
|
|
|
5476
5476
|
return;
|
|
5477
5477
|
var value = (typeof obj === 'string') ? parseFloat(obj.replace(/,/g, '.')) : obj;
|
|
5478
5478
|
this._writing = true;
|
|
5479
|
-
var strValue = this._formatFn(
|
|
5480
|
-
var sign = isNotNil(
|
|
5479
|
+
var strValue = this._formatFn(value, Object.assign(Object.assign({}, this._formatOptions), { placeholderChar: this.placeholderChar }));
|
|
5480
|
+
var sign = isNotNil(value) ? (value < 0 ? -1 : 1) :
|
|
5481
5481
|
// Use default sign, if any
|
|
5482
5482
|
(this.defaultSign ? (this.defaultSign === '-' ? -1 : 1) : null);
|
|
5483
5483
|
// DEBUG
|
|
@@ -5520,7 +5520,8 @@
|
|
|
5520
5520
|
MatLatLongField.prototype._onFocus = function (event) {
|
|
5521
5521
|
var _this = this;
|
|
5522
5522
|
// Apply the default sign, when pattern is DD and field is empty
|
|
5523
|
-
|
|
5523
|
+
var value = this.formControl.value;
|
|
5524
|
+
if (isNilOrNaN(value)) {
|
|
5524
5525
|
if (this.defaultSign) {
|
|
5525
5526
|
// Compute the text value, using the default sign
|
|
5526
5527
|
var defaultSign = this.defaultSign === '-' ? -1 : 1;
|
|
@@ -5550,8 +5551,9 @@
|
|
|
5550
5551
|
return true;
|
|
5551
5552
|
};
|
|
5552
5553
|
MatLatLongField.prototype._onBlur = function (event) {
|
|
5554
|
+
var _a;
|
|
5553
5555
|
var touched = this.checkIfTouched();
|
|
5554
|
-
if (touched && isNil(this.value)) {
|
|
5556
|
+
if (touched && isNil((_a = this.formControl) === null || _a === void 0 ? void 0 : _a.value)) {
|
|
5555
5557
|
this.inputElement.nativeElement.value = '';
|
|
5556
5558
|
}
|
|
5557
5559
|
this.onBlur.emit(event);
|
|
@@ -5653,7 +5655,7 @@
|
|
|
5653
5655
|
this.formControl.patchValue(value, { emitEvent: false });
|
|
5654
5656
|
this._writing = false;
|
|
5655
5657
|
this.markForCheck();
|
|
5656
|
-
this._onChangeCallback(
|
|
5658
|
+
this._onChangeCallback(value);
|
|
5657
5659
|
};
|
|
5658
5660
|
MatLatLongField.prototype.checkIfTouched = function () {
|
|
5659
5661
|
if (this.formControl.touched || this.textFormControl.touched) {
|
|
@@ -28421,7 +28423,8 @@
|
|
|
28421
28423
|
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
|
28422
28424
|
var AppTabEditor = /** @class */ (function (_super_1) {
|
|
28423
28425
|
__extends(AppTabEditor, _super_1);
|
|
28424
|
-
function AppTabEditor(route,
|
|
28426
|
+
function AppTabEditor(route, // Modal editor give 'null'
|
|
28427
|
+
router, alertCtrl, translate, options) {
|
|
28425
28428
|
var _this = _super_1.call(this, route, router, alertCtrl, translate) || this;
|
|
28426
28429
|
_this.route = route;
|
|
28427
28430
|
_this.router = router;
|
|
@@ -28433,6 +28436,7 @@
|
|
|
28433
28436
|
_this.tabCount = options.tabCount;
|
|
28434
28437
|
_this.enableSwipe = options.enableSwipe;
|
|
28435
28438
|
_this.tabGroupAnimationDuration = options.tabGroupAnimationDuration;
|
|
28439
|
+
_this.queryTabIndexParamName = 'tab';
|
|
28436
28440
|
return _this;
|
|
28437
28441
|
}
|
|
28438
28442
|
Object.defineProperty(AppTabEditor.prototype, "selectedTabIndex", {
|
|
@@ -28448,9 +28452,8 @@
|
|
|
28448
28452
|
AppTabEditor.prototype.ngOnInit = function () {
|
|
28449
28453
|
var _this = this;
|
|
28450
28454
|
_super_1.prototype.ngOnInit.call(this);
|
|
28451
|
-
this.queryTabIndexParamName = this.queryTabIndexParamName || 'tab';
|
|
28452
28455
|
// Read the selected tab index, from path query params
|
|
28453
|
-
if (this.tabGroup) {
|
|
28456
|
+
if (this.tabGroup && this.route && this.queryTabIndexParamName) {
|
|
28454
28457
|
this.registerSubscription(this.route.queryParams
|
|
28455
28458
|
.subscribe(function (queryParams) {
|
|
28456
28459
|
_this.queryParams = Object.assign({}, queryParams);
|
|
@@ -28495,8 +28498,8 @@
|
|
|
28495
28498
|
};
|
|
28496
28499
|
AppTabEditor.prototype.onTabChange = function (event, queryTabIndexParamName) {
|
|
28497
28500
|
queryTabIndexParamName = queryTabIndexParamName || this.queryTabIndexParamName;
|
|
28498
|
-
if (!queryTabIndexParamName)
|
|
28499
|
-
return true; // Skip if tab query param not set
|
|
28501
|
+
if (!queryTabIndexParamName || !this.route)
|
|
28502
|
+
return true; // Skip if tab query param not set, or no route
|
|
28500
28503
|
if (!this.queryParams || +this.queryParams[queryTabIndexParamName] !== event.index) {
|
|
28501
28504
|
this.queryParams = this.queryParams || {};
|
|
28502
28505
|
this.queryParams[queryTabIndexParamName] = event.index;
|
|
@@ -28577,7 +28580,7 @@
|
|
|
28577
28580
|
{ type: i0.Directive }
|
|
28578
28581
|
];
|
|
28579
28582
|
AppTabEditor.ctorParameters = function () { return [
|
|
28580
|
-
{ type: i3.ActivatedRoute },
|
|
28583
|
+
{ type: i3.ActivatedRoute, decorators: [{ type: i0.Optional }] },
|
|
28581
28584
|
{ type: i3.Router },
|
|
28582
28585
|
{ type: i1$5.AlertController },
|
|
28583
28586
|
{ type: i1$2.TranslateService },
|
|
@@ -29451,6 +29454,525 @@
|
|
|
29451
29454
|
{ type: AppEditorOptions, decorators: [{ type: i0.Optional }] }
|
|
29452
29455
|
]; };
|
|
29453
29456
|
|
|
29457
|
+
var AppEntityEditorModalOptions = /** @class */ (function (_super_1) {
|
|
29458
|
+
__extends(AppEntityEditorModalOptions, _super_1);
|
|
29459
|
+
function AppEntityEditorModalOptions() {
|
|
29460
|
+
return _super_1 !== null && _super_1.apply(this, arguments) || this;
|
|
29461
|
+
}
|
|
29462
|
+
return AppEntityEditorModalOptions;
|
|
29463
|
+
}(AppTabEditorOptions));
|
|
29464
|
+
// @dynamic
|
|
29465
|
+
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
|
29466
|
+
var AppEntityEditorModal = /** @class */ (function (_super_1) {
|
|
29467
|
+
__extends(AppEntityEditorModal, _super_1);
|
|
29468
|
+
function AppEntityEditorModal(injector, dataType, options) {
|
|
29469
|
+
var _this = _super_1.call(this, null, injector.get(i3.Router), injector.get(i1$5.AlertController), injector.get(i1$2.TranslateService), options) || this;
|
|
29470
|
+
_this.dataType = dataType;
|
|
29471
|
+
_this.saving = false;
|
|
29472
|
+
_this.$title = new rxjs.Subject();
|
|
29473
|
+
_this.i18nSuffix = null;
|
|
29474
|
+
_this.environement = injector.get(ENVIRONMENT);
|
|
29475
|
+
options = Object.assign({
|
|
29476
|
+
// Default options
|
|
29477
|
+
i18nPrefix: ''
|
|
29478
|
+
}, options);
|
|
29479
|
+
_this.queryTabIndexParamName = undefined; // Important: avoid query parameter changed
|
|
29480
|
+
_this.settings = injector.get(LocalSettingsService);
|
|
29481
|
+
_this.errorTranslator = injector.get(FormErrorTranslator);
|
|
29482
|
+
_this.cd = injector.get(i0.ChangeDetectorRef);
|
|
29483
|
+
_this.dateFormat = injector.get(DateFormatPipe);
|
|
29484
|
+
_this.modalCtrl = injector.get(i1$5.ModalController);
|
|
29485
|
+
_this.i18nContext = {
|
|
29486
|
+
prefix: options.i18nPrefix,
|
|
29487
|
+
suffix: _this.i18nSuffix || ''
|
|
29488
|
+
};
|
|
29489
|
+
return _this;
|
|
29490
|
+
// FOR DEV ONLY ----
|
|
29491
|
+
//this.debug = !environment.production;
|
|
29492
|
+
}
|
|
29493
|
+
Object.defineProperty(AppEntityEditorModal.prototype, "isNewData", {
|
|
29494
|
+
get: function () {
|
|
29495
|
+
var _a;
|
|
29496
|
+
return isNotNil(this._isNewData) ? this._isNewData : isNil((_a = this.data) === null || _a === void 0 ? void 0 : _a.id);
|
|
29497
|
+
},
|
|
29498
|
+
set: function (value) {
|
|
29499
|
+
this._isNewData = value;
|
|
29500
|
+
},
|
|
29501
|
+
enumerable: false,
|
|
29502
|
+
configurable: true
|
|
29503
|
+
});
|
|
29504
|
+
Object.defineProperty(AppEntityEditorModal.prototype, "disabled", {
|
|
29505
|
+
get: function () {
|
|
29506
|
+
return !this._enabled;
|
|
29507
|
+
},
|
|
29508
|
+
set: function (value) {
|
|
29509
|
+
this._enabled = !value;
|
|
29510
|
+
},
|
|
29511
|
+
enumerable: false,
|
|
29512
|
+
configurable: true
|
|
29513
|
+
});
|
|
29514
|
+
Object.defineProperty(AppEntityEditorModal.prototype, "isOnFieldMode", {
|
|
29515
|
+
get: function () {
|
|
29516
|
+
return this.settings.isOnFieldMode(this._usageMode);
|
|
29517
|
+
},
|
|
29518
|
+
enumerable: false,
|
|
29519
|
+
configurable: true
|
|
29520
|
+
});
|
|
29521
|
+
AppEntityEditorModal.prototype.markAsSaving = function (opts) {
|
|
29522
|
+
if (!this.saving) {
|
|
29523
|
+
this.saving = true;
|
|
29524
|
+
if (!opts || opts.emitEvent !== false)
|
|
29525
|
+
this.markForCheck();
|
|
29526
|
+
}
|
|
29527
|
+
};
|
|
29528
|
+
AppEntityEditorModal.prototype.markAsSaved = function (opts) {
|
|
29529
|
+
if (this.saving) {
|
|
29530
|
+
this.saving = false;
|
|
29531
|
+
if (!opts || opts.emitEvent !== false)
|
|
29532
|
+
this.markForCheck();
|
|
29533
|
+
}
|
|
29534
|
+
};
|
|
29535
|
+
AppEntityEditorModal.prototype.ngOnInit = function () {
|
|
29536
|
+
var _super = Object.create(null, {
|
|
29537
|
+
ngOnInit: { get: function () { return _super_1.prototype.ngOnInit; } }
|
|
29538
|
+
});
|
|
29539
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29540
|
+
var _this = this;
|
|
29541
|
+
return __generator(this, function (_b) {
|
|
29542
|
+
// Default values
|
|
29543
|
+
this.mobile = isNotNil(this.mobile) ? this.mobile : this.settings.mobile;
|
|
29544
|
+
_super.ngOnInit.call(this);
|
|
29545
|
+
// Register forms
|
|
29546
|
+
this.registerForms();
|
|
29547
|
+
// Disable
|
|
29548
|
+
if (this.disabled)
|
|
29549
|
+
this.disable();
|
|
29550
|
+
// Update title each time value changes
|
|
29551
|
+
if (!this.isNewData) {
|
|
29552
|
+
this.registerSubscription(this.form.valueChanges
|
|
29553
|
+
.pipe(operators.debounceTime(250))
|
|
29554
|
+
.subscribe(function (json) { return _this.updateTitle(json); }));
|
|
29555
|
+
}
|
|
29556
|
+
return [2 /*return*/];
|
|
29557
|
+
});
|
|
29558
|
+
});
|
|
29559
|
+
};
|
|
29560
|
+
AppEntityEditorModal.prototype.ngAfterViewInit = function () {
|
|
29561
|
+
var _this = this;
|
|
29562
|
+
_super_1.prototype.ngAfterViewInit.call(this);
|
|
29563
|
+
if (this.onAfterModalInit) {
|
|
29564
|
+
Promise.resolve(this.onAfterModalInit(this))
|
|
29565
|
+
.then(function () { return _this.load(); });
|
|
29566
|
+
}
|
|
29567
|
+
else {
|
|
29568
|
+
this.load();
|
|
29569
|
+
}
|
|
29570
|
+
};
|
|
29571
|
+
AppEntityEditorModal.prototype.ngOnDestroy = function () {
|
|
29572
|
+
_super_1.prototype.ngOnDestroy.call(this);
|
|
29573
|
+
this.$title.complete();
|
|
29574
|
+
this.$title.unsubscribe();
|
|
29575
|
+
};
|
|
29576
|
+
AppEntityEditorModal.prototype.waitIdle = function (opts) {
|
|
29577
|
+
var _this = this;
|
|
29578
|
+
// Wait end of saving
|
|
29579
|
+
if (this.saving)
|
|
29580
|
+
return waitFor(function () { return _this.saving !== true; });
|
|
29581
|
+
return _super_1.prototype.waitIdle.call(this, opts);
|
|
29582
|
+
};
|
|
29583
|
+
AppEntityEditorModal.prototype.load = function () {
|
|
29584
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29585
|
+
var err_1;
|
|
29586
|
+
return __generator(this, function (_b) {
|
|
29587
|
+
switch (_b.label) {
|
|
29588
|
+
case 0:
|
|
29589
|
+
this.markAsReady();
|
|
29590
|
+
this.markAsLoading();
|
|
29591
|
+
_b.label = 1;
|
|
29592
|
+
case 1:
|
|
29593
|
+
_b.trys.push([1, 3, 4, 5]);
|
|
29594
|
+
return [4 /*yield*/, this.updateView(this.data)];
|
|
29595
|
+
case 2:
|
|
29596
|
+
_b.sent();
|
|
29597
|
+
return [3 /*break*/, 5];
|
|
29598
|
+
case 3:
|
|
29599
|
+
err_1 = _b.sent();
|
|
29600
|
+
this.setError(err_1);
|
|
29601
|
+
this.selectedTabIndex = 0;
|
|
29602
|
+
return [3 /*break*/, 5];
|
|
29603
|
+
case 4:
|
|
29604
|
+
this.markAsPristine();
|
|
29605
|
+
this.markAsLoaded();
|
|
29606
|
+
return [7 /*endfinally*/];
|
|
29607
|
+
case 5: return [2 /*return*/];
|
|
29608
|
+
}
|
|
29609
|
+
});
|
|
29610
|
+
});
|
|
29611
|
+
};
|
|
29612
|
+
AppEntityEditorModal.prototype.reload = function () {
|
|
29613
|
+
if (this.dirty) {
|
|
29614
|
+
return this.load();
|
|
29615
|
+
}
|
|
29616
|
+
};
|
|
29617
|
+
AppEntityEditorModal.prototype.unload = function (opts) {
|
|
29618
|
+
throw new Error("No implemented on modal");
|
|
29619
|
+
};
|
|
29620
|
+
AppEntityEditorModal.prototype.updateView = function (data, opts) {
|
|
29621
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29622
|
+
return __generator(this, function (_b) {
|
|
29623
|
+
switch (_b.label) {
|
|
29624
|
+
case 0:
|
|
29625
|
+
this.resetError();
|
|
29626
|
+
if (!this.data)
|
|
29627
|
+
throw { code: ErrorCodes.DATA_NOT_FOUND_ERROR, message: 'ERROR.DATA_NO_FOUND' };
|
|
29628
|
+
return [4 /*yield*/, this.setValue(data)];
|
|
29629
|
+
case 1:
|
|
29630
|
+
_b.sent();
|
|
29631
|
+
if (!opts || opts.emitEvent !== false) {
|
|
29632
|
+
this.markAsPristine();
|
|
29633
|
+
this.markAsUntouched();
|
|
29634
|
+
this.updateViewState(data);
|
|
29635
|
+
// Update the title.
|
|
29636
|
+
this.updateTitle(data);
|
|
29637
|
+
}
|
|
29638
|
+
return [2 /*return*/];
|
|
29639
|
+
}
|
|
29640
|
+
});
|
|
29641
|
+
});
|
|
29642
|
+
};
|
|
29643
|
+
/**
|
|
29644
|
+
* Enable or disable state
|
|
29645
|
+
*/
|
|
29646
|
+
AppEntityEditorModal.prototype.updateViewState = function (data, opts) {
|
|
29647
|
+
if (this.isNewData || this.enabled) {
|
|
29648
|
+
this.enable(opts);
|
|
29649
|
+
}
|
|
29650
|
+
else {
|
|
29651
|
+
this.disable(opts);
|
|
29652
|
+
// Allow to sort table
|
|
29653
|
+
this.tables.forEach(function (t) { return t.enableSort(); });
|
|
29654
|
+
}
|
|
29655
|
+
};
|
|
29656
|
+
AppEntityEditorModal.prototype.saveAndClose = function (event) {
|
|
29657
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29658
|
+
var data;
|
|
29659
|
+
return __generator(this, function (_b) {
|
|
29660
|
+
switch (_b.label) {
|
|
29661
|
+
case 0: return [4 /*yield*/, this.saveAndGetDataIfValid()];
|
|
29662
|
+
case 1:
|
|
29663
|
+
data = _b.sent();
|
|
29664
|
+
if (data) {
|
|
29665
|
+
this.modalCtrl.dismiss(data);
|
|
29666
|
+
return [2 /*return*/, true];
|
|
29667
|
+
}
|
|
29668
|
+
return [2 /*return*/, false];
|
|
29669
|
+
}
|
|
29670
|
+
});
|
|
29671
|
+
});
|
|
29672
|
+
};
|
|
29673
|
+
AppEntityEditorModal.prototype.close = function (event) {
|
|
29674
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29675
|
+
var saveBeforeLeave;
|
|
29676
|
+
return __generator(this, function (_b) {
|
|
29677
|
+
switch (_b.label) {
|
|
29678
|
+
case 0:
|
|
29679
|
+
if (!this.dirty) return [3 /*break*/, 3];
|
|
29680
|
+
return [4 /*yield*/, Alerts.askSaveBeforeLeave(this.alertCtrl, this.translate, event)];
|
|
29681
|
+
case 1:
|
|
29682
|
+
saveBeforeLeave = _b.sent();
|
|
29683
|
+
// User cancelled
|
|
29684
|
+
if (isNil(saveBeforeLeave) || event && event.defaultPrevented) {
|
|
29685
|
+
return [2 /*return*/];
|
|
29686
|
+
}
|
|
29687
|
+
if (!(saveBeforeLeave === true)) return [3 /*break*/, 3];
|
|
29688
|
+
return [4 /*yield*/, this.saveAndClose(event)];
|
|
29689
|
+
case 2:
|
|
29690
|
+
_b.sent();
|
|
29691
|
+
return [2 /*return*/];
|
|
29692
|
+
case 3: return [4 /*yield*/, this.modalCtrl.dismiss()];
|
|
29693
|
+
case 4:
|
|
29694
|
+
_b.sent();
|
|
29695
|
+
return [2 /*return*/];
|
|
29696
|
+
}
|
|
29697
|
+
});
|
|
29698
|
+
});
|
|
29699
|
+
};
|
|
29700
|
+
/**
|
|
29701
|
+
* Save the editor, by calling the dataService.save().
|
|
29702
|
+
* Ensure that editor if valid. If not, display an error
|
|
29703
|
+
* @param event
|
|
29704
|
+
* @param opts
|
|
29705
|
+
*/
|
|
29706
|
+
AppEntityEditorModal.prototype.save = function (event, opts) {
|
|
29707
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29708
|
+
var saved, _b, err_2;
|
|
29709
|
+
return __generator(this, function (_c) {
|
|
29710
|
+
switch (_c.label) {
|
|
29711
|
+
case 0:
|
|
29712
|
+
if (this.loading || this.saving || this.disabled) {
|
|
29713
|
+
console.debug(this._logPrefix + 'Skip save: modal is busy (loading or saving)');
|
|
29714
|
+
return [2 /*return*/, false];
|
|
29715
|
+
}
|
|
29716
|
+
if (!this.dirty) {
|
|
29717
|
+
console.debug(this._logPrefix + 'Skip save: modal not dirty');
|
|
29718
|
+
return [2 /*return*/, true];
|
|
29719
|
+
}
|
|
29720
|
+
// Wait end of async validation
|
|
29721
|
+
return [4 /*yield*/, this.waitWhilePending()];
|
|
29722
|
+
case 1:
|
|
29723
|
+
// Wait end of async validation
|
|
29724
|
+
_c.sent();
|
|
29725
|
+
// If invalid
|
|
29726
|
+
if (this.invalid) {
|
|
29727
|
+
this.logFormErrors();
|
|
29728
|
+
this.setError('COMMON.FORM.HAS_ERROR');
|
|
29729
|
+
this.markAllAsTouched();
|
|
29730
|
+
this.openFirstInvalidTab();
|
|
29731
|
+
this.scrollToTop();
|
|
29732
|
+
this.submitted = true;
|
|
29733
|
+
return [2 /*return*/, false];
|
|
29734
|
+
}
|
|
29735
|
+
this.markAsSaving();
|
|
29736
|
+
this.resetError();
|
|
29737
|
+
if (this.debug)
|
|
29738
|
+
console.debug(this._logPrefix + 'Saving data...');
|
|
29739
|
+
_c.label = 2;
|
|
29740
|
+
case 2:
|
|
29741
|
+
_c.trys.push([2, 4, 5, 6]);
|
|
29742
|
+
saved = Promise.all((this.tables || [])
|
|
29743
|
+
.filter(function (c) { return c.dirty; })
|
|
29744
|
+
.map(function (c) { return c.save(); }))
|
|
29745
|
+
.then(function (res) { return res.findIndex(function (r) { return r !== true; }) === -1; });
|
|
29746
|
+
_b = this;
|
|
29747
|
+
return [4 /*yield*/, this.getValue()];
|
|
29748
|
+
case 3:
|
|
29749
|
+
_b.data = _c.sent();
|
|
29750
|
+
this.submitted = true;
|
|
29751
|
+
return [2 /*return*/, saved];
|
|
29752
|
+
case 4:
|
|
29753
|
+
err_2 = _c.sent();
|
|
29754
|
+
this.submitted = true;
|
|
29755
|
+
this.setError(err_2);
|
|
29756
|
+
this.selectedTabIndex = 0;
|
|
29757
|
+
this.scrollToTop(); // Scroll to top (to show error)
|
|
29758
|
+
this.markAsDirty();
|
|
29759
|
+
this.enable();
|
|
29760
|
+
return [2 /*return*/, false];
|
|
29761
|
+
case 5:
|
|
29762
|
+
this.markAsSaved();
|
|
29763
|
+
return [7 /*endfinally*/];
|
|
29764
|
+
case 6: return [2 /*return*/];
|
|
29765
|
+
}
|
|
29766
|
+
});
|
|
29767
|
+
});
|
|
29768
|
+
};
|
|
29769
|
+
/**
|
|
29770
|
+
* Save data (if dirty and valid), and return it. Otherwise, return nil value.
|
|
29771
|
+
*/
|
|
29772
|
+
AppEntityEditorModal.prototype.saveAndGetDataIfValid = function () {
|
|
29773
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29774
|
+
var saved;
|
|
29775
|
+
return __generator(this, function (_b) {
|
|
29776
|
+
switch (_b.label) {
|
|
29777
|
+
case 0:
|
|
29778
|
+
if (!!this.valid) return [3 /*break*/, 2];
|
|
29779
|
+
// Make sure validation is finished
|
|
29780
|
+
return [4 /*yield*/, AppFormUtils.waitWhilePending(this)];
|
|
29781
|
+
case 1:
|
|
29782
|
+
// Make sure validation is finished
|
|
29783
|
+
_b.sent();
|
|
29784
|
+
// If invalid: Open the first tab in error
|
|
29785
|
+
if (this.invalid) {
|
|
29786
|
+
this.openFirstInvalidTab();
|
|
29787
|
+
return [2 /*return*/, undefined];
|
|
29788
|
+
}
|
|
29789
|
+
_b.label = 2;
|
|
29790
|
+
case 2:
|
|
29791
|
+
if (!this.dirty) return [3 /*break*/, 4];
|
|
29792
|
+
return [4 /*yield*/, this.save(new Event('save'))];
|
|
29793
|
+
case 3:
|
|
29794
|
+
saved = _b.sent();
|
|
29795
|
+
if (!saved)
|
|
29796
|
+
return [2 /*return*/, undefined];
|
|
29797
|
+
_b.label = 4;
|
|
29798
|
+
case 4:
|
|
29799
|
+
// Valid and saved data
|
|
29800
|
+
return [2 /*return*/, this.data];
|
|
29801
|
+
}
|
|
29802
|
+
});
|
|
29803
|
+
});
|
|
29804
|
+
};
|
|
29805
|
+
AppEntityEditorModal.prototype.delete = function (event) {
|
|
29806
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29807
|
+
var result, err_3;
|
|
29808
|
+
return __generator(this, function (_b) {
|
|
29809
|
+
switch (_b.label) {
|
|
29810
|
+
case 0:
|
|
29811
|
+
if (this.loading || this.saving)
|
|
29812
|
+
return [2 /*return*/, false];
|
|
29813
|
+
this.markAsSaving();
|
|
29814
|
+
this.resetError();
|
|
29815
|
+
_b.label = 1;
|
|
29816
|
+
case 1:
|
|
29817
|
+
_b.trys.push([1, 8, , 9]);
|
|
29818
|
+
if (!this.onDelete) return [3 /*break*/, 5];
|
|
29819
|
+
return [4 /*yield*/, this.onDelete(event, this.data)];
|
|
29820
|
+
case 2:
|
|
29821
|
+
result = _b.sent();
|
|
29822
|
+
// User cancelled
|
|
29823
|
+
if (isNil(result) || (event && event.defaultPrevented))
|
|
29824
|
+
return [2 /*return*/];
|
|
29825
|
+
if (!result) return [3 /*break*/, 4];
|
|
29826
|
+
return [4 /*yield*/, this.modalCtrl.dismiss(this.data, 'delete')];
|
|
29827
|
+
case 3:
|
|
29828
|
+
_b.sent();
|
|
29829
|
+
_b.label = 4;
|
|
29830
|
+
case 4: return [3 /*break*/, 7];
|
|
29831
|
+
case 5:
|
|
29832
|
+
if (this.isNewData) {
|
|
29833
|
+
console.error(this._logPrefix + "Trying to delete a new data. Make no sense!");
|
|
29834
|
+
}
|
|
29835
|
+
return [4 /*yield*/, this.modalCtrl.dismiss(this.data, 'delete')];
|
|
29836
|
+
case 6:
|
|
29837
|
+
_b.sent();
|
|
29838
|
+
_b.label = 7;
|
|
29839
|
+
case 7: return [3 /*break*/, 9];
|
|
29840
|
+
case 8:
|
|
29841
|
+
err_3 = _b.sent();
|
|
29842
|
+
this.submitted = true;
|
|
29843
|
+
this.setError(err_3);
|
|
29844
|
+
this.selectedTabIndex = 0;
|
|
29845
|
+
this.markAsSaved();
|
|
29846
|
+
if (this.enabled)
|
|
29847
|
+
this.enable();
|
|
29848
|
+
return [2 /*return*/, false];
|
|
29849
|
+
case 9: return [2 /*return*/];
|
|
29850
|
+
}
|
|
29851
|
+
});
|
|
29852
|
+
});
|
|
29853
|
+
};
|
|
29854
|
+
AppEntityEditorModal.prototype.resetError = function (opts) {
|
|
29855
|
+
if (isNotNilOrBlank(this.error)) {
|
|
29856
|
+
this.error = null;
|
|
29857
|
+
if (!opts || opts.emitEvent !== false)
|
|
29858
|
+
this.markForCheck();
|
|
29859
|
+
}
|
|
29860
|
+
};
|
|
29861
|
+
AppEntityEditorModal.prototype.setError = function (err, opts) {
|
|
29862
|
+
if (!err) {
|
|
29863
|
+
this.error = undefined;
|
|
29864
|
+
}
|
|
29865
|
+
else if (typeof err === 'string') {
|
|
29866
|
+
console.error('[entity-editor] Error: ' + (err || ''));
|
|
29867
|
+
this.error = err;
|
|
29868
|
+
}
|
|
29869
|
+
else {
|
|
29870
|
+
console.error('[entity-editor] Error: ' + err.message || '', err);
|
|
29871
|
+
var userMessage = err.message && this.translate.instant(err.message) || err;
|
|
29872
|
+
// Add details error (if any) under the main message
|
|
29873
|
+
var detailMessage = (!err.details || typeof err.details === 'string')
|
|
29874
|
+
? err.details
|
|
29875
|
+
: err.details.message;
|
|
29876
|
+
if (isNotNilOrBlank(detailMessage)) {
|
|
29877
|
+
var cssClass = (opts === null || opts === void 0 ? void 0 : opts.detailsCssClass) || 'hidden-xs hidden-sm';
|
|
29878
|
+
userMessage += "<br/><small class=\"" + cssClass + "\" title=\"" + detailMessage + "\">";
|
|
29879
|
+
userMessage += detailMessage.length < 70 ? detailMessage : detailMessage.substring(0, 67) + '...';
|
|
29880
|
+
userMessage += '</small>';
|
|
29881
|
+
}
|
|
29882
|
+
this.error = userMessage;
|
|
29883
|
+
}
|
|
29884
|
+
if (!opts || opts.emitEvent !== false)
|
|
29885
|
+
this.markForCheck();
|
|
29886
|
+
};
|
|
29887
|
+
/* -- protected methods -- */
|
|
29888
|
+
AppEntityEditorModal.prototype.waitWhilePending = function (opts) {
|
|
29889
|
+
return AppFormUtils.waitWhilePending(this, opts);
|
|
29890
|
+
};
|
|
29891
|
+
AppEntityEditorModal.prototype.getValue = function () {
|
|
29892
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29893
|
+
var json, res;
|
|
29894
|
+
return __generator(this, function (_b) {
|
|
29895
|
+
switch (_b.label) {
|
|
29896
|
+
case 0: return [4 /*yield*/, this.getJsonValueToSave()];
|
|
29897
|
+
case 1:
|
|
29898
|
+
json = _b.sent();
|
|
29899
|
+
res = new this.dataType();
|
|
29900
|
+
res.fromObject(json);
|
|
29901
|
+
return [2 /*return*/, res];
|
|
29902
|
+
}
|
|
29903
|
+
});
|
|
29904
|
+
});
|
|
29905
|
+
};
|
|
29906
|
+
AppEntityEditorModal.prototype.getJsonValueToSave = function () {
|
|
29907
|
+
return Promise.resolve(this.form.value);
|
|
29908
|
+
};
|
|
29909
|
+
/**
|
|
29910
|
+
* Compute the title
|
|
29911
|
+
*
|
|
29912
|
+
* @param data
|
|
29913
|
+
*/
|
|
29914
|
+
AppEntityEditorModal.prototype.updateTitle = function (data) {
|
|
29915
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29916
|
+
var title;
|
|
29917
|
+
return __generator(this, function (_b) {
|
|
29918
|
+
switch (_b.label) {
|
|
29919
|
+
case 0:
|
|
29920
|
+
data = data || this.data;
|
|
29921
|
+
return [4 /*yield*/, this.computeTitle(data)];
|
|
29922
|
+
case 1:
|
|
29923
|
+
title = _b.sent();
|
|
29924
|
+
this.$title.next(title);
|
|
29925
|
+
return [2 /*return*/];
|
|
29926
|
+
}
|
|
29927
|
+
});
|
|
29928
|
+
});
|
|
29929
|
+
};
|
|
29930
|
+
AppEntityEditorModal.prototype.scrollToTop = function (duration) {
|
|
29931
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
29932
|
+
return __generator(this, function (_b) {
|
|
29933
|
+
if (this.content) {
|
|
29934
|
+
return [2 /*return*/, this.content.scrollToTop(duration)];
|
|
29935
|
+
}
|
|
29936
|
+
return [2 /*return*/];
|
|
29937
|
+
});
|
|
29938
|
+
});
|
|
29939
|
+
};
|
|
29940
|
+
AppEntityEditorModal.prototype.markForCheck = function () {
|
|
29941
|
+
var _a;
|
|
29942
|
+
(_a = this.cd) === null || _a === void 0 ? void 0 : _a.markForCheck();
|
|
29943
|
+
};
|
|
29944
|
+
/* -- private functions -- */
|
|
29945
|
+
/**
|
|
29946
|
+
* Open the first tab that is invalid
|
|
29947
|
+
*/
|
|
29948
|
+
AppEntityEditorModal.prototype.openFirstInvalidTab = function () {
|
|
29949
|
+
var invalidTabIndex = this.getFirstInvalidTabIndex();
|
|
29950
|
+
if (invalidTabIndex !== -1 && this.selectedTabIndex !== invalidTabIndex) {
|
|
29951
|
+
this.selectedTabIndex = invalidTabIndex;
|
|
29952
|
+
this.markForCheck();
|
|
29953
|
+
}
|
|
29954
|
+
};
|
|
29955
|
+
return AppEntityEditorModal;
|
|
29956
|
+
}(AppTabEditor));
|
|
29957
|
+
AppEntityEditorModal.decorators = [
|
|
29958
|
+
{ type: i0.Directive }
|
|
29959
|
+
];
|
|
29960
|
+
AppEntityEditorModal.ctorParameters = function () { return [
|
|
29961
|
+
{ type: i0.Injector },
|
|
29962
|
+
{ type: Function },
|
|
29963
|
+
{ type: undefined, decorators: [{ type: i0.Optional }] }
|
|
29964
|
+
]; };
|
|
29965
|
+
AppEntityEditorModal.propDecorators = {
|
|
29966
|
+
data: [{ type: i0.Input }],
|
|
29967
|
+
mobile: [{ type: i0.Input }],
|
|
29968
|
+
usageMode: [{ type: i0.Input }],
|
|
29969
|
+
onAfterModalInit: [{ type: i0.Input }],
|
|
29970
|
+
onDelete: [{ type: i0.Input }],
|
|
29971
|
+
i18nSuffix: [{ type: i0.Input }],
|
|
29972
|
+
isNewData: [{ type: i0.Input }],
|
|
29973
|
+
disabled: [{ type: i0.Input }]
|
|
29974
|
+
};
|
|
29975
|
+
|
|
29454
29976
|
// @dynamic
|
|
29455
29977
|
// eslint-disable-next-line @angular-eslint/directive-class-suffix
|
|
29456
29978
|
var AppInMemoryTable = /** @class */ (function (_super) {
|
|
@@ -32521,6 +33043,8 @@
|
|
|
32521
33043
|
exports.AppEditor = AppEditor;
|
|
32522
33044
|
exports.AppEditorOptions = AppEditorOptions;
|
|
32523
33045
|
exports.AppEntityEditor = AppEntityEditor;
|
|
33046
|
+
exports.AppEntityEditorModal = AppEntityEditorModal;
|
|
33047
|
+
exports.AppEntityEditorModalOptions = AppEntityEditorModalOptions;
|
|
32524
33048
|
exports.AppForm = AppForm;
|
|
32525
33049
|
exports.AppFormField = AppFormField;
|
|
32526
33050
|
exports.AppFormProvider = AppFormProvider;
|