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

311 lines
10 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2015-07-06 09:40:55 -07:00
var data = {};
2016-02-26 12:02:53 -07:00
function getPageData(context) {
var key = getSavedQueryKey(context);
2015-07-06 09:40:55 -07:00
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "Movie",
Recursive: true,
2015-09-16 10:44:34 -07:00
Fields: "PrimaryImageAspectRatio,SortName,MediaSourceCount,SyncInfo",
2015-07-06 09:40:55 -07:00
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
Limit: LibraryBrowser.getDefaultPageSize()
2015-08-15 11:46:57 -07:00
},
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster')
2015-07-06 09:40:55 -07:00
};
pageData.query.ParentId = LibraryMenu.getTopParentId();
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
2015-08-15 11:46:57 -07:00
return pageData;
}
2016-02-26 12:02:53 -07:00
function getQuery(context) {
2015-08-15 11:46:57 -07:00
2016-02-26 12:02:53 -07:00
return getPageData(context).query;
2015-07-06 09:40:55 -07:00
}
2013-04-01 20:28:20 -07:00
2016-02-26 12:02:53 -07:00
function getSavedQueryKey(context) {
2014-05-01 19:54:33 -07:00
2016-02-26 12:02:53 -07:00
if (!context.savedQueryKey) {
context.savedQueryKey = LibraryBrowser.getSavedQueryKey('movies');
}
return context.savedQueryKey;
2014-05-01 19:54:33 -07:00
}
2016-02-26 12:02:53 -07:00
function reloadItems(context) {
2013-04-01 20:28:20 -07:00
Dashboard.showLoadingMsg();
2013-04-10 22:27:27 -07:00
var userId = Dashboard.getCurrentUserId();
2016-02-26 12:02:53 -07:00
var query = getQuery(context);
var view = getPageData(context).view;
2015-07-06 09:40:55 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getItems(userId, query).then(function (result) {
2013-05-17 12:18:54 -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-05-17 12:18:54 -07:00
2013-04-08 14:05:00 -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,
showLimit: false,
2015-08-25 19:13:28 -07:00
updatePageSizeSetting: false,
addLayoutButton: true,
sortButton: true,
2015-09-01 15:04:54 -07:00
currentLayout: view,
2016-02-15 08:51:08 -07:00
layouts: 'Banner,List,Poster,PosterCard,Thumb,ThumbCard,Timeline',
filterButton: true
2015-01-28 12:30:45 -07:00
});
2016-02-26 12:02:53 -07:00
context.querySelector('.listTopPaging').innerHTML = pagingHtml;
2013-04-08 14:05:00 -07:00
2016-02-26 12:02:53 -07:00
updateFilterControls(context);
2013-10-18 09:09:47 -07:00
2013-12-22 10:16:24 -07:00
if (view == "Thumb") {
html = LibraryBrowser.getPosterViewHtml({
2013-04-10 22:27:27 -07:00
items: result.Items,
2013-12-22 10:16:24 -07:00
shape: "backdrop",
preferThumb: true,
2014-08-01 19:34:45 -07:00
lazy: true,
2016-02-12 13:26:03 -07:00
showDetailsMenu: true,
overlayPlayButton: true
2013-04-10 22:27:27 -07:00
});
}
2014-11-10 20:41:19 -07:00
else if (view == "ThumbCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
lazy: true,
showTitle: true,
cardLayout: true,
2015-05-14 19:16:57 -07:00
showYear: true,
showDetailsMenu: true
2014-11-10 20:41:19 -07:00
});
}
2014-04-02 14:55:19 -07:00
else if (view == "Banner") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "banner",
preferBanner: true,
2015-05-14 19:16:57 -07:00
lazy: true,
showDetailsMenu: true
2014-04-02 14:55:19 -07:00
});
}
else if (view == "List") {
html = LibraryBrowser.getListViewHtml({
items: result.Items,
sortBy: query.SortBy
});
}
2013-04-10 22:27:27 -07:00
else if (view == "Poster") {
2013-12-22 10:16:24 -07:00
html = LibraryBrowser.getPosterViewHtml({
2013-04-04 21:15:00 -07:00
items: result.Items,
2013-12-22 10:16:24 -07:00
shape: "portrait",
2014-03-17 18:45:41 -07:00
centerText: true,
2014-08-01 19:34:45 -07:00
lazy: true,
2016-02-12 13:26:03 -07:00
showDetailsMenu: true,
overlayPlayButton: true
2013-04-08 14:05:00 -07:00
});
2013-05-15 05:05:07 -07:00
}
2014-11-11 21:51:40 -07:00
else if (view == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
showTitle: true,
showYear: true,
lazy: true,
2015-05-14 19:16:57 -07:00
cardLayout: true,
showDetailsMenu: true
2015-09-09 20:22:52 -07:00
});
2014-11-11 21:51:40 -07:00
}
2013-05-15 05:05:07 -07:00
else if (view == "Timeline") {
2014-01-02 14:21:06 -07:00
html = LibraryBrowser.getPosterViewHtml({
2013-05-15 05:05:07 -07:00
items: result.Items,
2014-01-02 14:21:06 -07:00
shape: "portrait",
showTitle: true,
2014-01-13 09:48:37 -07:00
timeline: true,
2014-03-17 18:45:41 -07:00
centerText: true,
2015-05-14 19:16:57 -07:00
lazy: true,
showDetailsMenu: true
2013-05-15 05:05:07 -07:00
});
2013-04-04 21:15:00 -07:00
}
2013-04-08 14:05:00 -07:00
2016-02-26 12:02:53 -07:00
var elem = context.querySelector('.itemsContainer');
2015-06-28 07:45:21 -07:00
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2013-04-01 20:28:20 -07:00
2016-02-26 12:02:53 -07:00
$('.btnNextPage', context).on('click', function () {
2013-04-15 15:03:05 -07:00
query.StartIndex += query.Limit;
2016-02-26 12:02:53 -07:00
reloadItems(context);
2013-04-15 15:03:05 -07:00
});
2016-02-26 12:02:53 -07:00
$('.btnPreviousPage', context).on('click', function () {
2013-04-15 15:03:05 -07:00
query.StartIndex -= query.Limit;
2016-02-26 12:02:53 -07:00
reloadItems(context);
2013-04-15 15:03:05 -07:00
});
2013-04-08 14:05:00 -07:00
2016-02-26 12:02:53 -07:00
$('.btnChangeLayout', context).on('layoutchange', function (e, layout) {
2015-10-02 11:30:27 -07:00
if (layout == 'Timeline') {
2016-02-26 12:02:53 -07:00
getQuery(context).SortBy = 'ProductionYear,PremiereDate,SortName';
getQuery(context).SortOrder = 'Descending';
2015-10-02 11:30:27 -07:00
}
2016-02-26 12:02:53 -07:00
getPageData(context).view = layout;
LibraryBrowser.saveViewSetting(getSavedQueryKey(context), layout);
reloadItems(context);
2016-02-15 08:51:08 -07:00
});
2016-02-26 12:02:53 -07:00
$('.btnFilter', context).on('click', function () {
showFilterMenu(context);
2015-08-25 19:13:28 -07:00
});
// On callback make sure to set StartIndex = 0
2016-02-26 12:02:53 -07:00
$('.btnSort', context).on('click', function () {
2015-08-25 19:13:28 -07:00
LibraryBrowser.showSortMenu({
items: [{
name: Globalize.translate('OptionNameSort'),
id: 'SortName'
},
{
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'
}],
callback: function () {
2016-02-26 12:02:53 -07:00
reloadItems(context);
2015-08-25 19:13:28 -07:00
},
query: query
});
});
2016-02-26 12:02:53 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(context), query);
2013-10-18 09:09:47 -07:00
2016-02-26 12:02:53 -07:00
LibraryBrowser.setLastRefreshed(context);
2015-08-15 11:17:22 -07:00
2013-04-01 20:28:20 -07:00
Dashboard.hideLoadingMsg();
});
2013-04-01 20:28:20 -07:00
}
2016-02-26 12:02:53 -07:00
function showFilterMenu(context) {
2013-10-18 09:09:47 -07:00
2016-02-15 08:51:08 -07:00
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
2013-10-18 09:09:47 -07:00
2016-02-15 08:51:08 -07:00
var filterDialog = new filterDialogFactory({
2016-02-26 12:02:53 -07:00
query: getQuery(context),
2016-02-15 08:51:08 -07:00
mode: 'movies'
});
2013-10-18 09:09:47 -07:00
2016-02-15 08:51:08 -07:00
Events.on(filterDialog, 'filterchange', function () {
2016-02-26 12:02:53 -07:00
reloadItems(context);
2016-02-15 08:51:08 -07:00
});
2013-10-18 09:09:47 -07:00
2016-02-15 08:51:08 -07:00
filterDialog.show();
2015-09-07 08:54:57 -07:00
});
2013-10-18 09:09:47 -07:00
}
2016-02-26 12:02:53 -07:00
function updateFilterControls(context) {
2016-02-26 12:02:53 -07:00
var query = getQuery(context);
2016-02-26 12:02:53 -07:00
$('.alphabetPicker', context).alphaValue(query.NameStartsWithOrGreater);
}
2016-02-26 12:02:53 -07:00
function initPage(context) {
2013-10-26 15:01:21 -07:00
2016-02-26 12:02:53 -07:00
$('.alphabetPicker', context).on('alphaselect', function (e, character) {
2016-02-26 12:02:53 -07:00
var query = getQuery(context);
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = character;
2013-05-17 11:05:49 -07:00
query.StartIndex = 0;
2016-02-26 12:02:53 -07:00
reloadItems(context);
2013-10-18 09:09:47 -07:00
}).on('alphaclear', function (e) {
2016-02-26 12:02:53 -07:00
var query = getQuery(context);
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = '';
2016-02-26 12:02:53 -07:00
reloadItems(context);
2013-12-01 19:24:14 -07:00
});
2016-02-26 12:02:53 -07:00
$('.itemsContainer', context).on('needsrefresh', function () {
2014-03-18 18:35:40 -07:00
2016-02-26 12:02:53 -07:00
reloadItems(context);
2014-03-18 18:35:40 -07:00
});
2015-08-15 11:30:52 -07:00
}
2015-08-18 09:11:56 -07:00
window.MoviesPage.initMoviesTab = function (page, tabContent) {
2015-08-15 11:30:52 -07:00
2016-02-15 08:51:08 -07:00
initPage(tabContent);
2015-08-18 09:11:56 -07:00
};
2015-08-15 11:30:52 -07:00
2015-08-18 09:11:56 -07:00
window.MoviesPage.renderMoviesTab = function (page, tabContent) {
2015-08-15 11:30:52 -07:00
2015-08-18 09:11:56 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
2016-02-15 08:51:08 -07:00
reloadItems(tabContent);
updateFilterControls(tabContent);
2015-08-18 09:11:56 -07:00
}
};
});