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

164 lines
4.5 KiB
JavaScript
Raw Normal View History

2013-12-14 18:17:57 -07:00
(function (window, $, document, apiClient) {
var currentItem;
function deleteTimer(page, id) {
Dashboard.confirm("Are you sure you wish to cancel this series?", "Confirm Series Timer Cancellation", function (result) {
if (result) {
Dashboard.showLoadingMsg();
ApiClient.cancelLiveTvSeriesTimer(id).done(function () {
Dashboard.alert('Timer cancelled.');
reload(page);
});
}
});
}
function renderTimer(page, item) {
currentItem = item;
$('.itemName', page).html(item.Name);
$('.overview', page).html(item.Overview || '');
2013-12-17 22:44:46 -07:00
$('#txtPrePaddingSeconds', page).val(item.PrePaddingSeconds);
$('#txtPostPaddingSeconds', page).val(item.PostPaddingSeconds);
$('#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 = '';
if (item.RecurrenceType == 'NewProgramEventsAllChannels' || item.RecurrenceType == 'AllProgramEventsAllChannels') {
channelHtml += 'All Channels';
}
else if (item.ChannelId) {
channelHtml += '<a href="livetvchannel.html?id=' + item.ChannelId + '">' + item.ChannelName + '</a>';
}
$('.channel', page).html('Channel:&nbsp;&nbsp;&nbsp;' + channelHtml).trigger('create');
selectDays(page, item.Days);
$('.time', page).html('Time:&nbsp;&nbsp;&nbsp;' + LiveTvHelpers.getDisplayTime(item.StartDate));
2013-12-14 18:17:57 -07:00
Dashboard.hideLoadingMsg();
}
2013-12-15 07:19:24 -07:00
function selectDays(page, days) {
var daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
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) {
var daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
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;
apiClient.getLiveTvSeriesTimer(currentItem.Id).done(function (item) {
2013-12-17 22:44:46 -07:00
item.PrePaddingSeconds = $('#txtPrePaddingSeconds', form).val();
item.PostPaddingSeconds = $('#txtPostPaddingSeconds', form).val();
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 () {
Dashboard.alert('Timer Saved');
});
});
// Disable default form submission
return false;
}
function reload(page) {
Dashboard.showLoadingMsg();
var id = getParameterByName('id');
2013-12-15 07:19:24 -07:00
apiClient.getLiveTvSeriesTimer(id).done(function (result) {
2013-12-14 18:17:57 -07:00
renderTimer(page, result);
});
}
$(document).on('pageinit', "#liveTvSeriesTimerPage", function () {
var page = this;
$('#btnCancelTimer', page).on('click', function () {
deleteTimer(page, currentItem.Id);
});
}).on('pagebeforeshow', "#liveTvSeriesTimerPage", function () {
var page = this;
reload(page);
}).on('pagehide', "#liveTvSeriesTimerPage", function () {
currentItem = null;
});
function liveTvSeriesTimerPage() {
var self = this;
self.onSubmit = onSubmit;
}
window.LiveTvSeriesTimerPage = new liveTvSeriesTimerPage();
})(window, jQuery, document, ApiClient);