UNPKG

com.phloxui

Version:

PhloxUI Ng2+ Framework

1,254 lines 181 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes} checked by tsc */ import * as tslib_1 from "tslib"; import { Component, ElementRef, Input, EventEmitter, ViewChild, Inject, Output } from '@angular/core'; import { AbstractDataEditorView } from '../AbstractDataEditorView'; import { RecordViewModel, ShortcutModel } from '../../model/models'; import { TypeResolveService } from '../../../service/TypeResolveService.service'; import { DialogService } from '../../../service/DialogService.service'; import { EditorSettingServiceFactory } from '../IEditorSettingServiceFactory'; import { FormView } from '../../../component/editor/editor.internal/FormView.component'; import { DataUtils } from '../../../share/utils/DataUtils'; import { ArrayUtils } from '../../../share/utils/ArrayUtils'; import { JsonSchemaUtils } from '../../../share/utils/JsonSchemaUtils'; import { Option } from '../../../decorator/Option.decorator'; import { I18N } from '../../../decorator/I18N.decorator'; import { PhloxTable } from '../../table/PhloxTable.component'; import { StringDataView } from '../../../component/dataview/StringDataView.component'; import { CheckBox } from '../../../component/dataview/input/CheckBox.component'; import { EllipsisButton } from '../../../component/EllipsisButton.component'; import { KeyboardShortcutService } from '../../../service/KeyboardShortcutService.service'; import { MaterialIconLoader } from '../../../theme/material/component/MaterialIconLoader.component'; import { ComponentPopoverModel } from '../../model/ComponentPopoverModel'; import { ComponentPopover } from '../../../component/ComponentPopover.component'; import { ColumnDisplay } from './record.internal/ColumnDisplay.component'; import { ColumnSorting } from './record.internal/ColumnSorting.component'; var /** @type {?} */ TYPE_NAME = "phx-record-view"; var /** @type {?} */ FORM_VIEW = FormView.TYPE_NAME; var RecordView = /** @class */ (function (_super) { tslib_1.__extends(RecordView, _super); function RecordView(typeResolveServ, dialogService, editorSettingFactory, elementRef, kbService) { var _this = _super.call(this, editorSettingFactory, elementRef, kbService) || this; _this.DEFAULT_CHECKBOX_WIDTH = "40pt"; _this.DEFAULT_MORE_MENU_WIDTH = "40pt"; _this.tableData = []; _this.lastTableData = []; _this.model = new RecordViewModel(null, "DEFAULT", []); _this.typeResolveServ = typeResolveServ; _this.editable = false; _this.dialogService = dialogService; _this.selectedAll = false; _this.tableOption = {}; _this._columnDisplayModel = new ComponentPopoverModel(ColumnDisplay, null, null, null, null, 'auto', false, ["filter"]); _this._columnSortingModel = new ComponentPopoverModel(ColumnSorting, null, null, null, null, 'auto', false, ["sorting"]); _this.i18NResource = { header: { title: "RECORD_VIEW_TITLE", } }; // pass editor and store its instance. // pass editor and store its instance. _this._columnDisplayHandler = function (result) { if (result !== null && result !== undefined) { _this.columnDisplayInstance = result.instance; } if (_this.columnDisplayInstance !== null && _this.columnDisplayInstance !== undefined) { if (typeof _this.columnDisplayInstance.setDataEditor === 'function') { _this.columnDisplayInstance.setDataEditor(_this.editor); } // set column if (typeof _this.columnDisplayInstance.setColumns === 'function') { _this.columnDisplayInstance.setColumns(_this.model.columns); } if (typeof _this.columnDisplayInstance.getColumnChangeEvent === 'function') { _this.columnDisplayInstance.getColumnChangeEvent().subscribe(function (event) { if (event.detail.data.data !== null || event.detail.data.data !== undefined) { if (event.detail.data.column.show === true) { _this.showColumn(event.detail.data.column); } else { _this.hideColumn(event.detail.data.column); } } }); } } }; _this._columnSortingHandler = function (result) { if (result !== null && result !== undefined) { _this.columnSortingInstance = result.instance; } if (_this.columnSortingInstance !== null && _this.columnSortingInstance !== undefined) { if (typeof _this.columnSortingInstance.setDataEditor === 'function') { _this.columnSortingInstance.setDataEditor(_this.editor); } // set column if (typeof _this.columnSortingInstance.setColumns === 'function') { _this.columnSortingInstance.setColumns(_this.model.columns); } if (typeof _this.columnSortingInstance.getColumnChangeEvent === 'function') { _this.columnSortingInstance.getColumnChangeEvent().subscribe(function (event) { if (event.detail.data.data !== null || event.detail.data.data !== undefined) { if (event.detail.data.column.show === true) { _this.showColumn(event.detail.data.column); } else { _this.hideColumn(event.detail.data.column); } } }); } } }; return _this; } /** * @return {?} */ RecordView.prototype.ngOnInit = /** * @return {?} */ function () { var _this = this; _super.prototype.ngOnInit.call(this); this.applyI18N(this.i18NResource); if (this.editor != null && (typeof this.editor !== 'undefined')) { this.editor.addViewComponent(this); this.menuFactory = this.editor.getMenuModelFactory(); this.reloadTable(); if (this.showEvent !== null && (typeof this.showEvent !== 'undefined')) { this.showEvent.subscribe(function (event) { _this.reloadTable(); }); } var /** @type {?} */ createdEvent = this.editor.getDataCreateEvent(); if (createdEvent !== null && (typeof createdEvent !== 'undefined')) { createdEvent.subscribe(function (event) { var /** @type {?} */ data = null; if (event.detail !== null && typeof event.detail !== 'undefined') { if (event.detail.data !== null && typeof event.detail.data !== 'undefined') { data = event.detail.data; } } if (data !== null) { // do sthing } }); } var /** @type {?} */ updateEvent = this.editor.getDataUpdateEvent(); if (updateEvent !== null && (typeof updateEvent !== 'undefined')) { updateEvent.subscribe(function (event) { var /** @type {?} */ data = null; if (event.detail !== null && typeof event.detail !== 'undefined') { if (event.detail.data !== null && typeof event.detail.data !== 'undefined') { data = event.detail.data; } } if (data !== null) { _this.reloadTable(); } }); } var /** @type {?} */ deleteEvent = this.editor.getDataDeleteEvent(); if (deleteEvent !== null && (typeof deleteEvent !== 'undefined')) { deleteEvent.subscribe(function (event) { var /** @type {?} */ data = null; if (event.detail !== null && typeof event.detail !== 'undefined') { if (event.detail.data !== null && typeof event.detail.data !== 'undefined') { data = event.detail.data; } } if (data !== null) { _this.reloadTable(); } }); } var /** @type {?} */ revertEvent = this.editor.getDataRevertEvent(); if (revertEvent !== null && (typeof revertEvent !== 'undefined')) { revertEvent.subscribe(function (event) { var /** @type {?} */ data = null; if (event.detail !== null && typeof event.detail !== 'undefined') { if (event.detail.data !== null && typeof event.detail.data !== 'undefined') { data = event.detail.data; } } if (data !== null && data !== undefined) { var /** @type {?} */ dataList = []; // data pattern as { data: revertData[], originalData: oldData[]} if (!Array.isArray(data)) { dataList.push(data); } else { dataList = data; } try { for (var dataList_1 = tslib_1.__values(dataList), dataList_1_1 = dataList_1.next(); !dataList_1_1.done; dataList_1_1 = dataList_1.next()) { var d = dataList_1_1.value; _this.replaceRecordRowData(d.data); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (dataList_1_1 && !dataList_1_1.done && (_a = dataList_1.return)) _a.call(dataList_1); } finally { if (e_1) throw e_1.error; } } } _this.bodyTable.rerender(true); var e_1, _a; }); } var /** @type {?} */ dataReloadEvent = this.editor.getDataReloadEvent(); if (dataReloadEvent !== null && (typeof dataReloadEvent !== 'undefined')) { dataReloadEvent.subscribe(function (event) { _this.reloadTable(); }); } var /** @type {?} */ dataQueryEvent = this.editor.getDataQueryEvent(); if (dataQueryEvent !== null && (typeof dataQueryEvent !== 'undefined')) { dataQueryEvent.subscribe(function (event) { _this.reloadTable(); }); } } }; /** * @return {?} */ RecordView.prototype.ngOnDestroy = /** * @return {?} */ function () { _super.prototype.ngOnDestroy.call(this); if (this.editor !== null && (typeof this.editor !== 'undefined')) { this.editor.removeViewComponent(this); } }; /** * @param {?} model * @return {?} */ RecordView.prototype.generateTBHeaderObject = /** * @param {?} model * @return {?} */ function (model) { var _this = this; var /** @type {?} */ result = { "model": { "header": { "editable": true }, "body": {}, "columns": [] } }; if (model !== null && typeof model !== 'undefined') { var /** @type {?} */ hasFlexibleWidth = false; if (model.columns !== null && model.columns !== undefined) { for (var /** @type {?} */ i = 0; i < model.columns.length; i++) { var /** @type {?} */ col = model.columns[i]; var /** @type {?} */ colWidth = col.width; // if colWidth is null or undefined set flag hasFlexibleWidth if (colWidth === null || typeof colWidth === 'undefined') { hasFlexibleWidth = true; } // in the end if FlexibleWidth was not found, set at least colWidth in to null // if (i === model.columns.length - 1 && !hasFlexibleWidth) { // colWidth = null; // } var /** @type {?} */ hCol = {}; if (model.columns[i].show === true) { hCol = { "name": col.label, "width": colWidth, "header": { "type": StringDataView.TYPE_NAME, "class": col.textAlign } }; } else { hCol = { "name": col.label, "width": colWidth, "header": { "type": StringDataView.TYPE_NAME, "class": col.textAlign + " hide" } }; } if (col.stylesHeaderClass !== undefined && col.stylesHeaderClass !== null) { if (Array.isArray(col.stylesHeaderClass)) { try { for (var _a = tslib_1.__values(col.stylesHeaderClass), _b = _a.next(); !_b.done; _b = _a.next()) { var style = _b.value; hCol.header.class += " " + style; } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_2) throw e_2.error; } } } else if (typeof col.stylesHeaderClass === "string") { hCol.header.class += " " + col.stylesHeaderClass; } } result.model.columns.push(hCol); } } } // size > 0 add first and end col if (result.model.columns.length > 0) { var /** @type {?} */ chkBoxChanged = new EventEmitter(); chkBoxChanged.subscribe(function (event) { var /** @type {?} */ isCheck = event.detail.data.newValue; if (isCheck) { // selecte all var /** @type {?} */ dataArray = _this.bodyTable.getData(); try { for (var dataArray_1 = tslib_1.__values(dataArray), dataArray_1_1 = dataArray_1.next(); !dataArray_1_1.done; dataArray_1_1 = dataArray_1.next()) { var row = dataArray_1_1.value; row.selected = true; } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (dataArray_1_1 && !dataArray_1_1.done && (_a = dataArray_1.return)) _a.call(dataArray_1); } finally { if (e_3) throw e_3.error; } } } else { // clear all selected var /** @type {?} */ dataArray = _this.bodyTable.getData(); try { for (var dataArray_2 = tslib_1.__values(dataArray), dataArray_2_1 = dataArray_2.next(); !dataArray_2_1.done; dataArray_2_1 = dataArray_2.next()) { var row = dataArray_2_1.value; row.selected = false; } } catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (dataArray_2_1 && !dataArray_2_1.done && (_b = dataArray_2.return)) _b.call(dataArray_2); } finally { if (e_4) throw e_4.error; } } } var e_3, _a, e_4, _b; }); var /** @type {?} */ chkBxCol = { "name": "", "width": this.DEFAULT_CHECKBOX_WIDTH, "header": { "type": CheckBox.TYPE_NAME, "class": "center", "options": { "change": chkBoxChanged, "typeOfData": "boolean" } }, "editable": true }; ArrayUtils.insert(result.model.columns, chkBxCol, 0); var /** @type {?} */ moreCol = { "name": "", "width": this.DEFAULT_MORE_MENU_WIDTH, "header": { "type": StringDataView.TYPE_NAME, "class": "center" } }; result.model.columns.push(moreCol); } return result; var e_2, _c; }; /** * @param {?} model * @return {?} */ RecordView.prototype.generateTBBodyObject = /** * @param {?} model * @return {?} */ function (model) { var _this = this; var /** @type {?} */ result = { "model": { "header": {}, "body": { "row": { "editable": this.editable, } }, "columns": [] } }; if (model !== null && typeof model !== 'undefined') { var /** @type {?} */ hasFlexibleWidth = false; if (model.columns !== null && model.columns !== undefined) { var _loop_1 = function (i) { var /** @type {?} */ col = model.columns[i]; var /** @type {?} */ colWidth = col.width; // if colWidth is null or undefined set flag hasFlexibleWidth if (colWidth === null || typeof colWidth === 'undefined') { hasFlexibleWidth = true; } // in the end if FlexibleWidth was not found, set at least colWidth in to null // if (i === model.columns.length - 1 && !hasFlexibleWidth) { // colWidth = null // } var /** @type {?} */ hCol = {}; if (model.columns[i].show === true) { hCol = { "name": col.label, "width": colWidth, "editable": col.editable, "body": { "class": col.textAlign, "type": col.view, "options": col.options, "editorType": col.editor, "editorOptions": col.editorOptions } }; } else { hCol = { "name": col.label, "width": colWidth, "editable": col.editable, "body": { "class": col.textAlign + " hide", "type": col.view, "options": col.options, "editorType": col.editor, "editorOptions": col.editorOptions } }; } if (col.stylesBodyClass !== undefined && col.stylesBodyClass !== null) { if (Array.isArray(col.stylesBodyClass)) { try { for (var _a = tslib_1.__values(col.stylesBodyClass), _b = _a.next(); !_b.done; _b = _a.next()) { var style = _b.value; hCol.body.class += " " + style; } } 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; } } } else if (typeof col.stylesBodyClass === "string") { hCol.body.class += " " + col.stylesBodyClass; } } // overide options field if (hCol.body.options !== null && typeof hCol.body.options !== 'undefined') { hCol.body.options["field"] = "data." + col.value; } else { hCol.body.options = { "field": "data." + col.value }; } // overide editorOptions field if (hCol.body.editorOptions !== null && typeof hCol.body.editorOptions !== 'undefined') { hCol.body.editorOptions["field"] = "data." + col.value; } else { hCol.body.editorOptions = { "field": "data." + col.value }; } // check data change var /** @type {?} */ editorEmiter = new EventEmitter(); editorEmiter.subscribe(function (event) { if (event.detail.data.data !== undefined) { for (var /** @type {?} */ i_1 = 0; i_1 < _this.tableData.length; i_1++) { var /** @type {?} */ lastTableDataCheck = JSON.stringify(_this.lastTableData[i_1].data); var /** @type {?} */ tableDataCheck = JSON.stringify(_this.tableData[i_1].data); if (lastTableDataCheck !== tableDataCheck) { _this.lastTableData = JSON.parse(JSON.stringify(_this.tableData)); _this.makeHistory(); } } } }); hCol.body.editorOptions["change"] = editorEmiter; // focus save values var /** @type {?} */ editorFocusEmiter = new EventEmitter(); if (hCol.body.editorOptions["focus"] !== null && typeof hCol.body.editorOptions["focus"] !== 'undefined') { var /** @type {?} */ tempEmitter_1 = hCol.body.editorOptions["focus"]; editorFocusEmiter.subscribe(function (event) { //set defaultValue var /** @type {?} */ itemCompo = undefined; if (event.detail.data !== null && event.detail.data !== undefined) { itemCompo = event.detail.data.item; } var /** @type {?} */ compoVal = undefined; if (typeof itemCompo.getData === 'function') { compoVal = itemCompo.getData(); } // new val from json // new val from json _this.currentFocusValue = undefined; if (compoVal !== undefined && compoVal !== null) { _this.currentFocusValue = JSON.parse(JSON.stringify(compoVal)); } // pass event if (typeof tempEmitter_1["emit"] === 'function') { tempEmitter_1.emit(event); } }); hCol.body.editorOptions["focus"] = editorFocusEmiter; } else { editorFocusEmiter.subscribe(function (event) { //set defaultValue var /** @type {?} */ itemCompo = undefined; if (event.detail.data !== null && event.detail.data !== undefined) { itemCompo = event.detail.data.item; } var /** @type {?} */ compoVal = undefined; if (itemCompo !== undefined && typeof itemCompo.getData === 'function') { compoVal = itemCompo.getData(); } // new val from json // new val from json _this.currentFocusValue = undefined; if (compoVal !== undefined && compoVal !== null) { _this.currentFocusValue = JSON.parse(JSON.stringify(compoVal)); } }); hCol.body.editorOptions["focus"] = editorFocusEmiter; } result.model.columns.push(hCol); var e_5, _c; }; for (var /** @type {?} */ i = 0; i < model.columns.length; i++) { _loop_1(i); } } } // size > 0 add first and end col if (result.model.columns.length > 0) { var /** @type {?} */ chkBxCol = { "name": "", "width": this.DEFAULT_CHECKBOX_WIDTH, "body": { "type": CheckBox.TYPE_NAME, "class": "center", "options": { "field": "selected" } } }; ArrayUtils.insert(result.model.columns, chkBxCol, 0); var /** @type {?} */ moreCol = { "name": "", "width": this.DEFAULT_MORE_MENU_WIDTH, "body": { "type": EllipsisButton.TYPE_NAME, "class": "center", "options": { "menuFactory": this.menuFactory, "menuStyleClasses": this.menuStyleClasses } } }; result.model.columns.push(moreCol); } return result; }; /** * @param {?} value * @return {?} */ RecordView.prototype.isDataChange = /** * @param {?} value * @return {?} */ function (value) { if (this.currentFocusValue === undefined && value === undefined) { return false; } else if (this.currentFocusValue === null && value === null) { return false; } else if (this.currentFocusValue === undefined && value === null) { return true; } else if (this.currentFocusValue === null && value === undefined) { return true; } if (typeof this.currentFocusValue === "object" && typeof value === 'object') { return JSON.stringify(this.currentFocusValue) !== JSON.stringify(value); } return this.currentFocusValue !== value; }; /** * @return {?} */ RecordView.prototype.getOriginalData = /** * @return {?} */ function () { if (this.editor != null) { return this.editor.getData(); } return []; }; /** * @param {?} dataObj * @return {?} */ RecordView.prototype.replaceRecordRowData = /** * @param {?} dataObj * @return {?} */ function (dataObj) { var /** @type {?} */ comparator = this.editor.getDataComparator(); if (Array.isArray(dataObj)) { if (dataObj.length > 0) { dataObj = dataObj[0]; } } var /** @type {?} */ index = -1; for (var /** @type {?} */ i = 0; i < this.tableData.length; i++) { var /** @type {?} */ row = this.tableData[i]; var /** @type {?} */ data = row.data; if (comparator !== null) { if (comparator.equals(dataObj, data)) { index = i; break; } } } if (index > -1) { var /** @type {?} */ cloneObj = JSON.parse(JSON.stringify(dataObj)); var /** @type {?} */ recRow = new RecordRow(false, cloneObj); this.tableData[index] = recRow; // clone object } }; /** * @param {?} key * @param {?} dataObj * @return {?} */ RecordView.prototype.getTableValue = /** * @param {?} key * @param {?} dataObj * @return {?} */ function (key, dataObj) { if (key == null || dataObj == null) { return null; } var /** @type {?} */ result = null; if (key.indexOf(".") > 0) { var /** @type {?} */ splitKeys = key.split("."); if (splitKeys.length > 0) { var /** @type {?} */ firstKey = splitKeys[0]; var /** @type {?} */ firstValue = dataObj[firstKey]; if (firstValue != null && typeof firstValue !== 'undefined') { if (typeof firstValue === 'object') { if (splitKeys.length > 1) { var /** @type {?} */ secondKey = key.substring(key.indexOf(".") + 1, key.length); return this.getTableValue(secondKey, firstValue); // recursive beware looping } } } } } else { result = dataObj[key]; } if (result != null && typeof result !== 'undefined') { return result; } return null; }; /** * @param {?} key * @param {?} dataObj * @param {?} value * @return {?} */ RecordView.prototype.editDataObjectValue = /** * @param {?} key * @param {?} dataObj * @param {?} value * @return {?} */ function (key, dataObj, value) { DataUtils.setDataValue(key, dataObj, value); }; /** * @param {?} view * @return {?} */ RecordView.prototype.getViewComponent = /** * @param {?} view * @return {?} */ function (view) { if (view == null) { return null; } if (this.typeResolveServ != null) { return this.typeResolveServ.resolveType(view); } return null; }; /** * @param {?} rowIdx * @param {?} colIdx * @param {?} data * @return {?} */ RecordView.prototype.getDirty = /** * @param {?} rowIdx * @param {?} colIdx * @param {?} data * @return {?} */ function (rowIdx, colIdx, data) { // compare with original data if (data == null) { return false; } var /** @type {?} */ column = null; if (colIdx < this.model.columns.length) { column = this.model.columns[colIdx]; } var /** @type {?} */ editorData = this.getOriginalData(); var /** @type {?} */ originalData = null; if (originalData < editorData.length) { originalData = editorData[rowIdx]; } if (column != null && originalData != null) { var /** @type {?} */ colOriData = this.getTableValue(column.value, originalData); var /** @type {?} */ colTBData = this.getTableValue(column.value, data); return (colOriData !== colTBData); } return false; }; /** * @param {?} colIdx * @return {?} */ RecordView.prototype.getColumnEditable = /** * @param {?} colIdx * @return {?} */ function (colIdx) { var /** @type {?} */ column = null; if (colIdx < this.model.columns.length) { column = this.model.columns[colIdx]; } if (column != null) { return column.editable; } return false; }; /** * @return {?} */ RecordView.prototype.closeAllEditor = /** * @return {?} */ function () { if (this.bodyTable !== null && typeof this.bodyTable !== 'undefined') { var /** @type {?} */ rowControllers = this.bodyTable.getRowControllers(); try { for (var rowControllers_1 = tslib_1.__values(rowControllers), rowControllers_1_1 = rowControllers_1.next(); !rowControllers_1_1.done; rowControllers_1_1 = rowControllers_1.next()) { var row = rowControllers_1_1.value; row.setEditing(false); } } catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (rowControllers_1_1 && !rowControllers_1_1.done && (_a = rowControllers_1.return)) _a.call(rowControllers_1); } finally { if (e_6) throw e_6.error; } } } var e_6, _a; }; /** * @return {?} */ RecordView.prototype.getDirtyCreateData = /** * @return {?} */ function () { var /** @type {?} */ createObject = []; var /** @type {?} */ editorData = this.getOriginalData(); var /** @type {?} */ idx = 0; try { for (var editorData_1 = tslib_1.__values(editorData), editorData_1_1 = editorData_1.next(); !editorData_1_1.done; editorData_1_1 = editorData_1.next()) { var originalData = editorData_1_1.value; if (idx < this.tableData.length) { var /** @type {?} */ tbData = this.tableData[idx].data; // edit oridata var /** @type {?} */ colIdx = 0; try { for (var _a = tslib_1.__values(this.model.columns), _b = _a.next(); !_b.done; _b = _a.next()) { var col = _b.value; if (this.getDirty(idx, colIdx, tbData)) { createObject.push(tbData); break; } colIdx += 1; } } 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; } } } idx += 1; } } catch (e_8_1) { e_8 = { error: e_8_1 }; } finally { try { if (editorData_1_1 && !editorData_1_1.done && (_d = editorData_1.return)) _d.call(editorData_1); } finally { if (e_8) throw e_8.error; } } return createObject; var e_8, _d, e_7, _c; }; /** * @return {?} */ RecordView.prototype.reverseAllCellChanged = /** * @return {?} */ function () { this.tableData = []; var /** @type {?} */ editorData = this.getOriginalData(); var /** @type {?} */ rowIdx = 0; try { for (var editorData_2 = tslib_1.__values(editorData), editorData_2_1 = editorData_2.next(); !editorData_2_1.done; editorData_2_1 = editorData_2.next()) { var row = editorData_2_1.value; if (row == null || typeof row === 'undefined') { continue; } var /** @type {?} */ cloneObj = JSON.parse(JSON.stringify(row)); var /** @type {?} */ recRow = new RecordRow(false, cloneObj); this.tableData.push(recRow); // clone object var /** @type {?} */ colIdx = 0; try { for (var _a = tslib_1.__values(this.model.columns), _b = _a.next(); !_b.done; _b = _a.next()) { var col = _b.value; var /** @type {?} */ key = rowIdx + ':' + colIdx; colIdx += 1; } } catch (e_9_1) { e_9 = { error: e_9_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_9) throw e_9.error; } } rowIdx += 1; } } catch (e_10_1) { e_10 = { error: e_10_1 }; } finally { try { if (editorData_2_1 && !editorData_2_1.done && (_d = editorData_2.return)) _d.call(editorData_2); } finally { if (e_10) throw e_10.error; } } this.lastTableData = JSON.parse(JSON.stringify(this.tableData)); var e_10, _d, e_9, _c; }; /** * @param {?} rowIdx * @param {?} colIdx * @return {?} */ RecordView.prototype.reverseCellChanged = /** * @param {?} rowIdx * @param {?} colIdx * @return {?} */ function (rowIdx, colIdx) { var /** @type {?} */ editorData = this.getOriginalData(); var /** @type {?} */ originalRowData = null; if (rowIdx < editorData.length) { originalRowData = editorData[rowIdx]; } var /** @type {?} */ columnData = null; if (colIdx < this.model.columns.length) { columnData = this.model.columns[colIdx]; } var /** @type {?} */ originalCellData = this.getTableValue(columnData.value, originalRowData); var /** @type {?} */ tbData = null; if (rowIdx < this.tableData.length) { tbData = this.tableData[rowIdx].data; } this.editDataObjectValue(columnData.value, tbData, originalCellData); }; /** * @param {?} id * @return {?} */ RecordView.prototype.removeDataByObjectId = /** * @param {?} id * @return {?} */ function (id) { if (id !== null && typeof id !== 'undefined') { var /** @type {?} */ objIdField = this.editor.getObjectIdField(); var /** @type {?} */ index = -1; var /** @type {?} */ count = 0; try { for (var _a = tslib_1.__values(this.tableData), _b = _a.next(); !_b.done; _b = _a.next()) { var tbData = _b.value; var /** @type {?} */ tbDataID = DataUtils.getDataValue(objIdField, tbData.data); if (id === tbDataID) { index = count; break; } count += 1; } } catch (e_11_1) { e_11 = { error: e_11_1 }; } finally { try { if (_b && !_b.done && (_c = _a.return)) _c.call(_a); } finally { if (e_11) throw e_11.error; } } if (index > -1) { this.tableData.splice(index, 1); this.lastTableData = JSON.parse(JSON.stringify(this.tableData)); return true; } } return false; var e_11, _c; }; /** * @param {?} selected * @return {?} */ RecordView.prototype.setAllCheckBox = /** * @param {?} selected * @return {?} */ function (selected) { this.selectedAll = selected; for (var /** @type {?} */ i = 0; i < this.tableData.length; i++) { var /** @type {?} */ row = this.tableData[i]; row.selected = selected; } }; /** * @return {?} */ RecordView.prototype.getAllTableData = /** * @return {?} */ function () { var /** @type {?} */ result = []; for (var /** @type {?} */ i = 0; i < this.tableData.length; i++) { var /** @type {?} */ item = this.tableData[i].data; result.push(item); } return result; }; /** * @return {?} */ RecordView.prototype.getTableSelectedData = /** * @return {?} */ function () { var /** @type {?} */ result = []; for (var /** @type {?} */ i = 0; i < this.tableData.length; i++) { var /** @type {?} */ item = this.tableData[i].data; var /** @type {?} */ selected = this.tableData[i].selected; if (selected) { result.push(item); } } return result; }; /** * @return {?} */ RecordView.prototype.onViewSettingLoaded = /** * @return {?} */ function () { this.reloadTable(); }; /** * @param {?} column * @return {?} */ RecordView.prototype.showColumn = /** * @param {?} column * @return {?} */ function (column) { this.reloadTable(); }; /** * @param {?} column * @return {?} */ RecordView.prototype.hideColumn = /** * @param {?} column * @return {?} */ function (column) { this.reloadTable(); }; /** * @return {?} */ RecordView.prototype.getRecordColumnLength = /** * @return {?} */ function () { if (this.model === null || this.model === undefined) { return 0; } if (this.model.columns === null || this.model.columns === undefined) { return 0; } return this.model.columns.length; }; /** * @param {?} toggleEvent * @return {?} */ RecordView.prototype.onToggleChanged = /** * @param {?} toggleEvent * @return {?} */ function (toggleEvent) { this.editable = !this.editable; for (var /** @type {?} */ i = 0; i < this.tableData.length; i++) { this.bodyTable.getRowControllers()[i].setSelfEditable(this.editable); } if (toggleEvent.detail !== null && typeof toggleEvent.detail !== 'undefined') { if (toggleEvent.detail.data !== null && typeof toggleEvent.detail.data !== 'undefined') { this.editable = toggleEvent.detail.data.newValue; } } if (!this.editable) { this.closeAllEditor(); } }; /** * @param {?} $event * @return {?} */ RecordView.prototype.onSaveButtonClicked = /** * @param {?} $event * @return {?} */ function ($event) { var _this = this; if (this.dialogService != null) { var /** @type {?} */ dialogPromise = this.dialogService.showConfirmDialog('Confirm Saving', 'Do you want to Save all data ?', true); dialogPromise.then(function (result) { if (result == 1) { // save var /** @type {?} */ objs = _this.getAllTableData(); _this.editor.updateData(objs); } }); } }; /** * @param {?} $event * @return {?} */ RecordView.prototype.onUndoButtonClicked = /** * @param {?} $event * @return {?} */ function ($event) { var _this = this; if (!this.canUndo()) { return; } // delay to wait for lostFocus fire if (this.delayTimer !== null && typeof this.delayTimer !== 'undefined') { clearTimeout(this.delayTimer); this.delayTimer = null; } this.delayTimer = setTimeout(function () { _this.bodyTable.getModel().getRowModel().setEditable(_this.editable); _this.undo(); }, 1); }; /** * @param {?} $event * @return {?} */ RecordView.prototype.onRedoButtonClicked = /** * @param {?} $event * @return {?} */ function ($event) { var _this = this; if (!this.canRedo()) { return; } // delay to wait for lostFocus fire if (this.delayTimer !== null && typeof this.delayTimer !== 'undefined') { clearTimeout(this.delayTimer); this.delayTimer = null; } this.delayTimer = setTimeout(function () { _this.bodyTable.getModel().getRowModel().setEditable(_this.editable); _this.redo(); }, 1); }; /** * @param {?} $event * @return {?} */ RecordView.prototype.onCellDBLClicked = /** * @param {?} $event * @return {?} */ function ($event) { if (!this.editable) { return; } if ($event !== null && typeof $event !== 'undefined') { var /** @type {?} */ target = ($event.detail !== null && typeof $event.detail !== 'undefined') ? $event.detail.target : null; var /** @type {?} */ evData = ($event.detail !== null && typeof $event.detail !== 'undefined') ? $event.detail.data : null; if (evData !== null) { var /** @type {?} */ row = evData.rowIndex; var /** @type {?} */ col = evData.columnIndex; if (target !== null && typeof target !== 'undefined') { if (target.isCellEditing(col)) { var /** @type {?} */ nativeElement = this.bodyTable.getRowControllers()[row].getCellComponentInstanceAt(col).getElementRef().nativeElement; // blur all input before switch back $(nativeElement).find(":input").each(function (index, el) { $(el).blur(); }); target.setCellEditing(col, false); } else { target.setCellEditing(col, true); } } } } }; /** * @return {?} */ RecordView.prototype.getEditorDirtyData = /** * @return {?} */ function () { var _this = this; return new Promise(function (resolve, reject) { var /** @type {?} */ dirtyArray = _this.getDirtyCreateData(); resolve(dirtyArray); }); }; /** * @return {?} */ RecordView.prototype.getSelectedData = /** * @return {?} */ function () { var _this = this; return new Promise(function (resolve, reject) { var /** @type {?} */ selectedArray = _this.getTableSelectedData(); resolve(selectedArray); }); }; /** * @return {?} */ RecordView.prototype.hasDataDirty = /** * @return {?} */ function () { var /** @type {?} */ rowIdx = 0; try { for (var _a = tslib_1.__values(this.tableData), _b = _a.next(); !_b.done; _b = _a.next()) { var row = _b.value; var /** @type {?} */ colIdx = 0; try { for (var _c = tslib_1.__values(this.model.columns), _d = _c.next(); !_d.done; _d = _c.next()) { var col = _d.value; if (this.getDirty(rowIdx, colIdx, row.data)) { return true; } colIdx += 1; } } catch (e_12_1) { e_12 = { error: e_12_1 }; } finally { try { if (_d && !_d.done && (_e = _c.return)) _e.call(_c); } finally { if (e_12) throw e_12.error; } } rowIdx += 1; } } catch (e_13_1) { e_13 = { error: e_13_1 }; } finally { try { if (_b && !_b.done && (_f = _a.return)) _f.call(_a); } finally { if (e_13) throw e_13.error; } } return false; var e_13, _f, e_12, _e; }; /** * @return {?} */ RecordView.prototype.reloadTable = /** * @return {?} */ function () { // start and hide when data was loaded this.iconLoader.start(); var /** @type {?} */ setting = this.getViewSetting(); if (setting !== null && typeof setting !== 'undefined') { if (setting != null && ((typeof setting) !== 'undefined')) { this.model.fromJson(setting.value); } } if (this.editor.getDataSchema() != null) { var /** @type {?} */ dataSche = this.