2010-01-25 23:51:25 +01:00
|
|
|
function onClickUploadFileButton(evt) {
|
2010-03-11 21:58:42 +01:00
|
|
|
var projectName = $("#project-name-input")[0].value;
|
2010-08-06 08:15:05 +02:00
|
|
|
var dataURL = $.trim($("#project-url-input")[0].value);
|
2010-04-08 22:16:08 +02:00
|
|
|
if (! $.trim(projectName).length) {
|
2010-01-25 23:51:25 +01:00
|
|
|
window.alert("You must specify a project name.");
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-08-06 08:15:05 +02:00
|
|
|
} else if ($("#project-file-input")[0].files.length === 0 && ! dataURL.length) {
|
|
|
|
window.alert("You must specify a data file to upload or a URL to retrieve.");
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-02-24 00:22:02 +01:00
|
|
|
} else {
|
2010-06-20 16:47:45 +02:00
|
|
|
$("#file-upload-form").attr("action",
|
2010-08-22 08:16:13 +02:00
|
|
|
"/command/core/create-project-from-upload?" + [
|
2010-08-06 08:15:05 +02:00
|
|
|
"url=" + escape(dataURL),
|
2010-04-20 09:26:07 +02:00
|
|
|
"split-into-columns=" + $("#split-into-columns-input")[0].checked,
|
2010-08-06 08:15:05 +02:00
|
|
|
"separator=" + $("#separator-input")[0].value,
|
|
|
|
"ignore=" + $("#ignore-input")[0].value,
|
|
|
|
"header-lines=" + $("#header-lines-input")[0].value,
|
|
|
|
"skip=" + $("#skip-input")[0].value,
|
|
|
|
"limit=" + $("#limit-input")[0].value,
|
|
|
|
"guess-value-type=" + $("#guess-value-type-input")[0].checked,
|
|
|
|
"ignore-quotes=" + $("#ignore-quotes-input")[0].checked
|
2010-02-24 19:52:54 +01:00
|
|
|
].join("&"));
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-03 23:19:11 +02:00
|
|
|
return true;
|
2010-01-25 23:51:25 +01:00
|
|
|
}
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-03 23:19:11 +02:00
|
|
|
evt.preventDefault();
|
|
|
|
return false;
|
2010-02-03 07:23:40 +01:00
|
|
|
}
|
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
function formatDate(d) {
|
2010-05-05 01:05:10 +02:00
|
|
|
var d = new Date(d);
|
|
|
|
var last_year = Date.today().add({ years: -1 });
|
|
|
|
var last_month = Date.today().add({ months: -1 });
|
|
|
|
var last_week = Date.today().add({ days: -7 });
|
2010-04-09 03:48:50 +02:00
|
|
|
var today = Date.today();
|
|
|
|
var tomorrow = Date.today().add({ days: 1 });
|
2010-05-05 01:05:10 +02:00
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
if (d.between(today, tomorrow)) {
|
2010-05-17 21:22:58 +02:00
|
|
|
return "today " + d.toString("h:mm tt");
|
2010-05-05 01:05:10 +02:00
|
|
|
} else if (d.between(last_week, today)) {
|
2010-05-06 18:44:18 +02:00
|
|
|
var diff = Math.floor(today.getDayOfYear() - d.getDayOfYear());
|
2010-05-17 21:22:58 +02:00
|
|
|
return (diff <= 1) ? ("yesterday " + d.toString("h:mm tt")) : (diff + " days ago");
|
2010-05-05 01:05:10 +02:00
|
|
|
} else if (d.between(last_month, today)) {
|
2010-05-06 18:44:18 +02:00
|
|
|
var diff = Math.floor((today.getDayOfYear() - d.getDayOfYear()) / 7);
|
2010-05-05 01:05:10 +02:00
|
|
|
return (diff == 1) ? "a week ago" : diff.toFixed(0) + " weeks ago" ;
|
|
|
|
} else if (d.between(last_year, today)) {
|
2010-05-06 18:44:18 +02:00
|
|
|
var diff = Math.floor(today.getMonth() - d.getMonth());
|
2010-05-05 01:05:10 +02:00
|
|
|
return (diff == 1) ? "a month ago" : diff + " months ago";
|
2010-04-09 03:48:50 +02:00
|
|
|
} else {
|
2010-05-06 18:44:18 +02:00
|
|
|
var diff = Math.floor(today.getYear() - d.getYear());
|
2010-05-05 01:05:10 +02:00
|
|
|
return (diff == 1) ? "a year ago" : diff + " years ago";
|
2010-04-09 03:48:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isThereNewRelease() {
|
2010-09-23 00:55:28 +02:00
|
|
|
var thisRevision = GoogleRefineVersion.revision;
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
var revision_pattern = /r([0-9]+)/;
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
if (!revision_pattern.test(thisRevision)) { // probably "trunk"
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
var latestRevision = GoogleRefineReleases.releases[0].revision;
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
var thisRev = parseInt(revision_pattern.exec(thisRevision)[1],10);
|
2010-09-23 00:55:28 +02:00
|
|
|
var latestRev = parseInt(revision_pattern.exec(GoogleRefineReleases.releases[0].revision)[1],10);
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
return latestRev > thisRev;
|
|
|
|
}
|
|
|
|
|
2010-05-05 02:26:26 +02:00
|
|
|
function fetchProjects() {
|
|
|
|
$.getJSON(
|
2010-08-22 08:16:13 +02:00
|
|
|
"/command/core/get-all-project-metadata",
|
2010-05-05 02:26:26 +02:00
|
|
|
null,
|
|
|
|
function(data) {
|
|
|
|
renderProjects(data);
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
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-04-19 01:05:56 +02:00
|
|
|
projects.sort(function(a, b) { return b.date.getTime() - a.date.getTime(); });
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-04-19 01:05:56 +02:00
|
|
|
var container = $("#projects-container").empty();
|
2010-04-08 22:16:08 +02:00
|
|
|
if (!projects.length) {
|
2010-04-19 01:05:56 +02:00
|
|
|
$('<div>')
|
|
|
|
.addClass("message")
|
2010-10-14 19:39:41 +02:00
|
|
|
.text("You don't have any projects yet. Create one now!")
|
2010-04-19 01:05:56 +02:00
|
|
|
.appendTo(container);
|
2010-03-05 23:09:25 +01:00
|
|
|
} else {
|
2010-04-19 01:05:56 +02:00
|
|
|
var table = $(
|
2010-10-14 19:39:41 +02:00
|
|
|
'<table class="list-table"><tr>' +
|
2010-05-04 23:23:51 +02:00
|
|
|
'<th>Name</th>' +
|
2010-05-17 21:22:58 +02:00
|
|
|
'<th></th>' +
|
2010-05-04 23:23:51 +02:00
|
|
|
'<th align="right">Last Modified</th>' +
|
2010-05-05 03:45:37 +02:00
|
|
|
'<th></th>' +
|
2010-04-19 01:05:56 +02:00
|
|
|
'</tr></table>'
|
|
|
|
).appendTo(container)[0];
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-03-05 23:09:25 +01:00
|
|
|
var renderProject = function(project) {
|
2010-04-19 01:05:56 +02:00
|
|
|
var tr = table.insertRow(table.rows.length);
|
2010-05-04 23:23:51 +02:00
|
|
|
tr.className = "project";
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
var nameLink = $('<a></a>')
|
2010-10-14 19:39:41 +02:00
|
|
|
.addClass("list-table-itemname")
|
2010-05-04 23:23:51 +02:00
|
|
|
.text(project.name)
|
2010-06-15 02:35:23 +02:00
|
|
|
.attr("href", "/project?project=" + project.id)
|
2010-05-04 23:23:51 +02:00
|
|
|
.appendTo(tr.insertCell(tr.cells.length));
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
var renameLink = $('<a></a>')
|
|
|
|
.text("rename")
|
|
|
|
.attr("href", "javascript:{}")
|
|
|
|
.css("visibility", "hidden")
|
|
|
|
.click(function() {
|
2010-10-14 19:39:41 +02:00
|
|
|
var name = window.prompt("New project name:", project.name);
|
2010-05-17 21:22:58 +02:00
|
|
|
if (name == null) {
|
|
|
|
return;
|
|
|
|
}
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
name = $.trim(name);
|
|
|
|
if (project.name == name || name.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
2010-08-22 08:16:13 +02:00
|
|
|
url: "/command/core/rename-project",
|
2010-05-17 21:22:58 +02:00
|
|
|
data: { "project" : project.id, "name" : name },
|
|
|
|
dataType: "json",
|
|
|
|
success: function (data) {
|
|
|
|
if (data && typeof data.code != 'undefined' && data.code == "ok") {
|
|
|
|
nameLink.text(name);
|
|
|
|
} else {
|
|
|
|
alert("Failed to rename project: " + data.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}).appendTo(tr.insertCell(tr.cells.length));
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-04 23:23:51 +02:00
|
|
|
$('<div></div>')
|
2010-05-05 01:05:10 +02:00
|
|
|
.html(formatDate(project.date))
|
2010-05-04 23:23:51 +02:00
|
|
|
.addClass("last-modified")
|
2010-05-17 21:22:58 +02:00
|
|
|
.attr("title", project.date.toString())
|
2010-05-04 23:23:51 +02:00
|
|
|
.appendTo(tr.insertCell(tr.cells.length));
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-05 03:45:37 +02: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",
|
2010-08-22 08:16:13 +02:00
|
|
|
url: "/command/core/delete-project",
|
2010-05-05 03:45:37 +02:00
|
|
|
data: { "project" : project.id },
|
|
|
|
dataType: "json",
|
|
|
|
success: function (data) {
|
|
|
|
if (data && typeof data.code != 'undefined' && data.code == "ok") {
|
|
|
|
fetchProjects();
|
|
|
|
}
|
|
|
|
}
|
2010-06-20 16:47:45 +02:00
|
|
|
});
|
2010-05-05 03:45:37 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}).appendTo(tr.insertCell(tr.cells.length));
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
$(tr).mouseenter(function() {
|
|
|
|
renameLink.css("visibility", "visible");
|
|
|
|
}).mouseleave(function() {
|
|
|
|
renameLink.css("visibility", "hidden");
|
|
|
|
});
|
2010-03-05 23:09:25 +01:00
|
|
|
};
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-03-05 23:09:25 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-04 23:23:51 +02:00
|
|
|
function showHide(toHide, toShow) {
|
|
|
|
$("#" + toHide).hide();
|
|
|
|
$("#" + toShow).show();
|
|
|
|
}
|
|
|
|
|
2010-04-19 01:05:56 +02:00
|
|
|
function onLoad() {
|
|
|
|
fetchProjects();
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-04-19 01:05:56 +02:00
|
|
|
$("#upload-file-button").click(onClickUploadFileButton);
|
2010-04-19 02:02:34 +02:00
|
|
|
$("#more-options-link").click(function() {
|
|
|
|
$("#more-options-controls").hide();
|
|
|
|
$("#more-options").show();
|
|
|
|
});
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-09-29 03:50:57 +02:00
|
|
|
var version = (GoogleRefineVersion.version != "$VERSION") ? "Version " + GoogleRefineVersion.version + " [" + GoogleRefineVersion.revision + "]" : "Version <trunk>";
|
2010-09-23 00:55:28 +02:00
|
|
|
$("#google-refine-version").text(version);
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
var script = $('<script></script>')
|
2010-09-29 03:50:57 +02:00
|
|
|
.attr("src", "http://google-refine.googlecode.com/svn/support/releases.js")
|
2010-05-17 21:22:58 +02:00
|
|
|
.attr("type", "text/javascript")
|
|
|
|
.appendTo(document.body);
|
2010-06-20 16:47:45 +02:00
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
var poll = function() {
|
2010-09-29 03:50:57 +02:00
|
|
|
if ("releases" in window) {
|
2010-05-17 21:22:58 +02:00
|
|
|
if (isThereNewRelease()) {
|
|
|
|
$('<div id="version-message">' +
|
2010-09-29 03:50:57 +02:00
|
|
|
'New version "' + releases.releases[0].description + '" <a href="' + releases.homepage + '">available for download here</a>.' +
|
2010-05-17 21:22:58 +02:00
|
|
|
'</div>').appendTo(document.body);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
window.setTimeout(poll, 1000);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.setTimeout(poll, 1000);
|
2010-04-09 03:48:50 +02:00
|
|
|
}
|
2010-03-31 02:17:40 +02:00
|
|
|
|
2010-04-09 03:48:50 +02:00
|
|
|
$(onLoad);
|