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

379 lines
12 KiB
JavaScript
Raw Normal View History

2013-09-13 13:45:27 -07:00
(function ($, document) {
2015-09-21 10:46:02 -07:00
var data = {};
function getPageData() {
var key = getSavedQueryKey();
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SeriesSortName,SortName",
SortOrder: "Ascending",
IncludeItemTypes: "Episode",
Recursive: true,
Fields: "PrimaryImageAspectRatio,MediaSourceCount,UserData,SyncInfo",
IsMissing: false,
IsVirtualUnaired: false,
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
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;
}
function getQuery() {
return getPageData().query;
}
2014-05-01 19:54:33 -07:00
function getSavedQueryKey() {
2015-10-14 21:32:10 -07:00
return LibraryBrowser.getSavedQueryKey('episodes');
2014-05-01 19:54:33 -07:00
}
2015-09-21 10:46:02 -07:00
function reloadItems(page, viewPanel) {
2013-09-13 13:45:27 -07:00
Dashboard.showLoadingMsg();
2015-09-21 10:46:02 -07:00
var query = getQuery();
2015-12-14 08:43:03 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
2013-09-13 13:45:27 -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-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
var view = getPageData().view;
2013-09-13 13:45:27 -07:00
var html = '';
2015-01-28 12:30:45 -07:00
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
2014-07-19 21:46:29 -07:00
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
viewButton: true,
showLimit: false,
2015-09-21 10:46:02 -07:00
viewPanelClass: 'episodesViewPanel',
updatePageSizeSetting: false,
addLayoutButton: true,
viewIcon: 'filter-list',
sortButton: true,
currentLayout: view,
layouts: 'Poster,PosterCard'
2015-01-28 12:30:45 -07:00
});
2015-06-28 07:45:21 -07:00
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
2013-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
updateFilterControls(page, viewPanel);
2013-10-18 09:09:47 -07:00
if (view == "List") {
html = LibraryBrowser.getListViewHtml({
items: result.Items,
sortBy: query.SortBy
});
}
else if (view == "Poster") {
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
showTitle: true,
showParentTitle: true,
2014-08-01 19:34:45 -07:00
overlayText: true,
2014-07-10 21:27:46 -07:00
lazy: true,
2016-02-12 13:26:03 -07:00
showDetailsMenu: true,
overlayPlayButton: true
});
}
2014-11-10 20:41:19 -07:00
else if (view == "PosterCard") {
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
showTitle: true,
showParentTitle: true,
lazy: true,
2015-05-14 19:16:57 -07:00
cardLayout: true,
showDetailsMenu: true
2014-11-10 20:41:19 -07:00
});
}
2013-12-21 11:37:34 -07:00
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('.itemsContainer');
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2013-09-13 13:45:27 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
2015-09-21 10:46:02 -07:00
reloadItems(page, viewPanel);
2013-09-13 13:45:27 -07:00
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
2015-09-21 10:46:02 -07:00
reloadItems(page, viewPanel);
});
$('.btnChangeLayout', page).on('layoutchange', function (e, layout) {
getPageData().view = layout;
LibraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
reloadItems(page, viewPanel);
});
// On callback make sure to set StartIndex = 0
$('.btnSort', page).on('click', function () {
LibraryBrowser.showSortMenu({
items: [{
name: Globalize.translate('OptionNameSort'),
id: 'SeriesSortName,SortName'
},
{
name: Globalize.translate('OptionTvdbRating'),
id: 'CommunityRating,SeriesSortName,SortName'
},
{
name: Globalize.translate('OptionDateAdded'),
id: 'DateCreated,SeriesSortName,SortName'
},
{
name: Globalize.translate('OptionPremiereDate'),
id: 'PremiereDate,SeriesSortName,SortName'
},
{
name: Globalize.translate('OptionDatePlayed'),
id: 'DatePlayed,SeriesSortName,SortName'
},
{
name: Globalize.translate('OptionParentalRating'),
id: 'OfficialRating,SeriesSortName,SortName'
},
{
name: Globalize.translate('OptionPlayCount'),
id: 'PlayCount,SeriesSortName,SortName'
},
{
name: Globalize.translate('OptionRuntime'),
id: 'Runtime,SeriesSortName,SortName'
},
{
name: Globalize.translate('OptionVideoBitrate'),
id: 'VideoBitRate,SeriesSortName,SortName'
}],
callback: function () {
reloadItems(page, viewPanel);
},
query: query
});
2013-09-13 13:45:27 -07:00
});
2014-05-01 19:54:33 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2013-09-13 13:45:27 -07:00
Dashboard.hideLoadingMsg();
});
}
2015-09-21 10:46:02 -07:00
function updateFilterControls(tabContent, viewPanel) {
2015-09-21 10:46:02 -07:00
var query = getQuery();
$('.chkStandardFilter', viewPanel).each(function () {
2013-10-18 09:09:47 -07:00
var filters = "," + (query.Filters || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.toLowerCase().indexOf(',' + filterName.toLowerCase()) != -1;
2015-09-11 09:26:06 -07:00
});
2013-10-18 09:09:47 -07:00
2015-09-21 10:46:02 -07:00
$('.chkVideoTypeFilter', viewPanel).each(function () {
2013-10-18 09:09:47 -07:00
var filters = "," + (query.VideoTypes || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
2015-09-11 09:26:06 -07:00
});
2013-10-18 09:09:47 -07:00
2015-09-21 10:46:02 -07:00
$('#chkHD', viewPanel).checked(query.IsHD == true);
$('#chkSD', viewPanel).checked(query.IsHD == false);
2013-10-18 09:09:47 -07:00
2015-09-21 10:46:02 -07:00
$('#chkSubtitle', viewPanel).checked(query.HasSubtitles == true);
$('#chkTrailer', viewPanel).checked(query.HasTrailer == true);
$('#chkThemeSong', viewPanel).checked(query.HasThemeSong == true);
$('#chkThemeVideo', viewPanel).checked(query.HasThemeVideo == true);
$('#chkSpecialFeature', viewPanel).checked(query.ParentIndexNumber == 0);
2013-10-18 09:09:47 -07:00
2015-09-21 10:46:02 -07:00
$('#chkMissingEpisode', viewPanel).checked(query.IsMissing == true);
$('#chkFutureEpisode', viewPanel).checked(query.IsUnaired == true);
2013-10-18 09:09:47 -07:00
2015-09-21 10:46:02 -07:00
$('.alphabetPicker', tabContent).alphaValue(query.NameStartsWithOrGreater);
2013-10-18 09:09:47 -07:00
}
2015-09-21 10:46:02 -07:00
function initPage(tabContent, viewPanel) {
2013-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
$('.chkStandardFilter', viewPanel).on('change', function () {
2013-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-09-13 13:45:27 -07:00
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;
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-09-13 13:45:27 -07:00
});
2015-09-21 10:46:02 -07:00
$('.chkVideoTypeFilter', viewPanel).on('change', function () {
2013-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-09-13 13:45:27 -07:00
var filterName = this.getAttribute('data-filter');
var filters = query.VideoTypes || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
query.StartIndex = 0;
query.VideoTypes = filters;
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-09-13 13:45:27 -07:00
});
2015-09-21 10:46:02 -07:00
$('#chkSubtitle', viewPanel).on('change', function () {
2013-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-09-13 13:45:27 -07:00
query.StartIndex = 0;
query.HasSubtitles = this.checked ? true : null;
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-09-13 13:45:27 -07:00
});
2015-09-21 10:46:02 -07:00
$('#chkTrailer', viewPanel).on('change', function () {
2013-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-09-13 13:45:27 -07:00
query.StartIndex = 0;
query.HasTrailer = this.checked ? true : null;
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-09-13 13:45:27 -07:00
});
2015-09-21 10:46:02 -07:00
$('#chkThemeSong', viewPanel).on('change', function () {
2013-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-09-13 13:45:27 -07:00
query.StartIndex = 0;
query.HasThemeSong = this.checked ? true : null;
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-09-13 13:45:27 -07:00
});
2015-09-21 10:46:02 -07:00
$('#chkThemeVideo', viewPanel).on('change', function () {
2013-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-09-13 13:45:27 -07:00
query.StartIndex = 0;
query.HasThemeVideo = this.checked ? true : null;
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-09-13 13:45:27 -07:00
});
2015-09-21 10:46:02 -07:00
$('#chkSpecialFeature', viewPanel).on('change', function () {
2013-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-09-13 13:45:27 -07:00
query.ParentIndexNumber = this.checked ? 0 : null;
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-09-13 13:45:27 -07:00
});
2015-09-21 10:46:02 -07:00
$('#chkMissingEpisode', viewPanel).on('change', function () {
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-10-26 15:01:21 -07:00
query.StartIndex = 0;
query.IsMissing = this.checked ? true : false;
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-10-26 15:01:21 -07:00
});
2013-10-18 09:09:47 -07:00
2015-09-21 10:46:02 -07:00
$('#chkFutureEpisode', viewPanel).on('change', function () {
2013-10-26 15:01:21 -07:00
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-10-26 15:01:21 -07:00
query.StartIndex = 0;
if (this.checked) {
query.IsUnaired = true;
query.IsVirtualUnaired = null;
} else {
query.IsUnaired = null;
query.IsVirtualUnaired = false;
}
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
});
2015-09-21 10:46:02 -07:00
$('#chkHD', viewPanel).on('change', function () {
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-10-26 15:01:21 -07:00
query.StartIndex = 0;
query.IsHD = this.checked ? true : null;
2013-10-16 19:43:55 -07:00
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-10-26 15:01:21 -07:00
});
2013-10-24 11:38:57 -07:00
2015-09-21 10:46:02 -07:00
$('#chkSD', viewPanel).on('change', function () {
2013-10-24 11:38:57 -07:00
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-10-26 15:01:21 -07:00
query.StartIndex = 0;
query.IsHD = this.checked ? false : null;
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
});
2015-09-21 10:46:02 -07:00
$('.alphabetPicker', tabContent).on('alphaselect', function (e, character) {
2013-09-13 13:45:27 -07:00
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-09-13 13:45:27 -07:00
query.NameStartsWithOrGreater = character;
query.StartIndex = 0;
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-09-13 13:45:27 -07:00
}).on('alphaclear', function (e) {
2015-09-21 10:46:02 -07:00
var query = getQuery();
2013-09-13 13:45:27 -07:00
query.NameStartsWithOrGreater = '';
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2013-09-13 13:45:27 -07:00
});
2015-09-21 10:46:02 -07:00
$('.itemsContainer', tabContent).on('needsrefresh', function () {
2014-03-19 10:44:55 -07:00
2015-09-21 10:46:02 -07:00
reloadItems(tabContent, viewPanel);
2014-03-19 10:44:55 -07:00
});
2015-09-21 10:46:02 -07:00
}
2014-03-19 10:44:55 -07:00
2015-09-21 10:46:02 -07:00
window.TvPage.initEpisodesTab = function (page, tabContent) {
2013-10-17 11:24:27 -07:00
2015-09-21 10:46:02 -07:00
var viewPanel = page.querySelector('.episodesViewPanel');
initPage(tabContent, viewPanel);
};
2013-10-17 11:24:27 -07:00
2015-09-21 10:46:02 -07:00
window.TvPage.renderEpisodesTab = function (page, tabContent) {
2013-10-17 11:24:27 -07:00
2015-09-21 10:46:02 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
var viewPanel = page.querySelector('.episodesViewPanel');
reloadItems(tabContent, viewPanel);
updateFilterControls(tabContent, viewPanel);
2013-10-17 11:24:27 -07:00
}
2015-09-21 10:46:02 -07:00
};
2013-09-13 13:45:27 -07:00
})(jQuery, document);