2010-01-26 06:17:14 +01:00
|
|
|
var theProject;
|
|
|
|
var ui = {};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
var Gridworks = {
|
|
|
|
};
|
|
|
|
|
|
|
|
Gridworks.reportException = function(e) {
|
|
|
|
if (window.console) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
function onLoad() {
|
2010-01-26 06:17:14 +01:00
|
|
|
var params = URL.getParameters();
|
|
|
|
if ("project" in params) {
|
|
|
|
theProject = {
|
2010-01-29 01:46:15 +01:00
|
|
|
id: parseInt(params.project)
|
2010-01-26 06:17:14 +01:00
|
|
|
};
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
var uiState = {};
|
|
|
|
if ("ui" in params) {
|
|
|
|
try {
|
|
|
|
uiState = JSON.parse(params.ui);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Gridworks.reinitializeProjectData(function() {
|
|
|
|
initializeUI(uiState);
|
|
|
|
});
|
2010-01-26 06:17:14 +01:00
|
|
|
}
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|
|
|
|
$(onLoad);
|
2010-01-26 06:17:14 +01:00
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
function initializeUI(uiState) {
|
2010-02-03 07:23:40 +01:00
|
|
|
document.title = theProject.metadata.name + " - Gridworks";
|
2010-02-27 01:16:44 +01:00
|
|
|
|
|
|
|
var path = $("#path");
|
|
|
|
|
2010-03-23 22:12:13 +01:00
|
|
|
$('<span class="app-path-section">' +
|
|
|
|
'<a href="#">' + theProject.metadata.name + '</a> project' +
|
|
|
|
'</span>').appendTo(path);
|
|
|
|
|
|
|
|
$('<a href="javascript:{}">current view</a>')
|
2010-02-27 01:16:44 +01:00
|
|
|
.mouseenter(function() {
|
|
|
|
this.href = Gridworks.getPermanentLink();
|
|
|
|
})
|
2010-03-23 22:12:13 +01:00
|
|
|
.appendTo($('<span class="app-path-section"></span>').appendTo(path));
|
2010-01-26 06:17:14 +01:00
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
var body = $("#body").empty().html(
|
|
|
|
'<div bind="viewPanel" class="view-panel"></div>' +
|
|
|
|
'<div bind="facetPanel" class="facet-panel"></div>' +
|
|
|
|
'<div bind="historyPanel" class="history-panel"></div>' +
|
|
|
|
'<div bind="processPanel" class="process-panel"></div>' +
|
|
|
|
'<div class="menu-bar-container" bind="menuBarContainer"><div bind="menuBarPanel" class="menu-bar"></div></div>'
|
|
|
|
);
|
|
|
|
ui = DOM.bind(body);
|
2010-01-26 06:17:14 +01:00
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
ui.menuBarContainer.css("top", $("#header").outerHeight() + "px");
|
|
|
|
ui.menuBar = new MenuBar(ui.menuBarPanel); // construct the menu first so we can resize everything else
|
2010-01-26 06:17:14 +01:00
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
resize();
|
|
|
|
|
2010-02-27 01:16:44 +01:00
|
|
|
ui.browsingEngine = new BrowsingEngine(ui.facetPanel, uiState.facets || []);
|
2010-02-01 04:22:35 +01:00
|
|
|
ui.processWidget = new ProcessWidget(ui.processPanel);
|
2010-01-27 02:48:42 +01:00
|
|
|
ui.historyWidget = new HistoryWidget(ui.historyPanel);
|
2010-01-29 01:46:15 +01:00
|
|
|
ui.dataTableView = new DataTableView(ui.viewPanel);
|
2010-03-22 22:48:36 +01:00
|
|
|
|
|
|
|
$(window).bind("resize", resizeAll);
|
|
|
|
}
|
|
|
|
|
|
|
|
function resize() {
|
|
|
|
var header = $("#header");
|
|
|
|
var footer = $("#footer");
|
|
|
|
|
|
|
|
ui.menuBarContainer.css("top", header.outerHeight() + "px");
|
|
|
|
|
|
|
|
var facetPanelWidth = 250;
|
|
|
|
var width = $(window).width();
|
|
|
|
var top = ui.menuBarContainer.offset().top + ui.menuBarContainer.outerHeight();
|
|
|
|
var height = footer.offset().top - top;
|
|
|
|
|
|
|
|
ui.viewPanel
|
|
|
|
.css("top", top + "px")
|
|
|
|
.css("height", height + "px")
|
|
|
|
.css("left", "0px")
|
|
|
|
.css("width", (width - facetPanelWidth) + "px");
|
|
|
|
|
|
|
|
ui.facetPanel
|
|
|
|
.css("top", top + "px")
|
|
|
|
.css("height", height + "px")
|
|
|
|
.css("left", (width - facetPanelWidth) + "px")
|
|
|
|
.css("width", facetPanelWidth + "px");
|
2010-03-23 05:48:05 +01:00
|
|
|
|
|
|
|
var processPanelWidth = 400;
|
|
|
|
ui.processPanel
|
|
|
|
.css("width", processPanelWidth + "px")
|
|
|
|
.css("left", Math.floor((width - processPanelWidth) / 2) + "px");
|
2010-03-22 22:48:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function resizeAll() {
|
|
|
|
resize();
|
|
|
|
|
|
|
|
ui.menuBar.resize();
|
|
|
|
ui.browsingEngine.resize();
|
|
|
|
ui.processWidget.resize();
|
|
|
|
ui.historyWidget.resize();
|
|
|
|
ui.dataTableView.resize();
|
2010-01-26 08:57:11 +01:00
|
|
|
}
|
2010-02-05 00:38:40 +01:00
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
Gridworks.reinitializeProjectData = function(f) {
|
2010-02-05 00:38:40 +01:00
|
|
|
Ajax.chainGetJSON(
|
|
|
|
"/command/get-project-metadata?" + $.param({ project: theProject.id }), null,
|
|
|
|
function(data) {
|
|
|
|
theProject.metadata = data;
|
|
|
|
},
|
2010-02-11 07:44:48 +01:00
|
|
|
"/command/get-models?" + $.param({ project: theProject.id }), null,
|
2010-02-05 00:38:40 +01:00
|
|
|
function(data) {
|
2010-02-11 07:44:48 +01:00
|
|
|
theProject.columnModel = data.columnModel;
|
|
|
|
theProject.protograph = data.protograph;
|
|
|
|
|
2010-02-05 00:38:40 +01:00
|
|
|
for (var i = 0; i < theProject.columnModel.columns.length; i++) {
|
|
|
|
theProject.columnModel.columns[i].collapsed = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
f
|
|
|
|
);
|
2010-02-19 00:27:40 +01:00
|
|
|
}
|
2010-02-22 21:25:45 +01:00
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
/*
|
|
|
|
* Utility state functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
Gridworks.createUpdateFunction = function(options, onFinallyDone) {
|
|
|
|
var functions = [];
|
|
|
|
var pushFunction = function(f) {
|
|
|
|
var index = functions.length;
|
|
|
|
functions.push(function() {
|
|
|
|
f(functions[index + 1]);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
pushFunction(function(onDone) {
|
|
|
|
ui.historyWidget.update(onDone);
|
|
|
|
});
|
2010-02-27 00:33:16 +01:00
|
|
|
if (options["everythingChanged"] || options["modelsChanged"] || options["columnStatsChanged"]) {
|
2010-02-26 22:56:41 +01:00
|
|
|
pushFunction(Gridworks.reinitializeProjectData);
|
|
|
|
}
|
2010-03-05 23:31:47 +01:00
|
|
|
if (options["everythingChanged"] || options["modelsChanged"] || options["rowsChanged"] || options["rowMetadataChanged"] || options["cellsChanged"] || options["engineChanged"]) {
|
2010-02-26 22:56:41 +01:00
|
|
|
pushFunction(function(onDone) {
|
|
|
|
ui.dataTableView.update(onDone);
|
|
|
|
});
|
|
|
|
pushFunction(function(onDone) {
|
|
|
|
ui.browsingEngine.update(onDone);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
functions.push(onFinallyDone || function() {});
|
|
|
|
|
|
|
|
return functions[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
Gridworks.update = function(options, onFinallyDone) {
|
|
|
|
var done = false;
|
|
|
|
var dismissBusy = null;
|
|
|
|
|
2010-04-07 23:31:50 +02:00
|
|
|
Gridworks.setAjaxInProgress();
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
Gridworks.createUpdateFunction(options, function() {
|
2010-04-07 23:31:50 +02:00
|
|
|
Gridworks.clearAjaxInProgress();
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
done = true;
|
|
|
|
if (dismissBusy) {
|
|
|
|
dismissBusy();
|
|
|
|
}
|
|
|
|
if (onFinallyDone) {
|
|
|
|
onFinallyDone();
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
window.setTimeout(function() {
|
|
|
|
if (!done) {
|
|
|
|
dismissBusy = DialogSystem.showBusy();
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
};
|
|
|
|
|
|
|
|
Gridworks.postProcess = function(command, params, body, updateOptions, callbacks) {
|
|
|
|
params = params || {};
|
|
|
|
params.project = theProject.id;
|
|
|
|
|
|
|
|
body = body || {};
|
|
|
|
body.engine = JSON.stringify(ui.browsingEngine.getJSON());
|
|
|
|
|
|
|
|
updateOptions = updateOptions || {};
|
|
|
|
callbacks = callbacks || {};
|
|
|
|
|
|
|
|
var done = false;
|
|
|
|
var dismissBusy = null;
|
|
|
|
|
|
|
|
function onDone(o) {
|
|
|
|
done = true;
|
|
|
|
if (dismissBusy) {
|
|
|
|
dismissBusy();
|
|
|
|
}
|
|
|
|
|
2010-04-07 23:31:50 +02:00
|
|
|
Gridworks.clearAjaxInProgress();
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
if (o.code == "error") {
|
|
|
|
if ("onError" in callbacks) {
|
|
|
|
try {
|
|
|
|
callbacks["onError"](o);
|
|
|
|
} catch (e) {
|
|
|
|
Gridworks.reportException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ("onDone" in callbacks) {
|
|
|
|
try {
|
|
|
|
callbacks["onDone"](o);
|
|
|
|
} catch (e) {
|
|
|
|
Gridworks.reportException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (o.code == "ok") {
|
|
|
|
Gridworks.update(updateOptions, callbacks["onFinallyDone"]);
|
2010-03-23 01:26:28 +01:00
|
|
|
|
|
|
|
if ("historyEntry" in o) {
|
|
|
|
ui.processWidget.showUndo(o.historyEntry);
|
|
|
|
}
|
2010-02-26 22:56:41 +01:00
|
|
|
} else if (o.code == "pending") {
|
|
|
|
if ("onPending" in callbacks) {
|
|
|
|
try {
|
|
|
|
callbacks["onPending"](o);
|
|
|
|
} catch (e) {
|
|
|
|
Gridworks.reportException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui.processWidget.update(updateOptions, callbacks["onFinallyDone"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-07 23:31:50 +02:00
|
|
|
Gridworks.setAjaxInProgress();
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
$.post(
|
|
|
|
"/command/" + command + "?" + $.param(params),
|
|
|
|
body,
|
|
|
|
onDone,
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
|
|
|
|
window.setTimeout(function() {
|
|
|
|
if (!done) {
|
|
|
|
dismissBusy = DialogSystem.showBusy();
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
};
|
|
|
|
|
2010-04-07 23:31:50 +02:00
|
|
|
Gridworks.setAjaxInProgress = function() {
|
|
|
|
$(document.body).attr("ajax_in_progress", "true");
|
|
|
|
};
|
|
|
|
|
|
|
|
Gridworks.clearAjaxInProgress = function() {
|
|
|
|
$(document.body).attr("ajax_in_progress", "false");
|
|
|
|
};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
/*
|
|
|
|
* Utility model functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
Gridworks.cellIndexToColumn = function(cellIndex) {
|
2010-02-22 21:25:45 +01:00
|
|
|
var columns = theProject.columnModel.columns;
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
var column = columns[i];
|
2010-02-26 22:56:41 +01:00
|
|
|
if (column.cellIndex == cellIndex) {
|
2010-02-22 21:25:45 +01:00
|
|
|
return column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2010-02-26 22:56:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Gridworks.fetchRows = function(start, limit, onDone) {
|
|
|
|
$.post(
|
|
|
|
"/command/get-rows?" + $.param({ project: theProject.id, start: start, limit: limit }),
|
|
|
|
{ engine: JSON.stringify(ui.browsingEngine.getJSON()) },
|
|
|
|
function(data) {
|
|
|
|
theProject.rowModel = data;
|
|
|
|
if (onDone) {
|
|
|
|
onDone();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
2010-02-27 01:16:44 +01:00
|
|
|
|
|
|
|
Gridworks.getPermanentLink = function() {
|
|
|
|
var params = [
|
|
|
|
"project=" + escape(theProject.id),
|
|
|
|
"ui=" + escape(JSON.stringify({
|
|
|
|
facets: ui.browsingEngine.getFacetUIStates()
|
|
|
|
}))
|
|
|
|
];
|
|
|
|
return "project.html?" + params.join("&");
|
|
|
|
};
|