From a29f5ca76074f014d2a82390610797907528efc1 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Wed, 21 Apr 2021 06:37:03 +0000
Subject: [PATCH] Unterscheidung und Verarbeitung Geraete-Liste mit allen Angaben (auch Status) oder nur Name

---
 www/ui/js/app.js |   48 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/www/ui/js/app.js b/www/ui/js/app.js
index 0ef4266..5051dd6 100644
--- a/www/ui/js/app.js
+++ b/www/ui/js/app.js
@@ -155,6 +155,32 @@
     }
   };
   
+  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) {
+        var geraet = JSON.parse(responseText);
+        self.geraet_status_form(geraet);
+      }, function() {
+        self.addEvtListener('#ein-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 + "/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();
+          });
+        });        
+      });
+  };
+  
   this.geraet_liste = function() {
     self.entitaet_liste('Geräte','../api/store/Geraet/liste/', 
       "data/tpl/geraet_liste.txt", '../api/store/Geraet/', 
@@ -246,6 +272,14 @@
       "data/tpl/form_geraet.txt", '../api/store/Geraet/',
       '#geraet-name', function() { 
           self.geraet_liste();
+    });
+  };
+
+  this.geraet_status_form = function(ge) {
+    self.entitaet_form('Gerät', ge, ge.name,
+      "data/tpl/form_geraet_status.txt", '../api/store/Geraet/',
+      '#geraet-name', function() { 
+          self.geraet_schalt_liste();
     });
   };
 
@@ -476,7 +510,7 @@
    *     self.ablageort_form(ablageort);
    *   });
    */
-  this.entitaet_liste = function(bname, listUrl, tpl, storeUrl, formFunc, cb) {
+  this.entitaet_liste = function(bname, listUrl, tpl, storeUrl, formFunc, cb, customListCode) {
     self.reset_top_buttons();
     document.querySelector('.bereich-name').textContent = bname;
     var bb = document.querySelector('.breadcrumb-behaelter');
@@ -491,7 +525,12 @@
         //self.addEvtListener('#neu-btn', 'click', function (event) {
         self.addEvtListener('#top-neu-btn', 'click', function(event) {
           eval(formFunc + "(this)");
-        });        
+        });                
+        if(typeof(customListCode) !== 'function') {
+          // ..
+        } else {
+          customListCode();
+        }        
       });
     });
   };  
@@ -539,8 +578,6 @@
     event.preventDefault();
     const data = new FormData(event.target);
     const value = Object.fromEntries(data.entries());
-    //console.log({ value });
-    //console.log(JSON.stringify(value));
     var daten = JSON.stringify(value);
     var formkey = document.querySelector(keySelector).value;
     formkey = formkey.replace(' ', '').replace(/[\W]+/g, '');
@@ -852,9 +889,10 @@
   this.album  = a;
 }
 
-function Geraet(n, e, a, s) {
+function Geraet(n, e, a, s, st) {
   this.name = n;
   this.einUrl = e;
   this.ausUrl = a;
   this.statusUrl = s;
+  this.status = st;
 }
\ No newline at end of file

--
Gitblit v1.9.3