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

155 lines
5.0 KiB
JavaScript
Raw Normal View History

2016-07-29 13:06:58 -07:00
define(['libraryBrowser', 'cardBuilder'], function (libraryBrowser, cardBuilder) {
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-08-01 22:55:52 -07:00
Fields: "DateCreated,ItemCounts,PrimaryImageAspectRatio",
2016-06-17 11:35:21 -07:00
StartIndex: 0
2016-04-03 11:47:49 -07:00
},
view: libraryBrowser.getSavedView(key) || 'Thumb'
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-07-18 20:57:55 -07:00
return libraryBrowser.getSavedQueryKey('genres');
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);
}
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-07-29 13:06:58 -07:00
var elem = context.querySelector('#items');
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-04-03 11:47:49 -07:00
shape: "backdrop",
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
showItemCounts: true,
centerText: true,
2016-06-17 17:52:04 -07:00
overlayMoreButton: true
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-04-03 11:47:49 -07:00
shape: "backdrop",
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
showItemCounts: true,
2016-10-10 23:46:59 -07:00
centerText: false,
2016-07-29 13:06:58 -07:00
cardLayout: 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,
shape: "auto",
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
showItemCounts: true,
2016-10-10 23:46:59 -07:00
centerText: false,
2016-07-29 13:06:58 -07:00
cardLayout: 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,
shape: "auto",
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
showItemCounts: true,
2016-07-29 13:06:58 -07:00
centerText: true,
2016-06-17 17:52:04 -07:00
overlayMoreButton: true
2016-04-03 11:47:49 -07:00
});
}
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-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
2016-07-18 20:57:55 -07:00
libraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), self.getViewStyles());
2016-06-17 11:35:21 -07:00
});
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
};
});