mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
400141b093
commit
e3b70b10d1
@ -18,12 +18,43 @@
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
function validateProperty(v,vt) {
|
||||
if (/msg|flow|global/.test(vt)) {
|
||||
if (!RED.utils.validatePropertyExpression(v)) {
|
||||
return false;
|
||||
}
|
||||
} else if (v[i].vt === "jsonata") {
|
||||
try{jsonata(v);}catch(e){return false;}
|
||||
} else if ([i].vt === "json") {
|
||||
try{JSON.parse(v);}catch(e){return false;}
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType('change', {
|
||||
color: "#E2D96E",
|
||||
category: 'function',
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
rules:{value:[{t:"set",p:"payload",pt:"msg",to:"",tot:"str"}]},
|
||||
rules:{value:[{t:"set",p:"payload",pt:"msg",to:"",tot:"str"}],validate: function(rules) {
|
||||
if (!rules || rules.length === 0) { return true }
|
||||
for (var i=0;i<rules.length;i++) {
|
||||
var r = rules[i];
|
||||
if (r.t === 'set') {
|
||||
if (!validateProperty(r.p,r.pt) || !validateProperty(r.to,r.tot)) {
|
||||
return false;
|
||||
}
|
||||
} else if (r.t === 'change') {
|
||||
if (!validateProperty(r.p,r.pt) || !validateProperty(r.from,r.fromt) || !validateProperty(r.to,r.tot)) {
|
||||
return false;
|
||||
}
|
||||
} else if (r.t === 'move') {
|
||||
if (!validateProperty(r.p,r.pt)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}},
|
||||
// legacy
|
||||
action: {value:""},
|
||||
property: {value:""},
|
||||
@ -323,4 +354,5 @@
|
||||
$("#node-input-rule-container").editableList('height',height);
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user