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

206 lines
5.4 KiB
JavaScript
Raw Normal View History

(function ($, document, apiClient) {
2013-11-25 13:39:23 -07:00
var currentItem;
2013-11-26 14:36:11 -07:00
var programs;
2013-11-25 19:53:48 -07:00
2013-11-26 14:36:11 -07:00
function cancelRecording(page, id) {
}
function scheduleRecording(page, id) {
}
2013-11-25 13:39:23 -07:00
function renderPrograms(page, result) {
var html = '';
var cssClass = "detailTable";
html += '<div class="detailTableContainer"><table class="' + cssClass + '">';
html += '<tr>';
2013-11-25 14:53:06 -07:00
html += '<th>&nbsp;</th>';
2013-11-25 13:39:23 -07:00
html += '<th>Date</th>';
html += '<th>Start</th>';
html += '<th>End</th>';
html += '<th>Name</th>';
html += '<th>Genre</th>';
html += '</tr>';
for (var i = 0, length = result.Items.length; i < length; i++) {
var program = result.Items[i];
html += '<tr>';
2013-11-25 14:53:06 -07:00
html += '<td>';
2013-11-25 19:53:48 -07:00
2013-11-26 14:36:11 -07:00
if (program.RecordingId) {
html += '<button data-recordingid="' + program.RecordingId + '" class="btnCancelRecording" type="button" data-icon="delete" data-inline="true" data-mini="true" data-iconpos="notext">Cancel</button>';
2013-11-25 14:53:06 -07:00
} else {
2013-11-26 14:36:11 -07:00
html += '<button data-recordingid="' + program.RecordingId + '" class="btnScheduleRecording" type="button" data-icon="facetime-video" data-inline="true" data-mini="true" data-theme="b" data-iconpos="notext">Record</button>';
2013-11-25 14:53:06 -07:00
}
html += '</td>';
2013-11-25 13:39:23 -07:00
var startDate = program.StartDate;
try {
startDate = parseISO8601Date(startDate, { toLocal: true });
} catch (err) {
}
html += '<td>' + startDate.toLocaleDateString() + '</td>';
2013-11-25 19:53:48 -07:00
2013-11-27 12:04:19 -07:00
html += '<td>' + LiveTvHelpers.getDisplayTime(program.StartDate) + '</td>';
2013-11-25 13:39:23 -07:00
2013-11-27 12:04:19 -07:00
html += '<td>' + LiveTvHelpers.getDisplayTime(program.EndDate) + '</td>';
2013-11-25 13:39:23 -07:00
html += '<td>' + (program.Name || '') + '</td>';
html += '<td>' + program.Genres.join(' / ') + '</td>';
html += '</tr>';
}
html += '</table></div>';
2013-11-26 14:36:11 -07:00
var elem = $('#programList', page).html(html).trigger('create');
$('.btnCancelRecording', elem).on('click', function () {
var recordingId = this.getAttribute('data-recordingid');
cancelRecording(page, recordingId);
});
$('.btnScheduleRecording', elem).on('click', function () {
var recordingId = this.getAttribute('data-recordingid');
scheduleRecording(page, recordingId);
});
2013-11-25 13:39:23 -07:00
}
function loadPrograms(page) {
ApiClient.getLiveTvPrograms({
2013-11-25 19:53:48 -07:00
ChannelIds: currentItem.Id,
UserId: Dashboard.getCurrentUserId()
2013-11-25 13:39:23 -07:00
}).done(function (result) {
renderPrograms(page, result);
2013-11-26 14:36:11 -07:00
programs = result.Items;
Dashboard.hideLoadingMsg();
2013-11-25 13:39:23 -07:00
});
}
function reload(page) {
Dashboard.showLoadingMsg();
ApiClient.getLiveTvChannel(getParameterByName('id')).done(function (item) {
currentItem = item;
var name = item.Name;
$('#itemImage', page).html(LibraryBrowser.getDetailImageHtml(item));
Dashboard.setPageTitle(name);
$('.itemName', page).html(name);
2013-11-27 12:04:19 -07:00
$('.itemChannelNumber', page).html(item.Number);
$('.userDataIcons', page).html(LibraryBrowser.getUserDataIconsHtml(item));
if (ApiClient.isWebSocketOpen()) {
var vals = [item.Type, item.Id, item.Name];
vals.push('livetv');
ApiClient.sendWebSocketMessage("Context", vals.join('|'));
}
if (MediaPlayer.canPlay(item)) {
$('#playButtonContainer', page).show();
} else {
$('#playButtonContainer', page).hide();
}
Dashboard.getCurrentUser().done(function (user) {
if (user.Configuration.IsAdministrator && item.LocationType !== "Offline") {
$('#editButtonContainer', page).show();
} else {
$('#editButtonContainer', page).hide();
}
});
2013-11-25 13:39:23 -07:00
loadPrograms(page);
});
}
2013-11-27 12:04:19 -07:00
window.LiveTvHelpers = {
getDisplayTime: function (date) {
try {
date = parseISO8601Date(date, { toLocal: true });
} catch (err) {
return date;
}
date = date.toLocaleTimeString();
date = date.replace('0:00', '0');
return date;
}
};
$(document).on('pageinit', "#liveTvChannelPage", function () {
var page = this;
$('#btnPlay', page).on('click', function () {
var userdata = currentItem.UserData || {};
LibraryBrowser.showPlayMenu(this, currentItem.Name, currentItem.Type, currentItem.MediaType, userdata.PlaybackPositionTicks);
});
$('#btnRemote', page).on('click', function () {
RemoteControl.showMenuForItem({ item: currentItem, context: 'livetv' });
});
$('#btnEdit', page).on('click', function () {
Dashboard.navigate("edititemmetadata.html?channelid=" + currentItem.Id);
});
}).on('pageshow', "#liveTvChannelPage", function () {
var page = this;
reload(page);
}).on('pagehide', "#liveTvChannelPage", function () {
currentItem = null;
2013-11-26 14:36:11 -07:00
programs = null;
});
})(jQuery, document, ApiClient);