From 1b3d997c6a0734988db736050f4db93c198799e1 Mon Sep 17 00:00:00 2001 From: mirkokurt Date: Thu, 5 Dec 2019 14:37:28 +0100 Subject: [PATCH] Field checking improved --- arduino-cloud.html | 58 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/arduino-cloud.html b/arduino-cloud.html index 7a5ec12..6a8210a 100644 --- a/arduino-cloud.html +++ b/arduino-cloud.html @@ -47,45 +47,56 @@ }, paletteLabel: labelName, oneditprepare: function () { + debugger; if (this.connection && this.connection !== "_ADD_") { initThings(this.connection, this.thing); initProperties(this.connection, this.thing, this.property, outs); } $("select#node-input-connection").change((e) => { + debugger; const connection = $("#node-input-connection").val(); const thing_id = $("#node-input-thing").val(); - $("select#node-input-thing").empty(); - $("select#node-input-property").empty(); if (connection === "_ADD_") { + $("select#node-input-thing").empty(); $("").appendTo("#node-input-thing"); if (this.defaultname) { $("#node-input-name").val(""); } + $("#node-input-thing").trigger("change"); + } else { + if (thing_id !== "updating") { + $("select#node-input-thing").empty(); + $("select#node-input-property").empty(); + initThings(connection); + } } - if ((this.connection !== connection || thing_id === "") && connection !== "_ADD_") { - initThings(connection); - } - $("#node-input-thing").trigger("change"); }); $("#node-input-thing").change(() => { const thing_id = $("#node-input-thing").val(); + const property_id = $("#node-input-property").val(); const connection = $("#node-input-connection").val(); const thing_text = $("#node-input-thing").find('option:selected').text() - if (thing_id && thing_id !== "") { - initProperties(connection, thing_id, undefined, outs); - } else if (connection === "_ADD_") { + debugger; + if (connection === "_ADD_") { $("select#node-input-property").empty(); $("").appendTo("#node-input-property"); - } else { - $("select#node-input-property").empty(); - $("").appendTo("#node-input-property"); - } - $("#node-input-property").trigger("change"); + $("#node-input-property").trigger("change"); + } else if (property_id !== "updating") { + if (thing_id === undefined || thing_id === null || thing_id === "") { + $("select#node-input-property").empty(); + $("").appendTo("#node-input-property"); + $("#node-input-property").trigger("change"); + } else { + $("select#node-input-property").empty(); + initProperties(connection, thing_id, undefined, outs); + } + } }); $("#node-input-property").change(() => { const property_name = $("#node-input-property").find('option:selected').text(); const property_value = $("#node-input-property").find('option:selected').val(); - if (property_name !== "" && property_value !== "" && property_value !== undefined && this.defaultname) { + debugger; + if (property_name !== " " && property_name !== "" && property_value !== "" && property_value !== undefined && this.defaultname) { this.propname = property_name; $("#node-input-name").val(property_name); } @@ -127,9 +138,15 @@ } } function initThings(connection, thing_id) { + debugger; const queryString = prepareQueryString(connection); if (!queryString || queryString === "") return; + + $("select#node-input-thing").empty(); + $("").appendTo("#node-input-thing"); + $("select#node-input-thing").val("updating"); + $.getJSON(`things?${queryString}`, things => { $("select#node-input-thing").empty(); if (things && typeof (things) == "object" && things.error) { @@ -145,7 +162,7 @@ if (thing_id !== undefined) { $("#node-input-thing").val(thing_id); } - $("#node-input-property").trigger("change"); + $("#node-input-thing").trigger("change"); } else if (things && Array.isArray(things) && things.length === 0) { $("select#node-input-thing").empty(); $("").appendTo("#node-input-thing"); @@ -155,13 +172,18 @@ }); } function initProperties(connection, thing_id, property_id, outs) { + debugger; let queryString = prepareQueryString(connection); if (!queryString || queryString === "") return; if (!thing_id || thing_id === "" || thing_id === "0") return; queryString = `${queryString}&thing_id=${thing_id}`; - $("#node-input-property").html(""); + + $("select#node-input-property").empty(); + $("").appendTo("#node-input-property"); + $("select#node-input-property").val("updating"); + $.getJSON(`properties?${queryString}`, properties => { $("select#node-input-property").empty(); if (properties && typeof (properties) == "object" && properties.error) { @@ -178,7 +200,7 @@ if (property_id !== undefined) { $("#node-input-property").val(property_id); } - $("#node-input-name").trigger("change"); + $("#node-input-property").trigger("change"); } else if (properties && Array.isArray(properties) && properties.length === 0) { $("").appendTo("#node-input-property"); }