|
97 | 97 | } |
98 | 98 | } |
99 | 99 | }); |
| 100 | + $("#node-input-organization").focusout(() => { |
| 101 | + const connection = $("#node-input-connection").val(); |
| 102 | + const organization = $("#node-input-organization").val(); |
| 103 | + if (connection === "_ADD_") { |
| 104 | + $("#node-input-organization").empty(); |
| 105 | + str = this._("arduino-iot-cloud.config.connection.placeholders.no-conn-selected"); |
| 106 | + $("<option value='" + "" + "' > " + str + "</option>").appendTo("#node-input-thing"); |
| 107 | + $("#node-input-thing").trigger("change"); |
| 108 | + } else { |
| 109 | + $("select#node-input-thing").empty(); |
| 110 | + initThings(connection, this._, null, organization); |
| 111 | + } |
| 112 | + }); |
100 | 113 | $("#node-input-thing").change(() => { |
101 | 114 | const thing_id = $("#node-input-thing").val(); |
102 | 115 | const property_id = $("#node-input-property").val(); |
103 | 116 | const connection = $("#node-input-connection").val(); |
| 117 | + const organization = $("#node-input-organization").val(); |
104 | 118 | const thing_text = $("#node-input-thing").find('option:selected').text() |
105 | 119 | var str; |
106 | 120 | if (connection === "_ADD_") { |
|
116 | 130 | $("#node-input-property").trigger("change"); |
117 | 131 | } else { |
118 | 132 | $("select#node-input-property").empty(); |
119 | | - initProperties(connection, thing_id, this.property, outs, this._); |
| 133 | + initProperties(connection, thing_id, organization, this.property, outs, this._); |
120 | 134 | } |
121 | 135 | } |
122 | 136 | }); |
|
175 | 189 | } |
176 | 190 | } |
177 | 191 |
|
178 | | - function initThings(connection, label_func, thing_id) { |
| 192 | + function initThings(connection, label_func, thing_id, organization_id) { |
179 | 193 | const queryString = prepareQueryString(connection); |
180 | 194 | if (!queryString || queryString === "") |
181 | 195 | return; |
|
184 | 198 | $("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-thing"); |
185 | 199 | $("select#node-input-thing").val("updating"); |
186 | 200 | var msg; |
| 201 | + setupOrganization(organization_id); |
187 | 202 | $.getJSON(`things?${queryString}`, things => { |
188 | 203 | $("select#node-input-thing").empty(); |
189 | 204 | if (things && typeof (things) == "object" && things.error) { |
|
212 | 227 | }); |
213 | 228 | } |
214 | 229 |
|
215 | | - function initProperties(connection, thing_id, property_id, outs, label_func) { |
| 230 | + function setupOrganization(organization_id) { |
| 231 | + if (organization_id) { |
| 232 | + $.ajaxSetup({ |
| 233 | + headers: { |
| 234 | + organization: organization_id |
| 235 | + } |
| 236 | + }); |
| 237 | + } else if ($.ajaxSettings.headers) { |
| 238 | + delete $.ajaxSettings.headers.organization |
| 239 | + } |
| 240 | + } |
| 241 | + |
| 242 | + function initProperties(connection, thing_id, organization_id, property_id, outs, label_func) { |
216 | 243 | let queryString = prepareQueryString(connection); |
217 | 244 | if (!queryString || queryString === "") |
218 | 245 | return; |
|
224 | 251 | $("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-property"); |
225 | 252 | $("select#node-input-property").val("updating"); |
226 | 253 |
|
| 254 | + setupOrganization(organization_id); |
227 | 255 | $.getJSON(`properties?${queryString}`, properties => { |
228 | 256 | $("select#node-input-property").empty(); |
229 | 257 | var msg; |
|
309 | 337 | <label for="node-input-connection"><i class="fa fa-random fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.connection"></span></label> |
310 | 338 | <input type="text" id="node-input-connection"> |
311 | 339 | </div> |
| 340 | + <div class="form-row"> |
| 341 | + <label for="node-input-organization"><i class="fa fa-tag fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.organization"></span></label> |
| 342 | + <input type="text" id="node-input-organization" data-i18n="[placeholder]arduino-iot-cloud.config.node.placeholders.organization"> |
| 343 | + </div> |
312 | 344 | <div class="form-row"> |
313 | 345 | <label for="node-input-thing"><i class="fa fa-cubes fa-fw"></i><span data-i18n="arduino-iot-cloud.config.node.thing"></span></label> |
314 | 346 | <select id="node-input-thing"> |
|
0 commit comments