|
47 | 47 | }, |
48 | 48 | paletteLabel: labelName, |
49 | 49 | oneditprepare: function () { |
| 50 | + debugger; |
50 | 51 | if (this.connection && this.connection !== "_ADD_") { |
51 | 52 | initThings(this.connection, this.thing); |
52 | 53 | initProperties(this.connection, this.thing, this.property, outs); |
53 | 54 | } |
54 | 55 | $("select#node-input-connection").change((e) => { |
| 56 | + debugger; |
55 | 57 | const connection = $("#node-input-connection").val(); |
56 | 58 | const thing_id = $("#node-input-thing").val(); |
57 | | - $("select#node-input-thing").empty(); |
58 | | - $("select#node-input-property").empty(); |
59 | 59 | if (connection === "_ADD_") { |
| 60 | + $("select#node-input-thing").empty(); |
60 | 61 | $("<option value='" + "" + "'> " + "No connection selected" + "</option>").appendTo("#node-input-thing"); |
61 | 62 | if (this.defaultname) { |
62 | 63 | $("#node-input-name").val(""); |
63 | 64 | } |
| 65 | + $("#node-input-thing").trigger("change"); |
| 66 | + } else { |
| 67 | + if (thing_id !== "updating") { |
| 68 | + $("select#node-input-thing").empty(); |
| 69 | + $("select#node-input-property").empty(); |
| 70 | + initThings(connection); |
| 71 | + } |
64 | 72 | } |
65 | | - if ((this.connection !== connection || thing_id === "") && connection !== "_ADD_") { |
66 | | - initThings(connection); |
67 | | - } |
68 | | - $("#node-input-thing").trigger("change"); |
69 | 73 | }); |
70 | 74 | $("#node-input-thing").change(() => { |
71 | 75 | const thing_id = $("#node-input-thing").val(); |
| 76 | + const property_id = $("#node-input-property").val(); |
72 | 77 | const connection = $("#node-input-connection").val(); |
73 | 78 | const thing_text = $("#node-input-thing").find('option:selected').text() |
74 | | - if (thing_id && thing_id !== "") { |
75 | | - initProperties(connection, thing_id, undefined, outs); |
76 | | - } else if (connection === "_ADD_") { |
| 79 | + debugger; |
| 80 | + if (connection === "_ADD_") { |
77 | 81 | $("select#node-input-property").empty(); |
78 | 82 | $("<option value='" + "" + "'> " + "No connection selected" + "</option>").appendTo("#node-input-property"); |
79 | | - } else { |
80 | | - $("select#node-input-property").empty(); |
81 | | - $("<option value='" + "" + "'> " + "No thing selected" + "</option>").appendTo("#node-input-property"); |
82 | | - } |
83 | | - $("#node-input-property").trigger("change"); |
| 83 | + $("#node-input-property").trigger("change"); |
| 84 | + } else if (property_id !== "updating") { |
| 85 | + if (thing_id === undefined || thing_id === null || thing_id === "") { |
| 86 | + $("select#node-input-property").empty(); |
| 87 | + $("<option value='" + "" + "'> " + "No thing selected" + "</option>").appendTo("#node-input-property"); |
| 88 | + $("#node-input-property").trigger("change"); |
| 89 | + } else { |
| 90 | + $("select#node-input-property").empty(); |
| 91 | + initProperties(connection, thing_id, undefined, outs); |
| 92 | + } |
| 93 | + } |
84 | 94 | }); |
85 | 95 | $("#node-input-property").change(() => { |
86 | 96 | const property_name = $("#node-input-property").find('option:selected').text(); |
87 | 97 | const property_value = $("#node-input-property").find('option:selected').val(); |
88 | | - if (property_name !== "" && property_value !== "" && property_value !== undefined && this.defaultname) { |
| 98 | + debugger; |
| 99 | + if (property_name !== " " && property_name !== "" && property_value !== "" && property_value !== undefined && this.defaultname) { |
89 | 100 | this.propname = property_name; |
90 | 101 | $("#node-input-name").val(property_name); |
91 | 102 | } |
|
127 | 138 | } |
128 | 139 | } |
129 | 140 | function initThings(connection, thing_id) { |
| 141 | + debugger; |
130 | 142 | const queryString = prepareQueryString(connection); |
131 | 143 | if (!queryString || queryString === "") |
132 | 144 | return; |
| 145 | + |
| 146 | + $("select#node-input-thing").empty(); |
| 147 | + $("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-thing"); |
| 148 | + $("select#node-input-thing").val("updating"); |
| 149 | + |
133 | 150 | $.getJSON(`things?${queryString}`, things => { |
134 | 151 | $("select#node-input-thing").empty(); |
135 | 152 | if (things && typeof (things) == "object" && things.error) { |
|
145 | 162 | if (thing_id !== undefined) { |
146 | 163 | $("#node-input-thing").val(thing_id); |
147 | 164 | } |
148 | | - $("#node-input-property").trigger("change"); |
| 165 | + $("#node-input-thing").trigger("change"); |
149 | 166 | } else if (things && Array.isArray(things) && things.length === 0) { |
150 | 167 | $("select#node-input-thing").empty(); |
151 | 168 | $("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-thing"); |
|
155 | 172 | }); |
156 | 173 | } |
157 | 174 | function initProperties(connection, thing_id, property_id, outs) { |
| 175 | + debugger; |
158 | 176 | let queryString = prepareQueryString(connection); |
159 | 177 | if (!queryString || queryString === "") |
160 | 178 | return; |
161 | 179 | if (!thing_id || thing_id === "" || thing_id === "0") |
162 | 180 | return; |
163 | 181 | queryString = `${queryString}&thing_id=${thing_id}`; |
164 | | - $("#node-input-property").html(""); |
| 182 | + |
| 183 | + $("select#node-input-property").empty(); |
| 184 | + $("<option value='" + "updating" + "'> " + "" + "</option>").appendTo("#node-input-property"); |
| 185 | + $("select#node-input-property").val("updating"); |
| 186 | + |
165 | 187 | $.getJSON(`properties?${queryString}`, properties => { |
166 | 188 | $("select#node-input-property").empty(); |
167 | 189 | if (properties && typeof (properties) == "object" && properties.error) { |
|
178 | 200 | if (property_id !== undefined) { |
179 | 201 | $("#node-input-property").val(property_id); |
180 | 202 | } |
181 | | - $("#node-input-name").trigger("change"); |
| 203 | + $("#node-input-property").trigger("change"); |
182 | 204 | } else if (properties && Array.isArray(properties) && properties.length === 0) { |
183 | 205 | $("<option value='" + "" + "'> " + "No properties available" + "</option>").appendTo("#node-input-property"); |
184 | 206 | } |
|
0 commit comments