From 6a62bd168dd69e649ef98556a72af6be9de2c425 Mon Sep 17 00:00:00 2001
From: ulrich <not disclosed>
Date: Sun, 07 Jan 2018 10:00:11 +0000
Subject: [PATCH] Doku angepasst

---
 app.js |  114 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 86 insertions(+), 28 deletions(-)

diff --git a/app.js b/app.js
index 3de1288..3b56e63 100644
--- a/app.js
+++ b/app.js
@@ -6,9 +6,12 @@
 var TPL_DLG_SENDER_NEU = 'dlg-sender-neu';
 var TPL_DLG_SENDER_EDIT = 'dlg-sender-edit';
 var TPL_SENDER_EDIT_FORM = 'sender-edit-form';
+var TPL_SENDER_KACHEL = 'sender-kachel';
+var TPL_ABSPIELER = 'abspieler';
 var templateCache = {}; // mustache templates
 var prefsRendered = false;
 var senderKlickModus = "0"; // 1=abspielen, 2=bearbeiten, 3=loeschen
+var ID_UNDEFINED = -1;
 
 function app_init() {
   $('.dialog').hide();
@@ -25,17 +28,70 @@
   app_get_template('data/tpl/dlg-sender-neu.tpl', TPL_DLG_SENDER_NEU);
   app_get_template('data/tpl/dlg-sender-edit.tpl', TPL_DLG_SENDER_EDIT);
   app_get_template('data/tpl/dlg-sender-edit-form.tpl', TPL_SENDER_EDIT_FORM);
+  app_get_template('data/tpl/kachel.tpl', TPL_SENDER_KACHEL);
+  app_get_template('data/tpl/abspieler.tpl', TPL_ABSPIELER);
   //app_get_template('tpl/prefs.tpl', 'prefs');
   $('.sued').text('Bereit.');
   setTimeout(function() {
+    app_get_abspieler();
     app_get_sender();
   }, 200);
+}
+
+/* Senderliste */
+
+function app_kachel_anpassen(sender) {
+  var kachel = $( "div[sid='" + sender.id + "']" );
+  $(kachel).find(".sender-name").text(sender.name);
+  $(kachel).attr("data-verweis", sender.url);
+  $(kachel).find("img").attr("src", sender.logo);
+}
+
+function app_kachel_neu(sender) {
+  var html = Mustache.render(templateCache[TPL_SENDER_KACHEL], sender);
+  $("#sender").append(html);
+  var kachel = $( "div[sid='" + sender.id + "']" );
+  $(kachel).on('click', app_kachel_klick);
+}
+
+function app_kachel_klick() {
+  var kachel = $( this );
+  var senderId = $(kachel).attr("sid");
+  var senderName = $(kachel).find(".sender-name").text();
+  var senderUrl = $(kachel).attr("data-verweis");
+  var senderLogo = $(kachel).find("img").attr("src");
+  var s = new Sender(senderId, senderName, senderUrl, senderLogo);
+  switch (senderKlickModus) {
+      case "1":
+        break;
+      case "2":
+        $(".dlg-behaelter").html(
+          Mustache.render(templateCache[TPL_SENDER_EDIT_FORM], s)
+        );
+        $('#sender-speichern').on('click', function() {
+          $('#sender-speichern').off('click');
+          app_kachel_anpassen(app_sender_dialog_lesen(senderId));
+          app_dialog_schliessen();
+          app_meldung_mit_timeout('Speichern gewaehlt', 1500);
+        });
+        break;
+      case "3":
+        break;
+      default:
+        app_meldung_mit_timeout(
+          'Sender ' + s.name + ', ID ' + s.id,
+          1500
+        );
+        break;
+  }
+
 }
 
 /* --- Menüfunktionen --- */
 
 function app_nachricht_test() {
-  app_dialog_laden_und_zeigen(templateCache[TPL_DLG_MSG], 'data/msg-test.json');
+  app_dialog_laden_und_zeigen(
+    templateCache[TPL_DLG_MSG], 'data/msg-test.json');
   app_menu_toggle();
 }
 
@@ -48,6 +104,7 @@
   app_dialog_laden_und_zeigen(templateCache[TPL_DLG_SENDER_NEU], '');
   $('#sender-speichern').on('click', function() {
     $('#sender-speichern').off('click');
+    app_kachel_neu(app_sender_dialog_lesen(--ID_UNDEFINED));
     app_dialog_schliessen();
     app_meldung_mit_timeout('Speichern gewaehlt', 1500);
   });
@@ -73,6 +130,13 @@
     app_dialog_schliessen();
   });
   $('.dialog').slideDown(300);
+}
+
+function app_sender_dialog_lesen(senderId) {
+  var nameNeu = $("#sender-name").val();
+  var logoNeu = $("#sender-logo").val();
+  var urlNeu = $("#sender-url").val();
+  return new Sender(senderId, nameNeu, urlNeu, logoNeu);
 }
 
 function app_dialog_schliessen() {
@@ -107,33 +171,18 @@
     $(".sender-kachel").off("click");
     $(".sender-behaelter").html(
       Mustache.render(templateCache[TPL_SENDER], senderliste));
-    $('.sender-kachel').on('click', function() {
-      var kachel = $( this );
-      var senderId = kachel.attr("sid");
-      var senderName = $(kachel).find(".sender-name").text();
-      switch (senderKlickModus) {
-          case "1":
-            break;
-          case "2":
-            $(".dlg-behaelter").html(
-              Mustache.render(templateCache[TPL_SENDER_EDIT_FORM], '')
-            );
-            $('#sender-speichern').on('click', function() {
-              $('#sender-speichern').off('click');
-              app_dialog_schliessen();
-              app_meldung_mit_timeout('Speichern gewaehlt', 1500);
-            });
-            break;
-          case "3":
-            break;
-          default:
-            app_meldung_mit_timeout(
-              'Sender ' + senderName + ', ID ' + senderId,
-              1500
-            );
-            break;
-      }
-    });
+    $('.sender-kachel').on('click', app_kachel_klick);
+  });
+}
+
+function app_get_abspieler() {
+  $.ajax({
+    url: "data/abspieler.json",
+    type: "GET",
+    dataType : "json"
+  }).done(function( abspielerliste ) {
+    $(".abspieler-behaelter").html(
+      Mustache.render(templateCache[TPL_ABSPIELER], abspielerliste));
   });
 }
 
@@ -165,3 +214,12 @@
     templateCache[tname] = template;
   });
 }
+
+/* Objekte */
+
+function Sender(i, n, u, l) {
+  this.id = i;
+  this.name = n;
+  this.url = u;
+  this.logo = l;
+}

--
Gitblit v1.9.3