1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
node-red-nodes/io/ping/88-ping.html

122 lines
4.4 KiB
HTML
Raw Permalink Normal View History

<script type="text/html" data-template-name="ping">
<div class="form-row" id="div-node-input-host">
<label for="node-input-host"><i class="fa fa-dot-circle-o"></i> <span data-i18n="ping.label.target"></span></label>
<input type="text" id="node-input-host" placeholder="192.168.0.1, www.google.com">
</div>
2021-03-12 13:54:13 +01:00
<div class="form-row">
<label for="node-protocol"><i class="fa fa-gear"></i> <span data-i18n="ping.label.protocol"></label>
<select type="text" id="node-input-protocol" style="width: 70%">
<option value="Automatic" data-i18n="ping.label.protocol_option.auto"></option>
<option value="IPv4" data-i18n="ping.label.protocol_option.ipv4"></option>
<option value="IPv6" data-i18n="ping.label.protocol_option.ipv6"></option>
</select>
</div>
<div class="form-row">
<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">
<label for="node-input-timer"><i class="fa fa-repeat"></i> <span data-i18n="ping.label.ping"></label>
<input type="text" id="node-input-timer" placeholder="20">
</div>
<div class="form-row">
<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">
</div>
2020-04-03 17:50:09 +02:00
<div class="form-tips" id="node-ping-tip"><span data-i18n="ping.label.tip"></span></div>
</script>
<script type="text/javascript">
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();
2020-04-03 17:50:09 +02:00
}
}
RED.nodes.registerType("ping",{
category: "network-input",
color:"#fdf0c2",
defaults: {
2021-03-12 13:54:13 +01:00
protocol: {value:"Automatic"},
mode: {value:"timed"},
name: {value:""},
host: {value:"", validate: function(v){
return hostParameterValidator(this,v) ;
}
},
timer: {value:"20", validate: function(v){
return timerParameterValidator(this,v) ;
2020-04-03 17:50:09 +02:00
}
},
inputs: {value:0}
},
inputs:0,
outputs:1,
icon: "alert.png",
2018-04-14 23:43:14 +02:00
paletteLabel: function() {
return this._("ping.ping");
},
label: function() {
let lbl = this.name||this.host||this._("ping.ping");
if (lbl.split(',').length > 1){
lbl = this._("ping.ping");
}
return lbl;
},
labelStyle: function() {
return this.name?"node_label_italic":"";
},
oneditprepare: function () {
let node = this;
let $timer = $("#div-node-input-timer");
2020-04-03 17:50:09 +02:00
let $tip = $("#node-ping-tip");
$("#node-input-mode").val(node.mode);
let $mode = $( "#node-input-mode" );
2020-04-03 17:50:09 +02:00
function updateControlsVisibility(){
node.mode = $mode.val();
switch (node.mode) {
case "triggered":
node.inputs = 1;
node._def.inputs = 1
$timer.hide();
2020-04-03 17:50:09 +02:00
$tip.show();
break;
default:
node.inputs = 0;
node._def.inputs = 0;
$timer.show();
2020-04-03 17:50:09 +02:00
$tip.hide();
break;
}
}
$mode.change(updateControlsVisibility);
updateControlsVisibility();
}
});
</script>