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

225 lines
5.8 KiB
JavaScript
Raw Normal View History

(function ($, document, apiClient) {
2013-02-20 18:33:05 -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) {
2014-03-13 02:00:47 -07:00
views.push({ id: "moviesView", name: "Movies", url: "movieslatest.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
2014-01-16 20:13:12 -07:00
var elem = $('#views', page).html(html).trigger('create');
2013-08-06 12:21:42 -07:00
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
});
})(jQuery, document, ApiClient);