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

171 lines
5.3 KiB
JavaScript
Raw Normal View History

(function ($, document) {
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()
},
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster')
};
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();
$.when(promise1, promise2).done(function (response1, response2) {
var result = response1[0];
var user = response2[0];
// 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;
2015-01-22 23:15:15 -07:00
$('.listTopPaging', page).html(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,
currentLayout: view
2015-09-05 21:53:37 -07:00
}));
if (result.TotalRecordCount) {
if (view == "List") {
html = LibraryBrowser.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-07-06 19:25:23 -07:00
else if (view == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "square",
showTitle: true,
lazy: true,
coverImage: true,
showItemCounts: true,
centerText: true,
overlayPlayButton: 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,
preferThumb: true
});
}
else if (view == "ThumbCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
showTitle: true,
lazy: true,
preferThumb: true,
cardLayout: true,
showItemCounts: true
});
}
$('.noItemsMessage', page).hide();
} else {
$('.noItemsMessage', page).show();
}
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
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(page);
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(page);
});
2015-08-15 17:41:55 -07:00
$('.btnChangeLayout', page).on('layoutchange', function (e, layout) {
getPageData().view = layout;
2015-08-26 11:17:38 -07:00
LibraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
2015-08-15 17:41:55 -07:00
reloadItems(page);
});
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2014-08-14 06:24:30 -07:00
hideLoadingMessage(page);
});
}
2015-08-31 23:22:46 -07:00
$(document).on('pagebeforeshow', "#playlistsPage", function () {
var page = this;
2015-08-15 17:41:55 -07:00
reloadItems(page);
});
})(jQuery, document);