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

147 lines
3.7 KiB
JavaScript
Raw Normal View History

2015-06-29 11:45:42 -07:00
(function ($, document) {
2015-06-29 19:52:23 -07:00
function loadUpcoming(page) {
2015-06-29 11:45:42 -07:00
Dashboard.showLoadingMsg();
var limit = AppInfo.hasLowImageBandwidth ?
24 :
40;
var query = {
Limit: limit,
Fields: "AirTime,UserData,SeriesStudio,SyncInfo",
UserId: Dashboard.getCurrentUserId(),
ImageTypeLimit: 1,
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
};
query.ParentId = LibraryMenu.getTopParentId();
var context = '';
if (query.ParentId) {
context = 'tv';
}
ApiClient.getJSON(ApiClient.getUrl("Shows/Upcoming", query)).done(function (result) {
var items = result.Items;
if (items.length) {
page.querySelector('.noItemsMessage').style.display = 'none';
} else {
page.querySelector('.noItemsMessage').style.display = 'block';
}
var elem = page.querySelector('#upcomingItems');
2015-07-12 12:33:00 -07:00
renderUpcoming(elem, items);
Dashboard.hideLoadingMsg();
LibraryBrowser.setLastRefreshed(page);
});
}
function enableScrollX() {
return $.browser.mobile && AppInfo.enableAppLayouts;
}
function getThumbShape() {
return enableScrollX() ? 'overflowBackdrop' : 'backdrop';
}
function renderUpcoming(elem, items) {
var groups = [];
var currentGroupName = '';
var currentGroup = [];
var i, length;
for (i = 0, length = items.length; i < length; i++) {
var item = items[i];
var dateText = '';
if (item.PremiereDate) {
try {
dateText = LibraryBrowser.getFutureDateText(parseISO8601Date(item.PremiereDate, { toLocal: true }), true);
} catch (err) {
}
}
if (dateText != currentGroupName) {
if (currentGroup.length) {
groups.push({
name: currentGroupName,
items: currentGroup
});
}
currentGroupName = dateText;
currentGroup = [];
} else {
currentGroup.push(item);
}
}
var html = '';
for (i = 0, length = groups.length; i < length; i++) {
var group = groups[i];
html += '<div class="homePageSection">';
html += '<h1 class="listHeader">' + group.name + '</h1>';
if (enableScrollX()) {
html += '<div class="itemsContainer hiddenScrollX">';
} else {
html += '<div class="itemsContainer">';
}
html += LibraryBrowser.getPosterViewHtml({
items: group.items,
2015-06-29 11:45:42 -07:00
showLocationTypeIndicator: false,
2015-07-12 12:33:00 -07:00
shape: getThumbShape(),
2015-06-29 11:45:42 -07:00
showTitle: true,
showPremiereDate: true,
preferThumb: true,
2015-07-12 12:33:00 -07:00
context: 'tv',
2015-06-29 11:45:42 -07:00
lazy: true,
showDetailsMenu: true
});
2015-07-12 12:33:00 -07:00
html += '</div>';
2015-06-29 11:45:42 -07:00
2015-07-12 12:33:00 -07:00
html += '</div>';
}
2015-06-29 11:45:42 -07:00
2015-07-12 12:33:00 -07:00
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
2015-06-29 19:52:23 -07:00
}
2015-07-01 08:47:41 -07:00
$(document).on('pageinitdepends', "#indexPage", function () {
2015-06-29 19:52:23 -07:00
var page = this;
2015-07-01 08:47:41 -07:00
var tabContent = page.querySelector('.homeUpcomingTabContent');
2015-06-29 19:52:23 -07:00
2015-07-01 22:08:05 -07:00
$(page.querySelector('neon-animated-pages')).on('tabchange', function () {
2015-06-29 11:45:42 -07:00
2015-07-01 08:47:41 -07:00
if (parseInt(this.selected) == 3) {
if (LibraryBrowser.needsRefresh(tabContent)) {
loadUpcoming(tabContent);
}
}
});
});
2015-06-29 11:45:42 -07:00
})(jQuery, document);