Bedienoberfläche für Webradio
ulrich
2018-01-04 8881caa05f19299ddcc775b30b8c3c8ada2108b1
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';
47a970 6 var templateCache = {}; // mustache templates 'home', 'prefs', 'sender'
623a61 7 var prefsRendered = false;
U 8
9 function app_init() {
9f0d54 10   $('.dialog').hide();
623a61 11   $('.ost').hide();
ec55bf 12   app_menu_init("data/menu/", "hauptmenue.json", "../jslib/app-menu/app-menu.tpl", ".west");
8881ca 13   app_get_template('data/tpl/dlg-msg.tpl', TPL_DLG_MSG);
U 14   app_get_template('data/tpl/dlg-info.tpl', TPL_DLG_INFO);
15   app_get_template('data/tpl/sender.tpl', TPL_SENDER);
623a61 16   //app_get_template('tpl/prefs.tpl', 'prefs');
U 17   $('.sued').text('Bereit.');
18   setTimeout(function() {
a480d0 19     app_get_sender();
623a61 20   }, 200);
47a970 21 }
U 22
8881ca 23 /* --- Menüfunktionen --- */
U 24
9f0d54 25 function app_nachricht_test() {
36646e 26   app_nachricht_zeigen(templateCache[TPL_DLG_MSG], 'data/msg-test.json');
U 27 }
28
29 function app_info_dialog_zeigen() {
30   app_nachricht_zeigen(templateCache[TPL_DLG_INFO], '');
8881ca 31 }
U 32
33 /* --- Sonstiges --- */
34
35 function app_dialog_zeigen(vorlage, inhalt) {
36   $(".dialog").html(Mustache.render(vorlage, inhalt));
37   $(".close-btn").on('click', function() {
38     $('.close-btn').attr('onclick','').unbind('click');
39     $('.dialog').slideUp(300);
40   });
41   $('.dialog').slideDown(300);
9f0d54 42 }
U 43
47a970 44 /* --- Ajax-Aufrufe --- */
U 45
a480d0 46 function app_get_sender() {
U 47   $.ajax({
0c85a2 48     url: "data/sender.json",
a480d0 49     type: "GET",
U 50     dataType : "json"
51   }).done(function( senderliste ) {
21dcfa 52     $(".sender-behaelter").html(Mustache.render(templateCache[TPL_SENDER], senderliste));
a480d0 53   });
U 54 }
55
36646e 56 function app_nachricht_zeigen(vorlage, adresse) {
U 57   if(adresse !== '') {
58     $.ajax({
59       url: adresse,
60       type: "GET",
61       dataType : "json"
62     }).done(function( msg ) {
8881ca 63       app_dialog_zeigen(vorlage, msg);
36646e 64     });
U 65   } else {
8881ca 66     app_dialog_zeigen(vorlage, '');
36646e 67   }
9e336a 68 }
U 69
47a970 70 /*
U 71   Ein Template vom Server in den Cache laden
72   template_url - home.tpl, prefs.tpl, sender.tpl
73   tname - 'home', 'prefs', 'sender'
74 */
75 function app_get_template(template_url, tname) {
76   $.ajax({
77     url: template_url,
78     type: "GET",
79     dataType : "text"
80   }).done(function( template ) {
81     templateCache[tname] = template;
82   });
623a61 83 }