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
|
|
|
{
|
2020-03-23 11:14:02 +01:00
|
|
|
"id": "core/export-local",
|
|
|
|
"label": $.i18n('core-dialogs/export-to-local'),
|
|
|
|
"click": function () { ExporterManager.handlers.exportProjectToLocal(); }
|
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
|
|
|
{
|
2020-03-23 11:14:02 +01:00
|
|
|
"id" : "core/export-sql",
|
|
|
|
"label": $.i18n('core-project/sql-export'),
|
|
|
|
"click": function() { new SqlExporterDialog(); }
|
2018-03-25 05:33:41 +02:00
|
|
|
},
|
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) {
|
2020-06-18 22:06:46 +02:00
|
|
|
// prohibited characters in file name of linux (/) and windows (\/:*?"<>|)
|
|
|
|
// and MacOS https://stackoverflow.com/a/47455094/167425
|
|
|
|
return $.trim(name.replace(/[\\*\/:;,?"<>|#]/g, ' ')).replace(/\s+/g, '-');
|
2018-04-20 10:32:57 +02:00
|
|
|
};
|
|
|
|
|
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);
|
2020-03-23 11:14:02 +01:00
|
|
|
|
2011-08-30 21:19:46 +02:00
|
|
|
document.body.appendChild(form);
|
|
|
|
|
2020-02-23 14:04:20 +01:00
|
|
|
window.open(" ", "refine-export");
|
2011-08-30 21:19:46 +02:00
|
|
|
form.submit();
|
|
|
|
|
|
|
|
document.body.removeChild(form);
|
|
|
|
};
|
|
|
|
|
|
|
|
ExporterManager.prepareExportRowsForm = function(format, includeEngine, ext) {
|
2020-06-18 22:06:46 +02:00
|
|
|
var name = encodeURI(ExporterManager.stripNonFileChars(theProject.metadata.name));
|
2011-08-04 22:37:14 +02:00
|
|
|
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")
|
2020-08-06 13:47:31 +02:00
|
|
|
.val(theProject.id)
|
2011-08-04 22:37:14 +02:00
|
|
|
.appendTo(form);
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "format")
|
2020-08-06 13:47:31 +02:00
|
|
|
.val(format)
|
2011-08-04 22:37:14 +02:00
|
|
|
.appendTo(form);
|
2020-03-17 19:01:37 +01:00
|
|
|
$('<input />')
|
|
|
|
.attr("name", "quoteAll")
|
|
|
|
.appendTo(form);
|
2011-08-30 21:19:46 +02:00
|
|
|
if (includeEngine) {
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "engine")
|
2020-08-06 13:47:31 +02:00
|
|
|
.val(JSON.stringify(ui.browsingEngine.getJSON()))
|
2011-08-30 21:19:46 +02:00
|
|
|
.appendTo(form);
|
|
|
|
}
|
2020-03-23 11:14:02 +01:00
|
|
|
|
2011-08-30 21:19:46 +02:00
|
|
|
return form;
|
2010-10-02 04:06:01 +02:00
|
|
|
};
|
|
|
|
|
2020-03-23 11:14:02 +01:00
|
|
|
ExporterManager.handlers.exportProjectToLocal = function() {
|
2020-06-18 22:06:46 +02:00
|
|
|
var name = encodeURI(ExporterManager.stripNonFileChars(theProject.metadata.name));
|
2020-03-23 11:14:02 +01:00
|
|
|
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")
|
2020-08-06 13:47:31 +02:00
|
|
|
.val(theProject.id)
|
2020-03-23 11:14:02 +01:00
|
|
|
.appendTo(form);
|
|
|
|
|
|
|
|
document.body.appendChild(form);
|
2018-02-02 14:24:19 +01:00
|
|
|
|
2020-03-23 11:14:02 +01:00
|
|
|
window.open(" ", "refine-export");
|
|
|
|
form.submit();
|
|
|
|
|
|
|
|
document.body.removeChild(form);
|
|
|
|
};
|