From 5bf530d39a7e06bdd982a5c2495ff9a04fd83da4 Mon Sep 17 00:00:00 2001
From: undisclosed
Date: Wed, 11 Jan 2023 17:38:22 +0000
Subject: [PATCH] Erste Versuche mit StreamHandler

---
 www/js/app.js |  144 ++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 126 insertions(+), 18 deletions(-)

diff --git a/www/js/app.js b/www/js/app.js
index 752e918..9b634bb 100644
--- a/www/js/app.js
+++ b/www/js/app.js
@@ -4,8 +4,8 @@
   var cache; // mustache templates
   var ortPfad;
   var mediaPfad;
-  var katUrl;
-  var selTitel;
+  //var katUrl;
+  //var selTitel;
   var katName;
 
   this.init = function () {
@@ -38,7 +38,7 @@
     self.seitenleiste_umschalten();
     self.dialog_unten_zeigen();
   };
-  
+    
   /* ---------------- Entitaets-Listen ----------------- */
   
   this.livestream_selection = function() {
@@ -374,7 +374,14 @@
       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.addEvtListener('#voldn-btn', 'click', function() {
+        self.kommando('voldn');
+      });
+      self.addEvtListener('#volup-btn', 'click', function() {
+        self.kommando('volup');
+      });
+      
       self.media_liste();
     });
   };
@@ -395,6 +402,47 @@
           self.removeClassMulti('selected');
           t.classList.add('selected');
         });
+        self.addEvtListener('.entity-eintrag', 'dragstart', function (e) {
+          //console.log("drag started");          
+          e.dataTransfer.setData('text/plain', e.target.textContent);
+          setTimeout(() => {
+                  e.target.classList.add('hide');
+                  e.target.classList.add('drag-elem');
+          }, 0);          
+        });
+        self.addEvtListener('.entity-eintrag', 'dragenter', function (e) {
+          e.preventDefault();
+          //console.log("drag enter");
+          e.target.classList.add('drag-over');
+        });
+        self.addEvtListener('.entity-eintrag', 'dragover', function (e) {
+          e.preventDefault();
+          //console.log("drag over");
+          e.target.classList.add('drag-over');
+        });
+        self.addEvtListener('.entity-eintrag', 'dragleave', function (e) {
+          //console.log("drag leave");
+          e.target.classList.remove('drag-over');
+        });
+        self.addEvtListener('.entity-eintrag', 'drop', function (e) {     
+          e.preventDefault();
+          //console.log("drop");
+          //console.log("index: " + self.getIndexBySelector('drag-over'));
+          const pos = self.getIndexBySelector('drag-elem');
+          const zielPos = self.getIndexBySelector('drag-over');
+          const titeltext = e.dataTransfer.getData('text/plain');
+          const draggable = document.querySelector(".drag-elem");
+          draggable.classList.remove("drag-elem");
+          e.target.classList.remove('drag-over');
+          var plname = document.querySelector('#playlist').value;
+          self.http_put('api/alist/' + plname + "/" + pos + "/" + zielPos, '', function(responseText) {
+            //self.meldung_mit_timeout(responseText, 1500);
+          });
+          ulElem = draggable.parentElement;
+          ulElem.removeChild(draggable);          
+          e.target.insertAdjacentElement('beforebegin', draggable);
+          draggable.classList.remove('hide');
+        });             
       });
     });
   };  
@@ -444,7 +492,9 @@
   this.kommando = function(kommando) {
     var abs = document.querySelector('#abspieler').value;
     self.http_get('api/strg/' + abs + '/' + kommando, function(responseText) {
-      self.meldung_mit_timeout(responseText, 1500);
+      if(kommando !== 'volup' && kommando !== 'voldn') {
+        self.meldung_mit_timeout(responseText, 1500);
+      }
     });
   };
   
@@ -485,6 +535,32 @@
     console.log('url: ' + url);
     //window.open(url);
   };  
