function HistoryWidget(div, tabHeader) { this._div = div; this._tabHeader = tabHeader; this.update(); } HistoryWidget.prototype.resize = function() { var body = this._div.find(".history-panel-body"); var footer = this._div.find(".history-panel-footer"); var bodyPaddings = body.outerHeight(true) - body.height(); body.css("height", (this._div.height() - footer.outerHeight(true) - bodyPaddings) + "px"); }; HistoryWidget.prototype.update = function(onDone) { var self = this; Ajax.chainGetJSON( "/command/get-history?" + $.param({ project: theProject.id }), null, function(data) { self._data = data; self._render(); if (onDone) { onDone(); } } ); }; HistoryWidget.prototype._render = function() { var self = this; this._tabHeader.html('Undo/Redo ' + this._data.past.length + ''); this._div .empty() .unbind() .html( '
' + '

Don\'t worry ...

' + '

about making mistakes. Every change you make will be shown here, and you can undo changes at any point.

' + '

Learn more »

' + '
' + '
' + '
' + '
done upto here
' + '
' + '
' + '' ); var elmts = DOM.bind(this._div); var renderEntry = function(container, entry, lastDoneID, title) { var a = $('').appendTo(container); a.addClass("history-entry").html(entry.description).attr("title", title).click(function(evt) { return self._onClickHistoryEntry(evt, entry, lastDoneID); }); return a; }; if (this._data.past.length > 0 || this._data.future.length > 0) { if (!this._data.past.length) { elmts.pastDiv.html('
No change to undo
'); } else { for (var i = 0; i < this._data.past.length; i++) { var entry = this._data.past[i]; renderEntry(elmts.pastDiv, entry, i === 0 ? 0 : this._data.past[i - 1].id, "Undo to here"); } } if (!this._data.future.length) { elmts.futureDiv.html('
No change to redo
'); } else { for (var i = 0; i < this._data.future.length; i++) { var entry = this._data.future[i]; renderEntry(elmts.futureDiv, entry, entry.id, "Redo to here"); } } elmts.helpDiv.hide(); } else { elmts.bodyDiv.hide(); } elmts.extractLink.click(function() { self._extractOperations(); }); elmts.applyLink.click(function() { self._showApplyOperationsDialog(); }); this.resize(); elmts.bodyDiv[0].scrollTop = elmts.nowDiv[0].offsetTop + elmts.nowDiv[0].offsetHeight - elmts.bodyDiv[0].offsetHeight; }; HistoryWidget.prototype._onClickHistoryEntry = function(evt, entry, lastDoneID) { var self = this; Gridworks.postProcess( "undo-redo", { lastDoneID: lastDoneID }, null, { everythingChanged: true } ); }; HistoryWidget.prototype._extractOperations = function() { var self = this; $.getJSON( "/command/get-operations?" + $.param({ project: theProject.id }), null, function(data) { if ("entries" in data) { self._showExtractOperationsDialog(data); } }, "jsonp" ); }; HistoryWidget.prototype._showExtractOperationsDialog = function(json) { var self = this; var frame = DialogSystem.createDialog(); frame.width("800px"); var header = $('
').addClass("dialog-header").text("Extract Operations").appendTo(frame); var body = $('
').addClass("dialog-body").appendTo(frame); var footer = $('
').addClass("dialog-footer").appendTo(frame); var html = $( '
' + '' + '' + '' + '
' + 'The following JSON code encodes the operations you have done that can be abstracted. ' + 'You can copy and save it in order to apply the same operations in the future.' + '
' + '
' + '
' + '