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

184 lines
5.3 KiB
JavaScript
Raw Normal View History

2013-12-17 13:02:12 -07:00
(function ($, document, apiClient) {
var currentProgram;
function renderRecording(page, defaultTimer, program) {
currentProgram = program;
var context = 'livetv';
$('.itemName', page).html(program.Name);
2013-12-21 11:37:34 -07:00
$('.itemEpisodeName', page).html(program.EpisodeTitle || '');
2013-12-17 13:02:12 -07:00
if (program.CommunityRating) {
$('.itemCommunityRating', page).html(LibraryBrowser.getRatingHtml(program)).show();
} else {
$('.itemCommunityRating', page).hide();
}
LibraryBrowser.renderGenres($('.itemGenres', page), program, context);
LibraryBrowser.renderOverview($('.itemOverview', page), program);
$('.itemMiscInfo', page).html(LibraryBrowser.getMiscInfoHtml(program));
2013-12-22 14:11:32 -07:00
LiveTvHelpers.renderMiscProgramInfo($('.miscTvProgramInfo', page), program);
2013-12-17 22:44:46 -07:00
$('#chkNewOnly', page).checked(defaultTimer.RecordNewOnly).checkboxradio('refresh');
$('#chkAllChannels', page).checked(defaultTimer.RecordAnyChannel).checkboxradio('refresh');
$('#chkAnyTime', page).checked(defaultTimer.RecordAnyTime).checkboxradio('refresh');
2013-12-17 13:02:12 -07:00
2013-12-19 14:51:32 -07:00
$('#txtPrePaddingSeconds', page).val(defaultTimer.PrePaddingSeconds / 60);
$('#txtPostPaddingSeconds', page).val(defaultTimer.PostPaddingSeconds / 60);
2013-12-17 22:44:46 -07:00
$('#chkPrePaddingRequired', page).checked(defaultTimer.IsPrePaddingRequired).checkboxradio('refresh');
$('#chkPostPaddingRequired', page).checked(defaultTimer.IsPostPaddingRequired).checkboxradio('refresh');
2013-12-17 13:02:12 -07:00
2013-12-17 22:44:46 -07:00
if (program.IsSeries) {
$('#eligibleForSeriesFields', page).show();
} else {
$('#eligibleForSeriesFields', page).hide();
2013-12-17 13:02:12 -07:00
}
2013-12-17 22:44:46 -07:00
selectDays(page, defaultTimer.Days);
2013-12-17 13:02:12 -07:00
Dashboard.hideLoadingMsg();
}
function reload(page) {
Dashboard.showLoadingMsg();
2013-12-17 22:44:46 -07:00
var programId = getParameterByName('programid');
2013-12-17 13:02:12 -07:00
2013-12-17 22:44:46 -07:00
var promise1 = apiClient.getNewLiveTvTimerDefaults({ programId: programId });
var promise2 = apiClient.getLiveTvProgram(programId, Dashboard.getCurrentUserId());
2013-12-17 13:02:12 -07:00
$.when(promise1, promise2).done(function (response1, response2) {
var defaults = response1[0];
var program = response2[0];
renderRecording(page, defaults, program);
});
}
2013-12-17 22:44:46 -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');
}
}
2013-12-17 13:02:12 -07:00
function getDays(page) {
2013-12-17 22:44:46 -07:00
var daysOfWeek = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
2013-12-17 13:02:12 -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;
}
function onSubmit() {
Dashboard.showLoadingMsg();
var form = this;
2013-12-19 14:51:32 -07:00
var programId = getParameterByName('programid');
apiClient.getNewLiveTvTimerDefaults({ programId: programId }).done(function (item) {
2013-12-17 13:02:12 -07:00
2013-12-19 14:51:32 -07:00
item.PrePaddingSeconds = $('#txtPrePaddingSeconds', form).val() * 60;
item.PostPaddingSeconds = $('#txtPostPaddingSeconds', form).val() * 60;
2013-12-17 22:44:46 -07:00
item.IsPrePaddingRequired = $('#chkPrePaddingRequired', form).checked();
item.IsPostPaddingRequired = $('#chkPostPaddingRequired', form).checked();
2013-12-17 13:02:12 -07:00
item.RecordNewOnly = $('#chkNewOnly', form).checked();
item.RecordAnyChannel = $('#chkAllChannels', form).checked();
item.RecordAnyTime = $('#chkAnyTime', form).checked();
item.Days = getDays(form);
if ($('#chkRecordSeries', form).checked()) {
apiClient.createLiveTvSeriesTimer(item).done(function () {
Dashboard.hideLoadingMsg();
Dashboard.navigate('livetvseriestimers.html');
});
} else {
apiClient.createLiveTvTimer(item).done(function () {
Dashboard.hideLoadingMsg();
Dashboard.navigate('livetvtimers.html');
});
}
});
// Disable default form submission
return false;
}
2013-12-19 14:51:32 -07:00
window.LiveTvNewRecordingPage = {
onSubmit: onSubmit
2013-12-17 13:02:12 -07:00
2013-12-19 14:51:32 -07:00
};
2013-12-17 13:02:12 -07:00
$(document).on('pageinit', "#liveTvNewRecordingPage", function () {
var page = this;
$('#chkRecordSeries', page).on('change', function () {
if (this.checked) {
$('#seriesFields', page).show();
} else {
$('#seriesFields', page).hide();
}
});
2013-12-19 14:51:32 -07:00
2013-12-17 22:44:46 -07:00
$('#btnCancel', page).on('click', function () {
2013-12-21 11:37:34 -07:00
var programId = getParameterByName('programid');
Dashboard.navigate('livetvprogram.html?id=' + programId);
2013-12-17 22:44:46 -07:00
});
2013-12-17 13:02:12 -07:00
}).on('pagebeforeshow', "#liveTvNewRecordingPage", function () {
var page = this;
reload(page);
}).on('pagehide', "#liveTvNewRecordingPage", function () {
currentProgram = null;
});
})(jQuery, document, ApiClient);