+  
+  this.gehe_zu_dialog_zeigen = function () {
+    self.dialog_laden_und_zeigen('data/tpl/gehe-zu.txt', '', function(){
+      const form = document.querySelector('form');      
+      form.addEventListener('submit', function(event) {
+        // hier gehe zu realisieren
+        event.preventDefault();
+        const data = new FormData(event.target);
+        const value = Object.fromEntries(data.entries());
+        var daten = JSON.stringify(value);
+        console.log('gehe zu mit ' + daten);
+        var sekunden = (value['std'] * 3600) + (value['min'] * 60) + (value['sek'] * 1);
+        if(value['richtung'] === 'zurueck') {
+          sekunden *= -1;
+        }
+        console.log('sekunden: ' + sekunden);
+        self.dialog_schliessen();
+        // HTTP GET /mz/api/strg/abspieler/seek/[sekunden]
+        self.kommando('seek/' + sekunden);
+      });
+      self.addEvtListener('#cancel-btn', 'click', function(event) {
+        self.dialog_schliessen();
+      });
+      self.menue_umschalten();    
+    });
+  };
     
   /* ------------- Verwaltungsfunktionen Abspielliste -------------------- */
   
@@ -497,6 +573,17 @@
     });
   };
   
+  /*
+   * {
+   *  "katalogUrl":"/media",
+   *  "pfad":"/Musik/B/Bay-City-Rollers/Original-Album-Classics/3/",
+   *  "name":"3-37-Love-Is.mp3",
+   *  "interpret":"Bay City Rollers",
+   *  "titelAnzName":"Love Is",
+   *  "album":"Original Album Classics"
+   * }
+   * @returns {undefined}
+   */
   this.titelDazu = function() {
     var titel = self.titelErmitteln(document.querySelector(".selected"));
     //var titelName = elem.textContent;
@@ -519,20 +606,22 @@
   };  
   
   this.titelWeg = function() {
-    var elem = document.querySelector(".selected");
-    var parentElem = elem.parentNode;
+    //var elem = document.querySelector(".selected");
+    //var parentElem = elem.parentNode;
     //console.log("elem: " + elem.nodeName + ", parent: " + parentElem.nodeName + ", len: " + parentElem.childNodes.length);
-    var liElems = parentElem.getElementsByTagName(elem.nodeName); // nur die LI Elemente
+    //var liElems = parentElem.getElementsByTagName(elem.nodeName); // nur die LI Elemente
     //console.log("liElems.anz: " + liElems.length);
-    var gefunden = false;
-    for(var i = 0; i < liElems.length && !gefunden; i++) {
+    //var gefunden = false;
+    //for(var i = 0; i < liElems.length && !gefunden; i++) {
       //console.log(liElems.item(i).textContent);
-      if(liElems.item(i).classList.contains("selected")) {
-        gefunden = true;
-        var index = i;
+      //if(liElems.item(i).classList.contains("selected")) {
+        //gefunden = true;
+        //var index = i;
         //console.log(elem.textContent + ' hat Index ' + i);
-      }
-    }
+      //}
+    //}
+    
+    const index = self.getIndexBySelector("selected");
     // /mz/api/alist/[pl-name]/[nr] 
     var plname = document.querySelector('#playlist').value;
     self.http_delete('api/alist/' + plname + '/' + index,'', function(responseText) {
@@ -541,6 +630,26 @@
       self.titel_liste();
     });
     
+  };
+  
+  this.getIndexBySelector = function(selector) {
+    var qSel = '.' + selector;
+    var elem = document.querySelector(qSel);
+    var parentElem = elem.parentNode;
+    //console.log("elem: " + elem.nodeName + ", parent: " + parentElem.nodeName + ", len: " + parentElem.childNodes.length);
+    var liElems = parentElem.getElementsByTagName(elem.nodeName); // nur die LI Elemente
+    //console.log("liElems.anz: " + liElems.length);
+    var gefunden = false;
+    var index = -1;
+    for(var i = 0; i < liElems.length && !gefunden; i++) {
+      //console.log(liElems.item(i).textContent);
+      if(liElems.item(i).classList.contains(selector)) {
+        gefunden = true;
+        index = i;
+        //console.log(elem.textContent + ' hat Index ' + i);
+      }
+    }
+    return index;
   };
   
   /* ------------- Helfer fuer Entitaets-Formulare ----------------------- */
@@ -712,15 +821,14 @@
     self.http_call('DELETE', u, data, cb);
   };
   
-  this.http_call = function (method, u, data, scallback) {
+  this.http_call = function (method, callurl, data, scallback) {
     var xhr = new XMLHttpRequest();
-    var url = u;
     xhr.onreadystatechange = function () {
       if (this.readyState === 4 && this.status === 200) {
         scallback(this.responseText);
       }
     };
-    xhr.open(method, url);
+    xhr.open(method, callurl);
     if (method === 'GET') {
       xhr.send();
     } else if (method === 'POST' || method === 'PUT' || method === 'DELETE') {

--
Gitblit v1.9.3