From 39ebae580a05e74e3124b6a7917eb49fb46de8fb Mon Sep 17 00:00:00 2001
From: ulrich
Date: Wed, 21 Apr 2021 10:14:37 +0000
Subject: [PATCH] Ein/Aus-Schalter verbessert

---
 www/ui/js/app.js |   67 ++++++++++++++-------------------
 1 files changed, 28 insertions(+), 39 deletions(-)

diff --git a/www/ui/js/app.js b/www/ui/js/app.js
index 4d1d0cf..1689f28 100644
--- a/www/ui/js/app.js
+++ b/www/ui/js/app.js
@@ -156,47 +156,36 @@
     }
   };
   
+  this.ein_aus_btn = function() {
+    self.addEvtListener('#ein-aus-btn', 'click', function (event) {
+      var geraetName = event.target.attributes.gname.nodeValue;
+      var nameElem = event.target.parentNode.querySelector('.schalt-geraet-name');
+      if(nameElem.classList.contains('schalt-geraet-true')) {
+        // ausschalten
+        self.http_get('../api/gstrg/geraet/' + geraetName + "/aus", function(responseText) {
+          // console.log(responseText);
+          self.geraet_schalt_liste();
+        });
+      } else {
+        // einschalten            
+        self.http_get('../api/gstrg/geraet/' + geraetName + "/ein", function(responseText) {
+          // console.log(responseText);
+          self.geraet_schalt_liste();
+        });
+      }
+    });
+  };
+  
   this.geraet_schalt_liste = function() {
+    /*self.entitaet_liste('Geräte schalten','../api/store/Geraet/listealles/', 
+      "data/tpl/geraet_schalt_liste.txt", '../api/store/Geraet/', 
+      "self.form_geraet_status", function(responseText) {*/
     self.entitaet_liste('Geräte schalten','../api/store/Geraet/listealles/', 
       "data/tpl/geraet_schalt_liste.txt", '../api/store/Geraet/', 
-      "self.form_geraet_status", function(responseText) {
-        var geraet = JSON.parse(responseText);
-        self.geraet_status_form(geraet);
-      }, function() {
-        self.addEvtListener('#ein-aus-btn', 'click', function (event) {
-          var geraetName = event.target.attributes.gname.nodeValue;
-          var nameElem = event.target.parentNode.querySelector('.schalt-geraet-name');
-          if(nameElem.classList.contains('schalt-geraet-true')) {
-            // ausschalten
-            self.http_get('../api/gstrg/geraet/' + geraetName + "/aus", function(responseText) {
-              // console.log(responseText);
-              self.geraet_schalt_liste();
-            });
-          } else {
-            // einschalten            
-            self.http_get('../api/gstrg/geraet/' + geraetName + "/ein", function(responseText) {
-              // console.log(responseText);
-              self.geraet_schalt_liste();
-            });
-          }
-          /*
-          self.http_get('../api/gstrg/geraet/' + geraetName + "/ein", function(responseText) {
-            // console.log(responseText);
-            self.geraet_schalt_liste();
-          });
-          */
-        });
-        /*
-        self.addEvtListener('#aus-btn', 'click', function (event) {
-          var geraetName = event.target.attributes.gname.nodeValue;
-          //var geraetName = document.querySelector('.schalt-geraet-name').textContent;
-          self.http_get('../api/gstrg/geraet/' + geraetName + "/aus", function(responseText) {
-            // console.log(responseText);
-            self.geraet_schalt_liste();
-          });
-        });
-        */
-      });
+      "", function(responseText) {
+        //var geraet = JSON.parse(responseText);
+        //self.geraet_status_form(geraet);
+      }, self.ein_aus_btn);      
   };
   
   this.geraet_liste = function() {
@@ -533,7 +522,7 @@
    *     var ablageort = JSON.parse(responseText);
    *     self.ablageort_form(ablageort);
    *   });
-   */
+   */  
   this.entitaet_liste = function(bname, listUrl, tpl, storeUrl, formFunc, cb, customListCode) {
     self.reset_top_buttons();
     document.querySelector('.bereich-name').textContent = bname;

--
Gitblit v1.9.3