Rename propertySelect to typedInput and add boolean opt

This commit is contained in:
Nick O'Leary
2016-01-03 22:26:47 +00:00
parent 5f7019325c
commit f1c59faf72
11 changed files with 345 additions and 219 deletions

View File

@@ -65,7 +65,7 @@
return this.name||"switch";
},
oneditprepare: function() {
$("#node-input-property").propertySelect({default:this.propertyType||'msg',options:['msg','flow','global']});
$("#node-input-property").typedInput({default:this.propertyType||'msg',options:['msg','flow','global']});
var operators = [
{v:"eq",t:"=="},
{v:"neq",t:"!="},
@@ -104,13 +104,13 @@
if (type === "btwn") {
var labelWidth = rule.find(".node-input-rule-btwn-label").width();
btwnField1.propertySelect("width",(width-selectWidth-120));
btwnField2.propertySelect("width",(width-selectWidth-120));
btwnField1.typedInput("width",(width-selectWidth-120));
btwnField2.typedInput("width",(width-selectWidth-120));
} else {
if (type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else") {
// valueField.hide();
} else {
valueField.propertySelect("width",(width-selectWidth-120));
valueField.typedInput("width",(width-selectWidth-120));
}
}
}
@@ -128,10 +128,10 @@
selectField.append($("<option></option>").val(operators[d].v).text(operators[d].t));
}
var valueField = $('<input/>',{class:"node-input-rule-value",type:"text",style:"margin-left: 5px; width: 145px;"}).appendTo(row).propertySelect({default:'str',options:['msg','flow','global','str','num']});
var btwnValueField = $('<input/>',{class:"node-input-rule-btwn-value",type:"text",style:"margin-left: 5px;"}).appendTo(row).propertySelect({default:'num',options:['msg','flow','global','str','num']});
var valueField = $('<input/>',{class:"node-input-rule-value",type:"text",style:"margin-left: 5px; width: 145px;"}).appendTo(row).typedInput({default:'str',options:['msg','flow','global','str','num']});
var btwnValueField = $('<input/>',{class:"node-input-rule-btwn-value",type:"text",style:"margin-left: 5px;"}).appendTo(row).typedInput({default:'num',options:['msg','flow','global','str','num']});
var btwnAndLabel = $('<span/>',{class:"node-input-rule-btwn-label"}).text(" "+andLabel+" ").appendTo(row3);
var btwnValue2Field = $('<input/>',{class:"node-input-rule-btwn-value2",type:"text",style:"margin-left:2px;"}).appendTo(row3).propertySelect({default:'num',options:['msg','flow','global','str','num']});
var btwnValue2Field = $('<input/>',{class:"node-input-rule-btwn-value2",type:"text",style:"margin-left:2px;"}).appendTo(row3).typedInput({default:'num',options:['msg','flow','global','str','num']});
var finalspan = $('<span/>',{style:"float: right;margin-right: 10px;"}).appendTo(row);
finalspan.append(' &#8594; <span class="node-input-rule-index">'+i+'</span> ');
@@ -185,12 +185,12 @@
selectField.find("option").filter(function() {return $(this).val() == rule.t;}).attr('selected',true);
if (rule.t == "btwn") {
btwnValueField.val(rule.v);
btwnValueField.propertySelect('type',rule.vt||'num');
btwnValueField.typedInput('type',rule.vt||'num');
btwnValue2Field.val(rule.v2);
btwnValue2Field.propertySelect('type',rule.v2t||'num');
btwnValue2Field.typedInput('type',rule.v2t||'num');
} else if (typeof rule.v != "undefined") {
valueField.val(rule.v);
valueField.propertySelect('type',rule.vt||'str');
valueField.typedInput('type',rule.vt||'str');
}
if (rule.case) {
caseSensitive.prop('checked',true);
@@ -267,12 +267,12 @@
if (!(type === "true" || type === "false" || type === "null" || type === "nnull" || type === "else")) {
if (type === "btwn") {
r.v = rule.find(".node-input-rule-btwn-value").val();
r.vt = rule.find(".node-input-rule-btwn-value").propertySelect('type');
r.vt = rule.find(".node-input-rule-btwn-value").typedInput('type');
r.v2 = rule.find(".node-input-rule-btwn-value2").val();
r.v2t = rule.find(".node-input-rule-btwn-value2").propertySelect('type');
r.v2t = rule.find(".node-input-rule-btwn-value2").typedInput('type');
} else {
r.v = rule.find(".node-input-rule-value").val();
r.vt = rule.find(".node-input-rule-value").propertySelect('type');
r.vt = rule.find(".node-input-rule-value").typedInput('type');
}
if (type === "regex") {
r.case = rule.find(".node-input-rule-case").prop("checked");
@@ -281,7 +281,7 @@
node.rules.push(r);
});
this.outputs = node.rules.length;
this.propertyType = $("#node-input-property").propertySelect('type');
this.propertyType = $("#node-input-property").typedInput('type');
}
});
</script>

View File

