Bedienoberfläche für Webradio
..
ulrich
2018-01-04 d47008dac265779ba400ff1f0b1844dbfe4d4ef4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var TPL_HOME = 'home';
var TPL_PREFS = 'prefs';
var TPL_SENDER = 'sender';
var TPL_DLG_MSG = 'dlg-msg';
var TPL_DLG_INFO = 'dlg-info';
var templateCache = {}; // mustache templates 'home', 'prefs', 'sender'
var prefsRendered = false;
 
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_get_template('tpl/prefs.tpl', 'prefs');
  $('.sued').text('Bereit.');
  setTimeout(function() {
    app_get_sender();
  }, 200);
}
 
function app_nachricht_test() {
  app_nachricht_zeigen(templateCache[TPL_DLG_MSG], 'data/msg-test.json');
}
 
function app_info_dialog_zeigen() {
  app_nachricht_zeigen(templateCache[TPL_DLG_INFO], '');
}
 
/* --- Ajax-Aufrufe --- */
 
function app_get_sender() {
  $.ajax({
    url: "data/sender.json",
    type: "GET",
    dataType : "json"
  }).done(function( senderliste ) {
    $(".sender-behaelter").html(Mustache.render(templateCache[TPL_SENDER], senderliste));
  });
}
 
function app_nachricht_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);
    });
  } else {
    $(".dialog").html(Mustache.render(vorlage, ''));
    $(".close-btn").on('click', function() {
      $('.close-btn').attr('onclick','').unbind('click');
      $('.dialog').slideUp(300);
    });
    $('.dialog').slideDown(300);
  }
}
 
/*
  Ein Template vom Server in den Cache laden
  template_url - home.tpl, prefs.tpl, sender.tpl
  tname - 'home', 'prefs', 'sender'
*/
function app_get_template(template_url, tname) {
  $.ajax({
    url: template_url,
    type: "GET",
    dataType : "text"
  }).done(function( template ) {
    templateCache[tname] = template;
  });
}