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

205 lines
5.7 KiB
JavaScript
Raw Normal View History

2014-01-22 13:46:01 -07:00
(function ($, document, window) {
2014-01-23 15:15:15 -07:00
function resetTuner(page, id) {
2014-05-30 12:23:56 -07:00
var message = Globalize.translate('MessageConfirmResetTuner');
2014-01-23 15:15:15 -07:00
2014-05-30 12:23:56 -07:00
Dashboard.confirm(message, Globalize.translate('HeaderResetTuner'), function (confirmResult) {
2014-01-23 15:15:15 -07:00
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 += '<tr>';
html += '<td>';
html += tuner.Name;
html += '</td>';
html += '<td>';
html += tuner.SourceType;
html += '</td>';
html += '<td>';
2014-01-24 11:09:50 -07:00
if (tuner.Status == 'RecordingTv') {
if (tuner.ChannelName) {
2014-05-30 12:23:56 -07:00
html += '<a href="livetvchannel.html?id=' + tuner.ChannelId + '">';
html += Globalize.translate('StatusRecordingProgram').replace('{0}', tuner.ChannelName);
html += '</a>';
2014-01-24 11:09:50 -07:00
} else {
2014-05-30 12:23:56 -07:00
html += Globalize.translate('StatusRecording');
2014-01-24 11:09:50 -07:00
}
}
else if (tuner.Status == 'LiveTv') {
if (tuner.ChannelName) {
2014-05-30 12:23:56 -07:00
html += '<a href="livetvchannel.html?id=' + tuner.ChannelId + '">';
html += Globalize.translate('StatusWatchingProgram').replace('{0}', tuner.ChannelName);
html += '</a>';
2014-01-24 11:09:50 -07:00
} else {
2014-05-30 12:23:56 -07:00
html += Globalize.translate('StatusWatching');
2014-01-24 11:09:50 -07:00
}
}
else {
html += tuner.Status;
}
2014-01-23 15:15:15 -07:00
html += '</td>';
html += '<td>';
if (tuner.ProgramName) {
html += tuner.ProgramName;
}
html += '</td>';
html += '<td>';
html += tuner.Clients.join('<br/>');
html += '</td>';
html += '<td>';
2014-05-30 12:23:56 -07:00
html += '<button data-tunerid="' + tuner.Id + '" type="button" data-inline="true" data-icon="refresh" data-mini="true" data-iconpos="notext" class="btnResetTuner organizerButton" title="' + Globalize.translate('ButtonResetTuner') + '">' + Globalize.translate('ButtonResetTuner') + '</button>';
2014-01-23 15:15:15 -07:00
html += '</td>';
html += '</tr>';
}
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);
});
}
2015-03-12 08:51:48 -07:00
function getServiceHtml(service) {
2014-01-22 13:46:01 -07:00
2015-03-12 08:51:48 -07:00
var html = '';
html += '<div>';
2014-01-22 13:46:01 -07:00
var serviceUrl = service.HomePageUrl || '#';
2015-03-12 08:51:48 -07:00
html += '<p><a href="' + serviceUrl + '" target="_blank">' + service.Name + '</a></p>';
2014-01-22 13:46:01 -07:00
var versionHtml = service.Version || 'Unknown';
if (service.HasUpdateAvailable) {
2014-05-30 12:23:56 -07:00
versionHtml += ' <a style="margin-left: .25em;" href="' + serviceUrl + '" target="_blank">' + Globalize.translate('LiveTvUpdateAvailable') + '</a>';
2014-01-22 13:46:01 -07:00
}
else {
2014-05-30 12:23:56 -07:00
versionHtml += '<img src="css/images/checkmarkgreen.png" style="height: 17px; margin-left: 10px; margin-right: 0; position: relative; top: 5px; border-radius:3px;" /> ' + Globalize.translate('LabelVersionUpToDate');
2014-01-22 13:46:01 -07:00
}
2014-01-23 15:15:15 -07:00
2015-03-12 08:51:48 -07:00
html += '<p>' + versionHtml + '</p>';
2014-01-22 13:46:01 -07:00
2015-03-12 08:51:48 -07:00
var status = service.Status;
2014-01-22 13:46:01 -07:00
2015-03-12 08:51:48 -07:00
if (service.Status == 'Ok') {
2014-01-22 13:46:01 -07:00
status = '<span style="color:green;">' + status + '</span>';
} else {
2015-03-12 08:51:48 -07:00
if (service.StatusMessage) {
status += ' (' + service.StatusMessage + ')';
2014-01-22 13:46:01 -07:00
}
status = '<span style="color:red;">' + status + '</span>';
}
2015-03-12 08:51:48 -07:00
html += '<p>' + Globalize.translate('ValueStatus', status) + '</p>';
html += '</div>';
return html;
}
function loadPage(page, liveTvInfo) {
if (liveTvInfo.IsEnabled) {
$('.liveTvStatusContent', page).show();
$('.noLiveTvServices', page).hide();
} else {
$('.liveTvStatusContent', page).hide();
$('.noLiveTvServices', page).show();
}
$('.servicesList', page).html(liveTvInfo.Services.map(getServiceHtml).join('')).trigger('create');
var tuners = [];
for (var i = 0, length = liveTvInfo.Services.length; i < length; i++) {
for (var j = 0, numTuners = liveTvInfo.Services[i].Tuners.length; j < numTuners; j++) {
tuners.push(liveTvInfo.Services[i].Tuners[j]);
}
}
2014-01-22 13:46:01 -07:00
2015-03-12 08:51:48 -07:00
renderTuners(page, tuners);
2014-01-23 15:15:15 -07:00
2014-01-22 13:46:01 -07:00
Dashboard.hideLoadingMsg();
}
2014-01-23 15:15:15 -07:00
function reload(page) {
2014-01-22 13:46:01 -07:00
Dashboard.showLoadingMsg();
ApiClient.getLiveTvInfo().done(function (liveTvInfo) {
loadPage(page, liveTvInfo);
});
2014-01-23 15:15:15 -07:00
}
2015-06-01 22:46:06 -07:00
$(document).on('pageshowready', "#liveTvStatusPage", function () {
var page = this;
2014-01-23 15:15:15 -07:00
reload(page);
2014-01-22 13:46:01 -07:00
2015-01-20 13:19:54 -07:00
// on here
$('.btnRefreshGuide', page).taskButton({
mode: 'on',
progressElem: $('.refreshGuideProgress', page),
lastResultElem: $('.lastRefreshGuideResult', page),
taskKey: 'RefreshGuide'
});
2015-06-20 17:49:42 -07:00
}).on('pagebeforehide', "#liveTvStatusPage", function () {
var page = this;
2015-01-20 13:19:54 -07:00
// off here
$('.btnRefreshGuide', page).taskButton({
mode: 'off'
});
2014-01-22 13:46:01 -07:00
});
})(jQuery, document, window);