UNPKG

ferngully-aurelia-tools

Version:

Ferngully Tools for Aurelia

334 lines 18.8 kB
System.register(["aurelia-framework", "aurelia-dialog", "../dialog-service", "./form-schema-service", "./form-schema-crud-service", "aurelia-event-aggregator", "../notification-service/notification-service", "../sort-column-service", "aurelia-i18n", "aurelia-validation"], function (exports_1, context_1) { "use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __moduleName = context_1 && context_1.id; var aurelia_framework_1, aurelia_dialog_1, dialog_service_1, form_schema_service_1, form_schema_crud_service_1, aurelia_event_aggregator_1, notification_service_1, sort_column_service_1, aurelia_i18n_1, FormSchemaCollectionController; return { setters: [ function (aurelia_framework_1_1) { aurelia_framework_1 = aurelia_framework_1_1; }, function (aurelia_dialog_1_1) { aurelia_dialog_1 = aurelia_dialog_1_1; }, function (dialog_service_1_1) { dialog_service_1 = dialog_service_1_1; }, function (form_schema_service_1_1) { form_schema_service_1 = form_schema_service_1_1; }, function (form_schema_crud_service_1_1) { form_schema_crud_service_1 = form_schema_crud_service_1_1; }, function (aurelia_event_aggregator_1_1) { aurelia_event_aggregator_1 = aurelia_event_aggregator_1_1; }, function (notification_service_1_1) { notification_service_1 = notification_service_1_1; }, function (sort_column_service_1_1) { sort_column_service_1 = sort_column_service_1_1; }, function (aurelia_i18n_1_1) { aurelia_i18n_1 = aurelia_i18n_1_1; }, function (aurelia_validation_1_1) { exports_1({ "ValidateResult": aurelia_validation_1_1["ValidateResult"] }); } ], execute: function () { FormSchemaCollectionController = (function () { function FormSchemaCollectionController(commonDialogs, sortColumnService, dialogService, notificationService, formSchemaService, formSchemaCrudService, i18n, webServiceName) { this.commonDialogs = commonDialogs; this.sortColumnService = sortColumnService; this.dialogService = dialogService; this.notificationService = notificationService; this.formSchemaService = formSchemaService; this.formSchemaCrudService = formSchemaCrudService; this.i18n = i18n; this.showing = true; this.disableNew = false; this.disableDelete = false; this.showKeyColumn = false; this._makingLocalChanges = false; this._loaded = false; this.insertOnNew = false; this.refreshDatumOnUpdate = false; aurelia_event_aggregator_1.includeEventsIn(this); formSchemaService.webServiceName = formSchemaCrudService.webServiceName = webServiceName; } Object.defineProperty(FormSchemaCollectionController.prototype, "makingLocalChanges", { get: function () { return this._makingLocalChanges; }, set: function (value) { var _this = this; if (value) { this._makingLocalChanges = true; } else { setTimeout(function () { _this._makingLocalChanges = false; }, 0); } }, enumerable: true, configurable: true }); FormSchemaCollectionController.prototype.clearMakingLocalChanges = function (delay) { var _this = this; if (delay === void 0) { delay = 0; } return new Promise(function (resolve, reject) { setTimeout(function () { _this._makingLocalChanges = false; resolve(); }, delay); }); }; FormSchemaCollectionController.prototype.load = function (andFetch) { var _this = this; if (andFetch === void 0) { andFetch = true; } if (this.promiseToBeLoaded) { return this.promiseToBeLoaded; } var eventName; if (!this._loaded) { var promises = []; if (andFetch) { promises.push(this.getInstances()); } promises.push(this.getFormSchema()); eventName = "loaded"; this.promiseToBeLoaded = Promise.all(promises) .then(function (instances) { if (_this.rulesGenerator) { _this.rulesGenerator.generateValidationRules(_this.formSchema, _this.showKeyColumn); } return _this.instances; }); } else { eventName = "refetched"; this.promiseToBeLoaded = this.getInstances(); } return this.promiseToBeLoaded.then(function (instances) { _this.promiseToBeLoaded = undefined; _this._loaded = true; _this.publish(eventName); return _this.instances; }); }; FormSchemaCollectionController.prototype.getInstances = function () { var _this = this; return this.formSchemaCrudService.getAll().then(function (data) { _this.instances = data; }); }; FormSchemaCollectionController.prototype.getFormSchema = function () { var _this = this; return this.formSchemaService.getFormSchema() .then(function (schema) { _this.className = schema.name; _this.key = schema.key; return _this.formSchema = schema; }); }; FormSchemaCollectionController.prototype.preValidate = function (instance, propertyName, newValue, oldValue) { }; FormSchemaCollectionController.prototype._preValidate = function (instance, propertyName, newValue, oldValue) { this.makingLocalChanges = true; this.preValidate(instance, propertyName, newValue, oldValue); return this.clearMakingLocalChanges(); }; FormSchemaCollectionController.prototype.validate = function (instance, propertyName, newValue, oldValue) { var _this = this; if (this.validationService) { return this._preValidate(instance, propertyName, newValue, oldValue) .then(function () { return _this.validationService.isValid(instance); }); } else return Promise.resolve(false); }; FormSchemaCollectionController.prototype.registerInstances = function (instances) { if (this.validationService) { this.validationService.registerInstances(instances, this.rulesGenerator.validationRules); } }; FormSchemaCollectionController.prototype.unRegisterInstances = function (instances) { if (this.validationService) { this.validationService.unRegisterInstances(instances); } }; FormSchemaCollectionController.prototype.revalidateAll = function () { if (this.validationService) { return this.validationService.validate(); } else return Promise.resolve([]); }; FormSchemaCollectionController.prototype.handleUpdate = function (instance, propertyName, newValue, oldValue) { var _this = this; if (this.makingLocalChanges) { return Promise.resolve(false); } if (this.validationService) { return this.validate(instance, propertyName, newValue, oldValue) .then(function (isValid) { if (isValid) { return _this.executeUpdate(instance, propertyName, newValue, oldValue); } else { return Promise.resolve(false); } }); } else { return this.executeUpdate(instance, propertyName, newValue, oldValue); } }; FormSchemaCollectionController.prototype.executeUpdate = function (instance, propertyName, newValue, oldValue) { var _this = this; var dlgTitle = this.i18n.tr('Update') + " " + this.className; var recordIdentication = this.recordIdentication(instance); return this.formSchemaCrudService.update(instance[this.key], instance, propertyName, newValue, oldValue) .then(function (result) { if (result.Success) { var newInstance = result.Data; if (_this.refreshDatumOnUpdate) { _this.makingLocalChanges = true; Object.assign(instance, newInstance); _this.makingLocalChanges = false; } _this.notificationService .success(recordIdentication + " was updated"); _this.publish("changed"); _this.publish("modified", { instance: instance, propertyName: propertyName, newValue: newValue, oldValue: oldValue }); return Promise.resolve(true); } else { return _this.commonDialogs.prompt({ title: dlgTitle, text: _this.i18n.tr('formSchemaUpdateError', { 'className': _this.className, 'propertyName': propertyName, 'ErrorMessage': result.ErrorMessage }), ok: true }) .then(function () { _this.makingLocalChanges = true; instance[propertyName] = oldValue; _this.makingLocalChanges = false; return false; }); } }); }; FormSchemaCollectionController.prototype.handleCreate = function () { return this.formSchemaCrudService.create(); }; FormSchemaCollectionController.prototype.handleNew = function (instance) { var _this = this; var dlgTitle = this.i18n.tr('CreateNew') + " " + this.className; return this.formSchemaCrudService.insert(instance).then(function (result) { if (!result.Success) { return _this.commonDialogs.prompt({ title: dlgTitle, text: _this.i18n.tr('formSchemaNewError', { 'className': _this.className, 'ErrorMessage': result.ErrorMessage }), ok: true }) .then(function () { return null; }); } else { var newInstance = result.Data; _this.notificationService .success("A new " + _this.className + " was added"); _this.publish("changed"); _this.publish("entered", { instance: newInstance }); return newInstance; } }); }; FormSchemaCollectionController.prototype.handleDelete = function (instance) { var _this = this; var dlgTitle = this.i18n.tr('Delete') + " " + this.className; var id = instance[this.key]; var recordIdentication = this.recordIdentication(instance); return this.commonDialogs.prompt({ title: dlgTitle, text: this.i18n.tr('formSchemaConfirmDelete', { 'recordIdentication': recordIdentication }), yesNo: true }) .then(function (response) { if (!response.wasCancelled) { if (id === 0) { return Promise.resolve(true); } return _this.formSchemaCrudService.delete(id).then(function (result) { if (result.Success) { _this.notificationService .success(recordIdentication + " was deleted"); _this.publish("changed"); _this.publish("exited", { instance: instance }); return true; } else { return _this.commonDialogs.prompt({ title: dlgTitle, text: _this.i18n.tr('formSchemaConfirmDelete', { 'recordIdentication': recordIdentication, 'ErrorMessage': result.ErrorMessage }), ok: true }) .then(function () { return false; }); } }); } else { return Promise.resolve(false); } }); }; FormSchemaCollectionController.prototype.fetchInstance = function (instance) { var key = instance[this.formSchema.key]; return this.formSchemaCrudService.get(key).then(function (newInstance) { return newInstance; }); }; FormSchemaCollectionController.prototype.recordIdentication = function (instance) { if (this.formSchema.identifierPropertyName) { return "'" + instance[this.formSchema.identifierPropertyName] + "'"; } else { return this.i18n.tr("theData"); } }; FormSchemaCollectionController = __decorate([ aurelia_framework_1.inject(dialog_service_1.CommonDialogs, sort_column_service_1.SortColumnService, aurelia_dialog_1.DialogService, notification_service_1.NotificationService, form_schema_service_1.FormSchemaService, form_schema_crud_service_1.FormSchemaCrudService, aurelia_i18n_1.I18N), aurelia_framework_1.transient(), __metadata("design:paramtypes", [dialog_service_1.CommonDialogs, Object, aurelia_dialog_1.DialogService, notification_service_1.NotificationService, Object, Object, aurelia_i18n_1.I18N, String]) ], FormSchemaCollectionController); return FormSchemaCollectionController; }()); exports_1("FormSchemaCollectionController", FormSchemaCollectionController); } }; }); //# sourceMappingURL=form-schema-collection-controller.js.map