2010-10-17 08:23:58 +02:00
|
|
|
function HistoryPanel(div, tabHeader) {
|
2010-01-27 02:48:42 +01:00
|
|
|
this._div = div;
|
2010-04-13 01:48:48 +02:00
|
|
|
this._tabHeader = tabHeader;
|
2010-01-27 02:48:42 +01:00
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype.resize = function() {
|
2010-04-13 09:08:23 +02:00
|
|
|
var body = this._div.find(".history-panel-body");
|
2010-10-15 20:43:17 +02:00
|
|
|
var controls = this._div.find(".history-panel-controls");
|
2010-10-17 08:23:58 +02:00
|
|
|
var bodyControls = this._div.find(".history-panel-body-controls");
|
2010-10-16 08:21:00 +02:00
|
|
|
var nowDiv = this._div.find(".history-now");
|
2010-04-13 10:06:05 +02:00
|
|
|
|
2010-10-16 08:21:00 +02:00
|
|
|
var bodyPaddings = body.outerHeight(true) - body.height();
|
2010-10-17 08:23:58 +02:00
|
|
|
body.height((this._div.height() - controls.outerHeight(true) - bodyControls.outerHeight(true) - bodyPaddings) + "px");
|
2010-10-16 08:21:00 +02:00
|
|
|
body[0].scrollTop =
|
|
|
|
nowDiv[0].offsetTop +
|
|
|
|
nowDiv[0].offsetHeight -
|
|
|
|
body[0].offsetHeight;
|
2010-03-22 22:48:36 +01:00
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype.update = function(onDone) {
|
2010-01-27 02:48:42 +01:00
|
|
|
var self = this;
|
|
|
|
Ajax.chainGetJSON(
|
2010-08-22 08:16:13 +02:00
|
|
|
"/command/core/get-history?" + $.param({ project: theProject.id }), null,
|
2010-01-27 02:48:42 +01:00
|
|
|
function(data) {
|
|
|
|
self._data = data;
|
|
|
|
self._render();
|
2010-02-26 22:56:41 +01:00
|
|
|
|
|
|
|
if (onDone) {
|
|
|
|
onDone();
|
|
|
|
}
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype._render = function() {
|
2010-01-27 02:48:42 +01:00
|
|
|
var self = this;
|
2010-02-01 01:19:41 +01:00
|
|
|
|
2010-10-14 19:39:41 +02:00
|
|
|
this._tabHeader.html('Undo / Redo <span class="count">' + this._data.past.length + '</span>');
|
2010-04-13 01:48:48 +02:00
|
|
|
|
2010-10-17 08:54:27 +02:00
|
|
|
this._div.empty().unbind().html(DOM.loadHTML("core", "scripts/project/history-panel.html"));
|
2010-01-27 02:48:42 +01:00
|
|
|
|
2010-03-23 20:30:50 +01:00
|
|
|
var elmts = DOM.bind(this._div);
|
2010-02-01 01:19:41 +01:00
|
|
|
|
2010-10-17 07:30:03 +02:00
|
|
|
var renderEntry = function(container, index, entry, lastDoneID, past) {
|
2010-10-17 08:54:27 +02:00
|
|
|
var a = $(DOM.loadHTML("core", "scripts/project/history-entry.html")).appendTo(container);
|
|
|
|
a.attr("title", past ? "Undo to here" : "Redo to here")
|
2010-10-17 07:30:03 +02:00
|
|
|
.click(function(evt) {
|
|
|
|
return self._onClickHistoryEntry(evt, entry, lastDoneID);
|
|
|
|
})
|
|
|
|
.mouseover(function() {
|
|
|
|
if (past) {
|
|
|
|
elmts.pastHighlightDiv.show().height(elmts.pastDiv.height() - this.offsetTop);
|
|
|
|
} else {
|
|
|
|
elmts.futureHighlightDiv.show().height(this.offsetTop + this.offsetHeight);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.mouseout(function() {
|
|
|
|
if (past) {
|
|
|
|
elmts.pastHighlightDiv.hide();
|
|
|
|
} else {
|
|
|
|
elmts.futureHighlightDiv.hide();
|
|
|
|
}
|
|
|
|
});
|
2010-10-17 08:54:27 +02:00
|
|
|
|
|
|
|
a[0].appendChild(document.createTextNode(entry.description));
|
|
|
|
a[0].firstChild.appendChild(document.createTextNode((index + 1) + "."));
|
2010-10-16 20:36:35 +02:00
|
|
|
|
2010-02-01 01:19:41 +01:00
|
|
|
return a;
|
2010-01-27 02:48:42 +01:00
|
|
|
};
|
|
|
|
|
2010-04-17 01:38:49 +02:00
|
|
|
if (this._data.past.length > 0 || this._data.future.length > 0) {
|
|
|
|
if (!this._data.past.length) {
|
2010-10-17 08:54:27 +02:00
|
|
|
elmts.noUndoDiv.show();
|
2010-04-17 01:38:49 +02:00
|
|
|
} else {
|
|
|
|
for (var i = 0; i < this._data.past.length; i++) {
|
|
|
|
var entry = this._data.past[i];
|
2010-10-17 07:30:03 +02:00
|
|
|
renderEntry(elmts.pastDiv, i, entry, i === 0 ? 0 : this._data.past[i - 1].id, true);
|
2010-04-17 01:38:49 +02:00
|
|
|
}
|
2010-02-01 01:19:41 +01:00
|
|
|
}
|
|
|
|
|
2010-04-17 01:38:49 +02:00
|
|
|
if (!this._data.future.length) {
|
2010-10-17 08:54:27 +02:00
|
|
|
elmts.noRedoDiv.show();
|
2010-04-17 01:38:49 +02:00
|
|
|
} else {
|
|
|
|
for (var i = 0; i < this._data.future.length; i++) {
|
|
|
|
var entry = this._data.future[i];
|
2010-10-17 07:30:03 +02:00
|
|
|
renderEntry(elmts.futureDiv, this._data.past.length + i, entry, entry.id, false);
|
2010-04-17 01:38:49 +02:00
|
|
|
}
|
2010-02-01 01:19:41 +01:00
|
|
|
}
|
2010-04-17 01:38:49 +02:00
|
|
|
|
|
|
|
elmts.helpDiv.hide();
|
2010-10-17 08:54:27 +02:00
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
elmts.filterInput.keyup(function() {
|
|
|
|
var filter = $.trim(this.value.toLowerCase());
|
|
|
|
if (filter.length == 0) {
|
|
|
|
elmts.bodyDiv.find(".history-entry").show();
|
|
|
|
} else {
|
|
|
|
elmts.bodyDiv.find(".history-entry").each(function() {
|
|
|
|
var text = this.childNodes[1].nodeValue;
|
|
|
|
this.style.display = (text.toLowerCase().indexOf(filter) >= 0) ? "block" : "none";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2010-04-17 01:38:49 +02:00
|
|
|
} else {
|
|
|
|
elmts.bodyDiv.hide();
|
2010-10-17 08:23:58 +02:00
|
|
|
elmts.bodyControlsDiv.hide();
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
|
|
|
|
2010-03-23 20:30:50 +01:00
|
|
|
elmts.extractLink.click(function() { self._extractOperations(); });
|
|
|
|
elmts.applyLink.click(function() { self._showApplyOperationsDialog(); });
|
2010-04-13 09:08:23 +02:00
|
|
|
|
|
|
|
this.resize();
|
2010-01-27 02:48:42 +01:00
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype._onClickHistoryEntry = function(evt, entry, lastDoneID) {
|
2010-01-27 02:48:42 +01:00
|
|
|
var self = this;
|
2010-02-26 22:56:41 +01:00
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.postCoreProcess(
|
2010-02-26 22:56:41 +01:00
|
|
|
"undo-redo",
|
|
|
|
{ lastDoneID: lastDoneID },
|
2010-01-27 02:48:42 +01:00
|
|
|
null,
|
2010-02-26 22:56:41 +01:00
|
|
|
{ everythingChanged: true }
|
2010-01-27 02:48:42 +01:00
|
|
|
);
|
|
|
|
};
|
2010-02-17 02:30:09 +01:00
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype._extractOperations = function() {
|
2010-02-17 02:31:28 +01:00
|
|
|
var self = this;
|
2010-02-17 02:30:09 +01:00
|
|
|
$.getJSON(
|
2010-08-22 08:16:13 +02:00
|
|
|
"/command/core/get-operations?" + $.param({ project: theProject.id }),
|
2010-02-17 02:30:09 +01:00
|
|
|
null,
|
|
|
|
function(data) {
|
2010-02-22 07:31:09 +01:00
|
|
|
if ("entries" in data) {
|
|
|
|
self._showExtractOperationsDialog(data);
|
2010-02-17 02:30:09 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"jsonp"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype._showExtractOperationsDialog = function(json) {
|
2010-02-17 02:30:09 +01:00
|
|
|
var self = this;
|
2010-10-17 08:54:27 +02:00
|
|
|
var frame = $(DOM.loadHTML("core", "scripts/project/history-extract-dialog.html"));
|
2010-08-05 22:27:39 +02:00
|
|
|
var elmts = DOM.bind(frame);
|
2010-02-17 02:30:09 +01:00
|
|
|
|
2010-03-13 08:13:18 +01:00
|
|
|
var entryTable = elmts.entryTable[0];
|
2010-02-22 07:31:09 +01:00
|
|
|
var createEntry = function(entry) {
|
|
|
|
var tr = entryTable.insertRow(entryTable.rows.length);
|
|
|
|
var td0 = tr.insertCell(0);
|
|
|
|
var td1 = tr.insertCell(1);
|
|
|
|
td0.width = "1%";
|
|
|
|
|
|
|
|
if ("operation" in entry) {
|
|
|
|
entry.selected = true;
|
|
|
|
|
|
|
|
$('<input type="checkbox" checked="true" />').appendTo(td0).click(function() {
|
|
|
|
entry.selected = !entry.selected;
|
|
|
|
updateJson();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('<span>').text(entry.operation.description).appendTo(td1);
|
|
|
|
} else {
|
|
|
|
$('<span>').text(entry.description).css("color", "#888").appendTo(td1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for (var i = 0; i < json.entries.length; i++) {
|
|
|
|
createEntry(json.entries[i]);
|
|
|
|
}
|
2010-03-13 08:13:18 +01:00
|
|
|
|
2010-02-22 07:31:09 +01:00
|
|
|
var updateJson = function() {
|
|
|
|
var a = [];
|
|
|
|
for (var i = 0; i < json.entries.length; i++) {
|
|
|
|
var entry = json.entries[i];
|
|
|
|
if ("operation" in entry && entry.selected) {
|
|
|
|
a.push(entry.operation);
|
|
|
|
}
|
|
|
|
}
|
2010-03-13 08:13:18 +01:00
|
|
|
elmts.textarea.text(JSON.stringify(a, null, 2));
|
2010-02-22 07:31:09 +01:00
|
|
|
};
|
|
|
|
updateJson();
|
2010-02-17 02:30:09 +01:00
|
|
|
|
2010-08-05 22:27:39 +02:00
|
|
|
elmts.closeButton.click(function() { DialogSystem.dismissUntil(level - 1); });
|
|
|
|
elmts.selectAllButton.click(function() {
|
|
|
|
for (var i = 0; i < json.entries.length; i++) {
|
|
|
|
json.entries[i].selected = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame.find('input[type="checkbox"]').attr("checked", "true");
|
|
|
|
updateJson();
|
|
|
|
});
|
|
|
|
elmts.unselectAllButton.click(function() {
|
|
|
|
for (var i = 0; i < json.entries.length; i++) {
|
|
|
|
json.entries[i].selected = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame.find('input[type="checkbox"]').removeAttr("checked");
|
|
|
|
updateJson();
|
|
|
|
});
|
2010-02-17 02:30:09 +01:00
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
|
|
|
|
2010-05-27 23:08:56 +02:00
|
|
|
elmts.textarea[0].select();
|
2010-02-18 06:00:56 +01:00
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype._showApplyOperationsDialog = function() {
|
2010-02-18 06:00:56 +01:00
|
|
|
var self = this;
|
2010-10-17 08:54:27 +02:00
|
|
|
var frame = $(DOM.loadHTML("core", "scripts/project/history-apply-dialog.html"));
|
|
|
|
var elmts = DOM.bind(frame);
|
2010-02-18 06:00:56 +01:00
|
|
|
|
2010-10-17 08:54:27 +02:00
|
|
|
elmts.applyButton.click(function() {
|
2010-04-09 03:48:50 +02:00
|
|
|
var json;
|
|
|
|
|
2010-02-18 06:00:56 +01:00
|
|
|
try {
|
2010-04-09 03:48:50 +02:00
|
|
|
json = JSON.parse(elmts.textarea[0].value);
|
2010-02-18 06:00:56 +01:00
|
|
|
} catch (e) {
|
|
|
|
alert("The JSON you pasted is invalid.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.postCoreProcess(
|
2010-02-26 22:56:41 +01:00
|
|
|
"apply-operations",
|
|
|
|
{},
|
2010-02-18 06:00:56 +01:00
|
|
|
{ operations: JSON.stringify(json) },
|
2010-02-26 22:56:41 +01:00
|
|
|
{ everythingChanged: true },
|
|
|
|
{
|
|
|
|
onDone: function(o) {
|
|
|
|
if (o.code == "pending") {
|
|
|
|
// Something might have already been done and so it's good to update
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.update({ everythingChanged: true });
|
2010-02-26 22:56:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-18 06:00:56 +01:00
|
|
|
);
|
2010-02-26 22:56:41 +01:00
|
|
|
|
|
|
|
DialogSystem.dismissUntil(level - 1);
|
2010-10-17 08:54:27 +02:00
|
|
|
});
|
2010-02-18 06:00:56 +01:00
|
|
|
|
2010-10-17 08:54:27 +02:00
|
|
|
elmts.cancelButton.click(function() {
|
2010-02-18 06:00:56 +01:00
|
|
|
DialogSystem.dismissUntil(level - 1);
|
2010-10-17 08:54:27 +02:00
|
|
|
});
|
2010-02-18 06:00:56 +01:00
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
|
|
|
|
2010-10-17 08:54:27 +02:00
|
|
|
elmts.textarea.focus();
|
2010-02-17 02:30:09 +01:00
|
|
|
};
|