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

218 lines
6.6 KiB
JavaScript
Raw Normal View History

2013-11-21 13:48:26 -07:00
(function ($, document) {
2015-07-08 09:10:34 -07:00
var data = {};
2015-09-03 12:04:29 -07:00
function getPageData() {
2015-07-08 09:10:34 -07:00
var key = getSavedQueryKey();
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
Recursive: true,
Fields: "PrimaryImageAspectRatio,SortName,DateCreated,SyncInfo,ItemCounts",
StartIndex: 0,
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
Limit: LibraryBrowser.getDefaultPageSize()
2015-09-03 12:04:29 -07:00
},
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster')
2015-07-08 09:10:34 -07:00
};
pageData.query.ParentId = LibraryMenu.getTopParentId();
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
2015-09-03 12:04:29 -07:00
return pageData;
}
function getQuery() {
return getPageData().query;
2015-07-08 09:10:34 -07:00
}
2013-11-21 13:48:26 -07:00
2014-05-01 19:54:33 -07:00
function getSavedQueryKey() {
2015-10-14 21:32:10 -07:00
return LibraryBrowser.getSavedQueryKey('albumartists');
2014-05-01 19:54:33 -07:00
}
2015-09-03 12:04:29 -07:00
function reloadItems(page, viewPanel) {
2013-11-21 13:48:26 -07:00
Dashboard.showLoadingMsg();
2015-07-08 09:10:34 -07:00
var query = getQuery();
2014-06-22 09:49:39 -07:00
ApiClient.getAlbumArtists(Dashboard.getCurrentUserId(), query).done(function (result) {
2013-11-21 13:48:26 -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-11-21 13:48:26 -07:00
2015-09-03 12:04:29 -07:00
var view = getPageData().view;
2013-11-21 13:48:26 -07:00
var html = '';
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 12:04:29 -07:00
viewPanelClass: 'albumArtistsViewPanel',
updatePageSizeSetting: false,
addLayoutButton: true,
currentLayout: view,
viewButton: true,
viewIcon: 'filter-list'
2015-01-28 12:30:45 -07:00
});
2015-06-28 07:45:21 -07:00
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
2013-11-21 13:48:26 -07:00
2015-09-03 12:04:29 -07:00
updateFilterControls(page, viewPanel);
2013-11-21 13:48:26 -07:00
if (view == "List") {
html = LibraryBrowser.getListViewHtml({
items: result.Items,
context: 'music',
sortBy: query.SortBy
});
}
else if (view == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "square",
context: 'music',
showTitle: true,
coverImage: true,
2015-07-06 00:06:09 -07:00
lazy: true,
centerText: true,
2015-07-06 00:06:09 -07:00
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,
lazy: true,
2014-11-10 20:41:19 -07:00
cardLayout: true,
showSongCount: true
});
}
2013-11-21 13:48:26 -07:00
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('#items');
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2013-11-21 13:48:26 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
2015-09-03 12:04:29 -07:00
reloadItems(page, viewPanel);
2013-11-21 13:48:26 -07:00
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
2015-09-03 12:04:29 -07:00
reloadItems(page, viewPanel);
});
$('.btnChangeLayout', page).on('layoutchange', function (e, layout) {
getPageData().view = layout;
LibraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
reloadItems(page, viewPanel);
2013-11-21 13:48:26 -07:00
});
2014-05-01 19:54:33 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2015-07-08 09:10:34 -07:00
LibraryBrowser.setLastRefreshed(page);
2013-11-21 13:48:26 -07:00
Dashboard.hideLoadingMsg();
});
}
2015-09-03 12:04:29 -07:00
function updateFilterControls(tabContent, viewPanel) {
2013-11-21 13:48:26 -07:00
2015-07-08 09:10:34 -07:00
var query = getQuery();
2015-09-03 12:04:29 -07:00
$('.chkStandardFilter', viewPanel).each(function () {
var filters = "," + (query.Filters || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
2015-09-07 08:54:57 -07:00
});
2015-09-03 12:04:29 -07:00
$('.alphabetPicker', tabContent).alphaValue(query.NameStartsWithOrGreater);
2013-11-21 13:48:26 -07:00
}
2015-09-03 12:04:29 -07:00
function reloadFiltersIfNeeded(page, viewPanel) {
2015-09-03 11:07:15 -07:00
if (!getPageData().filtersLoaded) {
2015-09-03 11:07:15 -07:00
getPageData().filtersLoaded = true;
2015-07-08 09:10:34 -07:00
var query = getQuery();
2015-09-03 12:04:29 -07:00
QueryFilters.loadFilters(viewPanel, Dashboard.getCurrentUserId(), query, function () {
2015-07-08 09:10:34 -07:00
2015-09-03 12:04:29 -07:00
reloadItems(page, viewPanel);
});
}
}
2015-09-03 12:04:29 -07:00
function initPage(tabContent, viewPanel) {
2013-11-21 13:48:26 -07:00
2015-09-03 12:04:29 -07:00
$(viewPanel).on('panelopen', function () {
2015-09-03 12:04:29 -07:00
reloadFiltersIfNeeded(tabContent, viewPanel);
});
2015-09-03 12:04:29 -07:00
$('.chkStandardFilter', viewPanel).on('change', function () {
2013-11-21 13:48:26 -07:00
2015-07-08 09:10:34 -07:00
var query = getQuery();
2013-11-21 13:48:26 -07:00
var filterName = this.getAttribute('data-filter');
var filters = query.Filters || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
query.StartIndex = 0;
query.Filters = filters;
2015-09-03 12:04:29 -07:00
reloadItems(tabContent, viewPanel);
2013-11-21 13:48:26 -07:00
});
2015-09-08 07:35:52 -07:00
$('.alphabetPicker', tabContent).on('alphaselect', function (e, character) {
2013-11-21 13:48:26 -07:00
2015-07-08 09:10:34 -07:00
var query = getQuery();
2013-11-21 13:48:26 -07:00
query.NameStartsWithOrGreater = character;
query.StartIndex = 0;
2015-09-03 12:04:29 -07:00
reloadItems(tabContent, viewPanel);
2013-11-21 13:48:26 -07:00
}).on('alphaclear', function (e) {
2015-07-08 09:10:34 -07:00
var query = getQuery();
2013-11-21 13:48:26 -07:00
query.NameStartsWithOrGreater = '';
2015-09-03 12:04:29 -07:00
reloadItems(tabContent, viewPanel);
2014-07-19 21:46:29 -07:00
});
2015-09-03 12:04:29 -07:00
}
2014-07-19 21:46:29 -07:00
2015-09-03 12:04:29 -07:00
window.MusicPage.initAlbumArtistsTab = function (page, tabContent) {
2014-05-01 19:54:33 -07:00
2015-09-03 12:04:29 -07:00
var viewPanel = page.querySelector('.albumArtistsViewPanel');
initPage(tabContent, viewPanel);
};
2013-11-21 13:48:26 -07:00
2015-09-03 12:04:29 -07:00
window.MusicPage.renderAlbumArtistsTab = function (page, tabContent) {
2015-09-03 12:04:29 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
var viewPanel = page.querySelector('.albumArtistsViewPanel');
reloadItems(tabContent, viewPanel);
2015-07-08 09:10:34 -07:00
}
2015-09-03 12:04:29 -07:00
};
2013-11-21 13:48:26 -07:00
})(jQuery, document);