jellyfish-web/src/scripts/playlistedit.js

51 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-05-04 12:44:12 +02:00
define(['listView'], function (listView) {
'use strict';
2018-10-23 01:05:09 +03:00
function getFetchPlaylistItemsFn(itemId) {
2019-10-08 01:02:37 +03:00
return function () {
2018-10-23 01:05:09 +03:00
var query = {
2020-05-04 12:44:12 +02:00
Fields: 'PrimaryImageAspectRatio,UserData',
EnableImageTypes: 'Primary,Backdrop,Banner,Thumb',
2018-10-23 01:05:09 +03:00
UserId: ApiClient.getCurrentUserId()
};
2020-04-06 23:49:44 +02:00
return ApiClient.getJSON(ApiClient.getUrl(`Playlists/${itemId}/Items`, query));
2019-10-08 01:02:37 +03:00
};
2018-10-23 01:05:09 +03:00
}
function getItemsHtmlFn(itemId) {
2019-10-08 01:02:37 +03:00
return function (items) {
2018-10-23 01:05:09 +03:00
return listView.getListViewHtml({
items: items,
2019-10-08 01:02:37 +03:00
showIndex: false,
showRemoveFromPlaylist: true,
playFromHere: true,
2020-05-04 12:44:12 +02:00
action: 'playallfromhere',
2019-10-08 01:02:37 +03:00
smallIcon: true,
dragHandle: true,
2018-10-23 01:05:09 +03:00
playlistId: itemId
2019-10-08 01:02:37 +03:00
});
};
2018-10-23 01:05:09 +03:00
}
function init(page, item) {
2020-05-04 12:44:12 +02:00
var elem = page.querySelector('#childrenContent .itemsContainer');
elem.classList.add('vertical-list');
elem.classList.remove('vertical-wrap');
2019-10-08 01:02:37 +03:00
elem.enableDragReordering(true);
elem.fetchData = getFetchPlaylistItemsFn(item.Id);
elem.getItemsHtml = getItemsHtmlFn(item.Id);
2018-10-23 01:05:09 +03:00
}
2019-10-08 01:02:37 +03:00
2018-10-23 01:05:09 +03:00
window.PlaylistViewer = {
2019-10-08 01:02:37 +03:00
render: function (page, item) {
if (!page.playlistInit) {
page.playlistInit = true;
init(page, item);
}
2020-05-04 12:44:12 +02:00
page.querySelector('#childrenContent').classList.add('verticalSection-extrabottompadding');
page.querySelector('#childrenContent .itemsContainer').refreshItems();
2018-10-23 01:05:09 +03:00
}
2019-10-08 01:02:37 +03:00
};
});