From 9e336ac4568cb7f319fdf6cf7cb2d3851a9346db Mon Sep 17 00:00:00 2001 From: ulrich <not disclosed> Date: Thu, 04 Jan 2018 09:07:11 +0000 Subject: [PATCH] Nachrichtendialog in Template überführt --- data/msg-test.json | 4 ++++ app.js | 23 ++++++++++++++++++----- data/sender.json | 0 index.html | 11 +---------- tpl/dlg-msg.tpl | 4 ++++ 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/app.js b/app.js index 988d77e..6d38c15 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,7 @@ var TPL_HOME = 'home'; var TPL_PREFS = 'prefs'; var TPL_SENDER = 'sender'; +var TPL_DLG_MSG = 'dlg-msg'; var templateCache = {}; // mustache templates 'home', 'prefs', 'sender' var prefsRendered = false; @@ -8,6 +9,7 @@ $('.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/sender.tpl', TPL_SENDER); //app_get_template('tpl/prefs.tpl', 'prefs'); $('.sued').text('Bereit.'); @@ -17,11 +19,7 @@ } function app_nachricht_test() { - $(".close-btn").on('click', function() { - $('.close-btn').attr('onclick','').unbind('click'); - $('.dialog').slideUp(300); - }); - $('.dialog').slideDown(300); + app_get_nachricht('api/msg-test.json'); } /* --- Ajax-Aufrufe --- */ @@ -36,6 +34,21 @@ }); } +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 diff --git a/data/msg-test.json b/data/msg-test.json new file mode 100644 index 0000000..23cb64e --- /dev/null +++ b/data/msg-test.json @@ -0,0 +1,4 @@ +{ + "typ": "nachricht", + "text": "Hier kann eine Mitteilung stehen." +} diff --git a/api/sender.json b/data/sender.json similarity index 100% rename from api/sender.json rename to data/sender.json diff --git a/index.html b/index.html index 1feb93d..d063759 100644 --- a/index.html +++ b/index.html @@ -25,16 +25,8 @@ <div class="west"></div> <!-- zentraler Bereich --> <div class="zentrum-behaelter"> - <!-- Einblendbereich --> - - <div class="dialog"> - <div class="nachricht"> - <span class="close-btn pointer-cursor">✖</span> - Hier kann eine Mitteilung stehen. - </div> - </div> - + <div class="dialog"></div> <!-- zentraler Inhaltsbereich --> <div class="zentrum"> <div id="prefs"></div> @@ -57,7 +49,6 @@ <script src="../jslib/mustache/mustache.min.js"></script> <script src="../jslib/app-menu/app-menu.js"></script> <script src="app.js"></script> - <script type="text/javascript" charset="utf-8"> $(document).ready(function() { app_init(); diff --git a/tpl/dlg-msg.tpl b/tpl/dlg-msg.tpl new file mode 100644 index 0000000..b5d0ff5 --- /dev/null +++ b/tpl/dlg-msg.tpl @@ -0,0 +1,4 @@ +<div class="{{typ}}"> + <span class="close-btn pointer-cursor">✖</span> + {{text}} +</div> -- Gitblit v1.9.3