|
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 },
|
|
47 | 51 | const connection = $("#node-input-connection").val();
|
48 | 52 | $("select#node-input-thing").empty();
|
49 | 53 | $("select#node-input-property").empty();
|
50 |
| - if(this.defaultname && connection === "_ADD_") { |
51 |
| - $("#node-input-name").val(""); |
| 54 | + if(connection === "_ADD_") { |
| 55 | + $("<option value='" + "" + "'> " + "Select a connection" + "</option>").appendTo("#node-input-thing"); |
| 56 | + if(this.defaultname){ |
| 57 | + $("#node-input-name").val(""); |
| 58 | + } |
52 | 59 | }
|
53 | 60 | if (this.connection !== connection && connection !== "_ADD_") {
|
54 | 61 | initThings(connection);
|
55 | 62 | }
|
56 | 63 | $("#node-input-thing").trigger("change");
|
57 | 64 | });
|
58 | 65 | $("#node-input-thing").change(() => {
|
59 |
| - |
60 | 66 | const thing_id = $("#node-input-thing").val();
|
| 67 | + const connection = $("#node-input-connection").val(); |
| 68 | + const thing_text = $("#node-input-thing").find('option:selected').text() |
61 | 69 | if (thing_id && thing_id !== "") {
|
62 |
| - const connection = $("#node-input-connection").val(); |
63 | 70 | initProperties(connection, thing_id, undefined, outs);
|
| 71 | + } else if (connection === "_ADD_") { |
| 72 | + $("select#node-input-property").empty(); |
| 73 | + $("<option value='" + "" + "'> " + "Select a connection" + "</option>").appendTo("#node-input-property"); |
64 | 74 | } else {
|
65 | 75 | $("select#node-input-property").empty();
|
66 |
| - } |
| 76 | + $("<option value='" + "" + "'> " + "Select a thing" + "</option>").appendTo("#node-input-property"); |
| 77 | + } |
67 | 78 | $("#node-input-property").trigger("change");
|
68 | 79 | });
|
69 | 80 | $("#node-input-property").change(() => {
|
| 81 | + debugger; |
70 | 82 | const property_name = $("#node-input-property").find('option:selected').text();
|
71 | 83 | const property_value = $("#node-input-property").find('option:selected').val();
|
72 | 84 | if (property_name !== "" && property_value !== "" && property_value !== undefined && this.defaultname) {
|
|
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