2015-03-13 00:38:37 +01: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.workspaces = (function() {
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2015-03-13 00:38:37 +01:00
|
|
|
var activeWorkspace = 0;
|
|
|
|
var workspaceIndex = 0;
|
|
|
|
|
2016-09-23 23:02:12 +02:00
|
|
|
function addWorkspace(ws,skipHistoryEntry) {
|
2015-03-13 00:38:37 +01:00
|
|
|
if (ws) {
|
|
|
|
workspace_tabs.addTab(ws);
|
|
|
|
workspace_tabs.resize();
|
|
|
|
} else {
|
|
|
|
var tabId = RED.nodes.id();
|
|
|
|
do {
|
|
|
|
workspaceIndex += 1;
|
2017-04-16 21:25:15 +02:00
|
|
|
} while ($("#workspace-tabs a[title='"+RED._('workspace.defaultName',{number:workspaceIndex})+"']").size() !== 0);
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2015-07-08 23:12:52 +02:00
|
|
|
ws = {type:"tab",id:tabId,label:RED._('workspace.defaultName',{number:workspaceIndex})};
|
2015-03-13 00:38:37 +01:00
|
|
|
RED.nodes.addWorkspace(ws);
|
|
|
|
workspace_tabs.addTab(ws);
|
|
|
|
workspace_tabs.activateTab(tabId);
|
2016-09-23 23:02:12 +02:00
|
|
|
if (!skipHistoryEntry) {
|
|
|
|
RED.history.push({t:'add',workspaces:[ws],dirty:RED.nodes.dirty()});
|
|
|
|
RED.nodes.dirty(true);
|
|
|
|
}
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
2017-01-24 17:14:03 +01:00
|
|
|
RED.view.focus();
|
2016-09-23 23:02:12 +02:00
|
|
|
return ws;
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
2016-06-01 00:20:25 +02:00
|
|
|
function deleteWorkspace(ws) {
|
2015-03-13 00:38:37 +01:00
|
|
|
if (workspace_tabs.count() == 1) {
|
|
|
|
return;
|
|
|
|
}
|
2016-06-01 00:20:25 +02:00
|
|
|
removeWorkspace(ws);
|
|
|
|
var historyEvent = RED.nodes.removeWorkspace(ws.id);
|
|
|
|
historyEvent.t = 'delete';
|
|
|
|
historyEvent.dirty = RED.nodes.dirty();
|
|
|
|
historyEvent.workspaces = [ws];
|
|
|
|
RED.history.push(historyEvent);
|
|
|
|
RED.nodes.dirty(true);
|
|
|
|
RED.sidebar.config.refresh();
|
2015-07-01 00:42:03 +02:00
|
|
|
}
|
2015-03-13 00:38:37 +01:00
|
|
|
|
2016-06-01 00:20:25 +02:00
|
|
|
function showRenameWorkspaceDialog(id) {
|
|
|
|
var workspace = RED.nodes.workspace(id);
|
|
|
|
RED.view.state(RED.state.EDITING);
|
2017-03-16 17:29:19 +01:00
|
|
|
var tabflowEditor;
|
2016-06-01 00:20:25 +02:00
|
|
|
var trayOptions = {
|
|
|
|
title: RED._("workspace.editFlow",{name:workspace.label}),
|
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
id: "node-dialog-delete",
|
|
|
|
class: 'leftButton'+((workspace_tabs.count() == 1)?" disabled":""),
|
|
|
|
text: RED._("common.label.delete"), //'<i class="fa fa-trash"></i>',
|
|
|
|
click: function() {
|
|
|
|
deleteWorkspace(workspace);
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "node-dialog-cancel",
|
|
|
|
text: RED._("common.label.cancel"),
|
|
|
|
click: function() {
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "node-dialog-ok",
|
|
|
|
class: "primary",
|
|
|
|
text: RED._("common.label.done"),
|
|
|
|
click: function() {
|
|
|
|
var label = $( "#node-input-name" ).val();
|
2017-03-06 11:03:15 +01:00
|
|
|
var changed = false;
|
|
|
|
var changes = {};
|
2016-06-01 00:20:25 +02:00
|
|
|
if (workspace.label != label) {
|
2017-03-06 11:03:15 +01:00
|
|
|
changes.label = workspace.label;
|
|
|
|
changed = true;
|
|
|
|
workspace.label = label;
|
|
|
|
workspace_tabs.renameTab(workspace.id,label);
|
|
|
|
}
|
|
|
|
var disabled = $("#node-input-disabled").prop("checked");
|
|
|
|
if (workspace.disabled !== disabled) {
|
|
|
|
changes.disabled = workspace.disabled;
|
|
|
|
changed = true;
|
|
|
|
workspace.disabled = disabled;
|
|
|
|
}
|
2017-03-16 17:29:19 +01:00
|
|
|
var info = tabflowEditor.getValue();
|
|
|
|
if (workspace.info !== info) {
|
|
|
|
changes.info = workspace.info;
|
|
|
|
changed = true;
|
|
|
|
workspace.info = info;
|
|
|
|
}
|
2017-03-06 11:03:15 +01:00
|
|
|
$("#red-ui-tab-"+(workspace.id.replace(".","-"))).toggleClass('workspace-disabled',workspace.disabled);
|
|
|
|
// $("#workspace").toggleClass("workspace-disabled",workspace.disabled);
|
|
|
|
|
|
|
|
if (changed) {
|
2016-06-01 00:20:25 +02:00
|
|
|
var historyEvent = {
|
|
|
|
t: "edit",
|
|
|
|
changes:changes,
|
|
|
|
node: workspace,
|
|
|
|
dirty: RED.nodes.dirty()
|
|
|
|
}
|
2016-10-09 23:02:24 +02:00
|
|
|
workspace.changed = true;
|
2016-06-01 00:20:25 +02:00
|
|
|
RED.history.push(historyEvent);
|
|
|
|
RED.nodes.dirty(true);
|
|
|
|
RED.sidebar.config.refresh();
|
2017-04-10 01:00:10 +02:00
|
|
|
var selection = RED.view.selection();
|
|
|
|
if (!selection.nodes && !selection.links) {
|
|
|
|
RED.sidebar.info.refresh(workspace);
|
|
|
|
}
|
2016-06-01 00:20:25 +02:00
|
|
|
}
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
2017-03-16 17:29:19 +01:00
|
|
|
resize: function(dimensions) {
|
2017-04-16 21:25:15 +02:00
|
|
|
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
|
|
|
|
var editorRow = $("#dialog-form>div.node-text-editor-row");
|
|
|
|
var height = $("#dialog-form").height();
|
|
|
|
for (var i=0; i<rows.size(); i++) {
|
|
|
|
height -= $(rows[i]).outerHeight(true);
|
|
|
|
}
|
|
|
|
height -= (parseInt($("#dialog-form").css("marginTop"))+parseInt($("#dialog-form").css("marginBottom")));
|
2017-04-16 22:08:32 +02:00
|
|
|
height -= 28;
|
2017-04-16 21:25:15 +02:00
|
|
|
$(".node-text-editor").css("height",height+"px");
|
2017-03-16 17:29:19 +01:00
|
|
|
tabflowEditor.resize();
|
|
|
|
},
|
2016-06-01 00:20:25 +02:00
|
|
|
open: function(tray) {
|
|
|
|
var trayBody = tray.find('.editor-tray-body');
|
|
|
|
var dialogForm = $('<form id="dialog-form" class="form-horizontal"></form>').appendTo(trayBody);
|
|
|
|
$('<div class="form-row">'+
|
|
|
|
'<label for="node-input-name" data-i18n="[append]editor:common.label.name"><i class="fa fa-tag"></i> </label>'+
|
|
|
|
'<input type="text" id="node-input-name">'+
|
|
|
|
'</div>').appendTo(dialogForm);
|
2017-03-06 11:03:15 +01:00
|
|
|
|
|
|
|
$('<div class="form-row">'+
|
2017-04-16 22:08:32 +02:00
|
|
|
'<label for="node-input-disabled-btn" data-i18n="editor:workspace.status"></label>'+
|
2017-03-06 16:55:38 +01:00
|
|
|
'<button id="node-input-disabled-btn" class="editor-button"><i class="fa fa-toggle-on"></i> <span id="node-input-disabled-label"></span></button> '+
|
2017-03-06 11:03:15 +01:00
|
|
|
'<input type="checkbox" id="node-input-disabled" style="display: none;"/>'+
|
|
|
|
'</div>').appendTo(dialogForm);
|
|
|
|
|
2017-03-16 17:29:19 +01:00
|
|
|
$('<div class="form-row node-text-editor-row">'+
|
2017-04-16 22:08:32 +02:00
|
|
|
'<label for="node-input-info" data-i18n="editor:workspace.info" style="width:300px;"></label>'+
|
2017-04-16 21:25:15 +02:00
|
|
|
'<div style="height:250px;" class="node-text-editor" id="node-input-info"></div>'+
|
2017-03-16 17:29:19 +01:00
|
|
|
'</div>').appendTo(dialogForm);
|
|
|
|
tabflowEditor = RED.editor.createEditor({
|
|
|
|
id: 'node-input-info',
|
|
|
|
mode: 'ace/mode/markdown',
|
|
|
|
value: ""
|
|
|
|
});
|
|
|
|
|
2017-04-16 22:08:32 +02:00
|
|
|
$('<div class="form-tips" data-i18n="editor:workspace.tip"></div>').appendTo(dialogForm);
|
|
|
|
|
2017-03-06 11:03:15 +01:00
|
|
|
dialogForm.find('#node-input-disabled-btn').on("click",function(e) {
|
|
|
|
var i = $(this).find("i");
|
|
|
|
if (i.hasClass('fa-toggle-off')) {
|
|
|
|
i.addClass('fa-toggle-on');
|
|
|
|
i.removeClass('fa-toggle-off');
|
|
|
|
$("#node-input-disabled").prop("checked",false);
|
2017-03-06 16:55:38 +01:00
|
|
|
$("#node-input-disabled-label").html(RED._("editor:workspace.enabled"));
|
2017-03-06 11:03:15 +01:00
|
|
|
} else {
|
|
|
|
i.addClass('fa-toggle-off');
|
|
|
|
i.removeClass('fa-toggle-on');
|
|
|
|
$("#node-input-disabled").prop("checked",true);
|
2017-03-06 16:55:38 +01:00
|
|
|
$("#node-input-disabled-label").html(RED._("editor:workspace.disabled"));
|
2017-03-06 11:03:15 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if (workspace.hasOwnProperty("disabled")) {
|
|
|
|
$("#node-input-disabled").prop("checked",workspace.disabled);
|
|
|
|
if (workspace.disabled) {
|
|
|
|
dialogForm.find("#node-input-disabled-btn i").removeClass('fa-toggle-on').addClass('fa-toggle-off');
|
2017-03-06 16:55:38 +01:00
|
|
|
$("#node-input-disabled-label").html(RED._("editor:workspace.disabled"));
|
|
|
|
} else {
|
|
|
|
$("#node-input-disabled-label").html(RED._("editor:workspace.enabled"));
|
2017-03-06 11:03:15 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
workspace.disabled = false;
|
2017-03-06 16:55:38 +01:00
|
|
|
$("#node-input-disabled-label").html(RED._("editor:workspace.enabled"));
|
2017-03-06 11:03:15 +01:00
|
|
|
}
|
|
|
|
|
2016-06-01 00:20:25 +02:00
|
|
|
$('<input type="text" style="display: none;" />').prependTo(dialogForm);
|
|
|
|
dialogForm.submit(function(e) { e.preventDefault();});
|
2016-08-26 13:50:18 +02:00
|
|
|
$("#node-input-name").val(workspace.label);
|
2017-03-16 17:29:19 +01:00
|
|
|
RED.text.bidi.prepareInput($("#node-input-name"));
|
|
|
|
tabflowEditor.getSession().setValue(workspace.info || "", -1);
|
2016-06-01 00:20:25 +02:00
|
|
|
dialogForm.i18n();
|
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
if (RED.view.state() != RED.state.IMPORT_DRAGGING) {
|
|
|
|
RED.view.state(RED.state.DEFAULT);
|
|
|
|
}
|
2017-03-16 17:29:19 +01:00
|
|
|
RED.sidebar.info.refresh(workspace);
|
2017-06-26 15:23:48 +02:00
|
|
|
tabflowEditor.destroy();
|
2016-06-01 00:20:25 +02:00
|
|
|
}
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
2016-06-01 00:20:25 +02:00
|
|
|
RED.tray.show(trayOptions);
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2016-06-01 00:20:25 +02:00
|
|
|
|
2015-05-26 22:52:23 +02:00
|
|
|
var workspace_tabs;
|
2017-04-16 21:25:15 +02:00
|
|
|
function createWorkspaceTabs() {
|
2015-05-26 22:52:23 +02:00
|
|
|
workspace_tabs = RED.tabs.create({
|
|
|
|
id: "workspace-tabs",
|
|
|
|
onchange: function(tab) {
|
|
|
|
var event = {
|
|
|
|
old: activeWorkspace
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
2015-05-26 22:52:23 +02:00
|
|
|
activeWorkspace = tab.id;
|
|
|
|
event.workspace = activeWorkspace;
|
2017-03-06 11:03:15 +01:00
|
|
|
// $("#workspace").toggleClass("workspace-disabled",tab.disabled);
|
2015-07-10 20:49:31 +02:00
|
|
|
RED.events.emit("workspace:change",event);
|
2016-09-24 23:57:41 +02:00
|
|
|
window.location.hash = 'flow/'+tab.id;
|
2015-10-16 22:56:20 +02:00
|
|
|
RED.sidebar.config.refresh();
|
2017-01-24 17:14:03 +01:00
|
|
|
RED.view.focus();
|
|
|
|
},
|
|
|
|
onclick: function(tab) {
|
|
|
|
RED.view.focus();
|
2015-03-13 00:38:37 +01:00
|
|
|
},
|
2015-05-26 22:52:23 +02:00
|
|
|
ondblclick: function(tab) {
|
|
|
|
if (tab.type != "subflow") {
|
|
|
|
showRenameWorkspaceDialog(tab.id);
|
|
|
|
} else {
|
|
|
|
RED.editor.editSubflow(RED.nodes.subflow(tab.id));
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
|
|
|
},
|
2015-05-26 22:52:23 +02:00
|
|
|
onadd: function(tab) {
|
2017-03-06 11:03:15 +01:00
|
|
|
$('<span class="workspace-disabled-icon"><i class="fa fa-ban"></i> </span>').prependTo("#red-ui-tab-"+(tab.id.replace(".","-"))+" .red-ui-tab-label");
|
|
|
|
if (tab.disabled) {
|
|
|
|
$("#red-ui-tab-"+(tab.id.replace(".","-"))).addClass('workspace-disabled');
|
|
|
|
}
|
2015-09-27 21:18:21 +02:00
|
|
|
RED.menu.setDisabled("menu-item-workspace-delete",workspace_tabs.count() == 1);
|
2015-05-26 22:52:23 +02:00
|
|
|
},
|
|
|
|
onremove: function(tab) {
|
2015-09-27 21:18:21 +02:00
|
|
|
RED.menu.setDisabled("menu-item-workspace-delete",workspace_tabs.count() == 1);
|
2015-07-03 19:31:37 +02:00
|
|
|
},
|
2016-05-04 16:22:30 +02:00
|
|
|
onreorder: function(oldOrder, newOrder) {
|
|
|
|
RED.history.push({t:'reorder',order:oldOrder,dirty:RED.nodes.dirty()});
|
|
|
|
RED.nodes.dirty(true);
|
|
|
|
setWorkspaceOrder(newOrder);
|
|
|
|
},
|
2016-09-26 23:56:28 +02:00
|
|
|
minimumActiveTabWidth: 150,
|
|
|
|
scrollable: true,
|
|
|
|
addButton: function() {
|
|
|
|
addWorkspace();
|
|
|
|
}
|
2015-05-26 22:52:23 +02:00
|
|
|
});
|
|
|
|
}
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2015-03-13 00:38:37 +01:00
|
|
|
function init() {
|
2015-05-26 22:52:23 +02:00
|
|
|
createWorkspaceTabs();
|
2015-07-10 20:49:31 +02:00
|
|
|
RED.events.on("sidebar:resize",workspace_tabs.resize);
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2016-12-04 23:59:43 +01:00
|
|
|
RED.actions.add("core:show-next-tab",workspace_tabs.nextTab);
|
|
|
|
RED.actions.add("core:show-previous-tab",workspace_tabs.previousTab);
|
|
|
|
|
2015-09-27 21:18:21 +02:00
|
|
|
RED.menu.setAction('menu-item-workspace-delete',function() {
|
2015-03-13 00:38:37 +01:00
|
|
|
deleteWorkspace(RED.nodes.workspace(activeWorkspace));
|
|
|
|
});
|
2015-07-14 00:21:03 +02:00
|
|
|
|
|
|
|
$(window).resize(function() {
|
|
|
|
workspace_tabs.resize();
|
|
|
|
});
|
2016-12-04 23:59:43 +01:00
|
|
|
|
|
|
|
RED.actions.add("core:add-flow",addWorkspace);
|
|
|
|
RED.actions.add("core:edit-flow",editWorkspace);
|
|
|
|
RED.actions.add("core:remove-flow",removeWorkspace);
|
|
|
|
}
|
|
|
|
|
|
|
|
function editWorkspace(id) {
|
|
|
|
showRenameWorkspaceDialog(id||activeWorkspace);
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
2015-07-01 00:42:03 +02:00
|
|
|
|
2015-03-13 00:38:37 +01:00
|
|
|
function removeWorkspace(ws) {
|
|
|
|
if (!ws) {
|
|
|
|
deleteWorkspace(RED.nodes.workspace(activeWorkspace));
|
|
|
|
} else {
|
|
|
|
if (workspace_tabs.contains(ws.id)) {
|
|
|
|
workspace_tabs.removeTab(ws.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-23 23:49:48 +02:00
|
|
|
|
2016-05-04 16:22:30 +02:00
|
|
|
function setWorkspaceOrder(order) {
|
|
|
|
RED.nodes.setWorkspaceOrder(order.filter(function(id) {
|
|
|
|
return RED.nodes.workspace(id) !== undefined;
|
|
|
|
}));
|
|
|
|
workspace_tabs.order(order);
|
|
|
|
}
|
|
|
|
|
2015-03-13 00:38:37 +01:00
|
|
|
return {
|
|
|
|
init: init,
|
|
|
|
add: addWorkspace,
|
|
|
|
remove: removeWorkspace,
|
2016-05-04 16:22:30 +02:00
|
|
|
order: setWorkspaceOrder,
|
2016-12-04 23:59:43 +01:00
|
|
|
edit: editWorkspace,
|
2015-03-13 00:38:37 +01:00
|
|
|
contains: function(id) {
|
|
|
|
return workspace_tabs.contains(id);
|
|
|
|
},
|
|
|
|
count: function() {
|
|
|
|
return workspace_tabs.count();
|
|
|
|
},
|
|
|
|
active: function() {
|
|
|
|
return activeWorkspace
|
|
|
|
},
|
|
|
|
show: function(id) {
|
|
|
|
if (!workspace_tabs.contains(id)) {
|
|
|
|
var sf = RED.nodes.subflow(id);
|
|
|
|
if (sf) {
|
2015-07-30 12:03:37 +02:00
|
|
|
addWorkspace({type:"subflow",id:id,icon:"red/images/subflow_tab.png",label:sf.name, closeable: true});
|
2016-09-24 23:57:41 +02:00
|
|
|
} else {
|
|
|
|
return;
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
2015-07-01 00:42:03 +02:00
|
|
|
}
|
2015-03-13 00:38:37 +01:00
|
|
|
workspace_tabs.activateTab(id);
|
|
|
|
},
|
|
|
|
refresh: function() {
|
2016-06-01 00:20:25 +02:00
|
|
|
RED.nodes.eachWorkspace(function(ws) {
|
|
|
|
workspace_tabs.renameTab(ws.id,ws.label);
|
|
|
|
|
|
|
|
})
|
2015-03-13 00:38:37 +01:00
|
|
|
RED.nodes.eachSubflow(function(sf) {
|
|
|
|
if (workspace_tabs.contains(sf.id)) {
|
2015-07-30 12:03:37 +02:00
|
|
|
workspace_tabs.renameTab(sf.id,sf.name);
|
2015-03-13 00:38:37 +01:00
|
|
|
}
|
|
|
|
});
|
2015-10-16 22:56:20 +02:00
|
|
|
RED.sidebar.config.refresh();
|
2015-03-13 00:38:37 +01:00
|
|
|
},
|
|
|
|
resize: function() {
|
|
|
|
workspace_tabs.resize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|