|
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 || thing_id === "") && connection !== "_ADD_") { |
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(() => { |
|
117 | 129 | $.getJSON(`things?${queryString}`, things => { |
118 | 130 | $("select#node-input-thing").empty(); |
119 | 131 | if (things && typeof (things) == "object" && things.error) { |
| 132 | + $("select#node-input-thing").empty(); |
120 | 133 | $("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-thing"); |
| 134 | + $("select#node-input-property").empty(); |
| 135 | + $("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-property"); |
121 | 136 | } else if (things && Array.isArray(things) && things.length !== 0) { |
122 | 137 | $("<option value='" + "" + "'> " + "Select a thing" + "</option>").appendTo("#node-input-thing"); |
123 | 138 | for (const t of things) { |
|
127 | 142 | $("#node-input-thing").val(thing_id); |
128 | 143 | } |
129 | 144 | $("#node-input-property").trigger("change"); |
| 145 | + } else if (things && Array.isArray(things) && things.length === 0) { |
| 146 | + $("select#node-input-thing").empty(); |
| 147 | + $("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-thing"); |
| 148 | + $("select#node-input-property").empty(); |
| 149 | + $("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-property"); |
130 | 150 | } |
131 | 151 | }); |
132 | 152 | } |
|
141 | 161 | $.getJSON(`properties?${queryString}`, properties => { |
142 | 162 | $("select#node-input-property").empty(); |
143 | 163 | if (properties && typeof (properties) == "object" && properties.error) { |
| 164 | + $("select#node-input-thing").empty(); |
144 | 165 | $("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-thing"); |
| 166 | + $("select#node-input-property").empty(); |
| 167 | + $("<option value='" + "" + "'> " + things.error + "</option>").appendTo("#node-input-property"); |
145 | 168 | } else if ((properties && Array.isArray(properties) && properties.length !== 0)) { |
146 | 169 | $("<option value='" + "" + "'> " + "Select a property" + "</option>").appendTo("#node-input-property"); |
147 | 170 | for (const p of properties) { |
|
152 | 175 | $("#node-input-property").val(property_id); |
153 | 176 | } |
154 | 177 | $("#node-input-name").trigger("change"); |
| 178 | + } else if (properties && Array.isArray(properties) && properties.length === 0) { |
| 179 | + $("<option value='" + "" + "'> " + "No properties available" + "</option>").appendTo("#node-input-property"); |
155 | 180 | } |
156 | 181 | }); |
157 | 182 | } |
|
0 commit comments