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

168 lines
5.3 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2013-04-22 20:56:11 -07:00
var defaultSortBy = "Album,SortName";
2015-09-03 09:39:24 -07:00
var data = {};
2016-02-26 12:02:53 -07:00
function getPageData(context) {
var key = getSavedQueryKey(context);
2015-09-03 09:39:24 -07:00
var pageData = data[key];
if (!pageData) {
pageData = data[key] = {
query: {
SortBy: defaultSortBy,
SortOrder: "Ascending",
IncludeItemTypes: "Audio",
Recursive: true,
Fields: "AudioInfo,ParentId,SyncInfo",
Limit: 100,
StartIndex: 0,
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
}
};
2013-04-22 20:56:11 -07:00
2015-09-03 09:39:24 -07:00
pageData.query.ParentId = LibraryMenu.getTopParentId();
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
}
return pageData;
2014-05-01 19:54:33 -07:00
}
2016-02-26 12:02:53 -07:00
function getQuery(context) {
2016-02-26 12:02:53 -07:00
return getPageData(context).query;
2015-09-03 09:39:24 -07:00
}
2016-02-26 12:02:53 -07:00
function getSavedQueryKey(context) {
2016-02-26 12:02:53 -07:00
if (!context.savedQueryKey) {
context.savedQueryKey = LibraryBrowser.getSavedQueryKey('songs');
}
return context.savedQueryKey;
}
2016-02-15 09:57:51 -07:00
function reloadItems(page) {
2013-04-22 20:56:11 -07:00
Dashboard.showLoadingMsg();
2016-02-26 12:02:53 -07:00
var query = getQuery(page);
2015-12-14 08:43:03 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
2013-04-22 20:56:11 -07:00
2013-05-17 12:18:54 -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-05-17 12:18:54 -07:00
2013-04-22 20:56:11 -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,
2015-05-11 12:59:59 -07:00
showLimit: false,
2015-09-03 09:39:24 -07:00
sortButton: true,
2015-09-03 12:04:29 -07:00
updatePageSizeSetting: false,
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-22 20:56:11 -07:00
2014-08-19 15:28:35 -07:00
html += LibraryBrowser.getListViewHtml({
items: result.Items,
2014-08-30 07:26:29 -07:00
showIndex: true,
2015-06-05 07:27:01 -07:00
defaultAction: 'play',
smallIcon: true
2013-04-22 20:56:11 -07:00
});
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('#items');
elem.innerHTML = html + pagingHtml;
ImageLoader.lazyChildren(elem);
2015-01-28 12:30:45 -07:00
2013-04-22 20:56:11 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
2016-02-15 09:57:51 -07:00
reloadItems(page);
2013-04-22 20:56:11 -07:00
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
2016-02-15 09:57:51 -07:00
reloadItems(page);
});
$('.btnFilter', page).on('click', function () {
showFilterMenu(page);
2013-04-22 20:56:11 -07:00
});
2015-09-03 09:39:24 -07:00
// On callback make sure to set StartIndex = 0
$('.btnSort', page).on('click', function () {
LibraryBrowser.showSortMenu({
items: [{
2015-09-03 11:07:15 -07:00
name: Globalize.translate('OptionTrackName'),
id: 'Name'
2015-09-03 09:39:24 -07:00
},
{
2015-09-03 11:07:15 -07:00
name: Globalize.translate('OptionAlbum'),
id: 'Album,SortName'
2015-09-03 09:39:24 -07:00
},
{
2015-09-03 11:07:15 -07:00
name: Globalize.translate('OptionAlbumArtist'),
id: 'AlbumArtist,Album,SortName'
2015-09-03 09:39:24 -07:00
},
{
2015-09-03 11:07:15 -07:00
name: Globalize.translate('OptionArtist'),
id: 'Artist,Album,SortName'
2015-09-03 09:39:24 -07:00
},
{
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'),
2015-09-03 11:07:15 -07:00
id: 'PremiereDate,AlbumArtist,Album,SortName'
2015-09-03 09:39:24 -07:00
},
{
name: Globalize.translate('OptionRuntime'),
2015-09-03 11:07:15 -07:00
id: 'Runtime,AlbumArtist,Album,SortName'
2015-09-03 09:39:24 -07:00
}],
callback: function () {
2016-02-15 09:57:51 -07:00
reloadItems(page);
2015-09-03 09:39:24 -07:00
},
query: query
});
});
2016-02-26 12:02:53 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
2013-04-22 20:56:11 -07:00
Dashboard.hideLoadingMsg();
});
}
2016-02-15 09:57:51 -07:00
function showFilterMenu(page) {
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: 'songs'
});
2013-04-22 20:56:11 -07:00
2016-02-15 09:57:51 -07:00
Events.on(filterDialog, 'filterchange', function () {
reloadItems(page);
});
2013-04-22 20:56:11 -07:00
2016-02-15 09:57:51 -07:00
filterDialog.show();
2013-04-22 20:56:11 -07:00
});
2015-09-03 09:39:24 -07:00
}
2013-04-22 20:56:11 -07:00
2015-09-03 09:39:24 -07:00
window.MusicPage.renderSongsTab = function (page, tabContent) {
2013-04-22 20:56:11 -07:00
2015-09-03 09:39:24 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
2016-02-15 09:57:51 -07:00
reloadItems(tabContent);
2015-09-03 09:39:24 -07:00
}
};
2013-04-22 20:56:11 -07:00
});