Hide Dirble app, if no API token is given/available
authoreb041592 <35889760+eb041592@users.noreply.github.com>
Sun, 4 Feb 2018 11:50:44 +0000 (12:50 +0100)
committereb041592 <35889760+eb041592@users.noreply.github.com>
Sun, 4 Feb 2018 12:43:37 +0000 (13:43 +0100)
htdocs/js/mpd.js

index 8231f45..0f9e188 100644 (file)
@@ -110,7 +110,6 @@ var app = $.sammy(function() {
         $('#panel-heading').text("Search: "+searchstr);
     });
 
-
     this.get(/\#\/dirble\/(\d+)\/(\d+)/, function() {
         prepare();
         current_app = 'dirble';
@@ -134,14 +133,9 @@ var app = $.sammy(function() {
 
         dirble_stations = true;
 
-        if(dirble_api_token) {
-            dirble_load_stations();
-        } else {
-            getDirbleApiToken();
-        }
+        if (dirble_api_token) { dirble_load_stations(); }
     });
 
-
     this.get(/\#\/dirble\//, function() {
         prepare();
         current_app = 'dirble';
@@ -157,11 +151,7 @@ var app = $.sammy(function() {
 
         dirble_stations = false;
 
-        if(dirble_api_token) {
-            dirble_load_categories();
-        } else {
-            getDirbleApiToken();
-        }
+        if (dirble_api_token) { dirble_load_categories(); }
     });
 
     this.get("/", function(context) {
@@ -199,7 +189,6 @@ $(document).ready(function(){
     add_filter();
 });
 
-
 function webSocketConnect() {
     if (typeof MozWebSocket != "undefined") {
         socket = new MozWebSocket(get_appropriate_ws_url());
@@ -217,7 +206,9 @@ function webSocketConnect() {
 
             app.run();
             /* emit initial request for output names */
-            socket.send("MPD_API_GET_OUTPUTS");
+            socket.send('MPD_API_GET_OUTPUTS');
+            /* emit initial request for dirble api token */
+            socket.send('MPD_API_GET_DIRBLEAPITOKEN');
         }
 
         socket.onmessage = function got_packet(msg) {
@@ -567,11 +558,15 @@ function webSocketConnect() {
                 case 'dirbleapitoken':
                     dirble_api_token = obj.data;
                     
-                    if(dirble_stations) {
-                        dirble_load_stations();
+                   if (dirble_api_token) {
+                       $('#dirble').removeClass('hide');
+
+                        if (dirble_stations) { dirble_load_stations();   }
+                        else {                 dirble_load_categories(); }
+
                     } else {
-                        dirble_load_categories();
-                    }
+                        $('#dirble').addClass('hide');
+                   }
                     break;
                 case 'error':
                     $('.top-right').notify({
@@ -581,9 +576,8 @@ function webSocketConnect() {
                 default:
                     break;
             }
-
-
         }
+
         socket.onclose = function(){
             console.log("disconnected");
             $('.top-right').notify({
@@ -775,10 +769,6 @@ function getHost() {
     $('#mpd_pw_con').keypress(onEnter);
 }
 
-function getDirbleApiToken() {
-    socket.send('MPD_API_GET_DIRBLEAPITOKEN');
-}
-
 $('#search').submit(function () {
     app.setLocation("#/search/"+$('#search > div > input').val());
     $('#wait').modal('show');