nextcloud-app-radio/js/navigation.js

104 lines
3.0 KiB
JavaScript
Raw Normal View History

2018-08-20 14:20:03 +00:00
var MODULE = (function (radio) {
/* Click on menus */
2019-05-11 15:03:20 +00:00
$('#app-navigation ul a').click(function(e) {
2018-08-20 14:20:03 +00:00
e.preventDefault();
2019-05-11 15:03:20 +00:00
radio.action_navigate($(this).attr('href'));
2018-08-20 14:20:03 +00:00
});
2019-05-11 15:03:20 +00:00
/* Click on a radio station (table entry) and play it */
$('body').on('click', '.filename', function(e) {
2018-08-20 14:20:03 +00:00
e.preventDefault();
2019-05-11 15:03:20 +00:00
var entry_src = $(this).parent().attr('data-src');
if (entry_src.substring(0,9) == "#station/") {
var stationid = entry_src.substring(9);
var stationname = $(this).parent().find('.nametext').text();
radio.action_play(stationid, stationname);
} else {
radio.action_navigate(entry_src);
}
2018-08-20 14:20:03 +00:00
});
2019-05-11 15:03:20 +00:00
/* Save station to favorites */
$('body').on('click', '.favorite', function(e) {
e.preventDefault();
2019-05-11 15:03:20 +00:00
var entry_src = $(this).parent().parent().attr('data-src');
var stationid = entry_src.substring(9);
radio.action_favorite(stationid);
});
2019-05-11 15:03:20 +00:00
radio.action_load_menu_state = function() {
2018-08-20 14:20:03 +00:00
var baseUrl = OC.generateUrl('/apps/radio/getMenuState');
$.get(baseUrl, function ( data ) {
if ("menu_state" in data) {
2019-05-11 15:03:20 +00:00
var hashurl = data["menu_state"];
2018-08-20 14:20:03 +00:00
}
2019-05-11 15:03:20 +00:00
radio.action_navigate(hashurl);
2018-08-20 14:20:03 +00:00
return true;
});
}
2019-05-11 15:03:20 +00:00
radio.action_save_menu_state = function(hashurl) {
2018-08-20 14:20:03 +00:00
var baseUrl = OC.generateUrl('/apps/radio/saveMenuState');
var settings = {
2019-05-11 15:03:20 +00:00
"menu_state": hashurl
2018-08-20 14:20:03 +00:00
};
$.ajax({
url: baseUrl,
method: 'POST',
contentType: 'application/json',
data: JSON.stringify(settings)
}).done(function(data){
return true;
});
}
2019-05-11 15:03:20 +00:00
radio.action_navigate = function(hashurl) {
2018-08-20 14:20:03 +00:00
$('#filestable').hide();
$('#emptycontent').addClass('hidden');
$('.nofilterresults').addClass('hidden');
$('.loading').removeClass('hidden');
2019-05-11 15:03:20 +00:00
$('#app-navigation').find('li').removeClass("active");
$("tbody > tr").remove();
history.pushState("", "", hashurl);
radio.action_save_menu_state(hashurl)
2018-08-20 14:20:03 +00:00
2019-05-11 15:03:20 +00:00
clearTimeout(radio.searchTimeout);
radio.searchTimeout = setTimeout(function(){
switch (hashurl) {
case "#top":
2018-08-20 14:20:03 +00:00
$('li.nav-files').addClass('active');
2019-05-11 15:03:20 +00:00
radio.radio_query(hashurl);
2018-08-20 14:20:03 +00:00
break;
2019-05-11 15:03:20 +00:00
case "#recent":
2018-08-20 14:20:03 +00:00
$('li.nav-recent').addClass('active');
2019-05-11 15:03:20 +00:00
radio.radio_query(hashurl);
2018-08-20 14:20:03 +00:00
break;
2019-05-11 15:03:20 +00:00
case "#favorites":
2018-08-20 14:20:03 +00:00
$('li.nav-favorites').addClass('active');
radio.action_load_favorites();
break;
2019-05-11 15:03:20 +00:00
case "#categories":
$('li.nav-categories').addClass('active');
radio.action_load_categories();
break;
2019-05-11 15:03:20 +00:00
case (hashurl.match(/^#categories/) || {}).input:
$('li.nav-categories').addClass('active');
radio.radio_query(hashurl);
break;
2018-08-20 14:20:03 +00:00
}
}, 500);
};
// On app start, load top list
if(window.location.hash) {
2019-05-11 15:03:20 +00:00
var hashurl = window.location.hash;
radio.action_navigate(hashurl);
2018-08-20 14:20:03 +00:00
} else {
2019-05-11 15:03:20 +00:00
radio.action_load_menu_state();
2018-08-20 14:20:03 +00:00
};
return radio;
}(MODULE || {}));