2013-04-01 20:54:06 -04:00
|
|
|
|
(function ($, document, apiClient) {
|
2013-02-20 20:33:05 -05:00
|
|
|
|
|
2014-06-07 15:46:24 -04:00
|
|
|
|
function getUserViews(userId) {
|
|
|
|
|
|
|
|
|
|
var deferred = $.Deferred();
|
|
|
|
|
|
|
|
|
|
ApiClient.getUserViews(userId).done(function (result) {
|
|
|
|
|
|
|
|
|
|
var items = result.Items;
|
|
|
|
|
|
|
|
|
|
deferred.resolveWith(null, [items]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
function getDefaultSection(index) {
|
|
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
|
|
|
|
|
|
case 0:
|
2014-06-14 19:13:09 -04:00
|
|
|
|
return 'smalllibrarytiles';
|
2014-05-21 15:33:46 -04:00
|
|
|
|
case 1:
|
|
|
|
|
return 'resume';
|
|
|
|
|
case 2:
|
|
|
|
|
return 'latestmedia';
|
2014-06-15 19:30:04 -04:00
|
|
|
|
case 3:
|
2014-06-20 00:50:30 -04:00
|
|
|
|
return '';
|
2014-05-21 15:33:46 -04:00
|
|
|
|
default:
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadRecentlyAdded(elem, userId) {
|
2014-05-20 20:56:24 -04:00
|
|
|
|
|
|
|
|
|
var screenWidth = $(window).width();
|
|
|
|
|
|
|
|
|
|
var options = {
|
2014-05-13 20:46:45 -04:00
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
SortBy: "DateCreated",
|
2014-05-01 22:54:33 -04:00
|
|
|
|
SortOrder: "Descending",
|
2014-06-16 08:22:38 -04:00
|
|
|
|
Limit: screenWidth >= 2400 ? 30 : (screenWidth >= 1920 ? 20 : (screenWidth >= 1440 ? 10 : (screenWidth >= 800 ? 9 : 8))),
|
2014-05-01 22:54:33 -04:00
|
|
|
|
Recursive: true,
|
|
|
|
|
Fields: "PrimaryImageAspectRatio",
|
2014-05-21 15:33:46 -04:00
|
|
|
|
Filters: "IsUnplayed,IsNotFolder",
|
2014-05-01 22:54:33 -04:00
|
|
|
|
CollapseBoxSetItems: false,
|
2014-05-21 15:33:46 -04:00
|
|
|
|
ExcludeLocationTypes: "Virtual,Remote"
|
2014-05-01 22:54:33 -04:00
|
|
|
|
};
|
2013-04-01 14:55:56 -04:00
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
ApiClient.getItems(userId, options).done(function (result) {
|
2013-04-01 14:55:56 -04:00
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
var html = '';
|
2013-11-20 16:08:12 -05:00
|
|
|
|
|
2014-05-21 23:35:18 -04:00
|
|
|
|
if (result.Items.length) {
|
2014-05-30 17:06:57 -04:00
|
|
|
|
html += '<h1 class="listHeader">' + Globalize.translate('HeaderLatestMedia') + '</h1>';
|
2014-05-21 23:35:18 -04:00
|
|
|
|
html += '<div>';
|
|
|
|
|
html += LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
shape: 'backdrop',
|
|
|
|
|
showTitle: true,
|
2014-05-29 15:34:20 -04:00
|
|
|
|
centerText: true,
|
2014-05-30 00:16:31 -04:00
|
|
|
|
context: 'home',
|
|
|
|
|
lazy: true
|
2014-05-21 23:35:18 -04:00
|
|
|
|
});
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
|
2014-05-30 00:16:31 -04:00
|
|
|
|
$(elem).html(html).trigger('create').createPosterItemMenus();
|
2014-05-21 15:33:46 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-15 19:30:04 -04:00
|
|
|
|
function loadLatestChannelMedia(elem, userId) {
|
|
|
|
|
|
|
|
|
|
var screenWidth = $(window).width();
|
|
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
|
|
2014-06-17 12:03:14 -04:00
|
|
|
|
Limit: screenWidth >= 2400 ? 10 : (screenWidth >= 1920 ? 10 : (screenWidth >= 1440 ? 8 : (screenWidth >= 800 ? 7 : 6))),
|
2014-06-15 19:30:04 -04:00
|
|
|
|
Fields: "PrimaryImageAspectRatio",
|
|
|
|
|
Filters: "IsUnplayed",
|
|
|
|
|
UserId: userId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$.getJSON(ApiClient.getUrl("Channels/Items/Latest", options)).done(function (result) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
|
|
|
|
if (result.Items.length) {
|
|
|
|
|
html += '<h1 class="listHeader">' + Globalize.translate('HeaderLatestChannelMedia') + '</h1>';
|
|
|
|
|
html += '<div>';
|
|
|
|
|
html += LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
preferThumb: true,
|
|
|
|
|
shape: 'auto',
|
|
|
|
|
showTitle: true,
|
|
|
|
|
centerText: true,
|
|
|
|
|
context: 'home',
|
|
|
|
|
lazy: true
|
|
|
|
|
});
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(elem).html(html).trigger('create').createPosterItemMenus();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-14 19:13:09 -04:00
|
|
|
|
function loadLibraryTiles(elem, userId, shape, index) {
|
2014-05-21 15:33:46 -04:00
|
|
|
|
|
2014-06-07 15:46:24 -04:00
|
|
|
|
getUserViews(userId).done(function (items) {
|
2014-05-21 15:33:46 -04:00
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
|
2014-06-07 15:46:24 -04:00
|
|
|
|
if (items.length) {
|
2014-06-14 19:13:09 -04:00
|
|
|
|
|
2014-06-20 00:50:30 -04:00
|
|
|
|
var cssClass = index ? 'listHeader' : 'listHeader firstListHeader';
|
|
|
|
|
|
|
|
|
|
html += '<h1 class="' + cssClass + '">' + Globalize.translate('HeaderMyLibrary') + '</h1>';
|
2014-06-14 19:13:09 -04:00
|
|
|
|
|
2014-05-21 23:35:18 -04:00
|
|
|
|
html += '<div>';
|
|
|
|
|
html += LibraryBrowser.getPosterViewHtml({
|
2014-06-07 15:46:24 -04:00
|
|
|
|
items: items,
|
|
|
|
|
shape: shape,
|
2014-05-21 23:35:18 -04:00
|
|
|
|
showTitle: true,
|
2014-05-30 00:16:31 -04:00
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true
|
2014-05-21 23:35:18 -04:00
|
|
|
|
});
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-06 15:21:42 -04:00
|
|
|
|
|
2014-05-30 00:16:31 -04:00
|
|
|
|
$(elem).html(html).trigger('create').createPosterItemMenus();
|
2014-05-23 21:16:53 -04:00
|
|
|
|
|
|
|
|
|
handleLibraryLinkNavigations(elem);
|
2013-05-14 01:36:36 -04:00
|
|
|
|
});
|
2014-05-21 15:33:46 -04:00
|
|
|
|
}
|
2013-04-04 13:27:36 -04:00
|
|
|
|
|
2014-06-14 19:13:09 -04:00
|
|
|
|
function loadLibraryFolders(elem, userId, shape, index) {
|
|
|
|
|
|
|
|
|
|
ApiClient.getItems(userId, {
|
|
|
|
|
|
|
|
|
|
SortBy: "SortName"
|
|
|
|
|
|
|
|
|
|
}).done(function (result) {
|
|
|
|
|
|
|
|
|
|
var html = '';
|
|
|
|
|
var items = result.Items;
|
|
|
|
|
|
|
|
|
|
for (var i = 0, length = items.length; i < length; i++) {
|
|
|
|
|
items[i].url = 'itemlist.html?parentid=' + items[i].Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (items.length) {
|
|
|
|
|
|
|
|
|
|
html += '<h1 class="listHeader">' + Globalize.translate('HeaderLibraryFolders') + '</h1>';
|
|
|
|
|
|
|
|
|
|
html += '<div>';
|
|
|
|
|
html += LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: items,
|
|
|
|
|
shape: shape,
|
|
|
|
|
showTitle: true,
|
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true
|
|
|
|
|
});
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(elem).html(html).trigger('create').createPosterItemMenus();
|
|
|
|
|
|
|
|
|
|
handleLibraryLinkNavigations(elem);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
function loadResume(elem, userId) {
|
2014-05-01 22:54:33 -04:00
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
var screenWidth = $(window).width();
|
|
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
|
|
|
|
|
|
SortBy: "DatePlayed",
|
2014-05-01 22:54:33 -04:00
|
|
|
|
SortOrder: "Descending",
|
2014-05-21 15:33:46 -04:00
|
|
|
|
MediaTypes: "Video",
|
|
|
|
|
Filters: "IsResumable",
|
|
|
|
|
Limit: screenWidth >= 1920 ? 10 : (screenWidth >= 1440 ? 8 : 6),
|
2014-05-01 22:54:33 -04:00
|
|
|
|
Recursive: true,
|
|
|
|
|
Fields: "PrimaryImageAspectRatio",
|
|
|
|
|
CollapseBoxSetItems: false,
|
2014-05-21 15:33:46 -04:00
|
|
|
|
ExcludeLocationTypes: "Virtual"
|
2013-08-06 15:21:42 -04:00
|
|
|
|
};
|
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
ApiClient.getItems(userId, options).done(function (result) {
|
2013-04-04 13:27:36 -04:00
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
var html = '';
|
2014-05-03 19:38:23 -04:00
|
|
|
|
|
2014-05-21 23:35:18 -04:00
|
|
|
|
if (result.Items.length) {
|
2014-06-07 15:46:24 -04:00
|
|
|
|
html += '<h1 class="listHeader">' + Globalize.translate('HeaderResume') + '</h1>';
|
2014-05-21 23:35:18 -04:00
|
|
|
|
html += '<div>';
|
|
|
|
|
html += LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
preferBackdrop: true,
|
|
|
|
|
shape: 'backdrop',
|
|
|
|
|
overlayText: screenWidth >= 600,
|
|
|
|
|
showTitle: true,
|
2014-05-29 15:34:20 -04:00
|
|
|
|
showParentTitle: true,
|
2014-05-30 00:16:31 -04:00
|
|
|
|
context: 'home',
|
|
|
|
|
lazy: true
|
2014-05-21 23:35:18 -04:00
|
|
|
|
});
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
2013-04-04 13:27:36 -04:00
|
|
|
|
|
2014-05-30 00:16:31 -04:00
|
|
|
|
$(elem).html(html).trigger('create').createPosterItemMenus();
|
2013-04-04 13:27:36 -04:00
|
|
|
|
});
|
2014-05-21 15:33:46 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadSection(page, userId, displayPreferences, index) {
|
|
|
|
|
|
|
|
|
|
var section = displayPreferences.CustomPrefs['home' + index] || getDefaultSection(index);
|
|
|
|
|
|
|
|
|
|
var elem = $('.section' + index, page);
|
2014-06-20 00:50:30 -04:00
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
if (section == 'latestmedia') {
|
|
|
|
|
loadRecentlyAdded(elem, userId);
|
|
|
|
|
}
|
|
|
|
|
else if (section == 'librarytiles') {
|
2014-06-14 19:13:09 -04:00
|
|
|
|
loadLibraryTiles(elem, userId, 'backdrop', index);
|
2014-06-07 15:46:24 -04:00
|
|
|
|
}
|
2014-06-20 00:50:30 -04:00
|
|
|
|
else if (section == 'smalllibrarytiles' || section == 'librarybuttons') {
|
2014-06-16 08:22:38 -04:00
|
|
|
|
loadLibraryTiles(elem, userId, 'miniBackdrop', index);
|
2014-05-21 15:33:46 -04:00
|
|
|
|
}
|
|
|
|
|
else if (section == 'resume') {
|
|
|
|
|
loadResume(elem, userId);
|
|
|
|
|
}
|
2014-05-23 21:16:53 -04:00
|
|
|
|
|
2014-06-20 00:50:30 -04:00
|
|
|
|
else if (section == 'folders') {
|
2014-06-14 19:13:09 -04:00
|
|
|
|
loadLibraryFolders(elem, userId, 'backdrop', index);
|
|
|
|
|
|
2014-06-15 19:30:04 -04:00
|
|
|
|
} else if (section == 'latestchannelmedia') {
|
|
|
|
|
loadLatestChannelMedia(elem, userId);
|
|
|
|
|
|
2014-05-21 23:35:18 -04:00
|
|
|
|
} else {
|
2014-05-23 21:16:53 -04:00
|
|
|
|
|
2014-05-21 23:35:18 -04:00
|
|
|
|
elem.empty();
|
2014-05-21 15:33:46 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadSections(page, userId, displayPreferences) {
|
|
|
|
|
|
|
|
|
|
var i, length;
|
2014-06-15 19:30:04 -04:00
|
|
|
|
var sectionCount = 4;
|
2014-05-21 15:33:46 -04:00
|
|
|
|
|
2014-05-21 23:35:18 -04:00
|
|
|
|
var elem = $('.sections', page);
|
2014-05-23 21:16:53 -04:00
|
|
|
|
|
2014-05-21 23:35:18 -04:00
|
|
|
|
if (!elem.html().length) {
|
|
|
|
|
var html = '';
|
|
|
|
|
for (i = 0, length = sectionCount; i < length; i++) {
|
2014-05-21 15:33:46 -04:00
|
|
|
|
|
2014-05-21 23:35:18 -04:00
|
|
|
|
html += '<div class="homePageSection section' + i + '"></div>';
|
|
|
|
|
}
|
2014-05-21 15:33:46 -04:00
|
|
|
|
|
2014-05-21 23:35:18 -04:00
|
|
|
|
elem.html(html);
|
|
|
|
|
}
|
2014-05-21 15:33:46 -04:00
|
|
|
|
|
|
|
|
|
for (i = 0, length = sectionCount; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
loadSection(page, userId, displayPreferences, i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-23 21:16:53 -04:00
|
|
|
|
function handleLibraryLinkNavigations(elem) {
|
|
|
|
|
|
|
|
|
|
$('a', elem).on('click', function () {
|
|
|
|
|
|
|
|
|
|
var text = $('.posterItemText', this).html();
|
|
|
|
|
|
|
|
|
|
LibraryMenu.setText(text);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-04 22:32:40 -04:00
|
|
|
|
var homePageDismissValue = '2';
|
2014-06-07 15:46:24 -04:00
|
|
|
|
|
2014-05-30 17:06:57 -04:00
|
|
|
|
function dismissWelcome(page, userId) {
|
|
|
|
|
|
|
|
|
|
ApiClient.getDisplayPreferences('home', userId, 'webclient').done(function (result) {
|
|
|
|
|
|
2014-06-04 22:32:40 -04:00
|
|
|
|
result.CustomPrefs.homePageWelcomeDismissed = homePageDismissValue;
|
2014-06-07 15:46:24 -04:00
|
|
|
|
ApiClient.updateDisplayPreferences('home', result, userId, 'webclient').done(function () {
|
|
|
|
|
|
2014-05-30 17:06:57 -04:00
|
|
|
|
$('.welcomeMessage', page).hide();
|
2014-06-07 15:46:24 -04:00
|
|
|
|
|
2014-05-30 17:06:57 -04:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(document).on('pageinit', "#indexPage", function () {
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
var userId = Dashboard.getCurrentUserId();
|
|
|
|
|
|
|
|
|
|
$('.btnDismissWelcome', page).on('click', function () {
|
|
|
|
|
dismissWelcome(page, userId);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}).on('pagebeforeshow', "#indexPage", function () {
|
2014-05-21 15:33:46 -04:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
var userId = Dashboard.getCurrentUserId();
|
|
|
|
|
|
|
|
|
|
ApiClient.getDisplayPreferences('home', userId, 'webclient').done(function (result) {
|
|
|
|
|
|
2014-06-04 22:32:40 -04:00
|
|
|
|
if (result.CustomPrefs.homePageWelcomeDismissed == homePageDismissValue) {
|
2014-05-30 17:06:57 -04:00
|
|
|
|
$('.welcomeMessage', page).hide();
|
|
|
|
|
} else {
|
|
|
|
|
$('.welcomeMessage', page).show();
|
|
|
|
|
}
|
2014-06-07 15:46:24 -04:00
|
|
|
|
|
2014-05-21 15:33:46 -04:00
|
|
|
|
loadSections(page, userId, result);
|
|
|
|
|
});
|
|
|
|
|
|
2013-07-23 08:29:28 -04:00
|
|
|
|
});
|
|
|
|
|
|
2013-04-01 20:54:06 -04:00
|
|
|
|
})(jQuery, document, ApiClient);
|