(function ($, document, window) { function resetTuner(page, id) { var message = 'Are you sure you wish to reset this tuner? Any active players or recordings will be abruptly stopped.'; Dashboard.confirm(message, "Reset Tuner", function (confirmResult) { if (confirmResult) { Dashboard.showLoadingMsg(); ApiClient.resetLiveTvTuner(id).done(function () { Dashboard.hideLoadingMsg(); reload(page); }); } }); } function renderTuners(page, tuners) { var html = ''; for (var i = 0, length = tuners.length; i < length; i++) { var tuner = tuners[i]; html += ''; html += ''; html += tuner.Name; html += ''; html += ''; html += tuner.SourceType; html += ''; html += ''; if (tuner.Status == 'RecordingTv') { if (tuner.ChannelName) { html += 'Recording ' + tuner.ChannelName + ''; } else { html += 'Recording'; } } else if (tuner.Status == 'LiveTv') { if (tuner.ChannelName) { html += 'Watching ' + tuner.ChannelName + ''; } else { html += 'Watching'; } } else { html += tuner.Status; } html += ''; html += ''; if (tuner.ProgramName) { html += tuner.ProgramName; } html += ''; html += ''; html += tuner.Clients.join('
'); html += ''; html += ''; html += ''; html += ''; html += ''; } var elem = $('.tunersResultBody', page).html(html).parents('.tblTuners').table("refresh").trigger('create'); $('.btnResetTuner', elem).on('click', function () { var id = this.getAttribute('data-tunerid'); resetTuner(page, id); }); } function loadPage(page, liveTvInfo) { if (liveTvInfo.IsEnabled) { $('.liveTvStatusContent', page).show(); $('.noLiveTvServices', page).hide(); } else { $('.liveTvStatusContent', page).hide(); $('.noLiveTvServices', page).show(); } var service = liveTvInfo.Services.filter(function (s) { return s.Name == liveTvInfo.ActiveServiceName; })[0] || {}; var serviceUrl = service.HomePageUrl || '#'; $('#activeServiceName', page).html('' + liveTvInfo.ActiveServiceName + '').trigger('create'); var versionHtml = service.Version || 'Unknown'; if (service.HasUpdateAvailable) { versionHtml += ' (Update available)'; } else { versionHtml += ' Up to date!'; } $('#activeServiceVersion', page).html(versionHtml); var status = liveTvInfo.Status; if (liveTvInfo.Status == 'Ok') { status = '' + status + ''; } else { if (liveTvInfo.StatusMessage) { status += ' (' + liveTvInfo.StatusMessage + ')'; } status = '' + status + ''; } $('#activeServiceStatus', page).html(status); renderTuners(page, service.Tuners || []); Dashboard.hideLoadingMsg(); } function reload(page) { Dashboard.showLoadingMsg(); ApiClient.getLiveTvInfo().done(function (liveTvInfo) { loadPage(page, liveTvInfo); }); } $(document).on('pageshow', "#liveTvStatusPage", function () { var page = this; reload(page); }); })(jQuery, document, window);