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

293 lines
8.7 KiB
JavaScript
Raw Normal View History

2014-10-15 20:26:39 -07:00
(function (window, $, document) {
2013-12-14 18:17:57 -07:00
var currentItem;
2014-01-07 22:25:21 -07:00
function deleteTimer(page, id) {
2014-05-30 12:23:56 -07:00
Dashboard.confirm(Globalize.translate('MessageConfirmRecordingCancellation'), Globalize.translate('HeaderConfirmRecordingCancellation'), function (result) {
2014-01-07 22:25:21 -07:00
if (result) {
Dashboard.showLoadingMsg();
ApiClient.cancelLiveTvTimer(id).done(function () {
2014-05-30 12:23:56 -07:00
Dashboard.alert(Globalize.translate('MessageRecordingCancelled'));
2014-01-07 22:25:21 -07:00
reload(page);
});
}
});
}
2013-12-14 18:17:57 -07:00
function renderTimer(page, item) {
currentItem = item;
$('.itemName', page).html(item.Name);
2014-11-11 21:51:40 -07:00
$('#txtPrePaddingMinutes', page).val(item.PrePaddingSeconds / 60);
$('#txtPostPaddingMinutes', page).val(item.PostPaddingSeconds / 60);
2013-12-17 22:44:46 -07:00
$('#chkPrePaddingRequired', page).checked(item.IsPrePaddingRequired).checkboxradio('refresh');
$('#chkPostPaddingRequired', page).checked(item.IsPostPaddingRequired).checkboxradio('refresh');
2013-12-14 18:17:57 -07:00
2013-12-16 23:08:06 -07:00
$('#chkNewOnly', page).checked(item.RecordNewOnly).checkboxradio('refresh');
$('#chkAllChannels', page).checked(item.RecordAnyChannel).checkboxradio('refresh');
$('#chkAnyTime', page).checked(item.RecordAnyTime).checkboxradio('refresh');
2013-12-15 07:19:24 -07:00
var channelHtml = '';
2014-07-16 20:17:14 -07:00
if (item.RecordAnyChannel) {
channelHtml += Globalize.translate('LabelAllChannels');
2013-12-15 07:19:24 -07:00
}
else if (item.ChannelId) {
channelHtml += '<a href="livetvchannel.html?id=' + item.ChannelId + '">' + item.ChannelName + '</a>';
}
2014-07-16 20:17:14 -07:00
$('.channel', page).html(channelHtml).trigger('create');
2013-12-15 07:19:24 -07:00
selectDays(page, item.Days);
2014-07-16 20:17:14 -07:00
if (item.RecordAnyTime) {
$('.time', page).html(Globalize.translate('LabelAnytime')).trigger('create');
}
else if (item.ChannelId) {
2015-05-22 12:16:14 -07:00
$('.time', page).html(LibraryBrowser.getDisplayTime(item.StartDate)).trigger('create');
2014-07-16 20:17:14 -07:00
}
2013-12-14 18:17:57 -07:00
Dashboard.hideLoadingMsg();
}
2014-07-16 20:17:14 -07:00
function getDaysOfWeek() {
// Do not localize. These are used as values, not text.
return LiveTvHelpers.getDaysOfWeek().map(function (d) {
return d.value;
});
}
2013-12-15 07:19:24 -07:00
function selectDays(page, days) {
2014-07-16 20:17:14 -07:00
var daysOfWeek = getDaysOfWeek();
2013-12-15 07:19:24 -07:00
for (var i = 0, length = daysOfWeek.length; i < length; i++) {
var day = daysOfWeek[i];
$('#chk' + day, page).checked(days.indexOf(day) != -1).checkboxradio('refresh');
}
}
function getDays(page) {
2014-07-16 20:17:14 -07:00
var daysOfWeek = getDaysOfWeek();
2013-12-15 07:19:24 -07:00
var days = [];
for (var i = 0, length = daysOfWeek.length; i < length; i++) {
var day = daysOfWeek[i];
if ($('#chk' + day, page).checked()) {
days.push(day);
}
}
return days;
}
2013-12-14 18:17:57 -07:00
function onSubmit() {
Dashboard.showLoadingMsg();
var form = this;
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvSeriesTimer(currentItem.Id).done(function (item) {
2013-12-14 18:17:57 -07:00
2014-11-11 21:51:40 -07:00
item.PrePaddingSeconds = $('#txtPrePaddingMinutes', form).val() * 60;
item.PostPaddingSeconds = $('#txtPostPaddingMinutes', form).val() * 60;
2013-12-17 22:44:46 -07:00
item.IsPrePaddingRequired = $('#chkPrePaddingRequired', form).checked();
item.IsPostPaddingRequired = $('#chkPostPaddingRequired', form).checked();
2013-12-16 23:08:06 -07:00
item.RecordNewOnly = $('#chkNewOnly', form).checked();
item.RecordAnyChannel = $('#chkAllChannels', form).checked();
item.RecordAnyTime = $('#chkAnyTime', form).checked();
2013-12-15 07:19:24 -07:00
item.Days = getDays(form);
2013-12-14 18:17:57 -07:00
ApiClient.updateLiveTvSeriesTimer(item).done(function () {
2014-05-30 12:23:56 -07:00
Dashboard.alert(Globalize.translate('MessageRecordingSaved'));
2013-12-14 18:17:57 -07:00
});
});
// Disable default form submission
return false;
}
2014-05-09 12:43:06 -07:00
2014-01-07 22:25:21 -07:00
function renderRecordings(page, result) {
2014-05-09 12:43:06 -07:00
2014-01-07 22:25:21 -07:00
$('.recordingsTab', page).html(LibraryBrowser.getPosterViewHtml({
items: result.Items,
2014-08-15 09:35:41 -07:00
shape: "detailPageSquare",
2014-01-07 22:25:21 -07:00
showTitle: true,
2014-08-01 19:34:45 -07:00
overlayText: true,
2014-01-07 22:25:21 -07:00
coverImage: true
2015-01-22 23:15:15 -07:00
}));
2014-01-07 22:25:21 -07:00
}
2014-05-09 12:43:06 -07:00
2014-01-07 22:25:21 -07:00
function renderSchedule(page, result) {
var timers = result.Items;
var html = '';
html += '<ul data-role="listview" data-inset="true" data-split-icon="delete">';
2014-01-10 22:49:18 -07:00
var index = '';
2014-01-07 22:25:21 -07:00
for (var i = 0, length = timers.length; i < length; i++) {
var timer = timers[i];
2014-01-10 22:49:18 -07:00
var startDateText = LibraryBrowser.getFutureDateText(parseISO8601Date(timer.StartDate, { toLocal: true }));
2014-01-07 22:25:21 -07:00
2014-01-10 22:49:18 -07:00
if (startDateText != index) {
html += '<li data-role="list-divider">' + startDateText + '</li>';
index = startDateText;
}
2014-01-07 22:25:21 -07:00
2014-01-10 22:49:18 -07:00
html += '<li><a href="livetvtimer.html?id=' + timer.Id + '">';
2014-01-07 22:25:21 -07:00
var program = timer.ProgramInfo || {};
2014-01-10 22:49:18 -07:00
var imgUrl;
2014-01-07 22:25:21 -07:00
var programImages = program.ImageTags || {};
if (programImages.Primary) {
2014-01-07 22:25:21 -07:00
imgUrl = ApiClient.getScaledImageUrl(program.Id, {
height: 80,
tag: programImages.Primary,
2014-01-10 22:49:18 -07:00
type: "Primary"
});
} else {
imgUrl = "css/images/items/searchhintsv2/tv.png";
2014-01-07 22:25:21 -07:00
}
2014-01-10 22:49:18 -07:00
html += '<img src="css/images/items/searchhintsv2/tv.png" style="display:none;">';
html += '<div class="ui-li-thumb" style="background-image:url(\'' + imgUrl + '\');width:5em;height:5em;background-repeat:no-repeat;background-position:center center;background-size: cover;"></div>';
html += '<h3>';
html += program.EpisodeTitle || timer.Name;
html += '</h3>';
2014-01-07 22:25:21 -07:00
html += '<p>';
2014-05-09 12:43:06 -07:00
if (program.IsLive) {
2014-07-16 20:17:14 -07:00
html += '<span class="liveTvProgram">' + Globalize.translate('LabelLiveProgram') + '&nbsp;&nbsp;</span>';
}
else if (program.IsPremiere) {
2014-07-16 20:17:14 -07:00
html += '<span class="premiereTvProgram">' + Globalize.translate('LabelPremiereProgram') + '&nbsp;&nbsp;</span>';
}
else if (program.IsSeries && !program.IsRepeat) {
2014-07-16 20:17:14 -07:00
html += '<span class="newTvProgram">' + Globalize.translate('LabelNewProgram') + '&nbsp;&nbsp;</span>';
}
2015-05-22 12:16:14 -07:00
html += LibraryBrowser.getDisplayTime(timer.StartDate);
html += ' - ' + LibraryBrowser.getDisplayTime(timer.EndDate);
2014-01-07 22:25:21 -07:00
html += '</p>';
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>';
}
2014-01-07 22:25:21 -07:00
html += '</a>';
2014-05-30 12:23:56 -07:00
html += '<a data-timerid="' + timer.Id + '" href="#" title="' + Globalize.translate('ButonCancelRecording') + '" class="btnCancelTimer">' + Globalize.translate('ButonCancelRecording') + '</a>';
2014-01-07 22:25:21 -07:00
html += '</li>';
}
html += '</ul>';
var elem = $('.scheduleTab', page).html(html).trigger('create');
$('.btnCancelTimer', elem).on('click', function () {
deleteTimer(page, this.getAttribute('data-timerid'));
});
}
2013-12-14 18:17:57 -07:00
function reload(page) {
Dashboard.showLoadingMsg();
var id = getParameterByName('id');
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvSeriesTimer(id).done(function (result) {
2013-12-14 18:17:57 -07:00
renderTimer(page, result);
});
2014-01-07 22:25:21 -07:00
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvRecordings({
2014-01-07 22:25:21 -07:00
userId: Dashboard.getCurrentUserId(),
seriesTimerId: id
}).done(function (recordingResult) {
2014-01-07 22:25:21 -07:00
renderRecordings(page, recordingResult);
2014-01-07 22:25:21 -07:00
});
2014-10-15 20:26:39 -07:00
ApiClient.getLiveTvTimers({
2014-01-07 22:25:21 -07:00
seriesTimerId: id
}).done(function (timerResult) {
2014-01-07 22:25:21 -07:00
renderSchedule(page, timerResult);
2014-01-07 22:25:21 -07:00
});
2013-12-14 18:17:57 -07:00
}
2015-05-22 12:16:14 -07:00
$(document).on('pageinitdepends', "#liveTvSeriesTimerPage", function () {
2014-01-07 22:25:21 -07:00
var page = this;
$('.radioSeriesTimerTab', page).on('change', function () {
$('.tab', page).hide();
$('.' + this.value + 'Tab', page).show();
});
2015-06-08 14:32:20 -07:00
$('.liveTvSeriesTimerForm').off('submit', onSubmit).on('submit', onSubmit);
2015-05-22 12:16:14 -07:00
}).on('pagebeforeshowready', "#liveTvSeriesTimerPage", function () {
2013-12-14 18:17:57 -07:00
var page = this;
2014-03-27 12:30:21 -07:00
$('.radioProfileTab', page).checked(false).checkboxradio('refresh');
2014-01-07 22:25:21 -07:00
$('#radioSettings', page).checked(true).checkboxradio('refresh').trigger('change');
2013-12-14 18:17:57 -07:00
reload(page);
}).on('pagehide', "#liveTvSeriesTimerPage", function () {
currentItem = null;
});
2014-10-15 20:26:39 -07:00
})(window, jQuery, document);