1
0
mirror of https://github.com/SuperBFG7/ympd synced 2025-10-21 00:57:37 +00:00

Feat: save search as smart playlist #38

This commit is contained in:
jcorporation
2018-09-29 19:41:58 +01:00
parent e550601aa8
commit ffb0b72e6e
2 changed files with 52 additions and 0 deletions

View File

@@ -97,6 +97,7 @@ var modalSongDetails = new Modal(document.getElementById('modalSongDetails'));
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'));
@@ -487,6 +488,9 @@ function appInit() {
else if (event.target.innerText == 'Add all to playlist') {
showAddToPlaylist('SEARCH');
}
else if (event.target.innerText == 'Save as smart playlist') {
showSaveSmartPlaylist();
}
}
}, false);
@@ -1596,6 +1600,29 @@ function toggleAddToPlaylistFrm() {
}
}
function showSaveSmartPlaylist() {
var nameEl = document.getElementById('saveSmartPlaylistName');
nameEl.value = 'myMPDsmart-';
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');
}
}
function showAddToPlaylist(uri) {
document.getElementById('addToPlaylistUri').value = uri;
document.getElementById('addToPlaylistPlaylist').innerHTML = '';