2013-10-04 09:24:09 +02:00
|
|
|
|
2020-04-03 17:07:41 +02:00
|
|
|
<script type="text/html" data-template-name="ping">
|
|
|
|
<div class="form-row" id="div-node-input-host">
|
2017-11-10 16:17:05 +01:00
|
|
|
<label for="node-input-host"><i class="fa fa-dot-circle-o"></i> <span data-i18n="ping.label.target"></span></label>
|
2020-04-03 17:07:41 +02:00
|
|
|
<input type="text" id="node-input-host" placeholder="192.168.0.1, www.google.com">
|
2013-11-10 18:01:19 +01:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2020-04-03 17:07:41 +02:00
|
|
|
<label for="node-input-mode"><i class="fa fa-wrench"></i> <span data-i18n="ping.label.mode"></label>
|
|
|
|
<select type="text" id="node-input-mode" style="width: 70%">
|
|
|
|
<option value="timed" data-i18n="ping.label.mode_option.timed"></option>
|
|
|
|
<option value="triggered" data-i18n="ping.label.mode_option.triggered"></option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
<div class="form-row" id="div-node-input-timer">
|
2017-11-10 16:17:05 +01:00
|
|
|
<label for="node-input-timer"><i class="fa fa-repeat"></i> <span data-i18n="ping.label.ping"></label>
|
2013-11-10 18:01:19 +01:00
|
|
|
<input type="text" id="node-input-timer" placeholder="20">
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2017-11-10 16:17:05 +01:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="node-red:common.label.name"></span></label>
|
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]node-red:common.label.name">
|
2013-11-10 18:01:19 +01:00
|
|
|
</div>
|
2013-10-04 09:24:09 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
2020-04-03 17:07:41 +02:00
|
|
|
|
|
|
|
var timerParameterValidator = function(node,v){
|
|
|
|
var mode = getMode(node)
|
|
|
|
if(mode === "triggered"){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(v == ""){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return RED.validators.number()(v);
|
|
|
|
}
|
|
|
|
var hostParameterValidator = function(node,v){
|
|
|
|
var mode = getMode(node)
|
|
|
|
if(mode === "triggered"){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return v != ""
|
|
|
|
}
|
|
|
|
var getMode = function(node){
|
|
|
|
if(node){
|
|
|
|
return node.mode
|
|
|
|
} else {
|
|
|
|
let $mode = $( "#node-input-mode" );
|
|
|
|
return $mode.val();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RED.nodes.registerType("ping",{
|
|
|
|
category: "network-input",
|
2013-10-04 09:24:09 +02:00
|
|
|
color:"#fdf0c2",
|
|
|
|
defaults: {
|
2020-04-03 17:07:41 +02:00
|
|
|
mode: {value:"timed"},
|
2013-10-04 09:24:09 +02:00
|
|
|
name: {value:""},
|
2020-04-03 17:07:41 +02:00
|
|
|
host: {value:"", validate: function(v){
|
|
|
|
return hostParameterValidator(this,v) ;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
timer: {value:"20", validate: function(v){
|
|
|
|
return timerParameterValidator(this,v) ;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
inputs: {value:0}
|
2013-10-04 09:24:09 +02:00
|
|
|
},
|
|
|
|
inputs:0,
|
|
|
|
outputs:1,
|
|
|
|
icon: "alert.png",
|
2018-04-14 23:43:14 +02:00
|
|
|
paletteLabel: function() {
|
|
|
|
return this._("ping.ping");
|
|
|
|
},
|
2013-10-04 09:24:09 +02:00
|
|
|
label: function() {
|
2020-04-03 17:07:41 +02:00
|
|
|
let lbl = this.name||this.host||this._("ping.ping");
|
|
|
|
if(lbl.length > 20){
|
|
|
|
lbl = lbl.substring(0,17) + "..."
|
|
|
|
}
|
|
|
|
return lbl;
|
2013-10-04 09:24:09 +02:00
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
2020-04-03 17:07:41 +02:00
|
|
|
},
|
|
|
|
oneditprepare: function () {
|
|
|
|
let node = this;
|
|
|
|
let $timer = $("#div-node-input-timer");
|
|
|
|
$("#node-input-mode").val(node.mode);
|
|
|
|
let $mode = $( "#node-input-mode" );
|
|
|
|
function updateControlsVisibility(){
|
|
|
|
node.mode = $mode.val();
|
|
|
|
switch (node.mode) {
|
|
|
|
case "triggered":
|
|
|
|
node.inputs = 1;
|
|
|
|
node._def.inputs = 1
|
|
|
|
$timer.hide();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
node.inputs = 0;
|
|
|
|
node._def.inputs = 0;
|
|
|
|
$timer.show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$mode.change(updateControlsVisibility);
|
|
|
|
updateControlsVisibility();
|
2013-10-04 09:24:09 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|