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 = $(
|
2017-11-03 21:59:03 +01:00
|
|
|
'<table class="tablesorter-blue list-table"><thead><tr>' +
|
2011-08-04 22:37:14 +02:00
|
|
|
'<th></th>' +
|
|
|
|
'<th></th>' +
|
2017-10-26 21:45:58 +02:00
|
|
|
'<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>' +
|
2017-10-26 21:45:58 +02:00
|
|
|
'<th>'+$.i18n._('core-index-open')["creator"]+'</th>' +
|
|
|
|
'<th>'+$.i18n._('core-index-open')["subject"]+'</th>' +
|
|
|
|
'<th>'+$.i18n._('core-index-open')["description"]+'</th>' +
|
|
|
|
'<th>'+$.i18n._('core-index-open')["row-number"]+'</th>' +
|
|
|
|
(function() {
|
|
|
|
var htmlDisplay = "";
|
|
|
|
for (var n in data.customMetaDataColumns) {
|
|
|
|
if (data.customMetaDataColumns[n].display) {
|
|
|
|
htmlDisplay += '<th>'+ data.customMetaDataColumns[n].name + '</th>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return htmlDisplay;
|
|
|
|
})() +
|
2017-11-03 21:59:03 +01:00
|
|
|
'</tr></thead><tbody></tbody></table>'
|
2011-08-04 22:37:14 +02:00
|
|
|
).appendTo(container)[0];
|
|
|
|
|
|
|
|
var renderProject = function(project) {
|
2017-11-03 21:59:03 +01:00
|
|
|
var tr = table.getElementsByTagName('tbody')[0].insertRow(table.rows.length - 1);
|
2011-08-04 22:37:14 +02:00
|
|
|
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%')
|
|
|
|
);
|
2017-10-26 21:45:58 +02:00
|
|
|
|
|
|
|
var editMetaDataLink = $('<a></a>')
|
|
|
|
.text($.i18n._('core-index-open')["edit-meta-data"])
|
|
|
|
.addClass("secondary")
|
|
|
|
.attr("href", "javascript:{}")
|
|
|
|
.css("visibility", "hidden")
|
|
|
|
.click(function() {
|
2017-10-29 18:46:37 +01:00
|
|
|
new EditMetadataDialog(project, $(this).parent().parent());
|
2017-10-26 21:45:58 +02:00
|
|
|
})
|
|
|
|
.appendTo(
|
2017-10-29 19:14:39 +01:00
|
|
|
$(tr.insertCell(tr.cells.length)).css('width', '3%')
|
2017-10-26 21:45:58 +02:00
|
|
|
);
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
$('<div></div>')
|
2017-11-05 03:53:32 +01:00
|
|
|
.html(project.date.toISOString())
|
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%'));
|
2017-10-29 18:46:37 +01:00
|
|
|
|
2011-10-06 09:20:48 +02:00
|
|
|
var nameLink = $('<a></a>')
|
|
|
|
.addClass("project-name")
|
|
|
|
.text(project.name)
|
2012-10-13 19:47:08 +02:00
|
|
|
.attr("href", "project?project=" + project.id)
|
2017-10-29 19:14:39 +01:00
|
|
|
.appendTo($(tr.insertCell(tr.cells.length)).attr('width', '10%'));
|
2017-10-29 18:46:37 +01:00
|
|
|
|
|
|
|
var appendMetaField = function(data, width) {
|
2017-11-04 00:46:07 +01:00
|
|
|
width = width || '1%';
|
2017-10-29 18:46:37 +01:00
|
|
|
$('<div></div>')
|
|
|
|
.html(data)
|
|
|
|
.appendTo($(tr.insertCell(tr.cells.length)).attr('width', width));
|
|
|
|
};
|
|
|
|
|
|
|
|
appendMetaField(project.creator);
|
|
|
|
appendMetaField(project.subject);
|
|
|
|
appendMetaField(project.description, '20%');
|
|
|
|
appendMetaField(project.rowNumber);
|
|
|
|
|
|
|
|
var data = project.userMetaData;
|
|
|
|
for(var i in data)
|
|
|
|
{
|
|
|
|
if (data[i].display === true) {
|
|
|
|
appendMetaField(data[i].value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
$(tr).mouseenter(function() {
|
|
|
|
renameLink.css("visibility", "visible");
|
|
|
|
deleteLink.css("visibility", "visible");
|
2017-10-26 21:45:58 +02:00
|
|
|
editMetaDataLink.css("visibility", "visible");
|
2011-08-04 22:37:14 +02:00
|
|
|
}).mouseleave(function() {
|
|
|
|
renameLink.css("visibility", "hidden");
|
|
|
|
deleteLink.css("visibility", "hidden");
|
2017-10-26 21:45:58 +02:00
|
|
|
editMetaDataLink.css("visibility", "hidden");
|
2011-08-04 22:37:14 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var i = 0; i < projects.length; i++) {
|
|
|
|
renderProject(projects[i]);
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2017-11-03 21:59:03 +01:00
|
|
|
|
2017-11-05 03:53:32 +01:00
|
|
|
|
|
|
|
$(table).tablesorter({
|
|
|
|
headers : {
|
|
|
|
3 : {
|
|
|
|
sorter : "time"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
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?" + [
|
2015-11-17 14:55:19 +01:00
|
|
|
"url=" + encodeURIComponent(dataURL),
|
2011-08-04 22:37:14 +02:00
|
|
|
"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
|
|
|
};
|
|
|
|
|
2017-10-29 18:46:37 +01:00
|
|
|
Refine.OpenProjectUI.refreshProject = function(tr, metaData) {
|
|
|
|
var refreshMetaField = function(data, index) {
|
|
|
|
$('td', tr).eq(index)
|
|
|
|
.html(data);
|
|
|
|
};
|
|
|
|
|
|
|
|
var index = 5;
|
|
|
|
refreshMetaField(metaData.creator, index); index++;
|
|
|
|
refreshMetaField(metaData.subject,index); index++;
|
|
|
|
refreshMetaField(metaData.description,index); index++;
|
|
|
|
refreshMetaField(metaData.rowNumbe,index); index++;
|
|
|
|
|
|
|
|
var updateUserMetaData = function(ob) {
|
|
|
|
var userMetaData = ob.userMetaData;
|
|
|
|
|
|
|
|
for ( var n in ob) {
|
|
|
|
for ( var i in userMetaData) {
|
|
|
|
if (n === userMetaData[i].name) {
|
|
|
|
userMetaData[i].value = ob[n];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ob.userMetaData = userMetaData;
|
|
|
|
};
|
|
|
|
updateUserMetaData(metaData);
|
|
|
|
var data = metaData.userMetaData;
|
|
|
|
for(var i in data)
|
|
|
|
{
|
|
|
|
if (data[i].display === true) {
|
|
|
|
refreshMetaField(data[i].value,index); index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-04 00:46:07 +01:00
|
|
|
};
|
2017-10-29 18:46:37 +01:00
|
|
|
|
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
|
|
|
|
});
|