2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2010-10-20 20:11:15 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2010-10-20 20:11:15 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2010-10-20 20:11:15 +02:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
*/
|
2010-10-20 20:11:15 +02:00
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
function HistoryPanel(div, tabHeader) {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._div = div;
|
|
|
|
this._tabHeader = tabHeader;
|
|
|
|
this.update();
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype.resize = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var body = this._div.find(".history-panel-body");
|
|
|
|
var controls = this._div.find(".history-panel-controls");
|
|
|
|
var bodyControls = this._div.find(".history-panel-filter");
|
|
|
|
var nowDiv = this._div.find(".history-now");
|
|
|
|
|
|
|
|
var bodyPaddings = body.outerHeight(true) - body.height();
|
|
|
|
body.height((this._div.height() - controls.outerHeight(true) - bodyControls.outerHeight(true) - bodyPaddings) + "px");
|
|
|
|
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) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
Ajax.chainGetJSON(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-history?" + $.param({ project: theProject.id }), null,
|
2011-08-04 22:37:14 +02:00
|
|
|
function(data) {
|
|
|
|
self._data = data;
|
|
|
|
self._render();
|
|
|
|
|
|
|
|
if (onDone) {
|
|
|
|
onDone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2010-01-27 02:48:42 +01:00
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype._render = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
2010-10-18 21:47:36 +02:00
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
this._tabHeader.html($.i18n('core-project/undo-redo')+' <span class="count">' + this._data.past.length + ' / ' + ( this._data.future.length + this._data.past.length ) + '</span>');
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
this._div.empty().unbind().html(DOM.loadHTML("core", "scripts/project/history-panel.html"));
|
|
|
|
|
|
|
|
var elmts = DOM.bind(this._div);
|
2013-07-05 16:32:12 +02:00
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
elmts.or_proj_undo.html($.i18n('core-project/undo-history'));
|
|
|
|
elmts.or_proj_mistakes.html($.i18n('core-project/mistakes'));
|
|
|
|
elmts.or_proj_learnMore.html($.i18n('core-project/learn-more'));
|
|
|
|
elmts.applyLink.html($.i18n('core-project/apply'));
|
|
|
|
elmts.extractLink.html($.i18n('core-project/extract'));
|
|
|
|
elmts.or_proj_mistakes.html($.i18n('core-project/mistakes'));
|
|
|
|
elmts.or_proj_filter.html($.i18n('core-project/filter'));
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var renderEntry = function(container, index, entry, lastDoneID, past) {
|
|
|
|
var a = $(DOM.loadHTML("core", "scripts/project/history-entry.html")).appendTo(container);
|
|
|
|
if (lastDoneID >= 0) {
|
|
|
|
a.attr("href", "javascript:{}")
|
|
|
|
.click(function(evt) {
|
|
|
|
return self._onClickHistoryEntry(evt, entry, lastDoneID);
|
|
|
|
})
|
|
|
|
.mouseover(function() {
|
|
|
|
if (past) {
|
|
|
|
elmts.pastHighlightDiv.show().height(elmts.pastDiv.height() - this.offsetTop - this.offsetHeight);
|
|
|
|
} else {
|
|
|
|
elmts.futureHighlightDiv.show().height(this.offsetTop + this.offsetHeight);
|
2010-02-01 01:19:41 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
})
|
|
|
|
.mouseout(function() {
|
|
|
|
if (past) {
|
|
|
|
elmts.pastHighlightDiv.hide();
|
|
|
|
} else {
|
|
|
|
elmts.futureHighlightDiv.hide();
|
2010-02-01 01:19:41 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
a[0].childNodes[0].appendChild(document.createTextNode(index + "."));
|
|
|
|
a[0].childNodes[1].appendChild(document.createTextNode(entry.description));
|
|
|
|
|
|
|
|
return a;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this._data.past.length > 0 || this._data.future.length > 0) {
|
|
|
|
if (!this._data.past.length) {
|
|
|
|
renderEntry(elmts.nowDiv, 0, {
|
|
|
|
description: "Create project"
|
|
|
|
}, 0, true);
|
2010-04-17 01:38:49 +02:00
|
|
|
} else {
|
2011-08-04 22:37:14 +02:00
|
|
|
renderEntry(elmts.pastDiv, 0, {
|
|
|
|
description: "Create project"
|
|
|
|
}, 0, true);
|
|
|
|
|
|
|
|
for (var i = 0; i < this._data.past.length - 1; i++) {
|
|
|
|
var entry = this._data.past[i];
|
|
|
|
renderEntry(elmts.pastDiv, i + 1, entry, entry.id, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderEntry(elmts.nowDiv, this._data.past.length, this._data.past[this._data.past.length - 1], -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._data.future.length) {
|
|
|
|
for (var i = 0; i < this._data.future.length; i++) {
|
|
|
|
var entry = this._data.future[i];
|
|
|
|
renderEntry(elmts.futureDiv, this._data.past.length + i + 1, entry, entry.id, false);
|
|
|
|
}
|
2010-01-27 02:48:42 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
elmts.helpDiv.hide();
|
|
|
|
|
2013-06-23 19:37:29 +02:00
|
|
|
elmts.filterInput.bind("keyup change input",function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var filter = $.trim(this.value.toLowerCase());
|
2011-10-08 01:44:11 +02:00
|
|
|
if (filter.length === 0) {
|
2011-08-04 22:37:14 +02:00
|
|
|
elmts.bodyDiv.find(".history-entry").removeClass("filtered-out");
|
|
|
|
} else {
|
|
|
|
elmts.bodyDiv.find(".history-entry").each(function() {
|
|
|
|
var text = this.childNodes[1].firstChild.nodeValue;
|
|
|
|
if (text.toLowerCase().indexOf(filter) >= 0) {
|
|
|
|
$(this).removeClass("filtered-out");
|
|
|
|
} else {
|
|
|
|
$(this).addClass("filtered-out");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
elmts.bodyDiv.hide();
|
|
|
|
elmts.bodyControlsDiv.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
elmts.extractLink.click(function() { self._extractOperations(); });
|
|
|
|
elmts.applyLink.click(function() { self._showApplyOperationsDialog(); });
|
|
|
|
|
|
|
|
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) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
Refine.postCoreProcess(
|
|
|
|
"undo-redo",
|
|
|
|
{ lastDoneID: lastDoneID },
|
|
|
|
null,
|
|
|
|
{ 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() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
$.getJSON(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-operations?" + $.param({ project: theProject.id }),
|
2011-08-04 22:37:14 +02:00
|
|
|
null,
|
|
|
|
function(data) {
|
|
|
|
if ("entries" in data) {
|
|
|
|
self._showExtractOperationsDialog(data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"jsonp"
|
|
|
|
);
|
2010-02-17 02:30:09 +01:00
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype._showExtractOperationsDialog = function(json) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
var frame = $(DOM.loadHTML("core", "scripts/project/history-extract-dialog.html"));
|
|
|
|
var elmts = DOM.bind(frame);
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
elmts.dialogHeader.html($.i18n('core-project/extract-history'));
|
|
|
|
elmts.or_proj_extractSave.html($.i18n('core-project/extract-save'));
|
|
|
|
elmts.selectAllButton.html($.i18n('core-buttons/select-all'));
|
|
|
|
elmts.unselectAllButton.html($.i18n('core-buttons/unselect-all'));
|
|
|
|
elmts.closeButton.html($.i18n('core-buttons/close'));
|
2013-07-05 16:32:12 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
var entryTable = elmts.entryTable[0];
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var updateJson = function() {
|
|
|
|
var a = [];
|
2010-02-22 07:31:09 +01:00
|
|
|
for (var i = 0; i < json.entries.length; i++) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var entry = json.entries[i];
|
|
|
|
if ("operation" in entry && entry.selected) {
|
|
|
|
a.push(entry.operation);
|
|
|
|
}
|
2010-02-22 07:31:09 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
elmts.textarea.text(JSON.stringify(a, null, 2));
|
|
|
|
};
|
|
|
|
updateJson();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-08-06 13:47:31 +02:00
|
|
|
frame.find('input[type="checkbox"]').prop('checked', true);
|
2010-02-22 07:31:09 +01:00
|
|
|
updateJson();
|
2011-08-04 22:37:14 +02:00
|
|
|
});
|
|
|
|
elmts.unselectAllButton.click(function() {
|
|
|
|
for (var i = 0; i < json.entries.length; i++) {
|
|
|
|
json.entries[i].selected = false;
|
|
|
|
}
|
|
|
|
|
2020-08-06 13:47:31 +02:00
|
|
|
frame.find('input[type="checkbox"]').prop('checked', false);
|
2011-08-04 22:37:14 +02:00
|
|
|
updateJson();
|
|
|
|
});
|
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
|
|
|
|
|
|
|
elmts.textarea[0].select();
|
2010-02-18 06:00:56 +01:00
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
HistoryPanel.prototype._showApplyOperationsDialog = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
var frame = $(DOM.loadHTML("core", "scripts/project/history-apply-dialog.html"));
|
|
|
|
var elmts = DOM.bind(frame);
|
2013-07-05 16:32:12 +02:00
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
elmts.dialogHeader.html($.i18n('core-project/apply-operation'));
|
|
|
|
elmts.or_proj_pasteJson.html($.i18n('core-project/paste-json'));
|
2013-07-05 16:32:12 +02:00
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
elmts.applyButton.html($.i18n('core-buttons/perform-op'));
|
|
|
|
elmts.cancelButton.html($.i18n('core-buttons/cancel'));
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var fixJson = function(json) {
|
|
|
|
json = json.trim();
|
|
|
|
if (!json.startsWith("[")) {
|
|
|
|
json = "[" + json;
|
|
|
|
}
|
|
|
|
if (!json.endsWith("]")) {
|
|
|
|
json = json + "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
return json.replace(/\}\s*\,\s*\]/g, "} ]").replace(/\}\s*\{/g, "}, {");
|
|
|
|
};
|
|
|
|
|
|
|
|
elmts.applyButton.click(function() {
|
|
|
|
var json;
|
|
|
|
|
|
|
|
try {
|
|
|
|
json = elmts.textarea[0].value;
|
|
|
|
json = fixJson(json);
|
|
|
|
json = JSON.parse(json);
|
|
|
|
} catch (e) {
|
2018-11-21 18:30:00 +01:00
|
|
|
alert($.i18n('core-project/json-invalid')+".");
|
2011-08-04 22:37:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Refine.postCoreProcess(
|
|
|
|
"apply-operations",
|
|
|
|
{},
|
|
|
|
{ operations: JSON.stringify(json) },
|
|
|
|
{ everythingChanged: true },
|
|
|
|
{
|
|
|
|
onDone: function(o) {
|
|
|
|
if (o.code == "pending") {
|
|
|
|
// Something might have already been done and so it's good to update
|
|
|
|
Refine.update({ everythingChanged: true });
|
2010-02-26 22:56:41 +01:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
elmts.cancelButton.click(function() {
|
|
|
|
DialogSystem.dismissUntil(level - 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
var level = DialogSystem.showDialog(frame);
|
|
|
|
|
|
|
|
elmts.textarea.focus();
|
2010-02-17 02:30:09 +01:00
|
|
|
};
|