Skip to content

Commit 1b3d997

Browse files
committed
Field checking improved
1 parent 1befc9f commit 1b3d997

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

arduino-cloud.html

+40-18
Original file line numberDiff line numberDiff line change
@@ -47,45 +47,56 @@
4747
},
4848
paletteLabel: labelName,
4949
oneditprepare: function () {
50+
debugger;
5051
if (this.connection && this.connection !== "_ADD_") {
5152
initThings(this.connection, this.thing);
5253
initProperties(this.connection, this.thing, this.property, outs);
5354
}
5455
$("select#node-input-connection").change((e) => {
56+
debugger;
5557
const connection = $("#node-input-connection").val();
5658
const thing_id = $("#node-input-thing").val();
57-
$("select#node-input-thing").empty();
58-
$("select#node-input-property").empty();
5959
if (connection === "_ADD_") {
60+
$("select#node-input-thing").empty();
6061
$("<option value='" + "" + "'> " + "No connection selected" + "</option>").appendTo("#node-input-thing");
6162
if (this.defaultname) {
6263
$("#node-input-name").val("");
6364
}
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+
}
6472
}
65-
if ((this.connection !== connection || thing_id === "") && connection !== "_ADD_") {
66-
initThings(connection);
67-
}
68-
$("#node-input-thing").trigger("change");
6973
});
7074
$("#node-input-thing").change(() => {
7175
const thing_id = $("#node-input-thing").val();
76+
const property_id = $("#node-input-property").val();
7277
const connection = $("#node-input-connection").val();
7378
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_") {
7781
$("select#node-input-property").empty();
7882
$("<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+
}
8494
});
8595
$("#node-input-property").change(() => {
8696
const property_name = $("#node-input-property").find('option:selected').text();
8797
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) {
89100
this.propname = property_name;
90101
$("#node-input-name").val(property_name);
91102
}
@@ -127,9 +138,15 @@
127138
}
128139
}
129140
function initThings(connection, thing_id) {
141+
debugger;
130142
const queryString = prepareQueryString(connection);
131143
if (!queryString || queryString === "")
132144
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+
133150
$.getJSON(`things?${queryString}`, things => {
134151
$("select#node-input-thing").empty();
135152
if (things && typeof (things) == "object" && things.error) {
@@ -145,7 +162,7 @@
145162
if (thing_id !== undefined) {
146163
$("#node-input-thing").val(thing_id);
147164
}
148-
$("#node-input-property").trigger("change");
165+
$("#node-input-thing").trigger("change");
149166
} else if (things && Array.isArray(things) && things.length === 0) {
150167
$("select#node-input-thing").empty();
151168
$("<option value='" + "" + "'> " + "No things available" + "</option>").appendTo("#node-input-thing");
@@ -155,13 +172,18 @@
155172
});
156173
}
157174
function initProperties(connection, thing_id, property_id, outs) {
175+
debugger;
158176
let queryString = prepareQueryString(connection);
159177
if (!queryString || queryString === "")
160178
return;
161179
if (!thing_id || thing_id === "" || thing_id === "0")
162180
return;
163181
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+
165187
$.getJSON(`properties?${queryString}`, properties => {
166188
$("select#node-input-property").empty();
167189
if (properties && typeof (properties) == "object" && properties.error) {
@@ -178,7 +200,7 @@
178200
if (property_id !== undefined) {
179201
$("#node-input-property").val(property_id);
180202
}
181-
$("#node-input-name").trigger("change");
203+
$("#node-input-property").trigger("change");
182204
} else if (properties && Array.isArray(properties) && properties.length === 0) {
183205
$("<option value='" + "" + "'> " + "No properties available" + "</option>").appendTo("#node-input-property");
184206
}

0 commit comments

Comments
 (0)