|
1 | 1 | <script type="text/javascript"> |
| 2 | + function validator(v) { |
| 3 | + debugger; |
| 4 | + return (v !== null && v !== "" && v !== undefined); |
| 5 | + } |
2 | 6 | function setupNode(nodeName, ins, outs) { |
3 | 7 | RED.nodes.registerType(nodeName,{ |
4 | 8 | category: 'Arduino IoT Cloud', |
5 | 9 | color: '#00979d', |
6 | 10 | defaults: { |
7 | | - connection: {type: "arduino-connection", required: true}, |
8 | | - thing: {value:"",required:true}, |
9 | | - property: {value:"",required:true}, |
10 | | - name: {value:"",required:true}, |
| 11 | + connection: {type: "arduino-connection", validate: validator}, |
| 12 | + thing: {value:"", validate: validator}, |
| 13 | + property: {value:"", validate: validator}, |
| 14 | + name: {value:"", validate: validator}, |
11 | 15 | propname: {value:""}, |
12 | 16 | prevconnection: {value:""} |
13 | 17 | }, |
|
39 | 43 | if (connection !== "_ADD_") { |
40 | 44 | initThings(this.connection, this.thing, this.property); |
41 | 45 | } |
| 46 | + $("#node-input-thing").trigger("change"); |
42 | 47 | }); |
43 | 48 | $("#node-input-thing").change( () => { |
44 | 49 |
|
45 | 50 | const thing_id = $( "#node-input-thing" ).val(); |
46 | | - if (thing_id && thing_id !== "0") { |
| 51 | + if (thing_id) { |
47 | 52 | initProperties(this.connection, thing_id, undefined, outs); |
48 | | - } else |
| 53 | + } else { |
49 | 54 | $("select#node-input-property").empty(); |
| 55 | + } |
| 56 | + $("#node-input-property").trigger("change"); |
50 | 57 | }); |
51 | 58 | $("#node-input-property").change( () => { |
52 | 59 | const property_name = $("#node-input-property").find('option:selected').text(); |
53 | | - if (property_name && property_name !== "") { |
| 60 | + const property_value = $("#node-input-property").find('option:selected').val(); |
| 61 | + if (property_name !=="" && property_value !== "" && property_value !== undefined) { |
54 | 62 | this.propname = property_name; |
55 | 63 | $( "#node-input-name" ).val(property_name); |
56 | 64 | } |
| 65 | + $("#node-input-name").trigger("change"); |
57 | 66 | }); |
58 | 67 | }, |
59 | 68 | oneditsave: function () { |
|
117 | 126 | <script type="text/javascript"> |
118 | 127 | function initThings(connection, thing_id) { |
119 | 128 | $.getJSON(`things?connectionid=${connection}` , things => { |
120 | | - $("<option value='" + 0 + "'> " + "Select a thing" + "</option>").appendTo("#node-input-thing"); |
| 129 | + $("<option value='" + "" + "'> " + "Select a thing" + "</option>").appendTo("#node-input-thing"); |
121 | 130 | for (const t of things) { |
122 | 131 | $("<option value='" + t.id + "'>" + t.name + "</option>").appendTo("#node-input-thing"); |
123 | 132 | } |
124 | | - if (thing_id) { |
| 133 | + if (thing_id !== undefined) { |
125 | 134 | $("#node-input-thing").val(thing_id); |
| 135 | + $("#node-input-property").val(""); |
126 | 136 | } |
| 137 | + $("#node-input-property").trigger("change"); |
127 | 138 | }); |
128 | 139 | } |
129 | 140 | function initProperties(connection, thing_id, property_id, outs) { |
130 | 141 | if (thing_id === "" || thing_id === "0") |
131 | 142 | return; |
132 | 143 | $("#node-input-property").html(""); |
| 144 | + |
133 | 145 | $.getJSON(`properties?connectionid=${connection}&thing_id=${thing_id}` , properties => { |
134 | | - $("<option value='" + 0 + "'> " + "Select a property" + "</option>").appendTo("#node-input-property"); |
| 146 | + $("<option value='" + "" + "'> " + "Select a property" + "</option>").appendTo("#node-input-property"); |
| 147 | + |
135 | 148 | for (const p of properties) { |
136 | 149 | if (outs > 0 || p.permission === "READ_WRITE") |
137 | 150 | $("<option value='" + p.id + "'>" + p.name + "</option>").appendTo("#node-input-property"); |
138 | 151 | } |
139 | | - if (property_id) { |
| 152 | + if (property_id !== undefined) { |
140 | 153 | $("#node-input-property").val(property_id); |
141 | 154 | } |
| 155 | + $("#node-input-name").trigger("change"); |
142 | 156 | }); |
143 | 157 | } |
144 | 158 | </script> |
|
188 | 202 | category: 'Arduino IoT Cloud', |
189 | 203 | color: '#00979d', |
190 | 204 | defaults: { |
191 | | - connection: {type: "arduino-connection", required: true}, |
192 | | - thing: {value:"",required:true}, |
193 | | - property: {value:"",required:true}, |
| 205 | + connection: {type: "arduino-connection", validate: validator}, |
| 206 | + thing: {value:"",validate: validator}, |
| 207 | + property: {value:"",validate: validator}, |
194 | 208 | propid: {value:""}, |
195 | | - name: {value:"",required:true}, |
| 209 | + name: {value:"",validate: validator}, |
196 | 210 | timeWindowCount: {value: 1, validate:RED.validators.number(), required:true}, |
197 | 211 | timeWindowUnit: {value: '3600', required:true}, |
198 | 212 | prevconnection: {value:""}, |
|
227 | 241 | if (connection !== "_ADD_") { |
228 | 242 | initThings(this.connection, this.thing, this.property); |
229 | 243 | } |
| 244 | + $("#node-input-thing").trigger("change"); |
230 | 245 | }); |
231 | 246 | $("#node-input-thing").change( () => { |
232 | 247 | const thing_id = $( "#node-input-thing" ).val(); |
233 | 248 | if (thing_id && thing_id !== "0") { |
234 | 249 | initProperties(this.connection, thing_id); |
235 | | - } else |
| 250 | + } else { |
236 | 251 | $("select#node-input-property").empty(); |
| 252 | + } |
| 253 | + $("#node-input-property").trigger("change"); |
237 | 254 | }); |
238 | 255 | $("#node-input-property").change( () => { |
239 | 256 | const property_name = $("#node-input-property").find('option:selected').text(); |
240 | | - if (property_name && property_name !== "") { |
| 257 | + const property_value = $("#node-input-property").find('option:selected').val(); |
| 258 | + if (property_name !=="" && property_value !== "" && property_value !== undefined) { |
241 | 259 | this.propname = property_name; |
242 | 260 | $( "#node-input-name" ).val(property_name); |
243 | 261 | } |
| 262 | + $("#node-input-name").trigger("change"); |
244 | 263 | }); |
245 | 264 | }, |
246 | 265 | oneditsave: function () { |
|
293 | 312 | category: 'Arduino IoT Cloud', |
294 | 313 | color: '#00979d', |
295 | 314 | defaults: { |
296 | | - connection: {type: "arduino-connection", required: true}, |
297 | | - thing: {value:"",required:true}, |
298 | | - property: {value:"",required:true}, |
| 315 | + connection: {type: "arduino-connection", validate: validator}, |
| 316 | + thing: {value:"", validate: validator}, |
| 317 | + property: {value:"", validate: validator}, |
299 | 318 | propid: {value:""}, |
300 | | - name: {value:"",required:true}, |
| 319 | + name: {value:"", validate: validator}, |
301 | 320 | timeWindowCount: {value: 1, validate:RED.validators.number(), required:true}, |
302 | 321 | timeWindowUnit: {value: '3600', required:true}, |
303 | 322 | prevconnection: {value:""}, |
|
332 | 351 | if (connection !== "_ADD_") { |
333 | 352 | initThings(this.connection, this.thing, this.property); |
334 | 353 | } |
| 354 | + $("#node-input-thing").trigger("change"); |
335 | 355 | }); |
336 | 356 | $("#node-input-thing").change( () => { |
337 | 357 | const thing_id = $( "#node-input-thing" ).val(); |
338 | 358 | if (thing_id && thing_id !== "0") { |
339 | 359 | initProperties(this.connection, thing_id); |
340 | | - } else |
| 360 | + } else { |
341 | 361 | $("select#node-input-property").empty(); |
| 362 | + } |
| 363 | + $("#node-input-property").trigger("change"); |
342 | 364 | }); |
343 | 365 | $("#node-input-property").change( () => { |
344 | 366 | const property_name = $("#node-input-property").find('option:selected').text(); |
345 | | - if (property_name && property_name !== "") { |
| 367 | + const property_value = $("#node-input-property").find('option:selected').val(); |
| 368 | + if (property_name !=="" && property_value !== "" && property_value !== undefined) { |
346 | 369 | this.propname = property_name; |
347 | 370 | $( "#node-input-name" ).val(property_name); |
348 | 371 | } |
| 372 | + $("#node-input-name").trigger("change"); |
349 | 373 | }); |
350 | 374 | }, |
351 | 375 | oneditsave: function () { |
|
397 | 421 | category: 'Arduino IoT Cloud', |
398 | 422 | color: '#00979d', |
399 | 423 | defaults: { |
400 | | - connection: {type: "arduino-connection", required: true}, |
401 | | - thing: {value:"",required:true}, |
402 | | - property: {value:"",required:true}, |
| 424 | + connection: {type: "arduino-connection", validate: validator}, |
| 425 | + thing: {value:"",validate: validator}, |
| 426 | + property: {value:"",validate: validator}, |
403 | 427 | propid: {value:""}, |
404 | | - name: {value:"",required:true}, |
| 428 | + name: {value:"",validate: validator}, |
405 | 429 | prevconnection: {value:""}, |
406 | 430 | propname: {value:""} |
407 | 431 | }, |
|
434 | 458 | if (connection !== "_ADD_") { |
435 | 459 | initThings(this.connection, this.thing, this.property); |
436 | 460 | } |
| 461 | + $("#node-input-thing").trigger("change"); |
437 | 462 | }); |
438 | 463 | $("#node-input-thing").change( () => { |
439 | 464 | const thing_id = $( "#node-input-thing" ).val(); |
440 | 465 | if (thing_id && thing_id !== "0") { |
441 | 466 | initProperties(this.connection, thing_id); |
442 | | - } else |
| 467 | + } else { |
443 | 468 | $("select#node-input-property").empty(); |
| 469 | + } |
| 470 | + $("#node-input-property").trigger("change"); |
444 | 471 | }); |
445 | 472 | $("#node-input-property").change( () => { |
446 | 473 | const property_name = $("#node-input-property").find('option:selected').text(); |
447 | | - if (property_name && property_name !== "") { |
| 474 | + const property_value = $("#node-input-property").find('option:selected').val(); |
| 475 | + if (property_name !=="" && property_value !== "" && property_value !== undefined) { |
448 | 476 | this.propname = property_name; |
449 | 477 | $( "#node-input-name" ).val(property_name); |
450 | 478 | } |
| 479 | + $("#node-input-name").trigger("change"); |
451 | 480 | }); |
452 | 481 | }, |
453 | 482 | oneditsave: function () { |
|
0 commit comments