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

280 lines
9.7 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) {
2013-04-21 21:38:03 -07:00
2016-05-15 11:52:36 -07:00
return function (view, params, tabContent) {
var self = this;
2016-06-17 12:10:05 -07:00
var pageSize = libraryBrowser.getDefaultPageSize();
2016-05-15 11:52:36 -07:00
var data = {};
2016-06-17 12:10:05 -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",
IncludeItemTypes: "MusicAlbum",
Recursive: true,
2016-06-17 12:32:48 -07:00
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo",
2016-05-15 11:52:36 -07:00
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
2016-06-17 12:10:05 -07:00
StartIndex: 0,
Limit: pageSize
2016-05-15 11:52:36 -07:00
},
view: libraryBrowser.getSavedView(key) || 'PosterCard'
2016-05-15 11:52:36 -07:00
};
2016-06-17 12:10:05 -07:00
pageData.query.ParentId = params.topParentId;
libraryBrowser.loadSavedQueryValues(key, pageData.query);
2016-05-15 11:52:36 -07:00
}
return pageData;
2015-07-06 19:25:23 -07:00
}
2015-09-03 11:07:15 -07:00
2016-05-15 11:52:36 -07:00
function getQuery(context) {
2015-09-03 11:07:15 -07:00
2016-05-15 11:52:36 -07:00
return getPageData(context).query;
}
2015-07-06 19:25:23 -07:00
2016-05-15 11:52:36 -07:00
function getSavedQueryKey(context) {
2014-05-01 19:54:33 -07:00
2016-05-15 11:52:36 -07:00
if (!context.savedQueryKey) {
2016-06-17 12:10:05 -07:00
context.savedQueryKey = libraryBrowser.getSavedQueryKey('musicalbums');
2016-05-15 11:52:36 -07:00
}
return context.savedQueryKey;
2016-02-26 12:02:53 -07:00
}
2014-05-01 19:54:33 -07:00
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) {
2013-04-21 21:38:03 -07:00
2016-05-15 11:52:36 -07:00
Dashboard.showLoadingMsg();
2013-04-21 21:38:03 -07:00
2016-05-15 11:52:36 -07:00
var query = getQuery(page);
2015-07-06 19:25:23 -07:00
2016-05-15 11:52:36 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
2013-04-21 21:38:03 -07:00
2016-05-15 11:52:36 -07:00
// Scroll back up so they can see the results from the beginning
window.scrollTo(0, 0);
2013-05-17 12:18:54 -07:00
2016-06-17 12:10:05 -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:10:05 -07:00
addLayoutButton: false,
sortButton: false,
filterButton: false
2016-05-15 11:52:36 -07:00
});
2015-01-28 12:30:45 -07:00
2016-06-17 12:10:05 -07:00
var html;
var viewStyle = self.getCurrentViewStyle();
2016-05-15 11:52:36 -07:00
2016-06-17 12:10:05 -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,
context: 'music',
2016-06-17 12:10:05 -07:00
sortBy: query.SortBy
2016-05-15 11:52:36 -07:00
});
}
2016-06-17 12:10:05 -07:00
else if (viewStyle == "PosterCard") {
2016-05-15 11:52:36 -07:00
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,
showParentTitle: true,
lazy: true,
cardLayout: true
});
}
2016-06-17 12:10:05 -07:00
else {
2013-04-21 21:38:03 -07:00
2016-06-17 12:10:05 -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,
showParentTitle: true,
2016-06-17 12:10:05 -07:00
lazy: true,
centerText: true,
overlayPlayButton: true
2016-05-15 11:52:36 -07:00
});
}
2013-10-18 09:09:47 -07:00
2016-06-17 12:10:05 -07:00
var i, length;
var elems = tabContent.querySelectorAll('.paging');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].innerHTML = pagingHtml;
}
2016-06-17 12:10:05 -07:00
function onNextPageClick() {
2016-05-15 11:52:36 -07:00
query.StartIndex += query.Limit;
2016-06-17 12:10:05 -07:00
reloadItems(tabContent);
}
2013-04-21 21:38:03 -07:00
2016-06-17 12:10:05 -07:00
function onPreviousPageClick() {
2016-05-15 11:52:36 -07:00
query.StartIndex -= query.Limit;
2016-06-17 12:10:05 -07:00
reloadItems(tabContent);
}
elems = tabContent.querySelectorAll('.btnNextPage');
for (i = 0, length = elems.length; i < length; i++) {
elems[i].addEventListener('click', onNextPageClick);
}
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);
Dashboard.hideLoadingMsg();
});
}
self.showFilterMenu = function () {
require(['components/filterdialog/filterdialog'], function (filterDialogFactory) {
var filterDialog = new filterDialogFactory({
query: getQuery(tabContent),
mode: 'albums'
2016-05-15 11:52:36 -07:00
});
2016-02-15 09:57:51 -07:00
2016-06-17 12:10:05 -07:00
Events.on(filterDialog, 'filterchange', function () {
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
2016-05-15 11:52:36 -07:00
});
2015-09-03 11:07:15 -07:00
2016-06-17 12:10:05 -07:00
filterDialog.show();
});
}
2015-10-02 11:30:27 -07:00
2016-06-17 12:10:05 -07:00
function updateFilterControls(tabContent) {
2015-10-02 11:30:27 -07:00
2016-06-17 12:10:05 -07:00
var query = getQuery(tabContent);
self.alphaPicker.value(query.NameStartsWithOrGreater);
}
2015-09-03 11:07:15 -07:00
2016-06-17 12:10:05 -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();
});
tabContent.querySelector('.btnSort').addEventListener('click', function (e) {
libraryBrowser.showSortMenu({
items: [{
name: Globalize.translate('OptionNameSort'),
id: 'SortName'
},
2016-05-15 11:52:36 -07:00
{
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'
}],
2016-06-17 12:10:05 -07:00
callback: function () {
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
},
query: getQuery(tabContent),
button: e.target
2015-09-03 11:07:15 -07:00
});
2013-04-21 21:38:03 -07:00
});
2016-06-17 12:44:19 -07:00
var btnSelectView = tabContent.querySelector('.btnSelectView');
btnSelectView.addEventListener('click', function (e) {
2016-06-17 12:10:05 -07:00
libraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), 'List,Poster,PosterCard'.split(','));
2016-02-15 09:57:51 -07:00
});
2016-06-17 12:44:19 -07:00
btnSelectView.addEventListener('layoutchange', function (e) {
2013-04-21 21:38:03 -07:00
2016-06-17 12:10:05 -07:00
var viewStyle = e.detail.viewStyle;
2013-04-21 21:38:03 -07:00
2016-06-17 12:10:05 -07:00
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:10:05 -07:00
reloadItems(tabContent);
});
2016-05-15 11:52:36 -07:00
}
2013-05-15 05:05:07 -07:00
2016-06-17 12:10:05 -07:00
self.getCurrentViewStyle = function () {
return getPageData(tabContent).view;
};
2016-06-17 12:10:05 -07:00
initPage(tabContent);
2016-07-30 11:09:08 -07:00
onViewStyleChange();
2013-05-15 12:40:47 -07:00
2016-05-15 11:52:36 -07:00
self.renderTab = function () {
2016-05-15 11:52:36 -07:00
reloadItems(tabContent);
2016-06-17 12:10:05 -07:00
updateFilterControls(tabContent);
};
self.destroy = function () {
2016-05-15 11:52:36 -07:00
};
2015-09-03 11:07:15 -07:00
};
});