UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

1,120 lines (1,108 loc) • 115 kB
/** * DevExtreme (cjs/ui/grid_core/ui.grid_core.editing.js) * Version: 22.1.9 * Build date: Tue Apr 18 2023 * * Copyright (c) 2012 - 2023 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; function _typeof(obj) { return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) { return typeof obj } : function(obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj }, _typeof(obj) } exports.editingModule = void 0; var _renderer = _interopRequireDefault(require("../../core/renderer")); var _dom_adapter = _interopRequireDefault(require("../../core/dom_adapter")); var _events_engine = _interopRequireDefault(require("../../events/core/events_engine")); var _guid = _interopRequireDefault(require("../../core/guid")); var _dom = require("../../core/utils/dom"); var _type = require("../../core/utils/type"); var _iterator = require("../../core/utils/iterator"); var _extend = require("../../core/utils/extend"); var _uiGrid_core = _interopRequireDefault(require("./ui.grid_core.modules")); var _click = require("../../events/click"); var _pointer = _interopRequireDefault(require("../../events/pointer")); var _uiGrid_core2 = _interopRequireDefault(require("./ui.grid_core.utils")); var _array_utils = require("../../data/array_utils"); var _index = require("../../events/utils/index"); var _dialog = require("../dialog"); var _message = _interopRequireDefault(require("../../localization/message")); var _devices = _interopRequireDefault(require("../../core/devices")); var _deferred = require("../../core/utils/deferred"); var _common = require("../../core/utils/common"); var iconUtils = _interopRequireWildcard(require("../../core/utils/icon")); var _uiGrid_core3 = require("./ui.grid_core.editing_constants"); var _object = require("../../core/utils/object"); function _getRequireWildcardCache(nodeInterop) { if ("function" !== typeof WeakMap) { return null } var cacheBabelInterop = new WeakMap; var cacheNodeInterop = new WeakMap; return (_getRequireWildcardCache = function(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop })(nodeInterop) } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj } if (null === obj || "object" !== _typeof(obj) && "function" !== typeof obj) { return { default: obj } } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj) } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if ("default" !== key && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc) } else { newObj[key] = obj[key] } } } newObj.default = obj; if (cache) { cache.set(obj, newObj) } return newObj } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj } } function _extends() { _extends = Object.assign ? Object.assign.bind() : function(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key] } } } return target }; return _extends.apply(this, arguments) } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread() } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.") } function _unsupportedIterableToArray(o, minLen) { if (!o) { return } if ("string" === typeof o) { return _arrayLikeToArray(o, minLen) } var n = Object.prototype.toString.call(o).slice(8, -1); if ("Object" === n && o.constructor) { n = o.constructor.name } if ("Map" === n || "Set" === n) { return Array.from(o) } if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) { return _arrayLikeToArray(o, minLen) } } function _iterableToArray(iter) { if ("undefined" !== typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) { return Array.from(iter) } } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { return _arrayLikeToArray(arr) } } function _arrayLikeToArray(arr, len) { if (null == len || len > arr.length) { len = arr.length } for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i] } return arr2 } var READONLY_CLASS = "readonly"; var LINK_CLASS = "dx-link"; var ROW_SELECTED = "dx-selection"; var EDIT_BUTTON_CLASS = "dx-edit-button"; var COMMAND_EDIT_CLASS = "dx-command-edit"; var COMMAND_EDIT_WITH_ICONS_CLASS = COMMAND_EDIT_CLASS + "-with-icons"; var INSERT_INDEX = "__DX_INSERT_INDEX__"; var ROW_INSERTED = "dx-row-inserted"; var ROW_MODIFIED = "dx-row-modified"; var CELL_MODIFIED = "dx-cell-modified"; var EDITING_NAMESPACE = "dxDataGridEditing"; var CELL_FOCUS_DISABLED_CLASS = "dx-cell-focus-disabled"; var DATA_EDIT_DATA_UPDATE_TYPE = "update"; var DEFAULT_START_EDIT_ACTION = "click"; var EDIT_LINK_CLASS = { save: "dx-link-save", cancel: "dx-link-cancel", edit: "dx-link-edit", undelete: "dx-link-undelete", delete: "dx-link-delete", add: "dx-link-add" }; var EDIT_ICON_CLASS = { save: "save", cancel: "revert", edit: "edit", undelete: "revert", delete: "trash", add: "add" }; var METHOD_NAMES = { edit: "editRow", delete: "deleteRow", undelete: "undeleteRow", save: "saveEditData", cancel: "cancelEditData", add: "addRowByRowIndex" }; var ACTION_OPTION_NAMES = { add: "allowAdding", edit: "allowUpdating", delete: "allowDeleting" }; var BUTTON_NAMES = ["edit", "save", "cancel", "delete", "undelete"]; var EDITING_CHANGES_OPTION_NAME = "editing.changes"; var createFailureHandler = function(deferred) { return function(arg) { var error = arg instanceof Error ? arg : new Error(arg && String(arg) || "Unknown error"); deferred.reject(error) } }; var isEditingCell = function(isEditRow, cellOptions) { return cellOptions.isEditing || isEditRow && cellOptions.column.allowEditing }; var isEditingOrShowEditorAlwaysDataCell = function(isEditRow, cellOptions) { var isCommandCell = !!cellOptions.column.command; var isEditing = isEditingCell(isEditRow, cellOptions); var isEditorCell = !isCommandCell && (isEditing || cellOptions.column.showEditorAlways); return "data" === cellOptions.rowType && isEditorCell }; var EditingController = _uiGrid_core.default.ViewController.inherit(function() { var getButtonIndex = function(buttons, name) { var result = -1; buttons.some((function(button, index) { if (getButtonName(button) === name) { result = index; return true } })); return result }; function getButtonName(button) { return (0, _type.isObject)(button) ? button.name : button } return { init: function() { this._columnsController = this.getController("columns"); this._dataController = this.getController("data"); this._rowsView = this.getView("rowsView"); this._lastOperation = null; this._changes = []; if (this._deferreds) { this._deferreds.forEach((function(d) { return d.reject("cancel") })) } this._deferreds = []; if (!this._dataChangedHandler) { this._dataChangedHandler = this._handleDataChanged.bind(this); this._dataController.changed.add(this._dataChangedHandler) } if (!this._saveEditorHandler) { this.createAction("onInitNewRow", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onRowInserting", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onRowInserted", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onEditingStart", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onRowUpdating", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onRowUpdated", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onRowRemoving", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onRowRemoved", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onSaved", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onSaving", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onEditCanceling", { excludeValidators: ["disabled", "readOnly"] }); this.createAction("onEditCanceled", { excludeValidators: ["disabled", "readOnly"] }) } this._updateEditColumn(); this._updateEditButtons(); if (!this._internalState) { this._internalState = [] } this.component._optionsByReference[_uiGrid_core3.EDITING_EDITROWKEY_OPTION_NAME] = true; this.component._optionsByReference[EDITING_CHANGES_OPTION_NAME] = true }, getEditMode: function() { var editMode = this.option("editing.mode"); if (-1 !== _uiGrid_core3.EDIT_MODES.indexOf(editMode)) { return editMode } return _uiGrid_core3.EDIT_MODE_ROW }, _getDefaultEditorTemplate: function() { var _this = this; return function(container, options) { var $editor = (0, _renderer.default)("<div>").appendTo(container); _this.getController("editorFactory").createEditor($editor, (0, _extend.extend)({}, options.column, { value: options.value, setValue: options.setValue, row: options.row, parentType: "dataRow", width: null, readOnly: !options.setValue, isOnForm: options.isOnForm, id: options.id })) } }, _getNewRowPosition: function() { var newRowPosition = this.option("editing.newRowPosition"); var scrollingMode = this.option("scrolling.mode"); if ("virtual" === scrollingMode) { switch (newRowPosition) { case _uiGrid_core3.PAGE_TOP_NEW_ROW_POSITION: return _uiGrid_core3.VIEWPORT_TOP_NEW_ROW_POSITION; case _uiGrid_core3.PAGE_BOTTOM_NEW_ROW_POSITION: return _uiGrid_core3.VIEWPORT_BOTTOM_NEW_ROW_POSITION; default: return newRowPosition } } return newRowPosition }, getChanges: function() { return this.option(EDITING_CHANGES_OPTION_NAME) }, getInsertRowCount: function() { var changes = this.option(EDITING_CHANGES_OPTION_NAME); return changes.filter((function(change) { return "insert" === change.type })).length }, resetChanges: function() { var changes = this.getChanges(); var needReset = null === changes || void 0 === changes ? void 0 : changes.length; if (needReset) { this._silentOption(EDITING_CHANGES_OPTION_NAME, []) } }, _getInternalData: function(key) { return this._internalState.filter((function(item) { return (0, _common.equalByValue)(item.key, key) }))[0] }, _addInternalData: function(params) { var internalData = this._getInternalData(params.key); if (internalData) { return (0, _extend.extend)(internalData, params) } this._internalState.push(params); return params }, _getOldData: function(key) { var _this$_getInternalDat; return null === (_this$_getInternalDat = this._getInternalData(key)) || void 0 === _this$_getInternalDat ? void 0 : _this$_getInternalDat.oldData }, getUpdatedData: function(data) { var key = this._dataController.keyOf(data); var changes = this.getChanges(); var editIndex = _uiGrid_core2.default.getIndexByKey(key, changes); if (changes[editIndex]) { return (0, _array_utils.createObjectWithChanges)(data, changes[editIndex].data) } return data }, getInsertedData: function() { return this.getChanges().filter((function(change) { return change.data && change.type === _uiGrid_core3.DATA_EDIT_DATA_INSERT_TYPE })).map((function(change) { return change.data })) }, getRemovedData: function() { var _this2 = this; return this.getChanges().filter((function(change) { return _this2._getOldData(change.key) && change.type === _uiGrid_core3.DATA_EDIT_DATA_REMOVE_TYPE })).map((function(change) { return _this2._getOldData(change.key) })) }, _fireDataErrorOccurred: function(arg) { if ("cancel" === arg) { return } var $popupContent = this.getPopupContent(); this._dataController.dataErrorOccurred.fire(arg, $popupContent) }, _needToCloseEditableCell: _common.noop, _closeEditItem: _common.noop, _handleDataChanged: _common.noop, _isDefaultButtonVisible: function(button, options) { var result = true; switch (button.name) { case "delete": result = this.allowDeleting(options); break; case "undelete": result = false } return result }, _isButtonVisible: function(button, options) { var visible = button.visible; if (!(0, _type.isDefined)(visible)) { return this._isDefaultButtonVisible(button, options) } return (0, _type.isFunction)(visible) ? visible.call(button, { component: options.component, row: options.row, column: options.column }) : visible }, _isButtonDisabled: function(button, options) { var disabled = button.disabled; return (0, _type.isFunction)(disabled) ? disabled.call(button, { component: options.component, row: options.row, column: options.column }) : !!disabled }, _getButtonConfig: function(button, options) { var _this3 = this; var config = (0, _type.isObject)(button) ? button : {}; var buttonName = getButtonName(button); var editingTexts = function(options) { var editingTexts = options.component.option("editing.texts") || {}; return { save: editingTexts.saveRowChanges, cancel: editingTexts.cancelRowChanges, edit: editingTexts.editRow, undelete: editingTexts.undeleteRow, delete: editingTexts.deleteRow, add: editingTexts.addRowToNode } }(options); var methodName = METHOD_NAMES[buttonName]; var editingOptions = this.option("editing"); var actionName = ACTION_OPTION_NAMES[buttonName]; var allowAction = actionName ? editingOptions[actionName] : true; return (0, _extend.extend)({ name: buttonName, text: editingTexts[buttonName], cssClass: EDIT_LINK_CLASS[buttonName] }, { onClick: methodName && function(e) { var event = e.event; event.stopPropagation(); event.preventDefault(); setTimeout((function() { options.row && allowAction && _this3[methodName] && _this3[methodName](options.row.rowIndex) })) } }, config) }, _getEditingButtons: function(options) { var _this4 = this; var buttonIndex; var haveCustomButtons = !!options.column.buttons; var buttons = (options.column.buttons || []).slice(); if (haveCustomButtons) { buttonIndex = getButtonIndex(buttons, "edit"); if (buttonIndex >= 0) { if (getButtonIndex(buttons, "save") < 0) { buttons.splice(buttonIndex + 1, 0, "save") } if (getButtonIndex(buttons, "cancel") < 0) { buttons.splice(getButtonIndex(buttons, "save") + 1, 0, "cancel") } } buttonIndex = getButtonIndex(buttons, "delete"); if (buttonIndex >= 0 && getButtonIndex(buttons, "undelete") < 0) { buttons.splice(buttonIndex + 1, 0, "undelete") } } else { buttons = BUTTON_NAMES.slice() } return buttons.map((function(button) { return _this4._getButtonConfig(button, options) })) }, _renderEditingButtons: function($container, buttons, options, change) { var _this5 = this; buttons.forEach((function(button) { if (_this5._isButtonVisible(button, options)) { _this5._createButton($container, button, options, change) } })) }, _getEditCommandCellTemplate: function() { var _this6 = this; return function(container, options, change) { var $container = (0, _renderer.default)(container); if ("data" === options.rowType) { var buttons = _this6._getEditingButtons(options); _this6._renderEditingButtons($container, buttons, options, change); options.watch && options.watch((function() { return buttons.map((function(button) { return _this6._isButtonVisible(button, options) })) }), (function() { $container.empty(); _this6._renderEditingButtons($container, buttons, options) })) } else { _uiGrid_core2.default.setEmptyText($container) } } }, isRowBasedEditMode: function() { var editMode = this.getEditMode(); return -1 !== _uiGrid_core3.ROW_BASED_MODES.indexOf(editMode) }, getFirstEditableColumnIndex: function() { var columnsController = this.getController("columns"); var columnIndex; var visibleColumns = columnsController.getVisibleColumns(); (0, _iterator.each)(visibleColumns, (function(index, column) { if (column.allowEditing) { columnIndex = index; return false } })); return columnIndex }, getFirstEditableCellInRow: function(rowIndex) { var rowsView = this.getView("rowsView"); return rowsView && rowsView._getCellElement(rowIndex ? rowIndex : 0, this.getFirstEditableColumnIndex()) }, getFocusedCellInRow: function(rowIndex) { return this.getFirstEditableCellInRow(rowIndex) }, getIndexByKey: function(key, items) { return _uiGrid_core2.default.getIndexByKey(key, items) }, hasChanges: function(rowIndex) { var changes = this.getChanges(); var result = false; for (var i = 0; i < (null === changes || void 0 === changes ? void 0 : changes.length); i++) { if (changes[i].type && (!(0, _type.isDefined)(rowIndex) || this._dataController.getRowIndexByKey(changes[i].key) === rowIndex)) { result = true; break } } return result }, dispose: function() { this.callBase(); clearTimeout(this._inputFocusTimeoutID); _events_engine.default.off(_dom_adapter.default.getDocument(), _pointer.default.up, this._pointerUpEditorHandler); _events_engine.default.off(_dom_adapter.default.getDocument(), _pointer.default.down, this._pointerDownEditorHandler); _events_engine.default.off(_dom_adapter.default.getDocument(), _click.name, this._saveEditorHandler) }, _silentOption: function(name, value) { if ("editing.changes" === name) { this._changes = (0, _object.deepExtendArraySafe)([], value) } this.callBase.apply(this, arguments) }, optionChanged: function(args) { if ("editing" === args.name) { var fullName = args.fullName; if (fullName === _uiGrid_core3.EDITING_EDITROWKEY_OPTION_NAME) { this._handleEditRowKeyChange(args) } else if (fullName === EDITING_CHANGES_OPTION_NAME) { var isEqual = (0, _common.equalByValue)(args.value, this._changes, -1); if (!isEqual) { this._changes = (0, _object.deepExtendArraySafe)([], args.value); this._handleChangesChange(args) } } else if (!args.handled) { this._columnsController.reinit(); this.init(); this.resetChanges(); this._resetEditColumnName(); this._resetEditRowKey() } args.handled = true } else { this.callBase(args) } }, _handleEditRowKeyChange: function(args) { var rowIndex = this._dataController.getRowIndexByKey(args.value); var oldRowIndexCorrection = this._getEditRowIndexCorrection(); var oldRowIndex = this._dataController.getRowIndexByKey(args.previousValue) + oldRowIndexCorrection; if ((0, _type.isDefined)(args.value)) { if (args.value !== args.previousValue) { this._editRowFromOptionChanged(rowIndex, oldRowIndex) } } else { this.cancelEditData() } }, _handleChangesChange: function(args) { var _this7 = this; var dataController = this._dataController; var changes = args.value; if (!args.value.length && !args.previousValue.length) { return } changes.forEach((function(change) { if ("insert" === change.type) { _this7._addInsertInfo(change) } else { var _items$rowIndex; var items = dataController.items(); var rowIndex = dataController.getRowIndexByKey(change.key); _this7._addInternalData({ key: change.key, oldData: null === (_items$rowIndex = items[rowIndex]) || void 0 === _items$rowIndex ? void 0 : _items$rowIndex.data }) } })); dataController.updateItems({ repaintChangesOnly: true, isLiveUpdate: false, isOptionChanged: true }) }, publicMethods: function() { return ["addRow", "deleteRow", "undeleteRow", "editRow", "saveEditData", "cancelEditData", "hasEditData"] }, refresh: function() { if (!(0, _type.isDefined)(this._pageIndex)) { return } this._refreshCore.apply(this, arguments) }, _refreshCore: _common.noop, isEditing: function() { var isEditRowKeyDefined = (0, _type.isDefined)(this.option(_uiGrid_core3.EDITING_EDITROWKEY_OPTION_NAME)); return isEditRowKeyDefined }, isEditRow: function() { return false }, _setEditRowKey: function(value, silent) { if (silent) { this._silentOption(_uiGrid_core3.EDITING_EDITROWKEY_OPTION_NAME, value) } else { this.option(_uiGrid_core3.EDITING_EDITROWKEY_OPTION_NAME, value) } if (this._refocusEditCell) { this._refocusEditCell = false; this._focusEditingCell() } }, _setEditRowKeyByIndex: function(rowIndex, silent) { var key = this._dataController.getKeyByRowIndex(rowIndex); if (void 0 === key) { this._dataController.fireError("E1043"); return } this._setEditRowKey(key, silent) }, getEditRowIndex: function() { return this._getVisibleEditRowIndex() }, getEditFormRowIndex: function() { return -1 }, isEditRowByIndex: function(rowIndex) { var key = this._dataController.getKeyByRowIndex(rowIndex); var isKeyEqual = (0, _type.isDefined)(key) && (0, _common.equalByValue)(this.option(_uiGrid_core3.EDITING_EDITROWKEY_OPTION_NAME), key); if (isKeyEqual) { return this._getVisibleEditRowIndex() === rowIndex } return isKeyEqual }, isEditCell: function(visibleRowIndex, columnIndex) { return this.isEditRowByIndex(visibleRowIndex) && this._getVisibleEditColumnIndex() === columnIndex }, getPopupContent: _common.noop, _isProcessedItem: function(item) { return false }, _getInsertRowIndex: function(items, change, isProcessedItems) { var _this8 = this; var result = -1; var dataController = this._dataController; var key = this._getInsertAfterOrBeforeKey(change); if (!(0, _type.isDefined)(key) && 0 === items.length) { result = 0 } else if ((0, _type.isDefined)(key)) { items.some((function(item, index) { var isProcessedItem = isProcessedItems || _this8._isProcessedItem(item); if ((0, _type.isObject)(item)) { if (isProcessedItem || (0, _type.isDefined)(item[INSERT_INDEX])) { if ((0, _common.equalByValue)(item.key, key)) { result = index } } else if ((0, _common.equalByValue)(dataController.keyOf(item), key)) { result = index } } if (result >= 0) { var nextItem = items[result + 1]; if (nextItem && ("detail" === nextItem.rowType || "detailAdaptive" === nextItem.rowType) && (0, _type.isDefined)(change.insertAfterKey)) { return } if ((0, _type.isDefined)(change.insertAfterKey)) { result += 1 } return true } })) } return result }, _generateNewItem: function(key) { var _this$_getInternalDat2; var item = { key: key }; var insertInfo = null === (_this$_getInternalDat2 = this._getInternalData(key)) || void 0 === _this$_getInternalDat2 ? void 0 : _this$_getInternalDat2.insertInfo; if (null !== insertInfo && void 0 !== insertInfo && insertInfo[INSERT_INDEX]) { item[INSERT_INDEX] = insertInfo[INSERT_INDEX] } return item }, _getLoadedRowIndex: function(items, change, isProcessedItems) { var loadedRowIndex = this._getInsertRowIndex(items, change, isProcessedItems); var dataController = this._dataController; if (loadedRowIndex < 0) { var newRowPosition = this._getNewRowPosition(); var pageIndex = dataController.pageIndex(); var insertAfterOrBeforeKey = this._getInsertAfterOrBeforeKey(change); if (newRowPosition !== _uiGrid_core3.LAST_NEW_ROW_POSITION && 0 === pageIndex && !(0, _type.isDefined)(insertAfterOrBeforeKey)) { loadedRowIndex = 0 } else if (newRowPosition === _uiGrid_core3.LAST_NEW_ROW_POSITION && dataController.isLastPageLoaded()) { loadedRowIndex = items.length } } return loadedRowIndex }, processItems: function(items, e) { var _this9 = this; var changeType = e.changeType; this.update(changeType); var changes = this.getChanges(); changes.forEach((function(change) { var _this9$_getInternalDa; var isInsert = change.type === _uiGrid_core3.DATA_EDIT_DATA_INSERT_TYPE; if (!isInsert) { return } var key = change.key; var insertInfo = null === (_this9$_getInternalDa = _this9._getInternalData(key)) || void 0 === _this9$_getInternalDa ? void 0 : _this9$_getInternalDa.insertInfo; if (!(0, _type.isDefined)(key) || !(0, _type.isDefined)(insertInfo)) { insertInfo = _this9._addInsertInfo(change); key = insertInfo.key } var loadedRowIndex = _this9._getLoadedRowIndex(items, change); var item = _this9._generateNewItem(key); if (loadedRowIndex >= 0) { items.splice(loadedRowIndex, 0, item) } })); return items }, processDataItem: function(item, options, generateDataValues) { var columns = options.visibleColumns; var key = item.data[INSERT_INDEX] ? item.data.key : item.key; var changes = this.getChanges(); var editIndex = _uiGrid_core2.default.getIndexByKey(key, changes); item.isEditing = false; if (editIndex >= 0) { this._processDataItemCore(item, changes[editIndex], key, columns, generateDataValues) } }, _processDataItemCore: function(item, change, key, columns, generateDataValues) { var data = change.data, type = change.type; switch (type) { case _uiGrid_core3.DATA_EDIT_DATA_INSERT_TYPE: item.isNewRow = true; item.key = key; item.data = data; break; case DATA_EDIT_DATA_UPDATE_TYPE: item.modified = true; item.oldData = item.data; item.data = (0, _array_utils.createObjectWithChanges)(item.data, data); item.modifiedValues = generateDataValues(data, columns, true); break; case _uiGrid_core3.DATA_EDIT_DATA_REMOVE_TYPE: item.removed = true } }, _initNewRow: function(options) { var _this10 = this; this.executeAction("onInitNewRow", options); if (options.promise) { var deferred = new _deferred.Deferred; (0, _deferred.when)((0, _deferred.fromPromise)(options.promise)).done(deferred.resolve).fail(createFailureHandler(deferred)).fail((function(arg) { return _this10._fireDataErrorOccurred(arg) })); return deferred } }, _createInsertInfo: function() { var insertInfo = {}; insertInfo[INSERT_INDEX] = this._getInsertIndex(); return insertInfo }, _addInsertInfo: function(change, parentKey) { var _this$_getInternalDat3; var insertInfo; var key = change.key; if (!(0, _type.isDefined)(key)) { key = String(new _guid.default); change.key = key } insertInfo = null === (_this$_getInternalDat3 = this._getInternalData(key)) || void 0 === _this$_getInternalDat3 ? void 0 : _this$_getInternalDat3.insertInfo; if (!(0, _type.isDefined)(insertInfo)) { var insertAfterOrBeforeKey = this._getInsertAfterOrBeforeKey(change); insertInfo = this._createInsertInfo(); if (!(0, _type.isDefined)(insertAfterOrBeforeKey)) { this._setInsertAfterOrBeforeKey(change, parentKey) } } this._addInternalData({ insertInfo: insertInfo, key: key }); return { insertInfo: insertInfo, key: key } }, _setInsertAfterOrBeforeKey: function(change, parentKey) { var dataController = this._dataController; var allItems = dataController.items(true); var rowsView = this.getView("rowsView"); var newRowPosition = this._getNewRowPosition(); switch (newRowPosition) { case _uiGrid_core3.FIRST_NEW_ROW_POSITION: case _uiGrid_core3.LAST_NEW_ROW_POSITION: break; case _uiGrid_core3.PAGE_TOP_NEW_ROW_POSITION: case _uiGrid_core3.PAGE_BOTTOM_NEW_ROW_POSITION: if (allItems.length) { var itemIndex = newRowPosition === _uiGrid_core3.PAGE_TOP_NEW_ROW_POSITION ? 0 : allItems.length - 1; change[0 === itemIndex ? "insertBeforeKey" : "insertAfterKey"] = allItems[itemIndex].key } break; default: var isViewportBottom = newRowPosition === _uiGrid_core3.VIEWPORT_BOTTOM_NEW_ROW_POSITION; var visibleItemIndex = isViewportBottom ? null === rowsView || void 0 === rowsView ? void 0 : rowsView.getBottomVisibleItemIndex() : null === rowsView || void 0 === rowsView ? void 0 : rowsView.getTopVisibleItemIndex(); var row = dataController.getVisibleRows()[visibleItemIndex]; if (row && (!row.isEditing && "detail" === row.rowType || "detailAdaptive" === row.rowType)) { visibleItemIndex++ } var insertKey = dataController.getKeyByRowIndex(visibleItemIndex); if ((0, _type.isDefined)(insertKey)) { change.insertBeforeKey = insertKey } } }, _getInsertIndex: function() { var _this11 = this; var maxInsertIndex = 0; this.getChanges().forEach((function(editItem) { var _this11$_getInternalD; var insertInfo = null === (_this11$_getInternalD = _this11._getInternalData(editItem.key)) || void 0 === _this11$_getInternalD ? void 0 : _this11$_getInternalD.insertInfo; if ((0, _type.isDefined)(insertInfo) && editItem.type === _uiGrid_core3.DATA_EDIT_DATA_INSERT_TYPE && insertInfo[INSERT_INDEX] > maxInsertIndex) { maxInsertIndex = insertInfo[INSERT_INDEX] } })); return maxInsertIndex + 1 }, _getInsertAfterOrBeforeKey: function(insertChange) { var _insertChange$insertA; return null !== (_insertChange$insertA = insertChange.insertAfterKey) && void 0 !== _insertChange$insertA ? _insertChange$insertA : insertChange.insertBeforeKey }, _getPageIndexToInsertRow: function() { var newRowPosition = this._getNewRowPosition(); var dataController = this._dataController; var pageIndex = dataController.pageIndex(); var lastPageIndex = dataController.pageCount() - 1; if (newRowPosition === _uiGrid_core3.FIRST_NEW_ROW_POSITION && 0 !== pageIndex) { return 0 } else if (newRowPosition === _uiGrid_core3.LAST_NEW_ROW_POSITION && pageIndex !== lastPageIndex) { return lastPageIndex } return -1 }, addRow: function(parentKey) { var dataController = this._dataController; var store = dataController.store(); if (!store) { dataController.fireError("E1052", this.component.NAME); return (new _deferred.Deferred).reject() } return this._addRow(parentKey) }, _addRow: function(parentKey) { var _this12 = this; var dataController = this._dataController; var store = dataController.store(); var key = store && store.key(); var param = { data: {} }; var oldEditRowIndex = this._getVisibleEditRowIndex(); var deferred = new _deferred.Deferred; this.refresh({ allowCancelEditing: true }); if (!this._allowRowAdding()) { (0, _deferred.when)(this._navigateToNewRow(oldEditRowIndex)).done(deferred.resolve).fail(deferred.reject); return deferred.promise() } if (!key) { param.data.__KEY__ = String(new _guid.default) }(0, _deferred.when)(this._initNewRow(param, parentKey)).done((function() { if (_this12._allowRowAdding()) { (0, _deferred.when)(_this12._addRowCore(param.data, parentKey, oldEditRowIndex)).done(deferred.resolve).fail(deferred.reject) } else { deferred.reject("cancel") } })).fail(deferred.reject); return deferred.promise() }, _allowRowAdding: function() { var insertIndex = this._getInsertIndex(); if (insertIndex > 1) { return false } return true }, _addRowCore: function(data, parentKey, initialOldEditRowIndex) { var change = { data: data, type: _uiGrid_core3.DATA_EDIT_DATA_INSERT_TYPE }; var editRowIndex = this._getVisibleEditRowIndex(); var insertInfo = this._addInsertInfo(change, parentKey); var key = insertInfo.key; this._setEditRowKey(key, true); this._addChange(change); return this._navigateToNewRow(initialOldEditRowIndex, change, editRowIndex) }, _navigateToNewRow: function(oldEditRowIndex, change, editRowIndex) { var _editRowIndex, _change, _this13 = this; var d = new _deferred.Deferred; var dataController = this._dataController; var focusController = this.getController("focus"); editRowIndex = null !== (_editRowIndex = editRowIndex) && void 0 !== _editRowIndex ? _editRowIndex : -1; change = null !== (_change = change) && void 0 !== _change ? _change : this.getChanges().filter((function(c) { return c.type === _uiGrid_core3.DATA_EDIT_DATA_INSERT_TYPE }))[0]; if (!change) { return d.reject("cancel").promise() } var pageIndexToInsertRow = this._getPageIndexToInsertRow(); var rowIndex = this._getLoadedRowIndex(dataController.items(), change, true); var navigateToRowByKey = function(key) { (0, _deferred.when)(null === focusController || void 0 === focusController ? void 0 : focusController.navigateToRow(key)).done((function() { rowIndex = dataController.getRowIndexByKey(change.key); d.resolve() })) }; var insertAfterOrBeforeKey = this._getInsertAfterOrBeforeKey(change); if (pageIndexToInsertRow >= 0) { dataController.pageIndex(pageIndexToInsertRow).done((function() { navigateToRowByKey(change.key) })).fail(d.reject) } else if (rowIndex < 0 && (0, _type.isDefined)(insertAfterOrBeforeKey)) { navigateToRowByKey(insertAfterOrBeforeKey) } else { dataController.updateItems({ changeType: "update", rowIndices: [oldEditRowIndex, editRowIndex, rowIndex] }); rowIndex = dataController.getRowIndexByKey(change.key); if (rowIndex < 0) { navigateToRowByKey(change.key) } else { d.resolve() } } d.done((function() { var _this13$_rowsView; null === (_this13$_rowsView = _this13._rowsView) || void 0 === _this13$_rowsView ? void 0 : _this13$_rowsView.waitAsyncTemplates(true).done((function() { _this13._showAddedRow(rowIndex); _this13._afterInsertRow(change.key) })) })); return d.promise() }, _showAddedRow: function(rowIndex) { this._focusFirstEditableCellInRow(rowIndex) }, _beforeFocusElementInRow: _common.noop, _focusFirstEditableCellInRow: function(rowIndex) { var _this14 = this; var dataController = this._dataController; var key = dataController.getKeyByRowIndex(rowIndex); var $firstCell = this.getFirstEditableCellInRow(rowIndex); this._editCellInProgress = true; this._delayedInputFocus($firstCell, (function() { rowIndex = dataController.getRowIndexByKey(key); _this14._editCellInProgress = false; _this14._beforeFocusElementInRow(rowIndex) })) }, _isEditingStart: function(options) { this.executeAction("onEditingStart", options); return options.cancel }, _beforeUpdateItems: _common.noop, _getVisibleEditColumnIndex: function() { var editColumnName = this.option(_uiGrid_core3.EDITING_EDITCOLUMNNAME_OPTION_NAME); if (!(0, _type.isDefined)(editColumnName)) { return -1 } return this._columnsController.getVisibleColumnIndex(editColumnName) }, _setEditColumnNameByIndex: function(index, silent) { var _visibleColumns$index; var visibleColumns = this._columnsController.getVisibleColumns(); this._setEditColumnName(null === (_visibleColumns$index = visibleColumns[index]) || void 0 === _visibleColumns$index ? void 0 : _visibleColumns$index.name, silent) }, _setEditColumnName: function(name, silent) { if (silent) { this._silentOption(_uiGrid_core3.EDITING_EDITCOLUMNNAME_OPTION_NAME, name) } else { this.option(_uiGrid_core3.EDITING_EDITCOLUMNNAME_OPTION_NAME, name) } }, _resetEditColumnName: function() { this._setEditColumnName(null, true) }, _getEditColumn: function() { var editColumnName = this.option(_uiGrid_core3.EDITING_EDITCOLUMNNAME_OPTION_NAME); return this._getColumnByName(editColumnName) }, _getColumnByName: function(name) { var visibleColumns = this._columnsController.getVisibleColumns(); var editColumn; (0, _type.isDefined)(name) && visibleColumns.some((function(column) { if (column.name === name) { editColumn = column; return true } })); return editColumn }, _getVisibleEditRowIndex: function(columnName) { var dataController = this._dataController; var editRowKey = this.option(_uiGrid_core3.EDITING_EDITROWKEY_OPTION_NAME); var rowIndex = dataController.getRowIndexByKey(editRowKey); if (-1 === rowIndex) { return rowIndex } return rowIndex + this._getEditRowIndexCorrection(columnName) }, _getEditRowIndexCorrection: function(columnName) { var editColumn = columnName ? this._getColumnByName(columnName) : this._getEditColumn(); var isColumnHidden = "adaptiveHidden" === (null === editColumn || void 0 === editColumn ? void 0 : editColumn.visibleWidth); return isColumnHidden ? 1 : 0 }, _resetEditRowKey: function() { this._setEditRowKey(null, true) }, _resetEditIndices: function() { this._resetEditColumnName(); this._resetEditRowKey() }, editRow: function(rowIndex) { var _item$oldData; var dataController = this._dataController; var items = dataController.items(); var item = items[rowIndex]; var params = { data: item && item.data, cancel: false }; var oldRowIndex = this._getVisibleEditRowIndex(); if (!item) { return } if (rowIndex === oldRowIndex) { return true } if (void 0 === item.key) { this._dataController.fireError("E1043"); return } if (!item.isNewRow) { params.key = item.key } if (this._isEditingStart(params)) { return } this.resetChanges(); this.init(); this._resetEditColumnName(); this._pageIndex = dataController.pageIndex(); this._addInternalData({ key: item.key, oldData: null !== (_item$oldData = item.oldData) && void 0 !== _item$oldData ? _item$oldData : item.data }); this._setEditRowKey(item.key) }, _editRowFromOptionChanged: function(rowIndex, oldRowIndex) { var rowIndices = [oldRowIndex, rowIndex]; this._beforeUpdateItems(rowIndices, rowIndex, oldRowIndex); this._editRowFromOptionChangedCore(rowIndices, rowIndex) }, _editRowFromOptionChangedCore: function(rowIndices, rowIndex, preventRendering) { this._needFocusEditor = true; thi