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

234 lines
7.0 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2013-04-03 21:21:46 -07:00
2015-08-15 11:17:22 -07:00
var data = {};
2015-08-15 11:46:57 -07:00
function getPageData() {
2015-08-15 11:17:22 -07:00
var key = getSavedQueryKey();
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "BoxSet",
Recursive: true,
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo,CanDelete",
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
Limit: LibraryBrowser.getDefaultPageSize()
2015-08-15 11:46:57 -07:00
},
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster')
2015-08-15 11:17:22 -07:00
};
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
2015-08-15 11:46:57 -07:00
return pageData;
}
function getQuery() {
return getPageData().query;
2015-08-15 11:17:22 -07:00
}
2013-04-03 21:21:46 -07:00
2014-05-06 19:28:19 -07:00
function getSavedQueryKey() {
2015-10-14 21:32:10 -07:00
return LibraryBrowser.getSavedQueryKey('collections');
2014-05-06 19:28:19 -07:00
}
2015-08-15 16:10:50 -07:00
function reloadItems(page) {
2013-04-03 21:21:46 -07:00
2013-04-29 19:00:42 -07:00
Dashboard.showLoadingMsg();
2013-04-03 21:21:46 -07:00
2015-08-15 11:17:22 -07:00
var query = getQuery();
2014-07-19 21:46:29 -07:00
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) {
2014-07-19 21:46:29 -07:00
2015-12-14 08:43:03 -07:00
var result = responses[0];
var user = responses[1];
2013-04-03 21:21:46 -07:00
2013-05-17 12:18:54 -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);
2013-05-17 12:18:54 -07:00
2013-04-29 19:00:42 -07:00
var html = '';
2013-04-03 21:21:46 -07:00
2015-08-15 16:10:50 -07:00
var view = getPageData().view;
2015-01-22 23:15:15 -07:00
$('.listTopPaging', page).html(LibraryBrowser.getQueryPagingHtml({
2014-07-19 21:46:29 -07:00
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
2015-08-15 16:10:50 -07:00
viewButton: false,
2015-08-28 18:53:53 -07:00
sortButton: true,
2014-07-19 21:46:29 -07:00
showLimit: false,
2015-08-15 16:10:50 -07:00
updatePageSizeSetting: false,
addLayoutButton: true,
currentLayout: view
2015-08-15 11:17:22 -07:00
2015-12-14 08:43:03 -07:00
}));
2013-04-03 21:21:46 -07:00
if (result.TotalRecordCount) {
2014-05-31 07:30:59 -07:00
if (view == "List") {
html = LibraryBrowser.getListViewHtml({
items: result.Items,
sortBy: query.SortBy
});
}
else if (view == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
2015-01-22 23:15:15 -07:00
shape: "auto",
showTitle: true,
centerText: true,
2016-02-12 13:26:03 -07:00
lazy: true,
overlayPlayButton: true
});
}
2015-05-12 21:55:19 -07:00
else if (view == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "auto",
showTitle: true,
cardLayout: true,
lazy: true,
showItemCounts: true
});
}
2015-04-02 14:01:42 -07:00
else if (view == "Thumb") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
showTitle: true,
centerText: true,
lazy: true,
2016-02-12 13:26:03 -07:00
preferThumb: true,
overlayPlayButton: true
2015-04-02 14:01:42 -07:00
});
}
2015-05-12 21:55:19 -07:00
else if (view == "ThumbCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
showTitle: true,
lazy: true,
preferThumb: true,
cardLayout: true,
showItemCounts: true
});
}
2014-05-31 07:30:59 -07:00
2014-05-30 12:23:56 -07:00
$('.noItemsMessage', page).hide();
2014-07-19 21:46:29 -07:00
} else {
2014-05-31 07:30:59 -07:00
2014-05-30 12:23:56 -07:00
$('.noItemsMessage', page).show();
}
2013-04-11 08:43:57 -07:00
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
2013-04-29 19:00:42 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
2015-08-15 16:10:50 -07:00
reloadItems(page);
2013-04-29 19:00:42 -07:00
});
2013-04-15 15:03:05 -07:00
2013-04-29 19:00:42 -07:00
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
2015-08-15 16:10:50 -07:00
reloadItems(page);
});
$('.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 16:10:50 -07:00
reloadItems(page);
2013-04-29 19:00:42 -07:00
});
2013-04-15 15:03:05 -07:00
2015-08-28 18:53:53 -07:00
// On callback make sure to set StartIndex = 0
$('.btnSort', page).on('click', function () {
LibraryBrowser.showSortMenu({
items: [{
name: Globalize.translate('OptionNameSort'),
id: 'SortName'
},
{
name: Globalize.translate('OptionImdbRating'),
id: 'CommunityRating,SortName'
},
{
name: Globalize.translate('OptionDateAdded'),
id: 'DateCreated,SortName'
},
{
name: Globalize.translate('OptionParentalRating'),
id: 'OfficialRating,SortName'
},
{
name: Globalize.translate('OptionReleaseDate'),
id: 'PremiereDate,SortName'
}],
callback: function () {
reloadItems(page);
},
query: query
});
});
2014-05-06 19:28:19 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2013-10-18 09:09:47 -07:00
2013-04-29 19:00:42 -07:00
Dashboard.hideLoadingMsg();
});
}
2013-04-03 21:21:46 -07:00
2015-08-15 16:10:50 -07:00
function initPage(tabContent) {
2013-04-03 21:21:46 -07:00
2015-10-13 22:46:11 -07:00
// The button is created dynamically
$('.btnNewCollection', tabContent).on('click', function () {
2015-10-13 22:46:11 -07:00
require(['collectioneditor'], function (collectioneditor) {
2015-10-13 22:46:11 -07:00
new collectioneditor().show();
2015-10-13 22:46:11 -07:00
});
});
2015-08-15 11:17:22 -07:00
}
2014-07-19 21:46:29 -07:00
2015-12-14 08:43:03 -07:00
pageIdOn('pageinit', 'boxsetsPage', function () {
2016-04-03 11:47:49 -07:00
2015-08-15 11:17:22 -07:00
var page = this;
2014-06-03 20:34:36 -07:00
2015-08-15 11:17:22 -07:00
var content = page;
2014-06-03 20:34:36 -07:00
2015-08-15 16:10:50 -07:00
initPage(content);
2014-05-31 07:30:59 -07:00
2015-12-14 08:43:03 -07:00
});
pageIdOn('pagebeforeshow', 'boxsetsPage', function () {
2014-05-31 07:30:59 -07:00
var page = this;
2015-08-15 11:17:22 -07:00
var content = page;
2014-05-31 07:30:59 -07:00
2015-08-15 16:10:50 -07:00
reloadItems(content);
2015-12-14 08:43:03 -07:00
2013-04-29 19:00:42 -07:00
});
2013-04-03 21:21:46 -07:00
2016-04-03 11:47:49 -07:00
return function (view, params, tabContent) {
2015-08-18 09:11:56 -07:00
2016-04-03 11:47:49 -07:00
var self = this;
2015-08-18 09:11:56 -07:00
2016-04-03 11:47:49 -07:00
self.initTab = function () {
initPage(tabContent);
};
self.renderTab = function () {
reloadItems(tabContent);
};
2015-08-18 09:11:56 -07:00
};
});