2010-01-27 02:48:42 +01:00
|
|
|
function HistoryWidget(div) {
|
|
|
|
this._div = div;
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
HistoryWidget.prototype._render = function() {
|
|
|
|
var self = this;
|
2010-02-01 01:19:41 +01:00
|
|
|
|
|
|
|
this._div.empty();
|
2010-01-27 02:48:42 +01:00
|
|
|
|
2010-02-07 04:36:40 +01:00
|
|
|
$('<h3>Undo/Redo History</h3>').appendTo(this._div);
|
2010-01-27 02:48:42 +01:00
|
|
|
|
2010-02-01 01:19:41 +01:00
|
|
|
var bodyDiv = $('<div></div>').addClass("history-panel-body").appendTo(this._div);
|
2010-02-07 04:36:40 +01:00
|
|
|
bodyDiv.mouseenter(function(evt) {
|
|
|
|
$(this).addClass("history-panel-body-expanded");
|
|
|
|
}).mouseleave(function(evt) {
|
|
|
|
$(this).removeClass("history-panel-body-expanded");
|
|
|
|
autoscroll();
|
2010-02-01 01:19:41 +01:00
|
|
|
});
|
|
|
|
|
2010-01-27 02:48:42 +01:00
|
|
|
var renderEntry = function(container, entry, lastDoneID, title) {
|
|
|
|
var a = $('<a href="javascript:{}"></a>').appendTo(container);
|
|
|
|
a.addClass("history-entry").html(entry.description).attr("title", title).click(function(evt) {
|
|
|
|
return self._onClickHistoryEntry(evt, entry, lastDoneID);
|
|
|
|
});
|
2010-02-01 01:19:41 +01:00
|
|
|
return a;
|
2010-01-27 02:48:42 +01:00
|
|
|
};
|
|
|
|
|
2010-02-01 01:19:41 +01:00
|
|
|
var divPast = $('<div></div>').addClass("history-past").appendTo(bodyDiv);
|
|
|
|
if (this._data.past.length == 0) {
|
|
|
|
$('<div></div>').addClass("history-panel-message").text("No change to undo").appendTo(divPast);
|
|
|
|
} else {
|
|
|
|
for (var i = 0; i < this._data.past.length; i++) {
|
|
|
|
var entry = this._data.past[i];
|
2010-02-07 04:36:40 +01:00
|
|
|
renderEntry(divPast, entry, i == 0 ? 0 : this._data.past[i - 1].id, "Undo to here");
|
2010-02-01 01:19:41 +01:00
|
|
|
}
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
2010-02-01 01:19:41 +01:00
|
|
|
|
2010-02-07 04:36:40 +01:00
|
|
|
var divNow = $('<div></div>').text("done upto here").addClass("history-now").appendTo(bodyDiv);
|
2010-02-03 08:54:23 +01:00
|
|
|
|
2010-02-01 01:19:41 +01:00
|
|
|
var divFuture = $('<div></div>').addClass("history-future").appendTo(bodyDiv);
|
|
|
|
if (this._data.future.length == 0) {
|
|
|
|
$('<div></div>').addClass("history-panel-message").text("No change to redo").appendTo(divFuture);
|
|
|
|
} else {
|
|
|
|
for (var i = 0; i < this._data.future.length; i++) {
|
|
|
|
var entry = this._data.future[i];
|
2010-02-03 08:54:23 +01:00
|
|
|
renderEntry(divFuture, entry, entry.id, "Redo to here");
|
2010-02-01 01:19:41 +01:00
|
|
|
}
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
|
|
|
|
2010-02-07 04:36:40 +01:00
|
|
|
var autoscroll = function() {
|
|
|
|
bodyDiv[0].scrollTop = divNow[0].offsetTop + divNow[0].offsetHeight - bodyDiv[0].offsetHeight;
|
|
|
|
};
|
|
|
|
autoscroll();
|
2010-02-17 02:30:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
var footerDiv = $('<div></div>').addClass("history-panel-footer").appendTo(this._div);
|
|
|
|
$('<a href="javascript:{}"></a>').text("extract").appendTo(footerDiv).click(function() {
|
|
|
|
self._extractOperations();
|
|
|
|
});
|
|
|
|
$('<span> • </span>').appendTo(footerDiv);
|
|
|
|
$('<a href="javascript:{}"></a>').text("apply").appendTo(footerDiv).click(function() {
|
|
|
|
self._applyOperations();
|
|
|
|
});
|
2010-01-27 02:48:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
HistoryWidget.prototype._onClickHistoryEntry = function(evt, entry, lastDoneID) {
|
|
|
|
var self = this;
|
|
|
|
$.post(
|
|
|
|
"/command/undo-redo?" + $.param({ project: theProject.id, lastDoneID: lastDoneID }),
|
|
|
|
null,
|
|
|
|
function(data) {
|
|
|
|
if (data.code == "ok") {
|
|
|
|
self.update();
|
2010-02-05 00:38:40 +01:00
|
|
|
ui.dataTableView.update(true);
|
2010-01-27 02:48:42 +01:00
|
|
|
} else {
|
|
|
|
// update process UI
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
2010-02-17 02:30:09 +01:00
|
|
|
|
|
|
|
HistoryWidget.prototype._extractOperations = function() {
|
2010-02-17 02:31:28 +01:00
|
|
|
var self = this;
|
2010-02-17 02:30:09 +01:00
|
|
|
$.getJSON(
|
|
|
|
"/command/get-operations?" + $.param({ project: theProject.id }),
|
|
|
|
null,
|
|
|
|
function(data) {
|
|
|
|
if ("operations" in data) {
|
|
|
|
self._showOperationsDialog(data.operations);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"jsonp"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
HistoryWidget.prototype._showOperationsDialog = function(json) {
|
|
|
|
var self = this;
|
|
|
|
var frame = DialogSystem.createDialog();
|
|
|
|
frame.width("800px");
|
|
|
|
|
|
|
|
var header = $('<div></div>').addClass("dialog-header").text("Operations").appendTo(frame);
|
|
|
|
var body = $('<div></div>').addClass("dialog-body").appendTo(frame);
|
|
|
|
var footer = $('<div></div>').addClass("dialog-footer").appendTo(frame);
|
|
|
|
|
|
|
|
var textarea = $('<textarea />').attr("wrap", "hard").width("100%").height("400px").appendTo(body);
|
|
|
|
textarea.text(JSON.stringify(json, null, 2));
|
|
|
|
|
|
|
|
$('<button></button>').text("Done").click(function() {
|
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
}).appendTo(footer);
|
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
|
|
|
|
|
|
|
textarea[0].focus();
|
|
|
|
};
|