@@ -17,7 +17,7 @@
<script type="text/x-red" data-template-name="change">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
<input type="text" id="node-input-name" style="width: 370px;" data-i18n="[placeholder]common.label.name">
</div>
<div class="form-row" style="margin-bottom:0;">
<label><i class="fa fa-list"></i> <span data-i18n="change.label.rules"></span></label>
@@ -101,8 +101,8 @@
var regex = this._("change.label.regex");
function resizeRule(rule,width) {
rule.find('input[type="text"]:not(.red-ui-propertySelect)').width(width-180);
rule.find('.red-ui-propertySelect').propertySelect("width",width-180);
rule.find('input[type="text"]:not(.red-ui-typedInput)').width(width-180);
rule.find('.red-ui-typedInput').typedInput("width",width-180);
}
function generateRule(rule) {
@@ -133,22 +133,21 @@
selectField.append($("<option></option>").val(selectOptions[i].v).text(selectOptions[i].l));
}
var propertyName = $('<input/>',{style:"width: 250px",class:"node-input-rule-property-name",type:"text"}).appendTo(row1).propertySelect({options:['msg','flow','global']});
var propertyName = $('<input/>',{style:"width: 250px",class:"node-input-rule-property-name",type:"text"}).appendTo(row1).typedInput({options:['msg','flow','global']});
var finalspan = $('<span/>',{style:"float: right; margin-right: 10px;"}).appendTo(row1);
var deleteButton = $('<a/>',{href:"#",class:"editor-button editor-button-small", style:"margin-top: 7px; margin-left: 5px;"}).appendTo(finalspan);
$('<i/>',{class:"fa fa-remove"}).appendTo(deleteButton);
$('<div/>',{style:"display: inline-block;text-align:right; width:120px;padding-right: 10px; box-sizing: border-box;"}).text(to).appendTo(row2);
var propertyValue = $('<input/>',{style:"width: 250px",class:"node-input-rule-property-value",type:"text"}).appendTo(row2).propertySelect({default:'str',options:['msg','flow','global','str','num','json']});
var propertyValue = $('<input/>',{style:"width: 250px",class:"node-input-rule-property-value",type:"text"}).appendTo(row2).typedInput({default:'str',options:['msg','flow','global','str','num','bool','json']});
var row3_1 = $('<div/>').appendTo(row3);
$('<div/>',{style:"display: inline-block;text-align:right; width:120px;padding-right: 10px; box-sizing: border-box;"}).text(search).appendTo(row3_1);
var fromValue = $('<input/>',{style:"width: 250px",class:"node-input-rule-property-search-value",type:"text"}).appendTo(row3_1).propertySelect({default:'str',options:['msg','flow','global','str','re']});
var fromValue = $('<input/>',{style:"width: 250px",class:"node-input-rule-property-search-value",type:"text"}).appendTo(row3_1).typedInput({default:'str',options:['msg','flow','global','str','re']});
var row3_2 = $('<div/>',{style:"margin-top:8px;"}).appendTo(row3);
$('<div/>',{style:"display: inline-block;text-align:right; width:120px;padding-right: 10px; box-sizing: border-box;"}).text(replace).appendTo(row3_2);
var toValue = $('<input/>',{style:"width: 250px",class:"node-input-rule-property-replace-value",type:"text"}).appendTo(row3_2).propertySelect({default:'str',options:['msg','flow','global','str','num','json']});
var toValue = $('<input/>',{style:"width: 250px",class:"node-input-rule-property-replace-value",type:"text"}).appendTo(row3_2).typedInput({default:'str',options:['msg','flow','global','str','num','json']});
selectField.change(function() {
var width = $("#node-input-rule-container").width();
@@ -174,13 +173,13 @@
selectField.find("option").filter(function() {return $(this).val() == rule.t;}).attr('selected',true);
propertyName.val(rule.p);
propertyName.propertySelect('type',rule.pt)
propertyName.typedInput('type',rule.pt)
propertyValue.val(rule.to);
propertyValue.propertySelect('type',rule.tot)
propertyValue.typedInput('type',rule.tot)
fromValue.val(rule.from);
fromValue.propertySelect('type',rule.fromt)
fromValue.typedInput('type',rule.fromt)
toValue.val(rule.to);
toValue.propertySelect('type',rule.tot)
toValue.typedInput('type',rule.tot)
selectField.change();
$("#node-input-rule-container").append(container);
@@ -232,6 +231,7 @@
rules.each(function(i) {
resizeRule($(this),newWidth);
})
$("#node-input-name").width(newWidth-130);
};
$( "#dialog" ).on("dialogresize", changeDialogResize);
$( "#dialog" ).one("dialogopen", function(ev) {
@@ -259,16 +259,16 @@
var r = {
t:type,
p:rule.find(".node-input-rule-property-name").val(),
pt:rule.find(".node-input-rule-property-name").propertySelect('type')
pt:rule.find(".node-input-rule-property-name").typedInput('type')
};
if (type === "set") {
r.to = rule.find(".node-input-rule-property-value").val();
r.tot = rule.find(".node-input-rule-property-value").propertySelect('type');
r.tot = rule.find(".node-input-rule-property-value").typedInput('type');
} else if (type === "change") {
r.from = rule.find(".node-input-rule-property-search-value").val();
r.fromt = rule.find(".node-input-rule-property-search-value").propertySelect('type');
r.fromt = rule.find(".node-input-rule-property-search-value").typedInput('type');
r.to = rule.find(".node-input-rule-property-replace-value").val();
r.tot = rule.find(".node-input-rule-property-replace-value").propertySelect('type');
r.tot = rule.find(".node-input-rule-property-replace-value").typedInput('type');
r.re = rule.find(".node-input-rule-property-re").prop('checked');
}
node.rules.push(r);

View File

@@ -84,6 +84,8 @@ module.exports = function(RED) {
valid = false;
this.error(RED._("change.errors.invalid-json"));
}
} else if (rule.tot === 'bool') {
rule.to = /^true$/i.test(rule.to);
}
}