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

253 lines
8.0 KiB
JavaScript
Raw Normal View History

2013-04-21 21:38:03 -07:00
(function ($, document) {
2015-07-06 19:25:23 -07:00
var data = {};
2016-02-26 12:02:53 -07:00
function getPageData(context) {
var key = getSavedQueryKey(context);
2015-07-06 19:25:23 -07:00
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
2015-12-14 08:43:03 -07:00
SortBy: "SortName",
2015-07-06 19:25:23 -07:00
SortOrder: "Ascending",
IncludeItemTypes: "MusicAlbum",
Recursive: true,
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo",
StartIndex: 0,
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
Limit: LibraryBrowser.getDefaultPageSize()
2015-09-03 11:07:15 -07:00
},
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster')
2015-07-06 19:25:23 -07:00
};
pageData.query.ParentId = LibraryMenu.getTopParentId();
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
2015-09-03 11:07:15 -07:00
return pageData;
}
2016-02-26 12:02:53 -07:00
function getQuery(context) {
2015-09-03 11:07:15 -07:00
2016-02-26 12:02:53 -07:00
return getPageData(context).query;
2015-07-06 19:25:23 -07:00
}
2016-02-26 12:02:53 -07:00
function getSavedQueryKey(context) {
2014-05-01 19:54:33 -07:00
2016-02-26 12:02:53 -07:00
if (!context.savedQueryKey) {
context.savedQueryKey = LibraryBrowser.getSavedQueryKey('albums');
}
return context.savedQueryKey;
2014-05-01 19:54:33 -07:00
}
2016-02-15 09:57:51 -07:00
function reloadItems(page) {
2013-04-21 21:38:03 -07:00
Dashboard.showLoadingMsg();
2016-02-26 12:02:53 -07:00
var query = getQuery(page);
2015-07-06 19:25:23 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
2013-04-21 21:38:03 -07:00
2013-05-17 12:18:54 -07:00
// Scroll back up so they can see the results from the beginning
2015-06-28 07:45:21 -07:00
window.scrollTo(0, 0);
2013-05-17 12:18:54 -07:00
2013-04-21 21:38:03 -07:00
var html = '';
2016-02-26 12:02:53 -07:00
var view = getPageData(page).view;
2015-01-28 12:30:45 -07:00
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
2014-07-19 21:46:29 -07:00
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
2015-09-03 11:07:15 -07:00
sortButton: true,
addLayoutButton: true,
currentLayout: view,
2015-09-03 12:04:29 -07:00
updatePageSizeSetting: false,
2016-02-15 09:57:51 -07:00
layouts: 'List,Poster,PosterCard,Timeline',
filterButton: true
2015-01-28 12:30:45 -07:00
});
2015-06-28 07:45:21 -07:00
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
2013-04-21 21:38:03 -07:00
2016-02-15 09:57:51 -07:00
updateFilterControls(page);
2013-10-18 09:09:47 -07:00
2013-05-15 05:05:07 -07:00
if (view == "Poster") {
2013-12-23 08:26:36 -07:00
html = LibraryBrowser.getPosterViewHtml({
2013-05-15 05:05:07 -07:00
items: result.Items,
2013-12-23 08:26:36 -07:00
shape: "square",
context: 'music',
showTitle: true,
2014-04-09 21:12:04 -07:00
showParentTitle: true,
2015-07-06 00:06:09 -07:00
lazy: true,
centerText: true,
overlayPlayButton: true
2014-11-10 20:41:19 -07:00
});
}
else if (view == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "square",
context: 'music',
showTitle: true,
coverImage: true,
showParentTitle: true,
lazy: true,
2014-11-10 20:41:19 -07:00
cardLayout: true
2013-05-15 05:05:07 -07:00
});
}
else if (view == "List") {
html = LibraryBrowser.getListViewHtml({
items: result.Items,
context: 'music',
sortBy: query.SortBy
});
}
2013-05-15 05:05:07 -07:00
else if (view == "Timeline") {
2014-01-02 14:21:06 -07:00
html = LibraryBrowser.getPosterViewHtml({
2013-05-15 05:05:07 -07:00
items: result.Items,
shape: "square",
2014-01-02 14:21:06 -07:00
context: 'music',
showTitle: true,
showParentTitle: true,
2014-04-09 21:12:04 -07:00
timeline: true,
2014-11-10 20:41:19 -07:00
lazy: true
2013-05-15 05:05:07 -07:00
});
}
2013-04-21 21:38:03 -07:00
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('#items');
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2013-04-21 21:38:03 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
2016-02-15 09:57:51 -07:00
reloadItems(page);
2013-04-21 21:38:03 -07:00
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
2016-02-15 09:57:51 -07:00
reloadItems(page);
});
$('.btnFilter', page).on('click', function () {
showFilterMenu(page);
2015-09-03 11:07:15 -07:00
});
$('.btnChangeLayout', page).on('layoutchange', function (e, layout) {
2015-10-02 11:30:27 -07:00
if (layout == 'Timeline') {
2016-02-26 12:02:53 -07:00
getQuery(page).SortBy = 'ProductionYear,PremiereDate,SortName';
getQuery(page).SortOrder = 'Descending';
2015-10-02 11:30:27 -07:00
}
2016-02-26 12:02:53 -07:00
getPageData(page).view = layout;
LibraryBrowser.saveViewSetting(getSavedQueryKey(page), layout);
2016-02-15 09:57:51 -07:00
reloadItems(page);
2015-09-03 11:07:15 -07:00
});
// On callback make sure to set StartIndex = 0
$('.btnSort', page).on('click', function () {
LibraryBrowser.showSortMenu({
items: [{
name: Globalize.translate('OptionNameSort'),
id: 'SortName'
},
{
name: Globalize.translate('OptionAlbumArtist'),
id: 'AlbumArtist,SortName'
},
{
name: Globalize.translate('OptionCommunityRating'),
id: 'CommunityRating,SortName'
},
{
name: Globalize.translate('OptionCriticRating'),
id: 'CriticRating,SortName'
},
{
name: Globalize.translate('OptionDateAdded'),
id: 'DateCreated,SortName'
},
{
name: Globalize.translate('OptionReleaseDate'),
id: 'ProductionYear,PremiereDate,SortName'
}],
callback: function () {
2016-02-15 09:57:51 -07:00
reloadItems(page);
2015-09-03 11:07:15 -07:00
},
query: query
});
2013-04-21 21:38:03 -07:00
});
2016-02-26 12:02:53 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
2015-07-06 19:25:23 -07:00
LibraryBrowser.setLastRefreshed(page);
2013-04-21 21:38:03 -07:00
Dashboard.hideLoadingMsg();
});
}
2016-02-15 09:57:51 -07:00
function showFilterMenu(page) {
2013-10-18 09:09:47 -07:00
2016-02-15 09:57:51 -07:00
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
2016-02-15 09:57:51 -07:00
var filterDialog = new filterDialogFactory({
2016-02-26 12:02:53 -07:00
query: getQuery(page),
2016-02-15 09:57:51 -07:00
mode: 'albums'
});
2016-02-15 09:57:51 -07:00
Events.on(filterDialog, 'filterchange', function () {
reloadItems(page);
});
2016-02-15 09:57:51 -07:00
filterDialog.show();
2013-04-21 21:38:03 -07:00
});
2016-02-15 09:57:51 -07:00
}
2013-04-21 21:38:03 -07:00
2016-02-15 09:57:51 -07:00
function updateFilterControls(page) {
2013-04-21 21:38:03 -07:00
2016-02-26 12:02:53 -07:00
var query = getQuery(page);
2013-04-21 21:38:03 -07:00
2016-02-15 09:57:51 -07:00
$('.alphabetPicker', page).alphaValue(query.NameStartsWith);
}
2013-04-21 21:38:03 -07:00
2016-02-15 09:57:51 -07:00
function initPage(tabContent) {
2013-05-15 05:05:07 -07:00
2015-09-03 11:07:15 -07:00
$('.alphabetPicker', tabContent).on('alphaselect', function (e, character) {
2016-02-26 12:02:53 -07:00
var query = getQuery(tabContent);
2015-07-06 19:25:23 -07:00
if (query.SortBy.indexOf('AlbumArtist') == -1) {
query.NameStartsWithOrGreater = character;
query.AlbumArtistStartsWithOrGreater = '';
} else {
query.AlbumArtistStartsWithOrGreater = character;
query.NameStartsWithOrGreater = '';
}
2013-10-18 09:09:47 -07:00
2013-05-17 11:05:49 -07:00
query.StartIndex = 0;
2016-02-15 09:57:51 -07:00
reloadItems(tabContent);
}).on('alphaclear', function (e) {
2016-02-26 12:02:53 -07:00
var query = getQuery(tabContent);
2015-07-06 19:25:23 -07:00
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = '';
query.AlbumArtistStartsWithOrGreater = '';
2016-02-15 09:57:51 -07:00
reloadItems(tabContent);
2014-07-19 21:46:29 -07:00
});
2015-09-03 11:07:15 -07:00
}
2014-07-19 21:46:29 -07:00
2015-09-03 11:07:15 -07:00
window.MusicPage.initAlbumsTab = function (page, tabContent) {
2013-04-21 21:38:03 -07:00
2016-02-15 09:57:51 -07:00
initPage(tabContent);
2015-09-03 11:07:15 -07:00
};
2013-05-15 12:40:47 -07:00
2015-09-03 11:07:15 -07:00
window.MusicPage.renderAlbumsTab = function (page, tabContent) {
2015-09-03 11:07:15 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
2016-02-15 09:57:51 -07:00
reloadItems(tabContent);
2015-07-06 19:25:23 -07:00
}
2015-09-03 11:07:15 -07:00
};
2013-04-21 21:38:03 -07:00
})(jQuery, document);