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

246 lines
8.5 KiB
JavaScript
Raw Normal View History

2016-07-30 11:09:08 -07:00
define(['events', 'libraryBrowser', 'imageLoader', 'alphaPicker', 'listView', 'cardBuilder', 'emby-itemscontainer'], function (events, libraryBrowser, imageLoader, alphaPicker, listView, cardBuilder) {
2016-05-15 11:52:36 -07:00
return function (view, params, tabContent) {
var self = this;
var data = {};
2016-06-17 12:44:19 -07:00
2016-05-15 11:52:36 -07:00
function getPageData(context) {
var key = getSavedQueryKey(context);
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: "SortName",
SortOrder: "Ascending",
Recursive: true,
2016-08-03 10:26:42 -07:00
Fields: "PrimaryImageAspectRatio,SortName,ItemCounts,BasicSyncInfo",
2016-05-15 11:52:36 -07:00
StartIndex: 0,
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
Limit: LibraryBrowser.getDefaultPageSize()
},
view: libraryBrowser.getSavedView(key) || 'PosterCard'
2016-05-15 11:52:36 -07:00
};
2016-06-17 12:44:19 -07:00
pageData.query.ParentId = params.topParentId;
libraryBrowser.loadSavedQueryValues(key, pageData.query);
2016-05-15 11:52:36 -07:00
}
return pageData;
}
function getQuery(context) {
return getPageData(context).query;
}
function getSavedQueryKey(context) {
if (!context.savedQueryKey) {
2016-06-17 12:32:48 -07:00
context.savedQueryKey = LibraryBrowser.getSavedQueryKey(self.mode);
2016-05-15 11:52:36 -07:00
}
return context.savedQueryKey;
}
2016-07-30 11:09:08 -07:00
function onViewStyleChange() {
var viewStyle = self.getCurrentViewStyle();
var itemsContainer = tabContent.querySelector('.itemsContainer');
if (viewStyle == "List") {
itemsContainer.classList.add('vertical-list');
itemsContainer.classList.remove('vertical-wrap');
}
else {
itemsContainer.classList.remove('vertical-list');
itemsContainer.classList.add('vertical-wrap');
}
itemsContainer.innerHTML = '';
}
2016-05-15 11:52:36 -07:00
function reloadItems(page) {
Dashboard.showLoadingMsg();
var query = getQuery(page);
2016-06-17 12:32:48 -07:00
var promise = self.mode == 'albumartists' ?
ApiClient.getAlbumArtists(Dashboard.getCurrentUserId(), query) :
ApiClient.getArtists(Dashboard.getCurrentUserId(), query);
promise.then(function (result) {
2016-05-15 11:52:36 -07:00
// Scroll back up so they can see the results from the beginning
window.scrollTo(0, 0);
2016-06-17 12:44:19 -07:00
updateFilterControls(page);
2016-05-15 11:52:36 -07:00
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
showLimit: false,
updatePageSizeSetting: false,
2016-06-17 12:44:19 -07:00
addLayoutButton: false,
sortButton: false,
filterButton: false
2016-05-15 11:52:36 -07:00
});
2016-06-17 12:44:19 -07:00
var html;
var viewStyle = self.getCurrentViewStyle();
2016-05-15 11:52:36 -07:00
2016-06-17 12:44:19 -07:00
if (viewStyle == "List") {
2016-05-15 11:52:36 -07:00
2016-07-15 22:05:40 -07:00
html = listView.getListViewHtml({
2016-05-15 11:52:36 -07:00
items: result.Items,
sortBy: query.SortBy
});
}
2016-06-17 12:44:19 -07:00
else if (viewStyle == "PosterCard") {
2016-07-30 11:09:08 -07:00
html = cardBuilder.getCardsHtml({
2016-05-15 11:52:36 -07:00
items: result.Items,
shape: "square",
context: 'music',
showTitle: true,
coverImage: true,
lazy: true,
2016-06-17 12:44:19 -07:00
cardLayout: true,
showSongCount: true
2016-05-15 11:52:36 -07:00
});
}
2016-06-17 12:44:19 -07:00
else {
2016-05-15 11:52:36 -07:00
2016-06-17 12:44:19 -07:00
// Poster
2016-07-30 11:09:08 -07:00
html = cardBuilder.getCardsHtml({
2016-05-15 11:52:36 -07:00
items: result.Items,
shape: "square",
context: 'music',
showTitle: true,
coverImage: true,
lazy: true,
2016-06-17 12:44:19 -07:00
centerText: true,
overlayPlayButton: true
2016-05-15 11:52:36 -07:00
});
}
2016-06-17 12:44:19 -07:00
var i, length;
var elems = tabContent.querySelectorAll('.paging');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].innerHTML = pagingHtml;
}
2016-05-15 11:52:36 -07:00
2016-06-17 12:44:19 -07:00
function onNextPageClick() {
2016-05-15 11:52:36 -07:00
query.StartIndex += query.Limit;
2016-06-17 12:44:19 -07:00
reloadItems(tabContent);
}
2016-05-15 11:52:36 -07:00
2016-06-17 12:44:19 -07:00
function onPreviousPageClick() {
2016-05-15 11:52:36 -07:00
query.StartIndex -= query.Limit;
2016-06-17 12:44:19 -07:00
reloadItems(tabContent);
}
2016-05-15 11:52:36 -07:00
2016-06-17 12:44:19 -07:00
elems = tabContent.querySelectorAll('.btnNextPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onNextPageClick);
}
2016-05-15 11:52:36 -07:00
2016-06-17 12:44:19 -07:00
elems = tabContent.querySelectorAll('.btnPreviousPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onPreviousPageClick);
}
var itemsContainer = tabContent.querySelector('.itemsContainer');
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
2016-05-15 11:52:36 -07:00
Dashboard.hideLoadingMsg();
});
}
2016-06-17 12:44:19 -07:00
self.showFilterMenu = function () {
2016-05-15 11:52:36 -07:00
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
var filterDialog = new filterDialogFactory({
2016-06-17 12:44:19 -07:00
query: getQuery(tabContent),
2016-06-17 12:32:48 -07:00
mode: self.mode
2016-05-15 11:52:36 -07:00
});
Events.on(filterDialog, 'filterchange', function () {
2016-06-17 12:44:19 -07:00
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
2016-05-15 11:52:36 -07:00
});
filterDialog.show();
});
}
function updateFilterControls(tabContent) {
var query = getQuery(tabContent);
2016-06-06 22:42:26 -07:00
self.alphaPicker.value(query.NameStartsWithOrGreater);
2016-05-15 11:52:36 -07:00
}
2016-06-17 12:44:19 -07:00
function initPage(tabContent) {
var alphaPickerElement = tabContent.querySelector('.alphaPicker');
alphaPickerElement.addEventListener('alphavaluechanged', function (e) {
var newValue = e.detail.value;
var query = getQuery(tabContent);
query.NameStartsWithOrGreater = newValue;
query.StartIndex = 0;
reloadItems(tabContent);
});
self.alphaPicker = new alphaPicker({
element: alphaPickerElement,
valueChangeEvent: 'click'
});
tabContent.querySelector('.btnFilter').addEventListener('click', function () {
self.showFilterMenu();
});
var btnSelectView = tabContent.querySelector('.btnSelectView');
btnSelectView.addEventListener('click', function (e) {
2016-05-15 11:52:36 -07:00
2016-06-17 12:44:19 -07:00
libraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), 'List,Poster,PosterCard'.split(','));
});
btnSelectView.addEventListener('layoutchange', function (e) {
var viewStyle = e.detail.viewStyle;
getPageData(tabContent).view = viewStyle;
libraryBrowser.saveViewSetting(getSavedQueryKey(tabContent), viewStyle);
getQuery(tabContent).StartIndex = 0;
2016-07-30 11:09:08 -07:00
onViewStyleChange();
2016-06-17 12:44:19 -07:00
reloadItems(tabContent);
});
}
self.getCurrentViewStyle = function () {
return getPageData(tabContent).view;
};
initPage(tabContent);
2016-07-30 11:09:08 -07:00
onViewStyleChange();
2016-06-06 22:42:26 -07:00
self.renderTab = function () {
2016-05-15 11:52:36 -07:00
reloadItems(tabContent);
2016-06-17 12:44:19 -07:00
updateFilterControls(tabContent);
};
self.destroy = function () {
2016-05-15 11:52:36 -07:00
};
};
});