2018-05-14 23:13:43 +00:00
|
|
|
|
/* myMPD
|
|
|
|
|
(c) 2018 Juergen Mang <mail@jcgames.de>
|
2018-06-21 21:29:49 +00:00
|
|
|
|
This project's homepage is: https://github.com/jcorporation/mympd
|
2018-05-14 23:13:43 +00:00
|
|
|
|
|
|
|
|
|
myMPD ist fork of:
|
|
|
|
|
|
|
|
|
|
ympd
|
2014-02-22 00:57:26 +00:00
|
|
|
|
(c) 2013-2014 Andrew Karpow <andy@ndyk.de>
|
2016-09-11 15:54:25 +00:00
|
|
|
|
This project's homepage is: https://www.ympd.org
|
2014-02-22 00:57:26 +00:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2014-01-17 18:41:41 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2013-11-04 17:18:38 +00:00
|
|
|
|
var socket;
|
2018-06-11 17:33:11 +00:00
|
|
|
|
var last_song = '';
|
2013-11-05 13:59:12 +00:00
|
|
|
|
var last_state;
|
2015-04-28 09:08:21 +00:00
|
|
|
|
var last_outputs;
|
2014-01-16 17:32:20 +00:00
|
|
|
|
var current_song = new Object();
|
2015-10-22 15:48:42 +00:00
|
|
|
|
var isTouch = Modernizr.touch ? 1 : 0;
|
2018-06-03 08:52:38 +00:00
|
|
|
|
var playstate = '';
|
2018-05-21 23:36:05 +00:00
|
|
|
|
var progressBar;
|
|
|
|
|
var volumeBar;
|
2018-06-21 16:57:40 +00:00
|
|
|
|
var settings = {};
|
2013-11-04 17:18:38 +00:00
|
|
|
|
|
2018-06-07 18:47:40 +00:00
|
|
|
|
var app = {};
|
|
|
|
|
|
2018-06-10 21:21:48 +00:00
|
|
|
|
app.apps = { "Playback": { "state": "0/-/" },
|
|
|
|
|
"Queue": { "state": "0/Any Tag/" },
|
|
|
|
|
"Browse": {
|
|
|
|
|
"active": "Database",
|
|
|
|
|
"tabs": { "Filesystem": { "state": "0/-/" },
|
|
|
|
|
"Playlists": { "state": "0/-/" },
|
|
|
|
|
"Database": {
|
|
|
|
|
"active": "Artist",
|
|
|
|
|
"views": { "Artist": { "state": "0/-/" },
|
|
|
|
|
"Album": { "state": "0/-/" }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"Search": { "state": "0/Any Tag/" }
|
2018-06-07 18:47:40 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.current = { "app": "Playback", "tab": undefined, "view": undefined, "page": 0, "filter": "", "search": "" };
|
|
|
|
|
app.last = { "app": undefined, "tab": undefined, "view": undefined };
|
2018-06-07 18:47:40 +00:00
|
|
|
|
|
|
|
|
|
app.prepare=function() {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
if (app.current.app != app.last.app || app.current.tab != app.last.tab || app.current.view != app.last.view) {
|
2018-06-10 21:48:02 +00:00
|
|
|
|
//Hide all cards + nav
|
2018-06-07 18:47:40 +00:00
|
|
|
|
$('#navbar-bottom > div').removeClass('active');
|
|
|
|
|
$('#cardPlayback').addClass('hide');
|
|
|
|
|
$('#cardQueue').addClass('hide');
|
|
|
|
|
$('#cardBrowse').addClass('hide');
|
|
|
|
|
$('#cardSearch').addClass('hide');
|
2018-06-10 21:48:02 +00:00
|
|
|
|
$('#panel-heading-browse > ul > li > a').removeClass('active');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
$('#cardBrowsePlaylists').addClass('hide');
|
|
|
|
|
$('#cardBrowseDatabase').addClass('hide');
|
|
|
|
|
$('#cardBrowseFilesystem').addClass('hide');
|
2018-06-10 21:48:02 +00:00
|
|
|
|
//show active card + nav
|
2018-06-10 21:15:33 +00:00
|
|
|
|
$('#card'+app.current.app).removeClass('hide');
|
|
|
|
|
$('#nav'+app.current.app).addClass('active');
|
|
|
|
|
if (app.current.tab != undefined) {
|
|
|
|
|
$('#card'+app.current.app+app.current.tab).removeClass('hide');
|
|
|
|
|
$('#card'+app.current.app+'Nav'+app.current.tab).addClass('active');
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-07 22:26:35 +00:00
|
|
|
|
app.goto=function(a,t,v,s) {
|
2018-06-20 22:00:46 +00:00
|
|
|
|
var hash='';
|
2018-06-07 22:26:35 +00:00
|
|
|
|
if (app.apps[a].tabs) {
|
|
|
|
|
if (t == undefined) t = app.apps[a].active;
|
|
|
|
|
if (app.apps[a].tabs[t].views) {
|
|
|
|
|
if (v == undefined) v = app.apps[a].tabs[t].active;
|
2018-06-20 22:00:46 +00:00
|
|
|
|
hash = '/'+a+'/'+t+'/'+v+'!'+ (s == undefined ? app.apps[a].tabs[t].views[v].state : s);
|
2018-06-07 22:26:35 +00:00
|
|
|
|
} else {
|
2018-06-20 22:00:46 +00:00
|
|
|
|
hash = '/'+a+'/'+t+'!'+ (s == undefined ? app.apps[a].tabs[t].state : s);
|
2018-06-07 22:26:35 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2018-06-20 22:00:46 +00:00
|
|
|
|
hash = '/'+a+'!'+ (s == undefined ? app.apps[a].state : s);
|
2018-06-07 22:26:35 +00:00
|
|
|
|
}
|
2018-06-20 22:00:46 +00:00
|
|
|
|
location.hash=hash;
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.route=function() {
|
|
|
|
|
var hash=decodeURI(location.hash);
|
2018-06-20 22:00:46 +00:00
|
|
|
|
if (params=hash.match(/^\#\/(\w+)\/?(\w+)?\/?(\w+)?\!((\d+)\/([^\/]+)\/(.*))$/))
|
|
|
|
|
{
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.current.app = params[1];
|
|
|
|
|
app.current.tab = params[2];
|
|
|
|
|
app.current.view = params[3];
|
2018-06-11 15:30:08 +00:00
|
|
|
|
if (app.apps[app.current.app].state) {
|
|
|
|
|
app.apps[app.current.app].state = params[4];
|
|
|
|
|
}
|
|
|
|
|
else if (app.apps[app.current.app].tabs[app.current.tab].state) {
|
|
|
|
|
app.apps[app.current.app].tabs[app.current.tab].state = params[4];
|
|
|
|
|
app.apps[app.current.app].active=app.current.tab;
|
|
|
|
|
}
|
|
|
|
|
else if (app.apps[app.current.app].tabs[app.current.tab].views[app.current.view].state) {
|
|
|
|
|
app.apps[app.current.app].tabs[app.current.tab].views[app.current.view].state = params[4];
|
|
|
|
|
app.apps[app.current.app].active=app.current.tab;
|
|
|
|
|
app.apps[app.current.app].tabs[app.current.tab].active=app.current.view;
|
|
|
|
|
}
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.current.page = parseInt(params[5]);
|
|
|
|
|
app.current.filter = params[6];
|
|
|
|
|
app.current.search = params[7];
|
|
|
|
|
} else {
|
2018-06-11 18:34:45 +00:00
|
|
|
|
app.goto("Playback");
|
|
|
|
|
return;
|
2018-06-10 21:15:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.prepare();
|
|
|
|
|
if (app.current.app == 'Playback') {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_CURRENT_SONG"},songChange);
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
2018-06-10 21:15:33 +00:00
|
|
|
|
else if (app.current.app == 'Queue' ) {
|
|
|
|
|
if (app.last.app != app.current.app) {
|
|
|
|
|
if (app.current.search.length < 2) {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
setPagination(app.current.page);
|
2018-05-29 20:12:11 +00:00
|
|
|
|
}
|
2018-05-31 23:05:49 +00:00
|
|
|
|
$('#searchqueuetag > button').each(function() {
|
2018-06-14 19:56:12 +00:00
|
|
|
|
$(this).addClass('btn-secondary').removeClass('btn-success');
|
|
|
|
|
if ($(this).text() == app.current.filter) {
|
|
|
|
|
$(this).removeClass('btn-secondary').addClass('btn-success');
|
2018-05-31 23:05:49 +00:00
|
|
|
|
$('#searchqueuetagdesc').text($(this).text());
|
|
|
|
|
}
|
2018-05-29 20:12:11 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2018-06-14 19:56:12 +00:00
|
|
|
|
getQueue();
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
2018-06-10 21:15:33 +00:00
|
|
|
|
else if (app.current.app == 'Browse' && app.current.tab == 'Playlists') {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_PLAYLISTS","data": {"offset": app.current.page, "filter": app.current.filter}},parsePlaylists);
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
2018-06-10 21:15:33 +00:00
|
|
|
|
else if (app.current.app == 'Browse' && app.current.tab == 'Database' && app.current.view == 'Artist') {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_ARTISTS","data": {"offset": app.current.page, "filter": app.current.filter}},parseListDBtags);
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
2018-06-10 21:15:33 +00:00
|
|
|
|
else if (app.current.app == 'Browse' && app.current.tab == 'Database' && app.current.view == 'Album') {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_ARTISTALBUMS","data": {"offset": app.current.page, "filter": app.current.filter, "albumartist": app.current.search}},parseListDBtags);
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
2018-06-10 21:15:33 +00:00
|
|
|
|
else if (app.current.app == 'Browse' && app.current.tab == 'Filesystem') {
|
|
|
|
|
$('#BrowseBreadcrumb').empty().append('<li class="breadcrumb-item"><a uri="">root</a></li>');
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_FILESYSTEM","data": {"offset": app.current.page,"path":(app.current.search ? app.current.search : "/"),"filter": app.current.filter}},parseFilesystem);
|
2015-08-17 21:01:47 +00:00
|
|
|
|
// Don't add all songs from root
|
2018-05-31 23:05:49 +00:00
|
|
|
|
var add_all_songs = $('#browseFilesystemAddAllSongs');
|
2018-06-10 19:31:40 +00:00
|
|
|
|
if (app.current.search) {
|
2015-08-17 21:01:47 +00:00
|
|
|
|
add_all_songs.off(); // remove previous binds
|
|
|
|
|
add_all_songs.on('click', function() {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_ADD_TRACK", "data": { "uri": app.current.search}});
|
2015-08-17 21:01:47 +00:00
|
|
|
|
});
|
2018-06-03 10:50:50 +00:00
|
|
|
|
add_all_songs.removeAttr('disabled').removeClass('disabled');
|
2018-05-22 23:07:34 +00:00
|
|
|
|
} else {
|
2018-06-03 10:50:50 +00:00
|
|
|
|
add_all_songs.attr('disabled','disabled').addClass('disabled');
|
2015-08-17 21:01:47 +00:00
|
|
|
|
}
|
2018-05-13 23:06:12 +00:00
|
|
|
|
|
2018-06-10 19:31:40 +00:00
|
|
|
|
var path_array = app.current.search.split('/');
|
2014-01-16 17:32:20 +00:00
|
|
|
|
var full_path = "";
|
|
|
|
|
$.each(path_array, function(index, chunk) {
|
|
|
|
|
if(path_array.length - 1 == index) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
$('#BrowseBreadcrumb').append("<li class=\"breadcrumb-item active\">"+ chunk + "</li>");
|
2014-01-16 17:32:20 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
full_path = full_path + chunk;
|
2018-06-10 21:15:33 +00:00
|
|
|
|
$('#BrowseBreadcrumb').append("<li class=\"breadcrumb-item\"><a uri=\"" + full_path + "\">"+chunk+"</a></li>");
|
2014-01-16 17:32:20 +00:00
|
|
|
|
full_path += "/";
|
|
|
|
|
});
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
2018-06-10 21:15:33 +00:00
|
|
|
|
else if (app.current.app == 'Search') {
|
|
|
|
|
if (app.last.app != app.current.app) {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
if (app.current.search != '') {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
$('#SearchList > tbody').append(
|
2018-05-29 20:12:11 +00:00
|
|
|
|
"<tr><td><span class=\"material-icons\">search</span></td>" +
|
|
|
|
|
"<td colspan=\"3\">Searching</td>" +
|
|
|
|
|
"<td></td><td></td></tr>");
|
|
|
|
|
}
|
|
|
|
|
else {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
setPagination(app.current.page);
|
2018-05-29 20:12:11 +00:00
|
|
|
|
}
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#searchstr2').val(app.current.search);
|
2018-05-29 20:12:11 +00:00
|
|
|
|
}
|
2018-06-14 19:56:12 +00:00
|
|
|
|
$('#searchtags2 > button').each(function() {
|
|
|
|
|
$(this).addClass('btn-secondary').removeClass('btn-success');
|
|
|
|
|
if ($(this).text() == app.current.filter) {
|
|
|
|
|
$(this).removeClass('btn-secondary').addClass('btn-success');
|
|
|
|
|
$('#searchtags2desc').text($(this).text());
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-06-10 19:31:40 +00:00
|
|
|
|
if (app.current.search.length >= 2) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SEARCH", "data": { "mpdtag": app.current.filter,"offset":app.current.page,"searchstr":app.current.search}},parseSearch);
|
2018-05-29 23:12:47 +00:00
|
|
|
|
} else {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
$('#SearchList > tbody').empty();
|
2018-06-03 10:50:50 +00:00
|
|
|
|
$('#searchAddAllSongs').attr('disabled','disabled').addClass('disabled');
|
2018-05-29 20:12:11 +00:00
|
|
|
|
}
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto("Playback");
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
2018-06-10 21:15:33 +00:00
|
|
|
|
|
|
|
|
|
app.last.app=app.current.app;
|
|
|
|
|
app.last.tab=app.current.tab;
|
|
|
|
|
app.last.view=app.current.view;
|
2018-06-07 18:47:40 +00:00
|
|
|
|
};
|
2013-11-07 12:47:31 +00:00
|
|
|
|
|
2013-11-07 09:09:40 +00:00
|
|
|
|
$(document).ready(function(){
|
2018-06-21 17:28:07 +00:00
|
|
|
|
getSettings();
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_OUTPUTNAMES"},parseOutputnames);
|
2018-06-14 19:56:12 +00:00
|
|
|
|
|
2014-01-16 17:32:20 +00:00
|
|
|
|
webSocketConnect();
|
2018-05-21 23:36:05 +00:00
|
|
|
|
|
|
|
|
|
volumeBar=$('#volumebar').slider();
|
|
|
|
|
volumeBar.slider('setValue',0);
|
|
|
|
|
volumeBar.slider('on','slideStop', function(value){
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_VOLUME","data": {"volume":value}});
|
2014-01-16 17:32:20 +00:00
|
|
|
|
});
|
2018-05-21 23:36:05 +00:00
|
|
|
|
|
|
|
|
|
progressBar=$('#progressbar').slider();
|
|
|
|
|
progressBar.slider('setValue',0);
|
|
|
|
|
|
|
|
|
|
progressBar.slider('on','slideStop', function(value){
|
2014-01-17 15:41:54 +00:00
|
|
|
|
if(current_song && current_song.currentSongId >= 0) {
|
2018-05-21 23:36:05 +00:00
|
|
|
|
var seekVal = Math.ceil(current_song.totalTime*(value/100));
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_SEEK", "data": {"songid":current_song.currentSongId,"seek":seekVal}});
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2014-01-17 17:34:22 +00:00
|
|
|
|
|
2018-05-27 21:34:39 +00:00
|
|
|
|
$('#about').on('shown.bs.modal', function () {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_STATS"},parseStats);
|
2018-05-29 21:05:34 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
$('#settings').on('shown.bs.modal', function () {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_SETTINGS"},parseSettings);
|
2018-05-29 21:05:34 +00:00
|
|
|
|
})
|
2018-05-27 21:34:39 +00:00
|
|
|
|
|
2015-07-16 09:50:54 +00:00
|
|
|
|
$('#addstream').on('shown.bs.modal', function () {
|
|
|
|
|
$('#streamurl').focus();
|
2018-05-29 21:05:34 +00:00
|
|
|
|
})
|
|
|
|
|
|
2015-07-16 09:50:54 +00:00
|
|
|
|
$('#addstream form').on('submit', function (e) {
|
|
|
|
|
addStream();
|
|
|
|
|
});
|
2018-05-23 22:32:01 +00:00
|
|
|
|
|
|
|
|
|
$('#mainMenu').on('shown.bs.dropdown', function () {
|
|
|
|
|
$('#search > input').val('');
|
|
|
|
|
$('#search > input').focus();
|
2018-05-27 13:10:34 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-06-11 15:30:08 +00:00
|
|
|
|
add_filter('#BrowseFilesystemFilterLetters');
|
|
|
|
|
add_filter('#BrowseDatabaseFilterLetters');
|
|
|
|
|
add_filter('#BrowsePlaylistsFilterLetters');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
|
|
|
|
|
window.addEventListener("hashchange", app.route, false);
|
2013-11-07 09:09:40 +00:00
|
|
|
|
});
|
|
|
|
|
|
2013-11-05 13:59:12 +00:00
|
|
|
|
function webSocketConnect() {
|
2014-01-16 17:32:20 +00:00
|
|
|
|
if (typeof MozWebSocket != "undefined") {
|
2014-02-16 18:46:53 +00:00
|
|
|
|
socket = new MozWebSocket(get_appropriate_ws_url());
|
2014-01-16 17:32:20 +00:00
|
|
|
|
} else {
|
2014-02-16 18:46:53 +00:00
|
|
|
|
socket = new WebSocket(get_appropriate_ws_url());
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
socket.onopen = function() {
|
2014-02-16 18:46:53 +00:00
|
|
|
|
console.log("connected");
|
2018-05-22 23:07:34 +00:00
|
|
|
|
showNotification('Connected to myMPD','','','success');
|
2018-05-27 13:10:34 +00:00
|
|
|
|
$('#modalConnectionError').modal('hide');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
app.route();
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-22 01:11:45 +00:00
|
|
|
|
socket.onmessage = function got_packet(msg) {
|
|
|
|
|
if(msg.data === last_state || msg.data.length == 0)
|
2014-02-22 00:57:26 +00:00
|
|
|
|
return;
|
2018-05-17 22:10:57 +00:00
|
|
|
|
try {
|
|
|
|
|
var obj = JSON.parse(msg.data);
|
|
|
|
|
} catch(e) {
|
2018-05-27 15:30:36 +00:00
|
|
|
|
console.log('Invalid JSON data received: '+ msg.data);
|
2018-05-17 22:10:57 +00:00
|
|
|
|
}
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
|
|
|
|
switch (obj.type) {
|
2018-06-14 19:56:12 +00:00
|
|
|
|
case 'state':
|
|
|
|
|
parseState(obj);
|
|
|
|
|
break;
|
|
|
|
|
case 'disconnected':
|
|
|
|
|
showNotification('myMPD lost connection to MPD','','','danger');
|
|
|
|
|
break;
|
|
|
|
|
case 'update_queue':
|
|
|
|
|
if(app.current.app === 'Queue')
|
|
|
|
|
getQueue();
|
|
|
|
|
break;
|
|
|
|
|
case "song_change":
|
2018-06-19 22:43:36 +00:00
|
|
|
|
songChange(obj);
|
2018-06-14 19:56:12 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'error':
|
|
|
|
|
showNotification(obj.data,'','','danger');
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
socket.onclose = function(){
|
|
|
|
|
console.log('disconnected');
|
|
|
|
|
$('#modalConnectionError').modal('show');
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
console.log('reconnect');
|
|
|
|
|
webSocketConnect();
|
|
|
|
|
},3000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch(exception) {
|
|
|
|
|
alert('<p>Error' + exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_appropriate_ws_url()
|
|
|
|
|
{
|
|
|
|
|
var pcol;
|
|
|
|
|
var u = document.URL;
|
|
|
|
|
var separator;
|
|
|
|
|
|
|
|
|
|
if (u.substring(0, 5) == "https") {
|
|
|
|
|
pcol = "wss://";
|
|
|
|
|
u = u.substr(8);
|
|
|
|
|
} else {
|
|
|
|
|
pcol = "ws://";
|
|
|
|
|
if (u.substring(0, 4) == "http")
|
|
|
|
|
u = u.substr(7);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u = u.split('#');
|
|
|
|
|
if (/\/$/.test(u[0])) {
|
|
|
|
|
separator = "";
|
|
|
|
|
} else {
|
|
|
|
|
separator = "/";
|
|
|
|
|
}
|
|
|
|
|
return pcol + u[0] + separator + "ws";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseStats(obj) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
$('#mpdstats_artists').text(obj.data.artists);
|
|
|
|
|
$('#mpdstats_albums').text(obj.data.albums);
|
|
|
|
|
$('#mpdstats_songs').text(obj.data.songs);
|
|
|
|
|
$('#mpdstats_dbplaytime').text(beautifyDuration(obj.data.dbplaytime));
|
|
|
|
|
$('#mpdstats_playtime').text(beautifyDuration(obj.data.playtime));
|
|
|
|
|
$('#mpdstats_uptime').text(beautifyDuration(obj.data.uptime));
|
|
|
|
|
var d = new Date(obj.data.dbupdated * 1000);
|
|
|
|
|
$('#mpdstats_dbupdated').text(d.toUTCString());
|
|
|
|
|
$('#mympdVersion').text(obj.data.mympd_version);
|
|
|
|
|
$('#mpdVersion').text(obj.data.mpd_version);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-14 19:56:12 +00:00
|
|
|
|
function parseSettings(obj) {
|
2018-06-21 16:57:40 +00:00
|
|
|
|
if (obj.data.random)
|
|
|
|
|
$('#btnrandom').removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
else
|
|
|
|
|
$('#btnrandom').removeClass("btn-success").addClass("btn-secondary");
|
|
|
|
|
|
|
|
|
|
if (obj.data.consume)
|
|
|
|
|
$('#btnconsume').removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
else
|
|
|
|
|
$('#btnconsume').removeClass("btn-success").addClass("btn-secondary");
|
|
|
|
|
|
|
|
|
|
if (obj.data.single)
|
|
|
|
|
$('#btnsingle').removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
else
|
|
|
|
|
$('#btnsingle').removeClass("btn-success").addClass("btn-secondary");
|
|
|
|
|
|
|
|
|
|
if (obj.data.crossfade != undefined)
|
|
|
|
|
$('#inputCrossfade').removeAttr('disabled').val(obj.data.crossfade);
|
|
|
|
|
else
|
|
|
|
|
$('#inputCrossfade').attr('disabled', 'disabled');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
|
2018-06-21 16:57:40 +00:00
|
|
|
|
if (obj.data.mixrampdb != undefined)
|
|
|
|
|
$('#inputMixrampdb').removeAttr('disabled').val(obj.data.mixrampdb);
|
|
|
|
|
else
|
|
|
|
|
$('#inputMixrampdb').attr('disabled', 'disabled');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
|
2018-06-21 16:57:40 +00:00
|
|
|
|
if (obj.data.mixrampdelay != undefined)
|
|
|
|
|
$('#inputMixrampdelay').removeAttr('disabled').val(obj.data.mixrampdelay);
|
|
|
|
|
else
|
|
|
|
|
$('#inputMixrampdb').attr('disabled', 'disabled');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
|
2018-06-21 16:57:40 +00:00
|
|
|
|
if (obj.data.repeat)
|
|
|
|
|
$('#btnrepeat').removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
else
|
|
|
|
|
$('#btnrepeat').removeClass("btn-success").addClass("btn-secondary");
|
2018-06-14 19:56:12 +00:00
|
|
|
|
|
2018-06-21 16:57:40 +00:00
|
|
|
|
$("#selectReplaygain").val(obj.data.replaygain);
|
|
|
|
|
|
|
|
|
|
if (notificationsSupported()) {
|
|
|
|
|
if (obj.data.notificationWeb) {
|
|
|
|
|
$('#btnnotifyWeb').removeClass('btn-secondary').addClass("btn-success")
|
2018-06-14 19:56:12 +00:00
|
|
|
|
|
2018-06-21 16:57:40 +00:00
|
|
|
|
Notification.requestPermission(function (permission) {
|
|
|
|
|
if(!('permission' in Notification))
|
|
|
|
|
Notification.permission = permission;
|
|
|
|
|
if (permission === 'granted') {
|
|
|
|
|
$('#btnnotifyWeb').removeClass('btn-secondary').addClass('btn-success');
|
|
|
|
|
} else {
|
|
|
|
|
$('#btnnotifyWeb').addClass('btn-secondary').removeClass('btn-success');
|
|
|
|
|
obj.data.notificationWeb=0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
$('#btnnotifyWeb').addClass('btn-secondary').removeClass("btn-success");
|
|
|
|
|
} else {
|
|
|
|
|
$('#btnnotifyWeb').addClass("disabled");
|
|
|
|
|
$('#btnnotifyWeb').addClass('btn-secondary').removeClass("btn-success");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (obj.data.notificationPage)
|
|
|
|
|
$('#btnnotifyPage').removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
else
|
|
|
|
|
$('#btnnotifyPage').addClass('btn-secondary').removeClass("btn-success");
|
|
|
|
|
|
|
|
|
|
settings=obj.data;
|
2018-06-19 22:43:36 +00:00
|
|
|
|
setLocalStream(obj.data.mpdhost,obj.data.streamport);
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-21 17:28:07 +00:00
|
|
|
|
function getSettings() {
|
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_SETTINGS"},parseSettings);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-14 19:56:12 +00:00
|
|
|
|
function parseOutputnames(obj) {
|
|
|
|
|
$('#btn-outputs-block button').remove();
|
|
|
|
|
if ( Object.keys(obj.data).length ) {
|
|
|
|
|
$.each(obj.data, function(id, name){
|
|
|
|
|
var btn = $('<button id="btnoutput'+id+'" class="btn btn-secondary btn-block" onclick="toggleoutput(this, '+id+')">'+
|
|
|
|
|
'<span class="material-icons float-left">volume_up</span> '+name+'</button>');
|
|
|
|
|
btn.appendTo($('#btn-outputs-block'));
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$('#btn-outputs-block').addClass('hide');
|
|
|
|
|
}
|
|
|
|
|
/* remove cache, since the buttons have been recreated */
|
|
|
|
|
last_outputs = '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseState(obj) {
|
|
|
|
|
updatePlayIcon(obj);
|
|
|
|
|
updateVolumeIcon(obj.data.volume);
|
|
|
|
|
|
|
|
|
|
if(JSON.stringify(obj) === JSON.stringify(last_state))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
current_song.totalTime = obj.data.totalTime;
|
|
|
|
|
current_song.currentSongId = obj.data.currentsongid;
|
|
|
|
|
var total_minutes = Math.floor(obj.data.totalTime / 60);
|
|
|
|
|
var total_seconds = obj.data.totalTime - total_minutes * 60;
|
|
|
|
|
|
|
|
|
|
var elapsed_minutes = Math.floor(obj.data.elapsedTime / 60);
|
|
|
|
|
var elapsed_seconds = obj.data.elapsedTime - elapsed_minutes * 60;
|
|
|
|
|
|
|
|
|
|
volumeBar.slider('setValue',obj.data.volume);
|
|
|
|
|
var progress = Math.floor(100*obj.data.elapsedTime/obj.data.totalTime);
|
|
|
|
|
progressBar.slider('setValue',progress);
|
|
|
|
|
|
|
|
|
|
var counterText=elapsed_minutes + ":" +
|
|
|
|
|
(elapsed_seconds < 10 ? '0' : '') + elapsed_seconds + " / " +
|
|
|
|
|
total_minutes + ":" + (total_seconds < 10 ? '0' : '') + total_seconds;
|
|
|
|
|
|
|
|
|
|
$('#counter').text(counterText);
|
|
|
|
|
|
|
|
|
|
if (last_state) {
|
|
|
|
|
$('#QueueList > tbody > tr[trackid='+last_state.data.currentsongid+'] > td').eq(4).text(last_state.data.totalTime);
|
|
|
|
|
$('#QueueList > tbody > tr[trackid='+last_state.data.currentsongid+'] > td').eq(0).removeClass('material-icons').text(last_state.data.songpos);
|
|
|
|
|
}
|
|
|
|
|
$('#QueueList > tbody > tr').removeClass('active').removeClass("font-weight-bold");
|
|
|
|
|
|
|
|
|
|
$('#QueueList > tbody > tr[trackid='+obj.data.currentsongid+'] > td').eq(4).text(counterText);
|
|
|
|
|
$('#QueueList > tbody > tr[trackid='+obj.data.currentsongid+'] > td').eq(0).addClass('material-icons').text('play_arrow');
|
|
|
|
|
$('#QueueList > tbody > tr[trackid='+obj.data.currentsongid+']').addClass('active').addClass("font-weight-bold");
|
|
|
|
|
|
|
|
|
|
//Get current song on queue change for http streams
|
|
|
|
|
if (last_state == undefined || obj.data.queue_version != last_state.data.queue_version) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_CURRENT_SONG"},songChange);
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
last_state = obj;
|
|
|
|
|
|
|
|
|
|
$.each(obj.data.outputs, function(id, enabled){
|
|
|
|
|
if (enabled)
|
|
|
|
|
$('#btnoutput'+id).removeClass('btn-secondary').addClass("btn-success")
|
|
|
|
|
else
|
|
|
|
|
$('#btnoutput'+id).removeClass("btn-success").addClass("btn-secondary");
|
|
|
|
|
});
|
|
|
|
|
last_outputs = obj.data.outputs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getQueue() {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
if (app.current.search.length >= 2)
|
|
|
|
|
sendAPI({"cmd":"MPD_API_SEARCH_QUEUE", "data": {"mpdtag":app.current.filter, "offset":app.current.page,"searchstr": app.current.search}},parseQueue);
|
|
|
|
|
else
|
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_QUEUE", "data": {"offset": app.current.page}},parseQueue);
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseQueue(obj) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
if(app.current.app !== 'Queue')
|
2018-06-14 19:56:12 +00:00
|
|
|
|
return;
|
2018-05-27 12:37:50 +00:00
|
|
|
|
$('#panel-heading-queue').empty();
|
2018-05-29 21:55:24 +00:00
|
|
|
|
if (obj.totalEntities > 0) {
|
|
|
|
|
$('#panel-heading-queue').text(obj.totalEntities+' Songs');
|
2018-05-27 12:37:50 +00:00
|
|
|
|
}
|
|
|
|
|
if (typeof(obj.totalTime) != undefined && obj.totalTime > 0 ) {
|
2018-05-27 21:52:01 +00:00
|
|
|
|
$('#panel-heading-queue').append(' – ' + beautifyDuration(obj.totalTime));
|
2018-04-04 17:40:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-25 16:20:26 +00:00
|
|
|
|
var nrItems=0;
|
2018-06-10 19:31:40 +00:00
|
|
|
|
var tr=document.getElementById(app.current.app+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
2014-01-16 17:32:20 +00:00
|
|
|
|
for (var song in obj.data) {
|
2018-05-25 16:20:26 +00:00
|
|
|
|
nrItems++;
|
2014-01-16 17:32:20 +00:00
|
|
|
|
var minutes = Math.floor(obj.data[song].duration / 60);
|
|
|
|
|
var seconds = obj.data[song].duration - minutes * 60;
|
2018-05-29 20:12:11 +00:00
|
|
|
|
|
2018-05-29 23:12:47 +00:00
|
|
|
|
var row="<tr trackid=\"" + obj.data[song].id + "\"><td>" + (obj.data[song].pos + 1) + "</td>" +
|
2018-05-27 15:30:36 +00:00
|
|
|
|
"<td>"+ obj.data[song].title +"</td>" +
|
2014-11-11 17:41:39 +00:00
|
|
|
|
"<td>"+ obj.data[song].artist +"</td>" +
|
2018-04-23 11:38:58 +00:00
|
|
|
|
"<td>"+ obj.data[song].album +"</td>" +
|
2014-01-16 17:32:20 +00:00
|
|
|
|
"<td>"+ minutes + ":" + (seconds < 10 ? '0' : '') + seconds +
|
2018-05-29 23:12:47 +00:00
|
|
|
|
"</td><td></td></tr>";
|
2018-06-20 22:16:22 +00:00
|
|
|
|
if (nrItems <= tr.length) { if ($(tr[nrItems-1]).attr('trackid')!=obj.data[song].id) $(tr[nrItems-1]).replaceWith(row); }
|
2018-06-10 19:31:40 +00:00
|
|
|
|
else { $('#'+app.current.app+'List > tbody').append(row); }
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
2018-05-29 23:12:47 +00:00
|
|
|
|
for (var i=tr.length;i>nrItems;i--) {
|
2018-05-29 23:28:36 +00:00
|
|
|
|
$(tr[tr.length-1]).remove();
|
2018-05-29 23:12:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-25 16:20:26 +00:00
|
|
|
|
if (obj.type == 'queuesearch' && nrItems == 0) {
|
2018-06-10 21:48:02 +00:00
|
|
|
|
$('#QueueList > tbody').append(
|
2018-05-25 16:20:26 +00:00
|
|
|
|
"<tr><td><span class=\"material-icons\">error_outline</span></td>" +
|
|
|
|
|
"<td colspan=\"3\">No results, please refine your search!</td>" +
|
|
|
|
|
"<td></td><td></td></tr>"
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-05-29 21:55:24 +00:00
|
|
|
|
setPagination(obj.totalEntities);
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
2015-10-22 15:48:42 +00:00
|
|
|
|
if ( isTouch ) {
|
2018-06-10 21:48:02 +00:00
|
|
|
|
$('#QueueList > tbody > tr > td:last-child').append(
|
|
|
|
|
'<a class="pull-right btn-group-hover color-darkgrey" href="#/Queue!' + app.current.page + '/'+app.current.filter+'/'+app.current.search + '" '+
|
2018-06-11 17:33:11 +00:00
|
|
|
|
'onclick="delQueueSong($(this).parents(\'tr\'),event);">' +
|
2018-05-29 16:29:19 +00:00
|
|
|
|
'<span class="material-icons">delete</span></a>');
|
2015-10-22 15:48:42 +00:00
|
|
|
|
} else {
|
2018-06-10 21:48:02 +00:00
|
|
|
|
$('#QueueList > tbody > tr').on({
|
2015-10-22 15:48:42 +00:00
|
|
|
|
mouseover: function(){
|
2017-04-08 09:25:40 +00:00
|
|
|
|
var doomed = $(this);
|
2018-05-17 22:10:57 +00:00
|
|
|
|
if ( $('#btntrashmodeup').hasClass('btn-success') )
|
2018-06-11 17:33:11 +00:00
|
|
|
|
doomed = $('#QueueList > tbody > tr:lt(' + ($(this).index() + 1) + ')');
|
2018-05-17 22:10:57 +00:00
|
|
|
|
if ( $('#btntrashmodedown').hasClass('btn-success') )
|
2018-06-11 17:33:11 +00:00
|
|
|
|
doomed = $('#QueueList > tbody > tr:gt(' + ($(this).index() - 1) + ')');
|
2017-04-08 09:25:40 +00:00
|
|
|
|
$.each(doomed, function(){
|
2018-05-29 16:18:59 +00:00
|
|
|
|
if($(this).children().last().has('a').length == 0)
|
2015-10-22 15:48:42 +00:00
|
|
|
|
$(this).children().last().append(
|
2018-06-11 17:33:11 +00:00
|
|
|
|
'<a class="pull-right btn-group-hover color-darkgrey" href="#/Queue!'+ app.current.page + '/' +app.current.filter+'/'+app.current.search + '" ' +
|
|
|
|
|
'onclick="delQueueSong($(this).parents(\'tr\'),event);">' +
|
2018-05-29 16:18:59 +00:00
|
|
|
|
'<span class="material-icons">delete</span></a>')
|
2015-10-22 15:48:42 +00:00
|
|
|
|
.find('a').fadeTo('fast',1);
|
2017-04-08 09:25:40 +00:00
|
|
|
|
});
|
2015-10-22 15:48:42 +00:00
|
|
|
|
},
|
|
|
|
|
mouseleave: function(){
|
2017-04-08 09:25:40 +00:00
|
|
|
|
var doomed = $(this);
|
2018-05-17 22:10:57 +00:00
|
|
|
|
if ( $('#btntrashmodeup').hasClass('btn-success') )
|
2018-06-11 17:33:11 +00:00
|
|
|
|
doomed = $("#QueueList > tbody > tr:lt(" + ($(this).index() + 1) + ")");
|
2018-05-17 22:10:57 +00:00
|
|
|
|
if ( $('#btntrashmodedown').hasClass('btn-success') )
|
2018-06-11 17:33:11 +00:00
|
|
|
|
doomed = $("#QueueList > tbody > tr:gt(" + ($(this).index() - 1) + ")");
|
2017-04-08 09:25:40 +00:00
|
|
|
|
$.each(doomed, function(){$(this).children().last().find("a").stop().remove();});
|
2015-10-22 15:48:42 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2014-02-22 01:11:45 +00:00
|
|
|
|
|
2018-06-11 17:33:11 +00:00
|
|
|
|
$('#QueueList > tbody > tr').on({
|
2014-01-16 17:32:20 +00:00
|
|
|
|
click: function() {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$('#queueList > tbody > tr').removeClass('active');
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_PLAY_TRACK","data": {"track":$(this).attr('trackid')}});
|
2014-01-16 17:32:20 +00:00
|
|
|
|
$(this).addClass('active');
|
|
|
|
|
},
|
|
|
|
|
});
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseSearch(obj) {
|
|
|
|
|
if(app.current.app !== 'Search')
|
|
|
|
|
return;
|
|
|
|
|
$('#panel-heading-search').text(obj.totalEntities + ' Songs found');
|
|
|
|
|
if (obj.totalEntities > 0) {
|
|
|
|
|
$('#searchAddAllSongs').removeAttr('disabled').removeClass('disabled');
|
|
|
|
|
} else {
|
|
|
|
|
$('#searchAddAllSongs').attr('disabled','disabled').addClass('disabled');
|
|
|
|
|
}
|
|
|
|
|
parseFilesystem(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseFilesystem(obj) {
|
|
|
|
|
if(app.current.app !== 'Browse' && app.current.tab !== 'Filesystem' && app.current.app !== 'Search')
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* The use of encodeURI() below might seem useless, but it's not. It prevents
|
|
|
|
|
* some browsers, such as Safari, from changing the normalization form of the
|
|
|
|
|
* URI from NFD to NFC, breaking our link with MPD.
|
|
|
|
|
*/
|
2018-05-28 22:05:56 +00:00
|
|
|
|
var nrItems=0;
|
2018-06-14 19:56:12 +00:00
|
|
|
|
var tr=document.getElementById(app.current.app+(app.current.tab==undefined ? '' : app.current.tab)+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
for (var item in obj.data) {
|
|
|
|
|
nrItems++;
|
2018-06-14 19:56:12 +00:00
|
|
|
|
var row='';
|
2018-06-20 22:16:22 +00:00
|
|
|
|
var uri='';
|
2018-06-14 19:56:12 +00:00
|
|
|
|
switch(obj.data[item].type) {
|
|
|
|
|
case 'directory':
|
2018-06-20 22:16:22 +00:00
|
|
|
|
uri=encodeURI(obj.data[item].dir);
|
|
|
|
|
row ='<tr uri="' + uri + '" class="dir">' +
|
2018-06-14 19:56:12 +00:00
|
|
|
|
'<td><span class="material-icons">folder_open</span></td>' +
|
|
|
|
|
'<td colspan="3"><a>' + basename(obj.data[item].dir) + '</a></td>' +
|
|
|
|
|
'<td></td><td></td></tr>';
|
|
|
|
|
break;
|
|
|
|
|
case 'song':
|
|
|
|
|
var minutes = Math.floor(obj.data[item].duration / 60);
|
|
|
|
|
var seconds = obj.data[item].duration - minutes * 60;
|
2018-06-20 22:16:22 +00:00
|
|
|
|
uri=encodeURI(obj.data[item].uri);
|
|
|
|
|
row ='<tr uri="' + uri + '" class="song">' +
|
2018-06-14 19:56:12 +00:00
|
|
|
|
'<td><span class="material-icons">music_note</span></td>' +
|
|
|
|
|
'<td>' + obj.data[item].title + '</td>' +
|
|
|
|
|
'<td>' + obj.data[item].artist + '</td>' +
|
|
|
|
|
'<td>' + obj.data[item].album + '</td>' +
|
|
|
|
|
'<td>' + minutes + ':' + (seconds < 10 ? '0' : '') + seconds +
|
|
|
|
|
'</td><td></td></tr>';
|
|
|
|
|
break;
|
|
|
|
|
case 'playlist':
|
2018-06-20 22:16:22 +00:00
|
|
|
|
uri=encodeURI(obj.data[item].plist);
|
|
|
|
|
row ='<tr uri="' + uri + '" class="plist">' +
|
2018-06-14 19:56:12 +00:00
|
|
|
|
'<td><span class="material-icons">list</span></td>' +
|
|
|
|
|
'<td colspan="3"><a>' + basename(obj.data[item].plist) + '</a></td>' +
|
|
|
|
|
'<td></td><td></td></tr>';
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-06-20 22:16:22 +00:00
|
|
|
|
if (nrItems <= tr.length) { if ($(tr[nrItems-1]).attr('uri') != uri) $(tr[nrItems-1]).replaceWith(row); }
|
2018-06-14 19:56:12 +00:00
|
|
|
|
else { $('#'+app.current.app+(app.current.tab==undefined ? '' : app.current.tab)+'List > tbody').append(row); }
|
2018-06-03 16:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
for (var i=tr.length;i>nrItems;i--) {
|
2018-06-14 19:56:12 +00:00
|
|
|
|
$(tr[tr.length-1]).remove();
|
|
|
|
|
}
|
|
|
|
|
setPagination(obj.totalEntities);
|
|
|
|
|
|
|
|
|
|
if (nrItems == 0) {
|
|
|
|
|
$('#'+app.current.app+app.current.tab+'List > tbody').append(
|
|
|
|
|
'<tr><td><span class="material-icons">error_outline</span></td>' +
|
|
|
|
|
'<td colspan="3">No results</td>' +
|
|
|
|
|
'<td></td><td></td></tr>');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function appendClickableIcon(appendTo, onClickAction, glyphicon) {
|
|
|
|
|
$(appendTo).append(
|
|
|
|
|
'<a role="button" class="pull-right btn-group-hover">' +
|
|
|
|
|
'<span class="material-icons">' + glyphicon + '</span></a>')
|
|
|
|
|
.find('a').click(function(e) {
|
|
|
|
|
e.stopPropagation();
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":onClickAction,"data":{ "uri":decodeURI($(this).parents("tr").attr("uri"))}});
|
2018-06-14 19:56:12 +00:00
|
|
|
|
showNotification('"' + $('td:nth-last-child(3)', $(this).parents('tr')).text() + '" added','','','success');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isTouch ) {
|
|
|
|
|
appendClickableIcon($('#'+app.current.app+(app.current.tab == undefined ? '' : app.current.tab )+'List > tbody > tr.dir > td:last-child'), 'MPD_API_ADD_TRACK', 'playlist_add');
|
|
|
|
|
appendClickableIcon($('#'+app.current.app+(app.current.tab == undefined ? '' : app.current.tab )+'List > tbody > tr.song > td:last-child'), 'MPD_API_ADD_TRACK', 'playlist_add');
|
|
|
|
|
} else {
|
|
|
|
|
$('#'+app.current.app+(app.current.tab == undefined ? '' : app.current.tab )+'List > tbody > tr').on({
|
|
|
|
|
mouseenter: function() {
|
|
|
|
|
if($(this).is(".dir"))
|
|
|
|
|
appendClickableIcon($(this).children().last(), 'MPD_API_ADD_TRACK', 'playlist_add');
|
|
|
|
|
else if($(this).is(".song"))
|
|
|
|
|
appendClickableIcon($(this).children().last(), 'MPD_API_ADD_TRACK', 'playlist_add');
|
|
|
|
|
},
|
|
|
|
|
mouseleave: function(){
|
|
|
|
|
$(this).children().last().find("a").stop().remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
$('#'+app.current.app+(app.current.tab == undefined ? '' : app.current.tab )+'List > tbody > tr').on({
|
|
|
|
|
click: function() {
|
|
|
|
|
switch($(this).attr('class')) {
|
|
|
|
|
case 'dir':
|
|
|
|
|
app.current.page = 0;
|
|
|
|
|
app.current.search = $(this).attr("uri");
|
|
|
|
|
$("#BrowseFilesystemList > a").attr("href", '#/Browse/Filesystem!'+app.current.page+'/'+app.current.filter+'/'+app.current.search);
|
|
|
|
|
app.goto('Browse','Filesystem',undefined,app.current.page+'/'+app.current.filter+'/'+app.current.search);
|
|
|
|
|
break;
|
|
|
|
|
case 'song':
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_ADD_TRACK", "data": {"uri": decodeURI($(this).attr("uri"))}});
|
2018-06-14 19:56:12 +00:00
|
|
|
|
showNotification('"' + $('td:nth-last-child(5)', this).text() + '" added','','','success');
|
|
|
|
|
break;
|
|
|
|
|
case 'plist':
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_ADD_PLAYLIST", "data": {"plist": decodeURI($(this).attr("uri"))}});
|
2018-06-14 19:56:12 +00:00
|
|
|
|
showNotification('"' + $('td:nth-last-child(3)', this).text() + '" added','','','success');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#BrowseBreadcrumb > li > a').on({
|
|
|
|
|
click: function() {
|
|
|
|
|
app.current.page = 0;
|
|
|
|
|
app.current.search = $(this).attr("uri");
|
|
|
|
|
$("#BrowseFilesystemList > a").attr("href", '#/Browse/Filesystem!'+app.current.page+'/'+app.current.filter+'/'+app.current.search);
|
|
|
|
|
app.goto('Browse','Filesystem',undefined,app.current.page+'/'+app.current.filter+'/'+app.current.search);
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-06-19 22:43:36 +00:00
|
|
|
|
doSetFilterLetter('#BrowseFilesystemFilter');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parsePlaylists(obj) {
|
|
|
|
|
if(app.current.app !== 'Browse' && app.current.tab !== 'Playlists')
|
|
|
|
|
return;
|
|
|
|
|
var nrItems=0;
|
|
|
|
|
var tr=document.getElementById(app.current.app+app.current.tab+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
|
|
|
|
for (var item in obj.data) {
|
|
|
|
|
nrItems++;
|
|
|
|
|
var d = new Date(obj.data[item].last_modified * 1000);
|
2018-06-20 22:16:22 +00:00
|
|
|
|
var uri=encodeURI(obj.data[item].plist);
|
|
|
|
|
var row='<tr uri="' + uri + '">' +
|
2018-06-14 19:56:12 +00:00
|
|
|
|
'<td><span class="material-icons">list</span></td>' +
|
|
|
|
|
'<td><a>' + basename(obj.data[item].plist) + '</a></td>' +
|
|
|
|
|
'<td>'+d.toUTCString()+'</td><td></td></tr>';
|
2018-06-20 22:16:22 +00:00
|
|
|
|
if (nrItems <= tr.length) { if ($(tr[nrItems-1]).attr('uri') != uri) $(tr[nrItems-1]).replaceWith(row); }
|
2018-06-14 19:56:12 +00:00
|
|
|
|
else { $('#'+app.current.app+app.current.tab+'List > tbody').append(row); }
|
|
|
|
|
}
|
|
|
|
|
for (var i=tr.length;i>nrItems;i--) {
|
|
|
|
|
$(tr[tr.length-1]).remove();
|
2018-05-28 22:05:56 +00:00
|
|
|
|
}
|
|
|
|
|
setPagination(obj.totalEntities);
|
|
|
|
|
if ( isTouch ) {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+app.current.app+app.current.tab+'List > tbody > tr > td:last-child').append(
|
2018-06-10 21:48:02 +00:00
|
|
|
|
'<a class="pull-right btn-group-hover color-darkgrey" href="#/Browse/Playlists!' + app.current.page + '/'+app.current.filter+'/'+app.current.search+'" '+
|
2018-05-29 20:12:11 +00:00
|
|
|
|
'onclick="delPlaylist($(this).parents(\'tr\'));">' +
|
|
|
|
|
'<span class="material-icons">delete</span></a>');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
} else {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+app.current.app+app.current.tab+'List > tbody > tr').on({
|
2018-05-28 22:05:56 +00:00
|
|
|
|
mouseover: function(){
|
2018-05-29 20:12:11 +00:00
|
|
|
|
if($(this).children().last().has('a').length == 0)
|
2018-05-28 22:05:56 +00:00
|
|
|
|
$(this).children().last().append(
|
2018-06-10 21:48:02 +00:00
|
|
|
|
'<a class="pull-right btn-group-hover color-darkgrey" href="#/Browse/Playlists!' + app.current.page + '/'+app.current.filter+'/'+app.current.search+'" '+
|
2018-05-29 20:12:11 +00:00
|
|
|
|
'onclick="delPlaylist($(this).parents(\'tr\'));">' +
|
|
|
|
|
'<span class="material-icons">delete</span></a>');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
},
|
|
|
|
|
mouseleave: function(){
|
|
|
|
|
var doomed = $(this);
|
|
|
|
|
$(this).children().last().find("a").stop().remove();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+app.current.app+app.current.tab+'List > tbody > tr').on({
|
2018-05-28 22:05:56 +00:00
|
|
|
|
click: function() {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_ADD_PLAYLIST", "data": { "plist": decodeURI($(this).attr('uri'))}});
|
2018-05-28 22:05:56 +00:00
|
|
|
|
showNotification('"' + $('td:nth-last-child(3)', this).text() + '" added','','','success');
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-05-29 16:07:06 +00:00
|
|
|
|
if (nrItems == 0) {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+app.current.app+app.current.tab+'List > tbody').append(
|
2018-06-03 10:50:50 +00:00
|
|
|
|
'<tr><td><span class="material-icons">error_outline</span></td>' +
|
|
|
|
|
'<td colspan="3">No playlists found.</td>' +
|
|
|
|
|
'<td></td><td></td></tr>'
|
2018-05-29 16:07:06 +00:00
|
|
|
|
);
|
|
|
|
|
}
|
2018-06-19 22:43:36 +00:00
|
|
|
|
doSetFilterLetter('#browsePlaylistsFilter');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseListDBtags(obj) {
|
|
|
|
|
if(app.current.app !== 'Browse' && app.current.tab !== 'Database' && app.current.view !== 'Artist') return;
|
|
|
|
|
|
2018-06-03 16:36:06 +00:00
|
|
|
|
if (obj.tagtype == 'AlbumArtist') {
|
2018-06-10 21:48:02 +00:00
|
|
|
|
$('#BrowseDatabaseAlbumCards').addClass('hide');
|
|
|
|
|
$('#BrowseDatabaseArtistList').removeClass('hide');
|
2018-06-03 19:35:16 +00:00
|
|
|
|
$('#btnBrowseDatabaseArtist').addClass('hide');
|
2018-06-03 16:36:06 +00:00
|
|
|
|
var nrItems=0;
|
2018-06-10 19:31:40 +00:00
|
|
|
|
var tr=document.getElementById(app.current.app+app.current.tab+app.current.view+'List').getElementsByTagName('tbody')[0].getElementsByTagName('tr');
|
2018-06-03 16:36:06 +00:00
|
|
|
|
for (var item in obj.data) {
|
|
|
|
|
nrItems++;
|
2018-06-20 22:16:22 +00:00
|
|
|
|
var uri=encodeURI(obj.data[item].value);
|
|
|
|
|
var row='<tr uri="' + uri + '">' +
|
2018-06-03 16:36:06 +00:00
|
|
|
|
'<td><span class="material-icons">album</span></td>' +
|
|
|
|
|
'<td><a>' + obj.data[item].value + '</a></td></tr>';
|
2018-06-20 22:16:22 +00:00
|
|
|
|
if (nrItems <= tr.length) { if ($(tr[nrItems-1]).attr('uri')!=uri) $(tr[nrItems-1]).replaceWith(row); }
|
2018-06-10 19:31:40 +00:00
|
|
|
|
else { $('#'+app.current.app+app.current.tab+app.current.view+'List > tbody').append(row); }
|
2018-06-03 16:36:06 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
for (var i=tr.length;i>nrItems;i--) {
|
|
|
|
|
$(tr[tr.length-1]).remove();
|
|
|
|
|
}
|
|
|
|
|
setPagination(obj.totalEntities);
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+app.current.app+app.current.tab+app.current.view+'List > tbody > tr').on({
|
2018-06-03 16:36:06 +00:00
|
|
|
|
click: function() {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Browse','Database','Album','0/-/'+$(this).attr('uri'));
|
2018-06-03 16:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (nrItems == 0) {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+app.current.app+app.current.tab+app.current.view+'List > tbody').append(
|
2018-06-03 16:36:06 +00:00
|
|
|
|
'<tr><td><span class="material-icons">error_outline</span></td>' +
|
|
|
|
|
'<td colspan="3">No entries found.</td>' +
|
|
|
|
|
'<td></td><td></td></tr>'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else if (obj.tagtype == 'Album') {
|
2018-06-10 21:48:02 +00:00
|
|
|
|
$('#BrowseDatabaseArtistList').addClass('hide');
|
|
|
|
|
$('#BrowseDatabaseAlbumCards').removeClass('hide');
|
2018-06-03 19:35:16 +00:00
|
|
|
|
$('#btnBrowseDatabaseArtist').removeClass('hide');
|
2018-06-03 16:36:06 +00:00
|
|
|
|
var nrItems=0;
|
2018-06-21 21:29:49 +00:00
|
|
|
|
var cards=document.getElementById('BrowseDatabaseAlbumCards').querySelectorAll('.col-md');
|
2018-06-03 16:36:06 +00:00
|
|
|
|
for (var item in obj.data) {
|
2018-06-21 21:29:49 +00:00
|
|
|
|
nrItems++;
|
|
|
|
|
var id=genId(obj.data[item].value);
|
|
|
|
|
var card='<div class="col-md mr-0" id="'+id+'"><div class="card mb-4" id="card'+id+'">'+
|
2018-06-03 19:35:16 +00:00
|
|
|
|
' <img class="card-img-top" src="" alt="">'+
|
2018-06-03 16:36:06 +00:00
|
|
|
|
' <div class="card-body">'+
|
|
|
|
|
' <h5 class="card-title">'+obj.searchstr+'</h5>'+
|
|
|
|
|
' <h4 class="card-title">'+obj.data[item].value+'</h4>'+
|
2018-06-21 21:29:49 +00:00
|
|
|
|
' <table class="table table-sm table-hover" id="tbl'+id+'"><tbody></tbody></table'+
|
2018-06-03 16:36:06 +00:00
|
|
|
|
' </div>'+
|
2018-06-03 19:35:16 +00:00
|
|
|
|
'</div></div>';
|
2018-06-21 21:29:49 +00:00
|
|
|
|
if (nrItems <= cards.length) { if (cards[nrItems-1].id != id) $(cards[nrItems-1]).replaceWith(card); }
|
|
|
|
|
else { $('#BrowseDatabaseAlbumCards').append(card); }
|
|
|
|
|
if (nrItems > cards.length || cards[nrItems-1].id != id)
|
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_ARTISTALBUMTITLES", "data": { "albumartist": obj.searchstr, "album": obj.data[item].value}},parseListTitles);
|
|
|
|
|
}
|
|
|
|
|
for (var i=cards.length;i>nrItems;i--) {
|
|
|
|
|
$(cards[i-1]).remove();
|
2018-06-03 16:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
setPagination(obj.totalEntities);
|
|
|
|
|
}
|
2018-06-19 22:43:36 +00:00
|
|
|
|
doSetFilterLetter('#BrowseDatabaseFilter');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseListTitles(obj) {
|
|
|
|
|
if(app.current.app !== 'Browse' && app.current.tab !== 'Database' && app.current.view !== 'Album') return;
|
2018-06-21 21:29:49 +00:00
|
|
|
|
var id=genId(obj.album);
|
|
|
|
|
var album=$('#card'+id+' > div > table > tbody');
|
|
|
|
|
$('#card'+id+' > img').attr('src','/library/'+obj.data[0].uri.replace(/\/[^\/]+$/,'\/')+settings.coverimage)
|
|
|
|
|
.attr('uri',obj.data[0].uri.replace(/\/[^\/]+$/,''))
|
|
|
|
|
.attr('data-album',encodeURI(obj.album));
|
2018-06-03 16:36:06 +00:00
|
|
|
|
var titleList='';
|
|
|
|
|
for (var item in obj.data) {
|
2018-06-03 19:35:16 +00:00
|
|
|
|
titleList+='<tr uri="' + encodeURI(obj.data[item].uri) + '" class="song">'+
|
|
|
|
|
'<td>'+obj.data[item].track+'</td><td>'+obj.data[item].title+'</td></tr>';
|
2018-06-03 16:36:06 +00:00
|
|
|
|
}
|
|
|
|
|
album.append(titleList);
|
2018-06-21 21:29:49 +00:00
|
|
|
|
$('#card'+id+' > img').on({
|
2018-06-03 19:35:16 +00:00
|
|
|
|
click: function() {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_ADD_TRACK", "data": { "track": decodeURI($(this).attr('uri'))}});
|
2018-06-03 19:35:16 +00:00
|
|
|
|
showNotification('"'+decodeURI($(this).attr('data-album'))+'" added','','','success');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-21 21:29:49 +00:00
|
|
|
|
$('#tbl'+id+' > tbody > tr').on({
|
2018-06-03 19:35:16 +00:00
|
|
|
|
click: function() {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_ADD_TRACK", "data": { "track": decodeURI($(this).attr('uri'))}});
|
2018-06-03 19:35:16 +00:00
|
|
|
|
showNotification('"' + $('td:nth-last-child(1)', this).text() + '" added','','','success');
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-11-04 17:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-28 22:05:56 +00:00
|
|
|
|
function setPagination(number) {
|
2018-06-21 16:57:40 +00:00
|
|
|
|
var totalPages=Math.ceil(number / settings.max_elements_per_page);
|
2018-06-10 19:31:40 +00:00
|
|
|
|
var cat=app.current.app+(app.current.tab==undefined ? '': app.current.tab);
|
2018-05-28 22:05:56 +00:00
|
|
|
|
if (totalPages==0) { totalPages=1; }
|
2018-06-21 16:57:40 +00:00
|
|
|
|
$('#'+cat+'PaginationTopPage').text('Page '+(app.current.page / settings.max_elements_per_page + 1)+' / '+totalPages);
|
|
|
|
|
$('#'+cat+'PaginationBottomPage').text('Page '+(app.current.page / settings.max_elements_per_page + 1)+' / '+totalPages);
|
2018-05-28 22:05:56 +00:00
|
|
|
|
if (totalPages > 1) {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+cat+'PaginationTopPage').removeClass('disabled').removeAttr('disabled');
|
|
|
|
|
$('#'+cat+'PaginationBottomPage').removeClass('disabled').removeAttr('disabled');
|
|
|
|
|
$('#'+cat+'PaginationTopPages').empty();
|
|
|
|
|
$('#'+cat+'PaginationBottomPages').empty();
|
2018-05-28 22:05:56 +00:00
|
|
|
|
for (var i=0;i<totalPages;i++) {
|
2018-06-21 16:57:40 +00:00
|
|
|
|
$('#'+cat+'PaginationTopPages').append('<button onclick="gotoPage('+(i * settings.max_elements_per_page)+',this,event)" type="button" class="mr-1 mb-1 btn-sm btn btn-secondary">'+(i+1)+'</button>');
|
|
|
|
|
$('#'+cat+'PaginationBottomPages').append('<button onclick="gotoPage('+(i * settings.max_elements_per_page)+',this,event)" type="button" class="mr-1 mb-1 btn-sm btn btn-secondary">'+(i+1)+'</button>');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+cat+'PaginationTopPage').addClass('disabled').attr('disabled','disabled');
|
|
|
|
|
$('#'+cat+'PaginationBottomPage').addClass('disabled').attr('disabled','disabled');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-21 16:57:40 +00:00
|
|
|
|
if(number > app.current.page + settings.max_elements_per_page) {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+cat+'PaginationTopNext').removeClass('disabled').removeAttr('disabled');
|
|
|
|
|
$('#'+cat+'PaginationBottomNext').removeClass('disabled').removeAttr('disabled');
|
|
|
|
|
$('#'+cat+'ButtonsBottom').removeClass('hide');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
} else {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+cat+'PaginationTopNext').addClass('disabled').attr('disabled','disabled');
|
|
|
|
|
$('#'+cat+'PaginationBottomNext').addClass('disabled').attr('disabled','disabled');
|
|
|
|
|
$('#'+cat+'ButtonsBottom').addClass('hide');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-10 19:31:40 +00:00
|
|
|
|
if(app.current.page > 0) {
|
|
|
|
|
$('#'+cat+'PaginationTopPrev').removeClass('disabled').removeAttr('disabled');
|
|
|
|
|
$('#'+cat+'PaginationBottomPrev').removeClass('disabled').removeAttr('disabled');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
} else {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$('#'+cat+'PaginationTopPrev').addClass('disabled').attr('disabled','disabled');
|
|
|
|
|
$('#'+cat+'PaginationBottomPrev').addClass('disabled').attr('disabled','disabled');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-23 23:42:20 +00:00
|
|
|
|
function updateVolumeIcon(volume) {
|
2018-05-28 18:48:43 +00:00
|
|
|
|
if (volume == -1) {
|
|
|
|
|
$('#volumePrct').text('Volumecontrol disabled');
|
|
|
|
|
$('#volumeControl').addClass('hide');
|
2014-01-16 17:32:20 +00:00
|
|
|
|
} else {
|
2018-05-28 18:48:43 +00:00
|
|
|
|
$('#volumeControl').removeClass('hidden');
|
|
|
|
|
$('#volumePrct').text(volume+' %');
|
|
|
|
|
if(volume == 0) {
|
|
|
|
|
$("#volume-icon").text("volume_off");
|
|
|
|
|
} else if (volume < 50) {
|
|
|
|
|
$("#volume-icon").text("volume_down");
|
|
|
|
|
} else {
|
|
|
|
|
$("#volume-icon").text("volume_up");
|
|
|
|
|
}
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
2013-11-04 17:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-03 09:41:47 +00:00
|
|
|
|
function updatePlayIcon(obj) {
|
|
|
|
|
if(obj.data.state == 1) { // stop
|
|
|
|
|
$('#btnPlay > span').text('play_arrow');
|
2018-05-16 23:19:03 +00:00
|
|
|
|
playstate = 'stop';
|
2018-06-03 09:41:47 +00:00
|
|
|
|
} else if(obj.data.state == 2) { // play
|
|
|
|
|
$('#btnPlay > span').text('pause');
|
2018-05-16 23:19:03 +00:00
|
|
|
|
playstate = 'play';
|
2015-12-08 15:42:03 +00:00
|
|
|
|
} else { // pause
|
2018-06-03 09:41:47 +00:00
|
|
|
|
$('#btnPlay > span').text('play_arrow');
|
2018-05-16 23:19:03 +00:00
|
|
|
|
playstate = 'pause';
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
2018-06-03 09:41:47 +00:00
|
|
|
|
|
|
|
|
|
if (obj.data.nextsongpos == -1) {
|
|
|
|
|
$('#btnNext').addClass('disabled').attr('disabled','disabled');
|
|
|
|
|
} else {
|
|
|
|
|
$('#btnNext').removeClass('disabled').removeAttr('disabled');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (obj.data.songpos <= 0) {
|
|
|
|
|
$('#btnPrev').addClass('disabled').attr('disabled','disabled');
|
|
|
|
|
} else {
|
|
|
|
|
$('#btnPrev').removeClass('disabled').removeAttr('disabled');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (obj.data.queue_length == 0) {
|
|
|
|
|
$('#btnPlay').addClass('disabled').attr('disabled','disabled');
|
|
|
|
|
} else {
|
|
|
|
|
$('#btnPlay').removeClass('disabled').removeAttr('disabled');
|
|
|
|
|
}
|
2013-11-04 23:17:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 22:43:36 +00:00
|
|
|
|
function sendAPI(request, callback) {
|
2018-06-19 23:23:08 +00:00
|
|
|
|
$.ajax({url: "/api", contentType:"application/json", method: "POST", data: JSON.stringify(request), success: callback });
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-03 19:35:16 +00:00
|
|
|
|
function updateDB(event) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_UPDATE_DB"});
|
2018-05-22 23:07:34 +00:00
|
|
|
|
showNotification('Updating MPD Database...','','','success');
|
2018-06-03 19:35:16 +00:00
|
|
|
|
event.preventDefault();
|
2013-11-04 17:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-17 15:26:26 +00:00
|
|
|
|
function clickPlay() {
|
2018-05-16 23:19:03 +00:00
|
|
|
|
if( playstate != 'play')
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_PLAY"});
|
2014-01-17 15:26:26 +00:00
|
|
|
|
else
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_PAUSE"});
|
2014-01-17 15:26:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-10 16:54:57 +00:00
|
|
|
|
function clickStop() {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_STOP"});
|
2018-06-10 16:54:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-18 21:26:00 +00:00
|
|
|
|
function clickPrev() {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_PREV"});
|
2018-06-18 21:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clickNext() {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_NEXT"});
|
2018-06-18 21:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-24 17:50:05 +00:00
|
|
|
|
function setLocalStream(mpdhost,streamport) {
|
|
|
|
|
var mpdstream = 'http://';
|
|
|
|
|
if ( mpdhost == '127.0.0.1' || mpdhost == 'localhost')
|
|
|
|
|
mpdstream += window.location.hostname;
|
|
|
|
|
else
|
|
|
|
|
mpdstream += mpdhost;
|
|
|
|
|
mpdstream += ':'+streamport+'/';
|
2018-06-20 22:00:46 +00:00
|
|
|
|
settings.mpdstream=mpdstream;
|
2014-05-24 16:23:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-11 17:33:11 +00:00
|
|
|
|
function delQueueSong(tr,event) {
|
|
|
|
|
event.stopPropagation();
|
2018-05-17 22:10:57 +00:00
|
|
|
|
if ( $('#btntrashmodeup').hasClass('btn-success') ) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_RM_RANGE", "data": {"start":0, "end": (tr.index() + 1)}});
|
2018-05-17 22:10:57 +00:00
|
|
|
|
} else if ( $('#btntrashmodesingle').hasClass('btn-success') ) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_RM_TRACK", "data": { "track": tr.attr('trackid')}});
|
2018-05-17 22:10:57 +00:00
|
|
|
|
} else if ( $('#btntrashmodedown').hasClass('btn-success') ) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_RM_RANGE", "data": {"start": tr.index(), "end":-1}});
|
2017-04-08 09:25:40 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-29 20:12:11 +00:00
|
|
|
|
function delPlaylist(tr) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_RM_PLAYLIST","data": {"plist": decodeURI(tr.attr("uri"))}});
|
2018-05-29 20:12:11 +00:00
|
|
|
|
tr.remove();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-13 14:30:54 +00:00
|
|
|
|
function basename(path) {
|
2014-01-16 17:32:20 +00:00
|
|
|
|
return path.split('/').reverse()[0];
|
2013-11-13 14:30:54 +00:00
|
|
|
|
}
|
2013-11-07 09:09:40 +00:00
|
|
|
|
|
2018-05-29 21:05:34 +00:00
|
|
|
|
function toggleBtn(btn) {
|
|
|
|
|
if ($(btn).hasClass('btn-success')) {
|
|
|
|
|
$(btn).removeClass('btn-success').addClass('btn-secondary');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$(btn).removeClass('btn-secondary').addClass('btn-success');
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-07 09:09:40 +00:00
|
|
|
|
|
2018-05-29 21:05:34 +00:00
|
|
|
|
$('#btnrandom').on('click', function (e) {
|
|
|
|
|
toggleBtn(this);
|
2013-11-07 09:09:40 +00:00
|
|
|
|
});
|
|
|
|
|
$('#btnconsume').on('click', function (e) {
|
2018-05-29 21:05:34 +00:00
|
|
|
|
toggleBtn(this);
|
2013-11-07 09:09:40 +00:00
|
|
|
|
});
|
|
|
|
|
$('#btnsingle').on('click', function (e) {
|
2018-05-31 20:23:57 +00:00
|
|
|
|
toggleBtn(this);
|
2013-11-07 09:09:40 +00:00
|
|
|
|
});
|
|
|
|
|
$('#btnrepeat').on('click', function (e) {
|
2018-05-29 21:05:34 +00:00
|
|
|
|
toggleBtn(this);
|
2013-11-07 09:09:40 +00:00
|
|
|
|
});
|
2018-06-21 16:57:40 +00:00
|
|
|
|
$('#btnnotifyPage').on('click', function (e) {
|
|
|
|
|
toggleBtn(this);
|
|
|
|
|
});
|
|
|
|
|
$('#btnnotifyWeb').on('click', function (e) {
|
|
|
|
|
toggleBtn(this);
|
|
|
|
|
});
|
|
|
|
|
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
2018-06-07 18:47:40 +00:00
|
|
|
|
$('#cardBrowseNavFilesystem').on('click', function (e) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Browse','Filesystem');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#cardBrowseNavDatabase').on('click', function (e) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Browse','Database');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#btnBrowseDatabaseArtist').on('click', function (e) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Browse','Database','Artist');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#cardBrowseNavPlaylists').on('click', function (e) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Browse','Playlists');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#cardBrowseNavFilesystem').on('click', function (e) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Browse','Filesystem');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#navPlayback').on('click', function (e) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Playback');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#navQueue').on('click', function (e) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Queue');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#navBrowse').on('click', function (e) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Browse');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#navSearch').on('click', function (e) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Search');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-28 18:48:43 +00:00
|
|
|
|
function confirmSettings() {
|
2018-05-31 20:23:57 +00:00
|
|
|
|
var formOK=true;
|
|
|
|
|
if (!$('#inputCrossfade').is(':disabled')) {
|
|
|
|
|
var value=parseInt($('#inputCrossfade').val());
|
|
|
|
|
if (!isNaN(value)) {
|
2018-05-28 18:48:43 +00:00
|
|
|
|
$('#inputCrossfade').val(value);
|
2018-05-31 20:23:57 +00:00
|
|
|
|
} else {
|
2018-05-28 18:48:43 +00:00
|
|
|
|
$('#inputCrossfade').popover({"content":"Must be a number","trigger":"manual"});
|
|
|
|
|
$('#inputCrossfade').popover('show');
|
|
|
|
|
$('#inputCrossfade').focus();
|
2018-05-31 20:23:57 +00:00
|
|
|
|
formOK=false;
|
|
|
|
|
}
|
2018-05-28 18:48:43 +00:00
|
|
|
|
}
|
2018-05-31 20:23:57 +00:00
|
|
|
|
if (!$('#inputMixrampdb').is(':disabled')) {
|
2018-06-05 22:04:45 +00:00
|
|
|
|
var value=parseFloat($('#inputMixrampdb').val());
|
2018-05-31 20:23:57 +00:00
|
|
|
|
if (!isNaN(value)) {
|
2018-05-28 18:48:43 +00:00
|
|
|
|
$('#inputMixrampdb').val(value);
|
2018-05-31 20:23:57 +00:00
|
|
|
|
} else {
|
2018-05-28 18:48:43 +00:00
|
|
|
|
$('#inputMixrampdb').popover({"content":"Must be a number","trigger":"manual"});
|
|
|
|
|
$('#inputMixrampdb').popover('show');
|
|
|
|
|
$('#inputMixrampdb').focus();
|
2018-05-31 20:23:57 +00:00
|
|
|
|
formOK=false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!$('#inputMixrampdelay').is(':disabled')) {
|
2018-06-05 22:04:45 +00:00
|
|
|
|
if ($('#inputMixrampdelay').val() == 'nan') $('#inputMixrampdelay').val('-1');
|
|
|
|
|
var value=parseFloat($('#inputMixrampdelay').val());
|
2018-05-31 20:23:57 +00:00
|
|
|
|
if (!isNaN(value)) {
|
2018-05-28 18:48:43 +00:00
|
|
|
|
$('#inputMixrampdelay').val(value);
|
2018-05-31 20:23:57 +00:00
|
|
|
|
} else {
|
2018-06-05 22:04:45 +00:00
|
|
|
|
$('#inputMixrampdelay').popover({"content":"Must be a number, -1 to disable","trigger":"manual"});
|
2018-05-28 18:48:43 +00:00
|
|
|
|
$('#inputMixrampdelay').popover('show');
|
|
|
|
|
$('#inputMixrampdelay').focus();
|
2018-05-31 20:23:57 +00:00
|
|
|
|
formOK=false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (formOK == true) {
|
2018-06-21 16:57:40 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_SETTINGS", "data": {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
"consume": ($('#btnconsume').hasClass('btn-success') ? 1 : 0),
|
|
|
|
|
"random": ($('#btnrandom').hasClass('btn-success') ? 1 : 0),
|
|
|
|
|
"single": ($('#btnsingle').hasClass('btn-success') ? 1 : 0),
|
|
|
|
|
"repeat": ($('#btnrepeat').hasClass('btn-success') ? 1 : 0),
|
|
|
|
|
"replaygain": $('#selectReplaygain').val(),
|
|
|
|
|
"crossfade": $('#inputCrossfade').val(),
|
|
|
|
|
"mixrampdb": $('#inputMixrampdb').val(),
|
2018-06-21 16:57:40 +00:00
|
|
|
|
"mixrampdelay": $('#inputMixrampdelay').val(),
|
|
|
|
|
"notificationWeb": ($('#btnnotifyWeb').hasClass('btn-success') ? 1 : 0),
|
|
|
|
|
"notificationPage": ($('#btnnotifyPage').hasClass('btn-success') ? 1 : 0)
|
2018-06-21 17:28:07 +00:00
|
|
|
|
}},getSettings);
|
2018-05-31 20:23:57 +00:00
|
|
|
|
$('#settings').modal('hide');
|
2018-05-28 18:48:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-28 09:08:21 +00:00
|
|
|
|
function toggleoutput(button, id) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_TOGGLE_OUTPUT", "data": {"output": id, "state": ($(button).hasClass('btn-success') ? 0 : 1)}});
|
2015-04-28 09:08:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-27 12:37:50 +00:00
|
|
|
|
$('#trashmodebtns > button').on('click', function(e) {
|
|
|
|
|
$('#trashmodebtns').children("button").removeClass("btn-success").addClass('btn-secondary');
|
2018-05-14 23:13:43 +00:00
|
|
|
|
$(this).removeClass("btn-secondary").addClass("btn-success");
|
2017-04-08 09:25:40 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-06-21 16:57:40 +00:00
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
|
2018-05-23 22:32:01 +00:00
|
|
|
|
$('#search > input').keypress(function (event) {
|
|
|
|
|
if ( event.which == 13 ) {
|
|
|
|
|
$('#mainMenu > a').dropdown('toggle');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-02-22 00:57:26 +00:00
|
|
|
|
$('#search').submit(function () {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Search',undefined,undefined,app.current.page + '/Any Tag/' + $('#search > input').val());
|
2014-02-22 00:57:26 +00:00
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-05 21:30:16 +00:00
|
|
|
|
$('#search2').submit(function () {
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-31 23:05:49 +00:00
|
|
|
|
function addAllFromSearch() {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
if (app.current.search.length >= 2) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SEARCH_ADD","data":{"filter": app.current.filter,"searchstr": + app.current.search}});
|
2018-06-10 21:15:33 +00:00
|
|
|
|
var rowCount = $('#SearchList >tbody >tr').length;
|
2018-05-31 23:05:49 +00:00
|
|
|
|
showNotification('Added '+rowCount+' songs from search','','','success');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-29 20:12:11 +00:00
|
|
|
|
$('#searchstr2').keyup(function (event) {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
app.current.page=0;
|
|
|
|
|
app.current.search=$(this).val();
|
2018-06-10 21:15:33 +00:00
|
|
|
|
app.goto('Search',undefined,undefined,app.current.page + '/' + app.current.filter + '/' + app.current.search);
|
2018-05-29 20:12:11 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#searchtags2 > button').on('click',function (e) {
|
|
|
|
|
$('#searchtags2 > button').removeClass('btn-success').addClass('btn-secondary');
|
|
|
|
|
$(this).removeClass('btn-secondary').addClass('btn-success');
|
2018-06-10 19:31:40 +00:00
|
|
|
|
app.current.filter=$(this).text();
|
|
|
|
|
app.goto(app.current.app,app.current.tab,app.current.view,app.current.page + '/' + app.current.filter + '/' + app.current.search);
|
2018-05-29 20:12:11 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-05-27 12:37:50 +00:00
|
|
|
|
$('#searchqueuestr').keyup(function (event) {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
app.current.page=0;
|
|
|
|
|
app.current.search=$(this).val();
|
|
|
|
|
app.goto(app.current.app,app.current.tab,app.current.view,app.current.page + '/' + app.current.filter + '/' + app.current.search);
|
2018-05-27 12:37:50 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#searchqueuetag > button').on('click',function (e) {
|
|
|
|
|
$('#searchqueuetag > button').removeClass('btn-success').addClass('btn-secondary');
|
|
|
|
|
$(this).removeClass('btn-secondary').addClass('btn-success');
|
2018-06-10 19:31:40 +00:00
|
|
|
|
app.current.filter=$(this).text();
|
|
|
|
|
$('#searchqueuetagdesc').text(app.current.filter);
|
|
|
|
|
app.goto(app.current.app,app.current.tab,app.current.view,app.current.page + '/' + app.current.filter + '/' + app.current.search);
|
2018-05-27 12:37:50 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-05-24 22:21:19 +00:00
|
|
|
|
$('#searchqueue').submit(function () {
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2018-06-05 21:30:16 +00:00
|
|
|
|
$('#searchqueue').submit(function () {
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
2018-05-27 20:21:18 +00:00
|
|
|
|
function scrollToTop() {
|
|
|
|
|
document.body.scrollTop = 0; // For Safari
|
|
|
|
|
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function gotoPage(x,element,event) {
|
|
|
|
|
switch (x) {
|
|
|
|
|
case "next":
|
2018-06-21 16:57:40 +00:00
|
|
|
|
app.current.page += settings.max_elements_per_page;
|
2018-05-27 20:21:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case "prev":
|
2018-06-21 16:57:40 +00:00
|
|
|
|
app.current.page -= settings.max_elements_per_page;
|
2018-06-10 19:31:40 +00:00
|
|
|
|
if(app.current.page <= 0)
|
|
|
|
|
app.current.page = 0;
|
2018-05-27 20:21:18 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2018-06-10 19:31:40 +00:00
|
|
|
|
app.current.page = x;
|
2018-05-27 20:21:18 +00:00
|
|
|
|
}
|
2018-06-10 19:31:40 +00:00
|
|
|
|
app.goto(app.current.app,app.current.tab,app.current.view,app.current.page+'/'+app.current.filter+'/'+app.current.search);
|
2018-05-27 20:21:18 +00:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-06 11:40:14 +00:00
|
|
|
|
function addStream() {
|
|
|
|
|
if($('#streamurl').val().length > 0) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_ADD_TRACK","data":{"uri":$('#streamurl').val()}});
|
2015-03-06 11:40:14 +00:00
|
|
|
|
}
|
2015-07-16 09:50:54 +00:00
|
|
|
|
$('#streamurl').val("");
|
2015-03-06 11:40:14 +00:00
|
|
|
|
$('#addstream').modal('hide');
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 17:24:52 +00:00
|
|
|
|
function saveQueue() {
|
|
|
|
|
if($('#playlistname').val().length > 0) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SAVE_QUEUE","data":{"plist":$('#playlistname').val()}});
|
2015-09-02 17:24:52 +00:00
|
|
|
|
}
|
|
|
|
|
$('#savequeue').modal('hide');
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
function showNotification(notificationTitle,notificationText,notificationHtml,notificationType) {
|
2018-06-21 16:57:40 +00:00
|
|
|
|
if (settings.notificationWeb == 1) {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
var notification = new Notification(notificationTitle, {icon: 'assets/favicon.ico', body: notificationText});
|
|
|
|
|
setTimeout(function(notification) {
|
|
|
|
|
notification.close();
|
|
|
|
|
}, 3000, notification);
|
|
|
|
|
}
|
2018-06-21 16:57:40 +00:00
|
|
|
|
if (settings.notificationPage == 1) {
|
2018-05-22 23:07:34 +00:00
|
|
|
|
$.notify({ title: notificationTitle, message: notificationHtml},{ type: notificationType, offset: { y: 60, x:20 },
|
2018-06-21 21:29:49 +00:00
|
|
|
|
template: '<div data-notify="container" class="alert alert-{0}" role="alert">' +
|
2018-05-22 23:07:34 +00:00
|
|
|
|
'<span data-notify="title">{1}</span> ' +
|
|
|
|
|
'<span data-notify="message">{2}</span>' +
|
|
|
|
|
'</div>'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-17 17:34:22 +00:00
|
|
|
|
function notificationsSupported() {
|
2014-05-24 00:57:30 +00:00
|
|
|
|
return "Notification" in window;
|
2014-01-17 17:34:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 23:23:08 +00:00
|
|
|
|
function songChange(obj) {
|
2018-06-19 22:43:36 +00:00
|
|
|
|
if (last_song == obj.data.title+obj.data.artist+obj.data.album+obj.data.uri+obj.data.currentsongid)
|
2018-06-11 17:33:11 +00:00
|
|
|
|
return;
|
2018-05-22 23:07:34 +00:00
|
|
|
|
var textNotification = '';
|
|
|
|
|
var htmlNotification = '';
|
|
|
|
|
var pageTitle = 'myMPD: ';
|
2018-05-23 23:42:20 +00:00
|
|
|
|
|
2018-06-19 22:43:36 +00:00
|
|
|
|
if (typeof obj.data.uri != 'undefined' && obj.data.uri.length > 0) {
|
2018-05-24 00:07:34 +00:00
|
|
|
|
var coverImg='';
|
2018-06-19 22:43:36 +00:00
|
|
|
|
if (obj.data.uri.indexOf('http://') == 0 || obj.data.uri.indexOf('https://') == 0 ) {
|
2018-05-31 20:23:57 +00:00
|
|
|
|
coverImg='/assets/coverimage-httpstream.png';
|
2018-06-21 16:57:40 +00:00
|
|
|
|
} else if (settings.coverimage != '') {
|
|
|
|
|
coverImg='/library/'+obj.data.uri.replace(/\/[^\/]+$/,'\/'+settings.coverimage);
|
2018-05-31 20:23:57 +00:00
|
|
|
|
} else {
|
|
|
|
|
coverImg='/assets/coverimage-notavailable.png';
|
2018-05-24 00:07:34 +00:00
|
|
|
|
}
|
2018-05-31 20:23:57 +00:00
|
|
|
|
$('#album-cover').css('backgroundImage','url("'+coverImg+'"),url("/assets/coverimage-notavailable.png")');
|
2018-05-23 23:42:20 +00:00
|
|
|
|
}
|
2018-06-19 22:43:36 +00:00
|
|
|
|
if(typeof obj.data.artist != 'undefined' && obj.data.artist.length > 0 && obj.data.artist != '-') {
|
|
|
|
|
textNotification += obj.data.artist;
|
|
|
|
|
htmlNotification += '<br/>' + obj.data.artist;
|
|
|
|
|
pageTitle += obj.data.artist + ' - ';
|
|
|
|
|
$('#artist').text(obj.data.artist);
|
2018-05-23 23:42:20 +00:00
|
|
|
|
} else {
|
|
|
|
|
$('#artist').text('');
|
2018-05-22 23:07:34 +00:00
|
|
|
|
}
|
2018-06-19 22:43:36 +00:00
|
|
|
|
if(typeof obj.data.album != 'undefined' && obj.data.album.length > 0 && obj.data.album != '-') {
|
|
|
|
|
textNotification += ' - ' + obj.data.album;
|
|
|
|
|
htmlNotification += '<br/>' + obj.data.album;
|
|
|
|
|
$('#album').text(obj.data.album);
|
2018-05-23 23:42:20 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$('#album').text('');
|
2018-05-22 23:07:34 +00:00
|
|
|
|
}
|
2018-06-19 22:43:36 +00:00
|
|
|
|
if(typeof obj.data.title != 'undefined' && obj.data.title.length > 0) {
|
|
|
|
|
pageTitle += obj.data.title;
|
|
|
|
|
$('#currenttrack').text(obj.data.title);
|
2018-05-23 23:42:20 +00:00
|
|
|
|
} else {
|
|
|
|
|
$('#currenttrack').text('');
|
2018-05-22 23:07:34 +00:00
|
|
|
|
}
|
|
|
|
|
document.title = pageTitle;
|
2018-06-19 22:43:36 +00:00
|
|
|
|
showNotification(obj.data.title,textNotification,htmlNotification,'success');
|
|
|
|
|
last_song = obj.data.title+obj.data.artist+obj.data.album+obj.data.uri+obj.data.currentsongid;
|
2014-01-17 17:34:22 +00:00
|
|
|
|
}
|
2015-09-13 08:38:18 +00:00
|
|
|
|
|
2018-05-22 23:07:34 +00:00
|
|
|
|
|
2015-09-13 08:38:18 +00:00
|
|
|
|
$(document).keydown(function(e){
|
|
|
|
|
if (e.target.tagName == 'INPUT') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (e.which) {
|
|
|
|
|
case 37: //left
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_PREV"});
|
2015-09-13 08:38:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case 39: //right
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_NEXT"});
|
2015-09-13 08:38:18 +00:00
|
|
|
|
break;
|
|
|
|
|
case 32: //space
|
|
|
|
|
clickPlay();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
2015-09-02 17:38:42 +00:00
|
|
|
|
|
2018-06-03 08:52:38 +00:00
|
|
|
|
function setFilterLetter(filter) {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
app.goto(app.current.app,app.current.tab,app.current.view, '0/'+filter+'/'+app.current.search);
|
2018-06-04 18:31:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doSetFilterLetter(x) {
|
|
|
|
|
$(x+'Letters > button').removeClass('btn-success').addClass('btn-secondary');
|
2018-06-10 19:31:40 +00:00
|
|
|
|
if (app.current.filter == '0') {
|
2018-06-04 18:31:05 +00:00
|
|
|
|
$(x).text('Filter: #');
|
|
|
|
|
$(x+'Letters > button').each(function() {
|
|
|
|
|
if ($(this).text() == '#') {
|
|
|
|
|
$(this).addClass('btn-success');
|
|
|
|
|
}
|
|
|
|
|
});
|
2018-06-10 21:15:33 +00:00
|
|
|
|
} else if (app.current.filter != '-') {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
$(x).text('Filter: '+app.current.filter);
|
2018-06-04 18:31:05 +00:00
|
|
|
|
$(x+'Letters > button').each(function() {
|
2018-06-10 19:31:40 +00:00
|
|
|
|
if ($(this).text() == app.current.filter) {
|
2018-06-04 18:31:05 +00:00
|
|
|
|
$(this).addClass('btn-success');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
$(x).text('Filter');
|
|
|
|
|
}
|
2016-06-08 21:20:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-04 18:31:05 +00:00
|
|
|
|
function add_filter (x) {
|
2018-06-10 21:15:33 +00:00
|
|
|
|
$(x).append('<button class="mr-1 mb-1 btn btn-sm btn-secondary" onclick="setFilterLetter(\'-\');">'+
|
2018-06-03 08:52:38 +00:00
|
|
|
|
'<span class="material-icons" style="font-size:14px;">delete</span></button>');
|
2018-06-04 18:31:05 +00:00
|
|
|
|
$(x).append('<button class="mr-1 mb-1 btn btn-sm btn-secondary" onclick="setFilterLetter(\'0\');">#</button>');
|
2016-06-08 21:20:27 +00:00
|
|
|
|
for (i = 65; i <= 90; i++) {
|
|
|
|
|
var c = String.fromCharCode(i);
|
2018-06-04 18:31:05 +00:00
|
|
|
|
$(x).append('<button class="mr-1 mb-1 btn-sm btn btn-secondary" onclick="setFilterLetter(\'' + c + '\');">' + c + '</button>');
|
2016-06-08 21:20:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-21 23:36:05 +00:00
|
|
|
|
|
|
|
|
|
function chVolume (increment) {
|
|
|
|
|
var aktValue=volumeBar.slider('getValue');
|
|
|
|
|
var newValue=aktValue+increment;
|
|
|
|
|
if (newValue<0) { newValue=0; }
|
|
|
|
|
else if (newValue > 100) { newValue=100; }
|
|
|
|
|
volumeBar.slider('setValue',newValue);
|
2018-06-19 22:43:36 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_VOLUME", "data": {"volume":newValue}});
|
2018-05-27 21:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function beautifyDuration(x) {
|
|
|
|
|
var days = Math.floor(x / 86400);
|
|
|
|
|
var hours = Math.floor(x / 3600) - days * 24;
|
|
|
|
|
var minutes = Math.floor(x / 60) - hours * 60 - days * 1440;
|
|
|
|
|
var seconds = x - days * 86400 - hours * 3600 - minutes * 60;
|
|
|
|
|
|
|
|
|
|
return (days > 0 ? days + '\u2009d ' : '') +
|
|
|
|
|
(hours > 0 ? hours + '\u2009h ' + (minutes < 10 ? '0' : '') : '') +
|
|
|
|
|
minutes + '\u2009m ' + (seconds < 10 ? '0' : '') + seconds + '\u2009s';
|
2018-06-03 19:35:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function genId(x) {
|
|
|
|
|
return 'id'+x.replace(/[^\w]/g,'');
|
2018-05-21 23:36:05 +00:00
|
|
|
|
}
|