|
2 | 2 | window.connectionManager = []; |
3 | 3 |
|
4 | 4 | function validator(v) { |
5 | | - return (v !== null && v !== "" && v !== undefined); |
| 5 | + return (v !== null && v !== undefined && v !== ""); |
| 6 | + } |
| 7 | + |
| 8 | + function validateConnection(v) { |
| 9 | + return (v !== null && v !== undefined && v !== "" && v !== "_ADD_"); |
6 | 10 | } |
7 | 11 |
|
8 | 12 | function validateTime(v) { |
9 | 13 | return (v !== null && v !== "" && v !== undefined && Number.isInteger(parseInt(v)) && parseInt(v) !== 0); |
10 | 14 | } |
11 | 15 |
|
12 | 16 | function getDefaults(nodeName){ |
13 | | - var ret={connection: { type: "arduino-connection", validate: validator }, |
| 17 | + var ret={connection: { type: "arduino-connection", validate: validateConnection }, |
14 | 18 | thing: { value: "", validate: validator }, |
15 | 19 | property: { value: "", validate: validator }, |
16 | 20 | name: { value: "", validate: validator }, |
|
43 | 47 | initThings(this.connection, this.thing); |
44 | 48 | initProperties(this.connection, this.thing, this.property, outs); |
45 | 49 | } |
46 | | - $("select#node-input-connection").change(() => { |
| 50 | + $("select#node-input-connection").change((e) => { |
47 | 51 | const connection = $("#node-input-connection").val(); |
| 52 | + const thing_id = $("#node-input-thing").val(); |
48 | 53 | $("select#node-input-thing").empty(); |
49 | 54 | $("select#node-input-property").empty(); |
50 | | - if(this.defaultname && connection === "_ADD_") { |
51 | | - $("#node-input-name").val(""); |
| 55 | + if(connection === "_ADD_") { |
| 56 | + $("<option value='" + "" + "'> " + "No connection selected" + "</option>").appendTo("#node-input-thing"); |
| 57 | + if(this.defaultname){ |
| 58 | + $("#node-input-name").val(""); |
| 59 | + } |
52 | 60 | } |
53 | | - if (this.connection !== connection && connection !== "_ADD_") { |
| 61 | + if ((this.connection !== connection && connection !== "_ADD_") || thing_id === "") { |
54 | 62 | initThings(connection); |
55 | 63 | } |
56 | 64 | $("#node-input-thing").trigger("change"); |
57 | 65 | }); |
58 | 66 | $("#node-input-thing").change(() => { |
59 | | - |
60 | 67 | const thing_id = $("#node-input-thing").val(); |
| 68 | + const connection = $("#node-input-connection").val(); |
| 69 | + const thing_text = $("#node-input-thing").find('option:selected').text() |
61 | 70 | if (thing_id && thing_id !== "") { |
62 | | - const connection = $("#node-input-connection").val(); |
63 | 71 | initProperties(connection, thing_id, undefined, outs); |
| 72 | + } else if (connection === "_ADD_") { |
| 73 | + $("select#node-input-property").empty(); |
| 74 | + $("<option value='" + "" + "'> " + "No connection selected" + "</option>").appendTo("#node-input-property"); |
64 | 75 | } else { |
65 | 76 | $("select#node-input-property").empty(); |
66 | | - } |
| 77 | + $("<option value='" + "" + "'> " + "No thing selected" + "</option>").appendTo("#node-input-property"); |
| 78 | + } |
67 | 79 | $("#node-input-property").trigger("change"); |
68 | 80 | }); |
69 | 81 | $("#node-input-property").change(() => { |
|
166 | 178 | $.getJSON(`things?${queryString}`, things => { |
167 | 179 | $("select#node-input-thing").empty(); |
168 | 180 | if (things && typeof (things) == "object" && things.error) { |
| 181 | + $("select#node-input-thing").empty(); |
169 | 182 | $("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-thing"); |
| 183 | + $("select#node-input-property").empty(); |
| 184 | + $("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-property"); |
170 | 185 | } else if (things && Array.isArray(things) && things.length !== 0) { |
171 | 186 | $("<option value='" + "" + "'> " + "Select a thing" + "</option>").appendTo("#node-input-thing"); |
172 | 187 | for (const t of things) { |
|
176 | 191 | $("#node-input-thing").val(thing_id); |
177 | 192 | } |
178 | 193 | $("#node-input-property").trigger("change"); |
| 194 | + } else if (things && Array.isArray(things) && things.length === 0) { |
| 195 | + $("select#node-input-thing").empty(); |
| 196 | + $("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-thing"); |
| 197 | + $("select#node-input-property").empty(); |
| 198 | + $("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-property"); |
179 | 199 | } |
180 | 200 | }); |
181 | 201 | } |
|
190 | 210 | $.getJSON(`properties?${queryString}`, properties => { |
191 | 211 | $("select#node-input-property").empty(); |
192 | 212 | if (properties && typeof (properties) == "object" && properties.error) { |
| 213 | + $("select#node-input-thing").empty(); |
193 | 214 | $("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-thing"); |
| 215 | + $("select#node-input-property").empty(); |
| 216 | + $("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-property"); |
194 | 217 | } else if ((properties && Array.isArray(properties) && properties.length !== 0)) { |
195 | 218 | $("<option value='" + "" + "'> " + "Select a property" + "</option>").appendTo("#node-input-property"); |
196 | 219 | for (const p of properties) { |
|
201 | 224 | $("#node-input-property").val(property_id); |
202 | 225 | } |
203 | 226 | $("#node-input-name").trigger("change"); |
| 227 | + } else if (properties && Array.isArray(properties) && properties.length === 0) { |
| 228 | + $("<option value='" + "" + "'> " + "No properties available" + "</option>").appendTo("#node-input-property"); |
204 | 229 | } |
205 | 230 | }); |
206 | 231 | } |
|
0 commit comments