RandomSec/src/main/webapp/scripts/project/process-widget.js
2010-02-09 00:26:57 +00:00

68 lines
1.7 KiB
JavaScript

function ProcessWidget(div) {
this._div = div;
this._timerID = null;
this._processCount = 0;
this.update();
}
ProcessWidget.prototype.update = function() {
if (this._timerID != null) {
return;
}
var self = this;
Ajax.chainGetJSON(
"/command/get-processes?" + $.param({ project: theProject.id }), null,
function(data) {
self._data = data;
self._render();
}
);
};
ProcessWidget.prototype._render = function() {
var self = this;
this._div.empty();
var bodyDiv = $('<div></div>').addClass("process-panel-inner").appendTo(this._div);
if (this._data.processes.length == 0) {
this._div.hide();
if (this._processCount > 0) {
this._processCount = 0;
ui.historyWidget.update();
ui.dataTableView.update(true);
}
return;
}
this._processCount = this._data.processes.length;
this._div.show();
var hasPending = false;
var renderProcess = function(process) {
var div = $('<div></div>').addClass("process-panel-entry").appendTo(bodyDiv);
if (process.status == "pending") {
div.text(process.description + " (pending)");
} else {
div.text(process.description + " (" + process.progress + "%)");
hasPending = true;
}
};
var processes = this._data.processes;
for (var i = 0; i < processes.length; i++) {
renderProcess(processes[i]);
}
if (hasPending && this._timerID == null) {
this._timerID = window.setTimeout(function() {
self._timerID = null;
self.update();
}, 500);
}
};