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

192 lines
5.7 KiB
JavaScript
Raw Normal View History

2013-04-21 21:38:03 -07:00
(function ($, document) {
2015-07-08 17:20:01 -07:00
var data = {};
2016-02-26 12:02:53 -07:00
function getPageData(context) {
var key = getSavedQueryKey(context);
2015-07-08 17:20:01 -07:00
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 17:20:01 -07:00
};
pageData.query.ParentId = LibraryMenu.getTopParentId();
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
2015-09-03 12:04:29 -07:00
return pageData;
}
2016-02-26 12:02:53 -07:00
function getQuery(context) {
2015-09-03 12:04:29 -07:00
2016-02-26 12:02:53 -07:00
return getPageData(context).query;
2015-07-08 17:20:01 -07:00
}
2013-04-21 21:38:03 -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('artists');
}
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-09-03 12:04:29 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getArtists(Dashboard.getCurrentUserId(), query).then(function (result) {
2013-04-21 21:38:03 -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);
2016-02-26 12:02:53 -07:00
var view = getPageData(page).view;
2013-04-21 21:38:03 -07:00
2015-09-03 12:04:29 -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
updatePageSizeSetting: false,
addLayoutButton: true,
currentLayout: view,
2016-02-15 09:57:51 -07:00
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
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-04-21 21:38:03 -07:00
2015-09-03 12:04:29 -07:00
var elem = page.querySelector('#items');
2015-06-28 07:45:21 -07:00
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2015-01-28 12:30:45 -07:00
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);
2015-09-03 12:04:29 -07:00
});
$('.btnChangeLayout', page).on('layoutchange', function (e, layout) {
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);
});
$('.btnFilter', page).on('click', function () {
showFilterMenu(page);
2013-04-21 21:38:03 -07:00
});
2016-02-26 12:02:53 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
2015-07-08 17:20:01 -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) {
2015-09-03 12:04:29 -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: 'artists'
});
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();
2015-09-07 08:54:57 -07:00
});
2013-10-18 09:09:47 -07:00
}
2016-02-15 09:57:51 -07:00
function updateFilterControls(tabContent) {
2016-02-26 12:02:53 -07:00
var query = getQuery(tabContent);
2016-02-15 09:57:51 -07:00
$('.alphabetPicker', tabContent).alphaValue(query.NameStartsWithOrGreater);
}
2016-02-15 09:57:51 -07:00
function initPage(tabContent) {
2013-04-21 21:38:03 -07:00
2015-09-08 07:35:52 -07:00
$('.alphabetPicker', tabContent).on('alphaselect', function (e, character) {
2013-05-16 13:46:18 -07:00
2016-02-26 12:02:53 -07:00
var query = getQuery(tabContent);
2015-09-03 12:04:29 -07:00
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = character;
2013-05-17 11:05:49 -07:00
query.StartIndex = 0;
2013-05-16 13:46:18 -07:00
2016-02-15 09:57:51 -07:00
reloadItems(tabContent);
2013-05-16 13:46:18 -07:00
}).on('alphaclear', function (e) {
2016-02-26 12:02:53 -07:00
var query = getQuery(tabContent);
2015-09-03 12:04:29 -07:00
query.NameStartsWithOrGreater = '';
2016-02-15 09:57:51 -07:00
reloadItems(tabContent);
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.initArtistsTab = function (page, tabContent) {
2013-05-15 12:40:47 -07:00
2016-02-15 09:57:51 -07:00
initPage(tabContent);
2015-09-03 12:04:29 -07:00
};
2015-09-03 12:04:29 -07:00
window.MusicPage.renderArtistsTab = function (page, tabContent) {
2015-09-03 12:04:29 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
2016-02-15 09:57:51 -07:00
reloadItems(tabContent);
2015-07-08 17:20:01 -07:00
}
2015-09-03 12:04:29 -07:00
};
2013-04-21 21:38:03 -07:00
})(jQuery, document);