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

298 lines
11 KiB
JavaScript
Raw Normal View History

2016-07-16 11:02:39 -07:00
define(['events', 'libraryBrowser', 'imageLoader', 'alphaPicker', 'listView', 'emby-itemscontainer'], function (events, libraryBrowser, imageLoader, alphaPicker, listView) {
2016-03-18 12:43:17 -07:00
return function (view, params, tabContent) {
var self = this;
var pageSize = libraryBrowser.getDefaultPageSize();
2016-03-18 12:43:17 -07:00
var data = {};
function getPageData(context) {
var key = getSavedQueryKey(context);
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "Series",
Recursive: true,
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo",
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
Limit: pageSize
2016-03-18 12:43:17 -07:00
},
2016-04-23 22:27:12 -07:00
view: libraryBrowser.getSavedView(key) || libraryBrowser.getDefaultItemsView('Poster', 'Poster')
2016-03-18 12:43:17 -07:00
};
pageData.query.ParentId = params.topParentId;
libraryBrowser.loadSavedQueryValues(key, pageData.query);
2016-03-18 12:43:17 -07:00
}
return pageData;
}
function getQuery(context) {
return getPageData(context).query;
}
function getSavedQueryKey(context) {
if (!context.savedQueryKey) {
context.savedQueryKey = libraryBrowser.getSavedQueryKey('series');
2016-03-18 12:43:17 -07:00
}
return context.savedQueryKey;
}
2016-04-25 19:32:06 -07:00
function reloadItems(page) {
2016-03-18 12:43:17 -07:00
2016-04-25 19:32:06 -07:00
Dashboard.showLoadingMsg();
2016-03-18 12:43:17 -07:00
2016-04-25 19:32:06 -07:00
var query = getQuery(page);
2016-03-18 12:43:17 -07:00
2016-04-25 19:32:06 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
2016-04-29 20:59:59 -07:00
// Scroll back up so they can see the results from the beginning
window.scrollTo(0, 0);
2016-04-25 19:32:06 -07:00
updateFilterControls(page);
2016-03-18 12:43:17 -07:00
2016-04-25 19:32:06 -07:00
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
updatePageSizeSetting: false,
addLayoutButton: false,
sortButton: false,
filterButton: false
2016-03-18 12:43:17 -07:00
});
2016-04-25 19:32:06 -07:00
var html;
var viewStyle = self.getCurrentViewStyle();
2016-03-18 12:43:17 -07:00
2016-04-25 19:32:06 -07:00
if (viewStyle == "Thumb") {
2016-04-25 19:32:06 -07:00
html = libraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'tv',
lazy: true,
overlayPlayButton: true
});
}
else if (viewStyle == "ThumbCard") {
html = libraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'tv',
lazy: true,
cardLayout: true,
showTitle: true,
showSeriesYear: true
});
}
else if (viewStyle == "Banner") {
html = libraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "banner",
preferBanner: true,
context: 'tv',
lazy: true
});
}
else if (viewStyle == "List") {
2016-03-18 12:43:17 -07:00
2016-07-15 22:05:40 -07:00
html = listView.getListViewHtml({
2016-04-25 19:32:06 -07:00
items: result.Items,
context: 'tv',
sortBy: query.SortBy
});
}
else if (viewStyle == "PosterCard") {
html = libraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'tv',
showTitle: true,
showYear: true,
lazy: true,
cardLayout: true
});
}
else {
// Poster
html = libraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'tv',
centerText: true,
lazy: true,
overlayPlayButton: true
});
}
2016-03-18 12:43:17 -07:00
2016-06-04 10:14:03 -07:00
var i, length;
2016-06-14 13:59:30 -07:00
var elems = tabContent.querySelectorAll('.paging');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].innerHTML = pagingHtml;
2016-06-04 10:14:03 -07:00
}
2016-03-18 12:43:17 -07:00
2016-06-14 13:59:30 -07:00
function onNextPageClick() {
2016-04-25 19:32:06 -07:00
query.StartIndex += query.Limit;
reloadItems(tabContent);
2016-06-14 13:59:30 -07:00
}
2016-03-18 12:43:17 -07:00
2016-06-14 13:59:30 -07:00
function onPreviousPageClick() {
2016-04-25 19:32:06 -07:00
query.StartIndex -= query.Limit;
reloadItems(tabContent);
2016-06-14 13:59:30 -07:00
}
elems = tabContent.querySelectorAll('.btnNextPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onNextPageClick);
}
elems = tabContent.querySelectorAll('.btnPreviousPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onPreviousPageClick);
}
2016-03-18 12:43:17 -07:00
2016-04-25 19:32:06 -07:00
var itemsContainer = tabContent.querySelector('.itemsContainer');
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
2016-03-18 12:43:17 -07:00
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
2016-03-18 12:43:17 -07:00
Dashboard.hideLoadingMsg();
});
}
self.showFilterMenu = function () {
2016-03-18 12:43:17 -07:00
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
var filterDialog = new filterDialogFactory({
query: getQuery(tabContent),
2016-03-18 12:43:17 -07:00
mode: 'series'
});
Events.on(filterDialog, 'filterchange', function () {
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
2016-03-18 12:43:17 -07:00
});
filterDialog.show();
});
}
function updateFilterControls(tabContent) {
var query = getQuery(tabContent);
2016-06-06 22:42:26 -07:00
self.alphaPicker.value(query.NameStartsWithOrGreater);
2016-03-18 12:43:17 -07:00
}
function initPage(tabContent) {
2016-06-06 22:42:26 -07:00
var alphaPickerElement = tabContent.querySelector('.alphaPicker');
alphaPickerElement.addEventListener('alphavaluechanged', function (e) {
var newValue = e.detail.value;
2016-03-18 12:43:17 -07:00
var query = getQuery(tabContent);
2016-06-06 22:42:26 -07:00
query.NameStartsWithOrGreater = newValue;
2016-03-18 12:43:17 -07:00
query.StartIndex = 0;
reloadItems(tabContent);
2016-06-06 22:42:26 -07:00
});
2016-03-18 12:43:17 -07:00
2016-06-06 22:42:26 -07:00
self.alphaPicker = new alphaPicker({
2016-06-07 22:24:25 -07:00
element: alphaPickerElement,
valueChangeEvent: 'click'
});
2016-03-18 12:43:17 -07:00
tabContent.querySelector('.btnFilter').addEventListener('click', function () {
self.showFilterMenu();
});
2016-04-25 11:33:17 -07:00
tabContent.querySelector('.btnSort').addEventListener('click', function (e) {
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('OptionDatePlayed'),
id: 'DatePlayed,SortName'
},
{
name: Globalize.translate('OptionMetascore'),
id: 'Metascore,SortName'
},
{
name: Globalize.translate('OptionParentalRating'),
id: 'OfficialRating,SortName'
},
{
name: Globalize.translate('OptionPlayCount'),
id: 'PlayCount,SortName'
},
{
name: Globalize.translate('OptionReleaseDate'),
id: 'PremiereDate,SortName'
}],
callback: function () {
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
},
2016-04-25 11:33:17 -07:00
query: getQuery(tabContent),
button: e.target
});
});
2016-06-17 12:44:19 -07:00
var btnSelectView = tabContent.querySelector('.btnSelectView');
btnSelectView.addEventListener('click', function (e) {
libraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), 'Banner,List,Poster,PosterCard,Thumb,ThumbCard'.split(','));
});
2016-06-17 12:44:19 -07:00
btnSelectView.addEventListener('layoutchange', function (e) {
var viewStyle = e.detail.viewStyle;
getPageData(tabContent).view = viewStyle;
libraryBrowser.saveViewSetting(getSavedQueryKey(tabContent), viewStyle);
getQuery(tabContent).StartIndex = 0;
2016-03-18 12:43:17 -07:00
reloadItems(tabContent);
});
}
self.getCurrentViewStyle = function () {
return getPageData(tabContent).view;
};
2016-03-18 18:40:13 -07:00
initPage(tabContent);
2016-03-18 12:43:17 -07:00
self.renderTab = function () {
2016-04-25 19:32:06 -07:00
reloadItems(tabContent);
updateFilterControls(tabContent);
};
self.destroy = function () {
2016-03-18 12:43:17 -07:00
};
};
});