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

158 lines
5.0 KiB
JavaScript
Raw Normal View History

2016-06-17 11:35:21 -07:00
define([], function () {
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,
Fields: "DateCreated,SyncInfo,ItemCounts",
2016-06-17 11:35:21 -07:00
StartIndex: 0
2016-04-03 11:47:49 -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');
}
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);
}
function reloadItems(context, promise) {
var query = getQuery();
promise.then(function (result) {
2016-04-03 11:47:49 -07:00
var html = '';
2016-06-17 11:35:21 -07:00
var viewStyle = self.getCurrentViewStyle();
2016-04-03 11:47:49 -07:00
if (viewStyle == "Thumb") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
2016-06-17 11:35:21 -07:00
context: 'movies',
2016-04-03 11:47:49 -07:00
showItemCounts: true,
centerText: true,
lazy: true,
2016-06-17 17:52:04 -07:00
overlayMoreButton: true
2016-04-03 11:47:49 -07:00
});
}
else if (viewStyle == "ThumbCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
2016-06-17 11:35:21 -07:00
context: 'movies',
2016-04-03 11:47:49 -07:00
showItemCounts: true,
cardLayout: true,
showTitle: true,
2016-06-17 11:35:21 -07:00
lazy: true
2016-04-03 11:47:49 -07:00
});
}
else if (viewStyle == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
2016-06-17 11:35:21 -07:00
context: 'movies',
2016-04-03 11:47:49 -07:00
showItemCounts: true,
lazy: true,
cardLayout: true,
2016-06-17 11:35:21 -07:00
showTitle: true
2016-04-03 11:47:49 -07:00
});
}
else if (viewStyle == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
2016-06-17 11:35:21 -07:00
context: 'movies',
2016-04-03 11:47:49 -07:00
centerText: true,
showItemCounts: true,
lazy: true,
2016-06-17 17:52:04 -07:00
overlayMoreButton: true
2016-04-03 11:47:49 -07:00
});
}
2016-06-17 11:35:21 -07:00
var elem = context.querySelector('#items');
2016-04-03 11:47:49 -07:00
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
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;
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-06-17 12:44:19 -07:00
var btnSelectView = tabContent.querySelector('.btnSelectView');
btnSelectView.addEventListener('click', function (e) {
2016-06-17 11:35:21 -07:00
LibraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), self.getViewStyles());
});
2016-06-17 12:44:19 -07:00
btnSelectView.addEventListener('layoutchange', function (e) {
2016-06-17 11:35:21 -07:00
self.setCurrentViewStyle(e.detail.viewStyle);
});
2016-04-03 11:47:49 -07:00
};
});