jellyfin-web/dashboard-ui/scripts/playlistedit.js

117 lines
3.2 KiB
JavaScript
Raw Normal View History

2016-11-24 23:58:38 -07:00
define(['jQuery', 'listView', 'imageLoader'], function ($, listView, imageLoader) {
2016-10-22 22:11:46 -07:00
'use strict';
2015-08-19 21:06:49 -07:00
var data = {};
function getPageData() {
var key = getSavedQueryKey();
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
2016-08-01 22:55:52 -07:00
Fields: "PrimaryImageAspectRatio",
2015-08-19 21:06:49 -07:00
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
2016-02-25 13:29:38 -07:00
Limit: 200
2015-08-19 21:06:49 -07:00
},
view: LibraryBrowser.getSavedView(key) || 'List'
2015-08-19 21:06:49 -07:00
};
pageData.query.ParentId = LibraryMenu.getTopParentId();
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData;
}
2015-08-19 21:06:49 -07:00
function getQuery() {
2015-02-04 22:29:37 -07:00
2015-08-19 21:06:49 -07:00
return getPageData().query;
}
2015-02-04 22:29:37 -07:00
2015-08-19 21:06:49 -07:00
function getSavedQueryKey() {
2015-02-04 22:29:37 -07:00
2015-10-14 21:32:10 -07:00
return LibraryBrowser.getSavedQueryKey();
2015-02-04 22:29:37 -07:00
}
2015-08-19 21:06:49 -07:00
function reloadItems(page, item) {
Dashboard.showLoadingMsg();
2015-08-19 21:06:49 -07:00
var query = getQuery();
2015-08-19 21:06:49 -07:00
query.UserId = Dashboard.getCurrentUserId();
2014-08-04 20:41:56 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getJSON(ApiClient.getUrl('Playlists/' + item.Id + '/Items', query)).then(function (result) {
2014-08-04 20:41:56 -07:00
// Scroll back up so they can see the results from the beginning
2015-06-28 07:45:21 -07:00
window.scrollTo(0, 0);
var html = '';
2015-08-19 21:06:49 -07:00
html += LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
2015-06-18 21:23:55 -07:00
showLimit: false,
updatePageSizeSetting: false
2015-08-19 21:06:49 -07:00
});
2016-07-26 23:24:59 -07:00
html += listView.getListViewHtml({
items: result.Items,
sortBy: query.SortBy,
showIndex: false,
showRemoveFromPlaylist: true,
playFromHere: true,
action: 'playallfromhere',
smallIcon: true,
dragHandle: true,
playlistId: item.Id
});
2015-08-19 21:06:49 -07:00
var elem = page.querySelector('#childrenContent .itemsContainer');
2016-07-31 12:06:59 -07:00
elem.classList.add('vertical-list');
elem.classList.remove('vertical-wrap');
2015-06-28 07:45:21 -07:00
elem.innerHTML = html;
2015-09-05 21:53:37 -07:00
2016-11-24 23:58:38 -07:00
imageLoader.lazyChildren(elem);
2015-08-19 21:06:49 -07:00
$('.btnNextPage', elem).on('click', function () {
query.StartIndex += query.Limit;
2015-08-19 21:06:49 -07:00
reloadItems(page, item);
});
2015-08-19 21:06:49 -07:00
$('.btnPreviousPage', elem).on('click', function () {
query.StartIndex -= query.Limit;
2015-08-19 21:06:49 -07:00
reloadItems(page, item);
});
Dashboard.hideLoadingMsg();
});
}
2016-06-01 23:08:47 -07:00
function init(page, item) {
var elem = page.querySelector('#childrenContent .itemsContainer');
2016-07-19 13:23:28 -07:00
elem.enableDragReordering(true);
2016-06-01 23:08:47 -07:00
elem.addEventListener('needsrefresh', function () {
reloadItems(page, item);
});
}
2015-08-19 21:06:49 -07:00
window.PlaylistViewer = {
render: function (page, item) {
2015-10-16 10:10:48 -07:00
2016-06-01 23:08:47 -07:00
if (!page.playlistInit) {
page.playlistInit = true;
init(page, item);
}
2015-08-19 21:06:49 -07:00
reloadItems(page, item);
}
2015-08-19 21:06:49 -07:00
};
2016-03-07 12:13:58 -07:00
});