2019-05-16 14:43:42 +02:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2015-03-13 00:38:37 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
RED.clipboard = (function() {
|
2015-05-26 22:52:23 +02:00
|
|
|
|
|
|
|
var dialog;
|
|
|
|
var dialogContainer;
|
|
|
|
var exportNodesDialog;
|
|
|
|
var importNodesDialog;
|
2017-01-11 15:15:14 +01:00
|
|
|
var disabled = false;
|
2018-10-24 00:06:43 +02:00
|
|
|
var popover;
|
|
|
|
var currentPopoverError;
|
2019-04-24 12:50:24 +02:00
|
|
|
var activeTab;
|
2019-04-23 15:23:17 +02:00
|
|
|
var libraryBrowser;
|
2019-05-21 23:58:56 +02:00
|
|
|
var examplesBrowser;
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2016-01-08 20:54:16 +01:00
|
|
|
function setupDialogs() {
|
2019-05-09 20:22:40 +02:00
|
|
|
dialog = $('<div id="red-ui-clipboard-dialog" class="hide"><form class="dialog-form form-horizontal"></form></div>')
|
2019-05-01 23:41:20 +02:00
|
|
|
.appendTo("#red-ui-editor")
|
2015-05-26 22:52:23 +02:00
|
|
|
.dialog({
|
|
|
|
modal: true,
|
|
|
|
autoOpen: false,
|
2019-04-24 12:50:24 +02:00
|
|
|
width: 700,
|
2015-05-26 22:52:23 +02:00
|
|
|
resizable: false,
|
2019-05-09 20:22:40 +02:00
|
|
|
classes: {
|
|
|
|
"ui-dialog": "red-ui-editor-dialog",
|
|
|
|
"ui-dialog-titlebar-close": "hide",
|
|
|
|
"ui-widget-overlay": "red-ui-editor-dialog"
|
|
|
|
},
|
2015-05-26 22:52:23 +02:00
|
|
|
buttons: [
|
|
|
|
{
|
2019-05-02 23:33:29 +02:00
|
|
|
id: "red-ui-clipboard-dialog-cancel",
|
2016-05-03 22:36:22 +02:00
|
|
|
text: RED._("common.label.cancel"),
|
2015-05-26 22:52:23 +02:00
|
|
|
click: function() {
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
}
|
|
|
|
},
|
2018-11-05 23:31:42 +01:00
|
|
|
{
|
2019-05-02 23:33:29 +02:00
|
|
|
id: "red-ui-clipboard-dialog-download",
|
2018-11-05 23:31:42 +01:00
|
|
|
class: "primary",
|
|
|
|
text: RED._("clipboard.download"),
|
|
|
|
click: function() {
|
|
|
|
var element = document.createElement('a');
|
2019-05-16 14:26:49 +02:00
|
|
|
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent($("#red-ui-clipboard-dialog-export-text").val()));
|
2018-11-05 23:31:42 +01:00
|
|
|
element.setAttribute('download', "flows.json");
|
|
|
|
element.style.display = 'none';
|
|
|
|
document.body.appendChild(element);
|
2019-05-28 17:10:21 +02:00
|
|
|
element.click();
|
2018-11-05 23:31:42 +01:00
|
|
|
document.body.removeChild(element);
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
}
|
|
|
|
},
|
2016-09-19 14:54:23 +02:00
|
|
|
{
|
2019-05-02 23:33:29 +02:00
|
|
|
id: "red-ui-clipboard-dialog-export",
|
2016-09-19 14:54:23 +02:00
|
|
|
class: "primary",
|
|
|
|
text: RED._("clipboard.export.copy"),
|
|
|
|
click: function() {
|
2019-05-02 23:33:29 +02:00
|
|
|
if (activeTab === "red-ui-clipboard-dialog-export-tab-clipboard") {
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-text").select();
|
2019-04-23 15:23:17 +02:00
|
|
|
document.execCommand("copy");
|
|
|
|
document.getSelection().removeAllRanges();
|
|
|
|
RED.notify(RED._("clipboard.nodesExported"),{id:"clipboard"});
|
|
|
|
$( this ).dialog( "close" );
|
|
|
|
} else {
|
2019-05-16 14:26:49 +02:00
|
|
|
var flowToExport = $("#red-ui-clipboard-dialog-export-text").val();
|
2019-04-23 16:46:15 +02:00
|
|
|
var selectedPath = libraryBrowser.getSelected();
|
|
|
|
if (!selectedPath.children) {
|
|
|
|
selectedPath = selectedPath.parent;
|
|
|
|
}
|
2019-05-02 23:33:29 +02:00
|
|
|
var filename = $("#red-ui-clipboard-dialog-tab-library-name").val().trim();
|
2019-04-23 15:23:17 +02:00
|
|
|
var saveFlow = function() {
|
|
|
|
$.ajax({
|
2019-04-25 12:32:09 +02:00
|
|
|
url:'library/'+selectedPath.library+'/'+selectedPath.type+'/'+selectedPath.path + filename,
|
2019-04-23 15:23:17 +02:00
|
|
|
type: "POST",
|
|
|
|
data: flowToExport,
|
|
|
|
contentType: "application/json; charset=utf-8"
|
|
|
|
}).done(function() {
|
|
|
|
$(dialog).dialog( "close" );
|
|
|
|
RED.notify(RED._("library.exportedToLibrary"),"success");
|
|
|
|
}).fail(function(xhr,textStatus,err) {
|
|
|
|
if (xhr.status === 401) {
|
|
|
|
RED.notify(RED._("library.saveFailed",{message:RED._("user.notAuthorized")}),"error");
|
|
|
|
} else {
|
|
|
|
RED.notify(RED._("library.saveFailed",{message:xhr.responseText}),"error");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
if (selectedPath.children) {
|
2019-04-23 15:23:17 +02:00
|
|
|
var exists = false;
|
2019-04-24 12:50:24 +02:00
|
|
|
selectedPath.children.forEach(function(f) {
|
2019-04-23 15:23:17 +02:00
|
|
|
if (f.label === filename) {
|
|
|
|
exists = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (exists) {
|
|
|
|
dialog.dialog("close");
|
|
|
|
var notification = RED.notify(RED._("clipboard.export.exists",{file:RED.utils.sanitize(filename)}),{
|
|
|
|
type: "warning",
|
|
|
|
fixed: true,
|
|
|
|
buttons: [{
|
|
|
|
text: RED._("common.label.cancel"),
|
|
|
|
click: function() {
|
|
|
|
notification.hideNotification()
|
|
|
|
dialog.dialog( "open" );
|
|
|
|
}
|
|
|
|
},{
|
|
|
|
text: RED._("clipboard.export.overwrite"),
|
|
|
|
click: function() {
|
|
|
|
notification.hideNotification()
|
|
|
|
saveFlow();
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
saveFlow();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
saveFlow();
|
|
|
|
}
|
|
|
|
}
|
2016-09-19 14:54:23 +02:00
|
|
|
}
|
|
|
|
},
|
2015-05-26 22:52:23 +02:00
|
|
|
{
|
2019-05-02 23:33:29 +02:00
|
|
|
id: "red-ui-clipboard-dialog-ok",
|
2016-05-03 22:36:22 +02:00
|
|
|
class: "primary",
|
|
|
|
text: RED._("common.label.import"),
|
2015-05-26 22:52:23 +02:00
|
|
|
click: function() {
|
2019-05-16 14:26:49 +02:00
|
|
|
var addNewFlow = ($("#red-ui-clipboard-dialog-import-opt > a.selected").attr('id') === 'red-ui-clipboard-dialog-import-opt-new');
|
2019-05-21 23:58:56 +02:00
|
|
|
if (activeTab === "red-ui-clipboard-dialog-import-tab-clipboard") {
|
2019-05-16 14:26:49 +02:00
|
|
|
RED.view.importNodes($("#red-ui-clipboard-dialog-import-text").val(),addNewFlow);
|
2019-04-24 12:50:24 +02:00
|
|
|
} else {
|
2019-05-21 23:58:56 +02:00
|
|
|
var selectedPath;
|
|
|
|
if (activeTab === "red-ui-clipboard-dialog-import-tab-library") {
|
|
|
|
selectedPath = libraryBrowser.getSelected();
|
|
|
|
} else {
|
|
|
|
selectedPath = examplesBrowser.getSelected();
|
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
if (selectedPath.path) {
|
2019-04-25 12:32:09 +02:00
|
|
|
$.get('library/'+selectedPath.library+'/'+selectedPath.type+'/'+selectedPath.path, function(data) {
|
2019-04-24 12:50:24 +02:00
|
|
|
RED.view.importNodes(data,addNewFlow);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-05-26 22:52:23 +02:00
|
|
|
$( this ).dialog( "close" );
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-26 22:52:23 +02:00
|
|
|
],
|
|
|
|
close: function(e) {
|
2018-10-24 12:07:48 +02:00
|
|
|
if (popover) {
|
|
|
|
popover.close(true);
|
|
|
|
currentPopoverError = null;
|
|
|
|
}
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
2016-01-08 20:54:16 +01:00
|
|
|
});
|
2015-03-13 00:38:37 +01:00
|
|
|
|
2015-05-26 22:52:23 +02:00
|
|
|
dialogContainer = dialog.children(".dialog-form");
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2016-09-19 14:54:23 +02:00
|
|
|
exportNodesDialog =
|
|
|
|
'<div class="form-row">'+
|
2019-04-23 15:23:17 +02:00
|
|
|
'<label style="width:auto;margin-right: 10px;" data-i18n="common.label.export"></label>'+
|
2019-05-16 14:26:49 +02:00
|
|
|
'<span id="red-ui-clipboard-dialog-export-rng-group" class="button-group">'+
|
2019-05-17 11:42:43 +02:00
|
|
|
'<a id="red-ui-clipboard-dialog-export-rng-selected" class="red-ui-button toggle" href="#" data-i18n="clipboard.export.selected"></a>'+
|
|
|
|
'<a id="red-ui-clipboard-dialog-export-rng-flow" class="red-ui-button toggle" href="#" data-i18n="clipboard.export.current"></a>'+
|
|
|
|
'<a id="red-ui-clipboard-dialog-export-rng-full" class="red-ui-button toggle" href="#" data-i18n="clipboard.export.all"></a>'+
|
2016-09-19 14:54:23 +02:00
|
|
|
'</span>'+
|
2018-11-05 23:31:42 +01:00
|
|
|
'</div>'+
|
2019-05-15 14:54:29 +02:00
|
|
|
'<div class="red-ui-clipboard-dialog-box">'+
|
2019-05-09 20:22:40 +02:00
|
|
|
'<div class="red-ui-clipboard-dialog-tabs">'+
|
2019-05-02 23:33:29 +02:00
|
|
|
'<ul id="red-ui-clipboard-dialog-export-tabs"></ul>'+
|
2019-04-23 15:23:17 +02:00
|
|
|
'</div>'+
|
2019-05-02 23:33:29 +02:00
|
|
|
'<div id="red-ui-clipboard-dialog-export-tabs-content" class="red-ui-clipboard-dialog-tabs-content">'+
|
|
|
|
'<div id="red-ui-clipboard-dialog-export-tab-clipboard" class="red-ui-clipboard-dialog-tab-clipboard">'+
|
2020-05-21 16:14:39 +02:00
|
|
|
'<div class="form-row" style="height:calc(100% - 30px)">'+
|
2019-05-16 14:26:49 +02:00
|
|
|
'<textarea readonly id="red-ui-clipboard-dialog-export-text"></textarea>'+
|
2019-04-23 15:23:17 +02:00
|
|
|
'</div>'+
|
|
|
|
'<div class="form-row" style="text-align: right;">'+
|
2019-05-16 14:26:49 +02:00
|
|
|
'<span id="red-ui-clipboard-dialog-export-fmt-group" class="button-group">'+
|
2019-05-17 11:42:43 +02:00
|
|
|
'<a id="red-ui-clipboard-dialog-export-fmt-mini" class="red-ui-button red-ui-button-small toggle" href="#" data-i18n="clipboard.export.compact"></a>'+
|
|
|
|
'<a id="red-ui-clipboard-dialog-export-fmt-full" class="red-ui-button red-ui-button-small toggle" href="#" data-i18n="clipboard.export.formatted"></a>'+
|
2019-04-23 15:23:17 +02:00
|
|
|
'</span>'+
|
|
|
|
'</div>'+
|
|
|
|
'</div>'+
|
2019-05-02 23:33:29 +02:00
|
|
|
'<div id="red-ui-clipboard-dialog-export-tab-library" class="red-ui-clipboard-dialog-tab-library">'+
|
|
|
|
'<div id="red-ui-clipboard-dialog-export-tab-library-browser"></div>'+
|
2019-04-23 15:23:17 +02:00
|
|
|
'<div class="form-row">'+
|
2019-05-02 23:33:29 +02:00
|
|
|
'<label data-i18n="clipboard.export.exportAs"></label><input id="red-ui-clipboard-dialog-tab-library-name" type="text">'+
|
2019-04-23 15:23:17 +02:00
|
|
|
'</div>'+
|
|
|
|
'</div>'+
|
|
|
|
'</div>'+
|
|
|
|
'</div>'
|
|
|
|
;
|
|
|
|
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2018-11-05 23:31:42 +01:00
|
|
|
importNodesDialog =
|
2019-05-15 14:54:29 +02:00
|
|
|
'<div class="red-ui-clipboard-dialog-box" style="margin-bottom: 12px">'+
|
2019-05-09 20:22:40 +02:00
|
|
|
'<div class="red-ui-clipboard-dialog-tabs">'+
|
2019-05-02 23:33:29 +02:00
|
|
|
'<ul id="red-ui-clipboard-dialog-import-tabs"></ul>'+
|
2019-04-24 12:50:24 +02:00
|
|
|
'</div>'+
|
2019-05-02 23:33:29 +02:00
|
|
|
'<div id="red-ui-clipboard-dialog-import-tabs-content" class="red-ui-clipboard-dialog-tabs-content">'+
|
|
|
|
'<div id="red-ui-clipboard-dialog-import-tab-clipboard" class="red-ui-clipboard-dialog-tab-clipboard">'+
|
2019-04-24 12:50:24 +02:00
|
|
|
'<div class="form-row"><span data-i18n="clipboard.pasteNodes"></span>'+
|
2019-05-17 11:42:43 +02:00
|
|
|
' <a class="red-ui-button" id="red-ui-clipboard-dialog-import-file-upload-btn"><i class="fa fa-upload"></i> <span data-i18n="clipboard.selectFile"></span></a>'+
|
2019-05-16 14:26:49 +02:00
|
|
|
'<input type="file" id="red-ui-clipboard-dialog-import-file-upload" accept=".json" style="display:none">'+
|
2019-04-24 12:50:24 +02:00
|
|
|
'</div>'+
|
2020-05-21 16:14:39 +02:00
|
|
|
'<div class="form-row" style="height:calc(100% - 47px)">'+
|
2019-05-16 14:26:49 +02:00
|
|
|
'<textarea id="red-ui-clipboard-dialog-import-text"></textarea>'+
|
2019-04-24 12:50:24 +02:00
|
|
|
'</div>'+
|
|
|
|
'</div>'+
|
2019-05-21 23:58:56 +02:00
|
|
|
'<div id="red-ui-clipboard-dialog-import-tab-library" class="red-ui-clipboard-dialog-tab-library"></div>'+
|
|
|
|
'<div id="red-ui-clipboard-dialog-import-tab-examples" class="red-ui-clipboard-dialog-tab-library"></div>'+
|
2019-04-24 12:50:24 +02:00
|
|
|
'</div>'+
|
2016-09-23 23:02:12 +02:00
|
|
|
'</div>'+
|
|
|
|
'<div class="form-row">'+
|
2019-04-24 12:50:24 +02:00
|
|
|
'<label style="width:auto;margin-right: 10px;" data-i18n="clipboard.import.import"></label>'+
|
2019-05-16 14:26:49 +02:00
|
|
|
'<span id="red-ui-clipboard-dialog-import-opt" class="button-group">'+
|
2019-05-17 11:42:43 +02:00
|
|
|
'<a id="red-ui-clipboard-dialog-import-opt-current" class="red-ui-button toggle selected" href="#" data-i18n="clipboard.export.current"></a>'+
|
|
|
|
'<a id="red-ui-clipboard-dialog-import-opt-new" class="red-ui-button toggle" href="#" data-i18n="clipboard.import.newFlow"></a>'+
|
2019-04-24 12:50:24 +02:00
|
|
|
'</span>'+
|
2015-05-26 22:52:23 +02:00
|
|
|
'</div>';
|
2019-04-24 12:50:24 +02:00
|
|
|
|
2015-05-26 22:52:23 +02:00
|
|
|
}
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2019-04-23 15:23:17 +02:00
|
|
|
var validateExportFilenameTimeout
|
|
|
|
function validateExportFilename() {
|
|
|
|
if (validateExportFilenameTimeout) {
|
|
|
|
clearTimeout(validateExportFilenameTimeout);
|
|
|
|
}
|
|
|
|
validateExportFilenameTimeout = setTimeout(function() {
|
2019-05-02 23:33:29 +02:00
|
|
|
var filenameInput = $("#red-ui-clipboard-dialog-tab-library-name");
|
2019-04-23 15:23:17 +02:00
|
|
|
var filename = filenameInput.val().trim();
|
|
|
|
var valid = filename.length > 0 && !/[\/\\]/.test(filename);
|
|
|
|
if (valid) {
|
|
|
|
filenameInput.removeClass("input-error");
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export").button("enable");
|
2019-04-23 15:23:17 +02:00
|
|
|
} else {
|
|
|
|
filenameInput.addClass("input-error");
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export").button("disable");
|
2019-04-23 15:23:17 +02:00
|
|
|
}
|
|
|
|
},100);
|
|
|
|
}
|
|
|
|
|
2018-10-24 12:07:48 +02:00
|
|
|
var validateImportTimeout;
|
2015-06-17 21:48:56 +02:00
|
|
|
function validateImport() {
|
2019-05-02 23:33:29 +02:00
|
|
|
if (activeTab === "red-ui-clipboard-dialog-import-tab-clipboard") {
|
2019-04-24 12:50:24 +02:00
|
|
|
if (validateImportTimeout) {
|
|
|
|
clearTimeout(validateImportTimeout);
|
2018-10-24 00:06:43 +02:00
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
validateImportTimeout = setTimeout(function() {
|
2019-05-16 14:26:49 +02:00
|
|
|
var importInput = $("#red-ui-clipboard-dialog-import-text");
|
2019-04-24 12:50:24 +02:00
|
|
|
var v = importInput.val().trim();
|
|
|
|
if (v === "") {
|
|
|
|
popover.close(true);
|
|
|
|
currentPopoverError = null;
|
|
|
|
importInput.removeClass("input-error");
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-ok").button("disable");
|
2019-04-24 12:50:24 +02:00
|
|
|
return;
|
2018-10-24 00:06:43 +02:00
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
try {
|
|
|
|
if (!/^\[[\s\S]*\]$/m.test(v)) {
|
|
|
|
throw new Error(RED._("clipboard.import.errors.notArray"));
|
2018-10-24 12:07:48 +02:00
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
var res = JSON.parse(v);
|
|
|
|
for (var i=0;i<res.length;i++) {
|
|
|
|
if (typeof res[i] !== "object") {
|
|
|
|
throw new Error(RED._("clipboard.import.errors.itemNotObject",{index:i}));
|
|
|
|
}
|
|
|
|
if (!res[i].hasOwnProperty('id')) {
|
|
|
|
throw new Error(RED._("clipboard.import.errors.missingId",{index:i}));
|
|
|
|
}
|
|
|
|
if (!res[i].hasOwnProperty('type')) {
|
|
|
|
throw new Error(RED._("clipboard.import.errors.missingType",{index:i}));
|
|
|
|
}
|
2018-10-24 12:07:48 +02:00
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
currentPopoverError = null;
|
|
|
|
popover.close(true);
|
|
|
|
importInput.removeClass("input-error");
|
|
|
|
importInput.val(v);
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-ok").button("enable");
|
2019-04-24 12:50:24 +02:00
|
|
|
} catch(err) {
|
|
|
|
if (v !== "") {
|
|
|
|
importInput.addClass("input-error");
|
|
|
|
var errString = err.toString();
|
|
|
|
if (errString !== currentPopoverError) {
|
|
|
|
// Display the error as-is.
|
|
|
|
// Error messages are only in English. Each browser has its
|
|
|
|
// own set of messages with very little consistency.
|
|
|
|
// To provide translated messages this code will either need to:
|
|
|
|
// - reduce everything down to 'unexpected token at position x'
|
|
|
|
// which is the least useful, but most consistent message
|
|
|
|
// - use a custom/library parser that gives consistent messages
|
|
|
|
// which can be translated.
|
2019-05-02 23:33:29 +02:00
|
|
|
var message = $('<div class="red-ui-clipboard-import-error"></div>').text(errString);
|
2019-04-24 12:50:24 +02:00
|
|
|
var errorPos;
|
|
|
|
// Chrome error messages
|
|
|
|
var m = /at position (\d+)/i.exec(errString);
|
2018-10-24 12:07:48 +02:00
|
|
|
if (m) {
|
2019-04-24 12:50:24 +02:00
|
|
|
errorPos = parseInt(m[1]);
|
2018-10-24 12:07:48 +02:00
|
|
|
} else {
|
2019-04-24 12:50:24 +02:00
|
|
|
// Firefox error messages
|
|
|
|
m = /at line (\d+) column (\d+)/i.exec(errString);
|
|
|
|
if (m) {
|
|
|
|
var line = parseInt(m[1])-1;
|
|
|
|
var col = parseInt(m[2])-1;
|
|
|
|
var lines = v.split("\n");
|
|
|
|
errorPos = 0;
|
|
|
|
for (var i=0;i<line;i++) {
|
|
|
|
errorPos += lines[i].length+1;
|
|
|
|
}
|
|
|
|
errorPos += col;
|
|
|
|
} else {
|
|
|
|
// Safari doesn't provide any position information
|
|
|
|
// IE: tbd
|
|
|
|
}
|
2018-10-24 12:07:48 +02:00
|
|
|
}
|
2018-10-24 00:06:43 +02:00
|
|
|
|
2019-04-24 12:50:24 +02:00
|
|
|
if (errorPos !== undefined) {
|
|
|
|
v = v.replace(/\n/g,"↵");
|
|
|
|
var index = parseInt(m[1]);
|
|
|
|
var parseError = $('<div>').appendTo(message);
|
|
|
|
var code = $('<pre>').appendTo(parseError);
|
|
|
|
$('<span>').text(v.substring(errorPos-12,errorPos)).appendTo(code)
|
|
|
|
$('<span class="error">').text(v.charAt(errorPos)).appendTo(code);
|
|
|
|
$('<span>').text(v.substring(errorPos+1,errorPos+12)).appendTo(code);
|
|
|
|
}
|
|
|
|
popover.close(true).setContent(message).open();
|
|
|
|
currentPopoverError = errString;
|
2018-10-24 12:07:48 +02:00
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
} else {
|
|
|
|
currentPopoverError = null;
|
2018-10-24 00:06:43 +02:00
|
|
|
}
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-ok").button("disable");
|
2018-10-24 00:06:43 +02:00
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
},100);
|
|
|
|
} else {
|
|
|
|
var file = libraryBrowser.getSelected();
|
|
|
|
if (file && file.label && !file.children) {
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-ok").button("enable");
|
2019-04-24 12:50:24 +02:00
|
|
|
} else {
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-ok").button("disable");
|
2015-06-17 21:48:56 +02:00
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
}
|
2015-06-17 21:48:56 +02:00
|
|
|
}
|
2015-05-26 22:52:23 +02:00
|
|
|
|
2019-04-24 12:50:24 +02:00
|
|
|
function importNodes(mode) {
|
2017-01-11 15:15:14 +01:00
|
|
|
if (disabled) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
mode = mode || "clipboard";
|
|
|
|
|
2015-03-13 00:38:37 +01:00
|
|
|
dialogContainer.empty();
|
|
|
|
dialogContainer.append($(importNodesDialog));
|
2019-04-24 12:50:24 +02:00
|
|
|
|
|
|
|
var tabs = RED.tabs.create({
|
2019-05-02 23:33:29 +02:00
|
|
|
id: "red-ui-clipboard-dialog-import-tabs",
|
2019-04-24 12:50:24 +02:00
|
|
|
vertical: true,
|
|
|
|
onchange: function(tab) {
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-import-tabs-content").children().hide();
|
2019-04-24 12:50:24 +02:00
|
|
|
$("#" + tab.id).show();
|
|
|
|
activeTab = tab.id;
|
|
|
|
if (popover) {
|
|
|
|
popover.close(true);
|
|
|
|
currentPopoverError = null;
|
|
|
|
}
|
2019-05-02 23:33:29 +02:00
|
|
|
if (tab.id === "red-ui-clipboard-dialog-import-tab-clipboard") {
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-import-text").trigger("focus");
|
2019-04-26 17:21:35 +02:00
|
|
|
} else {
|
|
|
|
libraryBrowser.focus();
|
2019-04-24 12:50:24 +02:00
|
|
|
}
|
|
|
|
validateImport();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
tabs.addTab({
|
2019-05-02 23:33:29 +02:00
|
|
|
id: "red-ui-clipboard-dialog-import-tab-clipboard",
|
2019-04-24 12:50:24 +02:00
|
|
|
label: RED._("clipboard.clipboard")
|
|
|
|
});
|
|
|
|
tabs.addTab({
|
2019-05-02 23:33:29 +02:00
|
|
|
id: "red-ui-clipboard-dialog-import-tab-library",
|
2019-04-24 12:50:24 +02:00
|
|
|
label: RED._("library.library")
|
|
|
|
});
|
2019-05-21 23:58:56 +02:00
|
|
|
tabs.addTab({
|
|
|
|
id: "red-ui-clipboard-dialog-import-tab-examples",
|
|
|
|
label: RED._("library.types.examples")
|
|
|
|
});
|
2019-04-24 12:50:24 +02:00
|
|
|
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-tab-library-name").on("keyup", validateExportFilename);
|
|
|
|
$("#red-ui-clipboard-dialog-tab-library-name").on('paste',function() { setTimeout(validateExportFilename,10)});
|
|
|
|
$("#red-ui-clipboard-dialog-export").button("enable");
|
2019-04-24 12:50:24 +02:00
|
|
|
|
|
|
|
libraryBrowser = RED.library.createBrowser({
|
2019-05-21 23:58:56 +02:00
|
|
|
container: $("#red-ui-clipboard-dialog-import-tab-library"),
|
2019-04-24 12:50:24 +02:00
|
|
|
onselect: function(file) {
|
|
|
|
if (file && file.label && !file.children) {
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-ok").button("enable");
|
2019-04-24 12:50:24 +02:00
|
|
|
} else {
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-ok").button("disable");
|
2019-04-24 12:50:24 +02:00
|
|
|
}
|
2019-05-21 23:58:56 +02:00
|
|
|
},
|
|
|
|
onconfirm: function(item) {
|
|
|
|
if (item && item.label && !item.children) {
|
|
|
|
$("#red-ui-clipboard-dialog-ok").trigger("click");
|
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
}
|
|
|
|
})
|
2019-05-21 23:58:56 +02:00
|
|
|
loadFlowLibrary(libraryBrowser,"local",RED._("library.types.local"));
|
|
|
|
|
|
|
|
examplesBrowser = RED.library.createBrowser({
|
|
|
|
container: $("#red-ui-clipboard-dialog-import-tab-examples"),
|
|
|
|
onselect: function(file) {
|
|
|
|
if (file && file.label && !file.children) {
|
|
|
|
$("#red-ui-clipboard-dialog-ok").button("enable");
|
|
|
|
} else {
|
|
|
|
$("#red-ui-clipboard-dialog-ok").button("disable");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onconfirm: function(item) {
|
|
|
|
if (item && item.label && !item.children) {
|
|
|
|
$("#red-ui-clipboard-dialog-ok").trigger("click");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
loadFlowLibrary(examplesBrowser,"_examples_",RED._("library.types.examples"));
|
|
|
|
|
2019-04-24 12:50:24 +02:00
|
|
|
|
2016-09-23 23:02:12 +02:00
|
|
|
dialogContainer.i18n();
|
|
|
|
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-ok").show();
|
|
|
|
$("#red-ui-clipboard-dialog-cancel").show();
|
|
|
|
$("#red-ui-clipboard-dialog-export").hide();
|
|
|
|
$("#red-ui-clipboard-dialog-download").hide();
|
|
|
|
$("#red-ui-clipboard-dialog-ok").button("disable");
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-import-text").on("keyup", validateImport);
|
|
|
|
$("#red-ui-clipboard-dialog-import-text").on('paste',function() { setTimeout(validateImport,10)});
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-import-opt > a").on("click", function(evt) {
|
2016-09-23 23:02:12 +02:00
|
|
|
evt.preventDefault();
|
|
|
|
if ($(this).hasClass('disabled') || $(this).hasClass('selected')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$(this).parent().children().removeClass('selected');
|
|
|
|
$(this).addClass('selected');
|
|
|
|
});
|
|
|
|
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-import-file-upload").on("change", function() {
|
2018-11-05 23:31:42 +01:00
|
|
|
var fileReader = new FileReader();
|
|
|
|
fileReader.onload = function () {
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-import-text").val(fileReader.result);
|
2018-11-05 23:31:42 +01:00
|
|
|
validateImport();
|
|
|
|
};
|
|
|
|
fileReader.readAsText($(this).prop('files')[0]);
|
|
|
|
})
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-import-file-upload-btn").on("click", function(evt) {
|
2018-11-05 23:31:42 +01:00
|
|
|
evt.preventDefault();
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-import-file-upload").trigger("click");
|
2018-11-05 23:31:42 +01:00
|
|
|
})
|
|
|
|
|
2019-06-07 12:35:04 +02:00
|
|
|
tabs.activateTab("red-ui-clipboard-dialog-import-tab-"+mode);
|
|
|
|
if (mode === 'clipboard') {
|
|
|
|
setTimeout(function() {
|
|
|
|
$("#red-ui-clipboard-dialog-import-text").trigger("focus");
|
|
|
|
},100)
|
|
|
|
}
|
|
|
|
|
2020-05-21 16:14:39 +02:00
|
|
|
var dialogHeight = 400;
|
|
|
|
var winHeight = $(window).height();
|
|
|
|
if (winHeight < 600) {
|
|
|
|
dialogHeight = 400 - (600 - winHeight);
|
|
|
|
}
|
|
|
|
$(".red-ui-clipboard-dialog-box").height(dialogHeight);
|
2019-06-07 12:35:04 +02:00
|
|
|
|
2015-07-01 00:42:03 +02:00
|
|
|
dialog.dialog("option","title",RED._("clipboard.importNodes")).dialog("open");
|
2018-10-24 00:06:43 +02:00
|
|
|
popover = RED.popover.create({
|
2019-05-16 14:26:49 +02:00
|
|
|
target: $("#red-ui-clipboard-dialog-import-text"),
|
2018-10-24 00:06:43 +02:00
|
|
|
trigger: "manual",
|
|
|
|
direction: "bottom",
|
|
|
|
content: ""
|
|
|
|
});
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
2015-06-17 21:48:56 +02:00
|
|
|
|
2019-04-23 15:23:17 +02:00
|
|
|
function exportNodes(mode) {
|
2017-01-11 15:15:14 +01:00
|
|
|
if (disabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-23 15:23:17 +02:00
|
|
|
mode = mode || "clipboard";
|
|
|
|
|
2015-03-13 00:38:37 +01:00
|
|
|
dialogContainer.empty();
|
|
|
|
dialogContainer.append($(exportNodesDialog));
|
2019-04-23 15:23:17 +02:00
|
|
|
|
|
|
|
var tabs = RED.tabs.create({
|
2019-05-02 23:33:29 +02:00
|
|
|
id: "red-ui-clipboard-dialog-export-tabs",
|
2019-04-23 15:23:17 +02:00
|
|
|
vertical: true,
|
|
|
|
onchange: function(tab) {
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-tabs-content").children().hide();
|
2019-04-23 15:23:17 +02:00
|
|
|
$("#" + tab.id).show();
|
2019-04-24 12:50:24 +02:00
|
|
|
activeTab = tab.id;
|
2019-05-02 23:33:29 +02:00
|
|
|
if (tab.id === "red-ui-clipboard-dialog-export-tab-clipboard") {
|
|
|
|
$("#red-ui-clipboard-dialog-export").button("option","label", RED._("clipboard.export.copy"))
|
|
|
|
$("#red-ui-clipboard-dialog-download").show();
|
2019-04-23 15:23:17 +02:00
|
|
|
} else {
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export").button("option","label", RED._("clipboard.export.export"))
|
|
|
|
$("#red-ui-clipboard-dialog-download").hide();
|
2019-04-26 17:21:35 +02:00
|
|
|
libraryBrowser.focus();
|
2019-04-23 15:23:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
tabs.addTab({
|
2019-05-02 23:33:29 +02:00
|
|
|
id: "red-ui-clipboard-dialog-export-tab-clipboard",
|
2019-04-24 12:50:24 +02:00
|
|
|
label: RED._("clipboard.clipboard")
|
2019-04-23 15:23:17 +02:00
|
|
|
});
|
|
|
|
tabs.addTab({
|
2019-05-02 23:33:29 +02:00
|
|
|
id: "red-ui-clipboard-dialog-export-tab-library",
|
2019-04-24 12:50:24 +02:00
|
|
|
label: RED._("library.library")
|
2019-04-23 15:23:17 +02:00
|
|
|
});
|
|
|
|
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-tab-library-name").on("keyup", validateExportFilename);
|
|
|
|
$("#red-ui-clipboard-dialog-tab-library-name").on('paste',function() { setTimeout(validateExportFilename,10)});
|
|
|
|
$("#red-ui-clipboard-dialog-export").button("enable");
|
2019-04-23 15:23:17 +02:00
|
|
|
|
|
|
|
libraryBrowser = RED.library.createBrowser({
|
2019-05-02 23:33:29 +02:00
|
|
|
container: $("#red-ui-clipboard-dialog-export-tab-library-browser"),
|
2019-04-26 17:21:35 +02:00
|
|
|
folderTools: true,
|
2019-04-23 15:23:17 +02:00
|
|
|
onselect: function(file) {
|
2019-04-23 16:46:15 +02:00
|
|
|
if (file && file.label && !file.children) {
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-tab-library-name").val(file.label);
|
2019-04-23 15:23:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-05-21 23:58:56 +02:00
|
|
|
loadFlowLibrary(libraryBrowser,"local",RED._("library.types.local"));
|
2019-04-23 15:23:17 +02:00
|
|
|
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-tab-library-name").val("flows.json").select();
|
2019-04-23 15:23:17 +02:00
|
|
|
|
2016-09-19 14:54:23 +02:00
|
|
|
dialogContainer.i18n();
|
2019-05-16 14:26:49 +02:00
|
|
|
var format = RED.settings.flowFilePretty ? "red-ui-clipboard-dialog-export-fmt-full" : "red-ui-clipboard-dialog-export-fmt-mini";
|
2016-09-19 14:54:23 +02:00
|
|
|
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-fmt-group > a").on("click", function(evt) {
|
2016-09-19 14:54:23 +02:00
|
|
|
evt.preventDefault();
|
|
|
|
if ($(this).hasClass('disabled') || $(this).hasClass('selected')) {
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-text").trigger("focus");
|
2016-09-19 14:54:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$(this).parent().children().removeClass('selected');
|
|
|
|
$(this).addClass('selected');
|
|
|
|
|
2019-05-16 14:26:49 +02:00
|
|
|
var flow = $("#red-ui-clipboard-dialog-export-text").val();
|
2016-09-19 14:54:23 +02:00
|
|
|
if (flow.length > 0) {
|
|
|
|
var nodes = JSON.parse(flow);
|
|
|
|
|
2017-02-28 22:50:06 +01:00
|
|
|
format = $(this).attr('id');
|
2019-05-16 14:26:49 +02:00
|
|
|
if (format === 'red-ui-clipboard-dialog-export-fmt-full') {
|
2016-09-19 14:54:23 +02:00
|
|
|
flow = JSON.stringify(nodes,null,4);
|
|
|
|
} else {
|
|
|
|
flow = JSON.stringify(nodes);
|
|
|
|
}
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-text").val(flow);
|
|
|
|
setTimeout(function() { $("#red-ui-clipboard-dialog-export-text").scrollTop(0); },50);
|
2019-04-23 15:23:17 +02:00
|
|
|
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-text").trigger("focus");
|
2016-09-19 14:54:23 +02:00
|
|
|
}
|
|
|
|
});
|
2017-02-28 22:50:06 +01:00
|
|
|
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-rng-group > a").on("click", function(evt) {
|
2016-09-19 14:54:23 +02:00
|
|
|
evt.preventDefault();
|
|
|
|
if ($(this).hasClass('disabled') || $(this).hasClass('selected')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$(this).parent().children().removeClass('selected');
|
|
|
|
$(this).addClass('selected');
|
|
|
|
var type = $(this).attr('id');
|
|
|
|
var flow = "";
|
|
|
|
var nodes = null;
|
2019-05-16 14:26:49 +02:00
|
|
|
if (type === 'red-ui-clipboard-dialog-export-rng-selected') {
|
2018-10-30 23:18:16 +01:00
|
|
|
var selection = RED.workspaces.selection();
|
|
|
|
if (selection.length > 0) {
|
|
|
|
nodes = [];
|
|
|
|
selection.forEach(function(n) {
|
|
|
|
nodes.push(n);
|
2020-03-26 19:01:57 +01:00
|
|
|
nodes = nodes.concat(RED.nodes.groups(n.id));
|
2018-10-30 23:18:16 +01:00
|
|
|
nodes = nodes.concat(RED.nodes.filterNodes({z:n.id}));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
nodes = RED.view.selection().nodes||[];
|
|
|
|
}
|
2017-08-08 16:48:54 +02:00
|
|
|
// Don't include the subflow meta-port nodes in the exported selection
|
2018-10-30 23:18:16 +01:00
|
|
|
nodes = RED.nodes.createExportableNodeSet(nodes.filter(function(n) { return n.type !== 'subflow'}));
|
2019-05-16 14:26:49 +02:00
|
|
|
} else if (type === 'red-ui-clipboard-dialog-export-rng-flow') {
|
2016-09-19 14:54:23 +02:00
|
|
|
var activeWorkspace = RED.workspaces.active();
|
2020-03-26 19:01:57 +01:00
|
|
|
nodes = RED.nodes.groups(activeWorkspace);
|
|
|
|
nodes = nodes.concat(RED.nodes.filterNodes({z:activeWorkspace}));
|
2016-09-19 14:54:23 +02:00
|
|
|
var parentNode = RED.nodes.workspace(activeWorkspace)||RED.nodes.subflow(activeWorkspace);
|
|
|
|
nodes.unshift(parentNode);
|
|
|
|
nodes = RED.nodes.createExportableNodeSet(nodes);
|
2019-05-16 14:26:49 +02:00
|
|
|
} else if (type === 'red-ui-clipboard-dialog-export-rng-full') {
|
2016-09-19 14:54:23 +02:00
|
|
|
nodes = RED.nodes.createCompleteNodeSet(false);
|
|
|
|
}
|
|
|
|
if (nodes !== null) {
|
2019-05-16 14:26:49 +02:00
|
|
|
if (format === "red-ui-clipboard-dialog-export-fmt-full") {
|
2016-09-19 14:54:23 +02:00
|
|
|
flow = JSON.stringify(nodes,null,4);
|
|
|
|
} else {
|
|
|
|
flow = JSON.stringify(nodes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flow.length > 0) {
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export").removeClass('disabled');
|
2016-09-19 14:54:23 +02:00
|
|
|
} else {
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export").addClass('disabled');
|
2016-09-19 14:54:23 +02:00
|
|
|
}
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-text").val(flow);
|
|
|
|
setTimeout(function() { $("#red-ui-clipboard-dialog-export-text").scrollTop(0); },50);
|
|
|
|
$("#red-ui-clipboard-dialog-export-text").trigger("focus");
|
2016-09-19 14:54:23 +02:00
|
|
|
})
|
|
|
|
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-ok").hide();
|
|
|
|
$("#red-ui-clipboard-dialog-cancel").hide();
|
|
|
|
$("#red-ui-clipboard-dialog-export").hide();
|
2018-10-30 23:18:16 +01:00
|
|
|
var selection = RED.workspaces.selection();
|
|
|
|
if (selection.length > 0) {
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-rng-selected").trigger("click");
|
2016-09-19 14:54:23 +02:00
|
|
|
} else {
|
2018-10-30 23:18:16 +01:00
|
|
|
selection = RED.view.selection();
|
|
|
|
if (selection.nodes) {
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-rng-selected").trigger("click");
|
2018-10-30 23:18:16 +01:00
|
|
|
} else {
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-rng-selected").addClass('disabled').removeClass('selected');
|
|
|
|
$("#red-ui-clipboard-dialog-export-rng-flow").trigger("click");
|
2018-10-30 23:18:16 +01:00
|
|
|
}
|
2016-09-19 14:54:23 +02:00
|
|
|
}
|
2019-05-16 14:26:49 +02:00
|
|
|
if (format === "red-ui-clipboard-dialog-export-fmt-full") {
|
|
|
|
$("#red-ui-clipboard-dialog-export-fmt-full").trigger("click");
|
2016-09-19 14:54:23 +02:00
|
|
|
} else {
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-fmt-mini").trigger("click");
|
2016-09-19 14:54:23 +02:00
|
|
|
}
|
2019-06-07 12:35:04 +02:00
|
|
|
tabs.activateTab("red-ui-clipboard-dialog-export-tab-"+mode);
|
2020-05-21 16:14:39 +02:00
|
|
|
|
|
|
|
var dialogHeight = 400;
|
|
|
|
var winHeight = $(window).height();
|
|
|
|
if (winHeight < 600) {
|
|
|
|
dialogHeight = 400 - (600 - winHeight);
|
|
|
|
}
|
|
|
|
$(".red-ui-clipboard-dialog-box").height(dialogHeight);
|
|
|
|
|
2016-09-19 14:54:23 +02:00
|
|
|
dialog.dialog("option","title",RED._("clipboard.exportNodes")).dialog( "open" );
|
|
|
|
|
2019-05-16 14:26:49 +02:00
|
|
|
$("#red-ui-clipboard-dialog-export-text").trigger("focus");
|
2019-05-02 23:33:29 +02:00
|
|
|
$("#red-ui-clipboard-dialog-cancel").show();
|
|
|
|
$("#red-ui-clipboard-dialog-export").show();
|
|
|
|
$("#red-ui-clipboard-dialog-download").show();
|
2018-11-05 23:31:42 +01:00
|
|
|
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
2019-04-24 12:50:24 +02:00
|
|
|
|
2019-05-21 23:58:56 +02:00
|
|
|
function loadFlowLibrary(browser,library,label) {
|
|
|
|
// if (includeExamples) {
|
|
|
|
// listing.push({
|
|
|
|
// library: "_examples_",
|
|
|
|
// type: "flows",
|
|
|
|
// icon: 'fa fa-hdd-o',
|
|
|
|
// label: RED._("library.types.examples"),
|
|
|
|
// path: "",
|
2019-05-27 22:11:50 +02:00
|
|
|
// children: function(done,item) {
|
2019-05-21 23:58:56 +02:00
|
|
|
// RED.library.loadLibraryFolder("_examples_","flows","",function(children) {
|
|
|
|
// item.children = children;
|
|
|
|
// done(children);
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
browser.data([{
|
|
|
|
library: library,
|
2019-04-25 12:32:09 +02:00
|
|
|
type: "flows",
|
|
|
|
icon: 'fa fa-hdd-o',
|
2019-05-21 23:58:56 +02:00
|
|
|
label: label,
|
2019-04-25 12:32:09 +02:00
|
|
|
path: "",
|
|
|
|
expanded: true,
|
2019-05-27 22:11:50 +02:00
|
|
|
children: function(done, item) {
|
2019-05-21 23:58:56 +02:00
|
|
|
RED.library.loadLibraryFolder(library,"flows","",function(children) {
|
2019-04-25 12:32:09 +02:00
|
|
|
item.children = children;
|
|
|
|
done(children);
|
|
|
|
})
|
2019-04-24 12:50:24 +02:00
|
|
|
}
|
2019-05-28 12:23:03 +02:00
|
|
|
}], true);
|
|
|
|
|
2019-04-24 12:50:24 +02:00
|
|
|
}
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2015-03-14 23:53:31 +01:00
|
|
|
function hideDropTarget() {
|
2019-05-01 23:41:20 +02:00
|
|
|
$("#red-ui-drop-target").hide();
|
2016-12-04 23:59:43 +01:00
|
|
|
RED.keyboard.remove("escape");
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
2017-05-10 16:49:12 +02:00
|
|
|
function copyText(value,element,msg) {
|
|
|
|
var truncated = false;
|
|
|
|
if (typeof value !== "string" ) {
|
|
|
|
value = JSON.stringify(value, function(key,value) {
|
|
|
|
if (value !== null && typeof value === 'object') {
|
2018-07-15 00:06:15 +02:00
|
|
|
if (value.__enc__) {
|
2018-06-29 11:50:07 +02:00
|
|
|
if (value.hasOwnProperty('data') && value.hasOwnProperty('length')) {
|
|
|
|
truncated = value.data.length !== value.length;
|
|
|
|
return value.data;
|
|
|
|
}
|
|
|
|
if (value.type === 'function' || value.type === 'internal') {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
if (value.type === 'number') {
|
|
|
|
// Handle NaN and Infinity - they are not permitted
|
|
|
|
// in JSON. We can either substitute with a String
|
|
|
|
// representation or null
|
|
|
|
return null;
|
|
|
|
}
|
2017-05-10 16:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (truncated) {
|
|
|
|
msg += "_truncated";
|
|
|
|
}
|
2019-05-01 23:41:20 +02:00
|
|
|
$("#red-ui-clipboard-hidden").val(value).select();
|
2017-05-10 16:49:12 +02:00
|
|
|
var result = document.execCommand("copy");
|
|
|
|
if (result && element) {
|
|
|
|
var popover = RED.popover.create({
|
|
|
|
target: element,
|
|
|
|
direction: 'left',
|
|
|
|
size: 'small',
|
|
|
|
content: RED._(msg)
|
|
|
|
});
|
|
|
|
setTimeout(function() {
|
|
|
|
popover.close();
|
|
|
|
},1000);
|
|
|
|
popover.open();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2015-03-13 00:38:37 +01:00
|
|
|
return {
|
|
|
|
init: function() {
|
2015-05-26 22:52:23 +02:00
|
|
|
setupDialogs();
|
2017-05-10 16:49:12 +02:00
|
|
|
|
2019-06-06 18:17:05 +02:00
|
|
|
$('<input type="text" id="red-ui-clipboard-hidden" tabIndex="-1">').appendTo("#red-ui-editor");
|
2017-05-10 16:49:12 +02:00
|
|
|
|
2017-01-11 12:35:48 +01:00
|
|
|
RED.actions.add("core:show-export-dialog",exportNodes);
|
|
|
|
RED.actions.add("core:show-import-dialog",importNodes);
|
2016-12-04 23:59:43 +01:00
|
|
|
|
2019-06-07 12:35:04 +02:00
|
|
|
RED.actions.add("core:show-library-export-dialog",function() { exportNodes('library') });
|
|
|
|
RED.actions.add("core:show-library-import-dialog",function() { importNodes('library') });
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2020-05-07 14:46:18 +02:00
|
|
|
RED.actions.add("core:show-examples-import-dialog",function() { importNodes('examples') });
|
|
|
|
|
2017-01-11 15:15:14 +01:00
|
|
|
RED.events.on("editor:open",function() { disabled = true; });
|
|
|
|
RED.events.on("editor:close",function() { disabled = false; });
|
|
|
|
RED.events.on("search:open",function() { disabled = true; });
|
|
|
|
RED.events.on("search:close",function() { disabled = false; });
|
2019-06-11 23:43:01 +02:00
|
|
|
RED.events.on("actionList:open",function() { disabled = true; });
|
|
|
|
RED.events.on("actionList:close",function() { disabled = false; });
|
2017-01-11 15:15:14 +01:00
|
|
|
RED.events.on("type-search:open",function() { disabled = true; });
|
|
|
|
RED.events.on("type-search:close",function() { disabled = false; });
|
|
|
|
|
2019-05-01 23:41:20 +02:00
|
|
|
$('<div id="red-ui-drop-target"><div data-i18n="[append]workspace.dropFlowHere"><i class="fa fa-download"></i><br></div></div>').appendTo('#red-ui-editor');
|
|
|
|
|
|
|
|
$('#red-ui-workspace-chart').on("dragenter",function(event) {
|
2017-01-19 16:34:14 +01:00
|
|
|
if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1 ||
|
|
|
|
$.inArray("Files",event.originalEvent.dataTransfer.types) != -1) {
|
2019-05-01 23:41:20 +02:00
|
|
|
$("#red-ui-drop-target").css({display:'table'});
|
2016-12-04 23:59:43 +01:00
|
|
|
RED.keyboard.add("*", "escape" ,hideDropTarget);
|
2015-03-14 23:53:31 +01:00
|
|
|
}
|
|
|
|
});
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2019-05-01 23:41:20 +02:00
|
|
|
$('#red-ui-drop-target').on("dragover",function(event) {
|
2017-01-19 16:34:14 +01:00
|
|
|
if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1 ||
|
|
|
|
$.inArray("Files",event.originalEvent.dataTransfer.types) != -1) {
|
2015-03-14 23:53:31 +01:00
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on("dragleave",function(event) {
|
|
|
|
hideDropTarget();
|
|
|
|
})
|
|
|
|
.on("drop",function(event) {
|
2017-01-19 16:34:14 +01:00
|
|
|
if ($.inArray("text/plain",event.originalEvent.dataTransfer.types) != -1) {
|
|
|
|
var data = event.originalEvent.dataTransfer.getData("text/plain");
|
|
|
|
data = data.substring(data.indexOf('['),data.lastIndexOf(']')+1);
|
|
|
|
RED.view.importNodes(data);
|
|
|
|
} else if ($.inArray("Files",event.originalEvent.dataTransfer.types) != -1) {
|
|
|
|
var files = event.originalEvent.dataTransfer.files;
|
|
|
|
if (files.length === 1) {
|
|
|
|
var file = files[0];
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = (function(theFile) {
|
|
|
|
return function(e) {
|
|
|
|
RED.view.importNodes(e.target.result);
|
|
|
|
};
|
|
|
|
})(file);
|
|
|
|
reader.readAsText(file);
|
|
|
|
}
|
|
|
|
}
|
2015-03-14 23:53:31 +01:00
|
|
|
hideDropTarget();
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2015-03-13 00:38:37 +01:00
|
|
|
},
|
|
|
|
import: importNodes,
|
2017-05-10 16:49:12 +02:00
|
|
|
export: exportNodes,
|
|
|
|
copyText: copyText
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
|
|
|
})();
|