(function ($, document, apiClient) { function deleteTimer(page, id) { Dashboard.confirm("Are you sure you wish to cancel this timer?", "Confirm Timer Cancellation", function (result) { if (result) { Dashboard.showLoadingMsg(); ApiClient.cancelLiveTvTimer(id).done(function () { Dashboard.alert('Timer deleted'); reload(page); }); } }); } function renderTimers(page, timers) { var html = ''; var cssClass = "detailTable"; html += '
'; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; html += ''; for (var i = 0, length = timers.length; i < length; i++) { var timer = timers[i]; html += ''; html += ''; html += ''; html += ''; var startDate = timer.StartDate; try { startDate = parseISO8601Date(startDate, { toLocal: true }); } catch (err) { } html += ''; html += ''; var minutes = timer.DurationMs / 60000; html += ''; html += ''; html += ''; html += ''; } html += '
 NameChannelDateStartLengthStatusSeries
'; html += ''; html += ''; html += '' + timer.Name + ''; html += ''; if (timer.ChannelId) { html += '' + timer.ChannelName + ''; } html += '' + startDate.toLocaleDateString() + '' + LiveTvHelpers.getDisplayTime(timer.StartDate) + '' + minutes.toFixed(0) + ' mins' + (timer.Status || '') + ''; if (timer.SeriesTimerId) { html += ''; html += 'View'; html += ''; } html += '
'; var elem = $('#items', page).html(html).trigger('create'); $('.btnDeleteTimer', elem).on('click', function () { var id = this.getAttribute('data-timerid'); deleteTimer(page, id); }); Dashboard.hideLoadingMsg(); } function reload(page) { Dashboard.showLoadingMsg(); apiClient.getLiveTvTimers().done(function (result) { renderTimers(page, result.Items); }); } $(document).on('pagebeforeshow', "#liveTvTimersPage", function () { var page = this; reload(page); }); })(jQuery, document, ApiClient);