jellyfin-web/dashboard-ui/scripts/livetvchannel.js
2016-09-17 13:01:58 -04:00

69 lines
1.9 KiB
JavaScript

define(['datetime', 'listView'], function (datetime, listView) {
function isSameDay(date1, date2) {
return date1.toDateString() === date2.toDateString();
}
function renderPrograms(page, result) {
var html = '';
var currentItems = [];
var currentStartDate = null;
for (var i = 0, length = result.Items.length; i < length; i++) {
var item = result.Items[i];
var itemStartDate = datetime.parseISO8601Date(item.StartDate);
if (!currentStartDate || !isSameDay(currentStartDate, itemStartDate)) {
if (currentItems.length) {
html += '<h1>' + datetime.toLocaleDateString(itemStartDate, { weekday: 'long', month: 'long', day: 'numeric' }) + '</h1>';
html += '<div is="emby-itemscontainer" class="vertical-list">' + listView.getListViewHtml({
items: currentItems,
enableUserDataButtons: false,
showParentTitle: true,
image: false,
showProgramTimeColumn: true
}) + '</div>';
}
currentStartDate = itemStartDate;
currentItems = [];
}
currentItems.push(item);
}
page.querySelector('#childrenContent').innerHTML = html;
}
function loadPrograms(page, channelId) {
ApiClient.getLiveTvPrograms({
ChannelIds: channelId,
UserId: Dashboard.getCurrentUserId(),
HasAired: false,
SortBy: "StartDate",
EnableTotalRecordCount: false,
EnableImages: false,
ImageTypeLimit: 0
}).then(function (result) {
renderPrograms(page, result);
Dashboard.hideLoadingMsg();
});
}
window.LiveTvChannelPage = {
renderPrograms: loadPrograms
};
});