1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-11-26 06:47:17 +00:00

Hide Dirble app, if no API token is given/available

This commit is contained in:
eb041592 2018-02-04 12:50:44 +01:00
parent b091e47d2f
commit b3037d6117

View File

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