Bedienoberfläche für Webradio
ulrich
2018-01-05 c0ad5e4def882502078e9ed486fc25a5d0e80c0c
commit | author | age
623a61 1 var TPL_HOME = 'home';
U 2 var TPL_PREFS = 'prefs';
47a970 3 var TPL_SENDER = 'sender';
9e336a 4 var TPL_DLG_MSG = 'dlg-msg';
36646e 5 var TPL_DLG_INFO = 'dlg-info';
5226a2 6 var TPL_DLG_SENDER = 'dlg-sender';
df379b 7 var templateCache = {}; // mustache templates
623a61 8 var prefsRendered = false;
U 9
10 function app_init() {
9f0d54 11   $('.dialog').hide();
623a61 12   $('.ost').hide();
df379b 13   app_menu_init("data/menu/", "hauptmenue.json", "../jslib/app-menu/app-menu.tpl", ".west", "8em");
8881ca 14   app_get_template('data/tpl/dlg-msg.tpl', TPL_DLG_MSG);
U 15   app_get_template('data/tpl/dlg-info.tpl', TPL_DLG_INFO);
16   app_get_template('data/tpl/sender.tpl', TPL_SENDER);
5226a2 17   app_get_template('data/tpl/dlg-sender-edit.tpl', TPL_DLG_SENDER);
623a61 18   //app_get_template('tpl/prefs.tpl', 'prefs');
U 19   $('.sued').text('Bereit.');
20   setTimeout(function() {
a480d0 21     app_get_sender();
623a61 22   }, 200);
47a970 23 }
U 24
8881ca 25 /* --- Menüfunktionen --- */
U 26
9f0d54 27 function app_nachricht_test() {
b520d1 28   app_dialog_laden_und_zeigen(templateCache[TPL_DLG_MSG], 'data/msg-test.json');
df379b 29   app_menu_toggle();
36646e 30 }
U 31
32 function app_info_dialog_zeigen() {
b520d1 33   app_dialog_laden_und_zeigen(templateCache[TPL_DLG_INFO], '');
df379b 34   app_menu_toggle();
8881ca 35 }
U 36
5226a2 37 function app_neuer_sender() {
b520d1 38   app_dialog_laden_und_zeigen(templateCache[TPL_DLG_SENDER], '');
U 39   $('#sender-speichern').on('click', function() {
40     $('#sender-speichern').attr('onclick','').unbind('click');
41     app_dialog_schliessen();
742e75 42     app_meldung_mit_timeout('Speichern gewaehlt', 1500);
b520d1 43   });
U 44   app_menu_toggle();
5226a2 45 }
U 46
742e75 47 function app_sender_bearbeiten() {
U 48   app_meldung_mit_timeout('Nicht implementiert: Sender bearbeiten.', 1500);
c0ad5e 49   app_menu_toggle();
742e75 50 }
5226a2 51
742e75 52 function app_sender_loeschen() {
U 53   app_meldung_mit_timeout('Nicht implementiert: Sender loeschen.', 1500);
c0ad5e 54   app_menu_toggle();
742e75 55 }
U 56
57 /* --- Dialogfunktionen --- */
8881ca 58
U 59 function app_dialog_zeigen(vorlage, inhalt) {
60   $(".dialog").html(Mustache.render(vorlage, inhalt));
61   $(".close-btn").on('click', function() {
b520d1 62     app_dialog_schliessen();
8881ca 63   });
U 64   $('.dialog').slideDown(300);
b520d1 65 }
U 66
67 function app_dialog_schliessen() {
68   $('.close-btn').attr('onclick','').unbind('click');
69   $('.dialog').slideUp(300);
9f0d54 70 }
U 71
742e75 72 /* --- Meldungen in der Fusszeile --- */
U 73
74 /*
75   Eine Meldung eine Zeitlang in der Fusszeile anzeigen
76
77   meldung - Text der Meldung
78   timeout - die Anzahl Millisekunden, die eine Meldung zu sehen sein soll
79 */
80 function app_meldung_mit_timeout(meldung, timeout) {
81   $('.sued').text(meldung);
82   setTimeout(function() {
83     $('.sued').text('Bereit.');
84   }, timeout);
85 }
86
47a970 87 /* --- Ajax-Aufrufe --- */
U 88
a480d0 89 function app_get_sender() {
U 90   $.ajax({
0c85a2 91     url: "data/sender.json",
a480d0 92     type: "GET",
U 93     dataType : "json"
94   }).done(function( senderliste ) {
21dcfa 95     $(".sender-behaelter").html(Mustache.render(templateCache[TPL_SENDER], senderliste));
a480d0 96   });
U 97 }
98
b520d1 99 function app_dialog_laden_und_zeigen(vorlage, adresse) {
36646e 100   if(adresse !== '') {
U 101     $.ajax({
102       url: adresse,
103       type: "GET",
104       dataType : "json"
105     }).done(function( msg ) {
8881ca 106       app_dialog_zeigen(vorlage, msg);
36646e 107     });
U 108   } else {
8881ca 109     app_dialog_zeigen(vorlage, '');
36646e 110   }
9e336a 111 }
U 112
47a970 113 /*
U 114   Ein Template vom Server in den Cache laden
115   template_url - home.tpl, prefs.tpl, sender.tpl
116   tname - 'home', 'prefs', 'sender'
117 */
118 function app_get_template(template_url, tname) {
119   $.ajax({
120     url: template_url,
121     type: "GET",
122     dataType : "text"
123   }).done(function( template ) {
124     templateCache[tname] = template;
125   });
623a61 126 }