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

136 lines
4.4 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2013-04-19 16:57:23 -07:00
2016-05-15 11:52:36 -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: "Audio,MusicVideo",
Recursive: true,
Fields: "DateCreated,SyncInfo,ItemCounts",
StartIndex: 0,
Limit: LibraryBrowser.getDefaultPageSize()
},
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Thumb', 'Thumb')
};
pageData.query.ParentId = LibraryMenu.getTopParentId();
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData;
2015-09-03 09:39:24 -07:00
}
2013-04-19 16:57:23 -07:00
2016-05-15 11:52:36 -07:00
function getQuery() {
2013-04-19 16:57:23 -07:00
2016-05-15 11:52:36 -07:00
return getPageData().query;
}
2015-09-03 09:39:24 -07:00
2016-05-15 11:52:36 -07:00
function getSavedQueryKey() {
2015-09-03 09:39:24 -07:00
2016-05-15 11:52:36 -07:00
return LibraryBrowser.getSavedQueryKey('genres');
}
2013-04-19 16:57:23 -07:00
2016-05-15 11:52:36 -07:00
function reloadItems(context) {
Dashboard.showLoadingMsg();
var query = getQuery();
ApiClient.getMusicGenres(Dashboard.getCurrentUserId(), query).then(function (result) {
// Scroll back up so they can see the results from the beginning
window.scrollTo(0, 0);
var html = '';
var view = getPageData().view;
$('.listTopPaging', context).html(LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
updatePageSizeSetting: false,
addLayoutButton: true,
currentLayout: view
}));
if (view == "Thumb") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
showItemCounts: true,
context: 'music',
lazy: true,
centerText: true,
overlayPlayButton: true
});
}
else if (view == "ThumbCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'music',
showItemCounts: true,
cardLayout: true,
lazy: true,
showTitle: true
});
}
else if (view == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'music',
centerText: true,
showItemCounts: true,
lazy: true
});
}
var elem = context.querySelector('#items');
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
$('.btnNextPage', context).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(context);
2015-05-12 21:55:19 -07:00
});
2013-04-19 16:57:23 -07:00
2016-05-15 11:52:36 -07:00
$('.btnPreviousPage', context).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(context);
});
2013-04-19 16:57:23 -07:00
2016-05-15 11:52:36 -07:00
$('.btnChangeLayout', context).on('layoutchange', function (e, layout) {
getPageData().view = layout;
LibraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
reloadItems(context);
});
2013-04-19 16:57:23 -07:00
2016-05-15 11:52:36 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2013-04-19 16:57:23 -07:00
2016-05-15 11:52:36 -07:00
Dashboard.hideLoadingMsg();
2015-09-03 09:39:24 -07:00
});
2016-05-15 11:52:36 -07:00
}
2015-09-03 09:39:24 -07:00
2016-05-15 11:52:36 -07:00
self.renderTab = function () {
2013-04-19 16:57:23 -07:00
2016-05-15 11:52:36 -07:00
reloadItems(tabContent);
};
2015-09-03 09:39:24 -07:00
};
2013-04-19 16:57:23 -07:00
});