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

142 lines
4.5 KiB
JavaScript
Raw Normal View History

2014-10-15 20:26:39 -07:00
(function ($, document) {
2013-11-27 12:04:19 -07:00
function deleteTimer(page, id) {
2014-05-30 12:23:56 -07:00
Dashboard.confirm(Globalize.translate('MessageConfirmRecordingCancellation'), Globalize.translate('HeaderConfirmRecordingCancellation'), function (result) {
if (result) {
Dashboard.showLoadingMsg();
ApiClient.cancelLiveTvTimer(id).done(function () {
2014-05-30 12:23:56 -07:00
Dashboard.alert(Globalize.translate('MessageRecordingCancelled'));
reload(page);
});
}
});
}
2013-11-27 12:04:19 -07:00
function renderTimers(page, timers) {
var html = '';
2014-01-10 22:49:18 -07:00
var index = '';
2013-11-27 12:04:19 -07:00
2014-01-10 22:49:18 -07:00
for (var i = 0, length = timers.length; i < length; i++) {
2013-11-27 12:04:19 -07:00
2014-01-10 22:49:18 -07:00
var timer = timers[i];
2013-11-27 12:04:19 -07:00
2014-01-10 22:49:18 -07:00
var startDateText = LibraryBrowser.getFutureDateText(parseISO8601Date(timer.StartDate, { toLocal: true }));
2014-01-10 22:49:18 -07:00
if (startDateText != index) {
2015-08-16 15:03:22 -07:00
if (index) {
html += '</div>';
html += '</div>';
}
html += '<div class="homePageSection">';
html += '<h1>' + startDateText + '</h1>';
html += '<div class="paperList">';
2014-01-10 22:49:18 -07:00
index = startDateText;
}
2013-11-27 12:04:19 -07:00
2015-08-16 15:03:22 -07:00
html += '<paper-icon-item>';
2013-11-27 12:04:19 -07:00
2014-01-12 10:45:45 -07:00
var program = timer.ProgramInfo || {};
2014-01-10 22:49:18 -07:00
var imgUrl;
2015-08-02 16:47:31 -07:00
2014-01-10 22:49:18 -07:00
if (program.ImageTags && program.ImageTags.Primary) {
imgUrl = ApiClient.getScaledImageUrl(program.Id, {
height: 80,
2014-01-10 22:49:18 -07:00
tag: program.ImageTags.Primary,
type: "Primary"
});
2015-08-16 15:03:22 -07:00
}
if (imgUrl) {
html += '<paper-fab class="listAvatar blue" style="background-image:url(\'' + imgUrl + '\');background-repeat:no-repeat;background-position:center center;background-size: cover;" item-icon></paper-fab>';
2015-08-16 21:08:33 -07:00
}
else if (program.IsKids) {
html += '<paper-fab class="listAvatar" style="background:#2196F3;" icon="person" item-icon></paper-fab>';
}
else if (program.IsSports) {
html += '<paper-fab class="listAvatar" style="background:#8BC34A;" icon="person" item-icon></paper-fab>';
}
else if (program.IsMovie) {
html += '<paper-fab class="listAvatar" icon="movie" item-icon></paper-fab>';
}
else if (program.IsNews) {
html += '<paper-fab class="listAvatar" style="background:#673AB7;" icon="new-releases" item-icon></paper-fab>';
}
else {
html += '<paper-fab class="listAvatar blue" icon="live-tv" item-icon></paper-fab>';
2014-01-10 22:49:18 -07:00
}
2015-08-16 15:03:22 -07:00
html += '<paper-item-body two-line>';
html += '<a class="clearLink" href="livetvtimer.html?id=' + timer.Id + '">';
2013-11-27 12:04:19 -07:00
2015-08-16 15:03:22 -07:00
html += '<div>';
2014-01-10 22:49:18 -07:00
html += timer.Name;
2015-08-16 15:03:22 -07:00
html += '</div>';
2013-11-27 12:04:19 -07:00
2015-08-16 15:03:22 -07:00
html += '<div secondary>';
2015-05-22 12:16:14 -07:00
html += LibraryBrowser.getDisplayTime(timer.StartDate);
html += ' - ' + LibraryBrowser.getDisplayTime(timer.EndDate);
2015-08-16 15:03:22 -07:00
html += '</div>';
2013-11-27 12:04:19 -07:00
2015-08-16 15:03:22 -07:00
html += '</a>';
html += '</paper-item-body>';
2013-11-30 23:25:19 -07:00
2014-01-10 22:49:18 -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>';
2013-11-29 13:10:31 -07:00
}
2013-11-27 12:04:19 -07:00
2015-08-18 21:08:03 -07:00
html += '<paper-icon-button icon="cancel" data-timerid="' + timer.Id + '" title="' + Globalize.translate('ButonCancelRecording') + '" class="btnDeleteTimer"></paper-icon-button>';
2013-11-27 12:04:19 -07:00
2015-08-16 15:03:22 -07:00
html += '</paper-icon-item>';
2014-01-10 22:49:18 -07:00
}
2013-11-27 12:04:19 -07:00
2015-08-16 15:03:22 -07:00
if (timers.length) {
html += '</div>';
html += '</div>';
}
2013-11-27 12:04:19 -07:00
2015-09-05 21:53:37 -07:00
var elem = $('#items', page).html(html);
$('.btnDeleteTimer', elem).on('click', function () {
var id = this.getAttribute('data-timerid');
deleteTimer(page, id);
});
2013-11-29 11:44:51 -07:00
Dashboard.hideLoadingMsg();
2013-11-27 12:04:19 -07:00
}
function reload(page) {
2013-11-29 11:44:51 -07:00
Dashboard.showLoadingMsg();
2013-12-14 08:49:11 -07:00
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvTimers().done(function (result) {
2013-11-27 12:04:19 -07:00
renderTimers(page, result.Items);
});
}
2015-08-18 08:52:48 -07:00
window.LiveTvPage.renderTimersTab = function (page, tabContent) {
2013-11-27 12:04:19 -07:00
2015-08-18 08:52:48 -07:00
if (LibraryBrowser.needsRefresh(tabContent)) {
reload(tabContent);
}
};
2013-11-27 12:04:19 -07:00
2014-10-15 20:26:39 -07:00
})(jQuery, document);