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

456 lines
14 KiB
JavaScript
Raw Normal View History

(function ($, document, apiClient) {
2013-02-20 18:33:05 -07:00
2014-06-07 12:46:24 -07: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 12:33:46 -07:00
function loadRecentlyAdded(elem, userId) {
2014-05-20 17:56:24 -07:00
var screenWidth = $(window).width();
var options = {
2014-05-13 17:46:45 -07:00
2014-05-21 12:33:46 -07:00
SortBy: "DateCreated",
2014-05-01 19:54:33 -07:00
SortOrder: "Descending",
2014-06-23 09:05:19 -07:00
Limit: screenWidth >= 2400 ? 30 : (screenWidth >= 1920 ? 15 : (screenWidth >= 1440 ? 10 : (screenWidth >= 800 ? 9 : 8))),
2014-05-01 19:54:33 -07:00
Recursive: true,
Fields: "PrimaryImageAspectRatio",
2014-05-21 12:33:46 -07:00
Filters: "IsUnplayed,IsNotFolder",
2014-05-01 19:54:33 -07:00
CollapseBoxSetItems: false,
2014-05-21 12:33:46 -07:00
ExcludeLocationTypes: "Virtual,Remote"
2014-05-01 19:54:33 -07:00
};
2014-05-21 12:33:46 -07:00
ApiClient.getItems(userId, options).done(function (result) {
2014-05-21 12:33:46 -07:00
var html = '';
2013-11-20 14:08:12 -07:00
2014-05-21 20:35:18 -07:00
if (result.Items.length) {
2014-05-30 14:06:57 -07:00
html += '<h1 class="listHeader">' + Globalize.translate('HeaderLatestMedia') + '</h1>';
2014-05-21 20:35:18 -07:00
html += '<div>';
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
preferThumb: true,
shape: 'backdrop',
showTitle: true,
2014-05-29 12:34:20 -07:00
centerText: true,
2014-05-29 21:16:31 -07:00
context: 'home',
lazy: true
2014-05-21 20:35:18 -07:00
});
html += '</div>';
}
2014-05-21 12:33:46 -07:00
2014-05-29 21:16:31 -07:00
$(elem).html(html).trigger('create').createPosterItemMenus();
2014-05-21 12:33:46 -07:00
});
}
function loadLatestChannelMedia(elem, userId) {
var screenWidth = $(window).width();
var options = {
2014-06-17 09:03:14 -07:00
Limit: screenWidth >= 2400 ? 10 : (screenWidth >= 1920 ? 10 : (screenWidth >= 1440 ? 8 : (screenWidth >= 800 ? 7 : 6))),
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 16:13:09 -07:00
function loadLibraryTiles(elem, userId, shape, index) {
2014-05-21 12:33:46 -07:00
2014-06-07 12:46:24 -07:00
getUserViews(userId).done(function (items) {
2014-05-21 12:33:46 -07:00
var html = '';
2014-06-07 12:46:24 -07:00
if (items.length) {
2014-06-14 16:13:09 -07:00
2014-06-23 09:05:19 -07:00
var cssClass = index !== 0 ? 'listHeader' : 'listHeader firstListHeader';
2014-06-19 21:50:30 -07:00
2014-06-23 09:05:19 -07:00
html += '<div>';
html += '<h1 style="display:inline-block; vertical-align:middle;" class="' + cssClass + '">' + Globalize.translate('HeaderMyViews') + '</h1>';
html += '<a href="mypreferencesdisplay.html" data-role="button" data-icon="edit" data-mini="true" data-inline="true" data-iconpos="notext" class="sectionHeaderButton">d</a>';
html += '</div>';
2014-06-14 16:13:09 -07:00
2014-05-21 20:35:18 -07:00
html += '<div>';
html += LibraryBrowser.getPosterViewHtml({
2014-06-07 12:46:24 -07:00
items: items,
shape: shape,
2014-05-21 20:35:18 -07:00
showTitle: true,
2014-05-29 21:16:31 -07:00
centerText: true,
lazy: true
2014-05-21 20:35:18 -07:00
});
html += '</div>';
}
2013-08-06 12:21:42 -07:00
2014-05-29 21:16:31 -07:00
$(elem).html(html).trigger('create').createPosterItemMenus();
handleLibraryLinkNavigations(elem);
});
2014-05-21 12:33:46 -07:00
}
2013-04-04 10:27:36 -07:00
2014-06-14 16:13:09 -07: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 12:33:46 -07:00
function loadResume(elem, userId) {
2014-05-01 19:54:33 -07:00
2014-05-21 12:33:46 -07:00
var screenWidth = $(window).width();
var options = {
SortBy: "DatePlayed",
2014-05-01 19:54:33 -07:00
SortOrder: "Descending",
2014-05-21 12:33:46 -07:00
MediaTypes: "Video",
Filters: "IsResumable",
Limit: screenWidth >= 1920 ? 10 : (screenWidth >= 1440 ? 8 : 6),
2014-05-01 19:54:33 -07:00
Recursive: true,
Fields: "PrimaryImageAspectRatio",
CollapseBoxSetItems: false,
2014-05-21 12:33:46 -07:00
ExcludeLocationTypes: "Virtual"
2013-08-06 12:21:42 -07:00
};
2014-05-21 12:33:46 -07:00
ApiClient.getItems(userId, options).done(function (result) {
2013-04-04 10:27:36 -07:00
2014-05-21 12:33:46 -07:00
var html = '';
2014-05-03 16:38:23 -07:00
2014-05-21 20:35:18 -07:00
if (result.Items.length) {
2014-06-07 12:46:24 -07:00
html += '<h1 class="listHeader">' + Globalize.translate('HeaderResume') + '</h1>';
2014-05-21 20:35:18 -07:00
html += '<div>';
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
preferBackdrop: true,
shape: 'backdrop',
overlayText: screenWidth >= 600,
showTitle: true,
2014-05-29 12:34:20 -07:00
showParentTitle: true,
2014-05-29 21:16:31 -07:00
context: 'home',
lazy: true
2014-05-21 20:35:18 -07:00
});
html += '</div>';
}
2013-04-04 10:27:36 -07:00
2014-05-29 21:16:31 -07:00
$(elem).html(html).trigger('create').createPosterItemMenus();
2013-04-04 10:27:36 -07:00
});
2014-05-21 12:33:46 -07:00
}
2014-06-23 09:05:19 -07:00
function handleLibraryLinkNavigations(elem) {
$('a.posterItem', elem).on('click', function () {
var text = $('.posterItemText', this).html();
LibraryMenu.setText(text);
});
}
function loadLatestChannelItems(elem, userId, options) {
options = $.extend(options || {}, {
UserId: userId,
SupportsLatestItems: true
});
$.getJSON(ApiClient.getUrl("Channels", options)).done(function (result) {
var channels = result.Items;
var channelsHtml = channels.map(function (c) {
return '<div id="channel' + c.Id + '"></div>';
}).join('');
$(elem).html(channelsHtml);
for (var i = 0, length = channels.length; i < length; i++) {
var channel = channels[i];
loadLatestChannelItemsFromChannel(elem, channel, i);
}
});
}
function loadLatestChannelItemsFromChannel(page, channel, index) {
var screenWidth = $(window).width();
var options = {
Limit: screenWidth >= 1920 ? 9 : (screenWidth >= 1440 ? 8 : (screenWidth >= 800 ? 6 : 6)),
Fields: "PrimaryImageAspectRatio",
Filters: "IsUnplayed",
UserId: Dashboard.getCurrentUserId(),
ChannelIds: channel.Id
};
$.getJSON(ApiClient.getUrl("Channels/Items/Latest", options)).done(function (result) {
var html = '';
if (result.Items.length) {
var cssClass = index !== 0 ? 'listHeader' : 'listHeader firstListHeader';
html += '<div>';
var text = Globalize.translate('HeaderLatestFromChannel').replace('{0}', channel.Name);
html += '<h1 style="display:inline-block; vertical-align:middle;" class="' + cssClass + '">' + text + '</h1>';
html += '<a href="channelitems.html?context=channels&id=' + channel.Id + '" data-role="button" data-icon="arrow-r" data-mini="true" data-inline="true" data-iconpos="notext" class="sectionHeaderButton">d</a>';
html += '</div>';
}
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: 'auto',
defaultShape: 'square',
showTitle: true,
centerText: true,
context: 'channels',
lazy: true
});
$('#channel' + channel.Id + '', page).html(html).trigger('create').createPosterItemMenus();
});
}
function loadLatestLiveTvRecordings(elem, userId, index) {
ApiClient.getLiveTvRecordings({
userId: userId,
limit: 9,
IsInProgress: false
}).done(function (result) {
var html = '';
if (result.Items.length) {
var cssClass = index !== 0 ? 'listHeader' : 'listHeader firstListHeader';
html += '<div>';
html += '<h1 style="display:inline-block; vertical-align:middle;" class="' + cssClass + '">' + Globalize.translate('HeaderLatestTvRecordings') + '</h1>';
html += '<a href="livetvrecordings.html?context=livetv" data-role="button" data-icon="arrow-r" data-mini="true" data-inline="true" data-iconpos="notext" class="sectionHeaderButton">d</a>';
html += '</div>';
}
var screenWidth = $(window).width();
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "auto",
showTitle: true,
showParentTitle: true,
overlayText: screenWidth >= 600,
coverImage: true,
lazy: true
});
elem.html(html).trigger('create').createPosterItemMenus();
});
}
window.Sections = {
loadRecentlyAdded: loadRecentlyAdded,
loadLatestChannelMedia: loadLatestChannelMedia,
loadLibraryTiles: loadLibraryTiles,
loadLibraryFolders: loadLibraryFolders,
loadResume: loadResume,
loadLatestChannelItems: loadLatestChannelItems,
loadLatestLiveTvRecordings: loadLatestLiveTvRecordings
};
})(jQuery, document, ApiClient);
(function ($, document, apiClient) {
function getDefaultSection(index) {
switch (index) {
case 0:
return 'smalllibrarytiles';
case 1:
return 'resume';
case 2:
return '';
case 3:
return '';
default:
return '';
}
}
2014-05-21 12:33:46 -07:00
function loadSection(page, userId, displayPreferences, index) {
var section = displayPreferences.CustomPrefs['home' + index] || getDefaultSection(index);
var elem = $('.section' + index, page);
2014-06-19 21:50:30 -07:00
2014-05-21 12:33:46 -07:00
if (section == 'latestmedia') {
2014-06-23 09:05:19 -07:00
Sections.loadRecentlyAdded(elem, userId);
2014-05-21 12:33:46 -07:00
}
else if (section == 'librarytiles') {
2014-06-23 09:05:19 -07:00
Sections.loadLibraryTiles(elem, userId, 'backdrop', index);
2014-06-07 12:46:24 -07:00
}
2014-06-19 21:50:30 -07:00
else if (section == 'smalllibrarytiles' || section == 'librarybuttons') {
2014-06-23 09:05:19 -07:00
Sections.loadLibraryTiles(elem, userId, 'smallBackdrop', index);
2014-05-21 12:33:46 -07:00
}
else if (section == 'resume') {
2014-06-23 09:05:19 -07:00
Sections.loadResume(elem, userId);
}
else if (section == 'latesttvrecordings') {
Sections.loadLatestLiveTvRecordings(elem, userId);
2014-05-21 12:33:46 -07:00
}
2014-06-19 21:50:30 -07:00
else if (section == 'folders') {
2014-06-23 09:05:19 -07:00
Sections.loadLibraryFolders(elem, userId, 'smallBackdrop', index);
2014-06-14 16:13:09 -07:00
} else if (section == 'latestchannelmedia') {
2014-06-23 09:05:19 -07:00
Sections.loadLatestChannelMedia(elem, userId);
2014-05-21 20:35:18 -07:00
} else {
2014-05-21 20:35:18 -07:00
elem.empty();
2014-05-21 12:33:46 -07:00
}
}
function loadSections(page, userId, displayPreferences) {
var i, length;
var sectionCount = 4;
2014-05-21 12:33:46 -07:00
2014-05-21 20:35:18 -07:00
var elem = $('.sections', page);
2014-05-21 20:35:18 -07:00
if (!elem.html().length) {
var html = '';
for (i = 0, length = sectionCount; i < length; i++) {
2014-05-21 12:33:46 -07:00
2014-05-21 20:35:18 -07:00
html += '<div class="homePageSection section' + i + '"></div>';
}
2014-05-21 12:33:46 -07:00
2014-05-21 20:35:18 -07:00
elem.html(html);
}
2014-05-21 12:33:46 -07:00
for (i = 0, length = sectionCount; i < length; i++) {
loadSection(page, userId, displayPreferences, i);
}
}
2014-06-04 19:32:40 -07:00
var homePageDismissValue = '2';
2014-06-07 12:46:24 -07:00
2014-05-30 14:06:57 -07:00
function dismissWelcome(page, userId) {
ApiClient.getDisplayPreferences('home', userId, 'webclient').done(function (result) {
2014-06-04 19:32:40 -07:00
result.CustomPrefs.homePageWelcomeDismissed = homePageDismissValue;
2014-06-07 12:46:24 -07:00
ApiClient.updateDisplayPreferences('home', result, userId, 'webclient').done(function () {
2014-05-30 14:06:57 -07:00
$('.welcomeMessage', page).hide();
2014-06-07 12:46:24 -07:00
2014-05-30 14:06:57 -07: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 12:33:46 -07:00
var page = this;
var userId = Dashboard.getCurrentUserId();
ApiClient.getDisplayPreferences('home', userId, 'webclient').done(function (result) {
2014-06-04 19:32:40 -07:00
if (result.CustomPrefs.homePageWelcomeDismissed == homePageDismissValue) {
2014-05-30 14:06:57 -07:00
$('.welcomeMessage', page).hide();
} else {
$('.welcomeMessage', page).show();
}
2014-06-07 12:46:24 -07:00
2014-05-21 12:33:46 -07:00
loadSections(page, userId, result);
});
2013-07-23 05:29:28 -07:00
});
})(jQuery, document, ApiClient);