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