| | |
| | | self.dialog_unten_zeigen(); |
| | | }; |
| | | |
| | | /* |
| | | * Der StorageHandler verarbeitet Entitaeten mit z.B. |
| | | * HTTP PUT Ablageort/[Name] |
| | | * und erwartet dabei eine JSON-Struktur, die der Entitaet entspricht. |
| | | * Beim Ablageort z.B. |
| | | * private String name; |
| | | * private String ort; |
| | | * private String url; |
| | | * |
| | | * Im HTML-Formular muessen die input-Elemente mit name="..." |
| | | * so genannt werden wie die Felder der Entitaet. Fuer Ablageort also |
| | | * |
| | | * <input name="name" |
| | | * <input name="ort" |
| | | * <input name="url" |
| | | * |
| | | * Auf diese Weise kann eine generische Funktion die Formulardaten |
| | | * an den REST-Endpunkt des Servers uebermitteln. |
| | | */ |
| | | /* |
| | | this.test_form = function() { |
| | | self.vorlage_laden_und_fuellen("data/tpl/test_form.tpl", "", function (html) { |
| | | document.querySelector(".zentraler-inhalt").innerHTML = html; |
| | | const form = document.querySelector('form'); |
| | | form.addEventListener('submit', self.handleSubmit); |
| | | }); |
| | | }; |
| | | |
| | | this.handleSubmit = function(event) { |
| | | event.preventDefault(); |
| | | const data = new FormData(event.target); |
| | | const value = Object.fromEntries(data.entries()); |
| | | console.log({ value }); |
| | | console.log(JSON.stringify(value)); |
| | | }; |
| | | */ |
| | | |
| | | this.abspieler_auswahl_fuellen = function() { |
| | | self.http_get('../api/store/Abspieler/', function (responseText) { |
| | | /* |
| | | {"ArrayList": [{"name":"Wohnz","url":"http://rpi4-wz:9090/"},{"name":"Arbz","url":"http://rpi4-az:9090/"}]} |
| | | */ |
| | | self.vorlage_laden_und_fuellen("data/tpl/abs_sel.tpl", JSON.parse(responseText), function (html) { |
| | | document.querySelector(".abs-sel").innerHTML = html; |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | this.abspielliste_auswahl_fuellen = function() { |
| | | self.http_get('../api/store/Abspielliste/', function (responseText) { |
| | | /* |
| | | ? |
| | | */ |
| | | self.vorlage_laden_und_fuellen("data/tpl/pl_sel.tpl", JSON.parse(responseText), function (html) { |
| | | document.querySelector(".pl-sel").innerHTML = html; |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | /* Unterer Einblendbereich */ |
| | | |
| | | this.dialog_unten_zeigen = function() { |
| | | self.vorlage_laden_und_fuellen("data/tpl/ctrl.tpl", "", function (html) { |
| | | var dlg = document.querySelector(".dialog-unten"); |
| | | dlg.style.height = '4.5em'; |
| | | dlg.innerHTML = html; |
| | | self.abspieler_auswahl_fuellen(); |
| | | self.abspielliste_auswahl_fuellen(); |
| | | self.addEvtListener('#dazu-btn', 'click', self.addSelectedTitel); |
| | | self.media_liste(); |
| | | }); |
| | | }; |
| | | |
| | | /* ---------------- Titel einer Abspielliste ----------------- */ |
| | | |
| | | this.titel_liste = function() { |
| | | 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)"); |
| | | }); |
| | | */ |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | /* ---------------- Entitaets-Listen ----------------- */ |
| | | |
| | | self.reset_top_buttons = function() { |
| | | self.vorlage_laden_und_fuellen("data/tpl/top_btns.tpl", '', function (html) { |
| | | document.querySelector(".top-btns").innerHTML = html; |
| | | }); |
| | | }; |
| | | |
| | | // auf der obersten Ebene werden die Kataloge angezeigt, |
| | | // darunter der Inhalt des aktuellen Pfades |
| | | this.media_liste = function() { |
| | |
| | | self.abspielliste_liste(); |
| | | }); |
| | | }); |
| | | |
| | | |
| | | /* |
| | | self.addEvtListener('#ok-btn', 'click', function () { |
| | | var alname = document.querySelector('#abspielliste-name').value; |
| | | alname = alname.replace(' ', '').replace(/[\W]+/g, ''); |
| | | var abspielliste = new Abspielliste( |
| | | alname |
| | | ); |
| | | var daten = JSON.stringify(abspielliste); |
| | | //if(typeof pl === "undefined" || pl.key !== plname) { |
| | | if(typeof al.name === "undefined" || al.name.length < 1) { |
| | | // neu |
| | | self.http_put('../api/store/Abspielliste/' + alname, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.abspielliste_auswahl_fuellen(); |
| | | self.abspielliste_liste(); |
| | | }); |
| | | } else { |
| | | // aendern |
| | | self.http_put('../api/store/Abspielliste/' + al.name, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.abspielliste_auswahl_fuellen(); |
| | | self.abspielliste_liste(); |
| | | }); |
| | | } |
| | | }); |
| | | */ |
| | | |
| | | self.addEvtListener('#cancel-btn', 'click', function () { |
| | | //document.querySelector(".zentraler-inhalt").innerHTML = ''; |
| | | self.abspielliste_liste(); |
| | | }); |
| | | |
| | | self.addEvtListener('#loeschen-btn', 'click', function(event) { |
| | | event.preventDefault(); |
| | | self.handle_del_btn('#abspielliste-name', '../api/store/Abspielliste/', function() { |
| | |
| | | self.abspielliste_liste(); |
| | | }); |
| | | }); |
| | | |
| | | /* |
| | | self.addEvtListener('#loeschen-btn', 'click', function() { |
| | | var alname = document.querySelector('#abspielliste-name').value; |
| | | var dlgdata = {"del-elem": alname}; |
| | | self.dialog_laden_und_zeigen('data/tpl/dlg-loeschen.tpl', dlgdata, function() { |
| | | self.addEvtListener('#nein-btn', 'click', self.dialog_schliessen); |
| | | self.addEvtListener('#ja-btn', 'click', function() { |
| | | self.http_delete('../api/store/Abspielliste/' + alname, '', function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.dialog_schliessen(); |
| | | //document.querySelector(".zentraler-inhalt").innerHTML = ''; |
| | | self.abspielliste_auswahl_fuellen(); |
| | | self.abspielliste_liste(); |
| | | }); |
| | | }); |
| | | }); |
| | | }); |
| | | */ |
| | | }); |
| | | }; |
| | | |
| | |
| | | self.abspieler_liste(); |
| | | }); |
| | | }); |
| | | |
| | | /* |
| | | self.addEvtListener('#ok-btn', 'click', function () { |
| | | var plname = document.querySelector('#abspieler-name').value; |
| | | plname = plname.replace(' ', '').replace(/[\W]+/g, ''); |
| | | var abspieler = new Abspieler( |
| | | plname, |
| | | document.querySelector('#abspieler-url').value |
| | | ); |
| | | var daten = JSON.stringify(abspieler); |
| | | //if(typeof pl === "undefined" || pl.key !== plname) { |
| | | if(typeof pl.name === "undefined" || pl.name.length < 1) { |
| | | // neu |
| | | self.http_put('../api/store/Abspieler/' + plname, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.abspieler_auswahl_fuellen(); |
| | | self.abspieler_liste(); |
| | | }); |
| | | } else { |
| | | // aendern |
| | | self.http_put('../api/store/Abspieler/' + pl.name, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.abspieler_auswahl_fuellen(); |
| | | self.abspieler_liste(); |
| | | }); |
| | | } |
| | | }); |
| | | */ |
| | | |
| | | self.addEvtListener('#cancel-btn', 'click', function () { |
| | | //document.querySelector(".zentraler-inhalt").innerHTML = ''; |
| | | self.abspieler_liste(); |
| | | }); |
| | | |
| | | self.addEvtListener('#loeschen-btn', 'click', function(event) { |
| | | event.preventDefault(); |
| | | self.handle_del_btn('#abspieler-name', '../api/store/Abspieler/', function() { |
| | |
| | | self.abspieler_liste(); |
| | | }); |
| | | }); |
| | | |
| | | |
| | | /* |
| | | self.addEvtListener('#loeschen-btn', 'click', function() { |
| | | var plname = document.querySelector('#abspieler-name').value; |
| | | var dlgdata = {"del-elem": plname}; |
| | | self.dialog_laden_und_zeigen('data/tpl/dlg-loeschen.tpl', dlgdata, function() { |
| | | self.addEvtListener('#nein-btn', 'click', self.dialog_schliessen); |
| | | self.addEvtListener('#ja-btn', 'click', function() { |
| | | self.http_delete('../api/store/Abspieler/' + plname, '', function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.dialog_schliessen(); |
| | | //document.querySelector(".zentraler-inhalt").innerHTML = ''; |
| | | self.abspieler_auswahl_fuellen(); |
| | | self.abspieler_liste(); |
| | | }); |
| | | }); |
| | | }); |
| | | }); |
| | | */ |
| | | }); |
| | | }; |
| | | |
| | |
| | | self.prefs_liste(); |
| | | }); |
| | | }); |
| | | |
| | | |
| | | /* |
| | | self.addEvtListener('#ok-btn', 'click', function () { |
| | | var pkey = document.querySelector('#einstellung-key').value; |
| | | pkey = pkey.replace(' ', '').replace(/[\W]+/g, ''); |
| | | var pref = new Einstellung( |
| | | pkey, |
| | | document.querySelector('#einstellung-value').value |
| | | ); |
| | | var daten = JSON.stringify(pref); |
| | | //if(typeof k === "undefined" || k.key !== pkey) { |
| | | if(typeof k.key === "undefined" || k.key.length < 1) { |
| | | // neu |
| | | self.http_put('../api/store/Einstellung/' + pkey, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.prefs_liste(); |
| | | }); |
| | | } else { |
| | | // aendern |
| | | self.http_put('../api/store/Einstellung/' + k.key, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.prefs_liste(); |
| | | }); |
| | | } |
| | | }); |
| | | */ |
| | | self.addEvtListener('#cancel-btn', 'click', function (event) { |
| | | //document.querySelector(".zentraler-inhalt").innerHTML = ''; |
| | | event.preventDefault(); |
| | | self.prefs_liste(); |
| | | }); |
| | | |
| | | self.addEvtListener('#loeschen-btn', 'click', function(event) { |
| | | event.preventDefault(); |
| | | self.handle_del_btn('#einstellung-key', '../api/store/Einstellung/', function() { |
| | | self.prefs_liste(); |
| | | }); |
| | | }); |
| | | |
| | | /* |
| | | self.addEvtListener('#loeschen-btn', 'click', function() { |
| | | var pkey = document.querySelector('#einstellung-key').value; |
| | | var dlgdata = {"del-elem": pkey}; |
| | | self.dialog_laden_und_zeigen('data/tpl/dlg-loeschen.tpl', dlgdata, function() { |
| | | self.addEvtListener('#nein-btn', 'click', self.dialog_schliessen); |
| | | self.addEvtListener('#ja-btn', 'click', function() { |
| | | self.http_delete('../api/store/Einstellung/' + pkey, '', function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.dialog_schliessen(); |
| | | //document.querySelector(".zentraler-inhalt").innerHTML = ''; |
| | | self.prefs_liste(); |
| | | }); |
| | | }); |
| | | }); |
| | | }); |
| | | */ |
| | | }); |
| | | }; |
| | | |
| | |
| | | self.ablageort_liste(); |
| | | }); |
| | | }); |
| | | |
| | | /* |
| | | self.addEvtListener('#ok-btn', 'click', function () { |
| | | var aName = document.querySelector('#ablageort-name').value; |
| | | aName = aName.replace(' ', '').replace(/[\W]+/g, ''); |
| | | var a = new Ablageort( |
| | | aName, |
| | | document.querySelector('#ablageort-ort').value, |
| | | document.querySelector('#ablageort-url').value |
| | | ); |
| | | var daten = JSON.stringify(a); |
| | | //if(typeof ort === "undefined" || ort.name !== aName) { |
| | | if(typeof ort.name === "undefined" || ort.name.length < 1) { |
| | | // neu |
| | | self.http_put('../api/store/Ablageort/' + aName, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.ablageort_liste(); |
| | | }); |
| | | } else { |
| | | // aendern |
| | | self.http_put('../api/store/Ablageort/' + ort.name, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.ablageort_liste(); |
| | | }); |
| | | } |
| | | }); |
| | | */ |
| | | self.addEvtListener('#cancel-btn', 'click', function () { |
| | | //document.querySelector(".zentraler-inhalt").innerHTML = ''; |
| | | self.ablageort_liste(); |
| | | }); |
| | | |
| | | self.addEvtListener('#loeschen-btn', 'click', function(event) { |
| | | event.preventDefault(); |
| | | self.handle_del_btn('#ablageort-name', '../api/store/Ablageort/', function() { |
| | | self.ablageort_liste(); |
| | | }); |
| | | }); |
| | | |
| | | |
| | | /* |
| | | self.addEvtListener('#loeschen-btn', 'click', function() { |
| | | var aoname = document.querySelector('#ablageort-name').value; |
| | | var dlgdata = {"del-elem": aoname}; |
| | | self.dialog_laden_und_zeigen('data/tpl/dlg-loeschen.tpl', dlgdata, function() { |
| | | self.addEvtListener('#nein-btn', 'click', self.dialog_schliessen); |
| | | self.addEvtListener('#ja-btn', 'click', function() { |
| | | self.http_delete('../api/store/Ablageort/' + aoname, '', function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.dialog_schliessen(); |
| | | //document.querySelector(".zentraler-inhalt").innerHTML = ''; |
| | | self.ablageort_liste(); |
| | | }); |
| | | }); |
| | | }); |
| | | }); |
| | | */ |
| | | }); |
| | | }; |
| | | |
| | | /* ------------------------------- Helfer ----------------------- */ |
| | | /* ------------------------------- UI-Dynamik ----------------------- */ |
| | | |
| | | self.reset_top_buttons = function() { |
| | | self.vorlage_laden_und_fuellen("data/tpl/top_btns.tpl", '', function (html) { |
| | | document.querySelector(".top-btns").innerHTML = html; |
| | | }); |
| | | }; |
| | | |
| | | this.abspieler_auswahl_fuellen = function() { |
| | | self.http_get('../api/store/Abspieler/', function (responseText) { |
| | | self.vorlage_laden_und_fuellen("data/tpl/abs_sel.tpl", JSON.parse(responseText), function (html) { |
| | | document.querySelector(".abs-sel").innerHTML = html; |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | this.abspielliste_auswahl_fuellen = function() { |
| | | self.http_get('../api/store/Abspielliste/', function (responseText) { |
| | | self.vorlage_laden_und_fuellen("data/tpl/pl_sel.tpl", JSON.parse(responseText), function (html) { |
| | | document.querySelector(".pl-sel").innerHTML = html; |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | /* Unterer Einblendbereich */ |
| | | |
| | | this.dialog_unten_zeigen = function() { |
| | | self.vorlage_laden_und_fuellen("data/tpl/ctrl.tpl", "", function (html) { |
| | | var dlg = document.querySelector(".dialog-unten"); |
| | | dlg.style.height = '4.5em'; |
| | | dlg.innerHTML = html; |
| | | self.abspieler_auswahl_fuellen(); |
| | | self.abspielliste_auswahl_fuellen(); |
| | | self.addEvtListener('#dazu-btn', 'click', self.addSelectedTitel); |
| | | self.media_liste(); |
| | | }); |
| | | }; |
| | | |
| | | /* Titel einer Abspielliste */ |
| | | |
| | | this.titel_liste = function() { |
| | | 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'); |
| | | }); |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | /* ------------- Helfer fuer Entitaets-Formulare ----------------------- */ |
| | | |
| | | /* |
| | | * existingKey: wenn die Entitaet existiert und geandert werden soll |
| | | * leer, wenn neue Entitaet |
| | |
| | | var daten = JSON.stringify(value); |
| | | var formkey = document.querySelector(keySelector).value; |
| | | formkey = formkey.replace(' ', '').replace(/[\W]+/g, ''); |
| | | |
| | | if(typeof existingKey === "undefined" || existingKey.length < 1) { |
| | | // neu |
| | | self.http_put(putUrl + formkey, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | //self.prefs_liste(); |
| | | if(typeof(cb) !== 'function') { |
| | | // .. |
| | | } else { |
| | |
| | | } else { |
| | | // aendern |
| | | self.http_put(putUrl + existingKey, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | // self.prefs_liste(); |
| | | if(typeof(cb) !== 'function') { |
| | | // .. |
| | | } else { |
| | |
| | | self.addEvtListener('#ja-btn', 'click', function(event) { |
| | | console.log("loeschen geklickt."); |
| | | self.http_delete(delUrl + pkey, '', function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.dialog_schliessen(); |
| | | //document.querySelector(".zentraler-inhalt").innerHTML = ''; |
| | | //self.prefs_liste(); |
| | | if(typeof(cb) !== 'function') { |
| | | // .. |
| | | } else { |
| | |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | |
| | | /* ------------------ sonstige Helfer ----------------------- */ |
| | | |
| | | this.addEvtListener = function(selector, eventName, func) { |
| | | document.querySelectorAll(selector).forEach(elem => { elem.addEventListener(eventName, func); }); |
| | | }; |