| | |
| | | * 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; |
| | |
| | | console.log({ value }); |
| | | console.log(JSON.stringify(value)); |
| | | }; |
| | | |
| | | */ |
| | | |
| | | this.abspieler_auswahl_fuellen = function() { |
| | | self.http_get('../api/store/Abspieler/', function (responseText) { |
| | |
| | | self.abspieler_form(abspieler); |
| | | }); |
| | | }); |
| | | self.addEvtListener('#neu-btn', 'click', function(event) { |
| | | //self.addEvtListener('#neu-btn', 'click', function(event) { |
| | | self.addEvtListener('#top-neu-btn', 'click', function(event) { |
| | | eval("self.abspieler_form" + "(this)"); |
| | | }); |
| | | }); |
| | |
| | | this.abspielliste_form = function(al) { |
| | | self.vorlage_laden_und_fuellen("data/tpl/form_abspielliste.tpl", al, function (html) { |
| | | document.querySelector(".zentraler-inhalt").innerHTML = html; |
| | | const form = document.querySelector('form'); |
| | | form.addEventListener('submit', function(event) { |
| | | self.handle_submit(event, al.name, '../api/store/Abspielliste/', '#abspielliste-name', function() { |
| | | self.abspielliste_liste(); |
| | | }); |
| | | }); |
| | | |
| | | |
| | | /* |
| | | self.addEvtListener('#ok-btn', 'click', function () { |
| | | var alname = document.querySelector('#abspielliste-name').value; |
| | | alname = alname.replace(' ', '').replace(/[\W]+/g, ''); |
| | |
| | | }); |
| | | } |
| | | }); |
| | | */ |
| | | |
| | | 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_auswahl_fuellen(); |
| | | self.abspielliste_liste(); |
| | | }); |
| | | }); |
| | | |
| | | /* |
| | | self.addEvtListener('#loeschen-btn', 'click', function() { |
| | | var alname = document.querySelector('#abspielliste-name').value; |
| | | var dlgdata = {"del-elem": alname}; |
| | |
| | | }); |
| | | }); |
| | | }); |
| | | */ |
| | | }); |
| | | }; |
| | | |
| | | this.abspieler_form = function(pl) { |
| | | self.vorlage_laden_und_fuellen("data/tpl/form_abspieler.tpl", pl, function (html) { |
| | | document.querySelector(".zentraler-inhalt").innerHTML = html; |
| | | const form = document.querySelector('form'); |
| | | form.addEventListener('submit', function(event) { |
| | | self.handle_submit(event, pl.key, '../api/store/Abspieler/', '#abspieler-name', function() { |
| | | self.abspieler_liste(); |
| | | }); |
| | | }); |
| | | |
| | | /* |
| | | self.addEvtListener('#ok-btn', 'click', function () { |
| | | var plname = document.querySelector('#abspieler-name').value; |
| | | plname = plname.replace(' ', '').replace(/[\W]+/g, ''); |
| | |
| | | }); |
| | | } |
| | | }); |
| | | */ |
| | | |
| | | 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_auswahl_fuellen(); |
| | | self.abspieler_liste(); |
| | | }); |
| | | }); |
| | | |
| | | |
| | | /* |
| | | self.addEvtListener('#loeschen-btn', 'click', function() { |
| | | var plname = document.querySelector('#abspieler-name').value; |
| | | var dlgdata = {"del-elem": plname}; |
| | |
| | | }); |
| | | }); |
| | | }); |
| | | }); |
| | | }; |
| | | |
| | | /* |
| | | * existingKey: wenn die Entitaet existiert und geandert werden soll |
| | | * leer, wenn neue Entitaet |
| | | */ |
| | | this.handle_my_submit = function(event, existingKey, putUrl, keySelector) { |
| | | 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, ''); |
| | | |
| | | if(typeof existingKey === "undefined" || existingKey.length < 1) { |
| | | // neu |
| | | self.http_put(putUrl + formkey, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.prefs_liste(); |
| | | }); |
| | | } else { |
| | | // aendern |
| | | self.http_put(putUrl + existingKey, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | self.prefs_liste(); |
| | | }); |
| | | } |
| | | |
| | | |
| | | }; |
| | | |
| | | this.prefs_form = function(k) { |
| | |
| | | document.querySelector(".zentraler-inhalt").innerHTML = html; |
| | | const form = document.querySelector('form'); |
| | | form.addEventListener('submit', function(event) { |
| | | self.handle_my_submit(event, k.key, '../api/store/Einstellung/', '#einstellung-key'); |
| | | self.handle_submit(event, k.key, '../api/store/Einstellung/', '#einstellung-key', function() { |
| | | self.prefs_liste(); |
| | | }); |
| | | }); |
| | | |
| | | |
| | |
| | | } |
| | | }); |
| | | */ |
| | | self.addEvtListener('#cancel-btn', 'click', function () { |
| | | 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}; |
| | |
| | | }); |
| | | }); |
| | | }); |
| | | */ |
| | | }); |
| | | }; |
| | | |
| | |
| | | this.ablageort_form = function(ort) { |
| | | self.vorlage_laden_und_fuellen("data/tpl/form_ablageort.tpl", ort, function (html) { |
| | | document.querySelector(".zentraler-inhalt").innerHTML = html; |
| | | const form = document.querySelector('form'); |
| | | form.addEventListener('submit', function(event) { |
| | | self.handle_submit(event, ort.name, '../api/store/Ablageort/', '#ablageort-name', function() { |
| | | self.ablageort_liste(); |
| | | }); |
| | | }); |
| | | |
| | | /* |
| | | self.addEvtListener('#ok-btn', 'click', function () { |
| | | var aName = document.querySelector('#ablageort-name').value; |
| | | aName = aName.replace(' ', '').replace(/[\W]+/g, ''); |
| | |
| | | }); |
| | | } |
| | | }); |
| | | */ |
| | | 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}; |
| | |
| | | }); |
| | | }); |
| | | }); |
| | | */ |
| | | }); |
| | | }; |
| | | |
| | | /* ------------------------------- Helfer ----------------------- */ |
| | | |
| | | /* |
| | | * existingKey: wenn die Entitaet existiert und geandert werden soll |
| | | * leer, wenn neue Entitaet |
| | | */ |
| | | this.handle_submit = function(event, existingKey, putUrl, keySelector, cb) { |
| | | 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, ''); |
| | | |
| | | 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 { |
| | | cb(); |
| | | } |
| | | }); |
| | | } else { |
| | | // aendern |
| | | self.http_put(putUrl + existingKey, daten, function (responseText) { |
| | | // hier die Antwort verarbeiten |
| | | // self.prefs_liste(); |
| | | if(typeof(cb) !== 'function') { |
| | | // .. |
| | | } else { |
| | | cb(); |
| | | } |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | this.handle_del_btn = function(selectorKey, delUrl, cb) { |
| | | var pkey = document.querySelector(selectorKey).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(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 { |
| | | cb(); |
| | | } |
| | | }); |
| | | }); |
| | | }); |
| | | }; |
| | | |