2018-07-19 18:26:15 +00:00
|
|
|
|
"use strict";
|
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;
|
2014-01-16 17:32:20 +00:00
|
|
|
|
var current_song = new Object();
|
2018-06-03 08:52:38 +00:00
|
|
|
|
var playstate = '';
|
2018-06-21 16:57:40 +00:00
|
|
|
|
var settings = {};
|
2018-07-05 19:34:16 +00:00
|
|
|
|
var alertTimeout;
|
2018-07-16 17:33:20 +00:00
|
|
|
|
let deferredPrompt;
|
2013-11-04 17:18:38 +00:00
|
|
|
|
|
2018-06-07 18:47:40 +00:00
|
|
|
|
var app = {};
|
2018-07-09 15:36:45 +00:00
|
|
|
|
app.apps = { "Playback": { "state": "0/-/", "scrollPos": 0 },
|
|
|
|
|
"Queue": { "state": "0/Any Tag/", "scrollPos": 0 },
|
2018-06-10 21:21:48 +00:00
|
|
|
|
"Browse": {
|
|
|
|
|
"active": "Database",
|
2018-07-09 15:36:45 +00:00
|
|
|
|
"tabs": { "Filesystem": { "state": "0/-/", "scrollPos": 0 },
|
|
|
|
|
"Playlists": { "state": "0/-/", "scrollPos": 0 },
|
2018-06-10 21:21:48 +00:00
|
|
|
|
"Database": {
|
|
|
|
|
"active": "Artist",
|
2018-07-09 15:36:45 +00:00
|
|
|
|
"views": { "Artist": { "state": "0/-/", "scrollPos": 0 },
|
|
|
|
|
"Album": { "state": "0/-/", "scrollPos": 0 }
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-07-09 15:36:45 +00:00
|
|
|
|
"Search": { "state": "0/Any Tag/", "scrollPos": 0 }
|
2018-06-07 18:47:40 +00:00
|
|
|
|
};
|
|
|
|
|
|
2018-07-09 15:36:45 +00:00
|
|
|
|
app.current = { "app": "Playback", "tab": undefined, "view": undefined, "page": 0, "filter": "", "search": "", "scrollPos": 0 };
|
|
|
|
|
app.last = { "app": undefined, "tab": undefined, "view": undefined, "filter": "", "search": "", "scrollPos": 0 };
|
2018-06-07 18:47:40 +00:00
|
|
|
|
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var domCache = {};
|
|
|
|
|
domCache.navbarBottomBtns = document.getElementById('navbar-bottom').getElementsByTagName('div');
|
|
|
|
|
domCache.navbarBottomBtnsLen = domCache.navbarBottomBtns.length;
|
|
|
|
|
domCache.panelHeadingBrowse = document.getElementById('panel-heading-browse').getElementsByTagName('a');
|
|
|
|
|
domCache.panelHeadingBrowseLen = domCache.panelHeadingBrowse.length;
|
|
|
|
|
domCache.counter = document.getElementById('counter');
|
2018-06-28 22:51:24 +00:00
|
|
|
|
domCache.volumePrct = document.getElementById('volumePrct');
|
|
|
|
|
domCache.volumeControl = document.getElementById('volumeControl');
|
|
|
|
|
domCache.volumeIcon = document.getElementById('volumeIcon');
|
|
|
|
|
domCache.btnPlay = document.getElementById('btnPlay');
|
|
|
|
|
domCache.btnPrev = document.getElementById('btnPrev');
|
|
|
|
|
domCache.btnNext = document.getElementById('btnNext');
|
|
|
|
|
domCache.progressBar = document.getElementById('progressBar');
|
|
|
|
|
domCache.volumeBar = document.getElementById('volumeBar');
|
2018-06-29 06:52:32 +00:00
|
|
|
|
domCache.outputs = document.getElementById('outputs');
|
2018-07-16 17:33:20 +00:00
|
|
|
|
domCache.btnAdd = document.getElementById('btnAdd');
|
2018-06-27 23:19:09 +00:00
|
|
|
|
|
2018-07-02 22:02:02 +00:00
|
|
|
|
var modalConnectionError = new Modal(document.getElementById('modalConnectionError'));
|
|
|
|
|
var modalSettings = new Modal(document.getElementById('modalSettings'));
|
|
|
|
|
var modalAddstream = new Modal(document.getElementById('modalAddstream'));
|
|
|
|
|
var modalSavequeue = new Modal(document.getElementById('modalSavequeue'));
|
2018-07-09 17:28:28 +00:00
|
|
|
|
var modalSongDetails = new Modal(document.getElementById('modalSongDetails'));
|
2018-07-02 22:02:02 +00:00
|
|
|
|
var mainMenu = new Dropdown(document.getElementById('mainMenu'));
|
|
|
|
|
|
2018-07-09 15:36:45 +00:00
|
|
|
|
function appPrepare(scrollPos) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (app.current.app != app.last.app || app.current.tab != app.last.tab || app.current.view != app.last.view) {
|
|
|
|
|
//Hide all cards + nav
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < domCache.navbarBottomBtnsLen; i++) {
|
2018-06-27 23:19:09 +00:00
|
|
|
|
domCache.navbarBottomBtns[i].classList.remove('active');
|
|
|
|
|
}
|
|
|
|
|
document.getElementById('cardPlayback').classList.add('hide');
|
|
|
|
|
document.getElementById('cardQueue').classList.add('hide');
|
|
|
|
|
document.getElementById('cardBrowse').classList.add('hide');
|
|
|
|
|
document.getElementById('cardSearch').classList.add('hide');
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < domCache.panelHeadingBrowseLen; i++) {
|
2018-06-27 23:19:09 +00:00
|
|
|
|
domCache.panelHeadingBrowse[i].classList.remove('active');
|
|
|
|
|
}
|
|
|
|
|
document.getElementById('cardBrowsePlaylists').classList.add('hide');
|
|
|
|
|
document.getElementById('cardBrowseDatabase').classList.add('hide');
|
|
|
|
|
document.getElementById('cardBrowseFilesystem').classList.add('hide');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
//show active card + nav
|
2018-06-27 23:19:09 +00:00
|
|
|
|
document.getElementById('card' + app.current.app).classList.remove('hide');
|
|
|
|
|
document.getElementById('nav' + app.current.app).classList.add('active');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (app.current.tab != undefined) {
|
2018-06-27 23:19:09 +00:00
|
|
|
|
document.getElementById('card' + app.current.app + app.current.tab).classList.remove('hide');
|
|
|
|
|
document.getElementById('card' + app.current.app + 'Nav' + app.current.tab).classList.add('active');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
2018-07-09 15:36:45 +00:00
|
|
|
|
scrollTo(scrollPos);
|
2018-06-10 21:15:33 +00:00
|
|
|
|
}
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 19:40:27 +00:00
|
|
|
|
function appGoto(a,t,v,s) {
|
2018-07-09 15:36:45 +00:00
|
|
|
|
var scrollPos = 0;
|
|
|
|
|
if (document.body.scrollTop)
|
|
|
|
|
scrollPos = document.body.scrollTop
|
|
|
|
|
else
|
|
|
|
|
scrollPos = document.documentElement.scrollTop;
|
|
|
|
|
|
|
|
|
|
if (app.apps[app.current.app].scrollPos != undefined)
|
|
|
|
|
app.apps[app.current.app].scrollPos = scrollPos
|
|
|
|
|
else if (app.apps[app.current.app].tabs[app.current.tab].scrollPos != undefined)
|
|
|
|
|
app.apps[app.current.app].tabs[app.current.tab].scrollPos = scrollPos
|
|
|
|
|
else if (app.apps[app.current.app].tabs[app.current.tab].views[app.current.view].scrollPos != undefined)
|
|
|
|
|
app.apps[app.current.app].tabs[app.current.tab].views[app.current.view].scrollPos = scrollPos;
|
|
|
|
|
|
|
|
|
|
var hash = '';
|
2018-06-25 22:41:44 +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-07-05 19:34:16 +00:00
|
|
|
|
hash = '/' + a + '/' + t +'/'+v + '!' + (s == undefined ? app.apps[a].tabs[t].views[v].state : s);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
} else {
|
|
|
|
|
hash = '/'+a+'/'+t+'!'+ (s == undefined ? app.apps[a].tabs[t].state : s);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2018-07-05 19:34:16 +00:00
|
|
|
|
hash = '/' + a + '!'+ (s == undefined ? app.apps[a].state : s);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
2018-07-05 19:34:16 +00:00
|
|
|
|
location.hash = hash;
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 19:40:27 +00:00
|
|
|
|
function appRoute() {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
var hash = decodeURI(location.hash);
|
2018-07-19 18:26:15 +00:00
|
|
|
|
var params;
|
2018-07-05 19:34:16 +00:00
|
|
|
|
if (params = hash.match(/^\#\/(\w+)\/?(\w+)?\/?(\w+)?\!((\d+)\/([^\/]+)\/(.*))$/)) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
app.current.app = params[1];
|
|
|
|
|
app.current.tab = params[2];
|
|
|
|
|
app.current.view = params[3];
|
|
|
|
|
if (app.apps[app.current.app].state) {
|
|
|
|
|
app.apps[app.current.app].state = params[4];
|
2018-07-09 15:36:45 +00:00
|
|
|
|
app.current.scrollPos = app.apps[app.current.app].scrollPos;
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
|
|
|
|
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;
|
2018-07-09 15:36:45 +00:00
|
|
|
|
app.current.scrollPos = app.apps[app.current.app].tabs[app.current.tab].scrollPos;
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
|
|
|
|
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-07-09 15:36:45 +00:00
|
|
|
|
app.current.scrollPos = app.apps[app.current.app].tabs[app.current.tab].views[app.current.view].scrollPos;
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
|
|
|
|
app.current.page = parseInt(params[5]);
|
|
|
|
|
app.current.filter = params[6];
|
|
|
|
|
app.current.search = params[7];
|
2018-06-10 21:15:33 +00:00
|
|
|
|
} else {
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appGoto('Playback');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
return;
|
2018-06-10 21:15:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-09 15:36:45 +00:00
|
|
|
|
appPrepare(app.current.scrollPos);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
|
2018-06-10 21:15:33 +00:00
|
|
|
|
if (app.current.app == 'Playback') {
|
2018-06-25 22:41:44 +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' ) {
|
2018-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById('QueueList').classList.add('opacity05');
|
2018-07-16 20:39:27 +00:00
|
|
|
|
/* if (app.last.app != app.current.app) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (app.current.search.length < 2) {
|
|
|
|
|
setPagination(app.current.page);
|
|
|
|
|
}
|
2018-06-26 22:46:29 +00:00
|
|
|
|
}
|
2018-07-15 23:56:58 +00:00
|
|
|
|
*/
|
2018-06-26 22:46:29 +00:00
|
|
|
|
var btns = document.getElementById('searchqueuetag').getElementsByTagName('button');
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < btns.length; i++) {
|
2018-06-26 22:46:29 +00:00
|
|
|
|
btns[i].classList.remove('active');
|
|
|
|
|
if (btns[i].innerText == app.current.filter) {
|
|
|
|
|
btns[i].classList.add('active');
|
|
|
|
|
document.getElementById('searchqueuetagdesc').innerText = btns[i].innerText;
|
2018-05-31 23:05:49 +00:00
|
|
|
|
}
|
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-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById('BrowsePlaylistsList').classList.add('opacity05');
|
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-28 22:51:24 +00:00
|
|
|
|
doSetFilterLetter('BrowsePlaylistsFilter');
|
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-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById('BrowseDatabaseArtistList').classList.add('opacity05');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_ARTISTS","data": {"offset": app.current.page, "filter": app.current.filter}}, parseListDBtags);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
doSetFilterLetter('BrowseDatabaseFilter');
|
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-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById('BrowseDatabaseAlbumCards').classList.add('opacity05');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_ARTISTALBUMS","data": {"offset": app.current.page, "filter": app.current.filter, "albumartist": app.current.search}}, parseListDBtags);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
doSetFilterLetter('BrowseDatabaseFilter');
|
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') {
|
2018-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById('BrowseFilesystemList').classList.add('opacity05');
|
2018-06-25 22:41:44 +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-06-25 22:41:44 +00:00
|
|
|
|
if (app.current.search)
|
|
|
|
|
document.getElementById('BrowseFilesystemAddAllSongs').removeAttribute('disabled');
|
|
|
|
|
else
|
|
|
|
|
document.getElementById('BrowseFilesystemAddAllSongs').setAttribute('disabled', 'disabled')
|
|
|
|
|
// Create breadcrumb
|
2018-07-01 22:49:47 +00:00
|
|
|
|
var breadcrumbs='<li class="breadcrumb-item"><a data-uri="">root</a></li>';
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var pathArray = app.current.search.split('/');
|
|
|
|
|
var pathArrayLen = pathArray.length;
|
|
|
|
|
var fullPath = '';
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < pathArrayLen; i++) {
|
2018-06-27 23:19:09 +00:00
|
|
|
|
if (pathArrayLen -1 == i) {
|
2018-07-01 22:49:47 +00:00
|
|
|
|
breadcrumbs += '<li class="breadcrumb-item active">' + pathArray[i] + '</li>';
|
2018-06-25 22:41:44 +00:00
|
|
|
|
break;
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
2018-06-27 23:19:09 +00:00
|
|
|
|
fullPath += pathArray[i];
|
2018-07-01 22:49:47 +00:00
|
|
|
|
breadcrumbs += '<li class="breadcrumb-item"><a data-uri="' + fullPath + '">' + pathArray[i] + '</a></li>';
|
2018-06-27 23:19:09 +00:00
|
|
|
|
fullPath += '/';
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
|
|
|
|
var elBrowseBreadcrumb=document.getElementById('BrowseBreadcrumb');
|
2018-07-01 22:49:47 +00:00
|
|
|
|
elBrowseBreadcrumb.innerHTML = breadcrumbs;
|
2018-06-25 22:41:44 +00:00
|
|
|
|
var breadcrumbItems = elBrowseBreadcrumb.getElementsByTagName('a');
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var breadcrumbItemsLen = breadcrumbItems.length;
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < breadcrumbItemsLen; i++) {
|
2018-06-27 23:19:09 +00:00
|
|
|
|
breadcrumbItems[i].addEventListener('click', function() {
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appGoto('Browse', 'Filesystem', undefined, '0/' + app.current.filter + '/' + this.getAttribute('data-uri'));
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}, false);
|
|
|
|
|
}
|
2018-06-28 22:51:24 +00:00
|
|
|
|
doSetFilterLetter('BrowseFilesystemFilter');
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
2018-06-10 21:15:33 +00:00
|
|
|
|
else if (app.current.app == 'Search') {
|
2018-07-15 23:56:58 +00:00
|
|
|
|
document.getElementById('searchstr').focus();
|
2018-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById('SearchList').classList.add('opacity05');
|
2018-06-10 21:15:33 +00:00
|
|
|
|
if (app.last.app != app.current.app) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (app.current.search != '')
|
|
|
|
|
document.getElementById('SearchList').getElementsByTagName('tbody')[0].innerHTML=
|
|
|
|
|
'<tr><td><span class="material-icons">search</span></td>' +
|
|
|
|
|
'<td colspan="5">Searching...</td></tr>';
|
2018-07-15 23:56:58 +00:00
|
|
|
|
// else
|
|
|
|
|
// setPagination(app.current.page);
|
|
|
|
|
// document.getElementById('searchstr').value = app.current.search;
|
2018-05-29 20:12:11 +00:00
|
|
|
|
}
|
2018-06-25 22:41:44 +00:00
|
|
|
|
|
2018-06-10 19:31:40 +00:00
|
|
|
|
if (app.current.search.length >= 2) {
|
2018-06-28 22:51:24 +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-28 22:51:24 +00:00
|
|
|
|
document.getElementById('SearchList').getElementsByTagName('tbody')[0].innerHTML = '';
|
|
|
|
|
document.getElementById('searchAddAllSongs').setAttribute('disabled', 'disabled');
|
|
|
|
|
document.getElementById('panel-heading-search').innerText = '';
|
2018-07-15 23:56:58 +00:00
|
|
|
|
// setPagination(app.current.page);
|
2018-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById('SearchList').classList.remove('opacity05');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-15 23:56:58 +00:00
|
|
|
|
var btns = document.getElementById('searchtags').getElementsByTagName('button');
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var btnsLen = btns.length;
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < btnsLen; i++) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
btns[i].classList.remove('active');
|
|
|
|
|
if (btns[i].innerText == app.current.filter) {
|
|
|
|
|
btns[i].classList.add('active');
|
2018-07-15 23:56:58 +00:00
|
|
|
|
document.getElementById('searchtagsdesc').innerText = btns[i].innerText;
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
2018-05-29 20:12:11 +00:00
|
|
|
|
}
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appGoto("Playback");
|
2018-06-07 18:47:40 +00:00
|
|
|
|
}
|
2018-06-10 21:15:33 +00:00
|
|
|
|
|
2018-06-27 23:19:09 +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
|
|
|
|
|
2018-07-02 19:59:56 +00:00
|
|
|
|
function appInit() {
|
2018-06-21 17:28:07 +00:00
|
|
|
|
getSettings();
|
2018-06-28 22:51:24 +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
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
domCache.volumeBar.value = 0;
|
|
|
|
|
domCache.volumeBar.addEventListener('change', function(event) {
|
2018-07-05 21:56:42 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_SET_VOLUME","data": {"volume": domCache.volumeBar.value}});
|
2018-06-28 22:51:24 +00:00
|
|
|
|
}, false);
|
2018-05-21 23:36:05 +00:00
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
domCache.progressBar.value = 0;
|
|
|
|
|
domCache.progressBar.addEventListener('change', function(event) {
|
2014-01-17 15:41:54 +00:00
|
|
|
|
if(current_song && current_song.currentSongId >= 0) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var seekVal = Math.ceil(current_song.totalTime * (domCache.progressBar.value / 100));
|
|
|
|
|
sendAPI({"cmd": "MPD_API_SET_SEEK", "data": {"songid":current_song.currentSongId,"seek": seekVal}});
|
2014-01-16 17:32:20 +00:00
|
|
|
|
}
|
2018-06-28 22:51:24 +00:00
|
|
|
|
}, false);
|
|
|
|
|
|
2018-07-02 22:02:02 +00:00
|
|
|
|
document.getElementById('modalAbout').addEventListener('shown.bs.modal', function () {
|
2018-07-02 19:40:27 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_GET_STATS"}, parseStats);
|
2018-07-09 17:28:28 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-07-02 22:02:02 +00:00
|
|
|
|
document.getElementById('modalSettings').addEventListener('shown.bs.modal', function () {
|
2018-07-02 19:40:27 +00:00
|
|
|
|
getSettings();
|
|
|
|
|
document.getElementById('settingsFrm').classList.remove('was-validated');
|
|
|
|
|
document.getElementById('inputCrossfade').classList.remove('is-invalid');
|
|
|
|
|
document.getElementById('inputMixrampdb').classList.remove('is-invalid');
|
|
|
|
|
document.getElementById('inputMixrampdelay').classList.remove('is-invalid');
|
2018-07-09 17:28:28 +00:00
|
|
|
|
});
|
2018-05-27 21:34:39 +00:00
|
|
|
|
|
2018-07-02 22:02:02 +00:00
|
|
|
|
document.getElementById('modalAddstream').addEventListener('shown.bs.modal', function () {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
document.getElementById('streamurl').focus();
|
2018-07-09 17:28:28 +00:00
|
|
|
|
});
|
2018-05-29 21:05:34 +00:00
|
|
|
|
|
2018-07-02 22:02:02 +00:00
|
|
|
|
document.getElementById('addstreamFrm').addEventListener('submit', function () {
|
2015-07-16 09:50:54 +00:00
|
|
|
|
addStream();
|
|
|
|
|
});
|
2018-05-23 22:32:01 +00:00
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
addFilterLetter('BrowseFilesystemFilterLetters');
|
|
|
|
|
addFilterLetter('BrowseDatabaseFilterLetters');
|
|
|
|
|
addFilterLetter('BrowsePlaylistsFilterLetters');
|
|
|
|
|
|
2018-07-02 19:40:27 +00:00
|
|
|
|
var hrefs = document.querySelectorAll('button[data-href], a[data-href]');
|
|
|
|
|
var hrefsLen = hrefs.length;
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < hrefsLen; i++) {
|
2018-07-02 19:40:27 +00:00
|
|
|
|
hrefs[i].addEventListener('click', function(event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
var cmd = JSON.parse(this.getAttribute('data-href').replace(/\'/g,'"'));
|
|
|
|
|
if (typeof window[cmd.cmd] === 'function') {
|
|
|
|
|
switch(cmd.cmd) {
|
|
|
|
|
case 'sendAPI':
|
|
|
|
|
sendAPI(... cmd.options);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
window[cmd.cmd](... cmd.options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var pd = document.querySelectorAll('.pages');
|
|
|
|
|
var pdLen = pd.length;
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < pdLen; i++) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
pd[i].addEventListener('click', function(event) {
|
|
|
|
|
if (event.target.nodeName == 'BUTTON') {
|
|
|
|
|
gotoPage(event.target.getAttribute('data-page'));
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.getElementById('outputs').addEventListener('click', function(event) {
|
|
|
|
|
if (event.target.nodeName == 'BUTTON')
|
2018-07-02 19:40:27 +00:00
|
|
|
|
event.stopPropagation();
|
2018-06-28 22:51:24 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_TOGGLE_OUTPUT", "data": {"output": event.target.getAttribute('data-output-id'), "state": (event.target.classList.contains('active') ? 0 : 1)}});
|
2018-07-05 21:56:42 +00:00
|
|
|
|
toggleBtn(event.target.id);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
document.getElementById('QueueList').addEventListener('click', function(event) {
|
|
|
|
|
if (event.target.nodeName == 'TD')
|
|
|
|
|
sendAPI({"cmd": "MPD_API_PLAY_TRACK","data": {"track": event.target.parentNode.getAttribute('data-trackid')}});
|
|
|
|
|
else if (event.target.nodeName == 'A') {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
showMenu(event.target);
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
document.getElementById('BrowseFilesystemList').addEventListener('click', function(event) {
|
|
|
|
|
if (event.target.nodeName == 'TD') {
|
|
|
|
|
switch(event.target.parentNode.getAttribute('data-type')) {
|
|
|
|
|
case 'dir':
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appGoto('Browse', 'Filesystem', undefined, '0/' + app.current.filter +'/' + decodeURI(event.target.parentNode.getAttribute("data-uri")));
|
2018-06-28 22:51:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'song':
|
2018-07-05 19:34:16 +00:00
|
|
|
|
appendQueue('song', decodeURI(event.target.parentNode.getAttribute("data-uri")), event.target.parentNode.getAttribute("data-name"));
|
2018-06-28 22:51:24 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'plist':
|
2018-07-05 19:34:16 +00:00
|
|
|
|
appendQueue('plist', decodeURI(event.target.parentNode.getAttribute("data-uri")), event.target.parentNode.getAttribute("data-name"));
|
2018-06-28 22:51:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (event.target.nodeName == 'A') {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
showMenu(event.target);
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
document.getElementById('BrowsePlaylistsList').addEventListener('click', function(event) {
|
|
|
|
|
if (event.target.nodeName == 'TD') {
|
|
|
|
|
appendQueue('plist', decodeURI(event.target.parentNode.getAttribute("data-uri")), event.target.parentNode.getAttribute("data-name"));
|
|
|
|
|
}
|
|
|
|
|
else if (event.target.nodeName == 'A') {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
showMenu(event.target);
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
document.getElementById('BrowseDatabaseArtistList').addEventListener('click', function(event) {
|
|
|
|
|
if (event.target.nodeName == 'TD') {
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appGoto('Browse', 'Database', 'Album', '0/-/' + event.target.parentNode.getAttribute('data-uri'));
|
2018-06-28 22:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
document.getElementById('SearchList').addEventListener('click', function(event) {
|
|
|
|
|
if (event.target.nodeName == 'TD') {
|
|
|
|
|
appendQueue('song', decodeURI(event.target.parentNode.getAttribute("data-uri")), event.target.parentNode.getAttribute("data-name"));
|
|
|
|
|
}
|
|
|
|
|
else if (event.target.nodeName == 'A') {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
showMenu(event.target);
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
|
2018-07-15 23:56:58 +00:00
|
|
|
|
document.getElementById('searchtags').addEventListener('click', function(event) {
|
2018-06-28 23:44:52 +00:00
|
|
|
|
if (event.target.nodeName == 'BUTTON')
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appGoto(app.current.app, app.current.tab, app.current.view, '0/' + event.target.innerText + '/' + app.current.search);
|
2018-06-28 23:44:52 +00:00
|
|
|
|
}, false);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
|
2018-06-28 23:44:52 +00:00
|
|
|
|
document.getElementById('searchqueuestr').addEventListener('keyup', function(event) {
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appGoto(app.current.app, app.current.tab, app.current.view, '0/' + app.current.filter + '/' + this.value);
|
2018-06-28 23:44:52 +00:00
|
|
|
|
}, false);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
|
2018-06-28 23:44:52 +00:00
|
|
|
|
document.getElementById('searchqueuetag').addEventListener('click', function (event) {
|
|
|
|
|
if (event.target.nodeName == 'BUTTON')
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appGoto(app.current.app, app.current.tab, app.current.view, app.current.page + '/' + event.target.innerText + '/' + app.current.search);
|
2018-06-28 23:44:52 +00:00
|
|
|
|
}, false);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
|
|
|
|
|
document.getElementById('search').addEventListener('submit', function () {
|
|
|
|
|
return false;
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
document.getElementById('searchqueue').addEventListener('submit', function () {
|
|
|
|
|
return false;
|
|
|
|
|
}, false);
|
|
|
|
|
|
2018-07-15 23:56:58 +00:00
|
|
|
|
document.getElementById('searchstr').addEventListener('keyup', function (event) {
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appGoto('Search', undefined, undefined, '0/' + app.current.filter + '/' + this.value);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
}, false);
|
|
|
|
|
|
2018-07-02 19:40:27 +00:00
|
|
|
|
window.addEventListener('hashchange', appRoute, false);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
|
|
|
|
|
document.addEventListener('keydown', function(event) {
|
|
|
|
|
if (event.target.tagName == 'INPUT')
|
|
|
|
|
return;
|
2018-07-02 19:40:27 +00:00
|
|
|
|
switch (event.which) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
case 37: //left
|
|
|
|
|
clickPrev();
|
|
|
|
|
break;
|
|
|
|
|
case 39: //right
|
|
|
|
|
clickNext();
|
|
|
|
|
break;
|
|
|
|
|
case 32: //space
|
|
|
|
|
clickPlay();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-06-29 06:52:32 +00:00
|
|
|
|
event.preventDefault();
|
2018-06-28 22:51:24 +00:00
|
|
|
|
}, false);
|
2018-07-16 17:33:20 +00:00
|
|
|
|
|
2018-07-19 16:33:53 +00:00
|
|
|
|
if ('serviceWorker' in navigator && document.URL.substring(0, 5) == 'https') {
|
2018-07-16 17:33:20 +00:00
|
|
|
|
window.addEventListener('load', function() {
|
|
|
|
|
navigator.serviceWorker.register('/sw.js', {scope: '/'}).then(function(registration) {
|
|
|
|
|
// Registration was successful
|
|
|
|
|
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
|
|
|
|
}, function(err) {
|
|
|
|
|
// registration failed :(
|
|
|
|
|
console.log('ServiceWorker registration failed: ', err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.addEventListener('beforeinstallprompt', (e) => {
|
|
|
|
|
// Prevent Chrome 67 and earlier from automatically showing the prompt
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
// Stash the event so it can be triggered later.
|
|
|
|
|
deferredPrompt = e;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.addEventListener('beforeinstallprompt', (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
deferredPrompt = e;
|
|
|
|
|
// Update UI notify the user they can add to home screen
|
|
|
|
|
domCache.btnAdd.classList.remove('hide');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
domCache.btnAdd.addEventListener('click', (e) => {
|
|
|
|
|
// hide our user interface that shows our A2HS button
|
|
|
|
|
domCache.btnAdd.classList.add('hide');
|
|
|
|
|
// Show the prompt
|
|
|
|
|
deferredPrompt.prompt();
|
|
|
|
|
// Wait for the user to respond to the prompt
|
|
|
|
|
deferredPrompt.userChoice.then((choiceResult) => {
|
|
|
|
|
if (choiceResult.outcome === 'accepted')
|
|
|
|
|
console.log('User accepted the A2HS prompt');
|
|
|
|
|
else
|
|
|
|
|
console.log('User dismissed the A2HS prompt');
|
|
|
|
|
deferredPrompt = null;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.addEventListener('appinstalled', (evt) => {
|
|
|
|
|
console.log('appinstalled');
|
|
|
|
|
});
|
2018-07-02 19:59:56 +00:00
|
|
|
|
}
|
2013-11-07 09:09:40 +00:00
|
|
|
|
|
2013-11-05 13:59:12 +00:00
|
|
|
|
function webSocketConnect() {
|
2018-07-05 19:34:16 +00:00
|
|
|
|
socket = new WebSocket(getWsUrl());
|
2014-01-16 17:32:20 +00:00
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
socket.onopen = function() {
|
2018-07-05 19:34:16 +00:00
|
|
|
|
console.log('connected');
|
|
|
|
|
showNotification('Connected to myMPD', '', '', 'success');
|
2018-07-02 22:02:02 +00:00
|
|
|
|
modalConnectionError.hide();
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appRoute();
|
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-07-05 21:56:42 +00:00
|
|
|
|
|
2018-05-17 22:10:57 +00:00
|
|
|
|
try {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var obj = JSON.parse(msg.data);
|
2018-05-17 22:10:57 +00:00
|
|
|
|
} catch(e) {
|
2018-07-05 19:34:16 +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':
|
2018-07-05 19:34:16 +00:00
|
|
|
|
showNotification('myMPD lost connection to MPD', '', '', 'danger');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'update_queue':
|
|
|
|
|
if(app.current.app === 'Queue')
|
|
|
|
|
getQueue();
|
|
|
|
|
break;
|
2018-06-28 22:51:24 +00:00
|
|
|
|
case 'song_change':
|
2018-06-19 22:43:36 +00:00
|
|
|
|
songChange(obj);
|
2018-06-14 19:56:12 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'error':
|
2018-07-05 19:34:16 +00:00
|
|
|
|
showNotification(obj.data, '', '', 'danger');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
socket.onclose = function(){
|
|
|
|
|
console.log('disconnected');
|
2018-07-02 22:02:02 +00:00
|
|
|
|
modalConnectionError.show();
|
2018-06-14 19:56:12 +00:00
|
|
|
|
setTimeout(function() {
|
|
|
|
|
console.log('reconnect');
|
|
|
|
|
webSocketConnect();
|
2018-06-28 22:51:24 +00:00
|
|
|
|
}, 3000);
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch(exception) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
alert('Error: ' + exception);
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-05 19:34:16 +00:00
|
|
|
|
function getWsUrl() {
|
2018-06-14 19:56:12 +00:00
|
|
|
|
var pcol;
|
|
|
|
|
var u = document.URL;
|
|
|
|
|
var separator;
|
|
|
|
|
|
2018-07-05 19:34:16 +00:00
|
|
|
|
if (u.substring(0, 5) == 'https') {
|
|
|
|
|
pcol = 'wss://';
|
2018-06-14 19:56:12 +00:00
|
|
|
|
u = u.substr(8);
|
|
|
|
|
} else {
|
2018-07-05 19:34:16 +00:00
|
|
|
|
pcol = 'ws://';
|
|
|
|
|
if (u.substring(0, 4) == 'http')
|
2018-06-14 19:56:12 +00:00
|
|
|
|
u = u.substr(7);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u = u.split('#');
|
2018-07-05 21:56:42 +00:00
|
|
|
|
if (/\/$/.test(u[0]))
|
2018-07-05 19:34:16 +00:00
|
|
|
|
separator = '';
|
2018-07-05 21:56:42 +00:00
|
|
|
|
else
|
2018-07-05 19:34:16 +00:00
|
|
|
|
separator = '/';
|
2018-07-05 21:56:42 +00:00
|
|
|
|
|
2018-07-05 19:34:16 +00:00
|
|
|
|
return pcol + u[0] + separator + 'ws';
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseStats(obj) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
document.getElementById('mpdstats_artists').innerText = obj.data.artists;
|
|
|
|
|
document.getElementById('mpdstats_albums').innerText = obj.data.albums;
|
|
|
|
|
document.getElementById('mpdstats_songs').innerText = obj.data.songs;
|
|
|
|
|
document.getElementById('mpdstats_dbplaytime').innerText = beautifyDuration(obj.data.dbplaytime);
|
|
|
|
|
document.getElementById('mpdstats_playtime').innerText = beautifyDuration(obj.data.playtime);
|
|
|
|
|
document.getElementById('mpdstats_uptime').innerText = beautifyDuration(obj.data.uptime);
|
|
|
|
|
var d = new Date(obj.data.dbupdated * 1000);
|
|
|
|
|
document.getElementById('mpdstats_dbupdated').innerText = d.toUTCString();
|
|
|
|
|
document.getElementById('mympdVersion').innerText = obj.data.mympd_version;
|
|
|
|
|
document.getElementById('mpdVersion').innerText = obj.data.mpd_version;
|
2018-06-19 22:43:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
function toggleBtn(btn, state) {
|
|
|
|
|
var b = document.getElementById(btn);
|
2018-07-16 20:39:27 +00:00
|
|
|
|
if (!b) return;
|
2018-07-03 21:46:07 +00:00
|
|
|
|
if (state == undefined)
|
|
|
|
|
state = b.classList.contains('active') ? 0 : 1;
|
2018-06-28 22:51:24 +00:00
|
|
|
|
if (state == 1) {
|
|
|
|
|
b.classList.add('active');
|
|
|
|
|
b.setAttribute('aria-pressed','true');
|
|
|
|
|
} else {
|
|
|
|
|
b.classList.remove('active');
|
|
|
|
|
b.setAttribute('aria-pressed','false');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-14 19:56:12 +00:00
|
|
|
|
function parseSettings(obj) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
toggleBtn('btnRandom', obj.data.random);
|
|
|
|
|
toggleBtn('btnConsume', obj.data.consume);
|
|
|
|
|
toggleBtn('btnSingle', obj.data.single);
|
|
|
|
|
toggleBtn('btnRepeat', obj.data.repeat);
|
|
|
|
|
|
|
|
|
|
if (obj.data.crossfade != undefined) {
|
|
|
|
|
document.getElementById('inputCrossfade').removeAttribute('disabled');
|
|
|
|
|
document.getElementById('inputCrossfade').value = obj.data.crossfade;
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById('inputCrossfade').setAttribute('disabled', 'disabled');
|
|
|
|
|
}
|
|
|
|
|
if (obj.data.mixrampdb != undefined) {
|
|
|
|
|
document.getElementById('inputMixrampdb').removeAttribute('disabled');
|
|
|
|
|
document.getElementById('inputMixrampdb').value = obj.data.mixrampdb;
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById('inputMixrampdb').setAttribute('disabled', 'disabled');
|
|
|
|
|
}
|
|
|
|
|
if (obj.data.mixrampdelay != undefined) {
|
|
|
|
|
document.getElementById('inputMixrampdelay').removeAttribute('disabled');
|
|
|
|
|
document.getElementById('inputMixrampdelay').value = obj.data.mixrampdelay;
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById('inputMixrampdelay').setAttribute('disabled', 'disabled');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.getElementById('selectReplaygain').value = obj.data.replaygain;
|
|
|
|
|
|
|
|
|
|
var btnnotifyWeb = document.getElementById('btnnotifyWeb');
|
|
|
|
|
if (notificationsSupported()) {
|
|
|
|
|
if (obj.data.notificationWeb) {
|
|
|
|
|
toggleBtn('btnnotifyWeb', obj.data.notificationWeb);
|
|
|
|
|
Notification.requestPermission(function (permission) {
|
|
|
|
|
if (!('permission' in Notification))
|
|
|
|
|
Notification.permission = permission;
|
|
|
|
|
if (permission === 'granted') {
|
|
|
|
|
toggleBtn('btnnotifyWeb', 1);
|
|
|
|
|
} else {
|
|
|
|
|
toggleBtn('btnnotifyWeb', 0);
|
|
|
|
|
obj.data.notificationWeb = 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
toggleBtn('btnnotifyWeb', 0);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
btnnotifyWeb.setAttribute('disabled', 'disabled');
|
|
|
|
|
toggleBtn('btnnotifyWeb', 0);
|
|
|
|
|
}
|
2018-06-21 16:57:40 +00:00
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
toggleBtn('btnnotifyPage', obj.data.notificationPage);
|
|
|
|
|
|
|
|
|
|
settings=obj.data;
|
|
|
|
|
settings.mpdstream = 'http://';
|
|
|
|
|
if (settings.mpdhost == '127.0.0.1' || settings.mpdhost == 'localhost')
|
|
|
|
|
settings.mpdstream += window.location.hostname;
|
|
|
|
|
else
|
|
|
|
|
settings.mpdstream += settings.mpdhost;
|
|
|
|
|
settings.mpdstream += ':' + settings.streamport + '/';
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-21 17:28:07 +00:00
|
|
|
|
function getSettings() {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_GET_SETTINGS"}, parseSettings);
|
2018-06-21 17:28:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-14 19:56:12 +00:00
|
|
|
|
function parseOutputnames(obj) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var btns = '';
|
|
|
|
|
var outputsLen = obj.data.outputs.length;
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < outputsLen; i++) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
btns += '<button id="btnoutput' + obj.data.outputs[i].id +'" data-output-id="' + obj.data.outputs[i].id + '" class="btn btn-secondary btn-block">'+
|
|
|
|
|
'<span class="material-icons float-left">volume_up</span> ' + obj.data.outputs[i].name + '</button>';
|
|
|
|
|
}
|
2018-06-29 06:52:32 +00:00
|
|
|
|
domCache.outputs.innerHTML = btns;
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseState(obj) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
if (JSON.stringify(obj) === JSON.stringify(last_state))
|
2018-06-25 22:41:44 +00:00
|
|
|
|
return;
|
2018-06-14 19:56:12 +00:00
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
//Set playstate
|
2018-06-29 06:52:32 +00:00
|
|
|
|
if (obj.data.state == 1) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
domCache.btnPlay.innerText = 'play_arrow';
|
|
|
|
|
playstate = 'stop';
|
2018-06-29 06:52:32 +00:00
|
|
|
|
} else if (obj.data.state == 2) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
domCache.btnPlay.innerText = 'pause';
|
|
|
|
|
playstate = 'play';
|
|
|
|
|
} else {
|
|
|
|
|
domCache.btnPlay.innerText = 'play_arrow';
|
|
|
|
|
playstate = 'pause';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (obj.data.nextsongpos == -1)
|
|
|
|
|
domCache.btnNext.setAttribute('disabled','disabled');
|
|
|
|
|
else
|
|
|
|
|
domCache.btnNext.removeAttribute('disabled');
|
|
|
|
|
|
|
|
|
|
if (obj.data.songpos <= 0)
|
|
|
|
|
domCache.btnPrev.setAttribute('disabled','disabled');
|
|
|
|
|
else
|
|
|
|
|
domCache.btnPrev.removeAttribute('disabled');
|
|
|
|
|
|
|
|
|
|
if (obj.data.queue_length == 0)
|
|
|
|
|
domCache.btnPlay.setAttribute('disabled','disabled');
|
|
|
|
|
else
|
|
|
|
|
domCache.btnPlay.removeAttribute('disabled');
|
|
|
|
|
|
|
|
|
|
//Set volume
|
|
|
|
|
if (obj.data.volume == -1) {
|
2018-07-19 16:33:53 +00:00
|
|
|
|
domCache.volumePrct.innerText = 'Volumecontrol disabled';
|
2018-06-28 22:51:24 +00:00
|
|
|
|
domCache.volumeControl.classList.add('hide');
|
|
|
|
|
} else {
|
|
|
|
|
domCache.volumeControl.classList.remove('hide');
|
|
|
|
|
domCache.volumePrct.innerText = obj.data.volume + ' %';
|
|
|
|
|
if(obj.data.volume == 0)
|
|
|
|
|
domCache.volumeIcon.innerText = 'volume_off';
|
|
|
|
|
else if (obj.data.volume < 50)
|
|
|
|
|
domCache.volumeIcon.innerText = 'volume_down';
|
|
|
|
|
else
|
|
|
|
|
domCache.volumeIcon.innerText = 'volume_up';
|
|
|
|
|
}
|
|
|
|
|
domCache.volumeBar.value = obj.data.volume;
|
|
|
|
|
|
|
|
|
|
//Set play counters
|
2018-06-25 22:41:44 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
domCache.progressBar.value = Math.floor(100 * obj.data.elapsedTime / obj.data.totalTime);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
|
|
|
|
|
var counterText = elapsed_minutes + ":" +
|
|
|
|
|
(elapsed_seconds < 10 ? '0' : '') + elapsed_seconds + " / " +
|
|
|
|
|
total_minutes + ":" + (total_seconds < 10 ? '0' : '') + total_seconds;
|
2018-06-27 23:19:09 +00:00
|
|
|
|
domCache.counter.innerText = counterText;
|
2018-07-09 15:36:45 +00:00
|
|
|
|
|
2018-06-27 23:19:09 +00:00
|
|
|
|
//Set playing track in queue view
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (last_state) {
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var tr = document.getElementById('queueTrackId' + last_state.data.currentsongid);
|
|
|
|
|
if (tr) {
|
|
|
|
|
var trtds = tr.getElementsByTagName('td');
|
|
|
|
|
trtds[4].innerText = tr.getAttribute('data-duration');
|
|
|
|
|
trtds[0].classList.remove('material-icons');
|
|
|
|
|
trtds[0].innerText = tr.getAttribute('data-songpos');
|
|
|
|
|
tr.classList.remove('font-weight-bold');
|
|
|
|
|
}
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var tr = document.getElementById('queueTrackId' + obj.data.currentsongid);
|
|
|
|
|
if (tr) {
|
|
|
|
|
var trtds = tr.getElementsByTagName('td');
|
|
|
|
|
trtds[4].innerText = counterText;
|
|
|
|
|
trtds[0].classList.add('material-icons');
|
|
|
|
|
trtds[0].innerText = 'play_arrow';
|
|
|
|
|
tr.classList.add('font-weight-bold');
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 22:41:44 +00:00
|
|
|
|
//Get current song on queue change for http streams
|
|
|
|
|
if (last_state == undefined || obj.data.queue_version != last_state.data.queue_version)
|
2018-06-28 22:51:24 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_GET_CURRENT_SONG"}, songChange);
|
|
|
|
|
|
|
|
|
|
// Set outputs state
|
|
|
|
|
var outputsLen = obj.data.outputs.length;
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < outputsLen; i++) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
toggleBtn('btnoutput' + obj.data.outputs[i].id, obj.data.outputs[i].state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
last_state = obj;
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getQueue() {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (app.current.search.length >= 2)
|
2018-06-28 22:51:24 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_SEARCH_QUEUE", "data": {"mpdtag":app.current.filter, "offset":app.current.page, "searchstr": app.current.search}}, parseQueue);
|
2018-07-15 21:49:57 +00:00
|
|
|
|
else {
|
2018-07-16 20:39:27 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_GET_QUEUE", "data": {"offset": app.current.page}}, parseQueue);
|
2018-07-15 21:49:57 +00:00
|
|
|
|
}
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseQueue(obj) {
|
2018-06-26 22:46:29 +00:00
|
|
|
|
if (app.current.app !== 'Queue')
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (typeof(obj.totalTime) != undefined && obj.totalTime > 0 )
|
|
|
|
|
document.getElementById('panel-heading-queue').innerText = obj.totalEntities + ' Songs – ' + beautifyDuration(obj.totalTime);
|
|
|
|
|
else if (obj.totalEntities > 0)
|
|
|
|
|
document.getElementById('panel-heading-queue').innerText = obj.totalEntities + ' Songs';
|
|
|
|
|
else
|
|
|
|
|
document.getElementById('panel-heading-queue').innerText = '';
|
|
|
|
|
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var nrItems = obj.data.length;
|
2018-07-15 21:49:57 +00:00
|
|
|
|
var table = document.getElementById(app.current.app + 'List');
|
|
|
|
|
table.setAttribute('data-version', obj.queue_version);
|
|
|
|
|
var tbody = table.getElementsByTagName('tbody')[0];
|
2018-06-26 22:46:29 +00:00
|
|
|
|
var tr = tbody.getElementsByTagName('tr');
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < nrItems; i++) {
|
2018-06-27 23:19:09 +00:00
|
|
|
|
if (tr[i])
|
|
|
|
|
if (tr[i].getAttribute('data-trackid') == obj.data[i].id)
|
2018-06-26 22:46:29 +00:00
|
|
|
|
continue;
|
2018-06-27 23:19:09 +00:00
|
|
|
|
|
|
|
|
|
var minutes = Math.floor(obj.data[i].duration / 60);
|
|
|
|
|
var seconds = obj.data[i].duration - minutes * 60;
|
|
|
|
|
var duration = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
|
2018-06-26 22:46:29 +00:00
|
|
|
|
var row = document.createElement('tr');
|
|
|
|
|
|
2018-06-27 23:19:09 +00:00
|
|
|
|
row.setAttribute('data-trackid', obj.data[i].id);
|
|
|
|
|
row.setAttribute('id','queueTrackId' + obj.data[i].id);
|
|
|
|
|
row.setAttribute('data-songpos', (obj.data[i].pos + 1));
|
|
|
|
|
row.setAttribute('data-duration', duration);
|
2018-07-09 17:28:28 +00:00
|
|
|
|
row.setAttribute('data-uri', obj.data[i].uri);
|
2018-06-27 23:19:09 +00:00
|
|
|
|
row.innerHTML = '<td>' + (obj.data[i].pos + 1) + '</td>' +
|
|
|
|
|
'<td>' + obj.data[i].title + '</td>' +
|
|
|
|
|
'<td>' + obj.data[i].artist + '</td>' +
|
|
|
|
|
'<td>' + obj.data[i].album + '</td>' +
|
|
|
|
|
'<td>' + duration + '</td>' +
|
2018-07-05 21:56:42 +00:00
|
|
|
|
'<td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>';
|
2018-06-27 23:19:09 +00:00
|
|
|
|
if (i < tr.length)
|
|
|
|
|
tr[i].replaceWith(row);
|
2018-06-26 22:46:29 +00:00
|
|
|
|
else
|
|
|
|
|
tbody.append(row);
|
|
|
|
|
}
|
|
|
|
|
var tr_length=tr.length - 1;
|
|
|
|
|
for (var i = tr_length; i >= nrItems; i --) {
|
|
|
|
|
tr[i].remove();
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
if (obj.type == 'queuesearch' && nrItems == 0)
|
2018-06-26 22:46:29 +00:00
|
|
|
|
tbody.innerHTML = '<tr><td><span class="material-icons">error_outline</span></td>' +
|
|
|
|
|
'<td colspan="5">No results, please refine your search!</td></tr>';
|
2018-06-28 22:51:24 +00:00
|
|
|
|
else if (obj.type == 'queue' && nrItems == 0)
|
2018-06-26 22:46:29 +00:00
|
|
|
|
tbody.innerHTML = '<tr><td><span class="material-icons">error_outline</span></td>' +
|
|
|
|
|
'<td colspan="5">Empty queue</td></tr>';
|
|
|
|
|
|
|
|
|
|
setPagination(obj.totalEntities);
|
2018-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById('QueueList').classList.remove('opacity05');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseSearch(obj) {
|
2018-06-24 21:39:37 +00:00
|
|
|
|
if (app.current.app !== 'Search')
|
|
|
|
|
return;
|
2018-06-28 22:51:24 +00:00
|
|
|
|
document.getElementById('panel-heading-search').innerHTML = obj.totalEntities + ' Songs found';
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (obj.totalEntities > 0)
|
|
|
|
|
document.getElementById('searchAddAllSongs').removeAttribute('disabled');
|
|
|
|
|
else
|
|
|
|
|
document.getElementById('searchAddAllSongs').setAttribute('disabled','disabled');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
parseFilesystem(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseFilesystem(obj) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (app.current.app !== 'Browse' && app.current.tab !== 'Filesystem' && app.current.app !== 'Search')
|
|
|
|
|
return;
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var nrItems = obj.data.length;
|
2018-06-25 22:41:44 +00:00
|
|
|
|
var tbody = document.getElementById(app.current.app + (app.current.tab==undefined ? '' : app.current.tab) + 'List').getElementsByTagName('tbody')[0];
|
|
|
|
|
var tr = tbody.getElementsByTagName('tr');
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < nrItems; i++) {
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var uri = encodeURI(obj.data[i].uri);
|
|
|
|
|
if (tr[i])
|
|
|
|
|
if (tr[i].getAttribute('data-uri') == uri)
|
2018-06-25 22:41:44 +00:00
|
|
|
|
continue;
|
|
|
|
|
var row = document.createElement('tr');
|
2018-06-27 23:19:09 +00:00
|
|
|
|
row.setAttribute('data-type', obj.data[i].type);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
row.setAttribute('data-uri', uri);
|
2018-06-27 23:19:09 +00:00
|
|
|
|
row.setAttribute('data-name', obj.data[i].name);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
|
2018-06-27 23:19:09 +00:00
|
|
|
|
switch(obj.data[i].type) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
case 'dir':
|
|
|
|
|
row.innerHTML = '<td><span class="material-icons">folder_open</span></td>' +
|
2018-06-27 23:19:09 +00:00
|
|
|
|
'<td colspan="4">' + obj.data[i].name + '</td>' +
|
2018-07-05 21:56:42 +00:00
|
|
|
|
'<td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>';
|
2018-06-25 22:41:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'song':
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var minutes = Math.floor(obj.data[i].duration / 60);
|
|
|
|
|
var seconds = obj.data[i].duration - minutes * 60;
|
2018-06-25 22:41:44 +00:00
|
|
|
|
row.innerHTML = '<td><span class="material-icons">music_note</span></td>' +
|
2018-06-27 23:19:09 +00:00
|
|
|
|
'<td>' + obj.data[i].title + '</td>' +
|
|
|
|
|
'<td>' + obj.data[i].artist + '</td>' +
|
|
|
|
|
'<td>' + obj.data[i].album + '</td>' +
|
2018-06-25 22:41:44 +00:00
|
|
|
|
'<td>' + minutes + ':' + (seconds < 10 ? '0' : '') + seconds +
|
2018-07-05 21:56:42 +00:00
|
|
|
|
'</td><td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>';
|
2018-06-25 22:41:44 +00:00
|
|
|
|
break;
|
|
|
|
|
case 'plist':
|
|
|
|
|
row.innerHTML = '<td><span class="material-icons">list</span></td>' +
|
2018-06-27 23:19:09 +00:00
|
|
|
|
'<td colspan="4">' + obj.data[i].name + '</td>' +
|
2018-07-05 21:56:42 +00:00
|
|
|
|
'<td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>';
|
2018-06-25 22:41:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2018-06-27 23:19:09 +00:00
|
|
|
|
if (i < tr.length)
|
|
|
|
|
tr[i].replaceWith(row);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
else
|
|
|
|
|
tbody.append(row);
|
|
|
|
|
}
|
|
|
|
|
var tr_length=tr.length - 1;
|
|
|
|
|
for (var i = tr_length; i >= nrItems; i --) {
|
|
|
|
|
tr[i].remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setPagination(obj.totalEntities);
|
2018-06-14 19:56:12 +00:00
|
|
|
|
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (nrItems == 0)
|
2018-06-28 22:51:24 +00:00
|
|
|
|
tbody.innerHTML = '<tr><td><span class="material-icons">error_outline</span></td>' +
|
|
|
|
|
'<td colspan="5">No results</td></tr>';
|
2018-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById(app.current.app + (app.current.tab==undefined ? '' : app.current.tab) + 'List').classList.remove('opacity05');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parsePlaylists(obj) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (app.current.app !== 'Browse' && app.current.tab !== 'Playlists')
|
|
|
|
|
return;
|
2018-06-27 23:19:09 +00:00
|
|
|
|
|
|
|
|
|
var nrItems = obj.data.length;
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var tbody = document.getElementById(app.current.app + app.current.tab + 'List').getElementsByTagName('tbody')[0];
|
2018-06-25 22:41:44 +00:00
|
|
|
|
var tr = tbody.getElementsByTagName('tr');
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < nrItems; i++) {
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var uri = encodeURI(obj.data[i].uri);
|
|
|
|
|
if (tr[i])
|
|
|
|
|
if (tr[i].getAttribute('data-uri') == uri)
|
2018-06-25 22:41:44 +00:00
|
|
|
|
continue;
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var d = new Date(obj.data[i].last_modified * 1000);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
var row = document.createElement('tr');
|
|
|
|
|
row.setAttribute('data-uri', uri);
|
|
|
|
|
row.setAttribute('data-type', 'plist');
|
2018-06-27 23:19:09 +00:00
|
|
|
|
row.setAttribute('data-name', obj.data[i].name);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
row.innerHTML = '<td><span class="material-icons">list</span></td>' +
|
2018-06-27 23:19:09 +00:00
|
|
|
|
'<td>' + obj.data[i].name + '</td>' +
|
2018-06-25 22:41:44 +00:00
|
|
|
|
'<td>'+ d.toUTCString() + '</td>' +
|
2018-07-05 21:56:42 +00:00
|
|
|
|
'<td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>';
|
2018-06-27 23:19:09 +00:00
|
|
|
|
if (i < tr.length)
|
|
|
|
|
tr[i].replaceWith(row);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
else
|
|
|
|
|
tbody.append(row);
|
|
|
|
|
}
|
|
|
|
|
var tr_length=tr.length - 1;
|
|
|
|
|
for (var i = tr_length; i >= nrItems; i --) {
|
|
|
|
|
tr[i].remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setPagination(obj.totalEntities);
|
|
|
|
|
|
|
|
|
|
if (nrItems == 0)
|
2018-06-28 22:51:24 +00:00
|
|
|
|
tbody.innerHTML = '<tr><td><span class="material-icons">error_outline</span></td>' +
|
|
|
|
|
'<td colspan="5">No playlists found.</td></tr>'
|
2018-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById(app.current.app + (app.current.tab==undefined ? '' : app.current.tab) + 'List').classList.remove('opacity05');
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseListDBtags(obj) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if(app.current.app !== 'Browse' && app.current.tab !== 'Database' && app.current.view !== 'Artist') return;
|
2018-06-14 19:56:12 +00:00
|
|
|
|
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if (obj.tagtype == 'AlbumArtist') {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
document.getElementById('BrowseDatabaseAlbumCards').classList.add('hide');
|
|
|
|
|
document.getElementById('BrowseDatabaseArtistList').classList.remove('hide');
|
|
|
|
|
document.getElementById('btnBrowseDatabaseArtist').classList.add('hide');
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var nrItems = obj.data.length;
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var tbody = document.getElementById(app.current.app + app.current.tab + app.current.view + 'List').getElementsByTagName('tbody')[0];
|
2018-06-25 22:41:44 +00:00
|
|
|
|
var tr = tbody.getElementsByTagName('tr');
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < nrItems; i++) {
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var uri = encodeURI(obj.data[i].value);
|
|
|
|
|
if (tr[i])
|
|
|
|
|
if (tr[i].getAttribute('data-uri') == uri)
|
2018-06-25 22:41:44 +00:00
|
|
|
|
continue;
|
|
|
|
|
var row = document.createElement('tr');
|
|
|
|
|
row.setAttribute('data-uri', uri);
|
|
|
|
|
row.innerHTML='<td><span class="material-icons">album</span></td>' +
|
2018-06-28 22:51:24 +00:00
|
|
|
|
'<td>' + obj.data[i].value + '</td>';
|
2018-06-25 22:41:44 +00:00
|
|
|
|
|
2018-06-27 23:19:09 +00:00
|
|
|
|
if (i < tr.length)
|
|
|
|
|
tr[i].replaceWith(row);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
else
|
|
|
|
|
tbody.append(row);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
|
|
|
|
var tr_length=tr.length - 1;
|
|
|
|
|
for (var i = tr_length; i >= nrItems; i --) {
|
|
|
|
|
tr[i].remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setPagination(obj.totalEntities);
|
|
|
|
|
|
|
|
|
|
if (nrItems == 0)
|
2018-06-28 22:51:24 +00:00
|
|
|
|
tbody.innerHTML = '<tr><td><span class="material-icons">error_outline</span></td>' +
|
2018-07-09 17:28:28 +00:00
|
|
|
|
'<td colspan="5">No entries found.</td></tr>';
|
2018-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById('BrowseDatabaseArtistList').classList.remove('opacity05');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
|
|
|
|
|
} else if (obj.tagtype == 'Album') {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
document.getElementById('BrowseDatabaseAlbumCards').classList.remove('hide');
|
|
|
|
|
document.getElementById('BrowseDatabaseArtistList').classList.add('hide');
|
|
|
|
|
document.getElementById('btnBrowseDatabaseArtist').classList.remove('hide');
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var nrItems = obj.data.length;
|
2018-07-09 17:28:28 +00:00
|
|
|
|
var cardContainer = document.getElementById('BrowseDatabaseAlbumCards');
|
2018-06-27 23:19:09 +00:00
|
|
|
|
var cards = cardContainer.querySelectorAll('.col-md');
|
|
|
|
|
for (var i = 0; i < nrItems; i++) {
|
|
|
|
|
var id=genId(obj.data[i].value);
|
|
|
|
|
if (cards[i])
|
|
|
|
|
if (cards[i].getAttribute('id') == id)
|
2018-06-25 22:41:44 +00:00
|
|
|
|
continue;
|
|
|
|
|
var card=document.createElement('div');
|
|
|
|
|
card.classList.add('col-md');
|
|
|
|
|
card.classList.add('mr-0');
|
|
|
|
|
card.setAttribute('id', id);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
card.innerHTML = '<div class="card mb-4" id="card' + id + '">' +
|
2018-07-09 18:44:42 +00:00
|
|
|
|
' <a href="#" class="card-img-top"><img class="card-img-top" src="" ></a>' +
|
2018-06-28 22:51:24 +00:00
|
|
|
|
' <div class="card-body">' +
|
|
|
|
|
' <h5 class="card-title">' + obj.searchstr + '</h5>' +
|
|
|
|
|
' <h4 class="card-title">' + obj.data[i].value + '</h4>' +
|
|
|
|
|
' <table class="table table-sm table-hover" id="tbl' + id + '"><tbody></tbody></table'+
|
|
|
|
|
' </div>'+
|
|
|
|
|
'</div>';
|
2018-06-25 22:41:44 +00:00
|
|
|
|
|
2018-06-27 23:19:09 +00:00
|
|
|
|
if (i < cards.length)
|
|
|
|
|
cards[i].replaceWith(card);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
else
|
|
|
|
|
cardContainer.append(card);
|
|
|
|
|
|
2018-06-27 23:19:09 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_GET_ARTISTALBUMTITLES", "data": { "albumartist": obj.searchstr, "album": obj.data[i].value}}, parseListTitles);
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
|
|
|
|
var cards_length=cards.length - 1;
|
|
|
|
|
for (var i = cards_length; i >= nrItems; i --) {
|
|
|
|
|
cards[i].remove();
|
|
|
|
|
}
|
|
|
|
|
setPagination(obj.totalEntities);
|
2018-07-05 21:56:42 +00:00
|
|
|
|
document.getElementById('BrowseDatabaseAlbumCards').classList.remove('opacity05');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseListTitles(obj) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
if (app.current.app !== 'Browse' && app.current.tab !== 'Database' && app.current.view !== 'Album')
|
|
|
|
|
return;
|
2018-06-25 22:41:44 +00:00
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var id = genId(obj.album);
|
|
|
|
|
var card = document.getElementById('card' + id)
|
|
|
|
|
var tbody = card.getElementsByTagName('tbody')[0];
|
|
|
|
|
var img = card.getElementsByTagName('img')[0];
|
2018-07-04 22:49:34 +00:00
|
|
|
|
var imga = img.parentNode;
|
2018-06-28 22:51:24 +00:00
|
|
|
|
img.setAttribute('src', obj.cover);
|
2018-07-05 19:34:16 +00:00
|
|
|
|
imga.setAttribute('data-uri', encodeURI(obj.data[0].uri.replace(/\/[^\/]+$/,'')));
|
|
|
|
|
imga.setAttribute('data-name', obj.album);
|
2018-07-04 22:49:34 +00:00
|
|
|
|
imga.setAttribute('data-type', 'dir');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
|
2018-07-01 22:49:47 +00:00
|
|
|
|
var titleList = '';
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var nrItems = obj.data.length;
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < nrItems; i++) {
|
2018-07-01 22:49:47 +00:00
|
|
|
|
titleList += '<tr data-type="song" data-name="' + obj.data[i].title + '" data-uri="' + encodeURI(obj.data[i].uri) + '">' +
|
|
|
|
|
'<td>' + obj.data[i].track + '</td><td>' + obj.data[i].title + '</td>' +
|
2018-07-05 21:56:42 +00:00
|
|
|
|
'<td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>' +
|
2018-07-01 22:49:47 +00:00
|
|
|
|
'</tr>';
|
2018-06-28 22:51:24 +00:00
|
|
|
|
}
|
2018-07-01 22:49:47 +00:00
|
|
|
|
tbody.innerHTML = titleList;
|
2018-06-25 22:41:44 +00:00
|
|
|
|
|
2018-07-04 22:49:34 +00:00
|
|
|
|
imga.addEventListener('click', function(event) {
|
|
|
|
|
event.preventDefault();
|
2018-06-28 22:51:24 +00:00
|
|
|
|
showMenu(this);
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
tbody.parentNode.addEventListener('click', function(event) {
|
|
|
|
|
if (event.target.nodeName == 'TD') {
|
|
|
|
|
appendQueue('song', decodeURI(event.target.parentNode.getAttribute('data-uri')), event.target.parentNode.getAttribute('data-name'));
|
|
|
|
|
}
|
|
|
|
|
else if (event.target.nodeName == 'A') {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
showMenu(event.target);
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
2013-11-04 17:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-28 22:05:56 +00:00
|
|
|
|
function setPagination(number) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var totalPages = Math.ceil(number / settings.max_elements_per_page);
|
|
|
|
|
var cat = app.current.app + (app.current.tab == undefined ? '': app.current.tab);
|
|
|
|
|
if (totalPages == 0)
|
|
|
|
|
totalPages = 1;
|
|
|
|
|
var p = ['PaginationTop', 'PaginationBottom'];
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < 2; i++) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
document.getElementById(cat + p[i] + 'Page').innerText = (app.current.page / settings.max_elements_per_page + 1) + ' / ' + totalPages;
|
|
|
|
|
if (totalPages > 1) {
|
|
|
|
|
document.getElementById(cat + p[i] + 'Page').removeAttribute('disabled');
|
|
|
|
|
var pl = '';
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var j = 0; j < totalPages; j++) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
pl += '<button data-page="' + (j * settings.max_elements_per_page) + '" type="button" class="mr-1 mb-1 btn-sm btn btn-secondary">' +
|
|
|
|
|
( j + 1) + '</button>';
|
|
|
|
|
}
|
|
|
|
|
document.getElementById(cat + p[i] + 'Pages').innerHTML = pl;
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById(cat + p[i] + 'Page').setAttribute('disabled', 'disabled');
|
2018-05-28 22:05:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
if (number > app.current.page + settings.max_elements_per_page) {
|
|
|
|
|
document.getElementById(cat + p[i] + 'Next').removeAttribute('disabled');
|
|
|
|
|
document.getElementById(cat + 'ButtonsBottom').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById(cat + p[i] + 'Next').setAttribute('disabled', 'disabled');
|
|
|
|
|
document.getElementById(cat + 'ButtonsBottom').classList.add('hide');
|
|
|
|
|
}
|
2018-05-28 22:05:56 +00:00
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
if (app.current.page > 0) {
|
|
|
|
|
document.getElementById(cat + p[i] + 'Prev').removeAttribute('disabled');
|
|
|
|
|
document.getElementById(cat + 'ButtonsBottom').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById(cat + p[i] + 'Prev').setAttribute('disabled', 'disabled');
|
|
|
|
|
}
|
2018-05-28 22:05:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
function appendQueue(type, uri, name) {
|
2018-06-25 22:41:44 +00:00
|
|
|
|
switch(type) {
|
|
|
|
|
case 'song':
|
2018-06-28 22:51:24 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_ADD_TRACK", "data": {"uri": uri}});
|
2018-07-09 17:28:28 +00:00
|
|
|
|
showNotification('"' + name + '" added', '', '', 'success');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
break;
|
2018-07-05 20:04:25 +00:00
|
|
|
|
case 'dir':
|
|
|
|
|
sendAPI({"cmd": "MPD_API_ADD_TRACK", "data": {"uri": uri}});
|
2018-07-09 17:28:28 +00:00
|
|
|
|
showNotification('"' + name + '" added', '', '', 'success');
|
2018-07-05 20:04:25 +00:00
|
|
|
|
break;
|
2018-06-25 22:41:44 +00:00
|
|
|
|
case 'plist':
|
2018-06-28 22:51:24 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_ADD_PLAYLIST", "data": {"plist": uri}});
|
2018-07-09 17:28:28 +00:00
|
|
|
|
showNotification('"' + name + '" added', '', '', 'success');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-24 21:39:37 +00:00
|
|
|
|
|
2018-07-05 19:34:16 +00:00
|
|
|
|
function appendAfterQueue(type, uri, to, name) {
|
|
|
|
|
switch(type) {
|
|
|
|
|
case 'song':
|
|
|
|
|
sendAPI({"cmd": "MPD_API_ADD_TRACK_AFTER", "data": {"uri": uri, "to": to}});
|
2018-07-19 16:33:53 +00:00
|
|
|
|
showNotification('"' + name + '" added to pos ' + to, '', '', 'success');
|
2018-07-05 20:04:25 +00:00
|
|
|
|
break;
|
2018-07-05 19:34:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function replaceQueue(type, uri, name) {
|
|
|
|
|
switch(type) {
|
|
|
|
|
case 'song':
|
|
|
|
|
sendAPI({"cmd": "MPD_API_REPLACE_TRACK", "data": {"uri": uri}});
|
2018-07-09 17:28:28 +00:00
|
|
|
|
showNotification('"' + name + '" replaced', '', '', 'success');
|
2018-07-05 19:34:16 +00:00
|
|
|
|
break;
|
2018-07-05 20:04:25 +00:00
|
|
|
|
case 'dir':
|
|
|
|
|
sendAPI({"cmd": "MPD_API_REPLACE_TRACK", "data": {"uri": uri}});
|
2018-07-09 17:28:28 +00:00
|
|
|
|
showNotification('"' + name + '" replaced', '', '', 'success');
|
2018-07-05 20:04:25 +00:00
|
|
|
|
break;
|
2018-07-05 19:34:16 +00:00
|
|
|
|
case 'plist':
|
|
|
|
|
sendAPI({"cmd": "MPD_API_REPLACE_PLAYLIST", "data": {"plist": uri}});
|
2018-07-09 17:28:28 +00:00
|
|
|
|
showNotification('"' + name + '" replaced', '', '', 'success');
|
2018-07-05 19:34:16 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-09 17:28:28 +00:00
|
|
|
|
function songDetails(uri) {
|
|
|
|
|
sendAPI({"cmd": "MPD_API_GET_SONGDETAILS", "data": {"uri": uri}}, parseSongDetails);
|
|
|
|
|
modalSongDetails.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function parseSongDetails(obj) {
|
|
|
|
|
var modal = document.getElementById('modalSongDetails');
|
2018-07-09 17:50:21 +00:00
|
|
|
|
modal.querySelector('.album-cover').style.backgroundImage = 'url("' + obj.data.cover + '")';
|
2018-07-09 17:28:28 +00:00
|
|
|
|
modal.getElementsByTagName('h1')[0].innerText = obj.data.title;
|
|
|
|
|
var tr = modal.getElementsByTagName('tr');
|
|
|
|
|
var trLen = tr.length;
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < trLen; i++) {
|
2018-07-09 17:28:28 +00:00
|
|
|
|
var key = tr[i].getAttribute('data-name');
|
|
|
|
|
var value = obj.data[key];
|
|
|
|
|
if (key == 'duration') {
|
|
|
|
|
var minutes = Math.floor(value / 60);
|
|
|
|
|
var seconds = value - minutes * 60;
|
|
|
|
|
value = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
|
|
|
|
|
}
|
|
|
|
|
else if (key == 'uri') {
|
|
|
|
|
value = '<a class="text-success" href="/library/' + value + '">' + value + '</a>';
|
|
|
|
|
}
|
|
|
|
|
tr[i].getElementsByTagName('td')[1].innerHTML = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-25 22:41:44 +00:00
|
|
|
|
function showMenu(el) {
|
2018-07-04 22:49:34 +00:00
|
|
|
|
var type = el.getAttribute('data-type');
|
2018-07-05 19:34:16 +00:00
|
|
|
|
var uri = decodeURI(el.getAttribute('data-uri'));
|
|
|
|
|
var name = el.getAttribute('data-name');
|
2018-07-19 16:33:53 +00:00
|
|
|
|
var nextsongpos = 0;
|
2018-07-04 22:49:34 +00:00
|
|
|
|
if (type == null || uri == null) {
|
|
|
|
|
type = el.parentNode.parentNode.getAttribute('data-type');
|
2018-07-05 19:34:16 +00:00
|
|
|
|
uri = decodeURI(el.parentNode.parentNode.getAttribute('data-uri'));
|
|
|
|
|
name = el.parentNode.parentNode.getAttribute('data-name');
|
2018-07-04 22:49:34 +00:00
|
|
|
|
}
|
2018-07-19 16:33:53 +00:00
|
|
|
|
|
|
|
|
|
if (last_state)
|
|
|
|
|
nextsongpos = last_state.data.nextsongpos;
|
2018-07-04 22:49:34 +00:00
|
|
|
|
|
|
|
|
|
var menu = '';
|
2018-06-25 22:41:44 +00:00
|
|
|
|
if ((app.current.app == 'Browse' && app.current.tab == 'Filesystem') || app.current.app == 'Search' ||
|
|
|
|
|
(app.current.app == 'Browse' && app.current.tab == 'Database' && app.current.view == 'Album')) {
|
2018-07-05 19:34:16 +00:00
|
|
|
|
menu += '<a class="dropdown-item" href="#" data-href="{\'cmd\': \'appendQueue\', \'options\': [\'' + type + '\',\'' +
|
|
|
|
|
uri + '\',\'' + name + '\']}">Append to queue</a>' +
|
2018-07-18 21:47:37 +00:00
|
|
|
|
( type == 'song' ? '<a class="dropdown-item" href="#" data-href="{\'cmd\': \'appendAfterQueue\', \'options\': [\'' + type + '\',\'' +
|
2018-07-19 16:33:53 +00:00
|
|
|
|
uri + '\',' + nextsongpos + ',\'' + name + '\']}">Add after current playing song</a>' : '') +
|
2018-07-05 19:34:16 +00:00
|
|
|
|
'<a class="dropdown-item" href="#" data-href="{\'cmd\': \'replaceQueue\', \'options\': [\'' + type + '\',\'' +
|
2018-07-09 17:28:28 +00:00
|
|
|
|
uri + '\',\'' + name + '\']}">Replace queue</a>' +
|
|
|
|
|
// ( type != 'plist' ? '<div class="dropdown-divider"></div><a class="dropdown-item" href="#">Add to playlist</a>' : '') +
|
2018-06-25 22:41:44 +00:00
|
|
|
|
( type != 'dir' ? '<div class="dropdown-divider"></div>' : '') +
|
2018-07-09 17:28:28 +00:00
|
|
|
|
( type == 'song' ? '<a class="dropdown-item" data-href="{\'cmd\': \'songDetails\', \'options\': [\'' + uri + '\']}" href="#">Songdetails</a>' : '');
|
|
|
|
|
// ( type == 'plist' ? '<a class="dropdown-item" href="#">Show playlist</a>' : '');
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
2018-07-04 22:49:34 +00:00
|
|
|
|
else if (app.current.app == 'Browse' && app.current.tab == 'Playlists') {
|
2018-07-05 19:34:16 +00:00
|
|
|
|
menu += '<a class="dropdown-item" href="#" data-href="{\'cmd\': \'appendQueue\', \'options\': [\'' + type + '\',\'' +
|
|
|
|
|
uri + '\',\'' + name + '\']}">Append to queue</a>' +
|
|
|
|
|
'<a class="dropdown-item" href="#" data-href="{\'cmd\': \'replaceQueue\', \'options\': [\'' + type + '\',\'' +
|
|
|
|
|
uri + '\',\'' + name + '\']}">Replace queue</a>' +
|
2018-06-25 22:41:44 +00:00
|
|
|
|
'<div class="dropdown-divider"></div>' +
|
2018-07-09 19:20:09 +00:00
|
|
|
|
// '<a class="dropdown-item" href="#">Show playlist</a>' +
|
|
|
|
|
// '<a class="dropdown-item" href="#">Rename playlist</a>' +
|
2018-07-05 19:34:16 +00:00
|
|
|
|
'<a class="dropdown-item" href="#" data-href="{\'cmd\': \'delPlaylist\', \'options\': [\'' +
|
|
|
|
|
uri + '\',\'' + name + '\']}">Delete playlist</a>';
|
2018-06-25 22:41:44 +00:00
|
|
|
|
}
|
2018-06-26 22:46:29 +00:00
|
|
|
|
else if (app.current.app == 'Queue') {
|
2018-07-05 19:34:16 +00:00
|
|
|
|
menu += '<a class="dropdown-item" href="#" data-href="{\'cmd\': \'delQueueSong\', \'options\': [\'single\',' +
|
|
|
|
|
el.parentNode.parentNode.getAttribute('data-trackid') + ']}">Remove</a>' +
|
|
|
|
|
'<a class="dropdown-item" href="#" data-href="{\'cmd\': \'delQueueSong\', \'options\': [\'range\',0,'+
|
|
|
|
|
el.parentNode.parentNode.getAttribute('data-songpos') + ']}">Remove all upwards</a>' +
|
|
|
|
|
'<a class="dropdown-item" href="#" data-href="{\'cmd\': \'delQueueSong\', \'options\': [\'range\',' +
|
2018-07-09 17:28:28 +00:00
|
|
|
|
(parseInt(el.parentNode.parentNode.getAttribute('data-songpos'))-1) + ',-1]}">Remove all downwards</a>' +
|
|
|
|
|
'<div class="dropdown-divider"></div>' +
|
2018-07-19 16:33:53 +00:00
|
|
|
|
( uri.indexOf('http') == -1 ? '<a class="dropdown-item" data-href="{\'cmd\': \'songDetails\', \'options\': [\'' + uri + '\']}" href="#">Songdetails</a>' : '');
|
2018-06-26 22:46:29 +00:00
|
|
|
|
}
|
2018-07-04 22:49:34 +00:00
|
|
|
|
if (el.Popover == undefined) {
|
|
|
|
|
new Popover(el, { trigger: 'click', template: '<div class="popover" role="tooltip">' +
|
|
|
|
|
'<div class="arrow"></div>' +
|
|
|
|
|
'<div class="popover-content">' + menu + '</div>' +
|
|
|
|
|
'</div>'});
|
|
|
|
|
var popoverInit = el.Popover;
|
2018-07-05 19:34:16 +00:00
|
|
|
|
el.addEventListener('shown.bs.popover', function(event) {
|
|
|
|
|
document.querySelector('.popover-content').addEventListener('click', function(event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
var cmd = JSON.parse(event.target.getAttribute('data-href').replace(/\'/g,'"'));
|
|
|
|
|
if (typeof window[cmd.cmd] === 'function') {
|
|
|
|
|
switch(cmd.cmd) {
|
|
|
|
|
case 'sendAPI':
|
|
|
|
|
sendAPI(... cmd.options);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
window[cmd.cmd](... cmd.options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
}, false);
|
2018-07-04 22:49:34 +00:00
|
|
|
|
popoverInit.show();
|
|
|
|
|
}
|
2018-06-24 21:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-19 22:43:36 +00:00
|
|
|
|
function sendAPI(request, callback) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var ajaxRequest=new XMLHttpRequest();
|
|
|
|
|
ajaxRequest.open('POST', '/api', true);
|
|
|
|
|
ajaxRequest.setRequestHeader('Content-type', 'application/json');
|
|
|
|
|
ajaxRequest.onreadystatechange = function() {
|
2018-07-18 22:29:19 +00:00
|
|
|
|
if (ajaxRequest.readyState == 4) {
|
|
|
|
|
if (ajaxRequest.responseText != '') {
|
|
|
|
|
var obj = JSON.parse(ajaxRequest.responseText);
|
|
|
|
|
if (obj.type == 'error') {
|
|
|
|
|
showNotification('Error', obj.data, obj.data, 'error');
|
|
|
|
|
console.log('Error: ' + obj.data);
|
|
|
|
|
}
|
|
|
|
|
else if (obj.type == 'result' && obj.data != 'ok')
|
|
|
|
|
showNotification(obj.data, '', '', 'success');
|
|
|
|
|
else if (callback != undefined && typeof(callback) == 'function')
|
|
|
|
|
callback(obj);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.log('Empty response for request: ' + JSON.stringify(request));
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-28 22:51:24 +00:00
|
|
|
|
};
|
|
|
|
|
ajaxRequest.send(JSON.stringify(request));
|
2018-06-14 19:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 19:40:27 +00:00
|
|
|
|
function openLocalPlayer() {
|
|
|
|
|
window.open('/player.html#' + settings.mpdstream, 'LocalPlayer');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateDB() {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_UPDATE_DB"});
|
2018-07-18 22:29:19 +00:00
|
|
|
|
// showNotification('Updating MPD Database...', '', '', 'success');
|
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-28 22:51:24 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_SET_PLAY"});
|
2014-01-17 15:26:26 +00:00
|
|
|
|
else
|
2018-06-28 22:51:24 +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-28 22:51:24 +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-28 22:51:24 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_SET_PREV"});
|
2018-06-18 21:26:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function clickNext() {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_SET_NEXT"});
|
2014-05-24 16:23:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-05 19:34:16 +00:00
|
|
|
|
function delQueueSong(mode, start, end) {
|
|
|
|
|
if (mode == 'range')
|
|
|
|
|
sendAPI({"cmd": "MPD_API_RM_RANGE", "data": {"start": start, "end": end}});
|
|
|
|
|
else if (mode == 'single')
|
|
|
|
|
sendAPI({"cmd": "MPD_API_RM_TRACK", "data": { "track": start}});
|
2017-04-08 09:25:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-05 19:34:16 +00:00
|
|
|
|
function delPlaylist(plist, name) {
|
|
|
|
|
sendAPI({"cmd": "MPD_API_RM_PLAYLIST", "data": {"plist": plist}});
|
|
|
|
|
document.getElementById('BrowsePlaylistsList').querySelector('tr[data-uri=' + encodeURI(plist) + ']').remove();
|
2018-05-29 20:12:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-28 18:48:43 +00:00
|
|
|
|
function confirmSettings() {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var formOK = true;
|
|
|
|
|
var inputCrossfade = document.getElementById('inputCrossfade');
|
|
|
|
|
if (!inputCrossfade.getAttribute('disabled')) {
|
2018-07-05 21:56:42 +00:00
|
|
|
|
var value = parseInt(inputCrossfade.value);
|
|
|
|
|
if (!isNaN(value)) {
|
|
|
|
|
inputCrossfade.value = value;
|
|
|
|
|
} else {
|
|
|
|
|
inputCrossfade.classList.add('is-invalid');
|
|
|
|
|
formOK = false;
|
|
|
|
|
}
|
2018-05-28 18:48:43 +00:00
|
|
|
|
}
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var inputMixrampdb = document.getElementById('inputMixrampdb');
|
|
|
|
|
if (!inputMixrampdb.getAttribute('disabled')) {
|
2018-07-05 21:56:42 +00:00
|
|
|
|
var value = parseFloat(inputMixrampdb.value);
|
|
|
|
|
if (!isNaN(value)) {
|
|
|
|
|
inputMixrampdb.value = value;
|
|
|
|
|
} else {
|
|
|
|
|
inputMixrampdb.classList.add('is-invalid');
|
|
|
|
|
formOK = false;
|
|
|
|
|
}
|
2018-05-31 20:23:57 +00:00
|
|
|
|
}
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var inputMixrampdelay = document.getElementById('inputMixrampdelay');
|
|
|
|
|
if (!inputMixrampdelay.getAttribute('disabled')) {
|
2018-07-05 21:56:42 +00:00
|
|
|
|
if (inputMixrampdelay.value == 'nan') inputMixrampdelay.value = '-1';
|
|
|
|
|
var value = parseFloat(inputMixrampdelay.value);
|
|
|
|
|
if (!isNaN(value)) {
|
|
|
|
|
inputMixrampdelay.value = value;
|
|
|
|
|
} else {
|
|
|
|
|
inputMixrampdelay.classList.add('is-invalid');
|
|
|
|
|
formOK = false;
|
|
|
|
|
}
|
2018-05-31 20:23:57 +00:00
|
|
|
|
}
|
|
|
|
|
if (formOK == true) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var selectReplaygain = document.getElementById('selectReplaygain');
|
|
|
|
|
sendAPI({"cmd":"MPD_API_SET_SETTINGS", "data": {
|
|
|
|
|
"consume": (document.getElementById('btnConsume').classList.contains('active') ? 1 : 0),
|
|
|
|
|
"random": (document.getElementById('btnRandom').classList.contains('active') ? 1 : 0),
|
|
|
|
|
"single": (document.getElementById('btnSingle').classList.contains('active') ? 1 : 0),
|
|
|
|
|
"repeat": (document.getElementById('btnRepeat').classList.contains('active') ? 1 : 0),
|
|
|
|
|
"replaygain": selectReplaygain.options[selectReplaygain.selectedIndex].value,
|
|
|
|
|
"crossfade": document.getElementById('inputCrossfade').value,
|
|
|
|
|
"mixrampdb": document.getElementById('inputMixrampdb').value,
|
|
|
|
|
"mixrampdelay": document.getElementById('inputMixrampdelay').vaue,
|
|
|
|
|
"notificationWeb": (document.getElementById('btnnotifyWeb').classList.contains('active') ? 1 : 0),
|
|
|
|
|
"notificationPage": (document.getElementById('btnnotifyPage').classList.contains('active') ? 1 : 0)
|
|
|
|
|
}}, getSettings);
|
2018-07-02 22:02:02 +00:00
|
|
|
|
modalSettings.hide();
|
2018-06-24 17:57:47 +00:00
|
|
|
|
} else {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
document.getElementById('settingsFrm').classList.add('was-validated');
|
2018-05-28 18:48:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 19:40:27 +00:00
|
|
|
|
function addAllFromBrowse() {
|
|
|
|
|
sendAPI({"cmd": "MPD_API_ADD_TRACK", "data": { "uri": app.current.search}});
|
2018-07-05 19:34:16 +00:00
|
|
|
|
showNotification('Added all songs', '', '', 'success');
|
2018-07-02 19:40:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-07-05 20:04:25 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SEARCH_ADD", "data":{"filter": app.current.filter, "searchstr": app.current.search}});
|
2018-07-05 21:56:42 +00:00
|
|
|
|
showNotification('Added '+ parseInt(document.getElementById('panel-heading-search').innerText) +' songs from search', '', '', 'success');
|
2018-05-31 23:05:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-09 15:36:45 +00:00
|
|
|
|
function scrollTo(pos) {
|
|
|
|
|
document.body.scrollTop = pos; // For Safari
|
|
|
|
|
document.documentElement.scrollTop = pos; // For Chrome, Firefox, IE and Opera
|
2018-05-27 20:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
function gotoPage(x) {
|
2018-05-27 20:21:18 +00:00
|
|
|
|
switch (x) {
|
2018-06-26 22:46:29 +00:00
|
|
|
|
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;
|
2018-06-26 22:46:29 +00:00
|
|
|
|
case 'prev':
|
2018-06-21 16:57:40 +00:00
|
|
|
|
app.current.page -= settings.max_elements_per_page;
|
2018-06-26 21:12:23 +00:00
|
|
|
|
if (app.current.page <= 0)
|
2018-06-26 22:46:29 +00:00
|
|
|
|
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-07-02 19:40:27 +00:00
|
|
|
|
appGoto(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
|
|
|
|
}
|
|
|
|
|
|
2015-03-06 11:40:14 +00:00
|
|
|
|
function addStream() {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var streamUrl = document.getElementById('streamurl');
|
|
|
|
|
if (streamUrl.value != '')
|
2018-07-05 21:56:42 +00:00
|
|
|
|
sendAPI({"cmd": "MPD_API_ADD_TRACK", "data": {"uri": streamUrl.value}});
|
2018-06-28 22:51:24 +00:00
|
|
|
|
streamUrl.value = '';
|
2018-07-02 22:02:02 +00:00
|
|
|
|
modalAddstream.hide();
|
2015-03-06 11:40:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 17:24:52 +00:00
|
|
|
|
function saveQueue() {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var plName = document.getElementById('playlistname');
|
|
|
|
|
if (plName.value != '')
|
2018-07-05 21:56:42 +00:00
|
|
|
|
sendAPI({"cmd":"MPD_API_SAVE_QUEUE", "data": {"plist": plName.value}});
|
2018-06-28 22:51:24 +00:00
|
|
|
|
plName.value = '';
|
2018-07-02 22:02:02 +00:00
|
|
|
|
modalSavequeue.hide();
|
2015-09-02 17:24:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-07-02 19:59:56 +00:00
|
|
|
|
var alertBox;
|
|
|
|
|
if (!document.getElementById('alertBox')) {
|
|
|
|
|
alertBox = document.createElement('div');
|
2018-07-09 17:28:28 +00:00
|
|
|
|
alertBox.setAttribute('id', 'alertBox');
|
2018-07-10 23:12:36 +00:00
|
|
|
|
alertBox.addEventListener('click', function() {
|
|
|
|
|
hideNotification();
|
|
|
|
|
}, false);
|
2018-07-02 19:59:56 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
alertBox = document.getElementById('alertBox');
|
|
|
|
|
}
|
2018-07-18 22:50:38 +00:00
|
|
|
|
alertBox.classList.remove('alert-success', 'alert-error');
|
2018-07-02 19:59:56 +00:00
|
|
|
|
alertBox.classList.add('alert','alert-' + notificationType);
|
2018-07-18 22:29:19 +00:00
|
|
|
|
alertBox.innerHTML = '<div><strong>' + notificationTitle + '</strong><br/>' + notificationHtml + '</div>';
|
2018-07-02 19:59:56 +00:00
|
|
|
|
document.getElementsByTagName('main')[0].append(alertBox);
|
|
|
|
|
document.getElementById('alertBox').classList.add('alertBoxActive');
|
2018-07-05 19:34:16 +00:00
|
|
|
|
if (alertTimeout)
|
|
|
|
|
clearTimeout(alertTimeout);
|
|
|
|
|
alertTimeout = setTimeout(function() {
|
2018-07-10 23:12:36 +00:00
|
|
|
|
hideNotification();
|
2018-07-01 22:49:47 +00:00
|
|
|
|
}, 3000);
|
2018-05-22 23:07:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-10 23:12:36 +00:00
|
|
|
|
function hideNotification() {
|
|
|
|
|
if (document.getElementById('alertBox')) {
|
|
|
|
|
document.getElementById('alertBox').classList.remove('alertBoxActive');
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
document.getElementById('alertBox').remove();
|
|
|
|
|
}, 600);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-07-18 21:47:37 +00:00
|
|
|
|
if (obj.type == 'error')
|
|
|
|
|
return;
|
2018-06-26 22:46:29 +00:00
|
|
|
|
var cur_song = obj.data.title + obj.data.artist + obj.data.album + obj.data.uri + obj.data.currentsongid;
|
|
|
|
|
if (last_song == cur_song)
|
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-07-05 19:34:16 +00:00
|
|
|
|
document.getElementById('album-cover').style.backgroundImage = 'url("' + obj.data.cover + '")';
|
2018-06-22 00:01:15 +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 + ' - ';
|
2018-06-26 22:46:29 +00:00
|
|
|
|
document.getElementById('artist').innerText = obj.data.artist;
|
2018-05-23 23:42:20 +00:00
|
|
|
|
} else {
|
2018-06-26 22:46:29 +00:00
|
|
|
|
document.getElementById('artist').innerText = '';
|
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;
|
2018-06-26 22:46:29 +00:00
|
|
|
|
document.getElementById('album').innerText = obj.data.album;
|
2018-05-23 23:42:20 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2018-06-26 22:46:29 +00:00
|
|
|
|
document.getElementById('album').innerText = '';
|
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;
|
2018-06-26 22:46:29 +00:00
|
|
|
|
document.getElementById('currenttrack').innerText = obj.data.title;
|
2018-05-23 23:42:20 +00:00
|
|
|
|
} else {
|
2018-06-26 22:46:29 +00:00
|
|
|
|
document.getElementById('currenttrack').innerText = '';
|
2018-05-22 23:07:34 +00:00
|
|
|
|
}
|
|
|
|
|
document.title = pageTitle;
|
2018-07-05 19:34:16 +00:00
|
|
|
|
//Update Artist in queue view for http streams
|
|
|
|
|
var playingTr = document.getElementById('queueTrackId' + obj.data.currentsongid);
|
|
|
|
|
if (playingTr)
|
|
|
|
|
playingTr.getElementsByTagName('td')[1].innerText = obj.data.title;
|
|
|
|
|
|
2018-07-09 17:28:28 +00:00
|
|
|
|
showNotification(obj.data.title, textNotification, htmlNotification, 'success');
|
2018-06-26 22:46:29 +00:00
|
|
|
|
last_song = cur_song;
|
2014-01-17 17:34:22 +00:00
|
|
|
|
}
|
2015-09-13 08:38:18 +00:00
|
|
|
|
|
2018-06-04 18:31:05 +00:00
|
|
|
|
function doSetFilterLetter(x) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var af = document.getElementById(x + 'Letters').querySelector('.active');
|
|
|
|
|
if (af)
|
|
|
|
|
af.classList.remove('active');
|
|
|
|
|
var filter = app.current.filter;
|
|
|
|
|
if (filter == '0')
|
|
|
|
|
filter = '#';
|
|
|
|
|
|
|
|
|
|
document.getElementById(x).innerText = 'Filter' + (filter != '-' ? ': '+filter : '');
|
|
|
|
|
|
|
|
|
|
if (filter != '-') {
|
|
|
|
|
var btns = document.getElementById(x + 'Letters').getElementsByTagName('button');
|
|
|
|
|
var btnsLen = btns.length;
|
2018-07-15 23:56:58 +00:00
|
|
|
|
for (var i = 0; i < btnsLen; i++) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
if (btns[i].innerText == filter) {
|
|
|
|
|
btns[i].classList.add('active');
|
|
|
|
|
break;
|
2018-06-04 18:31:05 +00:00
|
|
|
|
}
|
2018-06-28 22:51:24 +00:00
|
|
|
|
}
|
2018-06-04 18:31:05 +00:00
|
|
|
|
}
|
2016-06-08 21:20:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
function addFilterLetter(x) {
|
|
|
|
|
var filter = '<button class="mr-1 mb-1 btn btn-sm btn-secondary material-icons material-icons-small">delete</button>' +
|
|
|
|
|
'<button class="mr-1 mb-1 btn btn-sm btn-secondary">#</button>';
|
2018-07-19 18:26:15 +00:00
|
|
|
|
for (var i = 65; i <= 90; i++) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
filter += '<button class="mr-1 mb-1 btn-sm btn btn-secondary">' + String.fromCharCode(i) + '</button>';
|
2016-06-08 21:20:27 +00:00
|
|
|
|
}
|
2018-06-28 22:51:24 +00:00
|
|
|
|
var letters = document.getElementById(x);
|
|
|
|
|
letters.innerHTML = filter;
|
|
|
|
|
|
|
|
|
|
letters.addEventListener('click', function(event) {
|
|
|
|
|
switch (event.target.innerText) {
|
|
|
|
|
case 'delete':
|
|
|
|
|
filter = '-';
|
|
|
|
|
break;
|
|
|
|
|
case '#':
|
|
|
|
|
filter = '0';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
filter = event.target.innerText;
|
|
|
|
|
}
|
2018-07-02 19:40:27 +00:00
|
|
|
|
appGoto(app.current.app, app.current.tab, app.current.view, '0/' + filter + '/' + app.current.search);
|
2018-06-28 22:51:24 +00:00
|
|
|
|
}, false);
|
2016-06-08 21:20:27 +00:00
|
|
|
|
}
|
2018-05-21 23:36:05 +00:00
|
|
|
|
|
2018-06-28 22:51:24 +00:00
|
|
|
|
function chVolume(increment) {
|
|
|
|
|
var newValue = parseInt(domCache.volumeBar.value) + increment;
|
|
|
|
|
if (newValue < 0)
|
|
|
|
|
newValue = 0;
|
|
|
|
|
else if (newValue > 100)
|
|
|
|
|
newValue=100;
|
|
|
|
|
domCache.volumeBar.value = newValue;
|
|
|
|
|
sendAPI({"cmd": "MPD_API_SET_VOLUME", "data": {"volume": newValue}});
|
2018-05-27 21:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function beautifyDuration(x) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
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) {
|
2018-06-28 22:51:24 +00:00
|
|
|
|
return 'id'+x.replace(/[^\w]/g,'');
|
2018-06-29 06:52:32 +00:00
|
|
|
|
}
|
2018-07-02 19:59:56 +00:00
|
|
|
|
|
|
|
|
|
//Init app
|
2018-07-05 21:56:42 +00:00
|
|
|
|
appInit();
|