Bedienoberfläche für Webradio
ulrich
2018-01-04 9e336ac4568cb7f319fdf6cf7cb2d3851a9346db
app.js
@@ -1,17 +1,65 @@
var TPL_HOME = 'home';
var TPL_PREFS = 'prefs';
var templateCache = {}; // mustache templates 'home', 'prefs'
var TPL_SENDER = 'sender';
var TPL_DLG_MSG = 'dlg-msg';
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/home.tpl', 'home');
  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/sender.tpl', TPL_SENDER);
  //app_get_template('tpl/prefs.tpl', 'prefs');
  $('.sued').text('Bereit.');
  /*
  setTimeout(function() {
    app_seitenwechsel('home', 'vor');
    app_get_sender();
  }, 200);
  */
}
function app_nachricht_test() {
  app_get_nachricht('api/msg-test.json');
}
/* --- Ajax-Aufrufe --- */
function app_get_sender() {
  $.ajax({
    url: "api/sender.json",
    type: "GET",
    dataType : "json"
  }).done(function( senderliste ) {
    $("#sender").html(Mustache.render(templateCache[TPL_SENDER], senderliste));
  });
}
function app_get_nachricht(addr) {
  $.ajax({
    url: addr,
    type: "GET",
    dataType : "json"
  }).done(function( msg ) {
    $(".dialog").html(Mustache.render(templateCache[TPL_DLG_MSG], msg));
    $(".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;
  });
}