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

281 lines
9.7 KiB
JavaScript
Raw Normal View History

2016-06-17 11:50:01 -07:00
define(['events', 'libraryBrowser', 'imageLoader', 'alphaPicker'], function (events, libraryBrowser, imageLoader, alphaPicker) {
return function (view, params, tabContent) {
var self = this;
var pageSize = libraryBrowser.getDefaultPageSize();
var data = {};
function getPageData(context) {
var key = getSavedQueryKey(context);
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "Trailer",
Recursive: true,
2016-06-17 12:32:48 -07:00
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo",
2016-06-17 11:50:01 -07:00
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
Limit: pageSize
},
view: libraryBrowser.getSavedView(key) || libraryBrowser.getDefaultItemsView('Poster', 'Poster')
};
2013-04-17 10:04:57 -07:00
2016-06-17 11:50:01 -07:00
libraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData;
2015-08-15 11:17:22 -07:00
}
2013-04-17 10:04:57 -07:00
2016-06-17 11:50:01 -07:00
function getQuery(context) {
2014-10-20 13:23:40 -07:00
2016-06-17 11:50:01 -07:00
return getPageData(context).query;
2016-02-26 12:02:53 -07:00
}
2014-10-20 13:23:40 -07:00
2016-06-17 11:50:01 -07:00
function getSavedQueryKey(context) {
2013-04-17 10:04:57 -07:00
2016-06-17 11:50:01 -07:00
if (!context.savedQueryKey) {
context.savedQueryKey = libraryBrowser.getSavedQueryKey('trailers');
}
return context.savedQueryKey;
}
2013-04-17 10:04:57 -07:00
2016-06-17 11:50:01 -07:00
function reloadItems(page) {
2014-10-20 13:23:40 -07:00
2016-06-17 11:50:01 -07:00
Dashboard.showLoadingMsg();
2013-04-17 10:04:57 -07:00
2016-06-17 11:50:01 -07:00
var query = getQuery(page);
2013-05-17 12:18:54 -07:00
2016-06-17 11:50:01 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
// Scroll back up so they can see the results from the beginning
window.scrollTo(0, 0);
updateFilterControls(page);
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
updatePageSizeSetting: false,
addLayoutButton: false,
sortButton: false,
filterButton: false
});
var html;
var viewStyle = self.getCurrentViewStyle();
if (viewStyle == "Thumb") {
html = libraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'movies',
lazy: true,
overlayPlayButton: true
});
}
else if (viewStyle == "ThumbCard") {
html = libraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'movies',
lazy: true,
cardLayout: true,
showTitle: true,
showYear: true
});
}
else if (viewStyle == "Banner") {
html = libraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "banner",
preferBanner: true,
context: 'movies',
lazy: true
});
}
else if (viewStyle == "List") {
html = libraryBrowser.getListViewHtml({
items: result.Items,
context: 'movies',
sortBy: query.SortBy
});
}
else if (viewStyle == "PosterCard") {
html = libraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'movies',
showTitle: true,
showYear: true,
lazy: true,
cardLayout: true
});
}
else {
// Poster
html = libraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'movies',
centerText: true,
lazy: true,
overlayPlayButton: true
});
}
var i, length;
var elems = tabContent.querySelectorAll('.paging');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].innerHTML = pagingHtml;
}
function onNextPageClick() {
query.StartIndex += query.Limit;
reloadItems(tabContent);
}
function onPreviousPageClick() {
query.StartIndex -= query.Limit;
reloadItems(tabContent);
}
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);
}
2014-10-20 13:23:40 -07:00
2016-06-17 11:50:01 -07:00
if (!items.length) {
html = '<p style="text-align:center;">' + Globalize.translate('MessageNoTrailersFound') + '</p>';
}
var itemsContainer = tabContent.querySelector('.itemsContainer');
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
Dashboard.hideLoadingMsg();
2015-01-28 12:30:45 -07:00
});
2016-06-17 11:50:01 -07:00
}
2015-01-28 12:30:45 -07:00
2016-06-17 11:50:01 -07:00
self.showFilterMenu = function () {
2013-04-17 10:04:57 -07:00
2016-06-17 11:50:01 -07:00
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
2013-10-18 09:09:47 -07:00
2016-06-17 11:50:01 -07:00
var filterDialog = new filterDialogFactory({
2016-06-17 17:52:04 -07:00
query: getQuery(tabContent),
mode: 'movies'
2016-06-17 11:50:01 -07:00
});
Events.on(filterDialog, 'filterchange', function () {
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
});
filterDialog.show();
});
2016-06-17 11:50:01 -07:00
}
2016-06-17 11:50:01 -07:00
function updateFilterControls(tabContent) {
2013-04-17 10:04:57 -07:00
2016-06-17 11:50:01 -07:00
var query = getQuery(tabContent);
self.alphaPicker.value(query.NameStartsWithOrGreater);
}
function initPage(tabContent) {
var alphaPickerElement = tabContent.querySelector('.alphaPicker');
alphaPickerElement.addEventListener('alphavaluechanged', function (e) {
var newValue = e.detail.value;
var query = getQuery(tabContent);
query.NameStartsWithOrGreater = newValue;
query.StartIndex = 0;
reloadItems(tabContent);
2013-04-17 10:04:57 -07:00
});
2016-06-17 11:50:01 -07:00
self.alphaPicker = new alphaPicker({
element: alphaPickerElement,
valueChangeEvent: 'click'
2016-02-15 06:43:22 -07:00
});
2016-06-17 11:50:01 -07:00
tabContent.querySelector('.btnFilter').addEventListener('click', function () {
self.showFilterMenu();
2013-04-17 10:04:57 -07:00
});
2016-06-17 11:50:01 -07:00
tabContent.querySelector('.btnSort').addEventListener('click', function (e) {
libraryBrowser.showSortMenu({
2015-08-25 19:13:28 -07:00
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('OptionParentalRating'),
id: 'OfficialRating,SortName'
},
{
name: Globalize.translate('OptionPlayCount'),
id: 'PlayCount,SortName'
},
{
name: Globalize.translate('OptionReleaseDate'),
id: 'PremiereDate,SortName'
}],
callback: function () {
2016-06-17 11:50:01 -07:00
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
2015-08-25 19:13:28 -07:00
},
2016-06-17 11:50:01 -07:00
query: getQuery(tabContent),
button: e.target
2015-08-25 19:13:28 -07:00
});
});
2016-06-17 11:50:01 -07:00
}
2015-08-25 19:13:28 -07:00
2016-06-17 11:50:01 -07:00
self.getCurrentViewStyle = function () {
return getPageData(tabContent).view;
2016-04-03 11:47:49 -07:00
};
2016-06-17 11:50:01 -07:00
initPage(tabContent);
2016-04-03 11:47:49 -07:00
self.renderTab = function () {
2015-08-15 11:30:52 -07:00
2016-02-15 06:43:22 -07:00
reloadItems(tabContent);
updateFilterControls(tabContent);
2016-04-03 11:47:49 -07:00
};
2013-04-17 10:04:57 -07:00
2016-06-17 11:50:01 -07:00
self.destroy = function () {
};
};
});