From 849ee289c2a0561b709f92f8cbbda00415c6caba Mon Sep 17 00:00:00 2001
From: ulrich
Date: Fri, 16 Apr 2021 08:10:03 +0000
Subject: [PATCH] Erste Fassung der Geraete-Liste zum Ein- und Ausschalten funktioniert

---
 www/ui/js/app.js |   68 ++++++++++++++++++++++++++++++++--
 1 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/www/ui/js/app.js b/www/ui/js/app.js
index 5be012f..98a5675 100644
--- a/www/ui/js/app.js
+++ b/www/ui/js/app.js
@@ -31,6 +31,7 @@
     self.addEvtListener('#mi-listen', 'click', self.abspielliste_liste);
     self.addEvtListener('#mi-list', 'click', self.titel_liste);
     self.addEvtListener('#mi-live', 'click', self.livestream_liste);
+    self.addEvtListener('#mi-devices', 'click', self.geraet_liste);
     
     self.fusszeile_umschalten();
     self.seitenleiste_umschalten();
@@ -154,6 +155,39 @@
     }
   };
   
+  this.geraet_schalt_liste = function() {
+    self.entitaet_liste('Geräte schalten','../api/store/Geraet/liste/', 
+      "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.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);
+          });
+        });        
+      });
+  };
+  
+  this.geraet_liste = function() {
+    self.entitaet_liste('Geräte','../api/store/Geraet/liste/', 
+      "data/tpl/geraet_liste.txt", '../api/store/Geraet/', 
+      "self.geraet_form", function(responseText) {
+        var geraet = JSON.parse(responseText);
+        self.geraet_form(geraet);
+      });
+  };
+
   this.ablageort_liste = function() {
     self.entitaet_liste('Kataloge','../api/store/Ablageort/liste/', 
       "data/tpl/ablageort_liste.txt", '../api/store/Ablageort/', 
@@ -228,6 +262,22 @@
       "data/tpl/form_livestream.txt", '../api/store/Livestream/',
       '#livestream-name', function() { 
           self.livestream_liste();
+    });
+  };
+
+  this.geraet_form = function(ge) {
+    self.entitaet_form('Gerät', ge, ge.name,
+      "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();
     });
   };
 
@@ -458,7 +508,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');
@@ -473,7 +523,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();
+        }        
       });
     });
   };  
@@ -521,8 +576,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, '');
@@ -832,4 +885,11 @@
   this.interpret = i;
   this.titelAnzName = t;
   this.album  = a;
+}
+
+function Geraet(n, e, a, s) {
+  this.name = n;
+  this.einUrl = e;
+  this.ausUrl = a;
+  this.statusUrl = s;
 }
\ No newline at end of file

--
Gitblit v1.9.3