2011-08-02 05:34:47 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2011, 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:
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2011-08-02 05:34:47 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2011-08-02 05:34:47 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2011-08-02 05:34:47 +02:00
|
|
|
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.
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
*/
|
2011-08-02 05:34:47 +02:00
|
|
|
|
|
|
|
Refine.OpenProjectUI = function(elmt) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
elmt.html(DOM.loadHTML("core", "scripts/index/open-project-ui.html"));
|
|
|
|
|
|
|
|
this._elmt = elmt;
|
|
|
|
this._elmts = DOM.bind(elmt);
|
|
|
|
|
|
|
|
$("#project-file-input").change(function() {
|
2011-10-08 01:44:11 +02:00
|
|
|
if ($("#project-name-input")[0].value.length === 0) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var fileName = this.files[0].fileName;
|
|
|
|
if (fileName) {
|
2011-10-08 01:44:11 +02:00
|
|
|
$("#project-name-input")[0].value = fileName.replace(/\.\w+/, "").replace(/[_\-]/g, " ");
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
$("#project-name-input").focus().select();
|
|
|
|
}
|
|
|
|
}).keypress(function(evt) {
|
|
|
|
if (evt.keyCode == 13) {
|
|
|
|
return self._onClickUploadFileButton(evt);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#upload-file-button").click(function(evt) {
|
2011-10-08 01:44:11 +02:00
|
|
|
return self._onClickUploadFileButton(evt);
|
2011-08-04 22:37:14 +02:00
|
|
|
});
|
|
|
|
|
2013-07-02 13:40:50 +02:00
|
|
|
$('#projects-workspace-open').text($.i18n._('core-index-open')["browse"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
$('#projects-workspace-open').click(function() {
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
2012-10-13 19:47:08 +02:00
|
|
|
url: "command/core/open-workspace-dir",
|
2011-08-04 22:37:14 +02:00
|
|
|
dataType: "json",
|
|
|
|
success: function (data) {
|
|
|
|
if (data.code != "ok" && "message" in data) {
|
|
|
|
alert(data.message);
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2011-08-02 05:34:47 +02:00
|
|
|
});
|
2011-08-04 22:37:14 +02:00
|
|
|
});
|
2011-08-02 05:34:47 +02:00
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
this._fetchProjects();
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
2011-08-08 01:26:51 +02:00
|
|
|
Refine.OpenProjectUI.prototype.resize = function() {
|
|
|
|
var height = this._elmt.height();
|
|
|
|
var width = this._elmt.width();
|
|
|
|
var controlsHeight = this._elmts.workspaceControls.outerHeight();
|
|
|
|
|
|
|
|
this._elmts.projectsContainer
|
|
|
|
.css("height", (height - controlsHeight - DOM.getVPaddings(this._elmts.projectsContainer)) + "px");
|
|
|
|
|
|
|
|
this._elmts.workspaceControls
|
|
|
|
.css("bottom", "0px")
|
2011-10-08 01:44:11 +02:00
|
|
|
.css("width", (width - DOM.getHPaddings(this._elmts.workspaceControls)) + "px");
|
2011-08-08 01:26:51 +02:00
|
|
|
};
|
|
|
|
|
2011-08-02 05:34:47 +02:00
|
|
|
Refine.OpenProjectUI.prototype._fetchProjects = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
$.getJSON(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-all-project-metadata",
|
2011-08-04 22:37:14 +02:00
|
|
|
null,
|
|
|
|
function(data) {
|
|
|
|
self._renderProjects(data);
|
2011-08-12 21:15:58 +02:00
|
|
|
self.resize();
|
2011-08-04 22:37:14 +02:00
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.OpenProjectUI.prototype._renderProjects = function(data) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
var projects = [];
|
|
|
|
for (var n in data.projects) {
|
|
|
|
if (data.projects.hasOwnProperty(n)) {
|
|
|
|
var project = data.projects[n];
|
|
|
|
project.id = n;
|
|
|
|
project.date = Date.parseExact(project.modified, "yyyy-MM-ddTHH:mm:ssZ");
|
|
|
|
projects.push(project);
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
projects.sort(function(a, b) { return b.date.getTime() - a.date.getTime(); });
|
|
|
|
|
|
|
|
var container = $("#projects-container").empty();
|
|
|
|
if (!projects.length) {
|
|
|
|
$("#no-project-message").clone().show().appendTo(container);
|
|
|
|
} else {
|
|
|
|
Refine.selectActionArea('open-project');
|
|
|
|
|
|
|
|
var table = $(
|
|
|
|
'<table class="list-table"><tr>' +
|
|
|
|
'<th></th>' +
|
|
|
|
'<th></th>' +
|
2013-07-02 13:40:50 +02:00
|
|
|
'<th>'+$.i18n._('core-index-open')["last-mod"]+'</th>' +
|
|
|
|
'<th>'+$.i18n._('core-index-open')["name"]+'</th>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'</tr></table>'
|
|
|
|
).appendTo(container)[0];
|
|
|
|
|
|
|
|
var renderProject = function(project) {
|
|
|
|
var tr = table.insertRow(table.rows.length);
|
|
|
|
tr.className = "project";
|
|
|
|
|
2011-08-08 01:26:51 +02:00
|
|
|
var deleteLink = $('<a></a>')
|
|
|
|
.addClass("delete-project")
|
2013-07-02 13:40:50 +02:00
|
|
|
.attr("title",$.i18n._('core-index-open')["del-title"])
|
2011-08-08 01:26:51 +02:00
|
|
|
.attr("href","")
|
|
|
|
.css("visibility", "hidden")
|
2012-10-13 19:47:08 +02:00
|
|
|
.html("<img src='images/close.png' />")
|
2011-08-08 01:26:51 +02:00
|
|
|
.click(function() {
|
2013-07-02 13:40:50 +02:00
|
|
|
if (window.confirm($.i18n._('core-index-open')["del-body"] + project.name + "\"?")) {
|
2011-08-08 01:26:51 +02:00
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
2012-10-13 19:47:08 +02:00
|
|
|
url: "command/core/delete-project",
|
2011-08-08 01:26:51 +02:00
|
|
|
data: { "project" : project.id },
|
|
|
|
dataType: "json",
|
|
|
|
success: function (data) {
|
|
|
|
if (data && typeof data.code != 'undefined' && data.code == "ok") {
|
|
|
|
self._fetchProjects();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}).appendTo(
|
|
|
|
$(tr.insertCell(tr.cells.length)).css('width', '1%')
|
|
|
|
);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var renameLink = $('<a></a>')
|
2013-07-11 15:01:45 +02:00
|
|
|
.text($.i18n._('core-index-open')["rename"])
|
2011-08-04 22:37:14 +02:00
|
|
|
.addClass("secondary")
|
|
|
|
.attr("href", "javascript:{}")
|
|
|
|
.css("visibility", "hidden")
|
|
|
|
.click(function() {
|
2013-07-02 13:40:50 +02:00
|
|
|
var name = window.prompt($.i18n._('core-index-open')["new-title"], project.name);
|
2011-10-08 01:44:11 +02:00
|
|
|
if (name === null) {
|
2011-08-04 22:37:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = $.trim(name);
|
2011-10-08 01:44:11 +02:00
|
|
|
if (project.name == name || name.length === 0) {
|
2011-08-04 22:37:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
2012-10-13 19:47:08 +02:00
|
|
|
url: "command/core/rename-project",
|
2011-08-04 22:37:14 +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);
|
2011-08-02 05:34:47 +02:00
|
|
|
} else {
|
2013-07-02 13:40:50 +02:00
|
|
|
alert($.i18n._('core-index-open')["warning-rename"]+" " + data.message);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-08-08 01:26:51 +02:00
|
|
|
}).appendTo(
|
|
|
|
$(tr.insertCell(tr.cells.length)).css('width', '1%')
|
|
|
|
);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
$('<div></div>')
|
2011-08-08 01:26:51 +02:00
|
|
|
.html(formatRelativeDate(project.date))
|
2011-08-04 22:37:14 +02:00
|
|
|
.addClass("last-modified")
|
|
|
|
.attr("title", project.date.toString())
|
2011-10-06 09:20:48 +02:00
|
|
|
.appendTo($(tr.insertCell(tr.cells.length)).attr('width', '1%'));
|
|
|
|
|
|
|
|
var nameLink = $('<a></a>')
|
|
|
|
.addClass("project-name")
|
|
|
|
.text(project.name)
|
2012-10-13 19:47:08 +02:00
|
|
|
.attr("href", "project?project=" + project.id)
|
2011-08-04 22:37:14 +02:00
|
|
|
.appendTo(tr.insertCell(tr.cells.length));
|
|
|
|
|
|
|
|
$(tr).mouseenter(function() {
|
|
|
|
renameLink.css("visibility", "visible");
|
|
|
|
deleteLink.css("visibility", "visible");
|
|
|
|
}).mouseleave(function() {
|
|
|
|
renameLink.css("visibility", "hidden");
|
|
|
|
deleteLink.css("visibility", "hidden");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < projects.length; i++) {
|
|
|
|
renderProject(projects[i]);
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.OpenProjectUI.prototype._onClickUploadFileButton = function(evt) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var projectName = $("#project-name-input")[0].value;
|
|
|
|
var dataURL = $.trim($("#project-url-input")[0].value);
|
|
|
|
if (! $.trim(projectName).length) {
|
2013-07-02 13:40:50 +02:00
|
|
|
window.alert($.i18n._('core-index-open')["warning-proj-name"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
} else if ($("#project-file-input")[0].files.length === 0 && ! dataURL.length) {
|
2013-07-02 13:40:50 +02:00
|
|
|
window.alert($.i18n._('core-index-open')["warning-data-file"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$("#file-upload-form").attr("action",
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/create-project-from-upload?" + [
|
2011-08-04 22:37:14 +02:00
|
|
|
"url=" + escape(dataURL),
|
|
|
|
"split-into-columns=" + $("#split-into-columns-input")[0].checked,
|
|
|
|
"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
|
|
|
|
].join("&"));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
evt.preventDefault();
|
|
|
|
return false;
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.actionAreas.push({
|
|
|
|
id: "open-project",
|
2013-07-02 13:40:50 +02:00
|
|
|
label: $.i18n._('core-index-open')["open-proj"],
|
2011-08-02 05:34:47 +02:00
|
|
|
uiClass: Refine.OpenProjectUI
|
|
|
|
});
|