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

408 lines
12 KiB
JavaScript
Raw Normal View History

2015-05-22 12:16:14 -07:00
(function () {
2015-09-07 21:22:38 -07:00
function getTimersHtml(timers) {
2015-12-14 08:43:03 -07:00
return new Promise(function (resolve, reject) {
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
require(['paper-fab', 'paper-item-body', 'paper-icon-item'], function () {
var html = '';
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
var index = '';
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
for (var i = 0, length = timers.length; i < length; i++) {
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
var timer = timers[i];
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
var startDateText = LibraryBrowser.getFutureDateText(parseISO8601Date(timer.StartDate, { toLocal: true }));
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
if (startDateText != index) {
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
if (index) {
html += '</div>';
html += '</div>';
}
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
html += '<div class="homePageSection">';
html += '<h1>' + startDateText + '</h1>';
html += '<div class="paperList">';
index = startDateText;
}
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
html += '<paper-icon-item>';
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
var program = timer.ProgramInfo || {};
var imgUrl;
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
if (program.ImageTags && program.ImageTags.Primary) {
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
imgUrl = ApiClient.getScaledImageUrl(program.Id, {
height: 80,
tag: program.ImageTags.Primary,
type: "Primary"
});
}
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
if (imgUrl) {
html += '<paper-fab mini class="blue" style="background-image:url(\'' + imgUrl + '\');background-repeat:no-repeat;background-position:center center;background-size: cover;" item-icon></paper-fab>';
}
else if (program.IsKids) {
html += '<paper-fab mini style="background:#2196F3;" icon="person" item-icon></paper-fab>';
}
else if (program.IsSports) {
html += '<paper-fab mini style="background:#8BC34A;" icon="person" item-icon></paper-fab>';
}
else if (program.IsMovie) {
html += '<paper-fab mini icon="movie" item-icon></paper-fab>';
}
else if (program.IsNews) {
html += '<paper-fab mini style="background:#673AB7;" icon="new-releases" item-icon></paper-fab>';
}
else {
html += '<paper-fab mini class="blue" icon="live-tv" item-icon></paper-fab>';
}
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
html += '<paper-item-body two-line>';
html += '<a class="clearLink" href="livetvtimer.html?id=' + timer.Id + '">';
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
html += '<div>';
html += timer.Name;
html += '</div>';
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
html += '<div secondary>';
html += LibraryBrowser.getDisplayTime(timer.StartDate);
html += ' - ' + LibraryBrowser.getDisplayTime(timer.EndDate);
html += '</div>';
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
html += '</a>';
html += '</paper-item-body>';
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
if (timer.SeriesTimerId) {
html += '<div class="ui-li-aside" style="right:0;">';
html += '<div class="timerCircle seriesTimerCircle"></div>';
html += '<div class="timerCircle seriesTimerCircle"></div>';
html += '<div class="timerCircle seriesTimerCircle"></div>';
html += '</div>';
}
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
html += '<paper-icon-button icon="cancel" data-timerid="' + timer.Id + '" title="' + Globalize.translate('ButonCancelRecording') + '" class="btnDeleteTimer"></paper-icon-button>';
2015-09-07 21:22:38 -07:00
2015-12-14 08:43:03 -07:00
html += '</paper-icon-item>';
}
if (timers.length) {
html += '</div>';
html += '</div>';
}
resolve(html);
});
});
2015-09-07 21:22:38 -07:00
}
2015-05-22 12:16:14 -07:00
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) {
2015-09-29 09:29:06 -07:00
var airDate = item.PremiereDate;
2015-05-22 12:16:14 -07:00
if (airDate && item.IsRepeat) {
try {
airDate = parseISO8601Date(airDate, { toLocal: true }).toLocaleDateString();
}
catch (e) {
2015-06-26 20:27:38 -07:00
Logger.log("Error parsing date: " + airDate);
2015-05-22 12:16:14 -07:00
}
elem.html(Globalize.translate('ValueOriginalAirDate').replace('{0}', airDate)).show();
} else {
elem.hide();
}
2015-09-07 21:22:38 -07:00
},
getTimersHtml: getTimersHtml
2015-05-22 12:16:14 -07:00
};
})();
(function ($, document, window) {
var showOverlayTimeout;
var hideOverlayTimeout;
var currentPosterItem;
function onOverlayMouseOver() {
if (hideOverlayTimeout) {
clearTimeout(hideOverlayTimeout);
hideOverlayTimeout = null;
}
}
function onOverlayMouseOut() {
startHideOverlayTimer();
}
function getOverlayHtml(item) {
var html = '';
html += '<div class="itemOverlayContent">';
if (item.EpisodeTitle) {
html += '<p>';
html += item.EpisodeTitle;
html += '</p>';
}
html += '<p class="itemMiscInfo miscTvProgramInfo"></p>';
html += '<p style="margin: 1.25em 0;">';
html += '<span class="itemCommunityRating">';
html += LibraryBrowser.getRatingHtml(item);
html += '</span>';
html += '<span class="userDataIcons">';
html += LibraryBrowser.getUserDataIconsHtml(item);
html += '</span>';
html += '</p>';
html += '<p class="itemGenres"></p>';
html += '<p class="itemOverlayHtml">';
html += (item.Overview || '');
html += '</p>';
2015-08-24 20:13:04 -07:00
html += '<div style="text-align:center;padding-bottom:.5em;">';
var endDate;
var startDate;
var now = new Date().getTime();
try {
endDate = parseISO8601Date(item.EndDate, { toLocal: true });
} catch (err) {
endDate = now;
}
try {
startDate = parseISO8601Date(item.StartDate, { toLocal: true });
} catch (err) {
startDate = now;
}
if (now < endDate && now >= startDate) {
html += '<paper-button data-id="' + item.ChannelId + '" raised class="accent mini btnPlay"><iron-icon icon="play-arrow"></iron-icon><span>' + Globalize.translate('ButtonPlay') + '</span></paper-button>';
}
if (!item.TimerId && !item.SeriesTimerId) {
html += '<paper-button data-id="' + item.Id + '" raised class="mini btnRecord" style="background-color:#cc3333;"><iron-icon icon="videocam"></iron-icon><span>' + Globalize.translate('ButtonRecord') + '</span></paper-button>';
}
html += '<div>';
2015-05-22 12:16:14 -07:00
html += '</div>';
return html;
}
2015-08-24 20:13:04 -07:00
function onPlayClick() {
2015-09-07 21:22:38 -07:00
hideOverlay();
2015-08-24 20:13:04 -07:00
MediaController.play({
ids: [this.getAttribute('data-id')]
});
}
function onRecordClick() {
2015-09-07 21:22:38 -07:00
hideOverlay();
2015-09-05 09:58:27 -07:00
2015-12-15 11:24:41 -07:00
var programId = this.getAttribute('data-id');
require(['components/recordingcreator/recordingcreator'], function (recordingcreator) {
recordingcreator.show(programId);
});
2015-08-24 20:13:04 -07:00
}
2015-05-22 12:16:14 -07:00
function showOverlay(elem, item) {
2015-12-14 08:43:03 -07:00
require(['components/paperdialoghelper', 'scale-up-animation', 'fade-out-animation'], function () {
2015-05-22 12:16:14 -07:00
2015-10-08 10:28:26 -07:00
var dlg = document.createElement('paper-dialog');
2015-05-22 12:16:14 -07:00
2015-10-08 10:28:26 -07:00
dlg.setAttribute('with-backdrop', 'with-backdrop');
dlg.setAttribute('role', 'alertdialog');
// seeing max call stack size exceeded in the debugger with this
dlg.setAttribute('noAutoFocus', 'noAutoFocus');
dlg.entryAnimation = 'scale-up-animation';
dlg.exitAnimation = 'fade-out-animation';
dlg.classList.add('ui-body-b');
dlg.classList.add('background-theme-b');
dlg.classList.add('tvProgramOverlay');
var html = '';
html += '<h2 class="dialogHeader">';
html += item.Name;
html += '</h2>';
2015-05-22 12:16:14 -07:00
2015-10-08 10:28:26 -07:00
html += '<div>';
2015-08-31 21:15:10 -07:00
html += getOverlayHtml(item);
html += '</div>';
2015-05-22 12:16:14 -07:00
2015-10-08 10:28:26 -07:00
dlg.innerHTML = html;
document.body.appendChild(dlg);
2015-05-22 12:16:14 -07:00
2015-10-08 10:28:26 -07:00
// Has to be assigned a z-index after the call to .open()
$(dlg).on('iron-overlay-closed', function () {
2015-05-22 12:16:14 -07:00
2015-10-08 10:28:26 -07:00
$(dlg).off('mouseenter', onOverlayMouseOver);
$(dlg).off('mouseleave', onOverlayMouseOut);
2015-05-22 12:16:14 -07:00
2015-10-08 10:28:26 -07:00
this.parentNode.removeChild(this);
2015-05-22 12:16:14 -07:00
2015-10-08 10:28:26 -07:00
if (currentPosterItem) {
2015-05-22 12:16:14 -07:00
2015-10-08 10:28:26 -07:00
currentPosterItem = null;
}
2015-08-31 21:15:10 -07:00
});
2015-05-22 12:16:14 -07:00
2015-10-08 10:28:26 -07:00
$('.btnPlay', dlg).on('click', onPlayClick);
$('.btnRecord', dlg).on('click', onRecordClick);
2015-08-24 20:13:04 -07:00
2015-10-08 10:28:26 -07:00
LibraryBrowser.renderGenres($('.itemGenres', dlg), item, 3);
$('.miscTvProgramInfo', dlg).html(LibraryBrowser.getMiscInfoHtml(item));
PaperDialogHelper.positionTo(dlg, elem);
dlg.open();
$(dlg).on('mouseenter', onOverlayMouseOver);
$(dlg).on('mouseleave', onOverlayMouseOut);
2015-05-22 12:16:14 -07:00
2015-08-31 21:15:10 -07:00
currentPosterItem = elem;
});
2015-05-22 12:16:14 -07:00
}
function onProgramClicked() {
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
if (hideOverlayTimeout) {
clearTimeout(hideOverlayTimeout);
hideOverlayTimeout = null;
}
hideOverlay();
}
function hideOverlay() {
2015-10-08 10:28:26 -07:00
var flyout = document.querySelector('.tvProgramOverlay');
2015-09-07 21:22:38 -07:00
2015-10-08 10:28:26 -07:00
if (flyout) {
flyout.close();
2015-05-22 12:16:14 -07:00
}
}
function startHideOverlayTimer() {
if (hideOverlayTimeout) {
clearTimeout(hideOverlayTimeout);
hideOverlayTimeout = null;
}
hideOverlayTimeout = setTimeout(hideOverlay, 200);
}
$.fn.createGuideHoverMenu = function (childSelector) {
function onShowTimerExpired(elem) {
var id = elem.getAttribute('data-programid');
2015-12-14 08:43:03 -07:00
ApiClient.getLiveTvProgram(id, Dashboard.getCurrentUserId()).then(function (item) {
2015-05-22 12:16:14 -07:00
showOverlay(elem, item);
});
}
2015-10-08 12:12:53 -07:00
function onHoverOut() {
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
}
2015-05-22 12:16:14 -07:00
function onHoverIn() {
if (showOverlayTimeout) {
clearTimeout(showOverlayTimeout);
showOverlayTimeout = null;
}
if (hideOverlayTimeout) {
clearTimeout(hideOverlayTimeout);
hideOverlayTimeout = null;
}
var elem = this;
if (currentPosterItem) {
if (currentPosterItem && currentPosterItem == elem) {
return;
} else {
hideOverlay();
}
}
showOverlayTimeout = setTimeout(function () {
onShowTimerExpired(elem);
}, 1000);
}
2015-10-01 09:28:24 -07:00
if (AppInfo.isTouchPreferred) {
2015-05-22 12:16:14 -07:00
/* browser with either Touch Events of Pointer Events
running on touch-capable device */
return this;
}
return this.on('mouseenter', childSelector, onHoverIn)
2015-10-08 12:12:53 -07:00
.on('mouseleave', childSelector, onHoverOut)
2015-05-22 12:16:14 -07:00
.on('click', childSelector, onProgramClicked);
};
})(jQuery, document, window);