jellyfin-web/dashboard-ui/scripts/livetvcomponents.js
2016-05-08 02:31:08 -04:00

134 lines
3.2 KiB
JavaScript

define(['datetime'], function (datetime) {
function enableScrollX() {
return browserInfo.mobile && AppInfo.enableAppLayouts;
}
function getTimersHtml(timers) {
var items = timers.map(function (t) {
t.Type = 'Timer';
return t;
});
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.StartDate) {
try {
var premiereDate = datetime.parseISO8601Date(item.StartDate, true);
dateText = LibraryBrowser.getFutureDateText(premiereDate, true);
} catch (err) {
}
}
if (dateText != currentGroupName) {
if (currentGroup.length) {
groups.push({
name: currentGroupName,
items: currentGroup
});
}
currentGroupName = dateText;
currentGroup = [item];
} 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,
shape: "square",
showTitle: true,
showAirTime: true,
showChannelName: true,
lazy: true,
cardLayout: true,
showDetailsMenu: true
});
html += '</div>';
html += '</div>';
}
return Promise.resolve(html);
}
window.LiveTvHelpers = {
getDaysOfWeek: function () {
var days = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
];
return days.map(function (d) {
return {
name: d,
value: d
};
});
},
renderOriginalAirDate: function (elem, item) {
var airDate = item.PremiereDate;
if (airDate && item.IsRepeat) {
try {
airDate = datetime.parseISO8601Date(airDate, true).toLocaleDateString();
}
catch (e) {
console.log("Error parsing date: " + airDate);
}
elem.html(Globalize.translate('ValueOriginalAirDate').replace('{0}', airDate)).show();
} else {
elem.hide();
}
},
getTimersHtml: getTimersHtml
};
});