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

314 lines
11 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2016-04-03 11:47:49 -07:00
return function (view, params, tabContent) {
var self = this;
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,
Fields: "PrimaryImageAspectRatio,SortName,MediaSourceCount,SyncInfo",
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
Limit: LibraryBrowser.getDefaultPageSize()
},
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster')
};
pageData.query.ParentId = params.topParentId;
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
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) {
context.savedQueryKey = LibraryBrowser.getSavedQueryKey('movies');
}
return context.savedQueryKey;
2016-02-26 12:02:53 -07:00
}
2014-05-01 19:54:33 -07:00
2016-04-03 11:47:49 -07:00
function reloadItems(context) {
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-04-03 11:47:49 -07:00
var userId = Dashboard.getCurrentUserId();
2016-04-03 11:47:49 -07:00
var query = getQuery(context);
var view = getPageData(context).view;
ApiClient.getItems(userId, query).then(function (result) {
// Scroll back up so they can see the results from the beginning
window.scrollTo(0, 0);
var html = '';
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
updatePageSizeSetting: false,
addLayoutButton: true,
sortButton: true,
currentLayout: view,
layouts: 'Banner,List,Poster,PosterCard,Thumb,ThumbCard,Timeline',
filterButton: true
});
2016-04-03 11:47:49 -07:00
context.querySelector('.listTopPaging').innerHTML = pagingHtml;
2013-05-17 12:18:54 -07:00
2016-04-03 11:47:49 -07:00
updateFilterControls(context);
2013-04-08 14:05:00 -07:00
2016-04-03 11:47:49 -07:00
if (view == "Thumb") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
lazy: true,
showDetailsMenu: true,
overlayPlayButton: true
});
}
else if (view == "ThumbCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
lazy: true,
showTitle: true,
cardLayout: true,
showYear: true,
showDetailsMenu: true
});
}
else if (view == "Banner") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "banner",
preferBanner: true,
lazy: true,
showDetailsMenu: true
});
}
else if (view == "List") {
2015-01-28 12:30:45 -07:00
2016-04-03 11:47:49 -07:00
html = LibraryBrowser.getListViewHtml({
items: result.Items,
sortBy: query.SortBy
});
}
else if (view == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
centerText: true,
lazy: true,
showDetailsMenu: true,
overlayPlayButton: true
});
}
else if (view == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
showTitle: true,
showYear: true,
lazy: true,
cardLayout: true,
showDetailsMenu: true
});
}
else if (view == "Timeline") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
showTitle: true,
timeline: true,
centerText: true,
lazy: true,
showDetailsMenu: true
});
}
2013-04-08 14:05:00 -07:00
2016-04-03 11:47:49 -07:00
var elem = context.querySelector('.itemsContainer');
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2013-10-18 09:09:47 -07:00
2016-04-03 11:47:49 -07:00
$('.btnNextPage', context).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(context);
2014-11-10 20:41:19 -07:00
});
2016-04-03 11:47:49 -07:00
$('.btnPreviousPage', context).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(context);
});
2013-04-08 14:05:00 -07:00
2016-04-03 11:47:49 -07:00
$('.btnChangeLayout', context).on('layoutchange', function (e, layout) {
2013-04-01 20:28:20 -07:00
2016-04-03 11:47:49 -07:00
if (layout == 'Timeline') {
getQuery(context).SortBy = 'ProductionYear,PremiereDate,SortName';
getQuery(context).SortOrder = 'Descending';
}
2013-04-15 15:03:05 -07:00
2016-04-03 11:47:49 -07:00
getPageData(context).view = layout;
LibraryBrowser.saveViewSetting(getSavedQueryKey(context), layout);
reloadItems(context);
});
2013-04-08 14:05:00 -07:00
2016-04-03 11:47:49 -07:00
$('.btnFilter', context).on('click', function () {
showFilterMenu(context);
});
2015-10-02 11:30:27 -07:00
2016-04-03 11:47:49 -07:00
// On callback make sure to set StartIndex = 0
$('.btnSort', context).on('click', function () {
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 () {
reloadItems(context);
},
query: query
});
});
2015-10-02 11:30:27 -07:00
2016-04-03 11:47:49 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(context), query);
2016-02-15 08:51:08 -07:00
2016-04-03 11:47:49 -07:00
LibraryBrowser.setLastRefreshed(context);
2015-08-25 19:13:28 -07:00
2016-04-03 11:47:49 -07:00
Dashboard.hideLoadingMsg();
2015-08-25 19:13:28 -07:00
});
2016-04-03 11:47:49 -07:00
}
2015-08-25 19:13:28 -07:00
2016-04-03 11:47:49 -07:00
function showFilterMenu(context) {
2016-04-03 11:47:49 -07:00
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
2013-10-18 09:09:47 -07:00
2016-04-03 11:47:49 -07:00
var filterDialog = new filterDialogFactory({
query: getQuery(context),
mode: 'movies'
});
2013-10-18 09:09:47 -07:00
2016-04-03 11:47:49 -07:00
Events.on(filterDialog, 'filterchange', function () {
reloadItems(context);
});
2013-10-18 09:09:47 -07:00
2016-04-03 11:47:49 -07:00
filterDialog.show();
2016-02-15 08:51:08 -07:00
});
2016-04-03 11:47:49 -07:00
}
2013-10-18 09:09:47 -07:00
2016-04-03 11:47:49 -07:00
function updateFilterControls(context) {
2016-04-03 11:47:49 -07:00
var query = getQuery(context);
2016-04-03 11:47:49 -07:00
$('.alphabetPicker', context).alphaValue(query.NameStartsWithOrGreater);
}
2016-04-03 11:47:49 -07:00
function initPage(context) {
2013-10-26 15:01:21 -07:00
2016-04-03 11:47:49 -07:00
$('.alphabetPicker', context).on('alphaselect', function (e, character) {
2016-04-03 11:47:49 -07:00
var query = getQuery(context);
query.NameStartsWithOrGreater = character;
query.StartIndex = 0;
2016-04-03 11:47:49 -07:00
reloadItems(context);
2013-10-18 09:09:47 -07:00
2016-04-03 11:47:49 -07:00
}).on('alphaclear', function (e) {
2016-04-03 11:47:49 -07:00
var query = getQuery(context);
query.NameStartsWithOrGreater = '';
2016-04-03 11:47:49 -07:00
reloadItems(context);
});
2013-12-01 19:24:14 -07:00
2016-04-03 11:47:49 -07:00
$('.itemsContainer', context).on('needsrefresh', function () {
2014-03-18 18:35:40 -07:00
2016-04-03 11:47:49 -07:00
reloadItems(context);
});
}
2015-08-15 11:30:52 -07:00
2016-04-03 11:47:49 -07:00
self.initTab = function () {
2015-08-15 11:30:52 -07:00
2016-04-03 11:47:49 -07:00
initPage(tabContent);
};
2015-08-15 11:30:52 -07:00
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
};
2015-08-18 09:11:56 -07:00
};
});