var __extends = this.__extends || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } __.prototype = b.prototype; d.prototype = new __(); }; var wijmo; (function (wijmo) { (function (grid) { (function (sheet) { 'use strict'; /** * Base class for Flexsheet undo/redo actions. */ var _UndoableAction = (function () { /** * Initializes a new instance of a @see:_UndoableAction class. * * @param owener The @see: FlexSheet control that the _UndoableAction works for. */ function _UndoableAction(owner) { this._owner = owner; this._sheetIndex = owner.selectedSheetIndex; } Object.defineProperty(_UndoableAction.prototype, "sheetIndex", { /** * Gets the index of the sheet that the undoable action wokrs for. */ get: function () { return this._sheetIndex; }, enumerable: true, configurable: true }); /** * Excutes undo of the undoable action */ _UndoableAction.prototype.undo = function () { throw 'This abstract method must be overrided.'; }; /** * Excutes redo of the undoable action */ _UndoableAction.prototype.redo = function () { throw 'This abstract method must be overrided.'; }; /** * Saves the current flexsheet state. */ _UndoableAction.prototype.saveNewState = function () { throw 'This abstract method must be overrided.'; }; return _UndoableAction; })(); sheet._UndoableAction = _UndoableAction; /** * Defines the _EditAction class. * * It deals with the undo\redo for editing value of the flexsheet cells. */ var _EditAction = (function (_super) { __extends(_EditAction, _super); /** * Initializes a new instance of a @see:_EditAction class. * * @param owener The @see: FlexSheet control that the _EditAction works for. */ function _EditAction(owner) { _super.call(this, owner); this._selection = owner.selection; this._oldValue = owner.getCellData(this._selection.topRow, this._selection.leftCol, !!owner.columns[this._selection.leftCol].dataMap); this._oldValue = this._oldValue != undefined ? this._oldValue : ''; } /** * Overrides the undo method of its base class @see:_UndoableAction. */ _EditAction.prototype.undo = function () { this._owner.setCellData(this._selection.topRow, this._selection.leftCol, this._oldValue); this._owner.select(this._selection); this._owner.refresh(false); }; /** * Overrides the redo method of its base class @see:_UndoableAction. */ _EditAction.prototype.redo = function () { this._owner.setCellData(this._selection.topRow, this._selection.leftCol, this._newValue); this._owner.select(this._selection); this._owner.refresh(false); }; /** * Overrides the saveNewState of its base class @see:_UndoableAction. */ _EditAction.prototype.saveNewState = function () { var currentCol = this._owner.columns[this._selection.leftCol]; if (!currentCol) { return false; } this._newValue = this._owner.getCellData(this._selection.topRow, this._selection.leftCol, !!this._owner.columns[this._selection.leftCol].dataMap); this._newValue = this._newValue != undefined ? this._newValue : ''; return this._newValue !== this._oldValue; }; return _EditAction; })(_UndoableAction); sheet._EditAction = _EditAction; /** * Defines the _ColumnResizeAction class. * * It deals with the undo\redo for resize the column of the flexsheet. */ var _ColumnResizeAction = (function (_super) { __extends(_ColumnResizeAction, _super); /** * Initializes a new instance of a @see:_ColumnResizeAction class. * * @param owener The @see: FlexSheet control that the _ColumnResizeAction works for. * @param colIndex it indicates which column is resizing. */ function _ColumnResizeAction(owner, colIndex) { _super.call(this, owner); this._colIndex = colIndex; this._oldColWidth = owner.columns[colIndex].width; } /** * Overrides the undo method of its base class @see:_UndoableAction. */ _ColumnResizeAction.prototype.undo = function () { this._owner.columns[this._colIndex].width = this._oldColWidth; }; /** * Overrides the redo method of its base class @see:_UndoableAction. */ _ColumnResizeAction.prototype.redo = function () { this._owner.columns[this._colIndex].width = this._newColWidth; }; /** * Overrides the saveNewState method of its base class @see:_UndoableAction. */ _ColumnResizeAction.prototype.saveNewState = function () { this._newColWidth = this._owner.columns[this._colIndex].width; if (this._oldColWidth === this._newColWidth) { return false; } return true; }; return _ColumnResizeAction; })(_UndoableAction); sheet._ColumnResizeAction = _ColumnResizeAction; /** * Defines the _RowResizeAction class. * * It deals with the undo\redo for resize the row of the flexsheet. */ var _RowResizeAction = (function (_super) { __extends(_RowResizeAction, _super); /** * Initializes a new instance of a @see:_RowResizeAction class. * * @param owener The @see: FlexSheet control that the _RowResizeAction works for. * @param rowIndex it indicates which row is resizing. */ function _RowResizeAction(owner, rowIndex) { _super.call(this, owner); this._rowIndex = rowIndex; this._oldRowHeight = owner.rows[rowIndex].height; } /** * Overrides the undo method of its base class @see:_UndoableAction. */ _RowResizeAction.prototype.undo = function () { this._owner.rows[this._rowIndex].height = this._oldRowHeight; }; /** * Overrides the redo method of its base class @see:_UndoableAction. */ _RowResizeAction.prototype.redo = function () { this._owner.rows[this._rowIndex].height = this._newRowHeight; }; /** * Overrides the saveNewState method of its base class @see:_UndoableAction. */ _RowResizeAction.prototype.saveNewState = function () { this._newRowHeight = this._owner.rows[this._rowIndex].height; if (this._oldRowHeight === this._newRowHeight) { return false; } return true; }; return _RowResizeAction; })(_UndoableAction); sheet._RowResizeAction = _RowResizeAction; /** * Defines the _InsertDeleteColumnAction class. * * It deals with the undo\redo for insert or delete column of the flexsheet. */ var _InsertDeleteColumnAction = (function (_super) { __extends(_InsertDeleteColumnAction, _super); /** * Initializes a new instance of a @see:_InsertDeleteColumnAction class. * * @param owener The @see: FlexSheet control that the _InsertDeleteColumnAction works for. */ function _InsertDeleteColumnAction(owner) { var colIndex, columns = []; _super.call(this, owner); for (colIndex = 0; colIndex < owner.columns.length; colIndex++) { columns.push(owner.columns[colIndex]); } this._oldValue = { columns: columns, sortList: owner.sortManager._committedList.slice(), styledCells: JSON.parse(JSON.stringify(owner.styledCells)), mergedCells: owner._cloneMergedCells() }; } /** * Overrides the undo method of its base class @see:_UndoableAction. */ _InsertDeleteColumnAction.prototype.undo = function () { var colIndex; this._owner.columns.clear(); this._owner.styledCells = undefined; this._owner.mergedRange = undefined; for (colIndex = 0; colIndex < this._oldValue.columns.length; colIndex++) { this._owner.columns.push(this._oldValue.columns[colIndex]); } this._owner.styledCells = this._oldValue.styledCells; this._owner.mergedRange = this._oldValue.mergedCells; // Synch with current sheet. this._owner._copyTo(this._owner.selectedSheet); this._owner._copyFrom(this._owner.selectedSheet); // Synch the cell style for current sheet. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells; // Synch the merged range for current sheet. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange; this._owner.sortManager.sorts.sourceCollection = this._oldValue.sortList.slice(); this._owner.sortManager.commitSort(false); this._owner.sortManager.refresh(); this._owner.onColumnChanged(); this._owner.refresh(true); }; /** * Overrides the redo method of its base class @see:_UndoableAction. */ _InsertDeleteColumnAction.prototype.redo = function () { var colIndex; this._owner.columns.clear(); this._owner.styledCells = undefined; this._owner.mergedRange = undefined; for (colIndex = 0; colIndex < this._newValue.columns.length; colIndex++) { this._owner.columns.push(this._newValue.columns[colIndex]); } this._owner.styledCells = this._newValue.styledCells; this._owner.mergedRange = this._newValue.mergedCells; // Synch with current sheet. this._owner._copyTo(this._owner.selectedSheet); this._owner._copyFrom(this._owner.selectedSheet); // Synch the cell style for current sheet. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells; // Synch the merged range for current sheet. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange; this._owner.sortManager.sorts.sourceCollection = this._newValue.sortList.slice(); this._owner.sortManager.commitSort(false); this._owner.sortManager.refresh(); this._owner.onColumnChanged(); this._owner.refresh(true); }; /** * Overrides the saveNewState method of its base class @see:_UndoableAction. */ _InsertDeleteColumnAction.prototype.saveNewState = function () { var colIndex, columns = []; for (colIndex = 0; colIndex < this._owner.columns.length; colIndex++) { columns.push(this._owner.columns[colIndex]); } this._newValue = { columns: columns, sortList: this._owner.sortManager._committedList.slice(), styledCells: JSON.parse(JSON.stringify(this._owner.styledCells)), mergedCells: this._owner._cloneMergedCells() }; return true; }; return _InsertDeleteColumnAction; })(_UndoableAction); sheet._InsertDeleteColumnAction = _InsertDeleteColumnAction; /** * Defines the _InsertDeleteRowAction class. * * It deals with the undo\redo for insert or delete row of the flexsheet. */ var _InsertDeleteRowAction = (function (_super) { __extends(_InsertDeleteRowAction, _super); /** * Initializes a new instance of a @see:_InsertDeleteRowAction class. * * @param owener The @see: FlexSheet control that the _InsertDeleteRowAction works for. */ function _InsertDeleteRowAction(owner) { var rowIndex, colIndex, rows = [], columns = []; _super.call(this, owner); for (rowIndex = 0; rowIndex < owner.rows.length; rowIndex++) { rows.push(owner.rows[rowIndex]); } for (colIndex = 0; colIndex < owner.columns.length; colIndex++) { columns.push(owner.columns[colIndex]); } this._oldValue = { rows: rows, columns: columns, itemsSource: owner.itemsSource ? owner.itemsSource.slice() : undefined, styledCells: JSON.parse(JSON.stringify(owner.styledCells)), mergedCells: owner._cloneMergedCells() }; } /** * Overrides the undo method of its base class @see:_UndoableAction. */ _InsertDeleteRowAction.prototype.undo = function () { var rowIndex, colIndex, processingRow, dataSourceBinding = !!this._oldValue.itemsSource; this._owner.finishEditing(); this._owner.columns.clear(); this._owner.rows.clear(); this._owner.styledCells = undefined; this._owner.mergedRange = undefined; if (dataSourceBinding) { this._owner.autoGenerateColumns = false; this._owner.itemsSource = this._oldValue.itemsSource.slice(); } for (rowIndex = 0; rowIndex < this._oldValue.rows.length; rowIndex++) { processingRow = this._oldValue.rows[rowIndex]; if (dataSourceBinding) { if (!processingRow.dataItem && !(processingRow instanceof sheet.HeaderRow)) { this._owner.rows.splice(rowIndex, 0, processingRow); } } else { this._owner.rows.push(processingRow); } } for (colIndex = 0; colIndex < this._oldValue.columns.length; colIndex++) { this._owner.columns.push(this._oldValue.columns[colIndex]); } this._owner.styledCells = this._oldValue.styledCells; this._owner.mergedRange = this._oldValue.mergedCells; // Synch with current sheet. this._owner._copyTo(this._owner.selectedSheet); this._owner._copyFrom(this._owner.selectedSheet); // Synch the cell style for current sheet. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells; // Synch the merged range for current sheet. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange; this._owner.refresh(true); }; /** * Overrides the redo method of its base class @see:_UndoableAction. */ _InsertDeleteRowAction.prototype.redo = function () { var rowIndex, colIndex, processingRow, dataSourceBinding = !!this._newValue.itemsSource; this._owner.finishEditing(); this._owner.columns.clear(); this._owner.rows.clear(); this._owner.styledCells = undefined; this._owner.mergedRange = undefined; if (dataSourceBinding) { this._owner.autoGenerateColumns = false; this._owner.itemsSource = this._newValue.itemsSource.slice(); } for (rowIndex = 0; rowIndex < this._newValue.rows.length; rowIndex++) { processingRow = this._newValue.rows[rowIndex]; if (dataSourceBinding) { if (!processingRow.dataItem && !(processingRow instanceof sheet.HeaderRow)) { this._owner.rows.splice(rowIndex, 0, processingRow); } } else { this._owner.rows.push(processingRow); } } for (colIndex = 0; colIndex < this._newValue.columns.length; colIndex++) { this._owner.columns.push(this._newValue.columns[colIndex]); } this._owner.styledCells = this._newValue.styledCells; this._owner.mergedRange = this._newValue.mergedCells; // Synch with current sheet. this._owner._copyTo(this._owner.selectedSheet); this._owner._copyFrom(this._owner.selectedSheet); // Synch the cell style for current sheet. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells; // Synch the merged range for current sheet. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange; this._owner.refresh(true); }; /** * Overrides the saveNewState method of its base class @see:_UndoableAction. */ _InsertDeleteRowAction.prototype.saveNewState = function () { var rowIndex, colIndex, rows = [], columns = []; for (rowIndex = 0; rowIndex < this._owner.rows.length; rowIndex++) { rows.push(this._owner.rows[rowIndex]); } for (colIndex = 0; colIndex < this._owner.columns.length; colIndex++) { columns.push(this._owner.columns[colIndex]); } this._newValue = { rows: rows, columns: columns, itemsSource: this._owner.itemsSource ? this._owner.itemsSource.slice() : undefined, styledCells: JSON.parse(JSON.stringify(this._owner.styledCells)), mergedCells: this._owner._cloneMergedCells() }; return true; }; return _InsertDeleteRowAction; })(_UndoableAction); sheet._InsertDeleteRowAction = _InsertDeleteRowAction; /** * Defines the _CellStyleAction class. * * It deals with the undo\redo for applying style for the cells of the flexsheet. */ var _CellStyleAction = (function (_super) { __extends(_CellStyleAction, _super); /** * Initializes a new instance of a @see:_CellStyleAction class. * * @param owener The @see: FlexSheet control that the _CellStyleAction works for. * @param styledCells Current styled cells of the @see: FlexSheet control. */ function _CellStyleAction(owner, styledCells) { _super.call(this, owner); this._oldStyledCells = styledCells ? JSON.parse(JSON.stringify(styledCells)) : JSON.parse(JSON.stringify(owner.styledCells)); } /** * Overrides the undo method of its base class @see:_UndoableAction. */ _CellStyleAction.prototype.undo = function () { this._owner.styledCells = JSON.parse(JSON.stringify(this._oldStyledCells)); // Synch the cell style for current sheet. this._owner.selectedSheet.styledCells = this._owner.styledCells; this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells; this._owner.refresh(true); }; /** * Overrides the redo method of its base class @see:_UndoableAction. */ _CellStyleAction.prototype.redo = function () { this._owner.styledCells = JSON.parse(JSON.stringify(this._newStyledCells)); // Synch the cell style for current sheet. this._owner.selectedSheet.styledCells = this._owner.styledCells; this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells; this._owner.refresh(true); }; /** * Overrides the saveNewState method of its base class @see:_UndoableAction. */ _CellStyleAction.prototype.saveNewState = function () { this._newStyledCells = JSON.parse(JSON.stringify(this._owner.styledCells)); return true; }; return _CellStyleAction; })(_UndoableAction); sheet._CellStyleAction = _CellStyleAction; /** * Defines the _CellMergeAction class. * * It deals with the undo\redo for merging the cells of the flexsheet. */ var _CellMergeAction = (function (_super) { __extends(_CellMergeAction, _super); /** * Initializes a new instance of a @see:_CellMergeAction class. * * @param owener The @see: FlexSheet control that the _CellMergeAction works for. */ function _CellMergeAction(owner) { _super.call(this, owner); this._oldMergedCells = owner._cloneMergedCells(); } /** * Overrides the undo method of its base class @see:_UndoableAction. */ _CellMergeAction.prototype.undo = function () { this._owner.mergedRange = this._oldMergedCells; // Synch the merged range for current sheet. this._owner.selectedSheet.mergedRange = this._owner.mergedRange; this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange; this._owner.refresh(true); }; /** * Overrides the redo method of its base class @see:_UndoableAction. */ _CellMergeAction.prototype.redo = function () { this._owner.mergedRange = this._newMergedCells; // Synch the merged range for current sheet. this._owner.selectedSheet.mergedRange = this._owner.mergedRange; this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange; this._owner.refresh(true); }; /** * Overrides the saveNewState method of its base class @see:_UndoableAction. */ _CellMergeAction.prototype.saveNewState = function () { this._newMergedCells = this._owner._cloneMergedCells(); return true; }; return _CellMergeAction; })(_UndoableAction); sheet._CellMergeAction = _CellMergeAction; /** * Defines the _SortColumnAction class. * * It deals with the undo\redo for sort columns of the flexsheet. */ var _SortColumnAction = (function (_super) { __extends(_SortColumnAction, _super); /** * Initializes a new instance of a @see:_CellMergeAction class. * * @param owener The @see: FlexSheet control that the _CellMergeAction works for. */ function _SortColumnAction(owner) { var rowIndex, colIndex, columns = [], rows = []; _super.call(this, owner); if (!owner.itemsSource) { for (rowIndex = 0; rowIndex < owner.rows.length; rowIndex++) { rows.push(owner.rows[rowIndex]); } for (colIndex = 0; colIndex < owner.columns.length; colIndex++) { columns.push(owner.columns[colIndex]); } } this._oldValue = { sortList: owner.sortManager._committedList.slice(), rows: rows, columns: columns }; } /** * Overrides the undo method of its base class @see:_UndoableAction. */ _SortColumnAction.prototype.undo = function () { var rowIndex, colIndex; this._owner.sortManager.sorts.sourceCollection = this._oldValue.sortList.slice(); this._owner.sortManager.commitSort(false); this._owner.sortManager.refresh(); if (!this._owner.itemsSource) { this._owner.rows.clear(); this._owner.columns.clear(); this._owner.selectedSheet.dataGrid.rows.clear(); this._owner.selectedSheet.dataGrid.columns.clear(); for (rowIndex = 0; rowIndex < this._oldValue.rows.length; rowIndex++) { this._owner.rows.push(this._oldValue.rows[rowIndex]); // Synch the rows of the datagrid for current sheet. this._owner.selectedSheet.dataGrid.rows.push(this._oldValue.rows[rowIndex]); } for (colIndex = 0; colIndex < this._oldValue.columns.length; colIndex++) { this._owner.columns.push(this._oldValue.columns[colIndex]); // Synch the columns of the datagrid for current sheet. this._owner.selectedSheet.dataGrid.columns.push(this._oldValue.columns[colIndex]); } } }; /** * Overrides the redo method of its base class @see:_UndoableAction. */ _SortColumnAction.prototype.redo = function () { var rowIndex, colIndex; this._owner.sortManager.sorts.sourceCollection = this._newValue.sortList.slice(); this._owner.sortManager.commitSort(false); this._owner.sortManager.refresh(); if (!this._owner.itemsSource) { this._owner.rows.clear(); this._owner.columns.clear(); this._owner.selectedSheet.dataGrid.rows.clear(); this._owner.selectedSheet.dataGrid.columns.clear(); for (rowIndex = 0; rowIndex < this._newValue.rows.length; rowIndex++) { this._owner.rows.push(this._newValue.rows[rowIndex]); // Synch the rows of the datagrid for current sheet. this._owner.selectedSheet.dataGrid.rows.push(this._newValue.rows[rowIndex]); } for (colIndex = 0; colIndex < this._newValue.columns.length; colIndex++) { this._owner.columns.push(this._newValue.columns[colIndex]); // Synch the columns of the datagrid for current sheet. this._owner.selectedSheet.dataGrid.columns.push(this._newValue.columns[colIndex]); } } }; /** * Overrides the saveNewState method of its base class @see:_UndoableAction. */ _SortColumnAction.prototype.saveNewState = function () { var rowIndex, colIndex, columns = [], rows = []; if (!this._owner.itemsSource) { for (rowIndex = 0; rowIndex < this._owner.rows.length; rowIndex++) { rows.push(this._owner.rows[rowIndex]); } for (colIndex = 0; colIndex < this._owner.columns.length; colIndex++) { columns.push(this._owner.columns[colIndex]); } } this._newValue = { sortList: this._owner.sortManager._committedList.slice(), rows: rows, columns: columns }; return true; }; return _SortColumnAction; })(_UndoableAction); sheet._SortColumnAction = _SortColumnAction; })(grid.sheet || (grid.sheet = {})); var sheet = grid.sheet; })(wijmo.grid || (wijmo.grid = {})); var grid = wijmo.grid; })(wijmo || (wijmo = {})); //# sourceMappingURL=_UndoableAction.js.map