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

419 lines
13 KiB
JavaScript
Raw Normal View History

(function ($, document) {
2015-07-06 09:40:55 -07:00
var data = {};
2015-08-15 11:46:57 -07:00
function getPageData() {
2015-07-06 09:40:55 -07:00
var key = getSavedQueryKey();
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;
}
function getQuery() {
return getPageData().query;
2015-07-06 09:40:55 -07:00
}
2013-04-01 20:28:20 -07:00
2014-05-01 19:54:33 -07:00
function getSavedQueryKey() {
2015-09-03 11:07:15 -07:00
return getWindowUrl() + 'movies';
2014-05-01 19:54:33 -07:00
}
2015-08-15 11:17:22 -07:00
function reloadItems(page, viewPanel) {
2013-04-01 20:28:20 -07:00
Dashboard.showLoadingMsg();
2013-04-10 22:27:27 -07:00
var userId = Dashboard.getCurrentUserId();
2015-07-06 09:40:55 -07:00
var query = getQuery();
2015-08-15 11:46:57 -07:00
var view = getPageData().view;
2015-07-06 09:40:55 -07:00
ApiClient.getItems(userId, query).done(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,
viewButton: true,
showLimit: false,
2015-08-25 19:13:28 -07:00
viewPanelClass: 'movieViewPanel',
updatePageSizeSetting: false,
addLayoutButton: true,
viewIcon: 'filter-list',
sortButton: true,
2015-09-01 15:04:54 -07:00
currentLayout: view,
2015-09-08 10:06:58 -07:00
layouts: 'Banner,List,Poster,PosterCard,Thumb,ThumbCard,Timeline'
2015-01-28 12:30:45 -07:00
});
2015-06-28 07:45:21 -07:00
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
2013-04-08 14:05:00 -07:00
2013-10-18 09:09:47 -07:00
updateFilterControls(page);
2015-01-22 23:15:15 -07:00
var trigger = false;
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,
2015-05-14 19:16:57 -07:00
showDetailsMenu: 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
});
2015-01-22 23:15:15 -07:00
trigger = true;
}
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,
2015-05-14 19:16:57 -07:00
showDetailsMenu: 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
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('.itemsContainer');
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2013-04-01 20:28:20 -07:00
2015-01-22 23:15:15 -07:00
if (trigger) {
2015-06-28 07:45:21 -07:00
Events.trigger(elem, 'create');
2015-01-22 23:15:15 -07:00
}
2013-04-08 14:05:00 -07:00
2013-04-18 22:08:18 -07:00
$('.btnNextPage', page).on('click', function () {
2013-04-15 15:03:05 -07:00
query.StartIndex += query.Limit;
2015-08-15 11:17:22 -07:00
reloadItems(page, viewPanel);
2013-04-15 15:03:05 -07:00
});
2013-04-18 22:08:18 -07:00
$('.btnPreviousPage', page).on('click', function () {
2013-04-15 15:03:05 -07:00
query.StartIndex -= query.Limit;
2015-08-15 11:17:22 -07:00
reloadItems(page, viewPanel);
2013-04-15 15:03:05 -07:00
});
2013-04-08 14:05:00 -07:00
2015-08-25 19:13:28 -07:00
$('.btnChangeLayout', page).on('layoutchange', function (e, layout) {
2015-10-02 11:30:27 -07:00
if (layout == 'Timeline') {
getQuery().SortBy = 'PremiereDate,SortName';
getQuery().SortOrder = 'Descending';
}
2015-08-25 19:13:28 -07:00
getPageData().view = layout;
2015-08-26 11:17:38 -07:00
LibraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
2015-09-08 07:35:52 -07:00
reloadItems(page, viewPanel);
2015-08-25 19:13:28 -07:00
});
// On callback make sure to set StartIndex = 0
$('.btnSort', page).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(page, viewPanel);
},
query: query
});
});
2014-05-01 19:54:33 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2013-10-18 09:09:47 -07:00
2015-07-06 09:40:55 -07:00
LibraryBrowser.setLastRefreshed(page);
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
}
2015-08-15 11:17:22 -07:00
function updateFilterControls(tabContent, viewPanel) {
2013-10-18 09:09:47 -07:00
2015-07-06 09:40:55 -07:00
var query = getQuery();
2013-10-18 09:09:47 -07:00
2015-08-15 11:17:22 -07:00
$('.chkStandardFilter', viewPanel).each(function () {
2013-10-18 09:09:47 -07:00
var filters = "," + (query.Filters || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
2015-09-07 08:54:57 -07:00
});
2013-10-18 09:09:47 -07:00
2015-08-15 11:17:22 -07:00
$('.chkVideoTypeFilter', viewPanel).each(function () {
2013-10-18 09:09:47 -07:00
var filters = "," + (query.VideoTypes || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
2015-09-07 08:54:57 -07:00
});
2013-10-18 09:09:47 -07:00
2015-09-07 08:54:57 -07:00
$('.chk3DFilter', viewPanel).checked(query.Is3D == true);
$('.chkHDFilter', viewPanel).checked(query.IsHD == true);
$('.chkSDFilter', viewPanel).checked(query.IsHD == false);
2013-10-18 09:09:47 -07:00
2015-08-15 11:17:22 -07:00
$('.alphabetPicker', tabContent).alphaValue(query.NameStartsWithOrGreater);
2013-10-18 09:09:47 -07:00
}
2015-08-15 11:17:22 -07:00
function reloadFiltersIfNeeded(tabContent, viewPanel) {
2015-09-03 11:07:15 -07:00
if (!getPageData().filtersLoaded) {
2015-09-03 11:07:15 -07:00
getPageData().filtersLoaded = true;
2015-07-06 09:40:55 -07:00
var query = getQuery();
2015-08-15 11:17:22 -07:00
QueryFilters.loadFilters(viewPanel, Dashboard.getCurrentUserId(), query, function () {
2015-08-15 11:17:22 -07:00
reloadItems(tabContent, viewPanel);
});
}
}
2015-08-15 11:30:52 -07:00
function initPage(tabContent, viewPanel) {
2015-08-15 11:17:22 -07:00
$(viewPanel).on('panelopen', function () {
reloadFiltersIfNeeded(tabContent, viewPanel);
});
$('.chkStandardFilter', viewPanel).on('change', function () {
2013-04-01 20:28:20 -07:00
2015-07-06 09:40:55 -07:00
var query = getQuery();
2013-04-01 20:28:20 -07:00
var filterName = this.getAttribute('data-filter');
var filters = query.Filters || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
2013-04-08 14:05:00 -07:00
query.StartIndex = 0;
2013-04-01 20:28:20 -07:00
query.Filters = filters;
2015-08-15 11:17:22 -07:00
reloadItems(tabContent, viewPanel);
2013-04-01 20:28:20 -07:00
});
2015-08-15 11:17:22 -07:00
$('.chkVideoTypeFilter', viewPanel).on('change', function () {
2014-03-02 13:44:48 -07:00
2015-07-06 09:40:55 -07:00
var query = getQuery();
2014-03-02 13:44:48 -07:00
var filterName = this.getAttribute('data-filter');
var filters = query.VideoTypes || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
query.StartIndex = 0;
query.VideoTypes = filters;
2015-08-15 11:17:22 -07:00
reloadItems(tabContent, viewPanel);
2014-03-02 13:44:48 -07:00
});
2015-08-27 12:59:42 -07:00
$('.chk3DFilter', viewPanel).on('change', function () {
2013-04-07 06:34:46 -07:00
2015-07-06 09:40:55 -07:00
var query = getQuery();
2013-04-08 14:05:00 -07:00
query.StartIndex = 0;
2013-07-11 06:56:09 -07:00
query.Is3D = this.checked ? true : null;
2013-04-07 06:34:46 -07:00
2015-08-15 11:17:22 -07:00
reloadItems(tabContent, viewPanel);
2013-04-07 06:34:46 -07:00
});
2013-05-15 05:05:07 -07:00
2015-08-27 12:59:42 -07:00
$('.chkHDFilter', viewPanel).on('change', function () {
2013-10-26 15:01:21 -07:00
2015-07-06 09:40:55 -07:00
var query = getQuery();
2013-10-26 15:01:21 -07:00
query.StartIndex = 0;
query.IsHD = this.checked ? true : null;
2015-08-15 11:17:22 -07:00
reloadItems(tabContent, viewPanel);
2013-10-26 15:01:21 -07:00
});
2015-08-27 12:59:42 -07:00
$('.chkSDFilter', viewPanel).on('change', function () {
2013-10-26 15:01:21 -07:00
2015-07-06 09:40:55 -07:00
var query = getQuery();
2013-10-26 15:01:21 -07:00
query.StartIndex = 0;
query.IsHD = this.checked ? false : null;
2015-08-15 11:17:22 -07:00
reloadItems(tabContent, viewPanel);
2013-10-26 15:01:21 -07:00
});
2015-08-15 11:17:22 -07:00
$('.alphabetPicker', tabContent).on('alphaselect', function (e, character) {
2015-07-06 09:40:55 -07:00
var query = getQuery();
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = character;
2013-05-17 11:05:49 -07:00
query.StartIndex = 0;
2015-08-15 11:17:22 -07:00
reloadItems(tabContent, viewPanel);
2013-10-18 09:09:47 -07:00
}).on('alphaclear', function (e) {
2015-07-06 09:40:55 -07:00
var query = getQuery();
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = '';
2015-08-15 11:17:22 -07:00
reloadItems(tabContent, viewPanel);
});
2013-04-07 06:34:46 -07:00
2015-08-15 11:17:22 -07:00
$('.radioBasicFilters', viewPanel).on('change', function () {
2013-12-01 19:24:14 -07:00
if (this.checked) {
2015-08-15 11:17:22 -07:00
$('.basicFilters', viewPanel).show();
$('.advancedFilters', viewPanel).hide();
2013-12-01 19:24:14 -07:00
} else {
2015-08-15 11:17:22 -07:00
$('.basicFilters', viewPanel).hide();
2013-12-01 19:24:14 -07:00
}
});
2015-08-15 11:17:22 -07:00
$('.radioAdvancedFilters', viewPanel).on('change', function () {
2013-12-01 19:24:14 -07:00
if (this.checked) {
2015-08-15 11:17:22 -07:00
$('.advancedFilters', viewPanel).show();
$('.basicFilters', viewPanel).hide();
2013-12-01 19:24:14 -07:00
} else {
2015-08-15 11:17:22 -07:00
$('.advancedFilters', viewPanel).hide();
2013-12-01 19:24:14 -07:00
}
});
2015-08-15 11:17:22 -07:00
$('.itemsContainer', tabContent).on('needsrefresh', function () {
2014-03-18 18:35:40 -07:00
2015-08-15 11:17:22 -07:00
reloadItems(tabContent, viewPanel);
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
2015-08-18 09:11:56 -07:00
var viewPanel = page.querySelector('.movieViewPanel');
initPage(tabContent, viewPanel);
};
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)) {
var viewPanel = page.querySelector('.movieViewPanel');
reloadItems(tabContent, viewPanel);
updateFilterControls(tabContent, viewPanel);
}
};
2015-08-15 11:17:22 -07:00
})(jQuery, document);