2010-01-25 23:51:25 +01:00
|
|
|
function onLoad() {
|
2010-02-03 07:23:40 +01:00
|
|
|
$.getJSON(
|
|
|
|
"/command/get-all-project-metadata",
|
|
|
|
null,
|
|
|
|
function(data) {
|
|
|
|
renderProjects(data);
|
2010-03-11 21:58:42 +01:00
|
|
|
$("#upload-file-button").click(onClickUploadFileButton);
|
2010-02-03 07:23:40 +01:00
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
2010-03-23 05:36:01 +01:00
|
|
|
|
2010-03-31 02:17:40 +02:00
|
|
|
if (isThereNewRelease()) {
|
2010-03-23 05:36:01 +01:00
|
|
|
$('<div id="version-message">' +
|
|
|
|
'New version "' + GridworksReleases.releases[0].description + '" <a href="' + GridworksReleases.homepage + '">available for download here</a>.' +
|
|
|
|
'</div>').appendTo(document.body)
|
|
|
|
}
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|
2010-03-31 02:17:40 +02:00
|
|
|
|
2010-01-25 23:51:25 +01:00
|
|
|
$(onLoad);
|
|
|
|
|
|
|
|
function onClickUploadFileButton(evt) {
|
2010-03-11 21:58:42 +01:00
|
|
|
var projectName = $("#project-name-input")[0].value;
|
|
|
|
if ($.trim(projectName).length == 0) {
|
2010-01-25 23:51:25 +01:00
|
|
|
window.alert("You must specify a project name.");
|
|
|
|
|
|
|
|
evt.preventDefault();
|
|
|
|
return false;
|
2010-02-24 00:22:02 +01:00
|
|
|
} else {
|
2010-02-24 19:52:54 +01:00
|
|
|
$("#file-upload-form").attr("action",
|
|
|
|
"/command/create-project-from-upload?" + [
|
|
|
|
"skip=" + $("#skip-input")[0].value,
|
2010-04-01 00:34:21 +02:00
|
|
|
"limit=" + $("#limit-input")[0].value,
|
|
|
|
"separator=" + $("#separator-input")[0].value
|
2010-02-24 19:52:54 +01:00
|
|
|
].join("&"));
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|
2010-02-03 07:23:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderProjects(data) {
|
|
|
|
var projects = [];
|
|
|
|
for (var n in data.projects) {
|
|
|
|
if (data.projects.hasOwnProperty(n)) {
|
|
|
|
var project = data.projects[n];
|
|
|
|
project.id = n;
|
2010-03-04 20:38:23 +01:00
|
|
|
project.date = Date.parseExact(project.modified, "yyyy-MM-ddTHH:mm:ssZ");
|
2010-02-03 07:23:40 +01:00
|
|
|
projects.push(project);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-05 23:09:25 +01:00
|
|
|
if (projects.length == 0) {
|
|
|
|
$('#body-empty').show();
|
|
|
|
$('#create-project-panel').remove().appendTo($('#body-empty-create-project-panel-container'));
|
|
|
|
} else {
|
|
|
|
$('#body-nonempty').show();
|
|
|
|
$('#create-project-panel').remove().appendTo($('#body-nonempty-create-project-panel-container'));
|
|
|
|
|
2010-02-24 19:52:54 +01:00
|
|
|
projects.sort(function(a, b) { return b.date.getTime() - a.date.getTime(); });
|
2010-03-05 23:09:25 +01:00
|
|
|
if (projects.length > 10) {
|
|
|
|
$('#body-nonempty-logo-container').css("vertical-align", "top");
|
|
|
|
$('#body-nonempty-create-project-panel-container').css("vertical-align", "top");
|
|
|
|
}
|
2010-02-24 19:52:54 +01:00
|
|
|
|
|
|
|
var container = $("#projects").empty().show();
|
2010-03-05 23:09:25 +01:00
|
|
|
$('<h1>').text("Projects").appendTo(container);
|
|
|
|
|
|
|
|
var renderProject = function(project) {
|
|
|
|
var div = $('<div>').addClass("project").appendTo(container);
|
2010-02-03 07:23:40 +01:00
|
|
|
|
2010-03-05 23:09:25 +01:00
|
|
|
$('<a></a>')
|
|
|
|
.addClass("delete-project")
|
|
|
|
.attr("title","Delete this project")
|
|
|
|
.attr("href","")
|
|
|
|
.html("<img src='/images/close.png' />")
|
|
|
|
.click(function() {
|
|
|
|
if (window.confirm("Are you sure you want to delete project \"" + project.name + "\"?")) {
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: "/command/delete-project",
|
|
|
|
data: { "project" : project.id },
|
|
|
|
dataType: "json",
|
|
|
|
success: function (data) {
|
|
|
|
if (data && typeof data['code'] != 'undefined' && data.code == "ok") {
|
|
|
|
window.location.reload()
|
|
|
|
}
|
2010-03-05 02:52:55 +01:00
|
|
|
}
|
2010-03-05 23:09:25 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}).appendTo(div);
|
|
|
|
|
|
|
|
$('<a></a>').text(project.name).attr("href", "/project.html?project=" + project.id).appendTo(div);
|
|
|
|
$('<span></span>').text(formatDate(project.date)).addClass("last-modified").appendTo(div);
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < projects.length; i++) {
|
|
|
|
renderProject(projects[i]);
|
2010-02-24 19:52:54 +01:00
|
|
|
}
|
2010-02-03 07:23:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatDate(d) {
|
|
|
|
var yesterday = Date.today().add({ days: -1 });
|
|
|
|
var today = Date.today();
|
|
|
|
var tomorrow = Date.today().add({ days: 1 });
|
|
|
|
if (d.between(today, tomorrow)) {
|
2010-03-16 21:55:01 +01:00
|
|
|
return "Today " + d.toString("h:mm tt");
|
2010-02-03 07:23:40 +01:00
|
|
|
} else if (d.between(yesterday, today)) {
|
2010-03-16 21:55:01 +01:00
|
|
|
return "Yesterday " + d.toString("h:mm tt");
|
2010-02-03 07:23:40 +01:00
|
|
|
} else {
|
2010-03-16 21:55:01 +01:00
|
|
|
return d.toString("ddd, MMM d, yyyy");
|
2010-02-03 07:23:40 +01:00
|
|
|
}
|
2010-03-31 02:17:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function isThereNewRelease() {
|
|
|
|
var thisRevision = GridworksVersion.revision;
|
|
|
|
|
|
|
|
var revision_pattern = /r([0-9]+)/;
|
|
|
|
|
|
|
|
if (!revision_pattern.test(thisRevision)) { // probably "trunk"
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var latestRevision = GridworksReleases.releases[0].revision;
|
|
|
|
|
|
|
|
var thisRev = parseInt(revision_pattern.exec(thisRevision)[1]);
|
|
|
|
var latestRev = parseInt(revision_pattern.exec(GridworksReleases.releases[0].revision)[1]);
|
|
|
|
|
|
|
|
return latestRev > thisRev;
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|