-fixed problem with list-view generating too many ajax requests

This commit is contained in:
martin 2011-02-06 22:35:53 -05:00
parent fae1401568
commit 04d63837ba
3 changed files with 45 additions and 22 deletions

View File

@ -66,6 +66,20 @@ function convertToHHMMSSmm(timeInMS){
return hours + ":" + minutes + ":" + seconds+ "." + ms; return hours + ":" + minutes + ":" + seconds+ "." + ms;
} }
function convertDateToHHMM(epochTime){
var d = new Date(epochTime);
var hours = d.getUTCHours().toString();
var minutes = d.getUTCMinutes().toString();
if (hours.length == 1)
hours = "0" + hours;
if (minutes.length == 1)
minutes = "0" + minutes;
return hours + ":" + minutes;
}
function convertDateToHHMMSS(epochTime){ function convertDateToHHMMSS(epochTime){
var d = new Date(epochTime); var d = new Date(epochTime);
@ -82,17 +96,29 @@ function convertDateToHHMMSS(epochTime){
return hours + ":" + minutes + ":" + seconds; return hours + ":" + minutes + ":" + seconds;
} }
/* Takes in a string of format similar to 2011-02-07 02:59:57,
* and converts this to epoch/posix time. */
function convertDateToPosixTime(s){ function convertDateToPosixTime(s){
var year = s.substring(0, 4);
var month = s.substring(5, 7); var temp = s.split(" ");
var day = s.substring(8, 10);
var hour = s.substring(11, 13); var date = temp[0].split("-");
var minute = s.substring(14, 16); var time = temp[1].split(":");
var sec = s.substring(17, 19);
var msec = 0; var year = date[0];
if (s.length >= 20){ var month = date[1];
msec = s.substring(20); var day = date[2];
} var hour = time[0];
var minute = time[1];
var sec = 0;
var msec = 0;
if (time[2].indexOf(".") != -1){
var temp1 = time[2].split(".");
sec = temp1[0];
msec = temp1[1];
} else
sec = time[2];
return Date.UTC(year, month, day, hour, minute, sec, msec); return Date.UTC(year, month, day, hour, minute, sec, msec);
} }

View File

@ -96,10 +96,12 @@ function createDataGrid(){
} }
} ); } );
setTimeout(init2, 5000);
} }
var viewType = "now" //"day"; var viewType = "now" //"day";
var mainLoopRegistered = false;
function setViewType(type){ function setViewType(type){
if (type == 0){ if (type == 0){
viewType = "now"; viewType = "now";
@ -119,6 +121,11 @@ function init2(){
registered = true; registered = true;
registerSongEndListener(notifySongEnd); registerSongEndListener(notifySongEnd);
} }
if (!mainLoopRegistered){
setTimeout(init2, 5000);
mainLoopRegistered = true;
}
} }
$(document).ready(function() { $(document).ready(function() {

View File

@ -172,7 +172,7 @@ function updatePlaybar(){
$('#show-length').empty(); $('#show-length').empty();
if (currentShow.length > 0){ if (currentShow.length > 0){
$('#show-length').text(convertDateToHHMMSS(currentShow[0].showStartPosixTime) + " - " + convertDateToHHMMSS(currentShow[0].showEndPosixTime)); $('#show-length').text(convertDateToHHMM(currentShow[0].showStartPosixTime) + " - " + convertDateToHHMM(currentShow[0].showEndPosixTime));
} }
/* Column 2 update */ /* Column 2 update */
@ -228,15 +228,6 @@ function parseItems(obj){
} }
function getScheduleFromServerDebug(){
$.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"text", success:function(data){
alert(data);
}});
setTimeout(getScheduleFromServer, serverUpdateInterval);
}
function getScheduleFromServer(){ function getScheduleFromServer(){
$.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){ $.ajax({ url: "/Schedule/get-current-playlist/format/json", dataType:"json", success:function(data){
parseItems(data.entries); parseItems(data.entries);
@ -248,7 +239,6 @@ function getScheduleFromServer(){
function init() { function init() {
//begin producer "thread" //begin producer "thread"
getScheduleFromServer(); getScheduleFromServer();
//getScheduleFromServerDebug();
//begin consumer "thread" //begin consumer "thread"
secondsTimer(); secondsTimer();