2013-04-21 21:38:03 -07:00
|
|
|
|
(function ($, document) {
|
|
|
|
|
|
2015-07-06 19:25:23 -07:00
|
|
|
|
var data = {};
|
2015-09-03 11:07:15 -07:00
|
|
|
|
function getPageData() {
|
2015-07-06 19:25:23 -07:00
|
|
|
|
var key = getSavedQueryKey();
|
|
|
|
|
var pageData = data[key];
|
|
|
|
|
|
|
|
|
|
if (!pageData) {
|
|
|
|
|
pageData = data[key] = {
|
|
|
|
|
query: {
|
2015-12-14 08:43:03 -07:00
|
|
|
|
SortBy: "SortName",
|
2015-07-06 19:25:23 -07:00
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
IncludeItemTypes: "MusicAlbum",
|
|
|
|
|
Recursive: true,
|
|
|
|
|
Fields: "PrimaryImageAspectRatio,SortName,SyncInfo",
|
|
|
|
|
StartIndex: 0,
|
|
|
|
|
ImageTypeLimit: 1,
|
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
|
|
|
|
Limit: LibraryBrowser.getDefaultPageSize()
|
2015-09-03 11:07:15 -07:00
|
|
|
|
},
|
|
|
|
|
view: LibraryBrowser.getSavedView(key) || LibraryBrowser.getDefaultItemsView('Poster', 'Poster')
|
2015-07-06 19:25:23 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pageData.query.ParentId = LibraryMenu.getTopParentId();
|
|
|
|
|
LibraryBrowser.loadSavedQueryValues(key, pageData.query);
|
|
|
|
|
}
|
2015-09-03 11:07:15 -07:00
|
|
|
|
return pageData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getQuery() {
|
|
|
|
|
|
|
|
|
|
return getPageData().query;
|
2015-07-06 19:25:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
function getSavedQueryKey() {
|
|
|
|
|
|
2015-10-14 21:32:10 -07:00
|
|
|
|
return LibraryBrowser.getSavedQueryKey('albums');
|
2014-05-01 19:54:33 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
function reloadItems(page, viewPanel) {
|
2013-04-21 21:38:03 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2015-07-06 19:25:23 -07:00
|
|
|
|
var query = getQuery();
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function (result) {
|
2013-04-21 21:38:03 -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-21 21:38:03 -07:00
|
|
|
|
var html = '';
|
2015-09-03 11:07:15 -07:00
|
|
|
|
var view = getPageData().view;
|
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,
|
2014-08-02 19:16:37 -07:00
|
|
|
|
showLimit: false,
|
2015-09-03 11:07:15 -07:00
|
|
|
|
sortButton: true,
|
|
|
|
|
viewPanelClass: 'albumsViewPanel',
|
|
|
|
|
addLayoutButton: true,
|
|
|
|
|
currentLayout: view,
|
2015-09-03 12:04:29 -07:00
|
|
|
|
updatePageSizeSetting: false,
|
2015-10-02 11:30:27 -07:00
|
|
|
|
viewIcon: 'filter-list',
|
|
|
|
|
layouts: 'List,Poster,PosterCard,Timeline'
|
2015-01-28 12:30:45 -07:00
|
|
|
|
});
|
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
page.querySelector('.listTopPaging').innerHTML = pagingHtml;
|
2013-04-21 21:38:03 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
updateFilterControls(page, viewPanel);
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2013-05-15 05:05:07 -07:00
|
|
|
|
if (view == "Poster") {
|
2013-12-23 08:26:36 -07:00
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
2013-05-15 05:05:07 -07:00
|
|
|
|
items: result.Items,
|
2013-12-23 08:26:36 -07:00
|
|
|
|
shape: "square",
|
|
|
|
|
context: 'music',
|
|
|
|
|
showTitle: true,
|
2014-04-09 21:12:04 -07:00
|
|
|
|
showParentTitle: true,
|
2015-07-06 00:06:09 -07:00
|
|
|
|
lazy: true,
|
|
|
|
|
centerText: true,
|
|
|
|
|
overlayPlayButton: true
|
2014-11-10 20:41:19 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (view == "PosterCard") {
|
|
|
|
|
|
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "square",
|
|
|
|
|
context: 'music',
|
|
|
|
|
showTitle: true,
|
|
|
|
|
coverImage: true,
|
|
|
|
|
showParentTitle: true,
|
2014-08-02 19:16:37 -07:00
|
|
|
|
lazy: true,
|
2014-11-10 20:41:19 -07:00
|
|
|
|
cardLayout: true
|
2013-05-15 05:05:07 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2014-07-05 09:51:39 -07:00
|
|
|
|
else if (view == "List") {
|
|
|
|
|
|
|
|
|
|
html = LibraryBrowser.getListViewHtml({
|
|
|
|
|
items: result.Items,
|
2014-07-05 12:57:18 -07:00
|
|
|
|
context: 'music',
|
|
|
|
|
sortBy: query.SortBy
|
2014-07-05 09:51:39 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2013-05-15 05:05:07 -07:00
|
|
|
|
else if (view == "Timeline") {
|
2014-01-02 14:21:06 -07:00
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
2013-05-15 05:05:07 -07:00
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "square",
|
2014-01-02 14:21:06 -07:00
|
|
|
|
context: 'music',
|
|
|
|
|
showTitle: true,
|
|
|
|
|
showParentTitle: true,
|
2014-04-09 21:12:04 -07:00
|
|
|
|
timeline: true,
|
2014-11-10 20:41:19 -07:00
|
|
|
|
lazy: true
|
2013-05-15 05:05:07 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
2013-04-21 21:38:03 -07:00
|
|
|
|
|
2015-06-28 07:45:21 -07:00
|
|
|
|
var elem = page.querySelector('#items');
|
|
|
|
|
elem.innerHTML = html + pagingHtml;
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
2013-04-21 21:38:03 -07:00
|
|
|
|
|
|
|
|
|
$('.btnNextPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex += query.Limit;
|
2015-09-03 11:07:15 -07:00
|
|
|
|
reloadItems(page, viewPanel);
|
2013-04-21 21:38:03 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnPreviousPage', page).on('click', function () {
|
|
|
|
|
query.StartIndex -= query.Limit;
|
2015-09-03 11:07:15 -07:00
|
|
|
|
reloadItems(page, viewPanel);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnChangeLayout', page).on('layoutchange', function (e, layout) {
|
2015-10-02 11:30:27 -07:00
|
|
|
|
|
|
|
|
|
if (layout == 'Timeline') {
|
2015-12-14 08:43:03 -07:00
|
|
|
|
getQuery().SortBy = 'ProductionYear,PremiereDate,SortName';
|
2015-10-02 11:30:27 -07:00
|
|
|
|
getQuery().SortOrder = 'Descending';
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
getPageData().view = layout;
|
|
|
|
|
LibraryBrowser.saveViewSetting(getSavedQueryKey(), layout);
|
|
|
|
|
reloadItems(page, viewPanel);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// On callback make sure to set StartIndex = 0
|
|
|
|
|
$('.btnSort', page).on('click', function () {
|
|
|
|
|
LibraryBrowser.showSortMenu({
|
|
|
|
|
items: [{
|
|
|
|
|
name: Globalize.translate('OptionNameSort'),
|
|
|
|
|
id: 'SortName'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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'
|
|
|
|
|
}],
|
|
|
|
|
callback: function () {
|
|
|
|
|
reloadItems(page, viewPanel);
|
|
|
|
|
},
|
|
|
|
|
query: query
|
|
|
|
|
});
|
2013-04-21 21:38:03 -07:00
|
|
|
|
});
|
|
|
|
|
|
2014-05-01 19:54:33 -07:00
|
|
|
|
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
|
2015-07-06 19:25:23 -07:00
|
|
|
|
LibraryBrowser.setLastRefreshed(page);
|
2013-04-21 21:38:03 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
function updateFilterControls(page, viewPanel) {
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2015-07-06 19:25:23 -07:00
|
|
|
|
var query = getQuery();
|
|
|
|
|
|
2013-10-18 09:09:47 -07:00
|
|
|
|
$('.alphabetPicker', page).alphaValue(query.NameStartsWith);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
function reloadFiltersIfNeeded(page, viewPanel) {
|
2014-11-09 21:20:11 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
if (!getPageData().filtersLoaded) {
|
2014-11-09 21:20:11 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
getPageData().filtersLoaded = true;
|
2014-11-09 21:20:11 -07:00
|
|
|
|
|
2015-07-06 19:25:23 -07:00
|
|
|
|
var query = getQuery();
|
2015-09-03 11:07:15 -07:00
|
|
|
|
QueryFilters.loadFilters(viewPanel, Dashboard.getCurrentUserId(), query, function () {
|
2015-07-06 19:25:23 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
reloadItems(page, viewPanel);
|
2014-11-09 21:20:11 -07:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
function initPage(tabContent, viewPanel) {
|
2014-11-09 21:20:11 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
$(viewPanel).on('panelopen', function () {
|
2013-09-06 12:17:15 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
reloadFiltersIfNeeded(tabContent, viewPanel);
|
2013-04-21 21:38:03 -07:00
|
|
|
|
});
|
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
$('.chkStandardFilter', viewPanel).on('change', function () {
|
2013-09-06 12:17:15 -07:00
|
|
|
|
|
2015-07-06 19:25:23 -07:00
|
|
|
|
var query = getQuery();
|
2013-04-21 21:38:03 -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 11:07:15 -07:00
|
|
|
|
reloadItems(tabContent, viewPanel);
|
2013-05-15 05:05:07 -07:00
|
|
|
|
});
|
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
$('.alphabetPicker', tabContent).on('alphaselect', function (e, character) {
|
2013-05-16 12:00:42 -07:00
|
|
|
|
|
2015-07-06 19:25:23 -07:00
|
|
|
|
var query = getQuery();
|
|
|
|
|
|
2013-09-06 12:17:15 -07:00
|
|
|
|
if (query.SortBy.indexOf('AlbumArtist') == -1) {
|
|
|
|
|
query.NameStartsWithOrGreater = character;
|
|
|
|
|
query.AlbumArtistStartsWithOrGreater = '';
|
|
|
|
|
} else {
|
|
|
|
|
query.AlbumArtistStartsWithOrGreater = character;
|
|
|
|
|
query.NameStartsWithOrGreater = '';
|
|
|
|
|
}
|
2013-10-18 09:09:47 -07:00
|
|
|
|
|
2013-05-17 11:05:49 -07:00
|
|
|
|
query.StartIndex = 0;
|
2013-05-16 12:00:42 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
reloadItems(tabContent, viewPanel);
|
2013-05-16 12:00:42 -07:00
|
|
|
|
|
|
|
|
|
}).on('alphaclear', function (e) {
|
|
|
|
|
|
2015-07-06 19:25:23 -07:00
|
|
|
|
var query = getQuery();
|
|
|
|
|
|
2013-05-16 20:24:41 -07:00
|
|
|
|
query.NameStartsWithOrGreater = '';
|
2013-09-06 12:17:15 -07:00
|
|
|
|
query.AlbumArtistStartsWithOrGreater = '';
|
2013-05-16 12:00:42 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
reloadItems(tabContent, viewPanel);
|
2014-07-19 21:46:29 -07:00
|
|
|
|
});
|
2015-09-03 11:07:15 -07:00
|
|
|
|
}
|
2014-07-19 21:46:29 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
window.MusicPage.initAlbumsTab = function (page, tabContent) {
|
2013-04-21 21:38:03 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
var viewPanel = page.querySelector('.albumsViewPanel');
|
|
|
|
|
initPage(tabContent, viewPanel);
|
|
|
|
|
};
|
2013-05-15 12:40:47 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
window.MusicPage.renderAlbumsTab = function (page, tabContent) {
|
2013-10-17 13:59:46 -07:00
|
|
|
|
|
2015-09-03 11:07:15 -07:00
|
|
|
|
if (LibraryBrowser.needsRefresh(tabContent)) {
|
|
|
|
|
var viewPanel = page.querySelector('.albumsViewPanel');
|
|
|
|
|
reloadItems(tabContent, viewPanel);
|
2015-07-06 19:25:23 -07:00
|
|
|
|
}
|
2015-09-03 11:07:15 -07:00
|
|
|
|
};
|
2013-04-21 21:38:03 -07:00
|
|
|
|
|
|
|
|
|
})(jQuery, document);
|