From a2378dda4a23a7bb7eec9764c7a3b5bbbc1dd72f Mon Sep 17 00:00:00 2001
From: ulrich
Date: Wed, 21 Apr 2021 12:49:08 +0000
Subject: [PATCH] Kleine Anpassungen an Bedienelementen

---
 www/ui/js/app.js |   65 +++++++++++++++++++++++++++++---
 1 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/www/ui/js/app.js b/www/ui/js/app.js
index 0ef4266..b2162e7 100644
--- a/www/ui/js/app.js
+++ b/www/ui/js/app.js
@@ -32,6 +32,7 @@
     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.addEvtListener('#mi-switch', 'click', self.geraet_schalt_liste);
     
     self.fusszeile_umschalten();
     self.seitenleiste_umschalten();
@@ -155,6 +156,38 @@
     }
   };
   
+  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/', 
+      "", function(responseText) {
+        //var geraet = JSON.parse(responseText);
+        //self.geraet_status_form(geraet);
+      }, self.ein_aus_btn);      
+  };
+  
   this.geraet_liste = function() {
     self.entitaet_liste('Geräte','../api/store/Geraet/liste/', 
       "data/tpl/geraet_liste.txt", '../api/store/Geraet/', 
@@ -249,6 +282,14 @@
     });
   };
 
+  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();
+    });
+  };
+
   this.prefs_form = function(k) {
     self.entitaet_form('Einstellung', k, k.key,
       "data/tpl/form_einstellung.txt", '../api/store/Einstellung/',
@@ -305,7 +346,7 @@
   this.dialog_unten_zeigen = function() {
     self.vorlage_laden_und_fuellen("data/tpl/ctrl.txt", "", function (html) {
       var dlg = document.querySelector(".dialog-unten");
-      dlg.style.height = '4.5em';
+      //dlg.style.height = '10em';
       dlg.innerHTML = html;
       self.abspieler_auswahl_fuellen();
       self.abspielliste_auswahl_fuellen();
@@ -327,6 +368,12 @@
       
       self.addEvtListener('#weg-btn', 'click', self.titelWeg);
       self.addEvtListener('#leeren-btn', 'click', self.alleTitelEntfernen);
+      
+      self.addEvtListener('#media-btn', 'click', self.media_liste);
+      self.addEvtListener('#plst-btn', 'click', self.titel_liste);
+      self.addEvtListener('#live-btn', 'click', self.livestream_selection);
+      self.addEvtListener('#switch-btn', 'click', self.geraet_schalt_liste);
+    
       self.media_liste();
     });
   };
@@ -475,8 +522,8 @@
    *     var ablageort = JSON.parse(responseText);
    *     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 +538,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 +591,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 +902,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