2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
Copyright 2010, 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
|
2010-10-20 20:11:15 +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
|
2010-10-20 20:11:15 +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
|
2010-10-20 20:11:15 +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
|
|
|
*/
|
2010-10-02 04:06:01 +02:00
|
|
|
function ExporterManager(button) {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._button = button;
|
|
|
|
this._initializeUI();
|
2010-10-02 04:06:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ExporterManager.handlers = {};
|
|
|
|
|
|
|
|
ExporterManager.MenuItems = [
|
2011-08-04 22:37:14 +02:00
|
|
|
{
|
|
|
|
"id" : "core/export-project",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/export-project'),
|
2011-08-04 22:37:14 +02:00
|
|
|
"click": function() { ExporterManager.handlers.exportProject(); }
|
|
|
|
},
|
2018-02-02 14:24:19 +01:00
|
|
|
{
|
|
|
|
"id" : "core/project-data-package",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/project-data-package'),
|
2018-02-02 14:24:19 +01:00
|
|
|
"click": function() { ExporterManager.handlers.projectDataPackage(); }
|
|
|
|
},
|
2011-08-04 22:37:14 +02:00
|
|
|
{},
|
|
|
|
{
|
|
|
|
"id" : "core/export-tsv",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/tab-value'),
|
2011-08-04 22:37:14 +02:00
|
|
|
"click": function() { ExporterManager.handlers.exportRows("tsv", "tsv"); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "core/export-csv",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/comma-sep'),
|
2011-08-04 22:37:14 +02:00
|
|
|
"click": function() { ExporterManager.handlers.exportRows("csv", "csv"); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "core/export-html-table",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/html-table'),
|
2011-08-04 22:37:14 +02:00
|
|
|
"click": function() { ExporterManager.handlers.exportRows("html", "html"); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "core/export-excel",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/excel'),
|
2011-08-04 22:37:14 +02:00
|
|
|
"click": function() { ExporterManager.handlers.exportRows("xls", "xls"); }
|
|
|
|
},
|
2014-11-02 22:58:04 +01:00
|
|
|
{
|
|
|
|
"id" : "core/export-excel-xml",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/excel-xml'),
|
2014-11-02 22:58:04 +01:00
|
|
|
"click": function() { ExporterManager.handlers.exportRows("xlsx", "xlsx"); }
|
|
|
|
},
|
2011-10-11 23:02:23 +02:00
|
|
|
{
|
|
|
|
"id" : "core/export-ods",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/odf'),
|
2011-10-11 23:02:23 +02:00
|
|
|
"click": function() { ExporterManager.handlers.exportRows("ods", "ods"); }
|
|
|
|
},
|
2011-08-04 22:37:14 +02:00
|
|
|
{},
|
2011-08-29 00:43:45 +02:00
|
|
|
{
|
|
|
|
"id" : "core/export-custom-tabular",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/custom-tabular'),
|
2011-08-29 00:43:45 +02:00
|
|
|
"click": function() { new CustomTabularExporterDialog(); }
|
|
|
|
},
|
2018-03-25 05:33:41 +02:00
|
|
|
{
|
|
|
|
"id" : "core/export-sql",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/sql-export'),
|
2018-03-25 05:33:41 +02:00
|
|
|
"click": function() { new SqlExporterDialog(); }
|
|
|
|
},
|
2011-08-04 22:37:14 +02:00
|
|
|
{
|
|
|
|
"id" : "core/export-templating",
|
2018-11-21 18:30:00 +01:00
|
|
|
"label": $.i18n('core-project/templating'),
|
2011-08-04 22:37:14 +02:00
|
|
|
"click": function() { new TemplatingExporterDialog(); }
|
|
|
|
}
|
2010-10-02 04:06:01 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
ExporterManager.prototype._initializeUI = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._button.click(function(evt) {
|
|
|
|
MenuSystem.createAndShowStandardMenu(
|
|
|
|
ExporterManager.MenuItems,
|
|
|
|
this,
|
|
|
|
{ horizontal: false }
|
|
|
|
);
|
|
|
|
|
|
|
|
evt.preventDefault();
|
|
|
|
return false;
|
|
|
|
});
|
2010-10-02 04:06:01 +02:00
|
|
|
};
|
|
|
|
|
2018-04-20 10:32:57 +02:00
|
|
|
ExporterManager.stripNonFileChars = function(name) {
|
|
|
|
//prohibited characters in file name of linux (/) and windows (\/:*?"<>|)
|
|
|
|
return $.trim(name.replace(/[\\*\/:?"<>|]/g, ' ')).replace(/\s+/g, '-');
|
|
|
|
};
|
|
|
|
|
2010-10-02 04:06:01 +02:00
|
|
|
ExporterManager.handlers.exportTripleloader = function(format) {
|
2011-08-04 22:37:14 +02:00
|
|
|
if (!theProject.overlayModels.freebaseProtograph) {
|
2018-11-21 18:30:00 +01:00
|
|
|
alert($.i18n('triple-loader/warning-align'));
|
2011-08-04 22:37:14 +02:00
|
|
|
} else {
|
|
|
|
ExporterManager.handlers.exportRows(format, "txt");
|
|
|
|
}
|
2010-10-02 04:06:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ExporterManager.handlers.exportRows = function(format, ext) {
|
2011-08-30 21:19:46 +02:00
|
|
|
var form = ExporterManager.prepareExportRowsForm(format, true, ext);
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "contentType")
|
|
|
|
.attr("value", "application/x-unknown") // force download
|
|
|
|
.appendTo(form);
|
|
|
|
|
|
|
|
document.body.appendChild(form);
|
|
|
|
|
|
|
|
window.open("about:blank", "refine-export");
|
|
|
|
form.submit();
|
|
|
|
|
|
|
|
document.body.removeChild(form);
|
|
|
|
};
|
|
|
|
|
|
|
|
ExporterManager.prepareExportRowsForm = function(format, includeEngine, ext) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-');
|
|
|
|
var form = document.createElement("form");
|
|
|
|
$(form)
|
|
|
|
.css("display", "none")
|
|
|
|
.attr("method", "post")
|
2012-10-13 19:47:08 +02:00
|
|
|
.attr("action", "command/core/export-rows/" + name + ((ext) ? ("." + ext) : ""))
|
2011-08-04 22:37:14 +02:00
|
|
|
.attr("target", "refine-export");
|
|
|
|
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "project")
|
|
|
|
.attr("value", theProject.id)
|
|
|
|
.appendTo(form);
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "format")
|
|
|
|
.attr("value", format)
|
|
|
|
.appendTo(form);
|
2011-08-30 21:19:46 +02:00
|
|
|
if (includeEngine) {
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "engine")
|
|
|
|
.attr("value", JSON.stringify(ui.browsingEngine.getJSON()))
|
|
|
|
.appendTo(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
return form;
|
2010-10-02 04:06:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ExporterManager.handlers.exportProject = function() {
|
2018-04-20 10:32:57 +02:00
|
|
|
var name = ExporterManager.stripNonFileChars(theProject.metadata.name);
|
2018-02-25 18:00:40 +01:00
|
|
|
// dialog
|
|
|
|
var dialog = $(DOM.loadHTML("core", "scripts/dialogs/export-project-dialog.html"));
|
|
|
|
var _elmts = DOM.bind(dialog);
|
|
|
|
|
2018-11-21 18:30:00 +01:00
|
|
|
_elmts.dialogHeader.html($.i18n('core-dialogs/choose-export-destination'));
|
|
|
|
_elmts.toLocalRadio.html($.i18n('core-dialogs/export-to-local'));
|
|
|
|
_elmts.toGoogleDriveRadio.html($.i18n('core-dialogs/export-to-google-drive'));
|
|
|
|
_elmts.exportButton.html($.i18n('core-buttons/export'));
|
|
|
|
_elmts.cancelButton.html($.i18n('core-buttons/cancel'));
|
2018-02-25 18:00:40 +01:00
|
|
|
|
|
|
|
_elmts.exportButton.click(function() {
|
|
|
|
if ($("input[name='export-destination']")[0].checked) {
|
|
|
|
exportToLocal(name);
|
|
|
|
} else {
|
|
|
|
exportToGoogleDrive(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogSystem.dismissAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
_elmts.cancelButton.click(function() { DialogSystem.dismissAll(); });
|
|
|
|
|
|
|
|
DialogSystem.showDialog(dialog);
|
|
|
|
|
|
|
|
// save to google drive
|
|
|
|
var doExportToGoogleDrive = function() {
|
|
|
|
var name = window.prompt(prompt, theProject.metadata.name);
|
|
|
|
if (name) {
|
2018-11-21 18:30:00 +01:00
|
|
|
var dismiss = DialogSystem.showBusy($.i18n('gdata-exporter/uploading'));
|
2018-02-25 18:00:40 +01:00
|
|
|
$.post(
|
|
|
|
"command/gdata/upload",
|
|
|
|
{
|
|
|
|
"project" : theProject.id,
|
|
|
|
"name" : name,
|
|
|
|
"format" : "raw/openrefine-project"
|
|
|
|
},
|
|
|
|
function(o) {
|
|
|
|
dismiss();
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2018-02-25 18:00:40 +01:00
|
|
|
if (o.url) {
|
2018-11-21 18:30:00 +01:00
|
|
|
alert($.i18n('gdata-exporter/upload-success') + o.url);
|
2018-02-25 18:00:40 +01:00
|
|
|
} else {
|
2018-11-21 18:30:00 +01:00
|
|
|
alert($.i18n('gdata-exporter/upload-error') + o.message)
|
2018-02-25 18:00:40 +01:00
|
|
|
}
|
|
|
|
onDone();
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2018-02-25 18:00:40 +01:00
|
|
|
function exportToGoogleDrive(name) {
|
|
|
|
if (GdataExtension.isAuthorized()) {
|
|
|
|
doExportToGoogleDrive();
|
|
|
|
} else {
|
|
|
|
GdataExtension.showAuthorizationDialog(doExportToGoogleDrive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save to local
|
|
|
|
function exportToLocal(name) {
|
|
|
|
var form = document.createElement("form");
|
|
|
|
$(form)
|
|
|
|
.css("display", "none")
|
|
|
|
.attr("method", "post")
|
|
|
|
.attr("action", "command/core/export-project/" + name + ".openrefine.tar.gz")
|
|
|
|
.attr("target", "refine-export");
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "project")
|
|
|
|
.attr("value", theProject.id)
|
|
|
|
.appendTo(form);
|
|
|
|
|
|
|
|
document.body.appendChild(form);
|
|
|
|
|
|
|
|
window.open("about:blank", "refine-export");
|
|
|
|
form.submit();
|
|
|
|
|
|
|
|
document.body.removeChild(form);
|
|
|
|
}
|
2010-10-02 04:06:01 +02:00
|
|
|
};
|
2018-02-02 14:24:19 +01:00
|
|
|
|
|
|
|
ExporterManager.handlers.projectDataPackage = function() {
|
|
|
|
function save(jsonMetadata) {
|
2018-04-20 10:32:57 +02:00
|
|
|
var name = ExporterManager.stripNonFileChars(theProject.metadata.name);
|
2018-02-02 14:24:19 +01:00
|
|
|
var form = document.createElement("form");
|
|
|
|
$(form)
|
|
|
|
.css("display", "none")
|
|
|
|
.attr("method", "post")
|
|
|
|
.attr("action", "command/core/project-data-package/" + name + ".openrefine.zip")
|
|
|
|
.attr("target", "refine-export");
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "project")
|
|
|
|
.attr("value", theProject.id)
|
|
|
|
.appendTo(form);
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "metadata")
|
|
|
|
.attr("value", jsonMetadata)
|
|
|
|
.appendTo(form);
|
|
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(form);
|
|
|
|
|
|
|
|
window.open("about:blank", "refine-export");
|
|
|
|
form.submit();
|
|
|
|
|
|
|
|
document.body.removeChild(form);
|
|
|
|
}
|
|
|
|
|
|
|
|
new EditGeneralMetadataDialog(theProject.id, save);
|
|
|
|
};
|