From 442a7a8b110a2d1a9713bbcbba64ce06be0103b6 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Wed, 24 Aug 2022 21:20:54 +0200 Subject: [PATCH] implemented action get_zone_info --- Webserver/Templates/action.html | 23 +++++++++++ Webserver/__init__.py | 4 ++ Webserver/static/js/webhook.js | 67 +++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 Webserver/Templates/action.html create mode 100644 Webserver/static/js/webhook.js diff --git a/Webserver/Templates/action.html b/Webserver/Templates/action.html new file mode 100644 index 0000000..2e5ea85 --- /dev/null +++ b/Webserver/Templates/action.html @@ -0,0 +1,23 @@ + + + + + {{ translater.getTranslation("Irrigation") }}{{ translater.getTranslation("system") }} + + + {% include "header.html" %} + +
+ +

Action

+ +
+

+ Sucess: {{ sucess }} +

+
+ +
+ + + \ No newline at end of file diff --git a/Webserver/__init__.py b/Webserver/__init__.py index 319b6a3..e126274 100644 --- a/Webserver/__init__.py +++ b/Webserver/__init__.py @@ -89,6 +89,10 @@ class Webserver: self.zoneManager.deleteIrrigationJobByID(index) case "get_zone_list": return self.zoneManager.zonesToJSON() + case "get_zone_info": + if (index): + zone = self.zoneManager.getZone(index) + return zone.toJSON() case "get_pipeline": return self.zoneManager.pipelineToJSON() return render_template('action.html', translater=self.translater, zones=self.zoneManager.zones, sucess=sucess) diff --git a/Webserver/static/js/webhook.js b/Webserver/static/js/webhook.js new file mode 100644 index 0000000..11b5f58 --- /dev/null +++ b/Webserver/static/js/webhook.js @@ -0,0 +1,67 @@ +function sleep (time) { + + return new Promise((resolve) => setTimeout(resolve, time)); + +} + + + +function send_web_request($url, $messagestring, $varstring) { + // Browserkompatibles Request-Objekt erzeugen: + r = null; + + if(window.XMLHttpRequest) + { + + r = new XMLHttpRequest(); + } + else if(window.ActiveXObject) + { + + try + { + r = new ActiveXObject('Msxml2.XMLHTTP'); + } + catch(e1) + { + try + { + r = new ActiveXObject('Microsoft.XMLHTTP'); + } + catch(e2) + { + alert("Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut."); + } + } + } + + // Wenn Request-Objekt vorhanden, dann Anfrage senden: + if(r != null) + { + + + // HTTP-POST + r.open('POST', $url, true); + + r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + + r.send($varstring); + if($messagestring != 'no') + { + alert($messagestring); + } + sleep(500).then(() => { + + //window.location.href = window.location.href; + //document.location.reload(); + + }); + + } + else + { + alert("Ein Fehler ist aufgetreten. Bitte versuchen Sie es erneut."); + } + + +} \ No newline at end of file