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

507 lines
16 KiB
JavaScript
Raw Normal View History

2015-06-12 21:14:48 -07:00
(function ($, document) {
function getUserViews(userId) {
var deferred = $.Deferred();
2015-07-30 07:34:46 -07:00
ApiClient.getUserViews({}, userId).done(function (result) {
2015-06-12 21:14:48 -07:00
var items = result.Items;
2015-08-28 08:02:22 -07:00
var list = [];
for (var i = 0, length = items.length; i < length; i++) {
var view = items[i];
list.push(view);
if (view.CollectionType == 'livetv') {
view.ImageTags = {};
view.icon = 'live-tv';
2015-08-28 10:39:52 -07:00
view.onclick = "LibraryBrowser.showTab('livetv.html', 0);return false;";
2015-08-28 08:02:22 -07:00
var guideView = $.extend({}, view);
guideView.Name = Globalize.translate('ButtonGuide');
guideView.ImageTags = {};
guideView.icon = 'dvr';
guideView.url = 'livetv.html?tab=1';
guideView.onclick = "LibraryBrowser.showTab('livetv.html', 1);return false;";
list.push(guideView);
var recordedTvView = $.extend({}, view);
recordedTvView.Name = Globalize.translate('ButtonRecordedTv');
recordedTvView.ImageTags = {};
recordedTvView.icon = 'video-library';
recordedTvView.url = 'livetv.html?tab=3';
recordedTvView.onclick = "LibraryBrowser.showTab('livetv.html', 3);return false;";
list.push(recordedTvView);
}
}
deferred.resolveWith(null, [list]);
2015-06-12 21:14:48 -07:00
});
return deferred.promise();
}
function enableScrollX() {
return $.browser.mobile && AppInfo.enableAppLayouts;
}
function getThumbShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
function getLibraryButtonsHtml(items) {
var html = "";
// "My Library" backgrounds
for (var i = 0, length = items.length; i < length; i++) {
var item = items[i];
var icon;
var backgroundColor = 'rgba(82, 181, 75, 0.9)';
switch (item.CollectionType) {
case "movies":
2015-08-28 08:02:22 -07:00
icon = "local-movies";
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(176, 94, 81, 0.9)';
break;
case "music":
2015-08-28 08:02:22 -07:00
icon = "library-music";
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(217, 145, 67, 0.9)';
break;
case "photos":
2015-08-28 08:02:22 -07:00
icon = "photo";
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(127, 0, 0, 0.9)';
break;
case "livetv":
2015-08-28 08:02:22 -07:00
icon = "live-tv";
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(217, 145, 67, 0.9)';
break;
case "tvshows":
2015-08-28 08:02:22 -07:00
icon = "live-tv";
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(77, 88, 164, 0.9)';
break;
case "games":
2015-08-28 08:02:22 -07:00
icon = "folder";
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(183, 202, 72, 0.9)';
break;
case "trailers":
2015-08-28 08:02:22 -07:00
icon = "local-movies";
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(176, 94, 81, 0.9)';
break;
case "homevideos":
2015-08-28 08:02:22 -07:00
icon = "video-library";
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(110, 52, 32, 0.9)';
break;
case "musicvideos":
2015-08-28 08:02:22 -07:00
icon = "video-library";
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(143, 54, 168, 0.9)';
break;
case "books":
2015-08-28 08:02:22 -07:00
icon = "folder";
2015-06-12 21:14:48 -07:00
break;
case "channels":
2015-08-28 08:02:22 -07:00
icon = "folder";
2015-06-12 21:14:48 -07:00
backgroundColor = 'rgba(51, 136, 204, 0.9)';
break;
case "playlists":
2015-08-28 08:02:22 -07:00
icon = "folder";
2015-06-12 21:14:48 -07:00
break;
default:
2015-08-28 08:02:22 -07:00
icon = "folder";
2015-06-12 21:14:48 -07:00
break;
}
var cssClass = 'card smallBackdropCard buttonCard';
if (item.CollectionType) {
cssClass += ' ' + item.CollectionType + 'buttonCard';
}
var href = item.url || LibraryBrowser.getHref(item);
2015-08-28 08:02:22 -07:00
var onclick = item.onclick ? ' onclick="' + item.onclick + '"' : '';
icon = item.icon || icon;
2015-06-12 21:14:48 -07:00
2015-08-28 08:02:22 -07:00
html += '<a' + onclick + ' data-itemid="' + item.Id + '" class="' + cssClass + '" href="' + href + '">';
2015-06-12 21:14:48 -07:00
html += '<div class="cardBox" style="background-color:' + backgroundColor + ';margin:4px;border-radius:4px;">';
html += "<div class='cardText' style='padding:8px 10px;color:#fff;font-size:14px;'>";
2015-08-28 08:02:22 -07:00
html += '<iron-icon icon="' + icon + '"></iron-icon>';
2015-06-12 21:14:48 -07:00
html += '<span style="margin-left:.7em;">' + item.Name + '</span>';
html += "</div>";
html += "</div>";
html += "</a>";
}
return html;
}
function loadlibraryButtons(elem, userId, index) {
return getUserViews(userId).done(function (items) {
var html = '<br/>';
if (index) {
html += '<h1 class="listHeader">' + Globalize.translate('HeaderMyMedia') + '</h1>';
}
html += '<div>';
html += getLibraryButtonsHtml(items);
html += '</div>';
2015-06-28 07:45:21 -07:00
elem.innerHTML = html;
2015-06-12 21:14:48 -07:00
handleLibraryLinkNavigations(elem);
});
}
2015-07-26 22:03:34 -07:00
function loadRecentlyAdded(elem, user) {
2015-06-12 21:14:48 -07:00
var limit = AppInfo.hasLowImageBandwidth ?
16 :
2015-06-25 18:10:56 -07:00
20;
2015-06-12 21:14:48 -07:00
var options = {
Limit: limit,
Fields: "PrimaryImageAspectRatio,SyncInfo",
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
};
return ApiClient.getJSON(ApiClient.getUrl('Users/' + user.Id + '/Items/Latest', options)).done(function (items) {
var html = '';
var cardLayout = false;
if (items.length) {
html += '<div>';
2015-07-08 09:10:34 -07:00
html += '<h1 class="listHeader">' + Globalize.translate('HeaderLatestMedia') + '</h1>';
2015-06-12 21:14:48 -07:00
html += '</div>';
html += '<div class="itemsContainer">';
html += LibraryBrowser.getPosterViewHtml({
items: items,
preferThumb: true,
shape: 'backdrop',
showUnplayedIndicator: false,
showChildCountIndicator: true,
lazy: true,
cardLayout: cardLayout,
showTitle: cardLayout,
showYear: cardLayout,
2015-07-27 09:21:18 -07:00
showDetailsMenu: true,
context: 'home'
2015-06-12 21:14:48 -07:00
});
html += '</div>';
}
2015-06-28 07:45:21 -07:00
elem.innerHTML = html;
2015-06-28 08:43:49 -07:00
ImageLoader.lazyChildren(elem);
$(elem).createCardMenus();
2015-06-12 21:14:48 -07:00
});
}
function loadLatestChannelMedia(elem, userId) {
var screenWidth = $(window).width();
var options = {
Limit: screenWidth >= 2400 ? 10 : (screenWidth >= 1600 ? 10 : (screenWidth >= 1440 ? 8 : (screenWidth >= 800 ? 7 : 6))),
Fields: "PrimaryImageAspectRatio,SyncInfo",
Filters: "IsUnplayed",
UserId: userId
};
return ApiClient.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 class="itemsContainer">';
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
preferThumb: true,
shape: 'auto',
showTitle: true,
centerText: true,
lazy: true,
showDetailsMenu: true
});
html += '</div>';
}
2015-06-28 07:45:21 -07:00
elem.innerHTML = html;
2015-06-28 08:43:49 -07:00
ImageLoader.lazyChildren(elem);
$(elem).createCardMenus();
2015-06-12 21:14:48 -07:00
});
}
function loadLibraryTiles(elem, user, shape, index, autoHideOnMobile, showTitles) {
return getUserViews(user.Id).done(function (items) {
var html = '';
if (autoHideOnMobile) {
html += '<div class="hiddenSectionOnMobile">';
} else {
html += '<div>';
}
if (items.length) {
2015-06-15 21:52:01 -07:00
var cssClass = index !== 0 ? 'listHeader' : 'listHeader';
2015-06-12 21:14:48 -07:00
html += '<div>';
2015-07-08 09:10:34 -07:00
html += '<h1 class="' + cssClass + '">' + Globalize.translate('HeaderMyMedia') + '</h1>';
2015-06-12 21:14:48 -07:00
html += '</div>';
html += '<div class="homeTopViews">';
html += LibraryBrowser.getPosterViewHtml({
items: items,
shape: shape,
showTitle: showTitles,
centerText: true,
lazy: true,
2015-06-17 18:41:22 -07:00
autoThumb: true,
transition: false
2015-06-12 21:14:48 -07:00
});
html += '</div>';
}
html += '</div>';
if (autoHideOnMobile) {
html += '<div class="hiddenSectionOnNonMobile" style="margin-top:1em;">';
html += getLibraryButtonsHtml(items);
html += '</div>';
}
2015-06-28 07:45:21 -07:00
elem.innerHTML = html;
2015-06-28 08:43:49 -07:00
ImageLoader.lazyChildren(elem);
$(elem).createCardMenus({ showDetailsMenu: false });
2015-06-12 21:14:48 -07:00
handleLibraryLinkNavigations(elem);
});
}
function loadResume(elem, userId) {
var screenWidth = $(window).width();
var options = {
SortBy: "DatePlayed",
SortOrder: "Descending",
MediaTypes: "Video",
Filters: "IsResumable",
Limit: screenWidth >= 1920 ? 10 : (screenWidth >= 1600 ? 8 : (screenWidth >= 1200 ? 9 : 6)),
Recursive: true,
Fields: "PrimaryImageAspectRatio,SyncInfo",
CollapseBoxSetItems: false,
ExcludeLocationTypes: "Virtual",
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
};
return ApiClient.getItems(userId, options).done(function (result) {
var html = '';
var cardLayout = AppInfo.hasLowImageBandwidth;
if (result.Items.length) {
html += '<h1 class="listHeader">' + Globalize.translate('HeaderResume') + '</h1>';
if (enableScrollX()) {
2015-07-13 14:26:11 -07:00
html += '<div class="hiddenScrollX itemsContainer">';
2015-06-12 21:14:48 -07:00
} else {
html += '<div class="itemsContainer">';
}
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
preferThumb: true,
shape: getThumbShape(),
overlayText: screenWidth >= 800 && !cardLayout,
showTitle: true,
showParentTitle: true,
lazy: true,
cardLayout: cardLayout,
2015-07-17 15:32:00 -07:00
showDetailsMenu: true,
2015-07-27 09:21:18 -07:00
overlayPlayButton: true,
context: 'home'
2015-06-12 21:14:48 -07:00
});
html += '</div>';
}
2015-06-28 07:45:21 -07:00
elem.innerHTML = html;
2015-06-28 08:43:49 -07:00
ImageLoader.lazyChildren(elem);
$(elem).createCardMenus();
2015-06-12 21:14:48 -07:00
});
}
function handleLibraryLinkNavigations(elem) {
2015-06-18 21:23:55 -07:00
$('a', elem).on('click', function () {
2015-06-12 21:14:48 -07:00
2015-07-10 11:30:42 -07:00
var card = this;
if (!this.classList.contains('card')) {
card = $(this).parents('.card')[0];
}
2015-06-12 21:14:48 -07:00
2015-07-10 11:30:42 -07:00
var textElem = $('.cardText', card);
var text = textElem.text();
2015-06-12 21:14:48 -07:00
2015-07-09 20:00:03 -07:00
LibraryMenu.setTitle(text);
2015-06-12 21:14:48 -07:00
});
}
function loadLatestChannelItems(elem, userId, options) {
options = $.extend(options || {}, {
UserId: userId,
SupportsLatestItems: true
});
return ApiClient.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('');
2015-06-28 07:45:21 -07:00
elem.innerHTML = channelsHtml;
2015-06-12 21:14:48 -07:00
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 >= 1600 ? 10 : (screenWidth >= 1440 ? 5 : (screenWidth >= 800 ? 6 : 6)),
Fields: "PrimaryImageAspectRatio,SyncInfo",
Filters: "IsUnplayed",
UserId: Dashboard.getCurrentUserId(),
ChannelIds: channel.Id
};
ApiClient.getJSON(ApiClient.getUrl("Channels/Items/Latest", options)).done(function (result) {
var html = '';
if (result.Items.length) {
2015-07-20 11:32:55 -07:00
html += '<div class="homePageSection">';
2015-06-12 21:14:48 -07:00
html += '<div>';
var text = Globalize.translate('HeaderLatestFromChannel').replace('{0}', channel.Name);
2015-07-20 11:32:55 -07:00
html += '<h1 style="display:inline-block; vertical-align:middle;" class="listHeader">' + text + '</h1>';
2015-07-26 22:03:34 -07:00
html += '<a href="channelitems.html?id=' + channel.Id + '" class="clearLink" style="margin-left:2em;"><paper-button raised class="more mini"><span>' + Globalize.translate('ButtonMore') + '</span></paper-button></a>';
2015-06-12 21:14:48 -07:00
html += '</div>';
2015-07-20 11:32:55 -07:00
html += '<div class="itemsContainer">';
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: 'autohome',
defaultShape: 'square',
showTitle: true,
centerText: true,
lazy: true,
2015-07-24 08:20:11 -07:00
showDetailsMenu: true,
overlayPlayButton: true
2015-07-20 11:32:55 -07:00
});
html += '</div>';
html += '</div>';
2015-06-12 21:14:48 -07:00
}
2015-06-28 07:45:21 -07:00
var elem = page.querySelector('#channel' + channel.Id + '');
elem.innerHTML = html;
2015-06-28 08:43:49 -07:00
ImageLoader.lazyChildren(elem);
$(elem).createCardMenus();
2015-06-12 21:14:48 -07:00
});
}
function loadLatestLiveTvRecordings(elem, userId, index) {
return ApiClient.getLiveTvRecordings({
userId: userId,
limit: 5,
IsInProgress: false
}).done(function (result) {
var html = '';
if (result.Items.length) {
2015-06-15 21:52:01 -07:00
var cssClass = index !== 0 ? 'listHeader' : 'listHeader';
2015-06-12 21:14:48 -07:00
html += '<div>';
html += '<h1 style="display:inline-block; vertical-align:middle;" class="' + cssClass + '">' + Globalize.translate('HeaderLatestTvRecordings') + '</h1>';
2015-08-28 18:53:53 -07:00
html += '<a href="livetv.html?tab=3" onclick="LibraryManager.showTab(\'livetv.html\',3);" class="clearLink" style="margin-left:2em;"><paper-button raised class="more mini"><span>' + Globalize.translate('ButtonMore') + '</span></paper-button></a>';
2015-06-12 21:14:48 -07:00
html += '</div>';
}
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "autohome",
showTitle: true,
showParentTitle: true,
coverImage: true,
lazy: true,
2015-08-22 08:54:29 -07:00
showDetailsMenu: true,
centerText: true
2015-06-12 21:14:48 -07:00
});
2015-06-28 07:45:21 -07:00
elem.innerHTML = html;
2015-06-28 08:43:49 -07:00
ImageLoader.lazyChildren(elem);
2015-06-12 21:14:48 -07:00
});
}
window.Sections = {
loadRecentlyAdded: loadRecentlyAdded,
loadLatestChannelMedia: loadLatestChannelMedia,
loadLibraryTiles: loadLibraryTiles,
loadResume: loadResume,
loadLatestChannelItems: loadLatestChannelItems,
loadLatestLiveTvRecordings: loadLatestLiveTvRecordings,
loadlibraryButtons: loadlibraryButtons
};
})(jQuery, document);