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

184 lines
6.0 KiB
JavaScript
Raw Normal View History

2016-07-15 22:05:40 -07:00
define(['listView'], function (listView) {
2015-08-15 17:41:55 -07:00
var data = {};
function getPageData() {
var key = getSavedQueryKey();
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "Playlist",
Recursive: true,
Fields: "PrimaryImageAspectRatio,SortName,CumulativeRunTimeTicks,CanDelete,SyncInfo",
StartIndex: 0,
Limit: LibraryBrowser.getDefaultPageSize()
},
2016-07-24 14:28:47 -07:00
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('PosterCard', 'PosterCard')
2015-08-15 17:41:55 -07:00
};
pageData.query.ParentId = LibraryMenu.getTopParentId();
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData;
}
2015-08-15 17:41:55 -07:00
function getQuery() {
2015-08-15 17:41:55 -07:00
return getPageData().query;
}
function getSavedQueryKey() {
2015-10-14 21:32:10 -07:00
return LibraryBrowser.getSavedQueryKey();
}
2014-08-14 06:24:30 -07:00
function showLoadingMessage(page) {
2015-06-16 10:37:49 -07:00
Dashboard.showLoadingMsg();
2014-08-14 06:24:30 -07:00
}
function hideLoadingMessage(page) {
2015-06-16 10:37:49 -07:00
Dashboard.hideLoadingMsg();
2014-08-14 06:24:30 -07:00
}
function reloadItems(page) {
2014-08-14 06:24:30 -07:00
showLoadingMessage(page);
2015-08-15 17:41:55 -07:00
var query = getQuery();
var promise1 = ApiClient.getItems(Dashboard.getCurrentUserId(), query);
var promise2 = Dashboard.getCurrentUser();
2015-12-14 08:43:03 -07:00
Promise.all([promise1, promise2]).then(function (responses) {
2015-12-14 08:43:03 -07:00
var result = responses[0];
var user = responses[1];
// 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-15 17:41:55 -07:00
var view = getPageData().view;
2016-05-27 10:18:22 -07:00
page.querySelector('.listTopPaging').innerHTML = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
2015-08-15 17:41:55 -07:00
viewButton: false,
showLimit: false,
updatePageSizeSetting: false,
addLayoutButton: true,
2016-05-27 10:18:22 -07:00
layouts: 'List,Poster,PosterCard,Thumb,ThumbCard',
2015-08-15 17:41:55 -07:00
currentLayout: view
2016-05-27 10:18:22 -07:00
});
if (result.TotalRecordCount) {
if (view == "List") {
2016-07-15 22:05:40 -07:00
html = listView.getListViewHtml({
items: result.Items,
sortBy: query.SortBy
});
}
2014-11-18 19:45:12 -07:00
else if (view == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "square",
showTitle: true,
lazy: true,
coverImage: true,
2014-11-18 19:45:12 -07:00
showItemCounts: true,
cardLayout: true
});
}
2015-08-17 09:52:56 -07:00
else if (view == "Thumb") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
showTitle: true,
centerText: true,
lazy: true,
2016-07-26 10:21:27 -07:00
preferThumb: true,
overlayPlayButton: true
2015-08-17 09:52:56 -07:00
});
}
else if (view == "ThumbCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
showTitle: true,
lazy: true,
preferThumb: true,
cardLayout: true,
showItemCounts: true
});
}
2016-05-27 10:18:22 -07:00
else {
// Poster
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "square",
showTitle: true,
lazy: true,
coverImage: true,
showItemCounts: true,
centerText: true,
overlayPlayButton: true
});
}
2016-05-27 10:18:22 -07:00
page.querySelector('.noItemsMessage').classList.add('hide');
} else {
2016-05-27 10:18:22 -07:00
page.querySelector('.noItemsMessage').classList.remove('hide');
}
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('.itemsContainer');
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
2015-01-22 23:15:15 -07:00
2016-05-27 10:18:22 -07:00
var btnNextPage = page.querySelector('.btnNextPage');
if (btnNextPage) {
btnNextPage.addEventListener('click', function () {
query.StartIndex += query.Limit;
reloadItems(page);
});
}
2016-05-27 10:18:22 -07:00
var btnPreviousPage = page.querySelector('.btnPreviousPage');
if (btnPreviousPage) {
btnPreviousPage.addEventListener('click', function () {
query.StartIndex -= query.Limit;
reloadItems(page);
});
}
2016-05-27 10:18:22 -07:00
var btnChangeLayout = page.querySelector('.btnChangeLayout');
if (btnChangeLayout) {
btnChangeLayout.addEventListener('layoutchange', function (e) {
var layout = e.detail.viewStyle;
getPageData().view = layout;
LibraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
reloadItems(page);
});
}
2015-08-15 17:41:55 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2014-08-14 06:24:30 -07:00
hideLoadingMessage(page);
});
}
2015-12-14 08:43:03 -07:00
pageIdOn('pagebeforeshow', "playlistsPage", function () {
var page = this;
2015-08-15 17:41:55 -07:00
reloadItems(page);
});
});