2014-10-15 20:26:39 -07:00
|
|
|
|
(function ($, document) {
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
var currentProgram;
|
2015-08-21 12:25:35 -07:00
|
|
|
|
var registrationInfo;
|
|
|
|
|
var lastRegId;
|
|
|
|
|
|
|
|
|
|
function getRegistration(programId) {
|
|
|
|
|
|
|
|
|
|
var deferred = DeferredBuilder.Deferred();
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
|
|
|
|
if (registrationInfo && (lastRegId == programId)) {
|
2015-08-21 12:25:35 -07:00
|
|
|
|
deferred.resolveWith(null, [registrationInfo]);
|
2015-08-21 19:59:10 -07:00
|
|
|
|
return deferred.promise();
|
2015-08-21 12:25:35 -07:00
|
|
|
|
}
|
2015-08-21 19:59:10 -07:00
|
|
|
|
|
2015-08-21 12:25:35 -07:00
|
|
|
|
registrationInfo = null;
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
ApiClient.getJSON(ApiClient.getUrl('LiveTv/Registration', {
|
|
|
|
|
|
|
|
|
|
ProgramId: programId,
|
|
|
|
|
Feature: 'seriesrecordings'
|
2015-12-14 08:43:03 -07:00
|
|
|
|
})).then(function (result) {
|
2015-08-21 12:25:35 -07:00
|
|
|
|
|
|
|
|
|
lastRegId = programId;
|
|
|
|
|
registrationInfo = result;
|
|
|
|
|
deferred.resolveWith(null, [registrationInfo]);
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
}, function () {
|
2015-08-21 12:25:35 -07:00
|
|
|
|
|
|
|
|
|
deferred.resolveWith(null, [
|
|
|
|
|
{
|
|
|
|
|
TrialVersion: true,
|
|
|
|
|
IsValid: true,
|
|
|
|
|
IsRegistered: false
|
|
|
|
|
}]);
|
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return deferred.promise();
|
|
|
|
|
}
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
function renderRecording(page, defaultTimer, program) {
|
|
|
|
|
|
|
|
|
|
currentProgram = program;
|
|
|
|
|
|
|
|
|
|
$('.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
|
|
|
|
|
2014-01-17 22:55:21 -07:00
|
|
|
|
$('.itemCommunityRating', page).html(LibraryBrowser.getRatingHtml(program));
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
2015-08-20 20:21:27 -07:00
|
|
|
|
LibraryBrowser.renderGenres($('.itemGenres', page), program);
|
2015-07-06 07:20:23 -07:00
|
|
|
|
LibraryBrowser.renderOverview(page.querySelectorAll('.itemOverview'), program);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
$('.itemMiscInfo', page).html(LibraryBrowser.getMiscInfoHtml(program));
|
|
|
|
|
|
2015-08-16 21:08:33 -07:00
|
|
|
|
$('#chkNewOnly', page).checked(defaultTimer.RecordNewOnly);
|
|
|
|
|
$('#chkAllChannels', page).checked(defaultTimer.RecordAnyChannel);
|
|
|
|
|
$('#chkAnyTime', page).checked(defaultTimer.RecordAnyTime);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
2014-11-11 21:51:40 -07:00
|
|
|
|
$('#txtPrePaddingMinutes', page).val(defaultTimer.PrePaddingSeconds / 60);
|
|
|
|
|
$('#txtPostPaddingMinutes', page).val(defaultTimer.PostPaddingSeconds / 60);
|
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
|
|
|
|
|
2014-10-15 20:26:39 -07:00
|
|
|
|
var promise1 = ApiClient.getNewLiveTvTimerDefaults({ programId: programId });
|
|
|
|
|
var promise2 = ApiClient.getLiveTvProgram(programId, Dashboard.getCurrentUserId());
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
Promise.all([promise1, promise2]).then(function (responses) {
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
var defaults = responses[0];
|
|
|
|
|
var program = responses[1];
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
renderRecording(page, defaults, program);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 22:44:46 -07:00
|
|
|
|
function selectDays(page, days) {
|
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
var daysOfWeek = getDaysOfWeek();
|
2013-12-17 22:44:46 -07:00
|
|
|
|
|
|
|
|
|
for (var i = 0, length = daysOfWeek.length; i < length; i++) {
|
|
|
|
|
|
|
|
|
|
var day = daysOfWeek[i];
|
|
|
|
|
|
2015-08-16 21:08:33 -07:00
|
|
|
|
$('#chk' + day, page).checked(days.indexOf(day) != -1);
|
2013-12-17 22:44:46 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2014-07-16 20:17:14 -07:00
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
function getDaysOfWeek() {
|
2014-07-16 20:17:14 -07:00
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
// Do not localize. These are used as values, not text.
|
2014-07-16 20:17:14 -07:00
|
|
|
|
return LiveTvHelpers.getDaysOfWeek().map(function (d) {
|
|
|
|
|
return d.value;
|
|
|
|
|
});
|
2014-05-30 12:23:56 -07:00
|
|
|
|
}
|
2013-12-17 22:44:46 -07:00
|
|
|
|
|
2013-12-17 13:02:12 -07:00
|
|
|
|
function getDays(page) {
|
|
|
|
|
|
2014-05-30 12:23:56 -07:00
|
|
|
|
var daysOfWeek = getDaysOfWeek();
|
2013-12-17 22:44:46 -07:00
|
|
|
|
|
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');
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.getNewLiveTvTimerDefaults({ programId: programId }).then(function (item) {
|
2013-12-17 13:02:12 -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 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()) {
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.createLiveTvSeriesTimer(item).then(function () {
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2015-08-02 16:56:21 -07:00
|
|
|
|
Dashboard.navigate('livetv.html');
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} else {
|
2015-12-14 08:43:03 -07:00
|
|
|
|
ApiClient.createLiveTvTimer(item).then(function () {
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
2015-08-02 16:56:21 -07:00
|
|
|
|
Dashboard.navigate('livetv.html');
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Disable default form submission
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 12:25:35 -07:00
|
|
|
|
function hideSeriesRecordingFields(page) {
|
|
|
|
|
$('#seriesFields', page).hide();
|
|
|
|
|
page.querySelector('.btnSubmitContainer').classList.remove('hide');
|
|
|
|
|
page.querySelector('.supporterContainer').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showSeriesRecordingFields(page) {
|
|
|
|
|
$('#seriesFields', page).show();
|
|
|
|
|
page.querySelector('.btnSubmitContainer').classList.remove('hide');
|
|
|
|
|
|
2015-12-14 08:43:03 -07:00
|
|
|
|
getRegistration(getParameterByName('programid')).then(function (regInfo) {
|
2015-08-21 12:25:35 -07:00
|
|
|
|
|
|
|
|
|
if (regInfo.IsValid) {
|
|
|
|
|
page.querySelector('.btnSubmitContainer').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
page.querySelector('.btnSubmitContainer').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (regInfo.IsRegistered) {
|
|
|
|
|
|
|
|
|
|
page.querySelector('.supporterContainer').classList.add('hide');
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
page.querySelector('.supporterContainer').classList.remove('hide');
|
|
|
|
|
|
|
|
|
|
if (AppInfo.enableSupporterMembership) {
|
|
|
|
|
page.querySelector('.btnSupporter').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
page.querySelector('.btnSupporter').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (regInfo.TrialVersion) {
|
|
|
|
|
page.querySelector('.supporterTrial').classList.remove('hide');
|
|
|
|
|
} else {
|
|
|
|
|
page.querySelector('.supporterTrial').classList.add('hide');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 07:01:59 -07:00
|
|
|
|
$(document).on('pageinit', "#liveTvNewRecordingPage", function () {
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
|
|
|
|
$('#chkRecordSeries', page).on('change', function () {
|
|
|
|
|
|
|
|
|
|
if (this.checked) {
|
2015-08-21 12:25:35 -07:00
|
|
|
|
showSeriesRecordingFields(page);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
} else {
|
2015-08-21 12:25:35 -07:00
|
|
|
|
hideSeriesRecordingFields(page);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
}
|
|
|
|
|
});
|
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');
|
|
|
|
|
|
2015-07-28 20:42:03 -07:00
|
|
|
|
Dashboard.navigate('itemdetails.html?id=' + programId);
|
2013-12-17 22:44:46 -07:00
|
|
|
|
|
|
|
|
|
});
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
2015-05-22 12:16:14 -07:00
|
|
|
|
$('.liveTvNewRecordingForm').off('submit', onSubmit).on('submit', onSubmit);
|
|
|
|
|
|
2015-08-31 23:22:46 -07:00
|
|
|
|
}).on('pagebeforeshow', "#liveTvNewRecordingPage", function () {
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
var page = this;
|
2015-08-21 12:25:35 -07:00
|
|
|
|
hideSeriesRecordingFields(page);
|
2013-12-17 13:02:12 -07:00
|
|
|
|
reload(page);
|
|
|
|
|
|
2015-06-20 17:49:42 -07:00
|
|
|
|
}).on('pagebeforehide', "#liveTvNewRecordingPage", function () {
|
2013-12-17 13:02:12 -07:00
|
|
|
|
|
|
|
|
|
currentProgram = null;
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2014-10-15 20:26:39 -07:00
|
|
|
|
})(jQuery, document);
|