mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
support drag and drop for playlist items
This commit is contained in:
parent
80929558e6
commit
fd64c014a3
45 changed files with 4202 additions and 3 deletions
|
@ -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({
|
||||
|
|
|
@ -1706,6 +1706,17 @@ var Dashboard = {
|
|||
|
||||
exit: function () {
|
||||
Dashboard.logout();
|
||||
},
|
||||
|
||||
loadDragula: function (callback) {
|
||||
|
||||
require(['dragula'], function (dragula) {
|
||||
|
||||
Dashboard.importCss('bower_components/dragula.js/dist/dragula.min.css');
|
||||
|
||||
callback(dragula);
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2051,7 +2062,8 @@ var AppInfo = {};
|
|||
directorybrowser: 'components/directorybrowser/directorybrowser',
|
||||
collectioneditor: 'components/collectioneditor/collectioneditor',
|
||||
playlisteditor: 'components/playlisteditor/playlisteditor',
|
||||
howler: 'bower_components/howler.js/howler.min'
|
||||
howler: 'bower_components/howler.js/howler.min',
|
||||
dragula: 'bower_components/dragula.js/dist/dragula.min'
|
||||
};
|
||||
|
||||
if (Dashboard.isRunningInCordova()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue