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

209 lines
6.2 KiB
JavaScript
Raw Normal View History

2013-04-03 21:21:46 -07:00
(function ($, document) {
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-08-15 11:17:22 -07:00
return getWindowUrl();
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();
$.when(promise1, promise2).done(function (response1, response2) {
var result = response1[0];
var user = response2[0];
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,
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-01-22 23:15:15 -07:00
})).trigger('create');
2013-04-03 21:21:46 -07:00
2015-01-22 23:15:15 -07:00
var trigger = false;
2013-10-18 09:09:47 -07:00
if (result.TotalRecordCount) {
2014-05-31 07:30:59 -07:00
2015-08-15 11:17:22 -07:00
var context = getParameterByName('context');
if (view == "List") {
html = LibraryBrowser.getListViewHtml({
items: result.Items,
2015-08-15 11:17:22 -07:00
context: context,
sortBy: query.SortBy
});
2015-01-22 23:15:15 -07:00
trigger = true;
}
else if (view == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
2015-01-22 23:15:15 -07:00
shape: "auto",
2015-08-15 11:17:22 -07:00
context: context,
2015-01-22 23:15:15 -07:00
showTitle: true,
centerText: true,
lazy: true
});
}
2015-05-12 21:55:19 -07:00
else if (view == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "auto",
2015-08-15 11:17:22 -07:00
context: context,
2015-05-12 21:55:19 -07:00
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",
2015-08-15 11:17:22 -07:00
context: context,
2015-04-02 14:01:42 -07:00
showTitle: true,
centerText: true,
lazy: true,
preferThumb: true
});
}
2015-05-12 21:55:19 -07:00
else if (view == "ThumbCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
2015-08-15 11:17:22 -07:00
context: context,
2015-05-12 21:55:19 -07:00
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
if (trigger) {
2015-06-28 07:45:21 -07:00
$(elem).trigger('create');
2015-01-22 23:15:15 -07:00
}
2013-04-11 08:43:57 -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;
reloadItems(page);
2013-04-29 19:00:42 -07:00
});
2013-04-15 15:03:05 -07:00
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-08-15 16:10:50 -07:00
$('select.selectView').on('change', function () {
2015-08-15 11:46:57 -07:00
var newView = this.value;
getPageData().view = newView;
2015-08-15 16:10:50 -07:00
reloadItems(tabContent);
2015-08-15 11:46:57 -07:00
LibraryBrowser.saveViewSetting(getSavedQueryKey(), newView);
});
2015-08-15 11:17:22 -07:00
}
2014-07-19 21:46:29 -07:00
2015-08-15 11:17:22 -07:00
$(document).on('pageinitdepends', "#boxsetsPage", function () {
2014-06-03 20:34:36 -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-08-15 11:17:22 -07:00
}).on('pagebeforeshowready', "#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);
2013-04-29 19:00:42 -07:00
});
2013-04-03 21:21:46 -07:00
2015-08-18 09:11:56 -07:00
window.MoviesPage = window.MoviesPage || {};
window.MoviesPage.renderCollectionsTab = function (page, tabContent) {
if (LibraryBrowser.needsRefresh(tabContent)) {
reloadItems(tabContent);
}
};
window.MoviesPage.initCollectionsTab = function (page, tabContent) {
initPage(tabContent);
};
2013-04-03 21:21:46 -07:00
})(jQuery, document);