/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
$( document ).ready(function() {
getSchedule2(null);
});
function padToTwoDigits(ss){
ss = ""+ss;
if(ss.length < 2){
ss= "0"+ss;
}
return ss;
}
function getSchedule2(requestObject){
if(isNull(requestObject)){
requestObject = {"channelsPerPage" : "4000", "pageNum" : "1"};
}
$.ajax({
url: 'rest/getSchedule',
type: 'post',
dataType: 'json',
contentType: "application/json",
data: JSON.stringify(requestObject),
success: function (data) {
var channelList = data.schedule;
var requestObject = data.requestObject;
var requestStartTimeEpochSeconds = requestObject.startTime.epochSecond;
var requestEndTimeEpochSeconds = requestObject.endTime.epochSecond;
$("#guideGoesHere").html("");
var channelUl = $("
");
var channelGroupsUl = $("").attr("id","channelGroups").append($("").append(channelUl));
for(var idx in channelList){
var individualChannelLi = $("");
var channel = channelList[idx];
var currentPercentOver = 0;
var channelProgramUl = $("").attr("channelNum",channel.displayName);
individualChannelLi.append(channelProgramUl);
var channelNameLi = $("");
channelNameLi.append("").addClass("channelNumLabel").append(channel.displayName);
channelProgramUl.append(channelNameLi);
var programsLi = $("").addClass("programs");
for(var idx2 in channel.programs){
var program = channel.programs[idx2];
programsLi.append(getProgramDiv(program,requestObject,currentPercentOver));
currentPercentOver += program.widthPercent;
}
channelProgramUl.append(programsLi);
channelUl.append(individualChannelLi);
}
$("#guideGoesHere").append(channelGroupsUl);
},
error: function ( jqXHR, textStatus, errorThrown ){
alert(errorThrown);
}
});
}
function getProgramDiv(program, requestObject, startAtPercent){
var programDiv = $("").addClass("channelProgram");
var titleInfoDiv = $("").addClass("titleInfo");
var otherStuffDiv = $("").addClass("otherProgramStuff");
titleInfoDiv.append(program.title);
if(!isNull(program.subTitle)){
titleInfoDiv.append($(""+program.subTitle+"
").addClass("programSubtitle"));
}
programDiv.append(titleInfoDiv);
programDiv.append(otherStuffDiv);
var requestStartTimeEpochSeconds = requestObject.startTime.epochSecond;
var requestEndTimeEpochSeconds = requestObject.endTime.epochSecond;
var showingMinutes = (requestEndTimeEpochSeconds-requestStartTimeEpochSeconds)/60;
var durationSeconds = program.stop.epochSecond-program.start.epochSecond;
var displayDurationSeconds = durationSeconds;
if(program.start.epochSecond < requestStartTimeEpochSeconds){
displayDurationSeconds = displayDurationSeconds-(requestStartTimeEpochSeconds-program.start.epochSecond);
}
if(program.stop.epochSecond > requestEndTimeEpochSeconds){
displayDurationSeconds = displayDurationSeconds-(program.stop.epochSecond-requestEndTimeEpochSeconds);
}
var displayDurationMinutes = displayDurationSeconds/60;
var widthPercent = (displayDurationMinutes/showingMinutes)*100;
programDiv.attr("style","left: "+startAtPercent+"%; width: "+widthPercent+"%");
program.widthPercent = widthPercent;
return programDiv;
}
function getSchedule(requestObject){
if(isNull(requestObject)){
requestObject = {"channelsPerPage" : "100", "pageNum" : "1"};
}
$.ajax({
url: 'rest/getSchedule',
type: 'post',
dataType: 'json',
contentType: "application/json",
data: JSON.stringify(requestObject),
success: function (data) {
$("#guideGoesHere").html("");
var guideTable = $("");
var channelList = data.schedule;
var requestObject = data.requestObject;
var requestStartTimeEpochSeconds = requestObject.startTime.epochSecond;
var requestEndTimeEpochSeconds = requestObject.endTime.epochSecond;
var requestStartDate = new Date(requestStartTimeEpochSeconds*1000);
var requestEndDate = new Date(requestEndTimeEpochSeconds*1000);
var nextDate = new Date(requestStartDate.getTime());
nextDate.setHours(nextDate.getHours()+1);
var timeDisplayRow = $(" | "+padToTwoDigits(requestStartDate.getHours())+":"+padToTwoDigits(requestStartDate.getMinutes())+" | "+padToTwoDigits(nextDate.getHours())+":"+padToTwoDigits(nextDate.getMinutes())+" |
");
guideTable.append(timeDisplayRow);
for(var idx in channelList){
var channel = channelList[idx];
var channelTableRow = $(""+channel.displayName+" |
");
for(var idx2 in channel.programs){
var program = channel.programs[idx2];
var durationSeconds = program.stop.epochSecond-program.start.epochSecond;
var durationMinutes = durationSeconds/60;
var displayDurationSeconds = durationSeconds;
if(program.start.epochSecond < requestStartTimeEpochSeconds){
displayDurationSeconds = displayDurationSeconds-(requestStartTimeEpochSeconds-program.start.epochSecond);
}
if(program.stop.epochSecond > requestEndTimeEpochSeconds){
displayDurationSeconds = displayDurationSeconds-(program.stop.epochSecond-requestEndTimeEpochSeconds);
}
var displayDurationMinutes = displayDurationSeconds/60;
var programText = program.title;
if(!isNull(program.subTitle)){
programText+="
"+program.subTitle+"";
}
channelTableRow.append(""+programText+" | ");
}
guideTable.append(channelTableRow);
}
$("#guideGoesHere").append(guideTable);
},
error: function ( jqXHR, textStatus, errorThrown ){
alert(errorThrown);
}
});
}
function isNull(item){
if(item === null || typeof item === "undefined"){
return true;
}
return false;
}