Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

history.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /* Tabulator v4.6.3 (c) Oliver Folkerd */
  2. var History = function History(table) {
  3. this.table = table; //hold Tabulator object
  4. this.history = [];
  5. this.index = -1;
  6. };
  7. History.prototype.clear = function () {
  8. this.history = [];
  9. this.index = -1;
  10. };
  11. History.prototype.action = function (type, component, data) {
  12. this.history = this.history.slice(0, this.index + 1);
  13. this.history.push({
  14. type: type,
  15. component: component,
  16. data: data
  17. });
  18. this.index++;
  19. };
  20. History.prototype.getHistoryUndoSize = function () {
  21. return this.index + 1;
  22. };
  23. History.prototype.getHistoryRedoSize = function () {
  24. return this.history.length - (this.index + 1);
  25. };
  26. History.prototype.undo = function () {
  27. if (this.index > -1) {
  28. var action = this.history[this.index];
  29. this.undoers[action.type].call(this, action);
  30. this.index--;
  31. this.table.options.historyUndo.call(this.table, action.type, action.component.getComponent(), action.data);
  32. return true;
  33. } else {
  34. console.warn("History Undo Error - No more history to undo");
  35. return false;
  36. }
  37. };
  38. History.prototype.redo = function () {
  39. if (this.history.length - 1 > this.index) {
  40. this.index++;
  41. var action = this.history[this.index];
  42. this.redoers[action.type].call(this, action);
  43. this.table.options.historyRedo.call(this.table, action.type, action.component.getComponent(), action.data);
  44. return true;
  45. } else {
  46. console.warn("History Redo Error - No more history to redo");
  47. return false;
  48. }
  49. };
  50. History.prototype.undoers = {
  51. cellEdit: function cellEdit(action) {
  52. action.component.setValueProcessData(action.data.oldValue);
  53. },
  54. rowAdd: function rowAdd(action) {
  55. action.component.deleteActual();
  56. },
  57. rowDelete: function rowDelete(action) {
  58. var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
  59. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  60. this.table.modules.groupRows.updateGroupRows(true);
  61. }
  62. this._rebindRow(action.component, newRow);
  63. },
  64. rowMove: function rowMove(action) {
  65. this.table.rowManager.moveRowActual(action.component, this.table.rowManager.rows[action.data.posFrom], !action.data.after);
  66. this.table.rowManager.redraw();
  67. }
  68. };
  69. History.prototype.redoers = {
  70. cellEdit: function cellEdit(action) {
  71. action.component.setValueProcessData(action.data.newValue);
  72. },
  73. rowAdd: function rowAdd(action) {
  74. var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
  75. if (this.table.options.groupBy && this.table.modExists("groupRows")) {
  76. this.table.modules.groupRows.updateGroupRows(true);
  77. }
  78. this._rebindRow(action.component, newRow);
  79. },
  80. rowDelete: function rowDelete(action) {
  81. action.component.deleteActual();
  82. },
  83. rowMove: function rowMove(action) {
  84. this.table.rowManager.moveRowActual(action.component, this.table.rowManager.rows[action.data.posTo], action.data.after);
  85. this.table.rowManager.redraw();
  86. }
  87. };
  88. //rebind rows to new element after deletion
  89. History.prototype._rebindRow = function (oldRow, newRow) {
  90. this.history.forEach(function (action) {
  91. if (action.component instanceof Row) {
  92. if (action.component === oldRow) {
  93. action.component = newRow;
  94. }
  95. } else if (action.component instanceof Cell) {
  96. if (action.component.row === oldRow) {
  97. var field = action.component.column.getField();
  98. if (field) {
  99. action.component = newRow.getCell(field);
  100. }
  101. }
  102. }
  103. });
  104. };
  105. Tabulator.prototype.registerModule("history", History);