2017-04-25 14:43:59 +02:00
|
|
|
/**
|
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
|
|
|
*
|
|
|
|
* 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.userSettings = (function() {
|
|
|
|
|
2017-04-28 21:49:01 +02:00
|
|
|
var trayWidth = 700;
|
2017-04-25 14:43:59 +02:00
|
|
|
var settingsVisible = false;
|
|
|
|
|
2017-04-30 00:10:55 +02:00
|
|
|
var panes = [];
|
|
|
|
|
|
|
|
function addPane(options) {
|
|
|
|
panes.push(options);
|
|
|
|
}
|
|
|
|
|
2017-04-28 21:49:01 +02:00
|
|
|
function show(initialTab) {
|
2017-04-25 14:43:59 +02:00
|
|
|
if (settingsVisible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
settingsVisible = true;
|
2017-04-28 21:49:01 +02:00
|
|
|
var tabContainer;
|
2017-04-25 14:43:59 +02:00
|
|
|
|
|
|
|
var trayOptions = {
|
2017-08-07 11:00:28 +02:00
|
|
|
title: RED._("menu.label.userSettings"),
|
2017-04-25 14:43:59 +02:00
|
|
|
buttons: [
|
|
|
|
{
|
|
|
|
id: "node-dialog-ok",
|
|
|
|
text: RED._("common.label.close"),
|
|
|
|
class: "primary",
|
|
|
|
click: function() {
|
|
|
|
RED.tray.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
resize: function(dimensions) {
|
|
|
|
trayWidth = dimensions.width;
|
|
|
|
},
|
|
|
|
open: function(tray) {
|
|
|
|
var trayBody = tray.find('.editor-tray-body');
|
2017-04-30 00:10:55 +02:00
|
|
|
var settingsContent = $('<div></div>').appendTo(trayBody);
|
|
|
|
var tabContainer = $('<div></div>',{id:"user-settings-tabs-container"}).appendTo(settingsContent);
|
2017-04-25 14:43:59 +02:00
|
|
|
|
2017-04-28 21:49:01 +02:00
|
|
|
$('<ul></ul>',{id:"user-settings-tabs"}).appendTo(tabContainer);
|
2017-04-30 00:10:55 +02:00
|
|
|
var settingsTabs = RED.tabs.create({
|
2017-04-25 14:43:59 +02:00
|
|
|
id: "user-settings-tabs",
|
2017-04-28 21:49:01 +02:00
|
|
|
vertical: true,
|
2017-04-25 14:43:59 +02:00
|
|
|
onchange: function(tab) {
|
2017-04-30 00:10:55 +02:00
|
|
|
setTimeout(function() {
|
|
|
|
$("#user-settings-tabs-content").children().hide();
|
|
|
|
$("#" + tab.id).show();
|
2017-05-03 12:37:42 +02:00
|
|
|
if (tab.pane.focus) {
|
|
|
|
tab.pane.focus();
|
|
|
|
}
|
2017-04-30 00:10:55 +02:00
|
|
|
},50);
|
2017-04-25 14:43:59 +02:00
|
|
|
}
|
|
|
|
});
|
2017-04-30 00:10:55 +02:00
|
|
|
var tabContents = $('<div></div>',{id:"user-settings-tabs-content"}).appendTo(settingsContent);
|
|
|
|
|
|
|
|
panes.forEach(function(pane) {
|
|
|
|
settingsTabs.addTab({
|
|
|
|
id: "user-settings-tab-"+pane.id,
|
2017-05-03 12:37:42 +02:00
|
|
|
label: pane.title,
|
|
|
|
pane: pane
|
2017-04-30 00:10:55 +02:00
|
|
|
});
|
|
|
|
pane.get().hide().appendTo(tabContents);
|
2017-04-25 14:43:59 +02:00
|
|
|
});
|
2017-04-30 00:10:55 +02:00
|
|
|
settingsContent.i18n();
|
|
|
|
settingsTabs.activateTab("user-settings-tab-"+(initialTab||'view'))
|
2017-05-03 12:37:42 +02:00
|
|
|
$("#sidebar-shade").show();
|
2017-04-25 14:43:59 +02:00
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
settingsVisible = false;
|
2017-04-30 00:10:55 +02:00
|
|
|
panes.forEach(function(pane) {
|
|
|
|
if (pane.close) {
|
|
|
|
pane.close();
|
|
|
|
}
|
|
|
|
});
|
2017-05-03 12:37:42 +02:00
|
|
|
$("#sidebar-shade").hide();
|
|
|
|
|
2017-04-25 14:43:59 +02:00
|
|
|
},
|
|
|
|
show: function() {}
|
|
|
|
}
|
|
|
|
if (trayWidth !== null) {
|
|
|
|
trayOptions.width = trayWidth;
|
|
|
|
}
|
|
|
|
RED.tray.show(trayOptions);
|
|
|
|
}
|
|
|
|
|
2017-04-28 21:49:01 +02:00
|
|
|
var viewSettings = [
|
|
|
|
{
|
2017-08-07 11:00:28 +02:00
|
|
|
title: "menu.label.view.grid",
|
2017-04-28 21:49:01 +02:00
|
|
|
options: [
|
2017-06-28 23:15:30 +02:00
|
|
|
{setting:"view-show-grid",oldSetting:"menu-menu-item-view-show-grid",label:"menu.label.view.showGrid",toggle:true,onchange:"core:toggle-show-grid"},
|
|
|
|
{setting:"view-snap-grid",oldSetting:"menu-menu-item-view-snap-grid",label:"menu.label.view.snapGrid",toggle:true,onchange:"core:toggle-snap-grid"},
|
2017-04-28 21:49:01 +02:00
|
|
|
{setting:"view-grid-size",label:"menu.label.view.gridSize",type:"number",default: 20, onchange:RED.view.gridSize}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2017-08-07 11:00:28 +02:00
|
|
|
title: "menu.label.nodes",
|
2017-04-28 21:49:01 +02:00
|
|
|
options: [
|
2017-06-28 23:15:30 +02:00
|
|
|
{setting:"view-node-status",oldSetting:"menu-menu-item-status",label:"menu.label.displayStatus",default: true, toggle:true,onchange:"core:toggle-status"}
|
2017-04-28 21:49:01 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2017-08-07 11:00:28 +02:00
|
|
|
title: "menu.label.other",
|
2017-04-28 21:49:01 +02:00
|
|
|
options: [
|
2017-06-28 23:15:30 +02:00
|
|
|
{setting:"view-show-tips",oldSettings:"menu-menu-item-show-tips",label:"menu.label.showTips",toggle:true,default:true,onchange:"core:toggle-show-tips"}
|
2017-04-28 21:49:01 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var allSettings = {};
|
|
|
|
|
|
|
|
function createViewPane() {
|
|
|
|
|
|
|
|
var pane = $('<div id="user-settings-tab-view" class="node-help"></div>');
|
|
|
|
|
|
|
|
viewSettings.forEach(function(section) {
|
2017-08-07 11:00:28 +02:00
|
|
|
$('<h3></h3>').text(RED._(section.title)).appendTo(pane);
|
2017-04-28 21:49:01 +02:00
|
|
|
section.options.forEach(function(opt) {
|
|
|
|
var initialState = RED.settings.get(opt.setting);
|
|
|
|
var row = $('<div class="user-settings-row"></div>').appendTo(pane);
|
|
|
|
var input;
|
|
|
|
if (opt.toggle) {
|
|
|
|
input = $('<label for="user-settings-'+opt.setting+'"><input id="user-settings-'+opt.setting+'" type="checkbox"> '+RED._(opt.label)+'</label>').appendTo(row).find("input");
|
|
|
|
input.prop('checked',initialState);
|
|
|
|
} else {
|
|
|
|
$('<label for="user-settings-'+opt.setting+'">'+RED._(opt.label)+'</label>').appendTo(row);
|
|
|
|
$('<input id="user-settings-'+opt.setting+'" type="'+(opt.type||"text")+'">').appendTo(row).val(initialState);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
return pane;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSelected(id, value) {
|
|
|
|
var opt = allSettings[id];
|
|
|
|
RED.settings.set(opt.setting,value);
|
|
|
|
var callback = opt.onchange;
|
|
|
|
if (typeof callback === 'string') {
|
|
|
|
callback = RED.actions.get(callback);
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
callback.call(opt,value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function toggle(id) {
|
|
|
|
var opt = allSettings[id];
|
|
|
|
var state = RED.settings.get(opt.setting);
|
|
|
|
setSelected(id,!state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-25 14:43:59 +02:00
|
|
|
function init() {
|
|
|
|
RED.actions.add("core:show-user-settings",show);
|
2017-04-28 21:49:01 +02:00
|
|
|
RED.actions.add("core:show-help", function() { show('keyboard')});
|
|
|
|
|
2017-04-30 00:10:55 +02:00
|
|
|
addPane({
|
|
|
|
id:'view',
|
2017-08-07 11:00:28 +02:00
|
|
|
title: RED._("menu.label.view.view"),
|
2017-04-30 00:10:55 +02:00
|
|
|
get: createViewPane,
|
|
|
|
close: function() {
|
|
|
|
viewSettings.forEach(function(section) {
|
|
|
|
section.options.forEach(function(opt) {
|
|
|
|
var input = $("#user-settings-"+opt.setting);
|
|
|
|
if (opt.toggle) {
|
|
|
|
setSelected(opt.setting,input.prop('checked'));
|
|
|
|
} else {
|
|
|
|
setSelected(opt.setting,input.val());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-04-28 21:49:01 +02:00
|
|
|
viewSettings.forEach(function(section) {
|
|
|
|
section.options.forEach(function(opt) {
|
2017-06-28 23:15:30 +02:00
|
|
|
if (opt.oldSetting) {
|
|
|
|
var oldValue = RED.settings.get(opt.oldSetting);
|
|
|
|
if (oldValue !== undefined && oldValue !== null) {
|
|
|
|
RED.settings.set(opt.setting,oldValue);
|
|
|
|
RED.settings.remove(opt.oldSetting);
|
|
|
|
}
|
|
|
|
}
|
2017-04-28 21:49:01 +02:00
|
|
|
allSettings[opt.setting] = opt;
|
|
|
|
if (opt.onchange) {
|
|
|
|
var value = RED.settings.get(opt.setting);
|
|
|
|
if (value === null && opt.hasOwnProperty('default')) {
|
|
|
|
value = opt.default;
|
|
|
|
RED.settings.set(opt.setting,value);
|
|
|
|
}
|
|
|
|
|
|
|
|
var callback = opt.onchange;
|
|
|
|
if (typeof callback === 'string') {
|
|
|
|
callback = RED.actions.get(callback);
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
callback.call(opt,value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-25 14:43:59 +02:00
|
|
|
}
|
|
|
|
return {
|
2017-04-28 21:49:01 +02:00
|
|
|
init: init,
|
2017-04-30 00:10:55 +02:00
|
|
|
toggle: toggle,
|
|
|
|
show: show,
|
|
|
|
add: addPane
|
2017-04-25 14:43:59 +02:00
|
|
|
};
|
|
|
|
})();
|