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:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
|
|
|
* Neither the name of Google Inc. nor the names of its
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
function ProcessPanel(div) {
|
2010-02-01 04:22:35 +01:00
|
|
|
this._div = div;
|
|
|
|
this._timerID = null;
|
2010-02-09 01:26:57 +01:00
|
|
|
this._processCount = 0;
|
2010-02-26 22:56:41 +01:00
|
|
|
|
|
|
|
this._updateOptions = {};
|
|
|
|
this._onDones = [];
|
2010-03-23 01:26:28 +01:00
|
|
|
this._latestHistoryEntry = null;
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
$(window).keypress(function(evt) {
|
2010-05-18 04:52:02 +02:00
|
|
|
if (evt.charCode == 26 || (evt.charCode == 122 && (evt.ctrlKey || evt.metaKey))) { // ctrl-z or meta-z
|
2010-03-23 01:26:28 +01:00
|
|
|
var t = evt.target;
|
|
|
|
if (t) {
|
|
|
|
var tagName = t.tagName.toLowerCase();
|
|
|
|
if (tagName == "textarea" || tagName == "input") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.undo();
|
|
|
|
}
|
|
|
|
});
|
2010-02-26 22:56:41 +01:00
|
|
|
|
|
|
|
this.update({});
|
2010-02-01 04:22:35 +01:00
|
|
|
}
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
ProcessPanel.prototype.resize = function() {
|
2010-03-22 22:48:36 +01:00
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
ProcessPanel.prototype.update = function(updateOptions, onDone) {
|
2010-03-23 01:26:28 +01:00
|
|
|
this._latestHistoryEntry = null;
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
for (var n in updateOptions) {
|
|
|
|
if (updateOptions.hasOwnProperty(n)) {
|
|
|
|
this._updateOptions[n] = updateOptions[n];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (onDone) {
|
|
|
|
this._onDones.push(onDone);
|
|
|
|
}
|
|
|
|
|
2010-04-09 03:00:44 +02:00
|
|
|
if (this._timerID !== null) {
|
2010-02-01 04:22:35 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
Ajax.chainGetJSON(
|
2010-08-22 08:16:13 +02:00
|
|
|
"/command/core/get-processes?" + $.param({ project: theProject.id }), null,
|
2010-02-01 04:22:35 +01:00
|
|
|
function(data) {
|
2010-03-23 01:26:28 +01:00
|
|
|
self._latestHistoryEntry = null;
|
2010-03-05 02:13:59 +01:00
|
|
|
self._render(data);
|
2010-02-01 04:22:35 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
ProcessPanel.prototype.showUndo = function(historyEntry) {
|
2010-03-23 01:26:28 +01:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._latestHistoryEntry = historyEntry;
|
|
|
|
|
2010-10-19 07:46:48 +02:00
|
|
|
this._div.stop(true,false)
|
|
|
|
.empty()
|
|
|
|
.html('<div id="notification"><span bind="description"></span> <span class="notification-action"><a href="javascript:{}" bind="undo">Undo</a></span></div>')
|
|
|
|
.fadeIn(200)
|
|
|
|
.delay(7500)
|
|
|
|
.fadeOut(200);
|
2010-03-23 01:26:28 +01:00
|
|
|
var elmts = DOM.bind(this._div);
|
2010-04-24 02:16:23 +02:00
|
|
|
|
2010-03-23 01:26:28 +01:00
|
|
|
elmts.description.text(historyEntry.description);
|
2010-04-08 21:52:23 +02:00
|
|
|
elmts.undo.click(function() { self.undo(); });
|
2010-03-23 01:26:28 +01:00
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
ProcessPanel.prototype.undo = function() {
|
2010-04-09 03:00:44 +02:00
|
|
|
if (this._latestHistoryEntry !== null) {
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.postCoreProcess(
|
2010-03-23 01:26:28 +01:00
|
|
|
"undo-redo",
|
|
|
|
{ undoID: this._latestHistoryEntry.id },
|
|
|
|
null,
|
|
|
|
{ everythingChanged: true }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
ProcessPanel.prototype._cancelAll = function() {
|
2010-03-05 02:13:59 +01:00
|
|
|
var self = this;
|
2010-03-04 02:14:48 +01:00
|
|
|
$.post(
|
2010-08-22 08:16:13 +02:00
|
|
|
"/command/core/cancel-processes?" + $.param({ project: theProject.id }),
|
2010-03-04 02:14:48 +01:00
|
|
|
null,
|
2010-03-05 02:13:59 +01:00
|
|
|
function(o) {
|
|
|
|
self._data = null;
|
|
|
|
self._runOnDones();
|
|
|
|
},
|
2010-03-04 02:14:48 +01:00
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
ProcessPanel.prototype._render = function(newData) {
|
2010-02-01 04:22:35 +01:00
|
|
|
var self = this;
|
2010-03-05 02:13:59 +01:00
|
|
|
var newProcessMap = {};
|
2010-02-01 04:22:35 +01:00
|
|
|
|
2010-06-27 05:48:56 +02:00
|
|
|
this._div.stop(true, false).empty();
|
2010-02-01 04:22:35 +01:00
|
|
|
|
2010-04-08 22:16:08 +02:00
|
|
|
if (!newData.processes.length) {
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.setTitle();
|
2010-10-19 07:46:48 +02:00
|
|
|
this._div.fadeOut(200);
|
2010-02-26 22:56:41 +01:00
|
|
|
} else {
|
2010-10-19 07:46:48 +02:00
|
|
|
this._div.fadeIn(200);
|
|
|
|
var cancelmessage = "Cancel"
|
|
|
|
var noticeDiv = $('<div id="notification"></div>').appendTo(this._div);
|
|
|
|
var descriptionSpan = $('<span></span>').appendTo(noticeDiv);
|
|
|
|
var statusDiv = $('<div></div>').appendTo(noticeDiv);
|
2010-02-26 22:56:41 +01:00
|
|
|
$('<img src="images/small-spinner.gif" />')
|
2010-10-19 07:46:48 +02:00
|
|
|
.addClass("notification-loader")
|
|
|
|
.appendTo(statusDiv);
|
|
|
|
var progressSpan = $('<span></span>').appendTo(statusDiv);
|
|
|
|
var countSpan = $('<span></span>').appendTo(statusDiv);
|
2010-02-26 22:56:41 +01:00
|
|
|
var renderProcess = function(process) {
|
2010-10-19 07:46:48 +02:00
|
|
|
if (process.status != "pending") {
|
|
|
|
Refine.setTitle(process.progress + "% complete");
|
|
|
|
descriptionSpan.text(process.description);
|
|
|
|
progressSpan.text(process.progress + '% complete');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var renderProcessCount = function(count) {
|
|
|
|
var pendingcount = count - 1;
|
|
|
|
countSpan.text(', ' + pendingcount + ' pending processes');
|
2010-02-26 22:56:41 +01:00
|
|
|
};
|
2010-03-05 02:13:59 +01:00
|
|
|
var processes = newData.processes;
|
2010-10-19 07:46:48 +02:00
|
|
|
if (processes.length >> 1) {
|
|
|
|
cancelmessage = "Cancel All";
|
|
|
|
renderProcessCount(processes.length);
|
|
|
|
}
|
2010-02-26 22:56:41 +01:00
|
|
|
for (var i = 0; i < processes.length; i++) {
|
2010-03-05 02:13:59 +01:00
|
|
|
var process = processes[i];
|
|
|
|
renderProcess(process);
|
|
|
|
if ("onDone" in process) {
|
|
|
|
newProcessMap[process.id] = process;
|
|
|
|
}
|
|
|
|
}
|
2010-10-19 07:46:48 +02:00
|
|
|
$('<a href="javascript:{}"></a>')
|
|
|
|
.addClass("notification-action")
|
|
|
|
.text(cancelmessage)
|
|
|
|
.click(function() {
|
|
|
|
self._cancelAll();
|
|
|
|
$(this).text("Canceling...").unbind();
|
|
|
|
})
|
|
|
|
.appendTo(statusDiv);
|
2010-03-05 02:13:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((this._data) && this._data.processes.length > 0) {
|
|
|
|
var oldProcesses = this._data.processes;
|
|
|
|
for (var i = 0; i < oldProcesses.length; i++) {
|
|
|
|
var process = oldProcesses[i];
|
|
|
|
if ("onDone" in process && !(process.id in newProcessMap)) {
|
|
|
|
this._perform(process.onDone);
|
|
|
|
}
|
2010-02-01 04:22:35 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-05 02:13:59 +01:00
|
|
|
this._data = newData;
|
2010-02-01 04:22:35 +01:00
|
|
|
|
2010-04-08 22:16:08 +02:00
|
|
|
if (this._data.processes.length && !this._timerID) {
|
2010-02-01 04:22:35 +01:00
|
|
|
this._timerID = window.setTimeout(function() {
|
|
|
|
self._timerID = null;
|
|
|
|
self.update();
|
|
|
|
}, 500);
|
2010-02-26 22:56:41 +01:00
|
|
|
} else {
|
2010-03-05 02:13:59 +01:00
|
|
|
this._runOnDones();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
ProcessPanel.prototype._perform = function(jobs) {
|
2010-03-05 02:13:59 +01:00
|
|
|
for (var i = 0; i < jobs.length; i++) {
|
|
|
|
var job = jobs[i];
|
|
|
|
if (job.action == "createFacet") {
|
|
|
|
try {
|
|
|
|
ui.browsingEngine.addFacet(
|
|
|
|
job.facetType,
|
|
|
|
job.facetConfig,
|
|
|
|
job.facetOptions
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
//
|
2010-02-26 22:56:41 +01:00
|
|
|
}
|
2010-03-05 02:13:59 +01:00
|
|
|
}
|
2010-02-01 04:22:35 +01:00
|
|
|
}
|
|
|
|
};
|
2010-03-05 02:13:59 +01:00
|
|
|
|
2010-10-17 08:23:58 +02:00
|
|
|
ProcessPanel.prototype._runOnDones = function() {
|
2010-03-05 02:13:59 +01:00
|
|
|
var updateOptions = this._updateOptions;
|
|
|
|
var onDones = this._onDones;
|
|
|
|
|
|
|
|
this._updateOptions = {};
|
|
|
|
this._onDones = [];
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.update(updateOptions, function() {
|
2010-03-05 02:13:59 +01:00
|
|
|
for (var i = 0; i < onDones.length; i++) {
|
|
|
|
try {
|
|
|
|
onDones[i]();
|
|
|
|
} catch (e) {
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.reportException(e);
|
2010-03-05 02:13:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|