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

195 lines
6.1 KiB
JavaScript
Raw Normal View History

2013-04-22 20:56:11 -07:00
(function ($, document) {
var defaultSortBy = "Album,SortName";
2015-09-03 09:39:24 -07:00
var data = {};
function getPageData() {
var key = getSavedQueryKey();
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
}
2015-09-03 09:39:24 -07:00
function getQuery() {
2015-09-03 09:39:24 -07:00
return getPageData().query;
}
2015-09-03 09:39:24 -07:00
function getSavedQueryKey() {
2015-09-03 11:07:15 -07:00
return getWindowUrl() + 'songs';
}
2015-09-03 09:39:24 -07:00
function reloadItems(page, viewPanel) {
2013-04-22 20:56:11 -07:00
Dashboard.showLoadingMsg();
2015-09-03 09:39:24 -07:00
var query = getQuery();
2013-04-22 20:56:11 -07:00
ApiClient.getItems(Dashboard.getCurrentUserId(), query).done(function (result) {
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,
viewButton: true,
2015-05-11 12:59:59 -07:00
showLimit: false,
2015-09-03 09:39:24 -07:00
sortButton: true,
viewPanelClass: 'songsViewPanel',
2015-09-03 12:04:29 -07:00
updatePageSizeSetting: false,
viewIcon: 'filter-list'
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
2015-06-29 13:38:15 -07:00
Events.trigger(elem, 'create');
2013-04-22 20:56:11 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
2015-09-03 09:39:24 -07:00
reloadItems(page, viewPanel);
2013-04-22 20:56:11 -07:00
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
2015-09-03 09:39:24 -07:00
reloadItems(page, viewPanel);
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 () {
reloadItems(page, viewPanel);
},
query: query
});
});
2014-05-01 19:54:33 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
2013-04-22 20:56:11 -07:00
Dashboard.hideLoadingMsg();
});
}
2015-09-03 09:39:24 -07:00
function reloadFiltersIfNeeded(page, viewPanel) {
2015-09-03 11:07:15 -07:00
if (!getPageData().filtersLoaded) {
2015-09-03 11:07:15 -07:00
getPageData().filtersLoaded = true;
2015-09-03 09:39:24 -07:00
var query = getQuery();
QueryFilters.loadFilters(viewPanel, Dashboard.getCurrentUserId(), query, function () {
2015-09-03 09:39:24 -07:00
reloadItems(page, viewPanel);
});
}
}
2015-09-03 09:39:24 -07:00
function initPage(tabContent, viewPanel) {
2015-09-03 09:39:24 -07:00
$(viewPanel).on('panelopen', function () {
2013-04-22 20:56:11 -07:00
2015-09-03 09:39:24 -07:00
reloadFiltersIfNeeded(tabContent, viewPanel);
2013-04-22 20:56:11 -07:00
});
2015-09-03 09:39:24 -07:00
$('.chkStandardFilter', viewPanel).on('change', function () {
2013-04-22 20:56:11 -07:00
2015-09-03 09:39:24 -07:00
var query = getQuery();
2013-04-22 20:56:11 -07:00
var filterName = this.getAttribute('data-filter');
var filters = query.Filters || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
query.StartIndex = 0;
query.Filters = filters;
2015-09-03 09:39:24 -07:00
reloadItems(tabContent, viewPanel);
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.initSongsTab = function (page, tabContent) {
2014-05-01 19:54:33 -07:00
2015-09-03 09:39:24 -07:00
var viewPanel = page.querySelector('.songsViewPanel');
initPage(tabContent, viewPanel);
};
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)) {
var viewPanel = page.querySelector('.songsViewPanel');
reloadItems(tabContent, viewPanel);
}
};
2013-04-22 20:56:11 -07:00
})(jQuery, document);