1 var History =
function(table){
9 History.prototype.clear =
function(){
14 History.prototype.action =
function(type, component, data){
16 this.history = this.history.slice(0, this.index + 1);
27 History.prototype.getHistoryUndoSize =
function(){
28 return this.index + 1;
31 History.prototype.getHistoryRedoSize =
function(){
32 return this.history.length - (this.index + 1);
35 History.prototype.undo =
function(){
38 let action = this.history[this.index];
40 this.undoers[action.type].call(
this, action);
44 this.table.options.historyUndo.call(this.table, action.type, action.component.getComponent(), action.data);
48 console.warn(
"History Undo Error - No more history to undo");
53 History.prototype.redo =
function(){
54 if(this.history.length-1 >
this.index){
58 let action = this.history[this.index];
60 this.redoers[action.type].call(
this, action);
62 this.table.options.historyRedo.call(this.table, action.type, action.component.getComponent(), action.data);
66 console.warn(
"History Redo Error - No more history to redo");
72 History.prototype.undoers = {
73 cellEdit:
function(action){
74 action.component.setValueProcessData(action.data.oldValue);
77 rowAdd:
function(action){
78 action.component.deleteActual();
81 rowDelete:
function(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(action){
92 this.table.rowManager.moveRowActual(action.component,
this.table.rowManager.rows[action.data.pos],
false);
93 this.table.rowManager.redraw();
98 History.prototype.redoers = {
99 cellEdit:
function(action){
100 action.component.setValueProcessData(action.data.newValue);
103 rowAdd:
function(action){
104 var newRow = this.table.rowManager.addRowActual(action.data.data, action.data.pos, action.data.index);
106 if(this.table.options.groupBy &&
this.table.modExists(
"groupRows")){
107 this.table.modules.groupRows.updateGroupRows(
true);
110 this._rebindRow(action.component, newRow);
113 rowDelete:
function(action){
114 action.component.deleteActual();
117 rowMove:
function(action){
118 this.table.rowManager.moveRowActual(action.component,
this.table.rowManager.rows[action.data.pos],
false);
119 this.table.rowManager.redraw();
124 History.prototype._rebindRow =
function(oldRow, newRow){
125 this.history.forEach(
function(action){
126 if(action.component instanceof Row){
127 if(action.component === oldRow){
128 action.component = newRow;
130 }
else if(action.component instanceof Cell){
131 if(action.component.row === oldRow){
132 var field = action.component.column.getField();
135 action.component = newRow.getCell(field);
143 Tabulator.prototype.registerModule(
"history", History);