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

249 lines
6.9 KiB
JavaScript
Raw Normal View History

(function ($, document, apiClient) {
2013-02-20 18:33:05 -07:00
2013-07-23 05:29:28 -07:00
function reloadTips(page) {
var tips = [
'Did you know that editing the artist or album of a music video will allow it to appear on the artist and album pages?',
2013-07-23 05:29:28 -07:00
'Did you know that editing the tmdb id, tvdb id, and/or games db id of an album will allow media browser to link it to a movie, series or game as a soundtrack?',
2013-12-27 19:46:32 -07:00
'Did you know that you can re-order your media folders by editing their sort names?',
2013-07-25 12:18:02 -07:00
'Did you know that series, seasons, games and boxsets can have local trailers?',
'Did you know that movies can have special features by placing them in a "specials" sub-folder underneath the movie folder?',
'Did you know that the trailer plugin can automatically download trailers for existing movies in your collection?'
2013-07-23 05:29:28 -07:00
];
2013-07-28 06:58:26 -07:00
var random = Math.floor((Math.random() * tips.length * 1.5));
2013-07-23 05:29:28 -07:00
var tip = tips[random];
2013-08-06 12:21:42 -07:00
2013-07-23 05:29:28 -07:00
if (tip) {
$('#tip', page).html(tip).show();
} else {
$('#tip', page).hide();
}
}
2013-08-06 12:21:42 -07:00
2013-04-04 10:27:36 -07:00
function getViewHtml(view) {
var html = '';
2013-08-06 12:21:42 -07:00
html += '<a id="' + view.id + '" class="posterItem backdropPosterItem" href="' + view.url + '">';
2013-04-25 17:52:55 -07:00
2013-08-06 12:21:42 -07:00
html += '<div class="posterItemImage" style="padding:1px;"></div><div class="posterItemText posterItemTextCentered">' + view.name + '</div>';
2013-04-25 17:52:55 -07:00
2013-04-04 10:27:36 -07:00
html += '</a>';
return html;
}
2013-08-06 12:21:42 -07:00
function appendViewImages(elem, urls) {
2013-02-20 18:33:05 -07:00
2013-08-06 12:21:42 -07:00
var html = '';
2013-02-20 18:33:05 -07:00
2013-08-06 12:21:42 -07:00
for (var i = 0, length = urls.length; i < length; i++) {
var url = urls[i];
2013-08-07 08:59:35 -07:00
html += '<div class="viewCollageImage" style="background-image: url(\'' + url + '\');"></div>';
2013-02-20 18:33:05 -07:00
}
2013-08-06 12:21:42 -07:00
elem.html(html);
}
function renderMovieViewImages(page, userId) {
apiClient.getItems(userId, {
SortBy: "random",
2013-09-27 14:09:04 -07:00
IncludeItemTypes: "Movie,Trailer",
2013-08-06 12:21:42 -07:00
Limit: 6,
ImageTypes: "Primary",
Recursive: true
}).done(function (result) {
var urls = [];
for (var i = 0, length = result.Items.length; i < length; i++) {
urls.push(LibraryBrowser.getImageUrl(result.Items[i], 'Primary', 0, {
width: 160,
EnableImageEnhancers: false
2013-08-06 12:21:42 -07:00
}));
}
appendViewImages($('#moviesView .posterItemImage', page), urls);
});
}
function renderMusicViewImages(page, userId) {
apiClient.getItems(userId, {
SortBy: "random",
IncludeItemTypes: "MusicAlbum",
Limit: 6,
ImageTypes: "Primary",
Recursive: true
}).done(function (result) {
var urls = [];
for (var i = 0, length = result.Items.length; i < length; i++) {
urls.push(LibraryBrowser.getImageUrl(result.Items[i], 'Primary', 0, {
width: 160,
EnableImageEnhancers: false
2013-08-06 12:21:42 -07:00
}));
}
appendViewImages($('#musicView .posterItemImage', page), urls);
});
}
function renderGamesViewImages(page, userId) {
apiClient.getItems(userId, {
SortBy: "random",
MediaTypes: "Game",
Limit: 6,
ImageTypes: "Primary",
Recursive: true
}).done(function (result) {
var urls = [];
for (var i = 0, length = result.Items.length; i < length; i++) {
urls.push(LibraryBrowser.getImageUrl(result.Items[i], 'Primary', 0, {
width: 160,
EnableImageEnhancers: false
2013-08-06 12:21:42 -07:00
}));
}
appendViewImages($('#gamesView .posterItemImage', page), urls);
});
}
function renderTvViewImages(page, userId) {
apiClient.getItems(userId, {
SortBy: "random",
IncludeItemTypes: "Series",
Limit: 6,
ImageTypes: "Primary",
Recursive: true
}).done(function (result) {
var urls = [];
for (var i = 0, length = result.Items.length; i < length; i++) {
urls.push(LibraryBrowser.getImageUrl(result.Items[i], 'Primary', 0, {
width: 160,
EnableImageEnhancers: false
2013-08-06 12:21:42 -07:00
}));
}
appendViewImages($('#tvView .posterItemImage', page), urls);
});
}
function renderViews(page, userId) {
2013-02-20 18:33:05 -07:00
apiClient.getItemCounts(userId).done(function (counts) {
2013-02-20 18:33:05 -07:00
var views = [];
2013-02-20 18:33:05 -07:00
if (counts.MovieCount || counts.TrailerCount) {
2013-08-06 12:21:42 -07:00
views.push({ id: "moviesView", name: "Movies", url: "moviesrecommended.html", img: "css/images/items/list/chapter.png", background: "#0094FF" });
}
2013-04-04 10:27:36 -07:00
if (counts.EpisodeCount || counts.SeriesCount) {
2013-08-06 12:21:42 -07:00
views.push({ id: "tvView", name: "TV Shows", url: "tvrecommended.html", img: "css/images/items/list/collection.png", background: "#FF870F" });
}
2013-05-28 10:25:10 -07:00
if (counts.SongCount || counts.MusicVideoCount) {
2013-08-06 12:21:42 -07:00
views.push({ id: "musicView", name: "Music", url: "musicrecommended.html", img: "css/images/items/list/audiocollection.png", background: "#6FBD45" });
}
if (counts.GameCount) {
2013-08-06 12:21:42 -07:00
views.push({ id: "gamesView", name: "Games", url: "gamesrecommended.html", img: "css/images/items/list/gamecollection.png", background: "#E12026" });
}
2013-11-20 14:08:12 -07:00
var html = '';
for (var i = 0, length = views.length; i < length; i++) {
2013-04-04 10:27:36 -07:00
html += getViewHtml(views[i]);
}
2013-04-04 10:27:36 -07:00
2013-08-06 12:21:42 -07:00
var elem = $('#views', page).html(html);
if (counts.MovieCount || counts.TrailerCount) {
renderMovieViewImages(elem, userId);
}
if (counts.EpisodeCount || counts.SeriesCount) {
renderTvViewImages(elem, userId);
}
if (counts.SongCount || counts.MusicVideoCount) {
renderMusicViewImages(elem, userId);
}
if (counts.GameCount) {
renderGamesViewImages(elem, userId);
}
});
2013-04-04 10:27:36 -07:00
2013-08-06 12:21:42 -07:00
}
$(document).on('pagebeforeshow', "#indexPage", function () {
var page = this;
var userId = Dashboard.getCurrentUserId();
if (!userId) {
return;
}
renderViews(page, userId);
var options = {
sortBy: "SortName"
};
apiClient.getItems(userId, options).done(function (result) {
2013-04-04 10:27:36 -07:00
$('#divCollections', page).html(LibraryBrowser.getPosterViewHtml({
items: result.Items,
showTitle: true,
shape: "backdrop",
centerText: true
}));
2013-04-04 10:27:36 -07:00
});
2013-07-23 05:29:28 -07:00
reloadTips(page);
});
})(jQuery, document, ApiClient);