support drag and drop for playlist items

This commit is contained in:
Luke Pulverenti 2015-10-15 01:48:03 -04:00
parent 80929558e6
commit fd64c014a3
45 changed files with 4202 additions and 3 deletions

View file

@ -76,6 +76,23 @@
var elem = page.querySelector('#childrenContent .itemsContainer');
elem.innerHTML = html;
var listItems = [];
var elems = elem.querySelectorAll('PAPER-ICON-ITEM');
for (var i = 0, length = elems.length; i < length; i++) {
listItems.push(elems[i]);
}
Dashboard.loadDragula(function (dragula) {
dragula([elem.querySelector('.paperList')], {
direction: 'vertical',
revertOnSpill: true
}).on('drop', function (el, target, source, sibling) {
onDrop(el, target, source, sibling, page, item);
});
});
ImageLoader.lazyChildren(elem);
$(elem).off('needsrefresh').on('needsrefresh', function () {
@ -85,10 +102,8 @@
}).off('removefromplaylist').on('removefromplaylist', function (e, playlistItemId) {
removeFromPlaylist(page, item, [playlistItemId]);
});
$('.btnNextPage', elem).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(page, item);
@ -103,6 +118,42 @@
});
}
function onDrop(el, target, source, sibling, page, item) {
var parent = $(el).parents('.paperList')[0];
var newIndex;
if (sibling) {
newIndex = parseInt(sibling.getAttribute('data-index'));
} else {
// dropped at the end
newIndex = parent.querySelectorAll('paper-icon-item').length;
}
var itemId = el.getAttribute('data-playlistitemid');
Dashboard.showLoadingMsg();
ApiClient.ajax({
url: ApiClient.getUrl('Playlists/' + item.Id + '/Items/' + itemId + '/Move/' + newIndex),
type: 'POST'
}).done(function () {
Dashboard.hideLoadingMsg();
}).fail(function () {
Dashboard.hideLoadingMsg();
reloadItems(page, item);
});
}
function removeFromPlaylist(page, item, ids) {
ApiClient.ajax({