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

141 lines
4.7 KiB
JavaScript
Raw Normal View History

define([], function () {
2016-03-18 12:43:17 -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: "Series",
Recursive: true,
Fields: "DateCreated,SyncInfo,ItemCounts",
2016-04-23 11:40:36 -07:00
StartIndex: 0
2016-03-18 12:43:17 -07:00
},
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Thumb', 'Thumb')
};
pageData.query.ParentId = params.topParentId;
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData;
}
function getQuery() {
return getPageData().query;
}
function getSavedQueryKey() {
return LibraryBrowser.getSavedQueryKey('genres');
}
function reloadItems(context) {
Dashboard.showLoadingMsg();
var query = getQuery();
ApiClient.getGenres(Dashboard.getCurrentUserId(), query).then(function (result) {
var html = '';
2016-04-23 11:40:36 -07:00
var viewStyle = self.getCurrentViewStyle();
2016-03-18 12:43:17 -07:00
if (viewStyle == "Thumb") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'tv',
showItemCounts: true,
centerText: true,
lazy: true,
overlayPlayButton: true
});
}
else if (viewStyle == "ThumbCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'tv',
showItemCounts: true,
cardLayout: true,
showTitle: true,
lazy: true
});
}
else if (viewStyle == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'tv',
showItemCounts: true,
lazy: true,
cardLayout: true,
showTitle: true
});
}
else if (viewStyle == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'tv',
centerText: true,
showItemCounts: true,
lazy: true,
overlayPlayButton: true
});
}
var elem = context.querySelector('#items');
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
Dashboard.hideLoadingMsg();
});
2015-08-26 11:17:38 -07:00
}
2016-04-23 11:40:36 -07:00
self.getViewStyles = function () {
return 'Poster,PosterCard,Thumb,ThumbCard'.split(',');
};
self.getCurrentViewStyle = function () {
return getPageData(tabContent).view;
};
2016-03-18 12:43:17 -07:00
2016-04-23 11:40:36 -07:00
self.setCurrentViewStyle = function(viewStyle) {
getPageData(tabContent).view = viewStyle;
LibraryBrowser.saveViewSetting(getSavedQueryKey(tabContent), viewStyle);
2016-03-18 20:14:53 -07:00
reloadItems(tabContent);
2016-03-18 12:43:17 -07:00
};
2016-04-23 11:40:36 -07:00
self.enableViewSelection = true;
self.renderTab = function () {
reloadItems(tabContent);
};
2016-06-17 12:44:19 -07:00
var btnSelectView = tabContent.querySelector('.btnSelectView');
btnSelectView.addEventListener('click', function (e) {
2016-04-23 11:40:36 -07:00
LibraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), self.getViewStyles());
});
2016-06-17 12:44:19 -07:00
btnSelectView.addEventListener('layoutchange', function (e) {
2016-04-23 11:40:36 -07:00
self.setCurrentViewStyle(e.detail.viewStyle);
});
2016-03-18 12:43:17 -07:00
};
});