jellyfin-web/dashboard-ui/scripts/moviepeople.js
2015-08-15 14:30:52 -04:00

185 lines
5.6 KiB
JavaScript

(function ($, document) {
var pageSizeKey = 'people';
var data = {};
function getQuery() {
var key = getSavedQueryKey();
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "Movie,Trailer",
Recursive: true,
Fields: "DateCreated,ItemCounts",
PersonTypes: "",
StartIndex: 0,
Limit: 100
}
};
pageData.query.ParentId = LibraryMenu.getTopParentId();
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData.query;
}
function getSavedQueryKey() {
return getWindowUrl();
}
function reloadItems(page, viewPanel) {
Dashboard.showLoadingMsg();
var query = getQuery();
ApiClient.getPeople(Dashboard.getCurrentUserId(), query).done(function (result) {
// Scroll back up so they can see the results from the beginning
window.scrollTo(0, 0);
var html = '';
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
viewButton: true,
showLimit: false,
updatePageSizeSetting: false,
pageSizeKey: pageSizeKey,
viewPanelClass: 'peopleViewPanel'
});
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
updateFilterControls(page, viewPanel);
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'movies',
showTitle: true,
showItemCounts: true,
coverImage: true,
lazy: true
});
var elem = page.querySelector('.itemsContainer');
elem.innerHTML = html + pagingHtml;
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(tabContent, viewPanel) {
var query = getQuery();
$('.chkPersonTypeFilter', viewPanel).each(function () {
var filters = "," + (query.PersonTypes || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
}).checkboxradio('refresh');
$('.alphabetPicker', tabContent).alphaValue(query.NameStartsWithOrGreater);
}
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);
});
$('.chkPersonTypeFilter', viewPanel).on('change', function () {
var query = getQuery();
var filterName = this.getAttribute('data-filter');
var filters = query.PersonTypes || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
query.StartIndex = 0;
query.PersonTypes = filters;
reloadItems(tabContent, viewPanel);
});
$('.alphabetPicker', tabContent).on('alphaselect', function (e, character) {
var query = getQuery();
query.NameStartsWithOrGreater = character;
query.StartIndex = 0;
reloadItems(tabContent, viewPanel);
}).on('alphaclear', function (e) {
var query = getQuery();
query.NameStartsWithOrGreater = '';
reloadItems(tabContent, viewPanel);
});
}
$(document).on('pageinitdepends', "#moviesRecommendedPage", function () {
var page = this;
var index = 5;
var tabContent = page.querySelector('.pageTabContent[data-index=\'' + index + '\']');
var viewPanel = $('.peopleViewPanel', 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(tabContent, viewPanel);
}
}
});
});
})(jQuery, document);