2 Copyright 2013 IBM Corp.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 <!-- First, the content of the edit dialog is defined. -->
18 <script type="text/x-red" data-template-name="delay">
20 <div class="form-row">
21 <label for="node-input-pauseType"><i class="fa fa-tasks"></i> Action</label>
22 <select id="node-input-pauseType" style="width:270px !important">
23 <option value="delay">Delay message</option>
24 <option value="rate">Limit rate to</option>
25 <option value="random">Random delay</option>
28 <div id="delay-details" class="form-row">
29 <label for="node-input-timeout"><i class="fa fa-clock-o"></i> For</label>
30 <input type="text" id="node-input-timeout" placeholder="Time" style="direction:rtl; width:50px !important">
31 <select id="node-input-timeoutUnits" style="width:200px !important">
32 <option value="milliseconds">Milliseconds</option>
33 <option value="seconds">Seconds</option>
34 <option value="minutes">Minutes</option>
35 <option value="hours">Hours</option>
36 <option value="days">Days</option>
40 <div id="rate-details" class="form-row">
41 <label for="node-input-rate"><i class="fa fa-clock-o"></i> To</label>
42 <input type="text" id="node-input-rate" placeholder="1" style="direction:rtl; width:30px !important">
43 <label for="node-input-reateUnits">msg(s) per</label>
44 <select id="node-input-rateUnits" style="width:140px !important">
45 <option value="second">Second</option>
46 <option value="minute">Minute</option>
47 <option value="hour">Hour</option>
48 <option value="day">Day</option>
51 <input style="margin: 20px 0 20px 100px; width: 30px;" type="checkbox" id="node-input-drop"><label style="width: 250px;" for="node-input-drop">drop intermediate messages</label>
54 <div id="random-details" class="form-row">
55 <label for="node-input-randomFirst"><i class="fa fa-clock-o"></i> Between</label>
56 <input type="text" id="node-input-randomFirst" placeholder="" style="directon:rtl; width:30px !important">
57 <label for="node-input-randomLast" style="width:20px"> & </label>
58 <input type="text" id="node-input-randomLast" placeholder="" style="directon:rtl; width:30px !important">
59 <select id="node-input-randomUnits" style="width:140px !important">
60 <option value="milliseconds">Milliseconds</option>
61 <option value="seconds">Seconds</option>
62 <option value="minutes">Minutes</option>
63 <option value="hours">Hours</option>
64 <option value="days">Days</option>
68 <div class="form-row">
69 <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
70 <input type="text" id="node-input-name" placeholder="Name">
75 <!-- Next, some simple help text is provided for the node. -->
76 <script type="text/x-red" data-help-name="delay">
77 <p>Introduces a delay into a flow or rate limts messges</p>
78 <p>Default delay is 5 seconds and rate limit of 1 msg/second, but both can be configured</p>
81 <!-- Finally, the node type is registered along with all of its properties -->
82 <script type="text/javascript">
83 RED.nodes.registerType('delay',{
84 category: 'function', // the palette category
86 defaults: { // defines the editable properties of the node
87 name: {value:""}, // along with default values.
88 pauseType: {value:"delay", required:true},
89 timeout: {value:"5", required:true, validate:RED.validators.number()},
90 timeoutUnits: {value:"seconds"},
91 rate: {value:"1", required:true, validate:RED.validators.number()},
92 rateUnits: {value: "second"},
93 randomFirst: {value:"1", required:true, validate:RED.validators.number()},
94 randomLast: {value:"5", required:true, validate:RED.validators.number()},
95 randomUnits: {value: "seconds"},
98 inputs:1, // set the number of inputs - only 0 or 1
99 outputs:1, // set the number of outputs - 0 to n
100 icon: "timer.png", // set the icon (held in public/icons)
101 label: function() { // sets the default label contents
102 if (this.pauseType == "delay") {
103 var units = this.timeoutUnits ? this.timeoutUnits.charAt(0) : "s";
104 if (this.timeoutUnits == "milliseconds") { units = "ms"; }
105 return this.name||"delay "+this.timeout+" " + units;
106 } else if (this.pauseType == "rate") {
107 var units = this.rateUnits ? this.rateUnits.charAt(0) : "s";
108 return this.name||"limit "+this.rate+" msg/"+ units;
109 } else if (this.pauseType == "random") {
110 return this.name || "random";
114 labelStyle: function() { // sets the class to apply to the label
115 return this.name?"node_label_italic":"";
117 oneditprepare: function() {
118 $( "#node-input-timeout" ).spinner({min:1,max:60});
119 $( "#node-input-rate" ).spinner({min:1});
121 $( "#node-input-randomFirst" ).spinner({min:0});
122 $( "#node-input-randomLast" ).spinner({min:1});
124 if (this.pauseType == "delay") {
125 $("#delay-details").show();
126 $("#rate-details").hide();
127 $("#random-details").hide();
128 } else if (this.pauseType == "rate") {
129 $("#delay-details").hide();
130 $("#rate-details").show();
131 $("#random-details").hide();
132 } else if (this.pauseType == "random") {
133 $("#delay-details").hide();
134 $("#rate-details").hide();
135 $("#random-details").show();
138 if (!this.timeoutUnits) {
139 $("#node-input-timeoutUnits option").filter(function() {
140 return $(this).val() == 'seconds';
141 }).attr('selected', true);
144 if (!this.randomUnits) {
145 $("#node-input-randomUnits option").filter(function() {
146 return $(this).val() == 'seconds';
147 }).attr('selected', true);
150 $("#node-input-pauseType").on("change",function() {
151 if (this.value == "delay") {
152 $("#delay-details").show();
153 $("#rate-details").hide();
154 $("#random-details").hide();
155 } else if (this.value == "rate") {
156 $("#delay-details").hide();
157 $("#rate-details").show();
158 $("#random-details").hide();
159 } else if (this.value == "random") {
160 $("#delay-details").hide();
161 $("#rate-details").hide();
162 $("#random-details").show();