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

299 lines
9.1 KiB
JavaScript
Raw Normal View History

(function ($, document) {
2013-03-26 19:48:33 -07:00
2015-07-08 17:20:01 -07:00
var currentItem;
2013-03-05 23:22:19 -07:00
2015-07-08 17:20:01 -07:00
var data = {};
2013-10-18 09:09:47 -07:00
2015-09-16 10:16:39 -07:00
function getPageData() {
2015-07-08 17:20:01 -07:00
var key = getSavedQueryKey();
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
Fields: "DateCreated,PrimaryImageAspectRatio,MediaSourceCount,SyncInfo",
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
StartIndex: 0,
Limit: LibraryBrowser.getDefaultPageSize()
}
};
pageData.query.Filters = "";
pageData.query.NameStartsWithOrGreater = '';
2015-10-25 22:29:32 -07:00
pageData.view = LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster');
2015-07-08 17:20:01 -07:00
pageData.query.ParentId = getParameterByName('parentId');
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
2015-09-16 10:16:39 -07:00
return pageData;
2015-07-08 17:20:01 -07:00
}
2015-09-16 10:16:39 -07:00
function getQuery() {
return getPageData().query;
}
2015-07-08 17:20:01 -07:00
function getSavedQueryKey() {
2015-10-14 21:32:10 -07:00
return LibraryBrowser.getSavedQueryKey();
2015-07-08 17:20:01 -07:00
}
2013-06-02 07:33:51 -07:00
function reloadItems(page) {
2013-03-30 07:57:30 -07:00
Dashboard.showLoadingMsg();
2015-07-08 17:20:01 -07:00
var query = getQuery();
var userId = Dashboard.getCurrentUserId();
2013-03-05 23:22:19 -07:00
2014-10-20 13:23:40 -07:00
var parentItemPromise = query.ParentId ?
ApiClient.getItem(userId, query.ParentId) :
ApiClient.getRootFolder(userId);
var itemsPromise = ApiClient.getItems(userId, query);
2015-12-14 08:43:03 -07:00
Promise.all([parentItemPromise, itemsPromise]).then(function (responses) {
2014-10-20 13:23:40 -07:00
2015-12-14 08:43:03 -07:00
var item = responses[0];
2014-10-20 13:23:40 -07:00
currentItem = item;
2015-12-14 08:43:03 -07:00
var result = responses[1];
2013-03-30 07:57:30 -07:00
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
2015-09-16 10:16:39 -07:00
var view = getPageData().view;
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,
2015-09-16 10:16:39 -07:00
showLimit: false,
addLayoutButton: true,
currentLayout: view,
viewIcon: 'filter-list',
sortButton: true,
2015-12-14 08:43:03 -07:00
layouts: 'Poster,PosterCard,Thumb'
2015-01-28 12:30:45 -07:00
});
2015-06-28 07:45:21 -07:00
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
2013-03-05 23:22:19 -07:00
2013-10-18 09:09:47 -07:00
updateFilterControls(page);
2014-08-14 06:24:30 -07:00
var context = getParameterByName('context');
2015-08-26 11:17:38 -07:00
var posterOptions = {
items: result.Items,
shape: "auto",
centerText: true,
2015-12-14 08:43:03 -07:00
lazy: true,
coverImage: item.Type == 'PhotoAlbum'
2015-08-26 11:17:38 -07:00
};
2014-08-14 06:24:30 -07:00
2013-04-18 19:52:22 -07:00
if (view == "Backdrop") {
2014-03-07 21:20:31 -07:00
2015-08-26 11:17:38 -07:00
posterOptions.shape = 'backdrop';
posterOptions.showTitle = true;
posterOptions.preferBackdrop = true;
html = LibraryBrowser.getPosterViewHtml(posterOptions);
2013-04-18 19:52:22 -07:00
}
else if (view == "Poster") {
2015-08-26 11:17:38 -07:00
2015-08-28 08:02:22 -07:00
posterOptions.showTitle = context == 'photos' ? 'auto' : true;
posterOptions.overlayText = context == 'photos';
2015-08-26 11:17:38 -07:00
html = LibraryBrowser.getPosterViewHtml(posterOptions);
2013-04-18 19:52:22 -07:00
}
2015-05-12 21:55:19 -07:00
else if (view == "PosterCard") {
2015-08-26 11:17:38 -07:00
posterOptions.showTitle = true;
posterOptions.showYear = true;
posterOptions.cardLayout = true;
2015-09-16 10:16:39 -07:00
posterOptions.centerText = false;
2015-08-26 11:17:38 -07:00
html = LibraryBrowser.getPosterViewHtml(posterOptions);
2015-05-12 21:55:19 -07:00
}
2013-03-30 07:57:30 -07:00
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('#items');
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2013-03-26 19:48:33 -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;
reloadItems(page);
});
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;
reloadItems(page);
});
2015-09-16 10:16:39 -07:00
$('.btnChangeLayout', page).on('layoutchange', function (e, layout) {
getPageData().view = layout;
LibraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
reloadItems(page);
});
// 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('OptionCommunityRating'),
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('OptionParentalRating'),
id: 'OfficialRating,SortName'
},
{
name: Globalize.translate('OptionPlayCount'),
id: 'PlayCount,SortName'
},
{
name: Globalize.translate('OptionReleaseDate'),
id: 'PremiereDate,SortName'
},
{
name: Globalize.translate('OptionRuntime'),
id: 'Runtime,SortName'
}],
callback: function () {
reloadItems(page);
},
query: query
});
});
2013-10-18 09:09:47 -07:00
LibraryBrowser.saveQueryValues(getParameterByName('parentId'), query);
2013-04-27 15:52:41 -07:00
2013-04-26 06:50:21 -07:00
var name = item.Name;
2013-04-26 06:50:21 -07:00
if (item.IndexNumber != null) {
name = item.IndexNumber + " - " + name;
}
if (item.ParentIndexNumber != null) {
name = item.ParentIndexNumber + "." + name;
}
2015-07-09 20:00:03 -07:00
LibraryMenu.setTitle(name);
2013-05-15 12:40:47 -07:00
2015-12-14 08:43:03 -07:00
page.dispatchEvent(new CustomEvent("displayingitem", {
detail: {
item: item
},
bubbles: true
}));
2013-05-10 05:18:07 -07:00
2015-07-08 17:20:01 -07:00
LibraryBrowser.setLastRefreshed(page);
2014-10-20 13:23:40 -07:00
Dashboard.hideLoadingMsg();
});
}
2013-03-30 07:57:30 -07:00
2013-10-18 09:09:47 -07:00
function updateFilterControls(page) {
2015-07-08 17:20:01 -07:00
var query = getQuery();
2013-10-18 09:09:47 -07:00
$('.chkStandardFilter', page).each(function () {
var filters = "," + (query.Filters || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
2015-09-16 10:16:39 -07:00
});
2013-10-18 09:09:47 -07:00
$('.alphabetPicker', page).alphaValue(query.NameStartsWithOrGreater);
}
2015-05-09 21:29:04 -07:00
function onListItemClick(e) {
2014-10-20 13:23:40 -07:00
2015-07-08 17:20:01 -07:00
var query = getQuery();
2015-05-09 21:29:04 -07:00
var page = $(this).parents('.page');
var info = LibraryBrowser.getListItemInfo(this);
2014-10-20 13:23:40 -07:00
2015-05-09 21:29:04 -07:00
if (info.mediaType == 'Photo') {
2015-08-28 08:02:22 -07:00
require(['scripts/photos'], function () {
Photos.startSlideshow(page, query, info.id);
});
2015-05-09 21:29:04 -07:00
return false;
}
2014-10-20 13:23:40 -07:00
}
2015-12-14 08:43:03 -07:00
pageIdOn('pageinit', "itemListPage", function () {
2013-03-30 07:57:30 -07:00
2013-04-18 19:52:22 -07:00
var page = this;
$('.chkStandardFilter', this).on('change', function () {
2015-07-08 17:20:01 -07:00
var query = getQuery();
2013-04-18 19:52:22 -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;
}
query.StartIndex = 0;
query.Filters = filters;
reloadItems(page);
});
2013-06-04 18:41:59 -07:00
$('.alphabetPicker', this).on('alphaselect', function (e, character) {
2015-07-08 17:20:01 -07:00
var query = getQuery();
2013-06-04 18:41:59 -07:00
query.NameStartsWithOrGreater = character;
query.StartIndex = 0;
reloadItems(page);
}).on('alphaclear', function (e) {
2015-07-08 17:20:01 -07:00
var query = getQuery();
2013-06-04 18:41:59 -07:00
query.NameStartsWithOrGreater = '';
reloadItems(page);
});
2015-05-09 21:29:04 -07:00
$(page).on('click', '.mediaItem', onListItemClick);
2014-10-20 13:23:40 -07:00
2015-12-14 08:43:03 -07:00
});
pageIdOn('pagebeforeshow', "itemListPage", function () {
2013-03-30 07:57:30 -07:00
2014-01-13 09:25:18 -07:00
var page = this;
2014-04-13 10:27:13 -07:00
2015-09-16 10:16:39 -07:00
reloadItems(page);
2014-01-13 09:25:18 -07:00
updateFilterControls(page);
2015-08-26 11:17:38 -07:00
LibraryMenu.setBackButtonVisible(getParameterByName('context'));
2013-06-04 18:41:59 -07:00
2015-12-14 08:43:03 -07:00
});
pageIdOn('pagebeforehide', "itemListPage", function () {
2013-06-02 07:33:51 -07:00
currentItem = null;
});
2013-03-05 23:22:19 -07:00
})(jQuery, document);