3 var History =
function History(table) {
10 History.prototype.clear =
function () {
15 History.prototype.action =
function (type, component, data) {
17 this.history = this.history.slice(0, this.index + 1);
28 History.prototype.getHistoryUndoSize =
function () {
29 return this.index + 1;
32 History.prototype.getHistoryRedoSize =
function () {
33 return this.history.length - (this.index + 1);
36 History.prototype.undo =
function () {
38 if (this.index > -1) {
39 var action = this.history[this.index];
41 this.undoers[action.type].call(
this, action);
45 this.table.options.historyUndo.call(this.table, action.type, action.component.getComponent(), action.data);
49 console.warn(
"History Undo Error - No more history to undo");
54 History.prototype.redo =
function () {
55 if (this.history.length - 1 >
this.index) {
59 var action = this.history[this.index];
61 this.redoers[action.type].call(
this, action);
63 this.table.options.historyRedo.call(this.table, action.type, action.component.getComponent(), action.data);
67 console.warn(
"History Redo Error - No more history to redo");
72 History.prototype.undoers = {
73 cellEdit:
function cellEdit(action) {
74 action.component.setValueProcessData(action.data.oldValue);
77 rowAdd:
function rowAdd(action) {
78 action.component.deleteActual();
81 rowDelete:
function rowDelete(action) {
82 var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
84 if (this.table.options.groupBy &&
this.table.modExists(
"groupRows")) {
85 this.table.modules.groupRows.updateGroupRows(
true);
88 this._rebindRow(action.component, newRow);
91 rowMove:
function rowMove(action) {
92 this.table.rowManager.moveRowActual(action.component,
this.table.rowManager.rows[action.data.pos],
false);
93 this.table.rowManager.redraw();
97 History.prototype.redoers = {
98 cellEdit:
function cellEdit(action) {
99 action.component.setValueProcessData(action.data.newValue);
102 rowAdd:
function rowAdd(action) {
103 var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
105 if (this.table.options.groupBy &&
this.table.modExists(
"groupRows")) {
106 this.table.modules.groupRows.updateGroupRows(
true);
109 this._rebindRow(action.component, newRow);
112 rowDelete:
function rowDelete(action) {
113 action.component.deleteActual();
116 rowMove:
function rowMove(action) {
117 this.table.rowManager.moveRowActual(action.component,
this.table.rowManager.rows[action.data.pos],
false);
118 this.table.rowManager.redraw();
123 History.prototype._rebindRow =
function (oldRow, newRow) {
124 this.history.forEach(
function (action) {
125 if (action.component instanceof Row) {
126 if (action.component === oldRow) {
127 action.component = newRow;
129 }
else if (action.component instanceof Cell) {
130 if (action.component.row === oldRow) {
131 var field = action.component.column.getField();
134 action.component = newRow.getCell(field);
141 Tabulator.prototype.registerModule(
"history", History);