mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-18 03:18:19 -07:00
199 lines
6.2 KiB
JavaScript
199 lines
6.2 KiB
JavaScript
(function ($, document) {
|
|
|
|
var data = {};
|
|
function getPageData() {
|
|
var key = getSavedQueryKey();
|
|
var pageData = data[key];
|
|
|
|
if (!pageData) {
|
|
pageData = data[key] = {
|
|
query: {
|
|
SortBy: "SortName",
|
|
SortOrder: "Ascending",
|
|
IncludeItemTypes: "Movie",
|
|
Recursive: true,
|
|
Fields: "DateCreated,SyncInfo,ItemCounts",
|
|
StartIndex: 0,
|
|
Limit: LibraryBrowser.getDefaultPageSize()
|
|
},
|
|
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Thumb', 'Thumb')
|
|
};
|
|
|
|
pageData.query.ParentId = LibraryMenu.getTopParentId();
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
}
|
|
return pageData;
|
|
}
|
|
|
|
function getQuery() {
|
|
|
|
return getPageData().query;
|
|
}
|
|
|
|
function getSavedQueryKey() {
|
|
|
|
return getWindowUrl();
|
|
}
|
|
|
|
function reloadItems(page, viewPanel) {
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
var query = getQuery();
|
|
ApiClient.getGenres(Dashboard.getCurrentUserId(), query).done(function (result) {
|
|
|
|
// Scroll back up so they can see the results from the beginning
|
|
window.scrollTo(0, 0);
|
|
|
|
var html = '';
|
|
|
|
$('.listTopPaging', page).html(LibraryBrowser.getQueryPagingHtml({
|
|
startIndex: query.StartIndex,
|
|
limit: query.Limit,
|
|
totalRecordCount: result.TotalRecordCount,
|
|
viewButton: true,
|
|
showLimit: false,
|
|
viewPanelClass: 'genreViewPanel'
|
|
|
|
})).trigger('create');
|
|
|
|
updateFilterControls(page);
|
|
var view = getPageData().view;
|
|
|
|
if (view == "Thumb") {
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
items: result.Items,
|
|
shape: "backdrop",
|
|
preferThumb: true,
|
|
context: 'movies',
|
|
showItemCounts: true,
|
|
centerText: true,
|
|
lazy: true
|
|
});
|
|
}
|
|
else if (view == "ThumbCard") {
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
items: result.Items,
|
|
shape: "backdrop",
|
|
preferThumb: true,
|
|
context: 'movies',
|
|
showItemCounts: true,
|
|
cardLayout: true,
|
|
showTitle: true,
|
|
lazy: true
|
|
});
|
|
}
|
|
else if (view == "PosterCard") {
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
items: result.Items,
|
|
shape: "portrait",
|
|
context: 'movies',
|
|
showItemCounts: true,
|
|
lazy: true,
|
|
cardLayout: true,
|
|
showTitle: true
|
|
});
|
|
}
|
|
else if (view == "Poster") {
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
items: result.Items,
|
|
shape: "portrait",
|
|
context: 'movies',
|
|
centerText: true,
|
|
showItemCounts: true,
|
|
lazy: true
|
|
});
|
|
}
|
|
|
|
var elem = page.querySelector('.itemsContainer');
|
|
elem.innerHTML = html;
|
|
ImageLoader.lazyChildren(elem);
|
|
|
|
$('.btnNextPage', page).on('click', function () {
|
|
query.StartIndex += query.Limit;
|
|
reloadItems(page, viewPanel);
|
|
});
|
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
query.StartIndex -= query.Limit;
|
|
reloadItems(page, viewPanel);
|
|
});
|
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
});
|
|
}
|
|
|
|
function updateFilterControls(page) {
|
|
|
|
var query = getQuery();
|
|
$('select.selectPageSize', page).val(query.Limit).selectmenu('refresh');
|
|
$('select.selectView', page).val(getPageData().view).selectmenu('refresh');
|
|
}
|
|
|
|
function initPage(tabContent, viewPanel) {
|
|
|
|
$('.chkStandardFilter', viewPanel).on('change', function () {
|
|
|
|
var query = getQuery();
|
|
var filterName = this.getAttribute('data-filter');
|
|
var filters = query.Filters || "";
|
|
|
|
filters = (',' + filters).replace(',' + filterName, '').substring(1);
|
|
|
|
if (this.checked) {
|
|
filters = filters ? (filters + ',' + filterName) : filterName;
|
|
}
|
|
|
|
query.StartIndex = 0;
|
|
query.Filters = filters;
|
|
|
|
reloadItems(tabContent, viewPanel);
|
|
});
|
|
|
|
$('select.selectPageSize', viewPanel).on('change', function () {
|
|
var query = getQuery();
|
|
query.Limit = parseInt(this.value);
|
|
query.StartIndex = 0;
|
|
reloadItems(tabContent, viewPanel);
|
|
});
|
|
|
|
$('select.selectView', viewPanel).on('change', function () {
|
|
|
|
var newView = this.value;
|
|
getPageData().view = newView;
|
|
|
|
reloadItems(tabContent, viewPanel);
|
|
LibraryBrowser.saveViewSetting(getSavedQueryKey(), newView);
|
|
});
|
|
}
|
|
|
|
$(document).on('pageinitdepends', "#moviesRecommendedPage", function () {
|
|
|
|
var page = this;
|
|
var index = 4;
|
|
var tabContent = page.querySelector('.pageTabContent[data-index=\'' + index + '\']');
|
|
var viewPanel = $('.genreViewPanel', page);
|
|
|
|
$(page.querySelector('neon-animated-pages')).on('tabchange', function () {
|
|
|
|
if (parseInt(this.selected) == index) {
|
|
|
|
if (!tabContent.initComplete) {
|
|
initPage(tabContent, viewPanel);
|
|
tabContent.initComplete = true;
|
|
}
|
|
|
|
if (LibraryBrowser.needsRefresh(tabContent)) {
|
|
reloadItems(tabContent, viewPanel);
|
|
updateFilterControls(viewPanel);
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
});
|
|
|
|
})(jQuery, document); |