|
25 | 25 | return (v !== null && v !== undefined && v !== "" && v !== "err");
|
26 | 26 | }
|
27 | 27 |
|
| 28 | + function validateDevice(v) { |
| 29 | + const sendasdevice = $("#node-input-sendasdevice").is(":checked") |
| 30 | + return !sendasdevice || (v !== null && v !== undefined && v !== "" && v !== "err"); |
| 31 | + } |
| 32 | + |
28 | 33 | function validateConnection(v) {
|
29 | 34 | return (v !== null && v !== undefined && v !== "" && v !== "_ADD_");
|
30 | 35 | }
|
|
52 | 57 | ret['variableName'] = {value: ""};
|
53 | 58 | }
|
54 | 59 |
|
| 60 | + if (nodeName === "property out") { |
| 61 | + ret['sendasdevice'] = {value: false}; |
| 62 | + ret["device"] = {value: "", validate: validateDevice}; |
| 63 | + } |
| 64 | + |
55 | 65 | return ret;
|
56 | 66 | }
|
57 | 67 |
|
|
100 | 110 | }
|
101 | 111 | }
|
102 | 112 | });
|
| 113 | + $("#node-input-sendasdevice").change(() => { |
| 114 | + const thing_id = $("#node-input-thing").val(); |
| 115 | + if (thing_id) { |
| 116 | + if ($("#node-input-sendasdevice").is(":checked")) { |
| 117 | + const connection = $("#node-input-connection").val(); |
| 118 | + const organization = $("#node-input-organization").val(); |
| 119 | + const device = $("#node-input-device").val(); |
| 120 | + initDevice(connection, thing_id, organization, device, this._); |
| 121 | + $("#node-input-device-line").show() |
| 122 | + } else { |
| 123 | + $("#node-input-device-line").hide() |
| 124 | + } |
| 125 | + } |
| 126 | + }); |
103 | 127 | $("#node-input-organization").change(() => {
|
104 | 128 | const connection = $("#node-input-connection").val();
|
105 | 129 | const organization = $("#node-input-organization").val();
|
|
119 | 143 | const property_id = $("#node-input-property").val();
|
120 | 144 | const connection = $("#node-input-connection").val();
|
121 | 145 | const organization = $("#node-input-organization").val();
|
| 146 | + const device = $("#node-input-device").val(); |
122 | 147 | const thing_text = $("#node-input-thing").find('option:selected').text()
|
123 | 148 | var str;
|
124 | 149 | if (connection === "_ADD_") {
|
|
135 | 160 | } else {
|
136 | 161 | $("select#node-input-property").empty();
|
137 | 162 | initProperties(connection, thing_id, organization, this.property, outs, this._);
|
| 163 | + initDevice(connection, thing_id, organization, this.device, this._); |
138 | 164 | }
|
139 | 165 | }
|
140 | 166 | });
|
|
221 | 247 | $("#node-input-thing").val(thing_id);
|
222 | 248 | }
|
223 | 249 | $("#node-input-thing").trigger("change");
|
| 250 | + $("#node-input-sendasdevice").trigger("change"); |
224 | 251 | } else if (things && Array.isArray(things) && things.length === 0) {
|
225 | 252 | $("select#node-input-thing").empty();
|
226 | 253 | msg = label_func("arduino-iot-cloud.config.node.placeholders.no-things-available");
|
|
243 | 270 | }
|
244 | 271 | }
|
245 | 272 |
|
| 273 | + function initDevice(connection, thing_id, organization_id, device_id, label_func) { |
| 274 | + let queryString = prepareQueryString(connection); |
| 275 | + if (!queryString || queryString === "") |
| 276 | + return; |
| 277 | + if (!thing_id || thing_id === "" || thing_id === "0" || thing_id === "updating") |
| 278 | + return; |
| 279 | + |
| 280 | + queryString = `${queryString}&thing_id=${thing_id}`; |
| 281 | + |
| 282 | + $("select#node-input-device").empty(); |
| 283 | + $("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-device"); |
| 284 | + $("select#node-input-device").val("updating"); |
| 285 | + |
| 286 | + setupOrganization(organization_id); |
| 287 | + $.getJSON(`thing?${queryString}`, thing => { |
| 288 | + $("select#node-input-device").empty(); |
| 289 | + if(thing && typeof (thing) == "object" && thing.error){ |
| 290 | + $("select#node-input-device").empty(); |
| 291 | + $("<option value='" + "" + "'> " + properties.error + "</option>").appendTo("select#node-input-device"); |
| 292 | + } else if (thing.device_id) { |
| 293 | + $("<option value='" + thing.device_id + "'>" + thing.device_name + "</option>").appendTo("select#node-input-device"); |
| 294 | + $("select#node-input-device").val(thing.device_id); |
| 295 | + } else { |
| 296 | + msg = label_func("arduino-iot-cloud.config.node.placeholders.no-device-select"); |
| 297 | + $("<option value='" + "" + "' > " + msg + "</option>").appendTo("select#node-input-device"); |
| 298 | + } |
| 299 | + }); |
| 300 | + } |
| 301 | + |
246 | 302 | function initProperties(connection, thing_id, organization_id, property_id, outs, label_func) {
|
247 | 303 | let queryString = prepareQueryString(connection);
|
248 | 304 | if (!queryString || queryString === "")
|
|
382 | 438 | <label for="node-input-name"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.name"></span></label>
|
383 | 439 | <input type="text" id="node-input-name" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.name">
|
384 | 440 | </div>
|
385 |
| - |
| 441 | + <div class="form-row"> |
| 442 | + <label for="node-input-name"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.send-mode"></span></label> |
| 443 | + <input type="checkbox" id="node-input-sendasdevice"> |
| 444 | + </div> |
| 445 | + <div class="form-row" id="node-input-device-line"> |
| 446 | + <label for="node-input-device"><i class="fa fa-cube fa-fw"></i> <span data-i18n="arduino-iot-cloud.config.node.device-id"></span></label> |
| 447 | + <select id="node-input-device" type="hidden" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.no-device-select"> |
| 448 | + </select> |
| 449 | + </div> |
386 | 450 | </script>
|
387 | 451 |
|
388 | 452 |
|
|
0 commit comments