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

324 lines
8.9 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-25 13:39:23 -07:00
function renderPrograms(page, result) {
var html = '';
2013-12-20 13:09:49 -07:00
var currentIndexValue;
2013-11-25 13:39:23 -07:00
var now = new Date();
2013-11-25 13:39:23 -07:00
for (var i = 0, length = result.Items.length; i < length; i++) {
var program = result.Items[i];
var startDate = parseISO8601Date(program.StartDate, { toLocal: true });
var startDateText = LibraryBrowser.getFutureDateText(startDate);
2013-12-20 13:09:49 -07:00
var endDate = parseISO8601Date(program.EndDate, { toLocal: true });
2013-11-25 14:53:06 -07:00
2013-12-20 13:09:49 -07:00
if (startDateText != currentIndexValue) {
2013-11-25 14:53:06 -07:00
2013-12-20 13:09:49 -07:00
html += '<h2 class="detailSectionHeader tvProgramSectionHeader">' + startDateText + '</h2>';
currentIndexValue = startDateText;
}
2013-11-25 13:39:23 -07:00
2013-12-20 13:09:49 -07:00
html += '<a href="livetvprogram.html?id=' + program.Id + '" class="tvProgram">';
2013-11-25 13:39:23 -07:00
var cssClass = "tvProgramTimeSlot";
if (now >= startDate && now < endDate) {
cssClass += " tvProgramCurrentTimeSlot";
}
html += '<div class="' + cssClass + '">';
2013-12-20 13:09:49 -07:00
html += '<div class="tvProgramTimeSlotInner">' + LiveTvHelpers.getDisplayTime(startDate) + '</div>';
html += '</div>';
2013-11-25 13:39:23 -07:00
cssClass = "tvProgramInfo";
2013-11-25 13:39:23 -07:00
2013-12-20 13:09:49 -07:00
if (program.IsKids) {
cssClass += " childProgramInfo";
}
else if (program.IsSports) {
cssClass += " sportsProgramInfo";
}
else if (program.IsNews) {
cssClass += " newsProgramInfo";
2013-11-25 13:39:23 -07:00
}
2013-12-20 13:09:49 -07:00
else if (program.IsMovie) {
cssClass += " movieProgramInfo";
}
2014-01-15 15:19:45 -07:00
html += '<div data-programid="' + program.Id + '" class="' + cssClass + '">';
2013-12-20 13:09:49 -07:00
var name = program.Name;
2014-01-11 16:07:56 -07:00
html += '<div class="tvProgramName">' + name + '</div>';
2013-12-20 13:09:49 -07:00
html += '<div class="tvProgramTime">';
2013-11-25 13:39:23 -07:00
2013-12-20 13:09:49 -07:00
if (program.IsLive) {
html += '<span class="liveTvProgram">LIVE&nbsp;&nbsp;</span>';
}
else if (program.IsPremiere) {
2014-01-06 06:33:14 -07:00
html += '<span class="premiereTvProgram">PREMIERE&nbsp;&nbsp;</span>';
2013-12-20 13:09:49 -07:00
}
else if (program.IsSeries && !program.IsRepeat) {
html += '<span class="newTvProgram">NEW&nbsp;&nbsp;</span>';
}
2013-11-25 19:53:48 -07:00
2013-12-20 13:09:49 -07:00
var minutes = program.RunTimeTicks / 600000000;
2013-11-25 13:39:23 -07:00
2013-12-20 13:09:49 -07:00
minutes = Math.round(minutes || 1) + ' min';
2013-11-25 13:39:23 -07:00
2013-12-20 13:09:49 -07:00
if (program.EpisodeTitle) {
2013-12-16 23:08:06 -07:00
2013-12-20 13:09:49 -07:00
html += program.EpisodeTitle + '&nbsp;&nbsp;(' + minutes + ')';
} else {
html += minutes;
2013-12-16 23:08:06 -07:00
}
2013-12-22 10:16:24 -07:00
2013-12-21 11:37:34 -07:00
if (program.SeriesTimerId) {
html += '<div class="timerCircle seriesTimerCircle"></div>';
html += '<div class="timerCircle seriesTimerCircle"></div>';
html += '<div class="timerCircle seriesTimerCircle"></div>';
}
else if (program.TimerId) {
html += '<div class="timerCircle"></div>';
}
2013-12-16 23:08:06 -07:00
2013-12-20 13:09:49 -07:00
html += '</div>';
html += '</div>';
2013-12-16 23:08:06 -07:00
2013-12-20 13:09:49 -07:00
html += '</a>';
}
2014-01-15 15:19:45 -07:00
$('#programList', page).html(html).trigger('create').createGuideHoverMenu('.tvProgramInfo');
2013-11-25 13:39:23 -07:00
}
function loadPrograms(page) {
ApiClient.getLiveTvPrograms({
2013-12-16 23:08:06 -07:00
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();
2013-12-17 13:02:12 -07:00
ApiClient.getLiveTvChannel(getParameterByName('id'), Dashboard.getCurrentUserId()).done(function (item) {
currentItem = item;
var name = item.Name;
$('#itemImage', page).html(LibraryBrowser.getDetailImageHtml(item));
Dashboard.setPageTitle(name);
2014-01-01 20:53:27 -07:00
$('.itemName', page).html(item.Number + ' ' + name);
2013-11-27 12:04:19 -07:00
$('.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('|'));
}
Dashboard.getCurrentUser().done(function (user) {
if (MediaPlayer.canPlay(item, user)) {
$('#playButtonContainer', page).show();
} else {
$('#playButtonContainer', page).hide();
}
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) {
2013-12-16 23:08:06 -07:00
2013-12-20 13:09:49 -07:00
if ((typeof date).toString().toLowerCase() === 'string') {
try {
2013-11-27 12:04:19 -07:00
2013-12-20 13:09:49 -07:00
date = parseISO8601Date(date, { toLocal: true });
2013-11-27 12:04:19 -07:00
2013-12-20 13:09:49 -07:00
} catch (err) {
return date;
}
2013-11-27 12:04:19 -07:00
}
2014-01-11 16:07:56 -07:00
var lower = date.toLocaleTimeString().toLowerCase();
var hours = date.getHours();
var minutes = date.getMinutes();
var text;
if (lower.indexOf('am') != -1 || lower.indexOf('pm') != -1) {
var suffix = hours > 11 ? 'pm' : 'am';
hours = (hours % 12) || 12;
text = hours;
2014-01-15 15:19:45 -07:00
2014-01-11 16:07:56 -07:00
if (minutes) {
2013-11-27 12:04:19 -07:00
2014-01-11 16:07:56 -07:00
text += ':';
if (minutes < 10) {
text += '0';
}
text += minutes;
}
text += suffix;
} else {
text = hours + ':';
if (minutes < 10) {
text += '0';
}
text += minutes;
}
2013-11-27 12:04:19 -07:00
2014-01-11 16:07:56 -07:00
return text;
2013-12-21 11:37:34 -07:00
},
2013-12-22 10:16:24 -07:00
renderMiscProgramInfo: function (elem, obj) {
2013-12-21 11:37:34 -07:00
var html = [];
if (obj.IsSeries && !obj.IsRepeat) {
html.push('<span class="newTvProgram">NEW</span>');
}
if (obj.IsLive) {
html.push('<span class="liveTvProgram">LIVE</span>');
}
2013-12-22 10:16:24 -07:00
2013-12-21 11:37:34 -07:00
if (obj.ChannelId) {
html.push('<a class="textlink" href="livetvchannel.html?id=' + obj.ChannelId + '">' + obj.ChannelName + '</a>');
}
if (obj.IsHD) {
html.push('HD');
}
if (obj.Audio) {
html.push(obj.Audio);
}
2013-12-22 10:16:24 -07:00
html = html.join('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
if (obj.SeriesTimerId) {
html += '<a href="livetvseriestimer.html?id=' + obj.SeriesTimerId + '" title="View Series Recording">';
html += '<div class="timerCircle seriesTimerCircle"></div>';
html += '<div class="timerCircle seriesTimerCircle"></div>';
html += '<div class="timerCircle seriesTimerCircle"></div>';
html += '</a>';
}
else if (obj.TimerId) {
html += '<a href="livetvtimer.html?id=' + obj.TimerId + '">';
html += '<div class="timerCircle"></div>';
html += '</a>';
}
elem.html(html).trigger('create');
2013-12-21 11:37:34 -07:00
},
2013-12-22 10:16:24 -07:00
renderOriginalAirDate: function (elem, item) {
2013-12-21 11:37:34 -07:00
var airDate = item.OriginalAirDate;
2014-01-18 21:25:01 -07:00
if (airDate && item.IsRepeat) {
2013-12-21 11:37:34 -07:00
try {
airDate = parseISO8601Date(airDate, { toLocal: true }).toLocaleDateString();
}
catch (e) {
console.log("Error parsing date: " + airDate);
}
elem.html('Original air date:&nbsp;&nbsp;' + airDate).show();
} else {
elem.hide();
}
2013-11-27 12:04:19 -07:00
}
};
$(document).on('pageinit', "#liveTvChannelPage", function () {
var page = this;
$('#btnPlay', page).on('click', function () {
var userdata = currentItem.UserData || {};
2013-12-29 11:53:56 -07:00
LibraryBrowser.showPlayMenu(this, currentItem.Id, 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);