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

221 lines
7.9 KiB
JavaScript
Raw Normal View History

2016-06-17 12:44:19 -07:00
define(['events', 'libraryBrowser', 'imageLoader', 'alphaPicker'], function (events, libraryBrowser, imageLoader, alphaPicker) {
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: {
2016-06-17 12:44:19 -07:00
SortBy: "Album,SortName",
2016-05-15 11:52:36 -07:00
SortOrder: "Ascending",
IncludeItemTypes: "Audio",
Recursive: true,
Fields: "AudioInfo,ParentId,SyncInfo",
Limit: 100,
StartIndex: 0,
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
}
};
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:44:19 -07:00
context.savedQueryKey = libraryBrowser.getSavedQueryKey('songs');
2016-05-15 11:52:36 -07:00
}
return context.savedQueryKey;
}
2016-06-17 12:44:19 -07:00
function reloadItems(page) {
2016-05-15 11:52:36 -07:00
Dashboard.showLoadingMsg();
2016-06-17 12:44:19 -07:00
var query = getQuery(page);
2016-05-15 11:52:36 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
// 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 = LibraryBrowser.getListViewHtml({
2016-05-15 11:52:36 -07:00
items: result.Items,
showIndex: true,
defaultAction: 'play',
smallIcon: true
});
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);
}
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: 'songs'
2016-05-15 11:52:36 -07:00
});
2016-06-17 12:44:19 -07:00
Events.on(filterDialog, 'filterchange', function () {
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
2016-05-15 11:52:36 -07:00
});
2016-06-17 12:44:19 -07:00
filterDialog.show();
});
}
function updateFilterControls(tabContent) {
var query = getQuery(tabContent);
self.alphaPicker.value(query.NameStartsWithOrGreater);
}
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('OptionTrackName'),
id: 'Name'
},
2016-05-15 11:52:36 -07:00
{
name: Globalize.translate('OptionAlbum'),
id: 'Album,SortName'
},
{
name: Globalize.translate('OptionAlbumArtist'),
id: 'AlbumArtist,Album,SortName'
},
{
name: Globalize.translate('OptionArtist'),
id: 'Artist,Album,SortName'
},
{
name: Globalize.translate('OptionDateAdded'),
id: 'DateCreated,SortName'
},
{
name: Globalize.translate('OptionDatePlayed'),
id: 'DatePlayed,SortName'
},
{
name: Globalize.translate('OptionPlayCount'),
id: 'PlayCount,SortName'
},
{
name: Globalize.translate('OptionReleaseDate'),
id: 'PremiereDate,AlbumArtist,Album,SortName'
},
{
name: Globalize.translate('OptionRuntime'),
id: 'Runtime,AlbumArtist,Album,SortName'
}],
2016-06-17 12:44:19 -07:00
callback: function () {
getQuery(tabContent).StartIndex = 0;
reloadItems(tabContent);
},
query: getQuery(tabContent),
button: e.target
2016-05-15 11:52:36 -07:00
});
});
}
2016-06-17 12:44:19 -07:00
self.getCurrentViewStyle = function () {
return getPageData(tabContent).view;
};
2016-05-15 11:52:36 -07:00
2016-06-17 12:44:19 -07:00
initPage(tabContent);
2016-05-15 11:52:36 -07:00
2016-06-17 12:44:19 -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);
2016-05-15 11:52:36 -07:00
};
2016-06-17 12:44:19 -07:00
self.destroy = function () {
};
};
});