From fcc734a744409e307d334a1f8f4bfcfc0a319cb1 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Thu, 08 Apr 2021 19:41:43 +0000
Subject: [PATCH] Titel auf Abspielliste, Abspielliste anzeigen, Eintrag auswaehlen

---
 src/de/uhilger/mediaz/api/ListHandler.java |    2 +-
 www/ui/js/app.js                           |   22 ++++++++++++++++++----
 src/de/uhilger/mediaz/api/JsonHelper.java  |   16 ++++++++++++++++
 www/ui/data/tpl/titel_liste.tpl            |   14 ++++++++++----
 4 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/src/de/uhilger/mediaz/api/JsonHelper.java b/src/de/uhilger/mediaz/api/JsonHelper.java
index 1c91930..b84c51e 100644
--- a/src/de/uhilger/mediaz/api/JsonHelper.java
+++ b/src/de/uhilger/mediaz/api/JsonHelper.java
@@ -28,6 +28,7 @@
   }
   
   public String jsonWithCustomType(Object o, String typeName) {
+    /*
     StringBuilder sb = new StringBuilder();
     sb.append("{\"");
     sb.append(typeName);
@@ -36,6 +37,21 @@
     sb.append(gson.toJson(o));
     sb.append("}");
     return sb.toString();
+    */
+    Gson gson = new Gson();
+    return embedInCustomType(gson.toJson(o), typeName);
+  }
+  
+  public String embedInCustomType(String jsonStr, String typeName) {
+    StringBuilder sb = new StringBuilder();
+    sb.append("{\"");
+    sb.append(typeName);
+    sb.append("\": ");
+    //Gson gson = new Gson();
+    //sb.append(gson.toJson(o));
+    sb.append(jsonStr);
+    sb.append("}");
+    return sb.toString();
   }
   
 }
diff --git a/src/de/uhilger/mediaz/api/ListHandler.java b/src/de/uhilger/mediaz/api/ListHandler.java
index 02cf740..b947f5e 100644
--- a/src/de/uhilger/mediaz/api/ListHandler.java
+++ b/src/de/uhilger/mediaz/api/ListHandler.java
@@ -51,7 +51,7 @@
     String plname = elems[elems.length - 1];
     FileStorage fs = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF)));
     String json = fs.readJson(FileStorage.ST_ABSPIELLISTE, plname);
-    return json;
+    return embedInCustomType(json, FileStorage.ST_ABSPIELLISTE);
   }
 
   @Override
diff --git a/www/ui/data/tpl/titel_liste.tpl b/www/ui/data/tpl/titel_liste.tpl
index 5d32852..d05e0cb 100644
--- a/www/ui/data/tpl/titel_liste.tpl
+++ b/www/ui/data/tpl/titel_liste.tpl
@@ -1,12 +1,18 @@
+
+<!--
+{"Abspielliste": {"name":"spontan","titel":[{"katalogUrl":"/media/mc","name":"/A/ACDC/Highway-To-Hell02-Girls-got-rhythm.mp3"},{"katalogUrl":"/media/mc","name":"/A/ACDC/Highway-To-Hell07-Get-it-hot.mp3"},{"katalogUrl":"/media/mc","name":"/A/Aerosmith/Big-Ones12-Crazy.mp3"}]}}
+-->
+
+{{#Abspielliste}}
 <div class='entity-formular'>
   <div class='entity-liste-kopf'>
     Abspielliste {{name}}     
     <!-- <button class='ctrl-btn' id='neu-btn' title='Neu'><i class='icon-doc'></i></button> -->
   </div>
   <ul class='entity-liste'>
-    {{#ArrayList}}
-    <li class='entity-eintrag'>{{.}}</li>
-    {{/ArrayList}}
+    {{#titel}}
+    <li class='entity-eintrag'>{{katalogUrl}}{{name}}</li>
+    {{/titel}}
   </ul>
 </div>
-
+{{/Abspielliste}}
diff --git a/www/ui/js/app.js b/www/ui/js/app.js
index 3f8f2b6..a28d20b 100644
--- a/www/ui/js/app.js
+++ b/www/ui/js/app.js
@@ -74,19 +74,28 @@
   /* ---------------- Titel einer Abspielliste ----------------- */
   
   this.titel_liste = function() {
-    self.http_get('../api/store/Ablageort/liste/', function (responseText) {
-      self.vorlage_laden_und_fuellen("data/tpl/ablageort_liste.tpl", JSON.parse(responseText), function (html) {
+    self.reset_top_buttons();
+    var plname = document.querySelector('#playlist').value;
+    self.http_get('../api/alist/' + plname, function (responseText) {
+      self.vorlage_laden_und_fuellen("data/tpl/titel_liste.tpl", JSON.parse(responseText), function (html) {
         document.querySelector(".zentraler-inhalt").innerHTML = html;
         self.addEvtListener('.entity-eintrag', 'click', function (event) {
           var t = event.target;
+          self.removeClassMulti('selected');
+          t.classList.add('selected');
+
+          /*
           self.http_get('../api/store/Ablageort/' + t.textContent, function(responseText){
             var ablageort = JSON.parse(responseText);
             self.ablageort_form(ablageort);
           });
+          */
         });
+        /*
         self.addEvtListener('#neu-btn', 'click', function (event) {
           eval("self.ablageort_form" + "(this)");
-        });        
+        });
+        */
       });
     });
   };
@@ -165,7 +174,12 @@
   
   this.addSelectedTitel = function() {
     var titelName = document.querySelector(".selected").textContent;
-    var titel = new Titel(self.mediaPfad + titelName, self.ortPfad);
+    var titel;
+    if(self.mediaPfad.endsWith('/')) {
+      titel = new Titel(self.mediaPfad + titelName, self.ortPfad);
+    } else {
+      titel = new Titel(self.mediaPfad + '/' + titelName, self.ortPfad);
+    }
     var plname = document.querySelector('#playlist').value;
     self.http_put('../api/alist/' + plname, JSON.stringify(titel), function(responseText) {
       self.meldung_mit_timeout(responseText, 1500);

--
Gitblit v1.9.3