Bedienoberfläche für Webradio
ulrich
2018-01-05 df379b8b3ca964dc5b95369f1456f020817060bd
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();
42     $('.sued').text('Speichern gewaehlt');
43     setTimeout(function() {
44       $('.sued').text('Bereit.');
45     }, 1500);
46   });
47   app_menu_toggle();
5226a2 48 }
U 49
50
8881ca 51 /* --- Sonstiges --- */
U 52
53 function app_dialog_zeigen(vorlage, inhalt) {
54   $(".dialog").html(Mustache.render(vorlage, inhalt));
55   $(".close-btn").on('click', function() {
b520d1 56     app_dialog_schliessen();
U 57     /*
8881ca 58     $('.close-btn').attr('onclick','').unbind('click');
U 59     $('.dialog').slideUp(300);
b520d1 60     */
8881ca 61   });
U 62   $('.dialog').slideDown(300);
b520d1 63 }
U 64
65 function app_dialog_schliessen() {
66   $('.close-btn').attr('onclick','').unbind('click');
67   $('.dialog').slideUp(300);
9f0d54 68 }
U 69
47a970 70 /* --- Ajax-Aufrufe --- */
U 71
a480d0 72 function app_get_sender() {
U 73   $.ajax({
0c85a2 74     url: "data/sender.json",
a480d0 75     type: "GET",
U 76     dataType : "json"
77   }).done(function( senderliste ) {
21dcfa 78     $(".sender-behaelter").html(Mustache.render(templateCache[TPL_SENDER], senderliste));
a480d0 79   });
U 80 }
81
b520d1 82 function app_dialog_laden_und_zeigen(vorlage, adresse) {
36646e 83   if(adresse !== '') {
U 84     $.ajax({
85       url: adresse,
86       type: "GET",
87       dataType : "json"
88     }).done(function( msg ) {
8881ca 89       app_dialog_zeigen(vorlage, msg);
36646e 90     });
U 91   } else {
8881ca 92     app_dialog_zeigen(vorlage, '');
36646e 93   }
9e336a 94 }
U 95
47a970 96 /*
U 97   Ein Template vom Server in den Cache laden
98   template_url - home.tpl, prefs.tpl, sender.tpl
99   tname - 'home', 'prefs', 'sender'
100 */
101 function app_get_template(template_url, tname) {
102   $.ajax({
103     url: template_url,
104     type: "GET",
105     dataType : "text"
106   }).done(function( template ) {
107     templateCache[tname] = template;
108   });
623a61 109 }