2013-10-13 21:28:21 +02:00
<!--
2017-01-11 16:24:33 +01:00
Copyright JS Foundation and other contributors, http://js.foundation
2013-10-13 21:28:21 +02: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.
-->
2020-01-01 22:32:56 +01:00
< script type = "text/html" data-template-name = "switch" >
2013-10-13 21:28:21 +02:00
< div class = "form-row" >
2015-05-10 22:47:22 +02:00
< label for = "node-input-name" > < i class = "fa fa-tag" > < / i > < span data-i18n = "common.label.name" > < / span > < / label >
2021-10-05 11:34:46 +02:00
< input type = "text" id = "node-input-name" style = "width: calc(100% - 105px)" data-i18n = "[placeholder]common.label.name" >
2013-10-13 21:28:21 +02:00
< / div >
2014-11-13 18:21:12 +01:00
< div class = "form-row" >
2018-11-11 19:44:25 +01:00
< label for = "node-input-property" > < i class = "fa fa-ellipsis-h" > < / i > < span data-i18n = "switch.label.property" > < / span > < / label >
2021-10-05 11:34:46 +02:00
< input type = "text" id = "node-input-property" style = "width: calc(100% - 105px)" / >
2017-02-07 23:30:54 +01:00
< input type = "hidden" id = "node-input-outputs" / >
2013-10-13 21:28:21 +02:00
< / div >
2016-05-20 23:13:28 +02:00
< div class = "form-row node-input-rule-container-row" >
< ol id = "node-input-rule-container" > < / ol >
2014-11-13 18:21:12 +01:00
< / div >
< div class = "form-row" >
2013-11-22 17:24:22 +01:00
< select id = "node-input-checkall" style = "width:100%; margin-right:5px;" >
2015-05-10 22:47:22 +02:00
< option value = "true" data-i18n = "switch.checkall" > < / option >
< option value = "false" data-i18n = "switch.stopfirst" > < / option >
2013-11-22 17:24:22 +01:00
< / select >
< / div >
2018-01-17 11:08:58 +01:00
< div class = "form-row" >
< input type = "checkbox" id = "node-input-repair" style = "display: inline-block; width: auto; vertical-align: top;" >
< label style = "width: auto;" for = "node-input-repair" > < span data-i18n = "switch.label.repair" > < / span > < / label > < / input >
< / div >
2013-10-13 21:28:21 +02:00
< / script >
< script type = "text/javascript" >
2017-01-27 19:11:25 +01:00
(function() {
var operators = [
2018-01-17 11:08:58 +01:00
{v:"eq",t:"==",kind:'V'},
{v:"neq",t:"!=",kind:'V'},
{v:"lt",t:"< ",kind:'V'},
{v:"lte",t:"< =",kind:'V'},
{v:"gt",t:">",kind:'V'},
{v:"gte",t:">=",kind:'V'},
2019-07-09 22:04:53 +02:00
{v:"hask",t:"switch.rules.hask",kind:'V'},
2018-01-17 11:08:58 +01:00
{v:"btwn",t:"switch.rules.btwn",kind:'V'},
{v:"cont",t:"switch.rules.cont",kind:'V'},
{v:"regex",t:"switch.rules.regex",kind:'V'},
{v:"true",t:"switch.rules.true",kind:'V'},
{v:"false",t:"switch.rules.false",kind:'V'},
{v:"null",t:"switch.rules.null",kind:'V'},
{v:"nnull",t:"switch.rules.nnull",kind:'V'},
2018-05-03 12:24:44 +02:00
{v:"istype",t:"switch.rules.istype",kind:'V'},
2018-07-11 17:14:09 +02:00
{v:"empty",t:"switch.rules.empty",kind:'V'},
{v:"nempty",t:"switch.rules.nempty",kind:'V'},
2018-01-17 11:08:58 +01:00
{v:"head",t:"switch.rules.head",kind:'S'},
{v:"index",t:"switch.rules.index",kind:'S'},
{v:"tail",t:"switch.rules.tail",kind:'S'},
{v:"jsonata_exp",t:"switch.rules.exp",kind:'O'},
{v:"else",t:"switch.rules.else",kind:'O'}
2017-01-27 19:11:25 +01:00
];
2021-10-05 11:34:46 +02:00
var previousValueType = {value:"prev",label:RED._("node-red:switch.previous"),hasValue:false};
2017-01-27 19:11:25 +01:00
function clipValueLength(v) {
if (v.length > 15) {
return v.substring(0,15)+"...";
}
return v;
}
2018-07-10 13:40:52 +02:00
function prop2name(key) {
var result = RED.utils.parseContextKey(key);
return result.key;
}
2017-01-27 19:11:25 +01:00
function getValueLabel(t,v) {
if (t === 'str') {
return '"'+clipValueLength(v)+'"';
2018-07-10 13:40:52 +02:00
} else if (t === 'msg') {
2017-01-27 19:11:25 +01:00
return t+"."+clipValueLength(v);
2018-07-10 13:40:52 +02:00
} else if (t === 'flow' || t === 'global') {
return t+"."+clipValueLength(prop2name(v));
2017-01-27 19:11:25 +01:00
}
return clipValueLength(v);
}
2021-10-05 11:34:46 +02:00
function exportRule(rule) {
var type = rule.find("select").val();
var r = {t:type};
if (!(type === "true" || type === "false" || type === "null" || type === "nnull" || type === "empty" || type === "nempty" || type === "else")) {
if ((type === "btwn") || (type === "index")) {
r.v = rule.find(".node-input-rule-btwn-value").typedInput('value');
r.vt = rule.find(".node-input-rule-btwn-value").typedInput('type');
r.v2 = rule.find(".node-input-rule-btwn-value2").typedInput('value');
r.v2t = rule.find(".node-input-rule-btwn-value2").typedInput('type');
} else if ((type === "head") || (type === "tail")) {
r.v = rule.find(".node-input-rule-num-value").typedInput('value');
r.vt = rule.find(".node-input-rule-num-value").typedInput('type');
} else if (type === "istype") {
r.v = rule.find(".node-input-rule-type-value").typedInput('type');
r.vt = rule.find(".node-input-rule-type-value").typedInput('type');
} else if (type === "jsonata_exp") {
r.v = rule.find(".node-input-rule-exp-value").typedInput('value');
r.vt = rule.find(".node-input-rule-exp-value").typedInput('type');
} else {
r.v = rule.find(".node-input-rule-value").typedInput('value');
r.vt = rule.find(".node-input-rule-value").typedInput('type');
}
if (type === "regex") {
r.case = rule.find(".node-input-rule-case").prop("checked");
}
}
return r;
}
2021-10-19 11:12:13 +02:00
function createValueField(row, defaultType){
return $('< input / > ',{class:"node-input-rule-value",type:"text",style:"width: 100%;"}).appendTo(row)
.typedInput({default:defaultType||'str',types:['msg','flow','global','str','num','jsonata','env',previousValueType]});
2021-10-05 11:34:46 +02:00
}
2021-10-19 11:12:13 +02:00
function createNumValueField(row, defaultType){
return $('< input / > ',{class:"node-input-rule-num-value",type:"text",style:"width: 100%;"}).appendTo(row)
.typedInput({default:defaultType||'num',types:['flow','global','num','jsonata','env']});
2021-10-05 11:34:46 +02:00
}
function createExpValueField(row){
2021-10-19 11:12:13 +02:00
return $('< input / > ',{class:"node-input-rule-exp-value",type:"text",style:"width: 100%;"}).appendTo(row)
.typedInput({default:'jsonata',types:['jsonata']});
2021-10-05 11:34:46 +02:00
}
2021-10-19 11:12:13 +02:00
function createBtwnValueField(row, defaultType){
return $('< input / > ',{class:"node-input-rule-btwn-value",type:"text",style:"width: 100%;"}).appendTo(row)
.typedInput({default:defaultType||'num',types:['msg','flow','global','str','num','jsonata','env',previousValueType]});
2021-10-05 11:34:46 +02:00
}
2021-10-19 11:12:13 +02:00
function createBtwnValue2Field(row3, andLabel, defaultType){
2021-10-05 11:34:46 +02:00
$('< div / > ',{class:"node-input-rule-btwn-label", style:"width: 120px; text-align: right;"}).text(" "+andLabel+" ").appendTo(row3);
var row3InputCell = $('< div / > ',{style:"flex-grow:1; margin-left: 5px;"}).appendTo(row3);
2021-10-19 11:12:13 +02:00
return $('< input / > ',{class:"node-input-rule-btwn-value2",type:"text",style:"width: 100%"}).appendTo(row3InputCell)
.typedInput({default:defaultType||'num',types:['msg','flow','global','str','num','jsonata','env',previousValueType]});
2021-10-05 11:34:46 +02:00
}
2021-10-19 11:12:13 +02:00
function createTypeValueField(row, defaultType){
return $('< input / > ',{class:"node-input-rule-type-value",type:"text",style:"width: 100%;"}).appendTo(row).typedInput({default:defaultType || 'string',types:[
2022-05-05 13:38:55 +02:00
{value:"string",label:RED._("common.type.string"),hasValue:false,icon:"red/images/typedInput/az.svg"},
{value:"number",label:RED._("common.type.number"),hasValue:false,icon:"red/images/typedInput/09.svg"},
{value:"boolean",label:RED._("common.type.boolean"),hasValue:false,icon:"red/images/typedInput/bool.svg"},
{value:"array",label:RED._("common.type.array"),hasValue:false,icon:"red/images/typedInput/json.svg"},
{value:"buffer",label:RED._("common.type.buffer"),hasValue:false,icon:"red/images/typedInput/bin.svg"},
{value:"object",label:RED._("common.type.object"),hasValue:false,icon:"red/images/typedInput/json.svg"},
{value:"json",label:RED._("common.type.jsonString"),hasValue:false,icon:"red/images/typedInput/json.svg"},
2021-10-05 11:34:46 +02:00
{value:"undefined",label:RED._("common.type.undefined"),hasValue:false},
{value:"null",label:RED._("common.type.null"),hasValue:false}
]});
}
2013-11-22 17:24:22 +01:00
RED.nodes.registerType('switch', {
color: "#E2D96E",
2013-10-13 21:28:21 +02:00
category: 'function',
defaults: {
name: {value:""},
2022-02-14 02:40:49 +01:00
property: {value:"payload", required:true,
label:RED._("node-red:common.label.payload"),
2022-04-12 01:09:46 +02:00
validate: RED.validators.typedInput("propertyType", false)},
2015-12-31 00:09:35 +01:00
propertyType: { value:"msg" },
2017-06-30 00:22:31 +02:00
rules: {value:[{t:"eq", v:"", vt:"str"}]},
2013-11-22 17:24:22 +01:00
checkall: {value:"true", required:true},
2018-01-17 11:08:58 +01:00
repair: {value:false},
2013-11-22 17:24:22 +01:00
outputs: {value:1}
2013-10-13 21:28:21 +02:00
},
2013-11-22 17:24:22 +01:00
inputs: 1,
outputs: 1,
2017-01-27 19:11:25 +01:00
outputLabels: function(index) {
var rule = this.rules[index];
var label = "";
if (rule) {
for (var i=0;i< operators.length ; i + + ) {
if (operators[i].v === rule.t) {
2017-06-27 18:16:18 +02:00
label = /^switch/.test(operators[i].t)?this._(operators[i].t):operators[i].t;
2017-01-27 19:11:25 +01:00
break;
}
}
2018-01-17 11:08:58 +01:00
if ((rule.t === 'btwn') || (rule.t === 'index')) {
2017-01-27 19:11:25 +01:00
label += " "+getValueLabel(rule.vt,rule.v)+" & "+getValueLabel(rule.v2t,rule.v2);
2018-07-20 09:53:30 +02:00
} else if (rule.t !== 'true' & & rule.t !== 'false' & & rule.t !== 'null' & & rule.t !== 'nnull' & & rule.t !== 'empty' & & rule.t !== 'nempty' & & rule.t !== 'else' ) {
2017-01-27 19:11:25 +01:00
label += " "+getValueLabel(rule.vt,rule.v);
}
return label;
}
},
2019-06-21 13:36:20 +02:00
icon: "switch.svg",
2013-10-13 21:28:21 +02:00
label: function() {
2018-04-16 12:12:21 +02:00
return this.name||this._("switch.switch");
2013-10-13 21:28:21 +02:00
},
2017-12-06 23:47:13 +01:00
labelStyle: function() {
return this.name?"node_label_italic":"";
},
2013-10-13 21:28:21 +02:00
oneditprepare: function() {
2016-01-04 17:53:32 +01:00
var node = this;
2021-10-05 11:34:46 +02:00
2016-01-15 12:35:59 +01:00
2019-06-07 14:35:36 +02:00
$("#node-input-property").typedInput({default:this.propertyType||'msg',types:['msg','flow','global','jsonata','env']});
2017-02-07 23:30:54 +01:00
var outputCount = $("#node-input-outputs").val("{}");
2013-11-22 17:24:22 +01:00
2015-10-04 23:14:49 +02:00
var andLabel = this._("switch.and");
var caseLabel = this._("switch.ignorecase");
2020-01-01 22:32:56 +01:00
$("#node-input-rule-container").css('min-height','150px').css('min-width','450px').editableList({
2016-05-20 23:13:28 +02:00
addItem: function(container,i,opt) {
2021-10-05 11:34:46 +02:00
var focusValueField = false;
2016-11-08 18:00:47 +01:00
if (!opt.hasOwnProperty('r')) {
opt.r = {};
2021-10-05 11:34:46 +02:00
if (i > 0) {
var lastRule = $("#node-input-rule-container").editableList('getItemAt',i-1);
var exportedRule = exportRule(lastRule.element);
opt.r.vt = exportedRule.vt;
2021-10-14 22:47:49 +02:00
opt.r.v = "";
2021-10-05 11:34:46 +02:00
// We could copy the value over as well and preselect it (see the 'activeElement' code below)
// But not sure that feels right. Is copying over the last value 'expected' behaviour?
// It would make sense for an explicit 'copy' action, but not sure where the copy button would
// go for each rule without being wasted space for most users.
// opt.r.v = exportedRule.v;
focusValueField = true;
}
2016-11-08 18:00:47 +01:00
}
2021-10-05 11:34:46 +02:00
opt.element = container;
2016-11-08 18:00:47 +01:00
var rule = opt.r;
2016-07-04 12:21:58 +02:00
if (!rule.hasOwnProperty('t')) {
rule.t = 'eq';
}
2017-02-07 23:30:54 +01:00
if (!opt.hasOwnProperty('i')) {
2018-03-20 21:37:29 +01:00
opt._i = Math.floor((0x99999-0x10000)*Math.random()).toString();
2017-02-07 23:30:54 +01:00
}
2018-01-25 15:02:04 +01:00
container.css({
overflow: 'hidden',
2021-10-05 11:34:46 +02:00
whiteSpace: 'nowrap',
display: "flex",
"align-items":"center"
2018-01-25 15:02:04 +01:00
});
2021-10-05 11:34:46 +02:00
var inputRows = $('< div > < / div > ',{style:"flex-grow:1"}).appendTo(container);
var row = $('< div > < / div > ',{style:"display: flex;"}).appendTo(inputRows);
var row2 = $('< div / > ',{style:"display: flex; padding-top: 5px; padding-left: 175px;"}).appendTo(inputRows);
var row3 = $('< div / > ',{style:"display: flex; padding-top: 5px; align-items: center"}).appendTo(inputRows);
2022-05-08 05:32:07 +02:00
var row4 = $('< div / > ',{style:"visibility: hidden; height: 0px;"}).appendTo(inputRows);
var textSpan = $("< span / > ").appendTo(row4);
2021-10-05 11:34:46 +02:00
var selectField = $('< select / > ',{style:"width:120px; text-align: center;"}).appendTo(row);
2018-01-17 11:08:58 +01:00
var group0 = $('< optgroup / > ', { label: "value rules" }).appendTo(selectField);
2016-05-20 23:13:28 +02:00
for (var d in operators) {
2018-01-17 11:08:58 +01:00
if(operators[d].kind === 'V') {
group0.append($("< option > < / option > ").val(operators[d].v).text(/^switch/.test(operators[d].t)?node._(operators[d].t):operators[d].t));
}
}
var group1 = $('< optgroup / > ', { label: "sequence rules" }).appendTo(selectField);
for (var d in operators) {
if(operators[d].kind === 'S') {
group1.append($("< option > < / option > ").val(operators[d].v).text(/^switch/.test(operators[d].t)?node._(operators[d].t):operators[d].t));
}
}
for (var d in operators) {
if(operators[d].kind === 'O') {
selectField.append($("< option > < / option > ").val(operators[d].v).text(/^switch/.test(operators[d].t)?node._(operators[d].t):operators[d].t));
}
2016-05-20 23:13:28 +02:00
}
2019-08-07 02:23:57 +02:00
2021-10-05 11:34:46 +02:00
var rowInputCell = $('< div > ',{style:"flex-grow:1; margin-left: 5px;"}).appendTo(row);
2019-08-07 02:23:57 +02:00
var valueField = null;
var numValueField = null;
var expValueField = null;
var btwnAndLabel = null;
2019-08-21 13:39:51 +02:00
var btwnValueField = null;
2019-08-07 02:23:57 +02:00
var btwnValue2Field = null;
var typeValueField = null;
2019-08-21 13:39:51 +02:00
2021-10-05 11:34:46 +02:00
var finalspan = $('< span / > ',{style:"margin-left: 5px;"}).appendTo(container);
2016-05-20 23:13:28 +02:00
finalspan.append(' → < span class = "node-input-rule-index" > '+(i+1)+'< / span > ');
2021-10-05 11:34:46 +02:00
2016-05-20 23:13:28 +02:00
var caseSensitive = $('< input / > ',{id:"node-input-rule-case-"+i,class:"node-input-rule-case",type:"checkbox",style:"width:auto;vertical-align:top"}).appendTo(row2);
$('< label / > ',{for:"node-input-rule-case-"+i,style:"margin-left: 3px;"}).text(caseLabel).appendTo(row2);
2021-10-05 11:34:46 +02:00
2019-04-29 12:50:15 +02:00
selectField.on("change", function() {
2021-10-05 11:34:46 +02:00
var fieldToFocus;
2016-07-04 12:21:58 +02:00
var type = selectField.val();
2021-10-19 11:12:13 +02:00
if (valueField) { valueField.typedInput('hide'); }
if (expValueField) { expValueField.typedInput('hide'); }
if (numValueField) { numValueField.typedInput('hide'); }
if (typeValueField) { typeValueField.typedInput('hide'); }
if (btwnValueField) { btwnValueField.typedInput('hide'); }
if (btwnValue2Field) { btwnValue2Field.typedInput('hide'); }
2019-08-21 13:39:51 +02:00
2019-08-07 02:23:57 +02:00
if ((type === "btwn") || (type === "index")) {
if (!btwnValueField){
2021-10-05 11:34:46 +02:00
btwnValueField = createBtwnValueField(rowInputCell);
2019-08-07 02:23:57 +02:00
}
2016-06-27 00:48:59 +02:00
btwnValueField.typedInput('show');
2021-10-05 11:34:46 +02:00
fieldToFocus = btwnValueField;
2018-01-17 11:08:58 +01:00
} else if ((type === "head") || (type === "tail")) {
2019-08-07 02:23:57 +02:00
if (!numValueField){
2021-10-05 11:34:46 +02:00
numValueField = createNumValueField(rowInputCell);
2019-08-07 02:23:57 +02:00
}
2018-01-17 11:08:58 +01:00
numValueField.typedInput('show');
2021-10-05 11:34:46 +02:00
fieldToFocus = numValueField;
2018-01-17 11:08:58 +01:00
} else if (type === "jsonata_exp") {
2019-08-07 02:23:57 +02:00
if (!expValueField){
2021-10-05 11:34:46 +02:00
expValueField = createExpValueField(rowInputCell);
2019-08-07 02:23:57 +02:00
}
2018-01-17 11:08:58 +01:00
expValueField.typedInput('show');
2021-10-05 11:34:46 +02:00
fieldToFocus = expValueField;
2019-08-21 13:39:51 +02:00
} else if (type === "istype") {
if (!typeValueField){
2021-10-19 11:12:13 +02:00
typeValueField = createTypeValueField(rowInputCell);
2018-05-03 12:24:44 +02:00
}
2019-08-21 13:39:51 +02:00
typeValueField.typedInput('show');
2021-10-05 11:34:46 +02:00
fieldToFocus = typeValueField;
2019-08-21 13:39:51 +02:00
} else if (! (type === "true" || type === "false" || type === "null" || type === "nnull" || type === "empty" || type === "nempty" || type === "else" )) {
2019-08-07 02:23:57 +02:00
if (!valueField){
2021-10-05 11:34:46 +02:00
valueField = createValueField(rowInputCell);
2019-08-07 02:23:57 +02:00
}
2016-06-27 00:48:59 +02:00
valueField.typedInput('show');
2021-10-05 11:34:46 +02:00
fieldToFocus = valueField;
2016-05-20 23:13:28 +02:00
}
if (type === "regex") {
row2.show();
row3.hide();
2018-01-17 11:08:58 +01:00
} else if ((type === "btwn") || (type === "index")) {
2016-05-20 23:13:28 +02:00
row2.hide();
row3.show();
2019-08-07 02:23:57 +02:00
if (!btwnValue2Field){
2021-10-05 11:34:46 +02:00
btwnValue2Field = createBtwnValue2Field(row3, andLabel);
2019-08-07 02:23:57 +02:00
}
2017-09-17 09:46:47 +02:00
btwnValue2Field.typedInput('show');
2013-10-13 21:28:21 +02:00
} else {
2016-05-20 23:13:28 +02:00
row2.hide();
row3.hide();
2013-10-13 21:28:21 +02:00
}
2021-10-05 11:34:46 +02:00
var selectedLabel = selectField.find("option:selected").text();
2022-05-08 05:32:07 +02:00
textSpan.text(selectedLabel);
var width = textSpan.width();
if (width < = 30) {
2021-10-05 11:34:46 +02:00
selectField.outerWidth(60);
2022-05-08 05:32:07 +02:00
} else if (width < = 85) {
2021-10-05 11:34:46 +02:00
selectField.outerWidth(120);
} else {
selectField.width("auto")
}
2021-10-12 18:18:02 +02:00
if (fieldToFocus) {
fieldToFocus.typedInput("focus");
}
2021-10-05 11:34:46 +02:00
// Preselect the contents of the element
// if (focusValueField & & document.activeElement) {
// document.activeElement.selectionStart = 0;
// document.activeElement.selectionEnd = document.activeElement.value.length;
// }
2016-05-20 23:13:28 +02:00
});
2016-07-04 12:21:58 +02:00
selectField.val(rule.t);
2021-10-19 11:12:13 +02:00
2018-01-17 11:08:58 +01:00
if ((rule.t == "btwn") || (rule.t == "index")) {
2021-10-19 11:12:13 +02:00
btwnValueField = createBtwnValueField(rowInputCell,rule.vt||'num');
2016-05-20 23:13:28 +02:00
btwnValueField.typedInput('value',rule.v);
2021-10-19 11:12:13 +02:00
btwnValue2Field = createBtwnValue2Field(row3, andLabel,rule.v2t||'num');
2016-05-20 23:13:28 +02:00
btwnValue2Field.typedInput('value',rule.v2);
2018-01-17 11:08:58 +01:00
} else if ((rule.t === "head") || (rule.t === "tail")) {
2021-10-19 11:12:13 +02:00
numValueField = createNumValueField(rowInputCell,rule.vt||'num');
2018-01-17 11:08:58 +01:00
numValueField.typedInput('value',rule.v);
2018-05-03 12:24:44 +02:00
} else if (rule.t === "istype") {
2021-10-19 11:12:13 +02:00
typeValueField = createTypeValueField(rowInputCell,rule.vt);
2018-05-03 12:24:44 +02:00
typeValueField.typedInput('value',rule.vt);
2018-01-17 11:08:58 +01:00
} else if (rule.t === "jsonata_exp") {
2021-10-19 11:12:13 +02:00
expValueField = createExpValueField(rowInputCell,rule.vt||'jsonata');
2018-01-17 11:08:58 +01:00
expValueField.typedInput('value',rule.v);
2016-05-20 23:13:28 +02:00
} else if (typeof rule.v != "undefined") {
2021-10-19 11:12:13 +02:00
valueField = createValueField(rowInputCell,rule.vt||'str');
2016-05-20 23:13:28 +02:00
valueField.typedInput('value',rule.v);
2015-10-04 23:14:49 +02:00
}
2021-10-19 11:12:13 +02:00
caseSensitive.prop('checked',!!rule.case);
2016-05-20 23:13:28 +02:00
selectField.change();
2017-02-07 23:30:54 +01:00
var currentOutputs = JSON.parse(outputCount.val()||"{}");
currentOutputs[opt.hasOwnProperty('i')?opt.i:opt._i] = i;
outputCount.val(JSON.stringify(currentOutputs));
2016-05-20 23:13:28 +02:00
},
2016-05-29 23:25:30 +02:00
removeItem: function(opt) {
2017-02-07 23:30:54 +01:00
var currentOutputs = JSON.parse(outputCount.val()||"{}");
2016-11-08 18:00:47 +01:00
if (opt.hasOwnProperty('i')) {
2017-02-07 23:30:54 +01:00
currentOutputs[opt.i] = -1;
} else {
delete currentOutputs[opt._i];
2016-11-08 18:00:47 +01:00
}
2016-05-20 23:13:28 +02:00
var rules = $("#node-input-rule-container").editableList('items');
2017-02-07 23:30:54 +01:00
rules.each(function(i) {
$(this).find(".node-input-rule-index").html(i+1);
var data = $(this).data('data');
currentOutputs[data.hasOwnProperty('i')?data.i:data._i] = i;
});
outputCount.val(JSON.stringify(currentOutputs));
2016-05-20 23:13:28 +02:00
},
2016-05-29 23:25:30 +02:00
sortItems: function(rules) {
2017-02-07 23:30:54 +01:00
var currentOutputs = JSON.parse(outputCount.val()||"{}");
2016-05-20 23:13:28 +02:00
var rules = $("#node-input-rule-container").editableList('items');
2017-02-07 23:30:54 +01:00
rules.each(function(i) {
$(this).find(".node-input-rule-index").html(i+1);
var data = $(this).data('data');
currentOutputs[data.hasOwnProperty('i')?data.i:data._i] = i;
});
outputCount.val(JSON.stringify(currentOutputs));
2016-05-20 23:13:28 +02:00
},
sortable: true,
2016-05-29 23:25:30 +02:00
removable: true
2013-10-13 21:28:21 +02:00
});
2013-11-22 17:24:22 +01:00
2013-10-13 21:28:21 +02:00
for (var i=0;i< this.rules.length ; i + + ) {
var rule = this.rules[i];
2016-11-08 18:00:47 +01:00
$("#node-input-rule-container").editableList('addItem',{r:rule,i:i});
2013-10-13 21:28:21 +02:00
}
},
oneditsave: function() {
2016-05-20 23:13:28 +02:00
var rules = $("#node-input-rule-container").editableList('items');
2013-10-13 21:28:21 +02:00
var node = this;
2016-11-08 18:00:47 +01:00
node.rules = [];
2013-10-13 21:28:21 +02:00
rules.each(function(i) {
2021-10-05 11:34:46 +02:00
node.rules.push(exportRule($(this)));
2013-10-13 21:28:21 +02:00
});
2016-01-03 23:26:47 +01:00
this.propertyType = $("#node-input-property").typedInput('type');
2016-01-04 17:53:32 +01:00
},
oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-input-rule-container-row)");
var height = size.height;
2019-04-29 12:50:15 +02:00
for (var i=0;i< rows.length ; i + + ) {
2016-01-04 17:53:32 +01:00
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-input-rule-container-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
2020-01-01 22:32:56 +01:00
height += 16;
2016-05-20 23:13:28 +02:00
$("#node-input-rule-container").editableList('height',height);
2013-10-13 21:28:21 +02:00
}
});
2017-01-27 19:11:25 +01:00
})();
2013-10-13 21:28:21 +02:00
< / script >