From 8d53d747bb33fde58d01907b1202f6bb1bc7f607 Mon Sep 17 00:00:00 2001
From: ulrich <not disclosed>
Date: Sat, 06 Jan 2018 10:46:46 +0000
Subject: [PATCH] Doku um Beispielkapitel ergänzt

---
 app.js |  129 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 108 insertions(+), 21 deletions(-)

diff --git a/app.js b/app.js
index dde105d..3de1288 100644
--- a/app.js
+++ b/app.js
@@ -3,16 +3,28 @@
 var TPL_SENDER = 'sender';
 var TPL_DLG_MSG = 'dlg-msg';
 var TPL_DLG_INFO = 'dlg-info';
-var templateCache = {}; // mustache templates 'home', 'prefs', 'sender'
+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 templateCache = {}; // mustache templates
 var prefsRendered = false;
+var senderKlickModus = "0"; // 1=abspielen, 2=bearbeiten, 3=loeschen
 
 function app_init() {
   $('.dialog').hide();
   $('.ost').hide();
-  app_menu_init("menu/", "hauptmenue.json", "../jslib/app-menu/app-menu.tpl", ".west");
-  app_get_template('tpl/dlg-msg.tpl', TPL_DLG_MSG);
-  app_get_template('tpl/dlg-info.tpl', TPL_DLG_INFO);
-  app_get_template('tpl/sender.tpl', TPL_SENDER);
+  app_menu_init(
+    "data/menu/",
+    "hauptmenue.json",
+    "../jslib/app-menu/app-menu.tpl",
+    ".west",
+    "8em");
+  app_get_template('data/tpl/dlg-msg.tpl', TPL_DLG_MSG);
+  app_get_template('data/tpl/dlg-info.tpl', TPL_DLG_INFO);
+  app_get_template('data/tpl/sender.tpl', TPL_SENDER);
+  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('tpl/prefs.tpl', 'prefs');
   $('.sued').text('Bereit.');
   setTimeout(function() {
@@ -20,12 +32,68 @@
   }, 200);
 }
 
+/* --- Menüfunktionen --- */
+
 function app_nachricht_test() {
-  app_nachricht_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();
 }
 
 function app_info_dialog_zeigen() {
-  app_nachricht_zeigen(templateCache[TPL_DLG_INFO], '');
+  app_dialog_laden_und_zeigen(templateCache[TPL_DLG_INFO], '');
+  app_menu_toggle();
+}
+
+function app_neuer_sender() {
+  app_dialog_laden_und_zeigen(templateCache[TPL_DLG_SENDER_NEU], '');
+  $('#sender-speichern').on('click', function() {
+    $('#sender-speichern').off('click');
+    app_dialog_schliessen();
+    app_meldung_mit_timeout('Speichern gewaehlt', 1500);
+  });
+  app_menu_toggle();
+}
+
+function app_sender_bearbeiten() {
+  senderKlickModus = "2"; // bearbeiten
+  app_dialog_laden_und_zeigen(templateCache[TPL_DLG_SENDER_EDIT], '');
+  app_menu_toggle();
+}
+
+function app_sender_loeschen() {
+  app_meldung_mit_timeout('Nicht implementiert: Sender loeschen.', 1500);
+  app_menu_toggle();
+}
+
+/* --- Dialogfunktionen --- */
+
+function app_dialog_zeigen(vorlage, inhalt) {
+  $(".dialog").html(Mustache.render(vorlage, inhalt));
+  $(".close-btn").on('click', function() {
+    app_dialog_schliessen();
+  });
+  $('.dialog').slideDown(300);
+}
+
+function app_dialog_schliessen() {
+  senderKlickModus = "0";
+  $('.close-btn').off('click');
+  $('.dialog').slideUp(300);
+}
+
+/* --- Meldungen in der Fusszeile --- */
+
+/*
+  Eine Meldung eine Zeitlang in der Fusszeile anzeigen
+
+  meldung - Text der Meldung
+  timeout - die Anzahl Millisekunden, die eine Meldung zu sehen sein soll
+*/
+function app_meldung_mit_timeout(meldung, timeout) {
+  $('.sued').text(meldung);
+  setTimeout(function() {
+    $('.sued').text('Bereit.');
+  }, timeout);
 }
 
 /* --- Ajax-Aufrufe --- */
@@ -36,31 +104,50 @@
     type: "GET",
     dataType : "json"
   }).done(function( senderliste ) {
-    $(".sender-behaelter").html(Mustache.render(templateCache[TPL_SENDER], senderliste));
+    $(".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;
+      }
+    });
   });
 }
 
-function app_nachricht_zeigen(vorlage, adresse) {
+function app_dialog_laden_und_zeigen(vorlage, adresse) {
   if(adresse !== '') {
     $.ajax({
       url: adresse,
       type: "GET",
       dataType : "json"
     }).done(function( msg ) {
-      $(".dialog").html(Mustache.render(vorlage, msg));
-      $(".close-btn").on('click', function() {
-        $('.close-btn').attr('onclick','').unbind('click');
-        $('.dialog').slideUp(300);
-      });
-      $('.dialog').slideDown(300);
+      app_dialog_zeigen(vorlage, msg);
     });
   } else {
-    $(".dialog").html(Mustache.render(vorlage, ''));
-    $(".close-btn").on('click', function() {
-      $('.close-btn').attr('onclick','').unbind('click');
-      $('.dialog').slideUp(300);
-    });
-    $('.dialog').slideDown(300);
+    app_dialog_zeigen(vorlage, '');
   }
 }
 

--
Gitblit v1.9.3