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

318 lines
11 KiB
JavaScript
Raw Normal View History

2016-06-17 11:40:57 -07:00
define(['events', 'libraryBrowser', 'imageLoader', 'alphaPicker'], function (events, libraryBrowser, imageLoader, alphaPicker) {
2016-04-03 11:47:49 -07:00
return function (view, params, tabContent) {
var self = this;
2016-06-17 11:40:57 -07:00
var pageSize = libraryBrowser.getDefaultPageSize();
2016-04-03 11:47:49 -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: "Movie",
Recursive: true,
2016-06-17 11:40:57 -07:00
Fields: "PrimaryImageAspectRatio,MediaSourceCount,SortName,SyncInfo",
2016-04-03 11:47:49 -07:00
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
2016-06-17 11:40:57 -07:00
Limit: pageSize
2016-04-03 11:47:49 -07:00
},
2016-06-17 11:40:57 -07:00
view: libraryBrowser.getSavedView(key) || libraryBrowser.getDefaultItemsView('Poster', 'Poster')
2016-04-03 11:47:49 -07:00
};
pageData.query.ParentId = params.topParentId;
2016-06-17 11:40:57 -07:00
libraryBrowser.loadSavedQueryValues(key, pageData.query);
2016-04-03 11:47:49 -07:00
}
return pageData;
2015-07-06 09:40:55 -07:00
}
2015-08-15 11:46:57 -07:00
2016-04-03 11:47:49 -07:00
function getQuery(context) {
2015-08-15 11:46:57 -07:00
2016-04-03 11:47:49 -07:00
return getPageData(context).query;
}
2013-04-01 20:28:20 -07:00
2016-04-03 11:47:49 -07:00
function getSavedQueryKey(context) {
2014-05-01 19:54:33 -07:00
2016-04-03 11:47:49 -07:00
if (!context.savedQueryKey) {
2016-06-17 11:40:57 -07:00
context.savedQueryKey = libraryBrowser.getSavedQueryKey('movies');
2016-04-03 11:47:49 -07:00
}
return context.savedQueryKey;
2016-02-26 12:02:53 -07:00
}
2014-05-01 19:54:33 -07:00
2016-06-17 11:40:57 -07:00
function reloadItems(page) {
2013-04-01 20:28:20 -07:00
2016-04-03 11:47:49 -07:00
Dashboard.showLoadingMsg();
2013-04-10 22:27:27 -07:00
2016-06-17 11:40:57 -07:00
var query = getQuery(page);
2016-06-17 11:40:57 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
2016-04-03 11:47:49 -07:00
// Scroll back up so they can see the results from the beginning
window.scrollTo(0, 0);
2016-06-17 11:40:57 -07:00
updateFilterControls(page);
2016-04-03 11:47:49 -07:00
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
updatePageSizeSetting: false,
2016-06-17 11:40:57 -07:00
addLayoutButton: false,
sortButton: false,
filterButton: false
2016-04-03 11:47:49 -07:00
});
2016-06-17 11:40:57 -07:00
var html;
var viewStyle = self.getCurrentViewStyle();
2013-05-17 12:18:54 -07:00
2016-06-17 11:40:57 -07:00
if (viewStyle == "Thumb") {
2013-04-08 14:05:00 -07:00
2016-06-17 11:40:57 -07:00
html = libraryBrowser.getPosterViewHtml({
2016-04-03 11:47:49 -07:00
items: result.Items,
shape: "backdrop",
preferThumb: true,
2016-06-17 11:40:57 -07:00
context: 'movies',
2016-04-03 11:47:49 -07:00
lazy: true,
overlayPlayButton: true
});
}
2016-06-17 11:40:57 -07:00
else if (viewStyle == "ThumbCard") {
2016-04-03 11:47:49 -07:00
2016-06-17 11:40:57 -07:00
html = libraryBrowser.getPosterViewHtml({
2016-04-03 11:47:49 -07:00
items: result.Items,
shape: "backdrop",
preferThumb: true,
2016-06-17 11:40:57 -07:00
context: 'movies',
2016-04-03 11:47:49 -07:00
lazy: true,
cardLayout: true,
2016-06-17 11:40:57 -07:00
showTitle: true,
showYear: true
2016-04-03 11:47:49 -07:00
});
}
2016-06-17 11:40:57 -07:00
else if (viewStyle == "Banner") {
2016-04-03 11:47:49 -07:00
2016-06-17 11:40:57 -07:00
html = libraryBrowser.getPosterViewHtml({
2016-04-03 11:47:49 -07:00
items: result.Items,
shape: "banner",
preferBanner: true,
2016-06-17 11:40:57 -07:00
context: 'movies',
lazy: true
2016-04-03 11:47:49 -07:00
});
}
2016-06-17 11:40:57 -07:00
else if (viewStyle == "List") {
2015-01-28 12:30:45 -07:00
2016-06-17 11:40:57 -07:00
html = libraryBrowser.getListViewHtml({
2016-04-03 11:47:49 -07:00
items: result.Items,
2016-06-17 11:40:57 -07:00
context: 'movies',
2016-04-03 11:47:49 -07:00
sortBy: query.SortBy
});
}
2016-06-17 11:40:57 -07:00
else if (viewStyle == "PosterCard") {
html = libraryBrowser.getPosterViewHtml({
2016-04-03 11:47:49 -07:00
items: result.Items,
shape: "portrait",
2016-06-17 11:40:57 -07:00
context: 'movies',
2016-04-03 11:47:49 -07:00
showTitle: true,
showYear: true,
lazy: true,
2016-06-17 11:40:57 -07:00
cardLayout: true
2016-04-03 11:47:49 -07:00
});
}
2016-06-17 11:40:57 -07:00
else {
// Poster
html = libraryBrowser.getPosterViewHtml({
2016-04-03 11:47:49 -07:00
items: result.Items,
shape: "portrait",
2016-06-17 11:40:57 -07:00
context: 'movies',
2016-04-03 11:47:49 -07:00
centerText: true,
lazy: true,
2016-06-17 11:40:57 -07:00
overlayPlayButton: true
2016-04-03 11:47:49 -07:00
});
}
2013-04-08 14:05:00 -07:00
2016-06-17 11:40:57 -07:00
var i, length;
var elems = tabContent.querySelectorAll('.paging');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].innerHTML = pagingHtml;
}
2013-10-18 09:09:47 -07:00
2016-06-14 13:59:30 -07:00
function onNextPageClick() {
2016-04-03 11:47:49 -07:00
query.StartIndex += query.Limit;
2016-06-14 13:59:30 -07:00
reloadItems(tabContent);
}
2016-06-14 13:59:30 -07:00
function onPreviousPageClick() {
2016-04-03 11:47:49 -07:00
query.StartIndex -= query.Limit;
2016-06-14 13:59:30 -07:00
reloadItems(tabContent);
}
2013-04-08 14:05:00 -07:00
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);
}
2013-04-01 20:28:20 -07:00
2016-06-17 11:40:57 -07:00
var itemsContainer = tabContent.querySelector('.itemsContainer');
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
2013-04-15 15:03:05 -07:00
2016-06-17 11:40:57 -07:00
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
2013-04-08 14:05:00 -07:00
2016-06-17 11:40:57 -07:00
Dashboard.hideLoadingMsg();
});
}
2016-06-14 13:59:30 -07:00
2016-06-17 11:40:57 -07:00
self.showFilterMenu = function () {
2016-06-14 13:59:30 -07:00
2016-06-17 11:40:57 -07:00
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
2015-10-02 11:30:27 -07:00
2016-06-17 11:40:57 -07:00
var filterDialog = new filterDialogFactory({
query: getQuery(tabContent),
mode: 'movies'
});
Events.on(filterDialog, 'filterchange', function () {
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
});
filterDialog.show();
});
}
function updateFilterControls(tabContent) {
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);
});
self.alphaPicker = new alphaPicker({
element: alphaPickerElement,
valueChangeEvent: 'click'
});
tabContent.querySelector('.btnFilter').addEventListener('click', function () {
self.showFilterMenu();
});
tabContent.querySelector('.btnSort').addEventListener('click', function (e) {
libraryBrowser.showSortMenu({
items: [{
name: Globalize.translate('OptionNameSort'),
id: 'SortName'
},
2016-04-03 11:47:49 -07:00
{
name: Globalize.translate('OptionBudget'),
id: 'Budget,SortName'
},
{
name: Globalize.translate('OptionImdbRating'),
id: 'CommunityRating,SortName'
},
{
name: Globalize.translate('OptionCriticRating'),
id: 'CriticRating,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'
},
{
name: Globalize.translate('OptionRevenue'),
id: 'Revenue,SortName'
},
{
name: Globalize.translate('OptionRuntime'),
id: 'Runtime,SortName'
},
{
name: Globalize.translate('OptionVideoBitrate'),
id: 'VideoBitRate,SortName'
}],
2016-06-17 11:40:57 -07:00
callback: function () {
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
},
query: getQuery(tabContent),
button: e.target
2016-04-03 11:47:49 -07:00
});
2016-02-15 08:51:08 -07:00
});
2013-10-18 09:09:47 -07:00
2016-06-17 12:44:19 -07:00
var btnSelectView = tabContent.querySelector('.btnSelectView');
btnSelectView.addEventListener('click', function (e) {
2016-06-17 11:40:57 -07:00
libraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), 'Banner,List,Poster,PosterCard,Thumb,ThumbCard'.split(','));
2016-06-06 22:42:26 -07:00
});
2013-10-18 09:09:47 -07:00
2016-06-17 12:44:19 -07:00
btnSelectView.addEventListener('layoutchange', function (e) {
2013-12-01 19:24:14 -07:00
2016-06-17 11:40:57 -07:00
var viewStyle = e.detail.viewStyle;
2014-03-18 18:35:40 -07:00
2016-06-17 11:40:57 -07:00
getPageData(tabContent).view = viewStyle;
libraryBrowser.saveViewSetting(getSavedQueryKey(tabContent), viewStyle);
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
2016-04-03 11:47:49 -07:00
});
}
2015-08-15 11:30:52 -07:00
2016-06-17 11:40:57 -07:00
self.getCurrentViewStyle = function () {
return getPageData(tabContent).view;
2016-04-03 11:47:49 -07:00
};
2015-08-15 11:30:52 -07:00
2016-06-17 11:40:57 -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 08:51:08 -07:00
reloadItems(tabContent);
updateFilterControls(tabContent);
2016-04-03 11:47:49 -07:00
};
2016-06-17 11:40:57 -07:00
self.destroy = function () {
};
};
});