1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-06-19 19:39:57 +00:00
ympd/htdocs/js/mympd.js

2322 lines
101 KiB
JavaScript
Raw Normal View History

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>
This project's homepage is: https://github.com/jcorporation/mympd
2018-05-14 23:13:43 +00:00
myMPD ist fork of:
ympd
(c) 2013-2014 Andrew Karpow <andy@ndyk.de>
This project's homepage is: https://www.ympd.org
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;
var lastSong = '';
var lastState;
var currentSong = new Object();
var playstate = '';
var settings = {};
2018-07-05 19:34:16 +00:00
var alertTimeout;
var progressTimer;
var deferredPrompt;
var dragEl;
var playlistEl;
2013-11-04 17:18:38 +00:00
var app = {};
app.apps = { "Playback": { "state": "0/-/", "scrollPos": 0 },
"Queue": { "state": "0/any/", "scrollPos": 0 },
2018-06-10 21:21:48 +00:00
"Browse": {
"active": "Database",
"tabs": { "Filesystem": { "state": "0/-/", "scrollPos": 0 },
2018-07-22 19:00:26 +00:00
"Playlists": {
"active": "All",
"views": { "All": { "state": "0/-/", "scrollPos": 0 },
"Detail": { "state": "0/-/", "scrollPos": 0 }
}
},
2018-06-10 21:21:48 +00:00
"Database": {
"active": "AlbumArtist",
"views": { "AlbumArtist": { "state": "0/-/", "scrollPos": 0 },
"Genre": { "state": "0/-/", "scrollPos": 0 },
"Artist": { "state": "0/-/", "scrollPos": 0 },
"Composer": { "state": "0/-/", "scrollPos": 0 },
"Performer": { "state": "0/-/", "scrollPos": 0 },
"Date": { "state": "0/-/", "scrollPos": 0 },
"Album": { "state": "0/-/", "scrollPos": 0 },
2018-06-25 22:41:44 +00:00
}
}
}
},
"Search": { "state": "0/any/", "scrollPos": 0 }
};
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-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');
domCache.volumePrct = document.getElementById('volumePrct');
domCache.volumeControl = document.getElementById('volumeControl');
domCache.volumeIcon = document.getElementById('volumeIcon');
2018-08-21 22:02:22 +00:00
domCache.btnsPlay = document.getElementsByClassName('btnPlay');
domCache.btnsPlayLen = domCache.btnsPlay.length;
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');
domCache.btnAdd = document.getElementById('nav-add2homescreen');
domCache.currentTrack = document.getElementById('currentTrack');
2018-08-21 22:02:22 +00:00
domCache.currentArtist = document.getElementById('currentArtist');
domCache.currentAlbum = document.getElementById('currentAlbum');
domCache.currentCover = document.getElementById('currentCover');
domCache.btnVoteUp = document.getElementById('btnVoteUp');
domCache.btnVoteDown = document.getElementById('btnVoteDown');
2018-06-27 23:19:09 +00:00
2018-09-18 23:10:53 +00:00
var modalConnectionError = new Modal(document.getElementById('modalConnectionError'), { backdrop: 'static', keyboard: false});
var modalSettings = new Modal(document.getElementById('modalSettings'));
var modalSavequeue = new Modal(document.getElementById('modalSaveQueue'));
2018-07-09 17:28:28 +00:00
var modalSongDetails = new Modal(document.getElementById('modalSongDetails'));
2018-07-22 19:00:26 +00:00
var modalAddToPlaylist = new Modal(document.getElementById('modalAddToPlaylist'));
var modalRenamePlaylist = new Modal(document.getElementById('modalRenamePlaylist'));
var modalUpdateDB = new Modal(document.getElementById('modalUpdateDB'));
var modalSaveSmartPlaylist = new Modal(document.getElementById('modalSaveSmartPlaylist'));
//var mainMenu = new Dropdown(document.getElementById('mainMenu'));
//var volumeMenu = new Dropdown(document.getElementById('volumeIcon'));
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
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');
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
}
scrollTo(scrollPos);
2018-06-10 21:15:33 +00:00
}
2018-07-22 19:00:26 +00:00
var list = document.getElementById(app.current.app +
(app.current.tab == undefined ? '' : app.current.tab) +
(app.current.view == undefined ? '' : app.current.view) + 'List');
if (list)
list.classList.add('opacity05');
}
function appGoto(a,t,v,s) {
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;
}
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];
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;
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;
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 {
appGoto('Playback');
2018-06-25 22:41:44 +00:00
return;
2018-06-10 21:15:33 +00:00
}
appPrepare(app.current.scrollPos);
2018-06-10 21:15:33 +00:00
if (app.current.app == 'Playback') {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_CURRENT_SONG"}, songChange);
}
2018-06-10 21:15:33 +00:00
else if (app.current.app == 'Queue' ) {
selectTag('searchqueuetag', 'searchqueuetagdesc', app.current.filter);
getQueue();
}
2018-07-22 19:00:26 +00:00
else if (app.current.app == 'Browse' && app.current.tab == 'Playlists' && app.current.view == 'All') {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYLIST_LIST", "data": {"offset": app.current.page, "filter": app.current.filter}}, parsePlaylists);
doSetFilterLetter('BrowsePlaylistsFilter');
}
2018-07-22 19:00:26 +00:00
else if (app.current.app == 'Browse' && app.current.tab == 'Playlists' && app.current.view == 'Detail') {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYLIST_CONTENT_LIST", "data": {"offset": app.current.page, "filter": app.current.filter, "uri": app.current.search}}, parsePlaylists);
2018-07-22 19:00:26 +00:00
doSetFilterLetter('BrowsePlaylistsFilter');
}
else if (app.current.app == 'Browse' && app.current.tab == 'Database') {
if (app.current.search != '') {
sendAPI({"cmd": "MPD_API_DATABASE_TAG_ALBUM_LIST", "data": {"offset": app.current.page, "filter": app.current.filter, "search": app.current.search, "tag": app.current.view}}, parseListDBtags);
doSetFilterLetter('BrowseDatabaseFilter');
}
else {
sendAPI({"cmd": "MPD_API_DATABASE_TAG_LIST","data": {"offset": app.current.page, "filter": app.current.filter, "tag": app.current.view}}, parseListDBtags);
doSetFilterLetter('BrowseDatabaseFilter');
selectTag('BrowseDatabaseByTagDropdown', 'btnBrowseDatabaseByTag', app.current.view);
}
}
2018-06-10 21:15:33 +00:00
else if (app.current.app == 'Browse' && app.current.tab == 'Filesystem') {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_DATABASE_FILESYSTEM_LIST", "data": {"offset": app.current.page, "path": (app.current.search ? app.current.search : "/"), "filter": app.current.filter}}, parseFilesystem);
// Don't add all songs from root
if (app.current.search) {
2018-06-25 22:41:44 +00:00
document.getElementById('BrowseFilesystemAddAllSongs').removeAttribute('disabled');
document.getElementById('BrowseFilesystemAddAllSongsBtn').removeAttribute('disabled');
}
else {
document.getElementById('BrowseFilesystemAddAllSongs').setAttribute('disabled', 'disabled');
document.getElementById('BrowseFilesystemAddAllSongsBtn').setAttribute('disabled', 'disabled');
}
2018-06-25 22:41:44 +00:00
// 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 = '';
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;
}
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;
for (var i = 0; i < breadcrumbItemsLen; i++) {
2018-06-27 23:19:09 +00:00
breadcrumbItems[i].addEventListener('click', function() {
appGoto('Browse', 'Filesystem', undefined, '0/' + app.current.filter + '/' + this.getAttribute('data-uri'));
2018-06-25 22:41:44 +00:00
}, false);
}
doSetFilterLetter('BrowseFilesystemFilter');
}
2018-06-10 21:15:33 +00:00
else if (app.current.app == 'Search') {
2018-09-29 18:47:00 +00:00
var searchstrEl = document.getElementById('searchstr');
searchstrEl.focus();
if (searchstrEl.value == '' && app.current.search != '')
searchstrEl.value = app.current.search;
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-06-25 22:41:44 +00:00
if (app.current.search.length >= 2) {
sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": { "plist": "", "offset": app.current.page, "filter": app.current.filter, "searchstr": app.current.search}}, parseSearch);
} else {
document.getElementById('SearchList').getElementsByTagName('tbody')[0].innerHTML = '';
document.getElementById('searchAddAllSongs').setAttribute('disabled', 'disabled');
document.getElementById('searchAddAllSongsBtn').setAttribute('disabled', 'disabled');
document.getElementById('panel-heading-search').innerText = '';
2018-07-05 21:56:42 +00:00
document.getElementById('SearchList').classList.remove('opacity05');
setPagination(0);
2018-06-25 22:41:44 +00:00
}
selectTag('searchtags', 'searchtagsdesc', app.current.filter);
}
else {
appGoto("Playback");
}
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;
};
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-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState);
webSocketConnect();
domCache.volumeBar.value = 0;
document.getElementById('btnChVolumeDown').addEventListener('click', function(event) {
event.stopPropagation();
}, false);
document.getElementById('btnChVolumeUp').addEventListener('click', function(event) {
event.stopPropagation();
}, false);
domCache.volumeBar.addEventListener('click', function(event) {
event.stopPropagation();
}, false);
domCache.volumeBar.addEventListener('change', function(event) {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_VOLUME", "data": {"volume": domCache.volumeBar.value}});
}, false);
domCache.progressBar.value = 0;
domCache.progressBar.addEventListener('change', function(event) {
if (currentSong && currentSong.currentSongId >= 0) {
var seekVal = Math.ceil(currentSong.totalTime * (domCache.progressBar.value / 100));
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_SEEK", "data": {"songid": currentSong.currentSongId, "seek": seekVal}});
}
}, false);
2018-09-23 21:48:12 +00:00
document.getElementById('navDBupdate').addEventListener('click', function(event) {
event.stopPropagation();
event.preventDefault();
var icon = this.getElementsByTagName('span')[0];
if (icon.innerText == 'keyboard_arrow_right')
icon.innerText = 'keyboard_arrow_down';
else
icon.innerText = 'keyboard_arrow_right';
}, false);
document.getElementById('volumeIcon').parentNode.addEventListener('show.bs.dropdown', function () {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_OUTPUT_LIST"}, parseOutputs);
});
document.getElementById('modalAbout').addEventListener('shown.bs.modal', function () {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_DATABASE_STATS"}, parseStats);
2018-07-09 17:28:28 +00:00
});
document.getElementById('modalUpdateDB').addEventListener('hidden.bs.modal', function () {
document.getElementById('updateDBprogress').classList.remove('updateDBprogressAnimate');
});
document.getElementById('modalSaveQueue').addEventListener('shown.bs.modal', function () {
var plName = document.getElementById('saveQueueName');
plName.focus();
plName.value = '';
plName.classList.remove('is-invalid');
document.getElementById('saveQueueFrm').classList.remove('was-validated');
});
2018-07-09 17:28:28 +00:00
document.getElementById('modalSettings').addEventListener('shown.bs.modal', function () {
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
document.getElementById('addToPlaylistPlaylist').addEventListener('change',function(event) {
if (this.options[this.selectedIndex].text == 'New Playlist') {
document.getElementById('addToPlaylistNewPlaylistDiv').classList.remove('hide');
document.getElementById('addToPlaylistNewPlaylist').focus();
}
else {
document.getElementById('addToPlaylistNewPlaylistDiv').classList.add('hide');
}
}, false);
addFilterLetter('BrowseFilesystemFilterLetters');
addFilterLetter('BrowseDatabaseFilterLetters');
addFilterLetter('BrowsePlaylistsFilterLetters');
var hrefs = document.querySelectorAll('[data-href]');
var hrefsLen = hrefs.length;
for (var i = 0; i < hrefsLen; i++) {
hrefs[i].classList.add('clickable');
hrefs[i].addEventListener('click', function(event) {
event.preventDefault();
//event.stopPropagation();
var cmd = JSON.parse(this.getAttribute('data-href'));
if (typeof window[cmd.cmd] === 'function') {
switch(cmd.cmd) {
case 'sendAPI':
sendAPI(... cmd.options);
break;
default:
window[cmd.cmd](... cmd.options);
}
}
}, false);
}
2018-08-21 22:02:22 +00:00
var pd = document.getElementsByClassName('pages');
var pdLen = pd.length;
for (var i = 0; i < pdLen; i++) {
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')
event.stopPropagation();
sendAPI({"cmd": "MPD_API_PLAYER_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);
}, false);
document.getElementById('QueueList').addEventListener('click', function(event) {
if (event.target.nodeName == 'TD')
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_PLAY_TRACK","data": {"track": event.target.parentNode.getAttribute('data-trackid')}});
else if (event.target.nodeName == 'A') {
showMenu(event.target, event);
}
}, false);
document.getElementById('BrowseFilesystemList').addEventListener('click', function(event) {
if (event.target.nodeName == 'TD') {
switch(event.target.parentNode.getAttribute('data-type')) {
case 'dir':
appGoto('Browse', 'Filesystem', undefined, '0/' + app.current.filter +'/' + decodeURI(event.target.parentNode.getAttribute("data-uri")));
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"));
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"));
break;
}
}
else if (event.target.nodeName == 'A') {
showMenu(event.target, event);
}
}, false);
2018-07-22 19:00:26 +00:00
document.getElementById('BrowsePlaylistsAllList').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') {
showMenu(event.target, event);
}
}, false);
2018-07-22 19:00:26 +00:00
document.getElementById('BrowsePlaylistsDetailList').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') {
showMenu(event.target, event);
2018-07-22 19:00:26 +00:00
}
}, false);
document.getElementById('BrowseDatabaseTagList').addEventListener('click', function(event) {
if (event.target.nodeName == 'TD') {
appGoto('Browse', 'Database', app.current.view, '0/-/' + event.target.parentNode.getAttribute('data-uri'));
}
}, 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') {
showMenu(event.target, event);
}
}, false);
2018-06-25 22:41:44 +00:00
document.getElementById('BrowseFilesystemAddAllSongsDropdown').addEventListener('click', function(event) {
if (event.target.nodeName == 'BUTTON') {
if (event.target.innerText == 'Add all to queue') {
addAllFromBrowse();
}
else if (event.target.innerText == 'Add all to playlist') {
showAddToPlaylist(app.current.search);
}
}
}, false);
document.getElementById('searchAddAllSongsDropdown').addEventListener('click', function(event) {
if (event.target.nodeName == 'BUTTON') {
if (event.target.innerText == 'Add all to queue') {
addAllFromSearchPlist('queue');
}
else if (event.target.innerText == 'Add all to playlist') {
showAddToPlaylist('SEARCH');
}
else if (event.target.innerText == 'Save as smart playlist') {
showSaveSmartPlaylist();
}
}
}, false);
document.getElementById('BrowseDatabaseAddAllSongsDropdown').addEventListener('click', function(event) {
if (event.target.nodeName == 'BUTTON') {
if (event.target.innerText == 'Add all to queue') {
addAllFromBrowseDatabasePlist('queue');
}
else if (event.target.innerText == 'Add all to playlist') {
showAddToPlaylist('DATABASE');
}
}
}, false);
document.getElementById('searchtags').addEventListener('click', function(event) {
2018-06-28 23:44:52 +00:00
if (event.target.nodeName == 'BUTTON')
appGoto(app.current.app, app.current.tab, app.current.view, '0/' + event.target.getAttribute('data-tag') + '/' + app.current.search);
2018-06-28 23:44:52 +00:00
}, false);
2018-06-28 23:44:52 +00:00
document.getElementById('searchqueuestr').addEventListener('keyup', function(event) {
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);
document.getElementById('searchqueuetag').addEventListener('click', function(event) {
2018-06-28 23:44:52 +00:00
if (event.target.nodeName == 'BUTTON')
appGoto(app.current.app, app.current.tab, app.current.view, app.current.page + '/' + event.target.getAttribute('data-tag') + '/' + app.current.search);
2018-06-28 23:44:52 +00:00
}, false);
document.getElementById('search').addEventListener('submit', function() {
return false;
}, false);
document.getElementById('searchqueue').addEventListener('submit', function() {
return false;
}, false);
document.getElementById('searchstr').addEventListener('keyup', function(event) {
appGoto('Search', undefined, undefined, '0/' + app.current.filter + '/' + this.value);
}, false);
document.getElementById('BrowseDatabaseByTagDropdown').addEventListener('click', function(event) {
if (event.target.nodeName == 'BUTTON')
appGoto(app.current.app, app.current.tab, event.target.getAttribute('data-tag') , '0/' + app.current.filter + '/' + app.current.search);
}, false);
document.getElementsByTagName('body')[0].addEventListener('click', function(event) {
// var oldPopover = document.getElementsByClassName('popover');
// for (var i = 0; i < oldPopover.length; i++)
// oldPopover[i].remove();
hideMenu();
}, false);
dragAndDropTable('QueueList');
dragAndDropTable('BrowsePlaylistsDetailList');
window.addEventListener('hashchange', appRoute, false);
window.addEventListener('focus', function() {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState);
}, false);
document.addEventListener('keydown', function(event) {
if (event.target.tagName == 'INPUT')
return;
switch (event.which) {
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();
}, false);
2018-07-19 16:33:53 +00:00
if ('serviceWorker' in navigator && document.URL.substring(0, 5) == 'https') {
window.addEventListener('load', function() {
2018-09-20 22:04:35 +00:00
navigator.serviceWorker.register('/sw.min.js', {scope: '/'}).then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
2018-07-24 22:52:59 +00:00
registration.update();
}, function(err) {
// Registration failed
console.log('ServiceWorker registration failed: ', err);
});
});
}
2018-07-24 22:52:59 +00:00
window.addEventListener('beforeinstallprompt', function(event) {
// Prevent Chrome 67 and earlier from automatically showing the prompt
2018-07-24 22:52:59 +00:00
event.preventDefault();
// Stash the event so it can be triggered later.
2018-07-24 22:52:59 +00:00
deferredPrompt = event;
});
2018-07-24 22:52:59 +00:00
window.addEventListener('beforeinstallprompt', function(event) {
event.preventDefault();
deferredPrompt = event;
// Update UI notify the user they can add to home screen
domCache.btnAdd.classList.remove('hide');
});
2018-07-24 22:52:59 +00:00
domCache.btnAdd.addEventListener('click', function(event) {
// 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;
});
});
2018-07-24 22:52:59 +00:00
window.addEventListener('appinstalled', function(event) {
console.log('myMPD installed as app');
});
2018-07-02 19:59:56 +00:00
}
2013-11-07 09:09:40 +00:00
function dragAndDropTable(table) {
var tableBody=document.getElementById(table).getElementsByTagName('tbody')[0];
tableBody.addEventListener('dragstart', function(event) {
if (event.target.nodeName == 'TR') {
event.target.classList.add('opacity05');
event.dataTransfer.setDragImage(event.target, 0, 0);
event.dataTransfer.effectAllowed = 'move';
event.dataTransfer.setData('Text', event.target.getAttribute('id'));
dragEl = event.target.cloneNode(true);
}
}, false);
tableBody.addEventListener('dragleave', function(event) {
event.preventDefault();
var target = event.target;
if (event.target.nodeName == 'TD')
target = event.target.parentNode;
if (target.nodeName == 'TR')
target.classList.remove('dragover');
}, false);
tableBody.addEventListener('dragover', function(event) {
event.preventDefault();
2018-08-21 22:02:22 +00:00
var tr = tableBody.getElementsByClassName('dragover');
var trLen = tr.length;
for (var i = 0; i < trLen; i++) {
tr[i].classList.remove('dragover');
}
var target = event.target;
if (event.target.nodeName == 'TD')
target = event.target.parentNode;
if (target.nodeName == 'TR')
target.classList.add('dragover');
event.dataTransfer.dropEffect = 'move';
}, false);
tableBody.addEventListener('dragend', function(event) {
2018-08-21 22:02:22 +00:00
var tr = tableBody.getElementsByClassName('dragover');
var trLen = tr.length;
for (var i = 0; i < trLen; i++) {
tr[i].classList.remove('dragover');
}
if (document.getElementById(event.dataTransfer.getData('Text')))
document.getElementById(event.dataTransfer.getData('Text')).classList.remove('opacity05');
}, false);
tableBody.addEventListener('drop', function(event) {
event.stopPropagation();
event.preventDefault();
var target = event.target;
if (event.target.nodeName == 'TD')
target = event.target.parentNode;
var oldSongpos = document.getElementById(event.dataTransfer.getData('Text')).getAttribute('data-songpos');
var newSongpos = target.getAttribute('data-songpos');
document.getElementById(event.dataTransfer.getData('Text')).remove();
dragEl.classList.remove('opacity05');
tableBody.insertBefore(dragEl, target);
2018-08-21 22:02:22 +00:00
var tr = tableBody.getElementsByClassName('dragover');
var trLen = tr.length;
for (var i = 0; i < trLen; i++) {
tr[i].classList.remove('dragover');
}
document.getElementById(table).classList.add('opacity05');
if (app.current.app == 'Queue')
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_MOVE_TRACK","data": {"from": oldSongpos, "to": newSongpos}});
else if (app.current.app == 'Browse' && app.current.tab == 'Playlists' && app.current.view == 'Detail')
playlistMoveTrack(oldSongpos, newSongpos);
}, false);
}
function playlistMoveTrack(from, to) {
sendAPI({"cmd": "MPD_API_PLAYLIST_MOVE_TRACK","data": { "plist": app.current.search, "from": from, "to": to}});
sendAPI({"cmd": "MPD_API_PLAYLIST_CONTENT_LIST","data": {"offset": app.current.page, "filter": app.current.filter, "uri": app.current.search}}, parsePlaylists);
}
function webSocketConnect() {
2018-09-29 17:52:37 +00:00
var wsUrl = getWsUrl();
socket = new WebSocket(wsUrl);
try {
socket.onopen = function() {
2018-07-05 19:34:16 +00:00
console.log('connected');
2018-09-29 17:52:37 +00:00
showNotification('Connected to myMPD: ' + wsUrl, '', '', 'success');
modalConnectionError.hide();
appRoute();
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState);
}
2014-02-22 01:11:45 +00:00
socket.onmessage = function got_packet(msg) {
if (msg.data === lastState || msg.data.length == 0)
return;
2018-07-05 21:56:42 +00:00
try {
var obj = JSON.parse(msg.data);
} catch(e) {
2018-07-05 19:34:16 +00:00
console.log('Invalid JSON data received: ' + msg.data);
}
switch (obj.type) {
case 'update_state':
parseState(obj);
break;
case 'disconnected':
2018-09-29 17:52:37 +00:00
showNotification('Lost connection to myMPD: ' + wsUrl, '', '', 'danger');
break;
case 'update_queue':
2018-07-24 22:58:29 +00:00
if (app.current.app === 'Queue')
getQueue();
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState);
break;
case 'update_options':
getSettings();
break;
case 'update_outputs':
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_OUTPUT_LIST"}, parseOutputs);
break;
case 'update_started':
2018-08-27 16:56:40 +00:00
updateDBstarted(false);
break;
case 'update_database':
case 'update_finished':
updateDBfinished(obj.type);
break;
case 'error':
2018-07-05 19:34:16 +00:00
showNotification(obj.data, '', '', 'danger');
break;
default:
break;
}
}
socket.onclose = function(){
console.log('disconnected');
modalConnectionError.show();
setTimeout(function() {
console.log('reconnect');
webSocketConnect();
}, 3000);
}
} catch(exception) {
alert('Error: ' + exception);
}
}
2018-07-05 19:34:16 +00:00
function getWsUrl() {
2018-09-29 17:52:37 +00:00
var hostname = window.location.hostname;
var protocol = window.location.protocol;
var port = window.location.port;
if (protocol == 'https:')
protocol = 'wss://';
2018-07-05 21:56:42 +00:00
else
2018-09-29 17:52:37 +00:00
protocol = 'ws://';
2018-07-05 21:56:42 +00:00
2018-09-29 17:52:37 +00:00
var wsUrl = protocol + hostname + (port != '' ? ':' + port : '') + '/ws';
document.getElementById('wsUrl').innerText = wsUrl;
return wsUrl;
}
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);
2018-06-25 22:41:44 +00:00
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.mympdVersion;
document.getElementById('mpdVersion').innerText = obj.data.mpdVersion;
2018-06-19 22:43:36 +00:00
}
function toggleBtn(btn, state) {
var b = document.getElementById(btn);
if (!b)
return;
2018-07-03 21:46:07 +00:00
if (state == undefined)
state = b.classList.contains('active') ? 0 : 1;
if (state == 1 || state == true)
b.classList.add('active');
else
b.classList.remove('active');
}
function parseSettings(obj) {
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 = true;
}
});
}
else {
toggleBtn('btnnotifyWeb', 0);
}
} else {
btnnotifyWeb.setAttribute('disabled', 'disabled');
toggleBtn('btnnotifyWeb', 0);
}
toggleBtn('btnnotifyPage', obj.data.notificationPage);
var stickerEls = document.getElementsByClassName('stickers');
2018-08-21 22:02:22 +00:00
var stickerElsLen = stickerEls.length;
var displayStickers = obj.data.stickers == true ? '' : 'none';
for (var i = 0; i < stickerElsLen; i++)
stickerEls[i].style.display = displayStickers;
var smartplsEls = document.getElementsByClassName('smartpls');
var smartplsElsLen = smartplsEls.length;
var displaySmartpls = obj.data.smartpls == true ? '' : 'none';
for (var i = 0; i < smartplsElsLen; i++)
smartplsEls[i].style.display = displaySmartpls;
if (obj.data.mixramp == true)
document.getElementsByClassName('mixramp')[0].style.display = '';
else
document.getElementsByClassName('mixramp')[0].style.display = 'none';
document.getElementById('selectJukeboxMode').value = obj.data.jukeboxMode;
document.getElementById('inputJukeboxQueueLength').value = obj.data.jukeboxQueueLength;
settings = obj.data;
playlistEl = 'selectJukeboxPlaylist';
sendAPI({"cmd": "MPD_API_PLAYLIST_LIST", "data": {"offset": 0, "filter": "-"}}, getAllPlaylists);
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 + '/';
addTagList('BrowseDatabaseByTagDropdown', false);
addTagList('searchqueuetag', true);
addTagList('searchtags', true);
}
2018-06-21 17:28:07 +00:00
function getSettings() {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_SETTINGS_GET"}, parseSettings);
2018-06-21 17:28:07 +00:00
}
function parseOutputs(obj) {
var btns = '';
var outputsLen = obj.data.outputs.length;
for (var i = 0; i < outputsLen; i++) {
btns += '<button id="btnOutput' + obj.data.outputs[i].id +'" data-output-id="' + obj.data.outputs[i].id + '" class="btn btn-secondary btn-block';
if (obj.data.outputs[i].state == 1)
btns += ' active';
btns += '"><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;
}
function setCounter(currentSongId, totalTime, elapsedTime) {
currentSong.totalTime = totalTime;
currentSong.elapsedTime = elapsedTime;
currentSong.currentSongId = currentSongId;
var total_minutes = Math.floor(totalTime / 60);
var total_seconds = totalTime - total_minutes * 60;
var elapsed_minutes = Math.floor(elapsedTime / 60);
var elapsed_seconds = elapsedTime - elapsed_minutes * 60;
domCache.progressBar.value = Math.floor(100 * elapsedTime / totalTime);
var counterText = elapsed_minutes + ":" +
(elapsed_seconds < 10 ? '0' : '') + elapsed_seconds + " / " +
total_minutes + ":" + (total_seconds < 10 ? '0' : '') + total_seconds;
domCache.counter.innerText = counterText;
//Set playing track in queue view
if (lastState) {
var tr = document.getElementById('queueTrackId' + lastState.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');
}
}
var tr = document.getElementById('queueTrackId' + 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');
}
if (progressTimer)
clearTimeout(progressTimer);
if (playstate == 'play') {
progressTimer = setTimeout(function() {
currentSong.elapsedTime ++;
setCounter(currentSong.currentSongId, currentSong.totalTime, currentSong.elapsedTime);
}, 1000);
}
}
function parseState(obj) {
if (JSON.stringify(obj) === JSON.stringify(lastState))
2018-06-25 22:41:44 +00:00
return;
//Set playstate
2018-06-29 06:52:32 +00:00
if (obj.data.state == 1) {
2018-08-21 22:02:22 +00:00
for (var i = 0; i < domCache.btnsPlayLen; i++)
2018-08-18 13:23:02 +00:00
domCache.btnsPlay[i].innerText = 'play_arrow';
playstate = 'stop';
2018-06-29 06:52:32 +00:00
} else if (obj.data.state == 2) {
2018-08-21 22:02:22 +00:00
for (var i = 0; i < domCache.btnsPlayLen; i++)
2018-08-18 13:23:02 +00:00
domCache.btnsPlay[i].innerText = 'pause';
playstate = 'play';
} else {
2018-08-21 22:02:22 +00:00
for (var i = 0; i < domCache.btnsPlayLen; i++)
2018-08-18 13:23:02 +00:00
domCache.btnsPlay[i].innerText = 'play_arrow';
playstate = 'pause';
}
if (obj.data.nextSongPos == -1 && settings.jukeboxMode == false)
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.queueLength == 0)
2018-08-21 22:02:22 +00:00
for (var i = 0; i < domCache.btnsPlayLen; i++)
2018-08-18 13:23:02 +00:00
domCache.btnsPlay[i].setAttribute('disabled','disabled');
else
2018-08-21 22:02:22 +00:00
for (var i = 0; i < domCache.btnsPlayLen; i++)
2018-08-18 13:23:02 +00:00
domCache.btnsPlay[i].removeAttribute('disabled');
//Set volume
if (obj.data.volume == -1) {
2018-07-19 16:33:53 +00:00
domCache.volumePrct.innerText = 'Volumecontrol disabled';
domCache.volumeControl.classList.add('hide');
} else {
domCache.volumeControl.classList.remove('hide');
domCache.volumePrct.innerText = obj.data.volume + ' %';
2018-07-24 22:58:29 +00:00
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
setCounter(obj.data.currentSongId, obj.data.totalTime, obj.data.elapsedTime);
//Get current song
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_CURRENT_SONG"}, songChange);
//clear playback card if not playing
if (obj.data.songPos == '-1') {
domCache.currentTrack.innerText = 'Not playing';
2018-08-21 22:02:22 +00:00
domCache.currentAlbum.innerText = '';
domCache.currentArtist.innerText = '';
domCache.currentCover.style.backgroundImage = '';
}
lastState = obj;
}
function getQueue() {
2018-06-25 22:41:44 +00:00
if (app.current.search.length >= 2)
sendAPI({"cmd": "MPD_API_QUEUE_SEARCH", "data": {"filter": app.current.filter, "offset": app.current.page, "searchstr": app.current.search}}, parseQueue);
else {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_LIST", "data": {"offset": app.current.page}}, parseQueue);
}
}
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 && obj.totalEntities <= settings.maxElementsPerPage )
document.getElementById('panel-heading-queue').innerText = obj.totalEntities + ' ' + (obj.totalEntities > 1 ? 'Songs' : 'Song') + ' ' + beautifyDuration(obj.totalTime);
2018-06-26 22:46:29 +00:00
else if (obj.totalEntities > 0)
document.getElementById('panel-heading-queue').innerText = obj.totalEntities + ' ' + (obj.totalEntities > 1 ? 'Songs' : 'Song');
2018-06-26 22:46:29 +00:00
else
document.getElementById('panel-heading-queue').innerText = '';
2018-06-27 23:19:09 +00:00
var nrItems = obj.data.length;
var table = document.getElementById(app.current.app + 'List');
table.setAttribute('data-version', obj.queueVersion);
var tbody = table.getElementsByTagName('tbody')[0];
2018-06-26 22:46:29 +00:00
var tr = tbody.getElementsByTagName('tr');
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 && tr[i].getAttribute('data-songpos') == (obj.data[i].pos + 1))
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');
row.setAttribute('draggable','true');
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);
}
2018-08-21 22:02:22 +00:00
var trLen = tr.length - 1;
for (var i = trLen; i >= nrItems; i --) {
2018-06-26 22:46:29 +00:00
tr[i].remove();
}
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>';
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');
}
function parseSearch(obj) {
2018-06-24 21:39:37 +00:00
if (app.current.app !== 'Search')
return;
document.getElementById('panel-heading-search').innerHTML = obj.totalEntities + ' Songs found';
if (obj.totalEntities > 0) {
2018-06-25 22:41:44 +00:00
document.getElementById('searchAddAllSongs').removeAttribute('disabled');
document.getElementById('searchAddAllSongsBtn').removeAttribute('disabled');
}
else {
document.getElementById('searchAddAllSongs').setAttribute('disabled','disabled');
document.getElementById('searchAddAllSongsBtn').setAttribute('disabled','disabled');
}
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;
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');
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-07-22 19:00:26 +00:00
'<td colspan="4">' + obj.data[i].name + '</td>' +
'<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-07-22 19:00:26 +00:00
'<td>' + obj.data[i].title + '</td>' +
'<td>' + obj.data[i].artist + '</td>' +
'<td>' + obj.data[i].album + '</td>' +
'<td>' + minutes + ':' + (seconds < 10 ? '0' : '') + seconds +
'</td><td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>';
2018-06-25 22:41:44 +00:00
break;
case 'smartpls':
2018-06-25 22:41:44 +00:00
case 'plist':
row.innerHTML = '<td><span class="material-icons">list</span></td>' +
2018-07-22 19:00:26 +00:00
'<td colspan="4">' + obj.data[i].name + '</td>' +
'<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);
}
2018-08-21 22:02:22 +00:00
var trLen = tr.length - 1;
for (var i = trLen; i >= nrItems; i --) {
2018-06-25 22:41:44 +00:00
tr[i].remove();
}
setPagination(obj.totalEntities);
2018-06-25 22:41:44 +00:00
if (nrItems == 0)
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');
}
function parsePlaylists(obj) {
2018-06-25 22:41:44 +00:00
if (app.current.app !== 'Browse' && app.current.tab !== 'Playlists')
return;
2018-07-22 19:00:26 +00:00
if (app.current.view == 'All') {
document.getElementById('BrowsePlaylistsAllList').classList.remove('hide');
document.getElementById('BrowsePlaylistsDetailList').classList.add('hide');
document.getElementById('btnBrowsePlaylistsAll').parentNode.classList.add('hide');
document.getElementById('btnPlaylistClear').parentNode.classList.add('hide');
} else {
if (obj.uri.indexOf('.') > -1 || obj.smartpls == true) {
2018-07-22 19:00:26 +00:00
document.getElementById('BrowsePlaylistsDetailList').setAttribute('data-ro', 'true')
document.getElementById('btnPlaylistClear').parentNode.classList.add('hide');
}
else {
document.getElementById('BrowsePlaylistsDetailList').setAttribute('data-ro', 'false');
document.getElementById('btnPlaylistClear').parentNode.classList.remove('hide');
}
document.getElementById('BrowsePlaylistsDetailList').setAttribute('data-uri', obj.uri);
if (obj.smartpls == true)
document.getElementById('BrowsePlaylistsDetailList').getElementsByTagName('caption')[0].innerText = 'Smart playlist: ' + obj.uri;
else
document.getElementById('BrowsePlaylistsDetailList').getElementsByTagName('caption')[0].innerText = 'Playlist: ' + obj.uri;
2018-07-22 19:00:26 +00:00
document.getElementById('BrowsePlaylistsDetailList').classList.remove('hide');
document.getElementById('BrowsePlaylistsAllList').classList.add('hide');
document.getElementById('btnBrowsePlaylistsAll').parentNode.classList.remove('hide');
}
2018-06-27 23:19:09 +00:00
var nrItems = obj.data.length;
2018-07-22 19:00:26 +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-22 19:00:26 +00:00
if (app.current.view == 'All') {
for (var i = 0; i < nrItems; i++) {
var uri = encodeURI(obj.data[i].uri);
if (tr[i])
if (tr[i].getAttribute('data-uri') == uri)
continue;
var d = new Date(obj.data[i].last_modified * 1000);
var row = document.createElement('tr');
row.setAttribute('data-uri', uri);
row.setAttribute('data-type', obj.data[i].type);
2018-07-22 19:00:26 +00:00
row.setAttribute('data-name', obj.data[i].name);
row.innerHTML = '<td><span class="material-icons">list</span></td>' +
'<td>' + obj.data[i].name + '</td>' +
'<td>'+ d.toUTCString() + '</td>' +
'<td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>';
if (i < tr.length)
tr[i].replaceWith(row);
else
tbody.append(row);
}
}
else if (app.current.view == 'Detail') {
for (var i = 0; i < nrItems; i++) {
var uri = encodeURI(obj.data[i].uri);
var songpos = obj.offset + i + 1;
2018-07-22 19:00:26 +00:00
if (tr[i])
if (tr[i].getAttribute('data-uri') == uri && tr[i].getAttribute('id') == 'playlistTrackId' + songpos)
2018-07-22 19:00:26 +00:00
continue;
var row = document.createElement('tr');
if (obj.smartpls == false)
row.setAttribute('draggable','true');
row.setAttribute('id','playlistTrackId' + songpos);
2018-07-22 19:00:26 +00:00
row.setAttribute('data-type', obj.data[i].type);
row.setAttribute('data-uri', uri);
row.setAttribute('data-name', obj.data[i].name);
row.setAttribute('data-songpos', songpos);
var minutes = Math.floor(obj.data[i].duration / 60);
var seconds = obj.data[i].duration - minutes * 60;
row.innerHTML = '<td>' + songpos + '</td>' +
2018-07-22 19:00:26 +00:00
'<td>' + obj.data[i].title + '</td>' +
'<td>' + obj.data[i].artist + '</td>' +
'<td>' + obj.data[i].album + '</td>' +
'<td>' + minutes + ':' + (seconds < 10 ? '0' : '') + seconds +
'</td><td><a href="#" class="material-icons color-darkgrey">playlist_add</a></td>';
if (i < tr.length)
tr[i].replaceWith(row);
else
tbody.append(row);
}
2018-06-25 22:41:44 +00:00
}
2018-08-21 22:02:22 +00:00
var trLen = tr.length - 1;
for (var i = trLen; i >= nrItems; i --) {
2018-06-25 22:41:44 +00:00
tr[i].remove();
}
setPagination(obj.totalEntities);
2018-07-22 19:00:26 +00:00
if (nrItems == 0)
if (app.current.view == 'All')
tbody.innerHTML = '<tr><td><span class="material-icons">error_outline</span></td>' +
'<td colspan="5">No playlists found.</td></tr>';
else
tbody.innerHTML = '<tr><td><span class="material-icons">error_outline</span></td>' +
'<td colspan="5">Empty playlist.</td></tr>';
document.getElementById(app.current.app + app.current.tab + app.current.view + 'List').classList.remove('opacity05');
}
function parseListDBtags(obj) {
// if (app.current.app !== 'Browse' && app.current.tab !== 'Database' && app.current.view !== 'AlbumArtist')
// return;
if (app.current.search != '') {
document.getElementById('BrowseDatabaseAlbumList').classList.remove('hide');
document.getElementById('BrowseDatabaseTagList').classList.add('hide');
document.getElementById('btnBrowseDatabaseByTag').parentNode.classList.add('hide');
document.getElementById('btnBrowseDatabaseTag').parentNode.classList.remove('hide');
document.getElementById('BrowseDatabaseAddAllSongs').parentNode.parentNode.classList.remove('hide');
document.getElementById('btnBrowseDatabaseTag').innerHTML = '&laquo; ' + app.current.view;
document.getElementById('BrowseDatabaseAlbumListCaption').innerText = obj.searchtagtype + ': ' + obj.searchstr;
2018-06-27 23:19:09 +00:00
var nrItems = obj.data.length;
var cardContainer = document.getElementById('BrowseDatabaseAlbumList');
2018-08-21 22:02:22 +00:00
var cards = cardContainer.getElementsByClassName('col-md');
2018-06-27 23:19:09 +00:00
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);
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>' +
' <div class="card-body">' +
' <h5 class="card-title" id="albumartist' + id + '"></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);
sendAPI({"cmd": "MPD_API_DATABASE_TAG_ALBUM_TITLE_LIST", "data": { "album": obj.data[i].value, "search": app.current.search, "tag": app.current.view}}, parseListTitles);
2018-06-25 22:41:44 +00:00
}
2018-08-21 22:02:22 +00:00
var cardsLen = cards.length - 1;
for (var i = cardsLen; i >= nrItems; i --) {
2018-06-25 22:41:44 +00:00
cards[i].remove();
}
setPagination(obj.totalEntities);
document.getElementById('BrowseDatabaseAlbumList').classList.remove('opacity05');
}
else {
document.getElementById('BrowseDatabaseAlbumList').classList.add('hide');
document.getElementById('BrowseDatabaseTagList').classList.remove('hide');
document.getElementById('btnBrowseDatabaseByTag').parentNode.classList.remove('hide');
document.getElementById('BrowseDatabaseAddAllSongs').parentNode.parentNode.classList.add('hide');
document.getElementById('btnBrowseDatabaseTag').parentNode.classList.add('hide');
var nrItems = obj.data.length;
var tbody = document.getElementById(app.current.app + app.current.tab + 'TagList').getElementsByTagName('tbody')[0];
var tr = tbody.getElementsByTagName('tr');
for (var i = 0; i < nrItems; i++) {
var uri = encodeURI(obj.data[i].value);
if (tr[i])
if (tr[i].getAttribute('data-uri') == uri)
continue;
var row = document.createElement('tr');
row.setAttribute('data-uri', uri);
row.innerHTML='<td><span class="material-icons">album</span></td>' +
'<td>' + obj.data[i].value + '</td>';
if (i < tr.length)
tr[i].replaceWith(row);
else
tbody.append(row);
}
var trLen = tr.length - 1;
for (var i = trLen; i >= nrItems; i --) {
tr[i].remove();
}
setPagination(obj.totalEntities);
if (nrItems == 0)
tbody.innerHTML = '<tr><td><span class="material-icons">error_outline</span></td>' +
'<td>No entries found.</td></tr>';
document.getElementById('BrowseDatabaseTagList').classList.remove('opacity05');
2018-06-25 22:41:44 +00:00
}
}
function parseListTitles(obj) {
// if (app.current.app !== 'Browse' && app.current.tab !== 'Database' && app.current.view !== 'Album')
// return;
2018-06-25 22:41:44 +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;
img.setAttribute('src', obj.cover);
2018-08-21 22:02:22 +00:00
imga.setAttribute('data-uri', encodeURI(obj.data[0].uri.replace(/\/[^\/]+$/, '')));
2018-07-05 19:34:16 +00:00
imga.setAttribute('data-name', obj.album);
2018-07-04 22:49:34 +00:00
imga.setAttribute('data-type', 'dir');
document.getElementById('albumartist' + id).innerText = obj.albumartist;
2018-06-25 22:41:44 +00:00
2018-07-01 22:49:47 +00:00
var titleList = '';
var nrItems = obj.data.length;
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-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) {
showMenu(this, event);
}, 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') {
showMenu(event.target, event);
}
}, false);
2013-11-04 17:18:38 +00:00
}
function setPagination(number) {
var totalPages = Math.ceil(number / settings.maxElementsPerPage);
var cat = app.current.app + (app.current.tab == undefined ? '': app.current.tab);
if (totalPages == 0)
totalPages = 1;
var p = ['PaginationTop', 'PaginationBottom'];
for (var i = 0; i < 2; i++) {
document.getElementById(cat + p[i] + 'Page').innerText = (app.current.page / settings.maxElementsPerPage + 1) + ' / ' + totalPages;
if (totalPages > 1) {
document.getElementById(cat + p[i] + 'Page').removeAttribute('disabled');
var pl = '';
for (var j = 0; j < totalPages; j++) {
pl += '<button data-page="' + (j * settings.maxElementsPerPage) + '" 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');
}
if (number > app.current.page + settings.maxElementsPerPage) {
document.getElementById(cat + p[i] + 'Next').removeAttribute('disabled');
document.getElementById(cat + p[i]).classList.remove('hide');
document.getElementById(cat + 'ButtonsBottom').classList.remove('hide');
} else {
document.getElementById(cat + p[i] + 'Next').setAttribute('disabled', 'disabled');
document.getElementById(cat + p[i]).classList.add('hide');
document.getElementById(cat + 'ButtonsBottom').classList.add('hide');
}
if (app.current.page > 0) {
document.getElementById(cat + p[i] + 'Prev').removeAttribute('disabled');
document.getElementById(cat + p[i]).classList.remove('hide');
document.getElementById(cat + 'ButtonsBottom').classList.remove('hide');
} else {
document.getElementById(cat + p[i] + 'Prev').setAttribute('disabled', 'disabled');
}
}
}
function appendQueue(type, uri, name) {
2018-06-25 22:41:44 +00:00
switch(type) {
case 'song':
2018-07-05 20:04:25 +00:00
case 'dir':
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_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-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_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':
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_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':
2018-07-05 20:04:25 +00:00
case 'dir':
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_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':
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_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;
}
}
function songClick() {
var uri = domCache.currentTrack.getAttribute('data-uri')
if (uri != '')
songDetails(uri);
}
function artistClick() {
2018-08-21 22:02:22 +00:00
var albumartist = domCache.currentArtist.getAttribute('data-albumartist');
if (albumartist != '')
appGoto('Browse', 'Database', 'AlbumArtist', '0/-/' + albumartist);
}
function albumClick() {
var album = domCache.currentAlbum.getAttribute('data-album');
if (album != '')
appGoto('Browse', 'Database', 'Album', '0/-/' + album);
}
2018-07-09 17:28:28 +00:00
function songDetails(uri) {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_DATABASE_SONGDETAILS", "data": {"uri": uri}}, parseSongDetails);
2018-07-09 17:28:28 +00:00
modalSongDetails.show();
}
function parseSongDetails(obj) {
var modal = document.getElementById('modalSongDetails');
2018-08-21 22:02:22 +00:00
modal.getElementsByClassName('album-cover')[0].style.backgroundImage = 'url("' + obj.data.cover + '")';
2018-07-09 17:28:28 +00:00
modal.getElementsByTagName('h1')[0].innerText = obj.data.title;
var songDetails = '';
for (var key in settings.tags) {
if (settings.tags[key] == true) {
var value = obj.data[key.toLowerCase()];
if (key == 'duration') {
var minutes = Math.floor(value / 60);
var seconds = value - minutes * 60;
value = minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
2018-08-17 09:53:03 +00:00
}
songDetails += '<tr><th>' + key + '</th><td>' + value + '</td></tr>';
2018-08-17 09:53:03 +00:00
}
2018-07-09 17:28:28 +00:00
}
songDetails += '<tr><th>Uri</th><td><a class="text-success" href="/library/' + obj.data.uri + '">' + obj.data.uri + '</a></td></tr>';
if (settings.stickers == true) {
var like = 'not voted';
if (obj.data.like == 0)
like = '<span class="material-icons">thumb_down_alt</span>';
else if (obj.data.like == 2)
2018-09-11 20:08:48 +00:00
like = '<span class="material-icons">thumb_up_alt</span>';
songDetails += '<tr><th colspan="2">Statistics</th></tr>' +
'<tr><th>Play count</th><td>' + obj.data.playCount + '</td></tr>' +
'<tr><th>Skip count</th><td>' + obj.data.skipCount + '</td></tr>' +
2018-09-20 18:56:24 +00:00
'<tr><th>Last played</th><td>' + (obj.data.lastPlayed == 0 ? 'never' : new Date(obj.data.lastPlayed * 1000).toUTCString()) + '</td></tr>' +
'<tr><th>Like</th><td>' + like + '</td></tr>';
}
modal.getElementsByTagName('tbody')[0].innerHTML = songDetails;
2018-07-09 17:28:28 +00:00
}
2018-07-22 19:00:26 +00:00
function playlistDetails(uri) {
appGoto('Browse', 'Playlists', 'Detail', '0/-/' + uri);
}
function removeFromPlaylist(uri, pos) {
pos--;
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYLIST_RM_TRACK", "data": {"uri": uri, "track": pos}});
2018-07-22 19:00:26 +00:00
document.getElementById('BrowsePlaylistsDetailList').classList.add('opacity05');
sendAPI({"cmd": "MPD_API_PLAYLIST_CONTENT_LIST", "data": {"offset": app.current.page, "filter": app.current.filter, "uri": app.current.search}}, parsePlaylists);
2018-07-22 19:00:26 +00:00
}
function playlistClear() {
var uri = document.getElementById('BrowsePlaylistsDetailList').getAttribute('data-uri');
sendAPI({"cmd": "MPD_API_PLAYLIST_CLEAR", "data": {"uri": uri}});
document.getElementById('BrowsePlaylistsDetailList').classList.add('opacity05');
sendAPI({"cmd": "MPD_API_PLAYLIST_CONTENT_LIST", "data": {"offset": app.current.page, "filter": app.current.filter, "uri": app.current.search}}, parsePlaylists);
2018-07-22 19:00:26 +00:00
}
function getAllPlaylists(obj) {
var nrItems = obj.data.length;
var playlists = '';
if (obj.offset == 0) {
if (playlistEl == 'addToPlaylistPlaylist')
playlists = '<option></option><option>New Playlist</option>';
else if (playlistEl == 'selectJukeboxPlaylist')
playlists = '<option>Database</option>';
}
2018-07-22 19:00:26 +00:00
for (var i = 0; i < nrItems; i++) {
playlists += '<option';
if (playlistEl == 'selectJukeboxPlaylist' && obj.data[i].uri == settings.jukeboxPlaylist)
playlists += ' selected';
playlists += '>' + obj.data[i].uri + '</option>';
2018-07-22 19:00:26 +00:00
}
if (obj.offset == 0)
document.getElementById(playlistEl).innerHTML = playlists;
else
document.getElementById(playlistEl).innerHTML += playlists;
2018-07-22 19:00:26 +00:00
if (obj.totalEntities > obj.returnedEntities) {
obj.offset += settings.maxElementsPerPage;
sendAPI({"cmd": "MPD_API_PLAYLIST_LIST", "data": {"offset": obj.offset, "filter": "-"}}, getAllPlaylists);
2018-07-22 19:00:26 +00:00
}
}
function updateSmartPlaylists() {
sendAPI({"cmd": "MPD_API_SMARTPLS_UPDATE_ALL"});
}
2018-08-18 14:26:12 +00:00
function voteSong(vote) {
var uri = domCache.currentTrack.getAttribute('data-uri');
if (uri == '')
return;
2018-08-21 22:02:22 +00:00
if (vote == 2 && domCache.btnVoteUp.classList.contains('active-fg-green'))
2018-08-18 14:26:12 +00:00
vote = 1;
2018-08-21 22:02:22 +00:00
else if (vote == 0 && domCache.btnVoteDown.classList.contains('active-fg-red'))
2018-08-18 14:26:12 +00:00
vote = 1;
sendAPI({"cmd": "MPD_API_LIKE", "data": {"uri": uri, "like": vote}});
2018-08-21 22:02:22 +00:00
setVoteSongBtns(vote, uri);
2018-08-18 14:26:12 +00:00
}
2018-08-21 22:02:22 +00:00
function setVoteSongBtns(vote, uri) {
if (uri == '' || uri.indexOf('http://') == 0 || uri.indexOf('https://') == 0) {
domCache.btnVoteUp.setAttribute('disabled', 'disabled');
domCache.btnVoteDown.setAttribute('disabled', 'disabled');
} else {
domCache.btnVoteUp.removeAttribute('disabled');
domCache.btnVoteDown.removeAttribute('disabled');
}
2018-08-18 14:26:12 +00:00
if (vote == 0) {
2018-08-21 22:02:22 +00:00
domCache.btnVoteUp.classList.remove('active-fg-green');
domCache.btnVoteDown.classList.add('active-fg-red');
2018-08-18 14:26:12 +00:00
} else if (vote == 1) {
2018-08-21 22:02:22 +00:00
domCache.btnVoteUp.classList.remove('active-fg-green');
domCache.btnVoteDown.classList.remove('active-fg-red');
2018-08-18 14:26:12 +00:00
} else if (vote == 2) {
2018-08-21 22:02:22 +00:00
domCache.btnVoteUp.classList.add('active-fg-green');
domCache.btnVoteDown.classList.remove('active-fg-red');
2018-08-18 14:26:12 +00:00
}
}
function toggleAddToPlaylistFrm() {
var btn = document.getElementById('toggleAddToPlaylistBtn');
toggleBtn('toggleAddToPlaylistBtn');
if (btn.classList.contains('active')) {
document.getElementById('addToPlaylistFrm').classList.remove('hide');
document.getElementById('addStreamFooter').classList.add('hide');
document.getElementById('addToPlaylistFooter').classList.remove('hide');
}
else {
document.getElementById('addToPlaylistFrm').classList.add('hide');
document.getElementById('addStreamFooter').classList.remove('hide');
document.getElementById('addToPlaylistFooter').classList.add('hide');
}
}
function showSaveSmartPlaylist() {
var nameEl = document.getElementById('saveSmartPlaylistName');
nameEl.value = '';
nameEl.classList.remove('is-invalid');
document.getElementById('saveSmartPlaylistFrm').classList.remove('was-validated');
modalSaveSmartPlaylist.show();
nameEl.focus();
}
function saveSmartPlaylist() {
var value = document.getElementById('saveSmartPlaylistName').value;
var valid = value.replace(/[\w\-]/g, '');
if (value != '' && valid == '') {
sendAPI({"cmd": "MPD_API_SMARTPLS_SAVE", "data": {"playlist": value, "tag": app.current.filter, "searchstr": app.current.search}});
modalSaveSmartPlaylist.hide();
showNotification('Saved smart playlist ' + value, '', '', 'success');
}
else {
document.getElementById('saveSmartPlaylistName').classList.add('is-invalid');
document.getElementById('saveSmartPlaylistFrm').classList.add('was-validated');
}
}
2018-07-22 19:00:26 +00:00
function showAddToPlaylist(uri) {
document.getElementById('addToPlaylistUri').value = uri;
document.getElementById('addToPlaylistPlaylist').innerHTML = '';
document.getElementById('addToPlaylistNewPlaylist').value = '';
document.getElementById('addToPlaylistNewPlaylistDiv').classList.add('hide');
document.getElementById('addToPlaylistFrm').classList.remove('was-validated');
document.getElementById('addToPlaylistNewPlaylist').classList.remove('is-invalid');
toggleBtn('toggleAddToPlaylistBtn',0);
var streamUrl = document.getElementById('streamUrl')
streamUrl.focus();
streamUrl.value = '';
streamUrl.classList.remove('is-invalid');
document.getElementById('addStreamFrm').classList.remove('was-validated');
if (uri != 'stream') {
document.getElementById('addStreamFooter').classList.add('hide');
document.getElementById('addStreamFrm').classList.add('hide');
document.getElementById('addToPlaylistFooter').classList.remove('hide');
document.getElementById('addToPlaylistFrm').classList.remove('hide');
document.getElementById('addToPlaylistLabel').innerText = 'Add to playlist';
} else {
document.getElementById('addStreamFooter').classList.remove('hide');
document.getElementById('addStreamFrm').classList.remove('hide');
document.getElementById('addToPlaylistFooter').classList.add('hide');
document.getElementById('addToPlaylistFrm').classList.add('hide');
document.getElementById('addToPlaylistLabel').innerText = 'Add Stream';
}
modalAddToPlaylist.show();
playlistEl = 'addToPlaylistPlaylist';
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYLIST_LIST","data": {"offset": 0, "filter": "-"}}, getAllPlaylists);
2018-07-22 19:00:26 +00:00
}
function addToPlaylist() {
var uri = document.getElementById('addToPlaylistUri').value;
if (uri == 'stream') {
uri = document.getElementById('streamUrl').value;
if (uri == '' || uri.indexOf('http') == -1) {
document.getElementById('streamUrl').classList.add('is-invalid');
document.getElementById('addStreamFrm').classList.add('was-validated');
return;
}
}
2018-07-22 19:00:26 +00:00
var plistEl = document.getElementById('addToPlaylistPlaylist');
var plist = plistEl.options[plistEl.selectedIndex].text;
if (plist == 'New Playlist') {
var newPl = document.getElementById('addToPlaylistNewPlaylist').value;
var valid = newPl.replace(/[\w\-]/g, '');
if (newPl != '' && valid == '') {
plist = newPl;
} else {
document.getElementById('addToPlaylistNewPlaylist').classList.add('is-invalid');
document.getElementById('addToPlaylistFrm').classList.add('was-validated');
return;
}
}
if (plist != '') {
if (uri == 'SEARCH')
addAllFromSearchPlist(plist);
else if (uri == 'DATABASE')
addAllFromBrowseDatabasePlist(plist);
else
sendAPI({"cmd": "MPD_API_PLAYLIST_ADD_TRACK", "data": {"uri": uri, "plist": plist}});
modalAddToPlaylist.hide();
}
else {
document.getElementById('addToPlaylistPlaylist').classList.add('is-invalid');
document.getElementById('addToPlaylistFrm').classList.add('was-validated');
}
2018-07-22 19:00:26 +00:00
}
function addStream() {
var streamUrl = document.getElementById('streamUrl').value;
if (streamUrl != '' && streamUrl.indexOf('http') == 0) {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_ADD_TRACK", "data": {"uri": streamUrl}});
modalAddToPlaylist.hide();
showNotification('Added stream ' + streamUrl + 'to queue', '', '', 'success');
}
else {
document.getElementById('streamUrl').classList.add('is-invalid');
document.getElementById('addStreamFrm').classList.add('was-validated');
}
}
2018-07-22 19:00:26 +00:00
function showRenamePlaylist(from) {
document.getElementById('renamePlaylistFrm').classList.remove('was-validated');
document.getElementById('renamePlaylistTo').classList.remove('is-invalid');
modalRenamePlaylist.show();
document.getElementById('renamePlaylistFrom').value = from;
document.getElementById('renamePlaylistTo').value = '';
}
function renamePlaylist() {
var from = document.getElementById('renamePlaylistFrom').value;
var to = document.getElementById('renamePlaylistTo').value;
var valid = to.replace(/[\w\-]/g, '');
2018-07-22 19:00:26 +00:00
if (to != '' && to != from && valid == '') {
sendAPI({"cmd": "MPD_API_PLAYLIST_RENAME", "data": {"from": from, "to": to}});
modalRenamePlaylist.hide();
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYLIST_LIST","data": {"offset": app.current.page, "filter": app.current.filter}}, parsePlaylists);
2018-07-22 19:00:26 +00:00
}
else {
document.getElementById('renamePlaylistTo').classList.add('is-invalid');
document.getElementById('renamePlaylistFrm').classList.add('was-validated');
}
}
function dirname(uri) {
return uri.replace(/\/[^\/]*$/, '');
}
function b64EncodeUnicode(str) {
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
function b64DecodeUnicode(str) {
return decodeURIComponent(atob(str).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
function addMenuItem(href, text) {
return '<a class="dropdown-item" href="#" data-href=\'' + b64EncodeUnicode(JSON.stringify(href)) + '\'>' + text +'</a>';
}
function hideMenu() {
var menuEl = document.querySelector('[data-popover]');
if (menuEl) {
new Popover(menuEl, {});
menuEl.Popover.hide();
menuEl.removeAttribute('data-popover');
}
}
function showMenu(el, event) {
event.preventDefault();
event.stopPropagation();
if (el.getAttribute('data-init'))
return;
hideMenu();
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 (lastState)
nextsongpos = lastState.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')) {
menu += addMenuItem({"cmd": "appendQueue", "options": [type, uri, name]}, 'Append to queue') +
(type == 'song' ? addMenuItem({"cmd": "appendAfterQueue", "options": [type, uri, nextsongpos, name]}, 'Add after current playing song') : '') +
addMenuItem({"cmd": "replaceQueue", "options": [type, uri, name]}, 'Replace queue') +
(type != 'plist' && type != 'smartpls' ? addMenuItem({"cmd": "showAddToPlaylist", "options": [uri]}, 'Add to playlist') : '') +
(type == 'song' ? addMenuItem({"cmd": "songDetails", "options": [uri]}, 'Songdetails') : '') +
(type == 'plist' || type == 'smartpls' ? addMenuItem({"cmd": "playlistDetails", "options": [uri]}, 'View playlist') : '');
if (app.current.app == 'Search') {
var baseuri = dirname(uri);
menu += '<div class="dropdown-divider"></div>' +
'<a class="dropdown-item" id="advancedMenuLink" data-toggle="collapse" href="#advancedMenu"><span class="material-icons material-icons-small-left">keyboard_arrow_right</span>Album actions</a>' +
'<div class="collapse" id="advancedMenu">' +
addMenuItem({"cmd": "appendQueue", "options": [type, baseuri, name]}, 'Append to queue') +
addMenuItem({"cmd": "appendAfterQueue", "options": [type, baseuri, nextsongpos, name]}, 'Add after current playing song') +
addMenuItem({"cmd": "replaceQueue", "options": [type, baseuri, name]}, 'Replace queue') +
addMenuItem({"cmd": "showAddToPlaylist", "options": [baseuri]}, 'Add to playlist') +
'</div>';
}
2018-06-25 22:41:44 +00:00
}
2018-07-22 19:00:26 +00:00
else if (app.current.app == 'Browse' && app.current.tab == 'Playlists' && app.current.view == 'All') {
menu += addMenuItem({"cmd": "appendQueue", "options": [type, uri, name]}, 'Append to queue') +
addMenuItem({"cmd": "replaceQueue", "options": [type, uri, name]},'Replace queue') +
(type == 'smartpls' ? addMenuItem({"cmd": "playlistDetails", "options": [uri]}, 'View playlist') : addMenuItem({"cmd": "playlistDetails", "options": [uri]}, 'Edit playlist'))+
(uri.indexOf('myMPDsmart') != 0 ?
addMenuItem({"cmd": "showRenamePlaylist", "options": [uri]}, 'Rename playlist') +
addMenuItem({"cmd": "delPlaylist", "options": [uri]}, 'Delete playlist') : '');
2018-06-25 22:41:44 +00:00
}
2018-07-22 19:00:26 +00:00
else if (app.current.app == 'Browse' && app.current.tab == 'Playlists' && app.current.view == 'Detail') {
var x = document.getElementById('BrowsePlaylistsDetailList');
menu += addMenuItem({"cmd": "appendQueue", "options": [type, uri, name]}, 'Append to queue') +
addMenuItem({"cmd": "replaceQueue", "options": [type, uri, name]}, 'Replace queue') +
(x.getAttribute('data-ro') == 'false' ? addMenuItem({"cmd": "removeFromPlaylist", "options": [x.getAttribute('data-uri'),
el.parentNode.parentNode.getAttribute('data-songpos')]}, 'Remove') : '') +
addMenuItem({"cmd": "showAddToPlaylist", "options": [uri]}, 'Add to playlist') +
(uri.indexOf('http') == -1 ? addMenuItem({"cmd": "songDetails", "options": [uri]}, 'Songdetails') : '');
2018-07-22 19:00:26 +00:00
}
2018-06-26 22:46:29 +00:00
else if (app.current.app == 'Queue') {
menu += addMenuItem({"cmd": "delQueueSong", "options": ["single", el.parentNode.parentNode.getAttribute('data-trackid')]}, 'Remove') +
addMenuItem({"cmd": "delQueueSong", "options": ["range", 0, el.parentNode.parentNode.getAttribute('data-songpos')]}, 'Remove all upwards') +
addMenuItem({"cmd": "delQueueSong", "options": ["range", (parseInt(el.parentNode.parentNode.getAttribute('data-songpos'))-1), -1]}, 'Remove all downwards') +
(uri.indexOf('http') == -1 ? addMenuItem({"cmd": "songDetails", "options": [uri]}, 'Songdetails') : '');
}
new Popover(el, { trigger: 'click', delay: 0, dismissible: true, template: '<div class="popover" role="tooltip">' +
'<div class="arrow"></div>' +
'<div class="popover-content">' + menu + '</div>' +
'</div>'});
var popoverInit = el.Popover;
el.setAttribute('data-init', 'true');
el.addEventListener('shown.bs.popover', function(event) {
event.target.setAttribute('data-popover', 'true');
document.getElementsByClassName('popover-content')[0].addEventListener('click', function(event) {
event.preventDefault();
event.stopPropagation();
if (event.target.nodeName == 'A') {
var dh = event.target.getAttribute('data-href');
if (dh) {
var cmd = JSON.parse(b64DecodeUnicode(dh));
if (typeof window[cmd.cmd] === 'function') {
switch(cmd.cmd) {
case 'sendAPI':
sendAPI(... cmd.options);
break;
default:
window[cmd.cmd](... cmd.options);
}
2018-07-05 19:34:16 +00:00
}
hideMenu();
2018-07-05 19:34:16 +00:00
}
}
}, false);
var collapseLink = document.getElementById('advancedMenuLink');
if (collapseLink) {
collapseLink.addEventListener('click', function(event) {
var icon = this.getElementsByTagName('span')[0];
if (icon.innerText == 'keyboard_arrow_right')
icon.innerText = 'keyboard_arrow_down';
else
icon.innerText = 'keyboard_arrow_right';
}, false);
var myCollapseInit = new Collapse(collapseLink);
}
}, false);
popoverInit.show();
2018-06-24 21:39:37 +00:00
}
2018-06-19 22:43:36 +00:00
function sendAPI(request, callback) {
var ajaxRequest=new XMLHttpRequest();
ajaxRequest.open('POST', '/api', true);
ajaxRequest.setRequestHeader('Content-type', 'application/json');
ajaxRequest.onreadystatechange = function() {
if (ajaxRequest.readyState == 4) {
if (ajaxRequest.responseText != '') {
var obj = JSON.parse(ajaxRequest.responseText);
if (obj.type == 'error') {
2018-07-22 19:00:26 +00:00
showNotification('Error', obj.data, obj.data, 'danger');
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));
}
}
};
ajaxRequest.send(JSON.stringify(request));
}
function openLocalPlayer() {
window.open('/player.html#' + settings.mpdstream, 'LocalPlayer');
}
function updateDB() {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_DATABASE_UPDATE"});
2018-08-27 16:56:40 +00:00
updateDBstarted(true);
}
2018-09-23 21:48:12 +00:00
function rescanDB() {
sendAPI({"cmd": "MPD_API_DATABASE_RESCAN"});
updateDBstarted(true);
}
2018-08-27 16:56:40 +00:00
function updateDBstarted(showModal) {
if (showModal == true) {
document.getElementById('updateDBfinished').innerText = '';
document.getElementById('updateDBfooter').classList.add('hide');
updateDBprogress.style.width = '20px';
updateDBprogress.style.marginLeft = '-20px';
modalUpdateDB.show();
document.getElementById('updateDBprogress').classList.add('updateDBprogressAnimate');
}
else {
showNotification('Database update started', '', '', 'success');
}
}
function updateDBfinished(idleEvent) {
2018-08-27 16:56:40 +00:00
if (document.getElementById('modalUpdateDB').classList.contains('show')) {
if (idleEvent == 'update_database')
document.getElementById('updateDBfinished').innerText = 'Database successfully updated.';
else if (idleEvent == 'update_finished')
document.getElementById('updateDBfinished').innerText = 'Database update finished.';
var updateDBprogress = document.getElementById('updateDBprogress');
updateDBprogress.classList.remove('updateDBprogressAnimate');
updateDBprogress.style.width = '100%';
updateDBprogress.style.marginLeft = '0px';
document.getElementById('updateDBfooter').classList.remove('hide');
}
else {
if (idleEvent == 'update_database')
showNotification('Database successfully updated.', '', '', 'success');
else if (idleEvent == 'update_finished')
showNotification('Database update finished.', '', '', 'success');
}
2013-11-04 17:18:38 +00:00
}
2014-01-17 15:26:26 +00:00
function clickPlay() {
2018-07-24 22:58:29 +00:00
if (playstate != 'play')
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_PLAY"});
2014-01-17 15:26:26 +00:00
else
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_PAUSE"});
2014-01-17 15:26:26 +00:00
}
2018-06-10 16:54:57 +00:00
function clickStop() {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_STOP"});
2018-06-10 16:54:57 +00:00
}
2018-06-18 21:26:00 +00:00
function clickPrev() {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_PREV"});
2018-06-18 21:26:00 +00:00
}
function clickNext() {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_NEXT"});
}
2018-07-05 19:34:16 +00:00
function delQueueSong(mode, start, end) {
if (mode == 'range')
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_RM_RANGE", "data": {"start": start, "end": end}});
2018-07-05 19:34:16 +00:00
else if (mode == 'single')
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_RM_TRACK", "data": { "track": start}});
}
2018-07-22 19:48:13 +00:00
function delPlaylist(uri) {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYLIST_RM", "data": {"uri": uri}});
sendAPI({"cmd": "MPD_API_PLAYLIST_LIST","data": {"offset": app.current.page, "filter": app.current.filter}}, parsePlaylists);
}
function confirmSettings() {
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))
2018-07-05 21:56:42 +00:00
inputCrossfade.value = value;
else {
2018-07-05 21:56:42 +00:00
inputCrossfade.classList.add('is-invalid');
formOK = false;
}
}
var inputJukeboxQueueLength = document.getElementById('inputJukeboxQueueLength');
var value = parseInt(inputJukeboxQueueLength.value);
if (!isNaN(value)) {
if (value > 0) {
inputJukeboxQueueLength.value = value;
} else {
inputJukeboxQueueLength.classList.add('is-invalid');
formOK = false;
}
}
else {
inputJukeboxQueueLength.classList.add('is-invalid');
formOK = false;
}
2018-08-21 22:02:22 +00:00
if (settings.mixramp) {
var inputMixrampdb = document.getElementById('inputMixrampdb');
if (!inputMixrampdb.getAttribute('disabled')) {
var value = parseFloat(inputMixrampdb.value);
if (!isNaN(value))
2018-08-21 22:02:22 +00:00
inputMixrampdb.value = value;
else {
2018-08-21 22:02:22 +00:00
inputMixrampdb.classList.add('is-invalid');
formOK = false;
}
}
var inputMixrampdelay = document.getElementById('inputMixrampdelay');
if (!inputMixrampdelay.getAttribute('disabled')) {
if (inputMixrampdelay.value == 'nan')
inputMixrampdelay.value = '-1';
2018-08-21 22:02:22 +00:00
var value = parseFloat(inputMixrampdelay.value);
if (!isNaN(value))
2018-08-21 22:02:22 +00:00
inputMixrampdelay.value = value;
else {
2018-08-21 22:02:22 +00:00
inputMixrampdelay.classList.add('is-invalid');
formOK = false;
}
2018-07-05 21:56:42 +00:00
}
}
2018-08-21 22:02:22 +00:00
if (formOK == true) {
var selectReplaygain = document.getElementById('selectReplaygain');
var selectJukeboxPlaylist = document.getElementById('selectJukeboxPlaylist');
var selectJukeboxMode = document.getElementById('selectJukeboxMode');
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_SETTINGS_SET", "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,
2018-08-21 22:02:22 +00:00
"mixrampdb": (settings.mixramp == true ? document.getElementById('inputMixrampdb').value : settings.mixrampdb),
"mixrampdelay": (settings.mixramp == true ? document.getElementById('inputMixrampdelay').value : settings.mixrampdelay),
"notificationWeb": (document.getElementById('btnnotifyWeb').classList.contains('active') ? true : false),
"notificationPage": (document.getElementById('btnnotifyPage').classList.contains('active') ? true : false),
"jukeboxMode": selectJukeboxMode.options[selectJukeboxMode.selectedIndex].value,
"jukeboxPlaylist": selectJukeboxPlaylist.options[selectJukeboxPlaylist.selectedIndex].value,
"jukeboxQueueLength": document.getElementById('inputJukeboxQueueLength').value
}}, getSettings);
modalSettings.hide();
} else
document.getElementById('settingsFrm').classList.add('was-validated');
}
function addAllFromBrowseFilesystem() {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_ADD_TRACK", "data": {"uri": app.current.search}});
2018-07-05 19:34:16 +00:00
showNotification('Added all songs', '', '', 'success');
}
function addAllFromSearchPlist(plist) {
if (app.current.search.length >= 2) {
sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": {"plist": plist, "filter": app.current.filter, "searchstr": app.current.search, "offset": 0}});
showNotification('Added '+ parseInt(document.getElementById('panel-heading-search').innerText) +' songs from search to ' + plist, '', '', 'success');
}
}
function addAllFromBrowseDatabasePlist(plist) {
if (app.current.search.length >= 2) {
sendAPI({"cmd": "MPD_API_DATABASE_SEARCH", "data": {"plist": plist, "filter": app.current.view, "searchstr": app.current.search, "offset": 0}});
showNotification('Added songs from database selection to ' + plist, '', '', 'success');
}
}
function scrollTo(pos) {
document.body.scrollTop = pos; // For Safari
document.documentElement.scrollTop = pos; // For Chrome, Firefox, IE and Opera
}
function gotoPage(x) {
switch (x) {
2018-06-26 22:46:29 +00:00
case 'next':
app.current.page += settings.maxElementsPerPage;
break;
2018-06-26 22:46:29 +00:00
case 'prev':
app.current.page -= settings.maxElementsPerPage;
2018-08-21 22:02:22 +00:00
if (app.current.page < 0)
2018-06-26 22:46:29 +00:00
app.current.page = 0;
break;
default:
app.current.page = x;
}
appGoto(app.current.app, app.current.tab, app.current.view, app.current.page + '/' + app.current.filter + '/' + app.current.search);
}
2015-09-02 17:24:52 +00:00
function saveQueue() {
var plName = document.getElementById('saveQueueName').value;
var valid = plName.replace(/[\w\-]/g, '');
if (plName != '' && valid == '') {
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_QUEUE_SAVE", "data": {"plist": plName}});
modalSavequeue.hide();
}
else {
alert(valid);
document.getElementById('saveQueueName').classList.add('is-invalid');
document.getElementById('saveQueueFrm').classList.add('was-validated');
}
2015-09-02 17:24:52 +00:00
}
function showNotification(notificationTitle,notificationText,notificationHtml,notificationType) {
if (settings.notificationWeb == true) {
var notification = new Notification(notificationTitle, {icon: 'assets/favicon.ico', body: notificationText});
setTimeout(function(notification) {
notification.close();
}, 3000, notification);
}
if (settings.notificationPage == true) {
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-22 19:00:26 +00:00
alertBox.classList.remove('alert-success', 'alert-danger');
2018-07-02 19:59:56 +00:00
alertBox.classList.add('alert','alert-' + notificationType);
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-07-10 23:12:36 +00:00
function hideNotification() {
if (document.getElementById('alertBox')) {
document.getElementById('alertBox').classList.remove('alertBoxActive');
setTimeout(function() {
var alertBox = document.getElementById('alertBox');
if (alertBox)
alertBox.remove();
2018-07-10 23:12:36 +00:00
}, 600);
}
}
function notificationsSupported() {
return "Notification" in window;
}
2018-06-19 23:23:08 +00:00
function songChange(obj) {
2018-07-22 19:00:26 +00:00
if (obj.type == 'error' || obj.type == 'result')
return;
var curSong = obj.data.title + obj.data.artist + obj.data.album + obj.data.uri + obj.data.currentSongId;
if (lastSong == curSong)
2018-06-11 17:33:11 +00:00
return;
var textNotification = '';
var htmlNotification = '';
var pageTitle = 'myMPD: ';
2018-08-21 22:02:22 +00:00
domCache.currentCover.style.backgroundImage = 'url("' + obj.data.cover + '")';
2018-07-24 22:58:29 +00:00
if (typeof obj.data.artist != 'undefined' && obj.data.artist.length > 0 && obj.data.artist != '-') {
2018-06-19 22:43:36 +00:00
textNotification += obj.data.artist;
2018-07-22 19:00:26 +00:00
htmlNotification += obj.data.artist;
2018-06-19 22:43:36 +00:00
pageTitle += obj.data.artist + ' - ';
2018-08-21 22:02:22 +00:00
domCache.currentArtist.innerText = obj.data.artist;
domCache.currentArtist.setAttribute('data-albumartist', obj.data.albumartist);
} else
2018-08-21 22:02:22 +00:00
domCache.currentArtist.innerText = '';
2018-07-24 22:58:29 +00:00
if (typeof obj.data.album != 'undefined' && obj.data.album.length > 0 && obj.data.album != '-') {
2018-06-19 22:43:36 +00:00
textNotification += ' - ' + obj.data.album;
htmlNotification += '<br/>' + obj.data.album;
2018-08-21 22:02:22 +00:00
domCache.currentAlbum.innerText = obj.data.album;
domCache.currentAlbum.setAttribute('data-album', obj.data.album);
}
else
2018-08-21 22:02:22 +00:00
domCache.currentAlbum.innerText = '';
2018-07-24 22:58:29 +00:00
if (typeof obj.data.title != 'undefined' && obj.data.title.length > 0) {
2018-06-19 22:43:36 +00:00
pageTitle += obj.data.title;
domCache.currentTrack.innerText = obj.data.title;
domCache.currentTrack.setAttribute('data-uri', obj.data.uri);
} else {
domCache.currentTrack.innerText = '';
domCache.currentTrack.setAttribute('data-uri', '');
}
document.title = pageTitle;
2018-08-21 22:02:22 +00:00
if (settings.stickers == true) {
setVoteSongBtns(obj.data.like, obj.data.uri);
}
2018-07-05 19:34:16 +00:00
//Update Artist in queue view for http streams
var playingTr = document.getElementById('queueTrackId' + obj.data.currentSongId);
2018-07-05 19:34:16 +00:00
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');
lastSong = curSong;
}
function doSetFilterLetter(x) {
2018-08-21 22:02:22 +00:00
var af = document.getElementById(x + 'Letters').getElementsByClassName('active')[0];
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;
for (var i = 0; i < btnsLen; i++) {
if (btns[i].innerText == filter) {
btns[i].classList.add('active');
break;
}
}
}
2016-06-08 21:20:27 +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>';
for (var i = 65; i <= 90; i++)
filter += '<button class="mr-1 mb-1 btn-sm btn btn-secondary">' + String.fromCharCode(i) + '</button>';
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;
}
appGoto(app.current.app, app.current.tab, app.current.view, '0/' + filter + '/' + app.current.search);
}, false);
2016-06-08 21:20:27 +00:00
}
function selectTag(btnsEl, desc, setTo) {
var btns = document.getElementById(btnsEl);
var aBtn = btns.querySelector('.active')
if (aBtn)
aBtn.classList.remove('active');
aBtn = btns.querySelector('[data-tag=' + setTo + ']');
if (aBtn) {
aBtn.classList.add('active');
document.getElementById(desc).innerText = aBtn.innerText;
}
}
function addTagList(x, any) {
var tagList = '';
if (any == true)
tagList += '<button type="button" class="btn btn-secondary btn-sm btn-block" data-tag="any">Any Tag</button>';
for (var key in settings.tags) {
if (settings.tags[key] == true && key != 'Track') {
tagList += '<button type="button" class="btn btn-secondary btn-sm btn-block" data-tag="' + key + '">' + key + '</button>';
}
}
var tagListEl = document.getElementById(x);
tagListEl.innerHTML = tagList;
}
function gotoTagList() {
appGoto(app.current.app, app.current.tab, app.current.view, '0/-/');
}
function chVolume(increment) {
var newValue = parseInt(domCache.volumeBar.value) + increment;
if (newValue < 0)
newValue = 0;
else if (newValue > 100)
2018-08-21 22:02:22 +00:00
newValue = 100;
domCache.volumeBar.value = newValue;
2018-08-27 18:47:00 +00:00
sendAPI({"cmd": "MPD_API_PLAYER_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-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();