UNPKG

com.phloxui

Version:

PhloxUI Ng2+ Framework

1,334 lines 194 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ import * as tslib_1 from "tslib"; import { EventEmitter } from '@angular/core'; import { PhloxAppInfo } from '../model/models'; import { DataSchema } from '../../share/model/models'; import { DefaultDataComparator } from '../../component/DefaultDataComparator'; import { DefaultDataEditorContextMenuFactory } from './DefaultDataEditorContextMenuFactory'; import { DATA_CREATE_EVENT, DATA_UPDATE_EVENT, DATA_DELETE_EVENT, DATA_REVERT_EVENT, DATA_SCHEMA_LOAD_EVENT } from '../../share/CustomEventType'; import { Option } from '../../decorator/Option.decorator'; import { AbstractI18NApplicable } from '../../share/AbstractI18NApplicable'; import { DataUtils } from '../../share/utils/DataUtils'; import { EventUtils } from '../../share/utils/EventUtils'; import { I18N } from '../../decorator/decorators'; var /** @type {?} */ CONFIG_NAME = 'com.phlox-ui.dataEditor'; /** * <p style="text-indent: 2em;"> * An abstract base class for <code>data editor</code> page component. A single <code>data editor</code> may contain one or more <code>data view</code>s ([[ViewModel]]). * All <code>data view</code>s must manipulate with the same data set in that editor. For an instance, when a user edit data from one view and switch to another view, the data * shown in the second view must always be identical the same as the first one. An editor may contain a set of <code>action</code>s ([[ActionModel]]) which user can perform * on editor's data. For more information about creating your own editor page, please see the documentation below. * </p> * <section style="padding-top: 7pt;"> * <header style="font-weight: bold;"> * Data View * </header> * <p style="text-indent: 2em;"> * To specify the list of views in an editor, you have to provide a <code>view provider</code> ([[IDataEditorViewProvider]]) into editor's constructor. The editor's constructor * will call [[IDataEditorViewProvider.getViewModels]] to obtain the list of <code>data view</code>s being displayed in this editor. The concept behind <code>data view</code> is that * to provide user the different perspectives on the same data set. For example, if you're going to build a customer data editor page, you may want to provide user a <code>list view</code> * which allows user to easily search a customer by typing into search text box, then, it'll show customer data in tabular form. Therefore, in some sense, you may want to provide * a <code>calendar view</code> displaying customer's birth date to the user --letting he/she to take less efforts on organizing a CRM work plan. For this kind of use, using <code> * data view</code>, instead of building seperate pages, is the best choice to build your application. * </p> * </section> * <section style="padding-top: 7pt;"> * <header style="font-weight: bold;"> * Action * </header> * <p style="text-indent: 2em;"> * abcdef * </p> * </section> * * @author shiorin, tee4cute * @see [[ViewModel]] * @see [[ActionModel]] * @see [[IDataEditorViewProvider]] * @see [[IDataEditorActionProvider]] * @see [[IDataServiceFactory]] * @abstract */ var AbstractDataEditor = /** @class */ (function (_super) { tslib_1.__extends(AbstractDataEditor, _super); function AbstractDataEditor(actionProvider, viewProvider, dataFactory, settingServiceFactory, phloxAppService, dialogService, bgProcessMgr) { var _this = _super.call(this) || this; _this.PAGE_LOOP_TIMEOUT = 5; _this.data = []; _this.dialogService = dialogService; _this.bgProcessMgr = bgProcessMgr; _this.dataServiceFactory = dataFactory; _this.viewProvider = viewProvider; _this.actionProvider = actionProvider; _this.settingServiceFactory = settingServiceFactory; _this.phloxAppService = phloxAppService; _this.views = []; _this.viewModels = []; _this.actionModels = []; _this.viewWrappers = []; _this.dataCreateEvent = new EventEmitter(); _this.dataUpdateEvent = new EventEmitter(); _this.dataDeleteEvent = new EventEmitter(); _this.dataRevertEvent = new EventEmitter(); _this.dataQueryEvent = new EventEmitter(); _this.viewShowEvent = new EventEmitter(); _this.viewHideEvent = new EventEmitter(); _this.viewChangeEvent = new EventEmitter(); _this.dataReloadEvent = new EventEmitter(); _this.dataSchemaLoadEvent = new EventEmitter(); _this.viewShowHandlerFunction = function (event) { _this.onViewShowHandler(event); }; _this.viewHideHandlerFunction = function (event) { _this.onViewHideHandler(event); }; _this.viewChangeHandlerFunction = function (event) { _this.onViewChangeHandler(event); }; return _this; } /** * @return {?} */ AbstractDataEditor.prototype.ngOnInit = /** * @return {?} */ function () { var _this = this; if (this.menuModelFactory == null || typeof this.menuModelFactory === 'undefined') { this.menuModelFactory = new DefaultDataEditorContextMenuFactory(this); } if (this.dataComparator == null || typeof this.dataComparator === 'undefined') { this.dataComparator = new DefaultDataComparator(); } this.initPage(); //loader if (this.bgProcessMgr !== null && typeof this.bgProcessMgr !== 'undefined') { this.bgProcessMgr.execute(function () { return new Promise(function (resolve, reject) { var /** @type {?} */ timeout = PhloxAppInfo.DEFAULT_PAGE_LOAD_TIMEOUT; if (_this.phloxAppInfo !== null && typeof _this.phloxAppInfo !== 'undefined' && _this.phloxAppInfo.settings.PAGE_LOAD_TIMEOUT !== null && typeof _this.phloxAppInfo.settings.PAGE_LOAD_TIMEOUT !== 'undefined') { timeout = _this.phloxAppInfo.settings.PAGE_LOAD_TIMEOUT; } var /** @type {?} */ startTime = null; var /** @type {?} */ handler = function () { if (startTime === null) { startTime = (new Date()).getTime(); } var /** @type {?} */ currentTime = (new Date()).getTime(); if (_this.isPageLoaded()) { resolve(); } else if ((currentTime - startTime) >= timeout) { reject(); } else { setTimeout(handler, _this.PAGE_LOOP_TIMEOUT); } }; handler(); }); }, { type: "connection.page" }); } }; /** * @return {?} */ AbstractDataEditor.prototype.initPage = /** * @return {?} */ function () { var _this = this; if ((this.viewProvider !== null && this.viewProvider !== undefined) && this.viewProvider.getViewModels(this) != null) { this.viewProvider.getViewModels(this).then(function (result) { _this.viewModels = []; if (result !== null && result !== undefined) { try { for (var result_1 = tslib_1.__values(result), result_1_1 = result_1.next(); !result_1_1.done; result_1_1 = result_1.next()) { var item = result_1_1.value; _this.viewModels.push(item); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (result_1_1 && !result_1_1.done && (_a = result_1.return)) _a.call(result_1); } finally { if (e_1) throw e_1.error; } } } // default first one when view loaded if (_this.viewModels !== null && _this.viewModels !== undefined && _this.viewModels.length > 0) { _this.showView(_this.viewModels[0]); } var e_1, _a; }); } if ((this.actionProvider !== null && this.actionProvider !== undefined) && this.actionProvider.getActionModels(this) != null) { this.actionProvider.getActionModels(this).then(function (result) { var /** @type {?} */ actModelArray = []; if (result !== null && result !== undefined) { try { for (var result_2 = tslib_1.__values(result), result_2_1 = result_2.next(); !result_2_1.done; result_2_1 = result_2.next()) { var item = result_2_1.value; actModelArray.push(item); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (result_2_1 && !result_2_1.done && (_a = result_2.return)) _a.call(result_2); } finally { if (e_2) throw e_2.error; } } } _this.setActionModels(actModelArray); var e_2, _a; }); } if (this.dataServiceFactory !== null && this.dataServiceFactory !== undefined) { var /** @type {?} */ dfProm = this.dataServiceFactory.createDataService(this); if (dfProm != null && dfProm !== undefined) { dfProm.then(function (result) { _this.dataService = result; _this.reloadData(); }); } } if (this.settingServiceFactory !== null && this.settingServiceFactory !== undefined) { var /** @type {?} */ vhSettingProm = this.settingServiceFactory.createEditorSettingService(this); if (vhSettingProm != null && vhSettingProm !== undefined) { vhSettingProm.then(function (result) { _this.editorSetting = result; _this.reloadEditorSetting(); }); } } if (this.phloxAppService !== null && this.phloxAppService !== undefined) { this.phloxAppService.getAppInfo().then(function (result) { _this.phloxAppInfo = result; }); } }; /** * @param {?} key * @return {?} */ AbstractDataEditor.prototype.getI18NMessage = /** * @param {?} key * @return {?} */ function (key) { if (this.phloxAppInfo != null && this.phloxAppInfo.i18n != null) { if (this.phloxAppInfo.i18n[key] !== null && typeof this.phloxAppInfo.i18n[key] !== 'undefined') { return this.phloxAppInfo.i18n[key]; } } return key; }; /** * @param {?} event * @return {?} */ AbstractDataEditor.prototype.onViewShowHandler = /** * @param {?} event * @return {?} */ function (event) { // re-emit if (this.viewShowEvent !== null && typeof this.viewShowEvent !== 'undefined') { this.viewShowEvent.emit(event); } }; /** * @param {?} event * @return {?} */ AbstractDataEditor.prototype.onViewHideHandler = /** * @param {?} event * @return {?} */ function (event) { // re-emit if (this.viewHideEvent !== null && typeof this.viewHideEvent !== 'undefined') { this.viewHideEvent.emit(event); } }; /** * @param {?} event * @return {?} */ AbstractDataEditor.prototype.onViewChangeHandler = /** * @param {?} event * @return {?} */ function (event) { // re-emit if (this.viewChangeEvent !== null && typeof this.viewChangeEvent !== 'undefined') { this.viewChangeEvent.emit(event); } }; /** * @param {?} data * @return {?} */ AbstractDataEditor.prototype.removeData = /** * @param {?} data * @return {?} */ function (data) { if (data !== null && typeof data !== 'undefined') { var /** @type {?} */ objIdField = this.getObjectIdField(); var /** @type {?} */ id = DataUtils.getDataValue(objIdField, data); if (id !== null && typeof id !== 'undefined') { var /** @type {?} */ index = -1; var /** @type {?} */ count = 0; try { for (var _a = tslib_1.__values(this.data), _b = _a.next(); !_b.done; _b = _a.next()) { var tbData = _b.value; var /** @type {?} */ objId = DataUtils.getDataValue(objIdField, tbData); var /** @type {?} */ tbDataID = objId; if (id === tbDataID) { index = count; break; } count += 1; } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_3) throw e_3.error; } } if (index > -1) { this.data.splice(index, 1); return true; } } } return false; var e_3, _c; }; /** * @param {?} checkData * @return {?} */ AbstractDataEditor.prototype.getRevertData = /** * @param {?} checkData * @return {?} */ function (checkData) { if (checkData === null || typeof checkData === 'undefined') { return null; } var /** @type {?} */ comparator = this.getDataComparator(); try { for (var _a = tslib_1.__values(this.data), _b = _a.next(); !_b.done; _b = _a.next()) { var d = _b.value; // revert if (comparator !== null) { if (comparator.equals(d, checkData)) { return d; } } } } catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_4) throw e_4.error; } } return null; var e_4, _c; }; /** * @param {?} viewModel * @return {?} */ AbstractDataEditor.prototype.getViewComponentFromModel = /** * @param {?} viewModel * @return {?} */ function (viewModel) { if (viewModel === null) { return null; } try { for (var _a = tslib_1.__values(this.views), _b = _a.next(); !_b.done; _b = _a.next()) { var v = _b.value; if (v.getModel() === viewModel) { return v; } } } catch (e_5_1) { e_5 = { error: e_5_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_5) throw e_5.error; } } return null; var e_5, _c; }; /** * @param {?} actionModels * @return {?} */ AbstractDataEditor.prototype.setActionModels = /** * @param {?} actionModels * @return {?} */ function (actionModels) { this.actionModels = actionModels; }; /** * @return {?} */ AbstractDataEditor.prototype.reInit = /** * @return {?} */ function () { this.initPage(); }; /** * @return {?} */ AbstractDataEditor.prototype.getObjectIdField = /** * @return {?} */ function () { if (this.phloxAppInfo !== null && typeof this.phloxAppInfo !== 'undefined') { return this.phloxAppInfo.getSettings().OBJECT_ID_FIELD_NAME; } return PhloxAppInfo.DEFAULT_OBJECT_ID_FIELD_NAME; }; /** * @return {?} */ AbstractDataEditor.prototype.getLanguageField = /** * @return {?} */ function () { if (this.phloxAppInfo !== null && typeof this.phloxAppInfo !== 'undefined') { return this.phloxAppInfo.getSettings().LANGUAGE_FIELD_NAME; } return PhloxAppInfo.DEFAULT_LANGUAGE_FIELD_NAME; }; /** * @return {?} */ AbstractDataEditor.prototype.getAppSetting = /** * @return {?} */ function () { if (this.phloxAppInfo !== null && typeof this.phloxAppInfo !== 'undefined') { return this.phloxAppInfo.getSettings(); } return {}; }; /** * @return {?} */ AbstractDataEditor.prototype.recreateDataService = /** * @return {?} */ function () { var _this = this; return new Promise(function (resolve, reject) { if (_this.dataServiceFactory != null && typeof _this.dataServiceFactory !== 'undefined') { var /** @type {?} */ dfProm = _this.dataServiceFactory.createDataService(_this); if (dfProm != null && typeof dfProm !== 'undefined') { dfProm.then(function (result) { _this.dataService = result; resolve(_this.dataService); }); } else { resolve(_this.dataService); } } else { resolve(_this.dataService); } }).catch(function (error) { return Promise.resolve(_this.dataService); }); }; /** * @return {?} */ AbstractDataEditor.prototype.getData = /** * @return {?} */ function () { return this.data; }; /** * @return {?} */ AbstractDataEditor.prototype.getCurrentView = /** * @return {?} */ function () { return this.currentView; }; /** * @param {?} view * @return {?} */ AbstractDataEditor.prototype.getViewModelIndex = /** * @param {?} view * @return {?} */ function (view) { if (view === null || typeof view === 'undefined') { return -1; } for (var /** @type {?} */ i = 0; i < this.viewModels.length; i++) { if (view === this.viewModels[i]) { return i; } } return -1; }; /** * @param {?} viewType * @return {?} */ AbstractDataEditor.prototype.getViewComponentFromType = /** * @param {?} viewType * @return {?} */ function (viewType) { if (viewType === null) { return null; } try { for (var _a = tslib_1.__values(this.views), _b = _a.next(); !_b.done; _b = _a.next()) { var v = _b.value; if (v.getModel().type === viewType) { return v; } } } catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_6) throw e_6.error; } } return null; var e_6, _c; }; /** * @param {?} view * @return {?} */ AbstractDataEditor.prototype.showView = /** * @param {?} view * @return {?} */ function (view) { var _this = this; return new Promise(function (resolve, reject) { var /** @type {?} */ isRender = false; var /** @type {?} */ viewIndex = _this.getViewModelIndex(view); var /** @type {?} */ viewWrapper = null; if (viewIndex > -1 && viewIndex < _this.viewWrappers.length) { viewWrapper = _this.viewWrappers[viewIndex]; isRender = viewWrapper.isRender(); } if (!isRender) { if (viewWrapper !== null) { viewWrapper.render(); } // delay before show if (_this.showViewDelayTimer !== null && typeof _this.showViewDelayTimer !== 'undefined') { clearTimeout(_this.showViewDelayTimer); _this.showViewDelayTimer = null; } _this.showViewDelayTimer = setTimeout(function () { resolve(_this._showView(view)); }, 1); } else { // rendered resolve(_this._showView(view)); } }); }; /** * @param {?} view * @return {?} */ AbstractDataEditor.prototype._showView = /** * @param {?} view * @return {?} */ function (view) { try { for (var _a = tslib_1.__values(this.views), _b = _a.next(); !_b.done; _b = _a.next()) { var v = _b.value; v._doHide(); } } catch (e_7_1) { e_7 = { error: e_7_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_7) throw e_7.error; } } var /** @type {?} */ viewCompo = this.getViewComponentFromModel(view); this.currentView = viewCompo; if (viewCompo !== null) { return viewCompo._doShow(); } return false; var e_7, _c; }; /** * @param {?} objId * @return {?} */ AbstractDataEditor.prototype.getDataFromObjectId = /** * @param {?} objId * @return {?} */ function (objId) { if (objId === null || typeof objId === 'undefined') { return null; } var /** @type {?} */ objIdField = this.getObjectIdField(); try { for (var _a = tslib_1.__values(this.data), _b = _a.next(); !_b.done; _b = _a.next()) { var d = _b.value; var /** @type {?} */ dId = DataUtils.getDataValue(objIdField, d); if (objId === dId) { return d; } } } catch (e_8_1) { e_8 = { error: e_8_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_8) throw e_8.error; } } return null; var e_8, _c; }; /** * @param {?} data * @return {?} */ AbstractDataEditor.prototype.editData = /** * @param {?} data * @return {?} */ function (data) { if (data === null || typeof data === 'undefined') { return; } var /** @type {?} */ objIdField = this.getObjectIdField(); var /** @type {?} */ objId = DataUtils.getDataValue(objIdField, data); var /** @type {?} */ obj = this.getDataFromObjectId(objId); if (obj !== null) { for (var /** @type {?} */ attr in data) { obj[attr] = data[attr]; } } }; /** * @param {?} dataProm * @return {?} */ AbstractDataEditor.prototype.getSavePromise = /** * @param {?} dataProm * @return {?} */ function (dataProm) { var _this = this; return new Promise(function (resolve, reject) { if (dataProm !== null && typeof dataProm !== 'undefined') { dataProm.then(function (resolveData) { var /** @type {?} */ createdArray = []; var /** @type {?} */ updatedArray = []; var /** @type {?} */ objectIdField = _this.getObjectIdField(); if (resolveData !== null && typeof resolveData !== 'undefined') { if (Array.isArray(resolveData)) { try { for (var resolveData_1 = tslib_1.__values(resolveData), resolveData_1_1 = resolveData_1.next(); !resolveData_1_1.done; resolveData_1_1 = resolveData_1.next()) { var obj = resolveData_1_1.value; var /** @type {?} */ objId = DataUtils.getDataValue(objectIdField, obj); if (objId !== null && typeof objId !== 'undefined') { updatedArray.push(obj); } else { createdArray.push(obj); } } } catch (e_9_1) { e_9 = { error: e_9_1 }; } finally { try { if (resolveData_1_1 && !resolveData_1_1.done && (_a = resolveData_1.return)) _a.call(resolveData_1); } finally { if (e_9) throw e_9.error; } } } } var /** @type {?} */ createProm = _this.createData(createdArray); if (createProm === null || typeof createProm === 'undefined') { createProm = Promise.resolve([]); } var /** @type {?} */ updateProm = _this.updateData(updatedArray); if (updateProm === null || typeof updateProm === 'undefined') { updateProm = Promise.resolve([]); } Promise.all([createProm, updateProm]).then(function (values) { var /** @type {?} */ result = []; if (values !== null && typeof values !== 'undefined') { if (values.length >= 1) { var /** @type {?} */ val = values[0]; if (val !== null && typeof val !== 'undefined') { if (Array.isArray(val)) { try { for (var val_1 = tslib_1.__values(val), val_1_1 = val_1.next(); !val_1_1.done; val_1_1 = val_1.next()) { var v = val_1_1.value; result.push(v); } } catch (e_10_1) { e_10 = { error: e_10_1 }; } finally { try { if (val_1_1 && !val_1_1.done && (_a = val_1.return)) _a.call(val_1); } finally { if (e_10) throw e_10.error; } } } else { result.push(val); } } } if (values.length >= 2) { var /** @type {?} */ val = values[1]; if (val !== null && typeof val !== 'undefined') { if (Array.isArray(val)) { try { for (var val_2 = tslib_1.__values(val), val_2_1 = val_2.next(); !val_2_1.done; val_2_1 = val_2.next()) { var v = val_2_1.value; result.push(v); } } catch (e_11_1) { e_11 = { error: e_11_1 }; } finally { try { if (val_2_1 && !val_2_1.done && (_b = val_2.return)) _b.call(val_2); } finally { if (e_11) throw e_11.error; } } } else { result.push(val); } } } } resolve(result); var e_10, _a, e_11, _b; }, function (error) { reject(error); }); var e_9, _a; }); } else { resolve([]); } }); }; /** * @return {?} */ AbstractDataEditor.prototype.getDialogService = /** * @return {?} */ function () { return this.dialogService; }; /** * @param {?} viewType * @return {?} */ AbstractDataEditor.prototype.showViewByType = /** * @param {?} viewType * @return {?} */ function (viewType) { var _this = this; return new Promise(function (resolve, reject) { if (viewType !== null && typeof viewType !== 'undefined') { try { for (var _a = tslib_1.__values(_this.viewModels), _b = _a.next(); !_b.done; _b = _a.next()) { var vModel = _b.value; if (vModel.type === viewType) { var /** @type {?} */ prom = _this.showView(vModel); if (prom !== null && typeof prom !== 'undefined') { prom.then(function (result) { resolve(result); }, function (error) { reject(error); }); } } } } catch (e_12_1) { e_12 = { error: e_12_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_12) throw e_12.error; } } return; } resolve(false); var e_12, _c; }); }; /** * @param {?} view * @return {?} */ AbstractDataEditor.prototype.addViewComponent = /** * @param {?} view * @return {?} */ function (view) { if (view == null) { return; } this.views.push(view); // update view model at index var /** @type {?} */ index = -1; for (var /** @type {?} */ i = 0; i < this.viewModels.length; i++) { var /** @type {?} */ vModelType = this.viewModels[i].type; var /** @type {?} */ mViewModelType = (view.getModel() === null ? null : view.getModel().type); if (mViewModelType !== null && vModelType === mViewModelType) { index = i; break; } } if (index > -1) { // update model this.viewModels[index] = view.getModel(); } else { // add new one to model this.viewModels.push(view.getModel()); } // add view add i18N if (typeof this.i18nValue !== 'undefined') { var /** @type {?} */ viewI18NMap = this.i18nValue['views']; // reserved keyword var /** @type {?} */ vModel = view.getModel(); var /** @type {?} */ vName = (vModel === null || typeof vModel === 'undefined') ? null : vModel.type; if (vName !== null && typeof vName !== 'undefined') { if (typeof view.applyI18N === 'function' && viewI18NMap !== undefined) { view.applyI18N(viewI18NMap[vName]); } } } // add view setOptions if (typeof this.options !== 'undefined') { var /** @type {?} */ viewOptionsMap = this.options['views']; // reserved keyword var /** @type {?} */ vModel = view.getModel(); var /** @type {?} */ vName = (vModel === null || typeof vModel === 'undefined') ? null : vModel.type; if (vName !== null && typeof vName !== 'undefined') { if (typeof view.setOptions === 'function') { view.setOptions(viewOptionsMap[vName]); } } } }; /** * @param {?} view * @return {?} */ AbstractDataEditor.prototype.removeViewComponent = /** * @param {?} view * @return {?} */ function (view) { if (view == null) { return; } var /** @type {?} */ tempArray = []; try { for (var _a = tslib_1.__values(this.views), _b = _a.next(); !_b.done; _b = _a.next()) { var v = _b.value; if (v === view) { continue; } tempArray.push(v); } } catch (e_13_1) { e_13 = { error: e_13_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_13) throw e_13.error; } } this.views = tempArray; var e_13, _c; }; /** * @return {?} */ AbstractDataEditor.prototype.reloadData = /** * @return {?} */ function () { var _this = this; return new Promise(function (resolve, reject) { // console.log(this.dataService); if (_this.dataService != null) { _this.dataService.loadData().then(function (result) { _this.data = result; resolve(result); _this.dataReloadEvent.emit(result); }); } else { resolve(null); _this.dataReloadEvent.emit(null); } }).catch(function (error) { return Promise.reject(error); }); }; /** * @return {?} */ AbstractDataEditor.prototype.reloadEditorSetting = /** * @return {?} */ function () { var _this = this; if (this.editorSetting != null) { return new Promise(function (resolve, reject) { _this.editorSetting.loadSettings().then(function (result) { _this.onEditorSettingLoaded(result); resolve(result); }, function (err) { reject(err); }).catch(function (error) { return Promise.reject(error); }); }); } return Promise.resolve(null); }; /** * @return {?} */ AbstractDataEditor.prototype.reloadViewSetting = /** * @return {?} */ function () { if (this.editorSetting != null) { try { for (var _a = tslib_1.__values(this.views), _b = _a.next(); !_b.done; _b = _a.next()) { var v = _b.value; v.reloadViewSetting(); } } catch (e_14_1) { e_14 = { error: e_14_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_14) throw e_14.error; } } } var e_14, _c; }; /** * @param {?} data * @return {?} */ AbstractDataEditor.prototype.createData = /** * @param {?} data * @return {?} */ function (data) { var _this = this; if (this.dataService === null || typeof this.dataService === 'undefined') { return Promise.resolve(null); } var /** @type {?} */ dataTemp = []; if (Array.isArray(data)) { dataTemp = data; } else { dataTemp.push(data); } var /** @type {?} */ prom = this.dataService.createData(data); var /** @type {?} */ langFieldName = this.getLanguageField(); if (prom !== null) { prom.then(function (resolveData) { var /** @type {?} */ result = []; if (resolveData !== null && typeof resolveData !== 'undefined') { if (Array.isArray(resolveData)) { try { for (var resolveData_2 = tslib_1.__values(resolveData), resolveData_2_1 = resolveData_2.next(); !resolveData_2_1.done; resolveData_2_1 = resolveData_2.next()) { var item = resolveData_2_1.value; if (item[langFieldName] === null || typeof item[langFieldName] === 'undefined') { // push only default data // push only default data _this.data.push(item); } result.push(item); } } catch (e_15_1) { e_15 = { error: e_15_1 }; } finally { try { if (resolveData_2_1 && !resolveData_2_1.done && (_a = resolveData_2.return)) _a.call(resolveData_2); } finally { if (e_15) throw e_15.error; } } } else { // add in to data array if (resolveData[langFieldName] === null || typeof resolveData[langFieldName] === 'undefined') { // push only default data // push only default data _this.data.push(resolveData); } result.push(resolveData); } } // emit after save var /** @type {?} */ data = { data: result, original: dataTemp }; var /** @type {?} */ ev = EventUtils.newCustomEvent(DATA_CREATE_EVENT, _this, data, null); _this.dataCreateEvent.emit(ev); return Promise.resolve(resolveData); var e_15, _a; }); } return prom; }; /** * @param {?} data * @return {?} */ AbstractDataEditor.prototype.createDataWithConfirmDialog = /** * @param {?} data * @return {?} */ function (data) { var _this = this; return new Promise(function (resolve, reject) { _this.dialogService.showConfirmDialog('Confirm Create Data', 'Do you want to Create data ?', false).then(function (result) { if (result == 1) { var /** @type {?} */ prom = _this.createData(data); if (prom !== null) { prom.then(function (result) { resolve(result); }); } } else { // NO resolve(null); } }); }); }; /** * @return {?} */ AbstractDataEditor.prototype.saveSelectedData = /** * @return {?} */ function () { var /** @type {?} */ currentView = this.getCurrentView(); if (currentView != null) { var /** @type {?} */ dataProm = currentView.getSelectedData(); return this.getSavePromise(dataProm); } return null; }; /** * @return {?} */ AbstractDataEditor.prototype.saveDirtyData = /** * @return {?} */ function () { var /** @type {?} */ currentView = this.getCurrentView(); if (currentView != null) { var /** @type {?} */ dataProm = currentView.getEditorDirtyData(); return this.getSavePromise(dataProm); } return null; }; /** * @return {?} */ AbstractDataEditor.prototype.saveSelectedDataWithConfirmDialog = /** * @return {?} */ function () { var _this = this; return new Promise(function (resolve, reject) { _this.dialogService.showConfirmDialog('Confirm Save Data', 'Do you want to Save Selected data ?', false).then(function (result) { if (result == 1) { var /** @type {?} */ prom = _this.saveSelectedData(); if (prom !== null) { prom.then(function (result) { resolve(result); }, function (error) { reject(error); }); } } else { // NO resolve(null); } }); }); }; /** * @return {?} */ AbstractDataEditor.prototype.saveDirtyDataWithConfirmDialog = /** * @return {?} */ function () { var _this = this; return new Promise(function (resolve, reject) { _this.dialogService.showConfirmDialog('Confirm Save Data', 'Do you want to Save all data ?', false).then(function (result) { if (result == 1) { var /** @type {?} */ prom = _this.saveDirtyData(); if (prom !== null) { prom.then(function (result) { resolve(result); }); } } else { // NO resolve(null); } }); }); }; /** * @return {?} */ AbstractDataEditor.prototype.updateSelectedData = /** * @return {?} */ function () { var _this = this; var /** @type {?} */ currentView = this.getCurrentView(); return new Promise(function (resolve, reject) { if (currentView != null) { var /** @type {?} */ dataProm = currentView.getSelectedData(); if (dataProm !== null && typeof dataProm !== 'undefined') { dataProm.then(function (resolveData) { var /** @type {?} */ updateProm = _this.updateData(resolveData); if (updateProm !== null) { updateProm.then(function (res) { resolve(res); }).catch(function (error) { reject(error); }); } else { resolve(null); } }); } } else { resolve(null); } }); }; /** * @return {?} */ AbstractDataEditor.prototype.updateDirtyData = /** * @return {?} */ function () { var _this = this; var /** @type {?} */ currentView = this.getCurrentView(); if (currentView != null) { var /** @type {?} */ dataProm = currentView.getEditorDirtyData(); if (dataProm !== null && typeof dataProm !== 'undefined') { dataProm.then(function (resolveData) { return _this.updateData(resolveData); }); } } return null; }; /** * @param {?} data * @return {?} */ AbstractDataEditor.prototype.updateData = /** * @param {?} data * @return {?} */ function (data) { var _this = this; if (this.dataService === null || typeof this.dataService === 'undefined') { return Promise.resolve(null); } return new Promise(function (resolve, reject) { var /** @type {?} */ dataTemp = []; if (Array.isArray(data)) { dataTemp = data; } else { dataTemp.push(data); } var /** @type {?} */ prom = _this.dataService.updateData(data); var /** @type {?} */ langFieldName = _this.getLanguageField(); if (prom !== null) { prom.then(function (resolveData) { var /** @type {?} */ result = []; if (resolveData !== null && typeof resolveData !== 'undefined') { if (Array.isArray(resolveData)) { try { for (var resolveData_3 = tslib_1.__values(resolveData), resolveData_3_1 = resolveData_3.next(); !resolveData_3_1.done; resolveData_3_1 = resolveData_3.next()) { var item = resolveData_3_1.value; if (item[langFieldName] === null || typeof item[langFieldName] === 'undefined') { // update cache with default data only // update cache with default data only _this.editData(item); } result.push(item); } } catch (e_16_1) { e_16 = { error: e_16_1 }; } finally { try { if (resolveData_3_1 && !resolveData_3_1.done && (_a = resolveData_3.return)) _a.call(resolveData_3); } finally { if (e_16) throw e_16.error; } } } else { // update in to data array if (resolveData[langFieldName] === null || typeof resolveData[langFieldName] === 'undefined') { _this.editData(resolveData); } result.push(resolveData); } } var /** @type {?} */ data = { data: result, original: dataTemp }; var /** @type {?} */ ev = EventUtils.newCustomEvent(DATA_UPDATE_EVENT, _this, data, null); _this.dataUpdateEvent.emit(ev); resolve(resolveData); var e_16, _a; }).catch(function (error) { reject(error); }); } else { resolve(null); } }); }; /** * @param {?} data * @return {?} */ AbstractDataEditor.prototype.updateDataWithConfirmDialog = /** * @param {?} data * @return {?} */ function (data) { var _this = this; return new Promise(function (resolve, reject) { _this.dialogService.showConfirmDialog('Confirm Update Data', 'Do you want to Update data ?', false).then(function (result) { if (result == 1) { var /** @type {?} */ prom = _this.updateData(data); if (prom !== null) { prom.then(function (result) { resolve(result); }); } } else { // NO resolve(data); } }); }); }; /** * @return {?} */ AbstractDataEditor.prototype.updateDirtyDataWithConfirmDialog = /** * @return {?} */ function () { var _this = this; return new Promise(function (resolve, reject) { _this.dialogService.showConfirmDialog('Confirm Update Data', 'Do you want to Update all data ?', false).then(function (result) { if (result == 1) { var /** @type {?} */ prom = _this.updateDirtyData(); if (prom !== null) { prom.then(function (result) { resolve(result); }); } } else { // NO resolve(null); } }); }); }; /** * @return {?} */ AbstractDataEditor.prototype.updateSelectedDataWithConfirmDialog = /** * @return {?} */ function () { var _this = this; return new Promise(function (resolve, reject) { _this.dialogService.showConfirmDialog('Confirm Update Data', 'Do you want to Update selected data ?', false).then(function (result) { if (result == 1) { var /** @type {?} */ prom = _