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

338 lines
9.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-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) {
2014-08-04 20:41:56 -07:00
html += '<span class="liveTvProgram">'+Globalize.translate('LabelLiveProgram')+'&nbsp;&nbsp;</span>';
2013-12-20 13:09:49 -07:00
}
else if (program.IsPremiere) {
2014-08-04 20:41:56 -07:00
html += '<span class="premiereTvProgram">'+Globalize.translate('LabelPremiereProgram')+'&nbsp;&nbsp;</span>';
2013-12-20 13:09:49 -07:00
}
else if (program.IsSeries && !program.IsRepeat) {
2014-08-15 09:35:41 -07:00
html += '<span class="newTvProgram">'+Globalize.translate('LabelNewProgram')+'&nbsp;&nbsp;</span>';
2013-12-20 13:09:49 -07:00
}
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));
2014-04-13 10:27:13 -07:00
$(page).trigger('displayingitem', [{
2014-04-13 10:27:13 -07:00
item: item,
context: 'livetv'
}]);
Dashboard.getCurrentUser().done(function (user) {
2014-03-29 08:40:32 -07:00
if (MediaController.canPlay(item)) {
$('#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 = {
2014-07-16 20:17:14 -07:00
getDaysOfWeek: function () {
var days = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
];
return days.map(function (d) {
return {
name: d,
value: d
};
});
},
2013-11-27 12:04:19 -07:00
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) {
2014-08-04 20:41:56 -07:00
html.push('<span class="newTvProgram">'+Globalize.translate('LabelNewProgram')+'</span>');
2013-12-21 11:37:34 -07:00
}
if (obj.IsLive) {
2014-08-04 20:41:56 -07:00
html.push('<span class="liveTvProgram">'+Globalize.translate('LabelLiveProgram')+'</span>');
2013-12-21 11:37:34 -07:00
}
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) {
2014-08-04 20:41:56 -07:00
html.push(Globalize.translate('LabelHDProgram'));
2013-12-21 11:37:34 -07:00
}
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) {
2014-08-04 20:41:56 -07:00
html += '<a href="livetvseriestimer.html?id=' + obj.SeriesTimerId + '" title="'+Globalize.translate('ButtonViewSeriesRecording')+'">';
2013-12-22 10:16:24 -07:00
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);
}
2014-08-04 20:41:56 -07:00
elem.html(Globalize.translate('ValueOriginalAirDate').replace('{0}', airDate)).show();
2013-12-21 11:37:34 -07:00
} 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 || {};
2014-03-29 08:40:32 -07:00
LibraryBrowser.showPlayMenu(this, currentItem.Id, currentItem.Type, false, currentItem.MediaType, userdata.PlaybackPositionTicks);
});
$('#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);