-
Notifications
You must be signed in to change notification settings - Fork 595
/
88-ping.html
121 lines (117 loc) · 4.45 KB
/
88-ping.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<script type="text/html" data-template-name="ping">
<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>
<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>
<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-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();
}
}
RED.nodes.registerType("ping",{
category: "network-input",
color:"#fdf0c2",
defaults: {
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) ;
}
},
inputs: {value:0}
},
inputs:0,
outputs:1,
icon: "alert.png",
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");
let $tip = $("#node-ping-tip");
$("#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();
$tip.show();
break;
default:
node.inputs = 0;
node._def.inputs = 0;
$timer.show();
$tip.hide();
break;
}
}
$mode.change(updateControlsVisibility);
updateControlsVisibility();
}
});
</script>