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

345 lines
9.4 KiB
JavaScript
Raw Normal View History

(function ($, document, apiClient) {
2013-02-20 18:33:05 -07:00
function createMediaLinks(options) {
var html = "";
var items = options.items;
// "My Library" backgrounds
for (var i = 0, length = items.length; i < length; i++) {
var item = items[i];
2014-05-20 17:56:24 -07:00
var imgUrl;
switch (item.CollectionType) {
case "movies":
imgUrl = "css/images/items/folders/movies.png";
break;
case "music":
imgUrl = "css/images/items/folders/music.png";
break;
case "photos":
imgUrl = "css/images/items/folders/photos.png";
break;
2014-05-20 17:56:24 -07:00
case "livetv":
case "tvshows":
imgUrl = "css/images/items/folders/tv.png";
break;
case "games":
imgUrl = "css/images/items/folders/games.png";
break;
case "trailers":
imgUrl = "css/images/items/folders/games.png";
break;
case "homevideos":
imgUrl = "css/images/items/folders/homevideos.png";
break;
case "musicvideos":
imgUrl = "css/images/items/folders/musicvideos.png";
break;
2014-05-20 17:56:24 -07:00
case "channels":
imgUrl = "css/images/items/folders/channels.png";
break;
case "boxsets":
default:
imgUrl = "css/images/items/folders/folder.png";
break;
}
var cssClass = "posterItem";
cssClass += ' ' + options.shape + 'PosterItem';
2014-05-20 17:56:24 -07:00
if (item.CollectionType) {
cssClass += ' ' + item.CollectionType + 'PosterItem';
}
2014-05-20 17:56:24 -07:00
var href = item.url || LibraryBrowser.getHref(item, options.context);
2014-05-20 17:56:24 -07:00
html += '<a data-itemid="' + item.Id + '" class="' + cssClass + '" href="' + href + '">';
var style = "";
if (imgUrl) {
style += 'background-image:url(\'' + imgUrl + '\');';
}
var imageCssClass = 'posterItemImage';
html += '<div class="' + imageCssClass + '" style="' + style + '">';
html += '</div>';
html += "<div class='posterItemDefaultText posterItemText'>";
html += item.Name;
html += "</div>";
html += "</a>";
}
return html;
}
2014-05-21 12:33:46 -07:00
function getDefaultSection(index) {
switch (index) {
case 0:
return 'librarybuttons';
case 1:
return 'resume';
case 2:
return 'latestmedia';
default:
return '';
}
}
function loadlibraryButtons(elem, userId, index) {
2014-05-07 11:38:50 -07:00
2014-05-01 19:54:33 -07:00
var options = {
2013-04-04 10:27:36 -07:00
2014-05-13 17:46:45 -07:00
SortBy: "SortName",
Fields: "PrimaryImageAspectRatio"
};
2014-05-20 17:56:24 -07:00
var promise1 = ApiClient.getItems(userId, options);
2014-05-21 12:33:46 -07:00
2014-05-20 17:56:24 -07:00
var promise2 = ApiClient.getLiveTvInfo();
var promise3 = $.getJSON(ApiClient.getUrl("Channels", {
userId: userId,
// We just want the total record count
limit: 0
}));
2014-05-21 12:33:46 -07:00
$.when(promise1, promise2, promise3).done(function (r1, r2, r3) {
2014-05-20 17:56:24 -07:00
var result = r1[0];
var liveTvInfo = r2[0];
var channelResponse = r3[0];
if (channelResponse.TotalRecordCount) {
result.Items.push({
Name: 'Channels',
CollectionType: 'channels',
Id: 'channels',
url: 'channels.html'
});
}
var showLiveTv = liveTvInfo.EnabledUsers.indexOf(userId) != -1;
if (showLiveTv) {
2014-05-21 12:33:46 -07:00
2014-05-20 17:56:24 -07:00
result.Items.push({
Name: 'Live TV',
CollectionType: 'livetv',
Id: 'livetv',
url: 'livetvsuggested.html'
});
}
2014-05-13 17:46:45 -07:00
2014-05-21 12:33:46 -07:00
var html = '';
if (index) {
html += '<h1 class="listHeader">My Library</h1>';
}
html += '<div>';
html += createMediaLinks({
2014-05-13 17:46:45 -07:00
items: result.Items,
shape: 'myLibrary',
2014-05-13 17:46:45 -07:00
showTitle: true,
centerText: true
2014-05-21 12:33:46 -07:00
});
html += '</div>';
$(elem).html(html);
handleLibraryLinkNavigations(elem);
2014-05-13 17:46:45 -07:00
});
2014-05-20 17:56:24 -07:00
}
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-05-21 12:33:46 -07:00
Limit: screenWidth >= 2400 ? 30 : (screenWidth >= 1920 ? 20 : (screenWidth >= 1440 ? 12 : (screenWidth >= 800 ? 12 : 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) {
html += '<h1 class="listHeader">Latest Media</h1>';
html += '<div>';
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
preferThumb: true,
shape: 'backdrop',
showTitle: true,
centerText: true
});
html += '</div>';
}
2014-05-21 12:33:46 -07:00
$(elem).html(html).createPosterItemMenus();
});
}
function loadLibraryTiles(elem, userId) {
var options = {
2013-04-04 10:27:36 -07:00
2014-05-21 12:33:46 -07:00
SortBy: "SortName",
Fields: "PrimaryImageAspectRatio"
};
ApiClient.getItems(userId, options).done(function (result) {
var html = '';
2014-05-21 20:35:18 -07:00
if (result.Items.length) {
html += '<h1 class="listHeader">My Library</h1>';
html += '<div>';
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: 'backdrop',
showTitle: true,
centerText: true
});
html += '</div>';
}
2013-08-06 12:21:42 -07:00
2014-05-21 12:33:46 -07:00
$(elem).html(html).createPosterItemMenus();
handleLibraryLinkNavigations(elem);
});
2014-05-21 12:33:46 -07:00
}
2013-04-04 10:27:36 -07:00
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) {
html += '<h1 class="listHeader">Resume</h1>';
html += '<div>';
html += LibraryBrowser.getPosterViewHtml({
items: result.Items,
preferBackdrop: true,
shape: 'backdrop',
overlayText: screenWidth >= 600,
showTitle: true,
showParentTitle: true
});
html += '</div>';
}
2013-04-04 10:27:36 -07:00
2014-05-21 12:33:46 -07:00
$(elem).html(html).createPosterItemMenus();
2013-04-04 10:27:36 -07:00
});
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);
if (section == 'latestmedia') {
loadRecentlyAdded(elem, userId);
}
else if (section == 'librarytiles') {
loadLibraryTiles(elem, userId);
}
else if (section == 'resume') {
loadResume(elem, userId);
}
else if (section == 'librarybuttons') {
loadlibraryButtons(elem, userId, index);
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 = 3;
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);
}
}
function handleLibraryLinkNavigations(elem) {
$('a', elem).on('click', function () {
var text = $('.posterItemText', this).html();
LibraryMenu.setText(text);
});
}
2014-05-21 12:33:46 -07:00
$(document).on('pagebeforeshow', "#indexPage", function () {
var page = this;
var userId = Dashboard.getCurrentUserId();
ApiClient.getDisplayPreferences('home', userId, 'webclient').done(function (result) {
loadSections(page, userId, result);
});
2013-07-23 05:29:28 -07:00
});
})(jQuery, document, ApiClient);