2013-04-25 16:28:01 -07:00
|
|
|
|
(function ($, document) {
|
|
|
|
|
|
2015-04-12 22:12:02 -07:00
|
|
|
|
function itemsPerRow() {
|
2015-05-16 12:09:02 -07:00
|
|
|
|
|
2015-04-12 22:12:02 -07:00
|
|
|
|
var screenWidth = $(window).width();
|
|
|
|
|
|
2015-04-29 10:39:23 -07:00
|
|
|
|
return screenWidth >= 1920 ? 9 : (screenWidth >= 1200 ? 12 : (screenWidth >= 1000 ? 10 : 8));
|
2015-04-12 22:12:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-16 12:09:02 -07:00
|
|
|
|
function enableScrollX() {
|
2015-06-04 13:27:46 -07:00
|
|
|
|
return $.browser.mobile && AppInfo.enableAppLayouts;
|
2015-05-16 12:09:02 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSquareShape() {
|
|
|
|
|
return enableScrollX() ? 'overflowSquare' : 'square';
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-11 18:38:38 -07:00
|
|
|
|
function loadLatest(page, parentId) {
|
2013-04-25 16:28:01 -07:00
|
|
|
|
|
2015-06-17 08:39:46 -07:00
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
2014-07-04 22:21:13 -07:00
|
|
|
|
var userId = Dashboard.getCurrentUserId();
|
2014-02-17 14:35:08 -07:00
|
|
|
|
|
2013-04-25 16:28:01 -07:00
|
|
|
|
var options = {
|
|
|
|
|
IncludeItemTypes: "Audio",
|
2015-04-12 22:12:02 -07:00
|
|
|
|
Limit: itemsPerRow(),
|
2014-12-10 23:20:28 -07:00
|
|
|
|
Fields: "PrimaryImageAspectRatio,SyncInfo",
|
2014-11-30 12:01:33 -07:00
|
|
|
|
ParentId: parentId,
|
|
|
|
|
ImageTypeLimit: 1,
|
2014-12-01 05:43:34 -07:00
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
|
2013-04-25 16:28:01 -07:00
|
|
|
|
};
|
|
|
|
|
|
2014-07-04 22:21:13 -07:00
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl('Users/' + userId + '/Items/Latest', options)).done(function (items) {
|
2013-04-25 16:28:01 -07:00
|
|
|
|
|
2015-06-28 08:43:49 -07:00
|
|
|
|
var elem = page.querySelector('#recentlyAddedSongs');
|
|
|
|
|
elem.innerHTML = LibraryBrowser.getPosterViewHtml({
|
2014-07-04 22:21:13 -07:00
|
|
|
|
items: items,
|
2013-12-27 14:20:27 -07:00
|
|
|
|
showUnplayedIndicator: false,
|
2015-05-11 12:59:59 -07:00
|
|
|
|
showLatestItemsPopup: false,
|
2015-05-16 12:09:02 -07:00
|
|
|
|
shape: getSquareShape(),
|
2013-04-25 17:52:55 -07:00
|
|
|
|
showTitle: true,
|
2015-07-26 14:02:23 -07:00
|
|
|
|
defaultAction: 'play',
|
2015-01-22 23:15:15 -07:00
|
|
|
|
showParentTitle: true,
|
2015-04-11 18:38:38 -07:00
|
|
|
|
lazy: true,
|
2015-07-06 00:06:09 -07:00
|
|
|
|
centerText: true,
|
2015-07-26 14:02:23 -07:00
|
|
|
|
overlayMoreButton: true
|
2015-04-11 18:38:38 -07:00
|
|
|
|
|
2015-06-28 08:43:49 -07:00
|
|
|
|
});
|
|
|
|
|
ImageLoader.lazyChildren(elem);
|
2013-04-25 17:52:55 -07:00
|
|
|
|
|
2015-06-17 08:39:46 -07:00
|
|
|
|
Dashboard.hideLoadingMsg();
|
2015-06-29 22:45:20 -07:00
|
|
|
|
|
|
|
|
|
LibraryBrowser.setLastRefreshed(page);
|
2013-04-25 17:52:55 -07:00
|
|
|
|
});
|
2015-04-11 18:38:38 -07:00
|
|
|
|
}
|
2013-04-25 17:52:55 -07:00
|
|
|
|
|
2015-04-11 18:38:38 -07:00
|
|
|
|
function loadRecentlyPlayed(page, parentId) {
|
|
|
|
|
|
|
|
|
|
var options = {
|
2013-04-25 17:52:55 -07:00
|
|
|
|
|
|
|
|
|
SortBy: "DatePlayed",
|
|
|
|
|
SortOrder: "Descending",
|
|
|
|
|
IncludeItemTypes: "Audio",
|
2015-04-12 22:12:02 -07:00
|
|
|
|
Limit: itemsPerRow(),
|
2013-04-25 17:52:55 -07:00
|
|
|
|
Recursive: true,
|
2014-12-10 23:20:28 -07:00
|
|
|
|
Fields: "PrimaryImageAspectRatio,AudioInfo,SyncInfo",
|
2014-05-01 19:54:33 -07:00
|
|
|
|
Filters: "IsPlayed",
|
2014-11-30 12:01:33 -07:00
|
|
|
|
ParentId: parentId,
|
|
|
|
|
ImageTypeLimit: 1,
|
2014-12-01 05:43:34 -07:00
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
|
2013-04-25 17:52:55 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), options).done(function (result) {
|
|
|
|
|
|
2015-06-28 08:43:49 -07:00
|
|
|
|
var elem;
|
|
|
|
|
|
2013-04-25 17:52:55 -07:00
|
|
|
|
if (result.Items.length) {
|
2015-06-28 08:43:49 -07:00
|
|
|
|
elem = $('#recentlyPlayed', page).show()[0];
|
2013-04-25 17:52:55 -07:00
|
|
|
|
} else {
|
2015-06-28 08:43:49 -07:00
|
|
|
|
elem = $('#recentlyPlayed', page).hide()[0];
|
2013-04-25 17:52:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-28 08:43:49 -07:00
|
|
|
|
var itemsContainer = elem.querySelector('.itemsContainer');
|
|
|
|
|
itemsContainer.innerHTML = LibraryBrowser.getPosterViewHtml({
|
2013-04-25 17:52:55 -07:00
|
|
|
|
items: result.Items,
|
2013-12-27 14:20:27 -07:00
|
|
|
|
showUnplayedIndicator: false,
|
2015-05-16 12:09:02 -07:00
|
|
|
|
shape: getSquareShape(),
|
2013-04-25 17:52:55 -07:00
|
|
|
|
showTitle: true,
|
2014-09-01 13:10:54 -07:00
|
|
|
|
showParentTitle: true,
|
2015-10-07 14:42:29 -07:00
|
|
|
|
defaultAction: 'instantmix',
|
2015-04-11 18:38:38 -07:00
|
|
|
|
lazy: true,
|
2015-07-06 00:06:09 -07:00
|
|
|
|
centerText: true,
|
|
|
|
|
overlayMoreButton: true
|
2014-09-01 13:10:54 -07:00
|
|
|
|
|
2015-06-28 08:43:49 -07:00
|
|
|
|
});
|
|
|
|
|
ImageLoader.lazyChildren(itemsContainer);
|
2013-04-25 17:52:55 -07:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2015-04-11 18:38:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadFrequentlyPlayed(page, parentId) {
|
|
|
|
|
|
|
|
|
|
var options = {
|
2013-04-25 17:52:55 -07:00
|
|
|
|
|
|
|
|
|
SortBy: "PlayCount",
|
|
|
|
|
SortOrder: "Descending",
|
|
|
|
|
IncludeItemTypes: "Audio",
|
2015-04-12 22:12:02 -07:00
|
|
|
|
Limit: itemsPerRow(),
|
2013-04-25 17:52:55 -07:00
|
|
|
|
Recursive: true,
|
2014-12-10 23:20:28 -07:00
|
|
|
|
Fields: "PrimaryImageAspectRatio,AudioInfo,SyncInfo",
|
2014-05-01 19:54:33 -07:00
|
|
|
|
Filters: "IsPlayed",
|
2014-11-30 12:01:33 -07:00
|
|
|
|
ParentId: parentId,
|
|
|
|
|
ImageTypeLimit: 1,
|
2014-12-01 05:43:34 -07:00
|
|
|
|
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
|
2013-04-25 17:52:55 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), options).done(function (result) {
|
|
|
|
|
|
2015-06-28 08:43:49 -07:00
|
|
|
|
var elem;
|
|
|
|
|
|
2013-04-25 17:52:55 -07:00
|
|
|
|
if (result.Items.length) {
|
2015-06-28 08:43:49 -07:00
|
|
|
|
elem = $('#topPlayed', page).show()[0];
|
2013-04-25 17:52:55 -07:00
|
|
|
|
} else {
|
2015-06-28 08:43:49 -07:00
|
|
|
|
elem = $('#topPlayed', page).hide()[0];
|
2013-04-25 17:52:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-28 08:43:49 -07:00
|
|
|
|
var itemsContainer = elem.querySelector('.itemsContainer');
|
|
|
|
|
itemsContainer.innerHTML = LibraryBrowser.getPosterViewHtml({
|
2013-04-25 17:52:55 -07:00
|
|
|
|
items: result.Items,
|
2013-12-27 14:20:27 -07:00
|
|
|
|
showUnplayedIndicator: false,
|
2015-05-16 12:09:02 -07:00
|
|
|
|
shape: getSquareShape(),
|
2013-04-25 17:52:55 -07:00
|
|
|
|
showTitle: true,
|
2014-09-01 13:10:54 -07:00
|
|
|
|
showParentTitle: true,
|
2015-10-07 14:42:29 -07:00
|
|
|
|
defaultAction: 'instantmix',
|
2015-04-11 18:38:38 -07:00
|
|
|
|
lazy: true,
|
2015-07-06 00:06:09 -07:00
|
|
|
|
centerText: true,
|
|
|
|
|
overlayMoreButton: true
|
2014-09-01 13:10:54 -07:00
|
|
|
|
|
2015-06-28 08:43:49 -07:00
|
|
|
|
});
|
|
|
|
|
ImageLoader.lazyChildren(itemsContainer);
|
2013-04-25 16:28:01 -07:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2015-04-11 18:38:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadPlaylists(page, parentId) {
|
|
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
|
|
|
|
|
|
SortBy: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
IncludeItemTypes: "Playlist",
|
|
|
|
|
Recursive: true,
|
2015-04-12 11:58:21 -07:00
|
|
|
|
ParentId: parentId,
|
2015-04-11 18:38:38 -07:00
|
|
|
|
Fields: "PrimaryImageAspectRatio,SortName,CumulativeRunTimeTicks,CanDelete,SyncInfo",
|
|
|
|
|
StartIndex: 0,
|
2015-04-12 22:12:02 -07:00
|
|
|
|
Limit: itemsPerRow()
|
2015-04-11 18:38:38 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ApiClient.getItems(Dashboard.getCurrentUserId(), options).done(function (result) {
|
|
|
|
|
|
|
|
|
|
var elem;
|
|
|
|
|
|
|
|
|
|
if (result.Items.length) {
|
2015-06-28 08:43:49 -07:00
|
|
|
|
elem = $('#playlists', page).show()[0];
|
2015-04-11 18:38:38 -07:00
|
|
|
|
} else {
|
2015-06-28 08:43:49 -07:00
|
|
|
|
elem = $('#playlists', page).hide()[0];
|
2015-04-11 18:38:38 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-28 08:43:49 -07:00
|
|
|
|
var itemsContainer = elem.querySelector('.itemsContainer');
|
|
|
|
|
itemsContainer.innerHTML = LibraryBrowser.getPosterViewHtml({
|
2015-04-11 18:38:38 -07:00
|
|
|
|
items: result.Items,
|
2015-05-16 12:09:02 -07:00
|
|
|
|
shape: getSquareShape(),
|
2015-04-11 18:38:38 -07:00
|
|
|
|
showTitle: true,
|
|
|
|
|
lazy: true,
|
2015-04-12 22:12:02 -07:00
|
|
|
|
defaultAction: 'play',
|
2015-04-11 18:38:38 -07:00
|
|
|
|
coverImage: true,
|
|
|
|
|
showItemCounts: true,
|
2015-07-06 00:06:09 -07:00
|
|
|
|
centerText: true,
|
|
|
|
|
overlayMoreButton: true
|
2015-04-11 18:38:38 -07:00
|
|
|
|
|
2015-06-28 08:43:49 -07:00
|
|
|
|
});
|
|
|
|
|
ImageLoader.lazyChildren(itemsContainer);
|
2015-04-11 18:38:38 -07:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-28 20:35:50 -07:00
|
|
|
|
function initSuggestedTab(page, tabContent) {
|
2015-04-11 18:38:38 -07:00
|
|
|
|
|
2015-09-03 09:39:24 -07:00
|
|
|
|
var containers = tabContent.querySelectorAll('.itemsContainer');
|
2015-05-16 12:09:02 -07:00
|
|
|
|
if (enableScrollX()) {
|
2015-06-28 07:45:21 -07:00
|
|
|
|
$(containers).addClass('hiddenScrollX');
|
2015-05-16 12:09:02 -07:00
|
|
|
|
} else {
|
2015-06-28 07:45:21 -07:00
|
|
|
|
$(containers).removeClass('hiddenScrollX');
|
2015-05-16 12:09:02 -07:00
|
|
|
|
}
|
2015-06-29 19:52:23 -07:00
|
|
|
|
|
2015-09-28 20:35:50 -07:00
|
|
|
|
$(containers).createCardMenus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadSuggestionsTab(page, tabContent) {
|
|
|
|
|
|
|
|
|
|
var parentId = LibraryMenu.getTopParentId();
|
|
|
|
|
|
2015-09-03 09:39:24 -07:00
|
|
|
|
if (LibraryBrowser.needsRefresh(tabContent)) {
|
|
|
|
|
console.log('loadSuggestionsTab');
|
|
|
|
|
loadLatest(tabContent, parentId);
|
|
|
|
|
loadPlaylists(tabContent, parentId);
|
|
|
|
|
loadRecentlyPlayed(tabContent, parentId);
|
|
|
|
|
loadFrequentlyPlayed(tabContent, parentId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadTab(page, index) {
|
|
|
|
|
|
|
|
|
|
var tabContent = page.querySelector('.pageTabContent[data-index=\'' + index + '\']');
|
|
|
|
|
var depends = [];
|
|
|
|
|
var scope = 'MusicPage';
|
|
|
|
|
var renderMethod = '';
|
|
|
|
|
var initMethod = '';
|
|
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
|
|
|
|
|
|
case 0:
|
2015-09-28 20:35:50 -07:00
|
|
|
|
initMethod = 'initSuggestedTab';
|
2015-09-03 09:39:24 -07:00
|
|
|
|
renderMethod = 'renderSuggestedTab';
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2015-09-03 11:07:15 -07:00
|
|
|
|
depends.push('scripts/musicalbums');
|
|
|
|
|
renderMethod = 'renderAlbumsTab';
|
|
|
|
|
initMethod = 'initAlbumsTab';
|
2015-09-03 09:39:24 -07:00
|
|
|
|
depends.push('scripts/queryfilters');
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2015-09-03 12:04:29 -07:00
|
|
|
|
depends.push('scripts/musicalbumartists');
|
|
|
|
|
renderMethod = 'renderAlbumArtistsTab';
|
|
|
|
|
initMethod = 'initAlbumArtistsTab';
|
|
|
|
|
depends.push('scripts/queryfilters');
|
2015-09-03 09:39:24 -07:00
|
|
|
|
break;
|
|
|
|
|
case 3:
|
2015-09-03 12:04:29 -07:00
|
|
|
|
depends.push('scripts/musicartists');
|
|
|
|
|
renderMethod = 'renderArtistsTab';
|
|
|
|
|
initMethod = 'initArtistsTab';
|
|
|
|
|
depends.push('scripts/queryfilters');
|
2015-09-03 09:39:24 -07:00
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
depends.push('scripts/songs');
|
|
|
|
|
renderMethod = 'renderSongsTab';
|
|
|
|
|
initMethod = 'initSongsTab';
|
|
|
|
|
depends.push('scripts/queryfilters');
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
depends.push('scripts/musicgenres');
|
|
|
|
|
renderMethod = 'renderGenresTab';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require(depends, function () {
|
|
|
|
|
|
|
|
|
|
if (initMethod && !tabContent.initComplete) {
|
|
|
|
|
|
|
|
|
|
window[scope][initMethod](page, tabContent);
|
|
|
|
|
tabContent.initComplete = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window[scope][renderMethod](page, tabContent);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.MusicPage = window.MusicPage || {};
|
|
|
|
|
window.MusicPage.renderSuggestedTab = loadSuggestionsTab;
|
2015-09-28 20:35:50 -07:00
|
|
|
|
window.MusicPage.initSuggestedTab = initSuggestedTab;
|
2015-09-03 09:39:24 -07:00
|
|
|
|
|
|
|
|
|
$(document).on('pageinit', "#musicRecommendedPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('.recommendations', page).createCardMenus();
|
|
|
|
|
|
|
|
|
|
var tabs = page.querySelector('paper-tabs');
|
|
|
|
|
var pages = page.querySelector('neon-animated-pages');
|
|
|
|
|
|
2015-09-03 12:04:29 -07:00
|
|
|
|
var baseUrl = 'music.html';
|
2015-09-03 09:39:24 -07:00
|
|
|
|
var topParentId = LibraryMenu.getTopParentId();
|
|
|
|
|
if (topParentId) {
|
|
|
|
|
baseUrl += '?topParentId=' + topParentId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LibraryBrowser.configurePaperLibraryTabs(page, tabs, pages, baseUrl);
|
|
|
|
|
|
|
|
|
|
$(pages).on('tabchange', function () {
|
|
|
|
|
loadTab(page, parseInt(this.selected));
|
|
|
|
|
});
|
|
|
|
|
|
2015-09-24 10:08:10 -07:00
|
|
|
|
}).on('pageshow', "#musicRecommendedPage", function () {
|
2015-09-03 09:39:24 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
if (!page.getAttribute('data-title')) {
|
|
|
|
|
|
|
|
|
|
var parentId = LibraryMenu.getTopParentId();
|
|
|
|
|
|
|
|
|
|
if (parentId) {
|
|
|
|
|
|
|
|
|
|
ApiClient.getItem(Dashboard.getCurrentUserId(), parentId).done(function (item) {
|
|
|
|
|
|
|
|
|
|
page.setAttribute('data-title', item.Name);
|
|
|
|
|
LibraryMenu.setTitle(item.Name);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
page.setAttribute('data-title', Globalize.translate('TabMusic'));
|
|
|
|
|
LibraryMenu.setTitle(Globalize.translate('TabMusic'));
|
|
|
|
|
}
|
2015-06-29 19:52:23 -07:00
|
|
|
|
}
|
2015-09-03 09:39:24 -07:00
|
|
|
|
|
2013-04-25 16:28:01 -07:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})(jQuery, document);
|