Improve framework
authorJoey Schulze <joey@infodrom.org>
Tue, 25 Dec 2018 00:25:15 +0000 (01:25 +0100)
committerJoey Schulze <joey@infodrom.org>
Tue, 25 Dec 2018 09:16:08 +0000 (10:16 +0100)
html/musiikki.js
templates/datetime.phtml
templates/rescan.phtml
templates/shares.phtml
templates/wifi.phtml

index e22475b..1001e53 100644 (file)
@@ -1,4 +1,5 @@
 // Script to open and close sidebar
+var page_callbacks = [];
 function w3_open()
 {
     $('#mySidebar').css('display', 'block');
@@ -11,19 +12,28 @@ function w3_close()
     $('#myOverlay').hide();
 }
 
+function register_callback(page, callback)
+{
+    page_callbacks[page] = callback;
+}
+
 function open_page(page) {
     w3_close();
     $('div.w3-container').hide();
 
-    if ($('div.w3-container#'+page + ' form').length)
+    if ($('div.w3-container#'+page + '[data-fetch="true"]').length)
        $.post('index.php',
               'action=get'+page,
               function(data){
                   if (typeof data == 'object') {
-                      for (name in data) {
-                          obj = $('div.w3-container#'+page + ' [name="'+name+'"]');
-                          if (obj.length)
-                              obj.val(data[name]);
+                      if (page in page_callbacks) {
+                          page_callbacks[page](data);
+                      } else {
+                          for (name in data) {
+                              obj = $('div.w3-container#'+page + ' [name="'+name+'"]');
+                              if (obj.length)
+                                  obj.val(data[name]);
+                          }
                       }
                   }
               });
index a583491..d9afdb9 100644 (file)
@@ -1,5 +1,5 @@
 <!-- Date/Time -->
-<div class="w3-container" id="datetime" style="margin-top:75px" style="display:none;">
+<div class="w3-container" id="datetime" style="margin-top:75px" data-fetch="true" style="display:none;">
   <h1 class="w3-xxxlarge w3-text-blue"><b>Date/Time.</b></h1>
   <hr style="width:50px;border:5px solid blue" class="w3-round">
   <p>Configure date and time.</p>
index 38599d2..61eefdc 100644 (file)
@@ -1,5 +1,5 @@
 <!-- Rescan -->
-<div class="w3-container" id="rescan" style="margin-top:75px" style="display:none;">
+<div class="w3-container" id="rescan" style="margin-top:75px" data-fetch="true" style="display:none;">
   <h1 class="w3-xxxlarge w3-text-blue"><b>Rescan.</b></h1>
   <hr style="width:50px;border:5px solid blue" class="w3-round">
   <form>
index 3b4bf4d..f9e4c6c 100644 (file)
@@ -1,5 +1,5 @@
 <!-- Shares -->
-<div class="w3-container" id="shares" style="margin-top:75px" style="display:none;">
+<div class="w3-container" id="shares" style="margin-top:75px" data-fetch="true" style="display:none;">
   <h1 class="w3-xxxlarge w3-text-blue"><b>Laufwerke.</b></h1>
   <hr style="width:50px;border:5px solid blue" class="w3-round">
   <form>
index 617725b..a297bcd 100644 (file)
@@ -1,5 +1,5 @@
 <!-- Wifi -->
-<div class="w3-container" id="wifi" style="margin-top:75px" style="display:none;">
+<div class="w3-container" id="wifi" style="margin-top:75px" data-fetch="true" style="display:none;">
   <h1 class="w3-xxxlarge w3-text-blue"><b>WLAN.</b></h1>
   <hr style="width:50px;border:5px solid blue" class="w3-round">
   <p>Netzwerk-Name und Passwort setzen</p>