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

160 lines
5.2 KiB
JavaScript
Raw Normal View History

2016-07-18 20:57:55 -07:00
define(['libraryBrowser'], function (libraryBrowser) {
2016-06-17 12:10:05 -07:00
return function (view, params, tabContent) {
2016-05-15 11:52:36 -07:00
var self = this;
2016-06-17 12:10:05 -07:00
var data = {};
function getPageData() {
var key = getSavedQueryKey();
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
2016-06-22 13:07:52 -07:00
IncludeItemTypes: "Audio,MusicAlbum",
2016-06-17 12:10:05 -07:00
Recursive: true,
Fields: "DateCreated,SyncInfo,ItemCounts",
StartIndex: 0
},
view: libraryBrowser.getSavedView(key) || libraryBrowser.getDefaultItemsView('PosterCard', 'PosterCard')
2016-06-17 12:10:05 -07:00
};
pageData.query.ParentId = params.topParentId;
2016-07-18 20:57:55 -07:00
libraryBrowser.loadSavedQueryValues(key, pageData.query);
2016-06-17 12:10:05 -07:00
}
return pageData;
}
function getQuery() {
return getPageData().query;
}
function getSavedQueryKey() {
2016-07-18 20:57:55 -07:00
return libraryBrowser.getSavedQueryKey('genres');
2016-06-17 12:10:05 -07:00
}
2016-06-29 10:43:34 -07:00
function getPromise() {
2016-06-17 12:10:05 -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-06-17 12:10:05 -07:00
var html = '';
var viewStyle = self.getCurrentViewStyle();
if (viewStyle == "Thumb") {
2016-07-18 20:57:55 -07:00
html = libraryBrowser.getPosterViewHtml({
2016-06-17 12:10:05 -07:00
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'music',
showItemCounts: true,
centerText: true,
lazy: true,
overlayMoreButton: true,
showTitle: true
2016-06-17 12:10:05 -07:00
});
}
else if (viewStyle == "ThumbCard") {
2016-07-18 20:57:55 -07:00
html = libraryBrowser.getPosterViewHtml({
2016-06-17 12:10:05 -07:00
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'music',
showItemCounts: true,
cardLayout: true,
showTitle: true,
lazy: true
});
}
else if (viewStyle == "PosterCard") {
2016-07-18 20:57:55 -07:00
html = libraryBrowser.getPosterViewHtml({
2016-06-17 12:10:05 -07:00
items: result.Items,
shape: "auto",
2016-06-17 12:10:05 -07:00
context: 'music',
showItemCounts: true,
lazy: true,
cardLayout: true,
showTitle: true
});
}
else if (viewStyle == "Poster") {
2016-07-18 20:57:55 -07:00
html = libraryBrowser.getPosterViewHtml({
2016-06-17 12:10:05 -07:00
items: result.Items,
shape: "auto",
2016-06-17 12:10:05 -07:00
context: 'music',
centerText: true,
showItemCounts: true,
lazy: true,
overlayMoreButton: true,
showTitle: true
2016-06-17 12:10:05 -07:00
});
}
var elem = context.querySelector('#items');
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
2016-07-18 20:57:55 -07:00
libraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2016-06-17 12:10:05 -07:00
Dashboard.hideLoadingMsg();
});
2015-09-03 09:39:24 -07:00
}
2016-06-17 12:10:05 -07:00
self.getViewStyles = function () {
return 'Poster,PosterCard,Thumb,ThumbCard'.split(',');
};
self.getCurrentViewStyle = function () {
return getPageData(tabContent).view;
};
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-06-17 12:10:05 -07:00
};
self.enableViewSelection = true;
2016-06-29 10:43:34 -07:00
var promise;
self.preRender = function () {
promise = getPromise();
};
2016-06-17 12:10:05 -07:00
self.renderTab = function () {
2016-06-29 10:43:34 -07:00
reloadItems(tabContent, promise);
2016-06-17 12:10:05 -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 12:10:05 -07:00
2016-07-18 20:57:55 -07:00
libraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), self.getViewStyles());
2016-06-17 12:10:05 -07:00
});
2016-06-17 12:44:19 -07:00
btnSelectView.addEventListener('layoutchange', function (e) {
2016-06-17 12:10:05 -07:00
self.setCurrentViewStyle(e.detail.viewStyle);
});
};
});