_UndoableAction.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. var __extends = this.__extends || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. __.prototype = b.prototype;
  5. d.prototype = new __();
  6. };
  7. var wijmo;
  8. (function (wijmo) {
  9. (function (grid) {
  10. (function (sheet) {
  11. 'use strict';
  12. /**
  13. * Base class for Flexsheet undo/redo actions.
  14. */
  15. var _UndoableAction = (function () {
  16. /**
  17. * Initializes a new instance of a @see:_UndoableAction class.
  18. *
  19. * @param owener The @see: FlexSheet control that the _UndoableAction works for.
  20. */
  21. function _UndoableAction(owner) {
  22. this._owner = owner;
  23. this._sheetIndex = owner.selectedSheetIndex;
  24. }
  25. Object.defineProperty(_UndoableAction.prototype, "sheetIndex", {
  26. /**
  27. * Gets the index of the sheet that the undoable action wokrs for.
  28. */
  29. get: function () {
  30. return this._sheetIndex;
  31. },
  32. enumerable: true,
  33. configurable: true
  34. });
  35. /**
  36. * Excutes undo of the undoable action
  37. */
  38. _UndoableAction.prototype.undo = function () {
  39. throw 'This abstract method must be overrided.';
  40. };
  41. /**
  42. * Excutes redo of the undoable action
  43. */
  44. _UndoableAction.prototype.redo = function () {
  45. throw 'This abstract method must be overrided.';
  46. };
  47. /**
  48. * Saves the current flexsheet state.
  49. */
  50. _UndoableAction.prototype.saveNewState = function () {
  51. throw 'This abstract method must be overrided.';
  52. };
  53. return _UndoableAction;
  54. })();
  55. sheet._UndoableAction = _UndoableAction;
  56. /**
  57. * Defines the _EditAction class.
  58. *
  59. * It deals with the undo\redo for editing value of the flexsheet cells.
  60. */
  61. var _EditAction = (function (_super) {
  62. __extends(_EditAction, _super);
  63. /**
  64. * Initializes a new instance of a @see:_EditAction class.
  65. *
  66. * @param owener The @see: FlexSheet control that the _EditAction works for.
  67. */
  68. function _EditAction(owner) {
  69. _super.call(this, owner);
  70. this._selection = owner.selection;
  71. this._oldValue = owner.getCellData(this._selection.topRow, this._selection.leftCol, !!owner.columns[this._selection.leftCol].dataMap);
  72. this._oldValue = this._oldValue != undefined ? this._oldValue : '';
  73. }
  74. /**
  75. * Overrides the undo method of its base class @see:_UndoableAction.
  76. */
  77. _EditAction.prototype.undo = function () {
  78. this._owner.setCellData(this._selection.topRow, this._selection.leftCol, this._oldValue);
  79. this._owner.select(this._selection);
  80. this._owner.refresh(false);
  81. };
  82. /**
  83. * Overrides the redo method of its base class @see:_UndoableAction.
  84. */
  85. _EditAction.prototype.redo = function () {
  86. this._owner.setCellData(this._selection.topRow, this._selection.leftCol, this._newValue);
  87. this._owner.select(this._selection);
  88. this._owner.refresh(false);
  89. };
  90. /**
  91. * Overrides the saveNewState of its base class @see:_UndoableAction.
  92. */
  93. _EditAction.prototype.saveNewState = function () {
  94. var currentCol = this._owner.columns[this._selection.leftCol];
  95. if (!currentCol) {
  96. return false;
  97. }
  98. this._newValue = this._owner.getCellData(this._selection.topRow, this._selection.leftCol, !!this._owner.columns[this._selection.leftCol].dataMap);
  99. this._newValue = this._newValue != undefined ? this._newValue : '';
  100. return this._newValue !== this._oldValue;
  101. };
  102. return _EditAction;
  103. })(_UndoableAction);
  104. sheet._EditAction = _EditAction;
  105. /**
  106. * Defines the _ColumnResizeAction class.
  107. *
  108. * It deals with the undo\redo for resize the column of the flexsheet.
  109. */
  110. var _ColumnResizeAction = (function (_super) {
  111. __extends(_ColumnResizeAction, _super);
  112. /**
  113. * Initializes a new instance of a @see:_ColumnResizeAction class.
  114. *
  115. * @param owener The @see: FlexSheet control that the _ColumnResizeAction works for.
  116. * @param colIndex it indicates which column is resizing.
  117. */
  118. function _ColumnResizeAction(owner, colIndex) {
  119. _super.call(this, owner);
  120. this._colIndex = colIndex;
  121. this._oldColWidth = owner.columns[colIndex].width;
  122. }
  123. /**
  124. * Overrides the undo method of its base class @see:_UndoableAction.
  125. */
  126. _ColumnResizeAction.prototype.undo = function () {
  127. this._owner.columns[this._colIndex].width = this._oldColWidth;
  128. };
  129. /**
  130. * Overrides the redo method of its base class @see:_UndoableAction.
  131. */
  132. _ColumnResizeAction.prototype.redo = function () {
  133. this._owner.columns[this._colIndex].width = this._newColWidth;
  134. };
  135. /**
  136. * Overrides the saveNewState method of its base class @see:_UndoableAction.
  137. */
  138. _ColumnResizeAction.prototype.saveNewState = function () {
  139. this._newColWidth = this._owner.columns[this._colIndex].width;
  140. if (this._oldColWidth === this._newColWidth) {
  141. return false;
  142. }
  143. return true;
  144. };
  145. return _ColumnResizeAction;
  146. })(_UndoableAction);
  147. sheet._ColumnResizeAction = _ColumnResizeAction;
  148. /**
  149. * Defines the _RowResizeAction class.
  150. *
  151. * It deals with the undo\redo for resize the row of the flexsheet.
  152. */
  153. var _RowResizeAction = (function (_super) {
  154. __extends(_RowResizeAction, _super);
  155. /**
  156. * Initializes a new instance of a @see:_RowResizeAction class.
  157. *
  158. * @param owener The @see: FlexSheet control that the _RowResizeAction works for.
  159. * @param rowIndex it indicates which row is resizing.
  160. */
  161. function _RowResizeAction(owner, rowIndex) {
  162. _super.call(this, owner);
  163. this._rowIndex = rowIndex;
  164. this._oldRowHeight = owner.rows[rowIndex].height;
  165. }
  166. /**
  167. * Overrides the undo method of its base class @see:_UndoableAction.
  168. */
  169. _RowResizeAction.prototype.undo = function () {
  170. this._owner.rows[this._rowIndex].height = this._oldRowHeight;
  171. };
  172. /**
  173. * Overrides the redo method of its base class @see:_UndoableAction.
  174. */
  175. _RowResizeAction.prototype.redo = function () {
  176. this._owner.rows[this._rowIndex].height = this._newRowHeight;
  177. };
  178. /**
  179. * Overrides the saveNewState method of its base class @see:_UndoableAction.
  180. */
  181. _RowResizeAction.prototype.saveNewState = function () {
  182. this._newRowHeight = this._owner.rows[this._rowIndex].height;
  183. if (this._oldRowHeight === this._newRowHeight) {
  184. return false;
  185. }
  186. return true;
  187. };
  188. return _RowResizeAction;
  189. })(_UndoableAction);
  190. sheet._RowResizeAction = _RowResizeAction;
  191. /**
  192. * Defines the _InsertDeleteColumnAction class.
  193. *
  194. * It deals with the undo\redo for insert or delete column of the flexsheet.
  195. */
  196. var _InsertDeleteColumnAction = (function (_super) {
  197. __extends(_InsertDeleteColumnAction, _super);
  198. /**
  199. * Initializes a new instance of a @see:_InsertDeleteColumnAction class.
  200. *
  201. * @param owener The @see: FlexSheet control that the _InsertDeleteColumnAction works for.
  202. */
  203. function _InsertDeleteColumnAction(owner) {
  204. var colIndex, columns = [];
  205. _super.call(this, owner);
  206. for (colIndex = 0; colIndex < owner.columns.length; colIndex++) {
  207. columns.push(owner.columns[colIndex]);
  208. }
  209. this._oldValue = {
  210. columns: columns,
  211. sortList: owner.sortManager._committedList.slice(),
  212. styledCells: JSON.parse(JSON.stringify(owner.styledCells)),
  213. mergedCells: owner._cloneMergedCells()
  214. };
  215. }
  216. /**
  217. * Overrides the undo method of its base class @see:_UndoableAction.
  218. */
  219. _InsertDeleteColumnAction.prototype.undo = function () {
  220. var colIndex;
  221. this._owner.columns.clear();
  222. this._owner.styledCells = undefined;
  223. this._owner.mergedRange = undefined;
  224. for (colIndex = 0; colIndex < this._oldValue.columns.length; colIndex++) {
  225. this._owner.columns.push(this._oldValue.columns[colIndex]);
  226. }
  227. this._owner.styledCells = this._oldValue.styledCells;
  228. this._owner.mergedRange = this._oldValue.mergedCells;
  229. // Synch with current sheet.
  230. this._owner._copyTo(this._owner.selectedSheet);
  231. this._owner._copyFrom(this._owner.selectedSheet);
  232. // Synch the cell style for current sheet.
  233. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells;
  234. // Synch the merged range for current sheet.
  235. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange;
  236. this._owner.sortManager.sorts.sourceCollection = this._oldValue.sortList.slice();
  237. this._owner.sortManager.commitSort(false);
  238. this._owner.sortManager.refresh();
  239. this._owner.onColumnChanged();
  240. this._owner.refresh(true);
  241. };
  242. /**
  243. * Overrides the redo method of its base class @see:_UndoableAction.
  244. */
  245. _InsertDeleteColumnAction.prototype.redo = function () {
  246. var colIndex;
  247. this._owner.columns.clear();
  248. this._owner.styledCells = undefined;
  249. this._owner.mergedRange = undefined;
  250. for (colIndex = 0; colIndex < this._newValue.columns.length; colIndex++) {
  251. this._owner.columns.push(this._newValue.columns[colIndex]);
  252. }
  253. this._owner.styledCells = this._newValue.styledCells;
  254. this._owner.mergedRange = this._newValue.mergedCells;
  255. // Synch with current sheet.
  256. this._owner._copyTo(this._owner.selectedSheet);
  257. this._owner._copyFrom(this._owner.selectedSheet);
  258. // Synch the cell style for current sheet.
  259. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells;
  260. // Synch the merged range for current sheet.
  261. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange;
  262. this._owner.sortManager.sorts.sourceCollection = this._newValue.sortList.slice();
  263. this._owner.sortManager.commitSort(false);
  264. this._owner.sortManager.refresh();
  265. this._owner.onColumnChanged();
  266. this._owner.refresh(true);
  267. };
  268. /**
  269. * Overrides the saveNewState method of its base class @see:_UndoableAction.
  270. */
  271. _InsertDeleteColumnAction.prototype.saveNewState = function () {
  272. var colIndex, columns = [];
  273. for (colIndex = 0; colIndex < this._owner.columns.length; colIndex++) {
  274. columns.push(this._owner.columns[colIndex]);
  275. }
  276. this._newValue = {
  277. columns: columns,
  278. sortList: this._owner.sortManager._committedList.slice(),
  279. styledCells: JSON.parse(JSON.stringify(this._owner.styledCells)),
  280. mergedCells: this._owner._cloneMergedCells()
  281. };
  282. return true;
  283. };
  284. return _InsertDeleteColumnAction;
  285. })(_UndoableAction);
  286. sheet._InsertDeleteColumnAction = _InsertDeleteColumnAction;
  287. /**
  288. * Defines the _InsertDeleteRowAction class.
  289. *
  290. * It deals with the undo\redo for insert or delete row of the flexsheet.
  291. */
  292. var _InsertDeleteRowAction = (function (_super) {
  293. __extends(_InsertDeleteRowAction, _super);
  294. /**
  295. * Initializes a new instance of a @see:_InsertDeleteRowAction class.
  296. *
  297. * @param owener The @see: FlexSheet control that the _InsertDeleteRowAction works for.
  298. */
  299. function _InsertDeleteRowAction(owner) {
  300. var rowIndex, colIndex, rows = [], columns = [];
  301. _super.call(this, owner);
  302. for (rowIndex = 0; rowIndex < owner.rows.length; rowIndex++) {
  303. rows.push(owner.rows[rowIndex]);
  304. }
  305. for (colIndex = 0; colIndex < owner.columns.length; colIndex++) {
  306. columns.push(owner.columns[colIndex]);
  307. }
  308. this._oldValue = {
  309. rows: rows,
  310. columns: columns,
  311. itemsSource: owner.itemsSource ? owner.itemsSource.slice() : undefined,
  312. styledCells: JSON.parse(JSON.stringify(owner.styledCells)),
  313. mergedCells: owner._cloneMergedCells()
  314. };
  315. }
  316. /**
  317. * Overrides the undo method of its base class @see:_UndoableAction.
  318. */
  319. _InsertDeleteRowAction.prototype.undo = function () {
  320. var rowIndex, colIndex, processingRow, dataSourceBinding = !!this._oldValue.itemsSource;
  321. this._owner.finishEditing();
  322. this._owner.columns.clear();
  323. this._owner.rows.clear();
  324. this._owner.styledCells = undefined;
  325. this._owner.mergedRange = undefined;
  326. if (dataSourceBinding) {
  327. this._owner.autoGenerateColumns = false;
  328. this._owner.itemsSource = this._oldValue.itemsSource.slice();
  329. }
  330. for (rowIndex = 0; rowIndex < this._oldValue.rows.length; rowIndex++) {
  331. processingRow = this._oldValue.rows[rowIndex];
  332. if (dataSourceBinding) {
  333. if (!processingRow.dataItem && !(processingRow instanceof sheet.HeaderRow)) {
  334. this._owner.rows.splice(rowIndex, 0, processingRow);
  335. }
  336. } else {
  337. this._owner.rows.push(processingRow);
  338. }
  339. }
  340. for (colIndex = 0; colIndex < this._oldValue.columns.length; colIndex++) {
  341. this._owner.columns.push(this._oldValue.columns[colIndex]);
  342. }
  343. this._owner.styledCells = this._oldValue.styledCells;
  344. this._owner.mergedRange = this._oldValue.mergedCells;
  345. // Synch with current sheet.
  346. this._owner._copyTo(this._owner.selectedSheet);
  347. this._owner._copyFrom(this._owner.selectedSheet);
  348. // Synch the cell style for current sheet.
  349. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells;
  350. // Synch the merged range for current sheet.
  351. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange;
  352. this._owner.refresh(true);
  353. };
  354. /**
  355. * Overrides the redo method of its base class @see:_UndoableAction.
  356. */
  357. _InsertDeleteRowAction.prototype.redo = function () {
  358. var rowIndex, colIndex, processingRow, dataSourceBinding = !!this._newValue.itemsSource;
  359. this._owner.finishEditing();
  360. this._owner.columns.clear();
  361. this._owner.rows.clear();
  362. this._owner.styledCells = undefined;
  363. this._owner.mergedRange = undefined;
  364. if (dataSourceBinding) {
  365. this._owner.autoGenerateColumns = false;
  366. this._owner.itemsSource = this._newValue.itemsSource.slice();
  367. }
  368. for (rowIndex = 0; rowIndex < this._newValue.rows.length; rowIndex++) {
  369. processingRow = this._newValue.rows[rowIndex];
  370. if (dataSourceBinding) {
  371. if (!processingRow.dataItem && !(processingRow instanceof sheet.HeaderRow)) {
  372. this._owner.rows.splice(rowIndex, 0, processingRow);
  373. }
  374. } else {
  375. this._owner.rows.push(processingRow);
  376. }
  377. }
  378. for (colIndex = 0; colIndex < this._newValue.columns.length; colIndex++) {
  379. this._owner.columns.push(this._newValue.columns[colIndex]);
  380. }
  381. this._owner.styledCells = this._newValue.styledCells;
  382. this._owner.mergedRange = this._newValue.mergedCells;
  383. // Synch with current sheet.
  384. this._owner._copyTo(this._owner.selectedSheet);
  385. this._owner._copyFrom(this._owner.selectedSheet);
  386. // Synch the cell style for current sheet.
  387. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells;
  388. // Synch the merged range for current sheet.
  389. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange;
  390. this._owner.refresh(true);
  391. };
  392. /**
  393. * Overrides the saveNewState method of its base class @see:_UndoableAction.
  394. */
  395. _InsertDeleteRowAction.prototype.saveNewState = function () {
  396. var rowIndex, colIndex, rows = [], columns = [];
  397. for (rowIndex = 0; rowIndex < this._owner.rows.length; rowIndex++) {
  398. rows.push(this._owner.rows[rowIndex]);
  399. }
  400. for (colIndex = 0; colIndex < this._owner.columns.length; colIndex++) {
  401. columns.push(this._owner.columns[colIndex]);
  402. }
  403. this._newValue = {
  404. rows: rows,
  405. columns: columns,
  406. itemsSource: this._owner.itemsSource ? this._owner.itemsSource.slice() : undefined,
  407. styledCells: JSON.parse(JSON.stringify(this._owner.styledCells)),
  408. mergedCells: this._owner._cloneMergedCells()
  409. };
  410. return true;
  411. };
  412. return _InsertDeleteRowAction;
  413. })(_UndoableAction);
  414. sheet._InsertDeleteRowAction = _InsertDeleteRowAction;
  415. /**
  416. * Defines the _CellStyleAction class.
  417. *
  418. * It deals with the undo\redo for applying style for the cells of the flexsheet.
  419. */
  420. var _CellStyleAction = (function (_super) {
  421. __extends(_CellStyleAction, _super);
  422. /**
  423. * Initializes a new instance of a @see:_CellStyleAction class.
  424. *
  425. * @param owener The @see: FlexSheet control that the _CellStyleAction works for.
  426. * @param styledCells Current styled cells of the @see: FlexSheet control.
  427. */
  428. function _CellStyleAction(owner, styledCells) {
  429. _super.call(this, owner);
  430. this._oldStyledCells = styledCells ? JSON.parse(JSON.stringify(styledCells)) : JSON.parse(JSON.stringify(owner.styledCells));
  431. }
  432. /**
  433. * Overrides the undo method of its base class @see:_UndoableAction.
  434. */
  435. _CellStyleAction.prototype.undo = function () {
  436. this._owner.styledCells = JSON.parse(JSON.stringify(this._oldStyledCells));
  437. // Synch the cell style for current sheet.
  438. this._owner.selectedSheet.styledCells = this._owner.styledCells;
  439. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells;
  440. this._owner.refresh(true);
  441. };
  442. /**
  443. * Overrides the redo method of its base class @see:_UndoableAction.
  444. */
  445. _CellStyleAction.prototype.redo = function () {
  446. this._owner.styledCells = JSON.parse(JSON.stringify(this._newStyledCells));
  447. // Synch the cell style for current sheet.
  448. this._owner.selectedSheet.styledCells = this._owner.styledCells;
  449. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].styledCells = this._owner.styledCells;
  450. this._owner.refresh(true);
  451. };
  452. /**
  453. * Overrides the saveNewState method of its base class @see:_UndoableAction.
  454. */
  455. _CellStyleAction.prototype.saveNewState = function () {
  456. this._newStyledCells = JSON.parse(JSON.stringify(this._owner.styledCells));
  457. return true;
  458. };
  459. return _CellStyleAction;
  460. })(_UndoableAction);
  461. sheet._CellStyleAction = _CellStyleAction;
  462. /**
  463. * Defines the _CellMergeAction class.
  464. *
  465. * It deals with the undo\redo for merging the cells of the flexsheet.
  466. */
  467. var _CellMergeAction = (function (_super) {
  468. __extends(_CellMergeAction, _super);
  469. /**
  470. * Initializes a new instance of a @see:_CellMergeAction class.
  471. *
  472. * @param owener The @see: FlexSheet control that the _CellMergeAction works for.
  473. */
  474. function _CellMergeAction(owner) {
  475. _super.call(this, owner);
  476. this._oldMergedCells = owner._cloneMergedCells();
  477. }
  478. /**
  479. * Overrides the undo method of its base class @see:_UndoableAction.
  480. */
  481. _CellMergeAction.prototype.undo = function () {
  482. this._owner.mergedRange = this._oldMergedCells;
  483. // Synch the merged range for current sheet.
  484. this._owner.selectedSheet.mergedRange = this._owner.mergedRange;
  485. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange;
  486. this._owner.refresh(true);
  487. };
  488. /**
  489. * Overrides the redo method of its base class @see:_UndoableAction.
  490. */
  491. _CellMergeAction.prototype.redo = function () {
  492. this._owner.mergedRange = this._newMergedCells;
  493. // Synch the merged range for current sheet.
  494. this._owner.selectedSheet.mergedRange = this._owner.mergedRange;
  495. this._owner.selectedSheet.dataGrid['wj_sheetInfo'].mergedRange = this._owner.mergedRange;
  496. this._owner.refresh(true);
  497. };
  498. /**
  499. * Overrides the saveNewState method of its base class @see:_UndoableAction.
  500. */
  501. _CellMergeAction.prototype.saveNewState = function () {
  502. this._newMergedCells = this._owner._cloneMergedCells();
  503. return true;
  504. };
  505. return _CellMergeAction;
  506. })(_UndoableAction);
  507. sheet._CellMergeAction = _CellMergeAction;
  508. /**
  509. * Defines the _SortColumnAction class.
  510. *
  511. * It deals with the undo\redo for sort columns of the flexsheet.
  512. */
  513. var _SortColumnAction = (function (_super) {
  514. __extends(_SortColumnAction, _super);
  515. /**
  516. * Initializes a new instance of a @see:_CellMergeAction class.
  517. *
  518. * @param owener The @see: FlexSheet control that the _CellMergeAction works for.
  519. */
  520. function _SortColumnAction(owner) {
  521. var rowIndex, colIndex, columns = [], rows = [];
  522. _super.call(this, owner);
  523. if (!owner.itemsSource) {
  524. for (rowIndex = 0; rowIndex < owner.rows.length; rowIndex++) {
  525. rows.push(owner.rows[rowIndex]);
  526. }
  527. for (colIndex = 0; colIndex < owner.columns.length; colIndex++) {
  528. columns.push(owner.columns[colIndex]);
  529. }
  530. }
  531. this._oldValue = {
  532. sortList: owner.sortManager._committedList.slice(),
  533. rows: rows,
  534. columns: columns
  535. };
  536. }
  537. /**
  538. * Overrides the undo method of its base class @see:_UndoableAction.
  539. */
  540. _SortColumnAction.prototype.undo = function () {
  541. var rowIndex, colIndex;
  542. this._owner.sortManager.sorts.sourceCollection = this._oldValue.sortList.slice();
  543. this._owner.sortManager.commitSort(false);
  544. this._owner.sortManager.refresh();
  545. if (!this._owner.itemsSource) {
  546. this._owner.rows.clear();
  547. this._owner.columns.clear();
  548. this._owner.selectedSheet.dataGrid.rows.clear();
  549. this._owner.selectedSheet.dataGrid.columns.clear();
  550. for (rowIndex = 0; rowIndex < this._oldValue.rows.length; rowIndex++) {
  551. this._owner.rows.push(this._oldValue.rows[rowIndex]);
  552. // Synch the rows of the datagrid for current sheet.
  553. this._owner.selectedSheet.dataGrid.rows.push(this._oldValue.rows[rowIndex]);
  554. }
  555. for (colIndex = 0; colIndex < this._oldValue.columns.length; colIndex++) {
  556. this._owner.columns.push(this._oldValue.columns[colIndex]);
  557. // Synch the columns of the datagrid for current sheet.
  558. this._owner.selectedSheet.dataGrid.columns.push(this._oldValue.columns[colIndex]);
  559. }
  560. }
  561. };
  562. /**
  563. * Overrides the redo method of its base class @see:_UndoableAction.
  564. */
  565. _SortColumnAction.prototype.redo = function () {
  566. var rowIndex, colIndex;
  567. this._owner.sortManager.sorts.sourceCollection = this._newValue.sortList.slice();
  568. this._owner.sortManager.commitSort(false);
  569. this._owner.sortManager.refresh();
  570. if (!this._owner.itemsSource) {
  571. this._owner.rows.clear();
  572. this._owner.columns.clear();
  573. this._owner.selectedSheet.dataGrid.rows.clear();
  574. this._owner.selectedSheet.dataGrid.columns.clear();
  575. for (rowIndex = 0; rowIndex < this._newValue.rows.length; rowIndex++) {
  576. this._owner.rows.push(this._newValue.rows[rowIndex]);
  577. // Synch the rows of the datagrid for current sheet.
  578. this._owner.selectedSheet.dataGrid.rows.push(this._newValue.rows[rowIndex]);
  579. }
  580. for (colIndex = 0; colIndex < this._newValue.columns.length; colIndex++) {
  581. this._owner.columns.push(this._newValue.columns[colIndex]);
  582. // Synch the columns of the datagrid for current sheet.
  583. this._owner.selectedSheet.dataGrid.columns.push(this._newValue.columns[colIndex]);
  584. }
  585. }
  586. };
  587. /**
  588. * Overrides the saveNewState method of its base class @see:_UndoableAction.
  589. */
  590. _SortColumnAction.prototype.saveNewState = function () {
  591. var rowIndex, colIndex, columns = [], rows = [];
  592. if (!this._owner.itemsSource) {
  593. for (rowIndex = 0; rowIndex < this._owner.rows.length; rowIndex++) {
  594. rows.push(this._owner.rows[rowIndex]);
  595. }
  596. for (colIndex = 0; colIndex < this._owner.columns.length; colIndex++) {
  597. columns.push(this._owner.columns[colIndex]);
  598. }
  599. }
  600. this._newValue = {
  601. sortList: this._owner.sortManager._committedList.slice(),
  602. rows: rows,
  603. columns: columns
  604. };
  605. return true;
  606. };
  607. return _SortColumnAction;
  608. })(_UndoableAction);
  609. sheet._SortColumnAction = _SortColumnAction;
  610. })(grid.sheet || (grid.sheet = {}));
  611. var sheet = grid.sheet;
  612. })(wijmo.grid || (wijmo.grid = {}));
  613. var grid = wijmo.grid;
  614. })(wijmo || (wijmo = {}));
  615. //# sourceMappingURL=_UndoableAction.js.map