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

246 lines
8.4 KiB
JavaScript
Raw Normal View History

2016-11-16 10:54:05 -07:00
define(['libraryBrowser', 'cardBuilder', 'lazyLoader', 'apphost', 'globalize', 'dom'], function (libraryBrowser, cardBuilder, lazyLoader, appHost, globalize, dom) {
2016-10-22 22:11:46 -07:00
'use strict';
2016-04-03 11:47:49 -07:00
return function (view, params, tabContent) {
var self = this;
var data = {};
function getPageData() {
var key = getSavedQueryKey();
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "Movie",
Recursive: true,
2016-11-15 12:42:43 -07:00
EnableTotalRecordCount: false
2016-04-03 11:47:49 -07:00
},
2016-11-15 20:05:53 -07:00
view: libraryBrowser.getSavedView(key) || (appHost.preferVisualCards ? 'PosterCard' : 'Poster')
2016-04-03 11:47:49 -07:00
};
pageData.query.ParentId = params.topParentId;
2016-07-18 20:57:55 -07:00
libraryBrowser.loadSavedQueryValues(key, pageData.query);
2016-04-03 11:47:49 -07:00
}
return pageData;
}
function getQuery() {
return getPageData().query;
}
function getSavedQueryKey() {
2016-11-15 12:42:43 -07:00
return libraryBrowser.getSavedQueryKey('moviegenres');
2016-04-03 11:47:49 -07:00
}
2016-06-29 10:43:34 -07:00
function getPromise() {
2016-04-03 11:47:49 -07:00
Dashboard.showLoadingMsg();
var query = getQuery();
2016-06-29 10:43:34 -07:00
return ApiClient.getGenres(Dashboard.getCurrentUserId(), query);
}
2016-11-15 12:42:43 -07:00
function enableScrollX() {
return browserInfo.mobile && AppInfo.enableAppLayouts;
}
2016-06-29 10:43:34 -07:00
2016-11-15 12:42:43 -07:00
function getThumbShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
2016-06-29 10:43:34 -07:00
2016-11-15 12:42:43 -07:00
function getPortraitShape() {
return enableScrollX() ? 'overflowPortrait' : 'portrait';
2016-11-16 10:54:05 -07:00
}
function getMoreItemsHref(itemId, type) {
2016-11-25 11:25:01 -07:00
return 'secondaryitems.html?type=' + type + '&genreId=' + itemId + '&parentId=' + params.topParentId;
2016-11-16 10:54:05 -07:00
}
dom.addEventListener(tabContent, 'click', function (e) {
var btnMoreFromGenre = dom.parentWithClass(e.target, 'btnMoreFromGenre');
if (btnMoreFromGenre) {
var id = btnMoreFromGenre.getAttribute('data-id');
Dashboard.navigate(getMoreItemsHref(id, 'Movie'));
}
}, {
passive: true
});
2016-11-15 12:42:43 -07:00
function fillItemsContainer(elem) {
2016-04-03 11:47:49 -07:00
2016-11-15 12:42:43 -07:00
var id = elem.getAttribute('data-id');
2016-04-03 11:47:49 -07:00
2016-11-15 12:42:43 -07:00
var viewStyle = self.getCurrentViewStyle();
var limit = viewStyle == 'Thumb' || viewStyle == 'ThumbCard' ?
5 :
8;
2016-11-15 20:05:53 -07:00
if (enableScrollX()) {
limit = 10;
}
2016-11-15 12:42:43 -07:00
var enableImageTypes = viewStyle == 'Thumb' || viewStyle == 'ThumbCard' ?
"Primary,Backdrop,Thumb" :
"Primary";
var query = {
SortBy: "SortName",
SortOrder: "Ascending",
IncludeItemTypes: "Movie",
Recursive: true,
Fields: "PrimaryImageAspectRatio,MediaSourceCount,BasicSyncInfo",
ImageTypeLimit: 1,
EnableImageTypes: enableImageTypes,
Limit: limit,
GenreIds: id,
2016-11-15 20:05:53 -07:00
EnableTotalRecordCount: false,
ParentId: params.topParentId
2016-11-15 12:42:43 -07:00
};
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
var supportsImageAnalysis = appHost.supports('imageanalysis');
2016-04-03 11:47:49 -07:00
if (viewStyle == "Thumb") {
2016-07-29 13:06:58 -07:00
cardBuilder.buildCards(result.Items, {
itemsContainer: elem,
2016-11-15 12:42:43 -07:00
shape: getThumbShape(),
2016-04-03 11:47:49 -07:00
preferThumb: true,
2016-08-01 22:55:52 -07:00
showTitle: true,
2016-07-29 13:06:58 -07:00
scalable: true,
2016-04-03 11:47:49 -07:00
centerText: true,
2016-11-15 12:42:43 -07:00
overlayMoreButton: true,
allowBottomPadding: false
2016-04-03 11:47:49 -07:00
});
}
else if (viewStyle == "ThumbCard") {
2016-07-29 13:06:58 -07:00
cardBuilder.buildCards(result.Items, {
itemsContainer: elem,
2016-11-15 12:42:43 -07:00
shape: getThumbShape(),
2016-04-03 11:47:49 -07:00
preferThumb: true,
2016-08-01 22:55:52 -07:00
showTitle: true,
2016-07-29 13:06:58 -07:00
scalable: true,
2016-10-10 23:46:59 -07:00
centerText: false,
2016-11-15 12:42:43 -07:00
cardLayout: true,
vibrant: supportsImageAnalysis,
showYear: true
2016-04-03 11:47:49 -07:00
});
}
else if (viewStyle == "PosterCard") {
2016-07-29 13:06:58 -07:00
cardBuilder.buildCards(result.Items, {
itemsContainer: elem,
2016-11-15 12:42:43 -07:00
shape: getPortraitShape(),
2016-08-01 22:55:52 -07:00
showTitle: true,
2016-07-29 13:06:58 -07:00
scalable: true,
2016-10-10 23:46:59 -07:00
centerText: false,
2016-11-15 12:42:43 -07:00
cardLayout: true,
vibrant: supportsImageAnalysis,
showYear: true
2016-04-03 11:47:49 -07:00
});
}
else if (viewStyle == "Poster") {
2016-07-29 13:06:58 -07:00
cardBuilder.buildCards(result.Items, {
itemsContainer: elem,
2016-11-15 12:42:43 -07:00
shape: getPortraitShape(),
2016-08-01 22:55:52 -07:00
showTitle: true,
2016-07-29 13:06:58 -07:00
scalable: true,
centerText: true,
2016-11-15 12:42:43 -07:00
overlayMoreButton: true,
allowBottomPadding: false
2016-04-03 11:47:49 -07:00
});
}
2016-11-16 10:54:05 -07:00
if (result.Items.length >= query.Limit) {
tabContent.querySelector('.btnMoreFromGenre' + id).classList.remove('hide');
}
2016-11-15 12:42:43 -07:00
});
}
function reloadItems(context, promise) {
var query = getQuery();
promise.then(function (result) {
var elem = context.querySelector('#items');
var html = '';
var items = result.Items;
for (var i = 0, length = items.length; i < length; i++) {
var item = items[i];
html += '<div class="homePageSection">';
2016-11-16 10:54:05 -07:00
html += '<div style="display:flex;align-items:center;">';
2016-11-15 12:42:43 -07:00
html += '<h1 class="listHeader">';
html += item.Name;
html += '</h1>';
2016-11-17 11:18:19 -07:00
html += '<button is="emby-button" type="button" class="raised more mini hide btnMoreFromGenre btnMoreFromGenre' + item.Id + '" data-id="' + item.Id + '">';
2016-11-16 10:54:05 -07:00
html += '<span>' + globalize.translate('ButtonMore') + '</span>';
html += '</button>';
html += '</div>';
2016-11-15 12:42:43 -07:00
if (enableScrollX()) {
html += '<div is="emby-itemscontainer" class="itemsContainer hiddenScrollX lazy" data-id="' + item.Id + '">';
} else {
html += '<div is="emby-itemscontainer" class="itemsContainer vertical-wrap lazy" data-id="' + item.Id + '">';
}
html += '</div>';
html += '</div>';
}
elem.innerHTML = html;
lazyLoader.lazyChildren(elem, fillItemsContainer);
2016-07-18 20:57:55 -07:00
libraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2016-04-03 11:47:49 -07:00
Dashboard.hideLoadingMsg();
});
2015-08-15 11:17:22 -07:00
}
2016-06-17 11:35:21 -07:00
self.getViewStyles = function () {
return 'Poster,PosterCard,Thumb,ThumbCard'.split(',');
};
self.getCurrentViewStyle = function () {
return getPageData(tabContent).view;
};
2016-04-03 11:47:49 -07:00
2016-06-17 11:35:21 -07:00
self.setCurrentViewStyle = function (viewStyle) {
getPageData(tabContent).view = viewStyle;
2016-07-18 20:57:55 -07:00
libraryBrowser.saveViewSetting(getSavedQueryKey(tabContent), viewStyle);
2016-06-29 10:43:34 -07:00
fullyReload();
2016-04-03 11:47:49 -07:00
};
2016-06-17 11:35:21 -07:00
self.enableViewSelection = true;
2016-06-29 10:43:34 -07:00
var promise;
self.preRender = function () {
promise = getPromise();
};
2016-06-17 11:35:21 -07:00
self.renderTab = function () {
2016-06-29 10:43:34 -07:00
reloadItems(tabContent, promise);
2016-06-17 11:35:21 -07:00
};
2016-06-29 10:43:34 -07:00
function fullyReload() {
self.preRender();
self.renderTab();
}
2016-04-03 11:47:49 -07:00
};
});