|
54 | 54 |
|
55 | 55 | if (nodeName === "property out") {
|
56 | 56 | ret['sendasdevice'] = {value: false};
|
| 57 | + ret["device"] = {value: ""}; |
57 | 58 | }
|
58 | 59 |
|
59 | 60 | return ret;
|
|
83 | 84 | }
|
84 | 85 | initThings(this.connection, this._, this.thing, this.organization);
|
85 | 86 | initProperties(this.connection, this.thing, this.organization, this.property, outs, this._);
|
| 87 | + initDevice(this.connection, this.thing.id, this.organization, this._); |
86 | 88 | }
|
87 | 89 | $("select#node-input-connection").change((e) => {
|
88 | 90 | var msg = this._("arduino-iot-cloud.config.connection.placeholders.no-conn-selected");
|
|
105 | 107 | }
|
106 | 108 | });
|
107 | 109 | $("#node-input-sendasdevice").change(() => {
|
108 |
| - sendasdevice = $("#node-input-sendasdevice").val(); |
109 |
| - this.sendasdevice = sendasdevice; |
| 110 | + if ($("#node-input-sendasdevice").is(":checked")) { |
| 111 | + const connection = $("#node-input-connection").val(); |
| 112 | + const thing_id = $("#node-input-thing").val(); |
| 113 | + const organization = $("#node-input-organization").val(); |
| 114 | + initDevice(connection, thing_id, organization, this._); |
| 115 | + $("#node-input-device-line").show() |
| 116 | + } else { |
| 117 | + $("#node-input-device-line").hide() |
| 118 | + $("#node-input-device").val(""); |
| 119 | + } |
110 | 120 | });
|
111 | 121 | $("#node-input-organization").change(() => {
|
112 | 122 | const connection = $("#node-input-connection").val();
|
|
143 | 153 | } else {
|
144 | 154 | $("select#node-input-property").empty();
|
145 | 155 | initProperties(connection, thing_id, organization, this.property, outs, this._);
|
| 156 | + initDevice(connection, thing_id, organization, this._); |
146 | 157 | }
|
147 | 158 | }
|
148 | 159 | });
|
|
251 | 262 | }
|
252 | 263 | }
|
253 | 264 |
|
| 265 | + function initDevice(connection, thing_id, organization_id, label_func) { |
| 266 | + let queryString = prepareQueryString(connection); |
| 267 | + if (!queryString || queryString === "") |
| 268 | + return; |
| 269 | + if (!thing_id || thing_id === "" || thing_id === "0" || thing_id === "updating") |
| 270 | + return; |
| 271 | + queryString = `${queryString}&thing_id=${thing_id}`; |
| 272 | + |
| 273 | + $("select#node-input-device").empty(); |
| 274 | + $("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-device"); |
| 275 | + $("select#node-input-device").val("updating"); |
| 276 | + |
| 277 | + setupOrganization(organization_id); |
| 278 | + $.getJSON(`thing?${queryString}`, thing => { |
| 279 | + $("select#node-input-device").empty(); |
| 280 | + msg = label_func("arduino-iot-cloud.config.node.placeholders.device-select"); |
| 281 | + $("<option value='" + "" + "'> " + msg + "</option>").appendTo("#node-input-device"); |
| 282 | + if(thing){ |
| 283 | + $("<option value='" + thing.device_id + "'>" + thing.device_name + "</option>").appendTo("#node-input-device"); |
| 284 | + $("select#node-input-device").val(thing.device_id); |
| 285 | + } |
| 286 | + }); |
| 287 | + } |
| 288 | + |
254 | 289 | function initProperties(connection, thing_id, organization_id, property_id, outs, label_func) {
|
255 | 290 | let queryString = prepareQueryString(connection);
|
256 | 291 | if (!queryString || queryString === "")
|
|
394 | 429 | <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>
|
395 | 430 | <input type="checkbox" id="node-input-sendasdevice">
|
396 | 431 | </div>
|
397 |
| - |
| 432 | + <div class="form-row" id="node-input-device-line"> |
| 433 | + <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> |
| 434 | + <select id="node-input-device" type="hidden" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.device-select"> |
| 435 | + </select> |
| 436 | + </div> |
398 | 437 | </script>
|
399 | 438 |
|
400 | 439 |
|
|
0 commit comments