From 292996fc5b5cac616e744136f30e74daa71c6360 Mon Sep 17 00:00:00 2001 From: mkonecny Date: Wed, 9 Feb 2011 18:54:15 -0500 Subject: [PATCH] -list-view doesn't reset to the top every 5 seconds anymore. --- public/js/playlist/nowplayingdatagrid.js | 20 +++++++++++++++----- public/js/playlist/playlist.js | 24 ++++++++---------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/public/js/playlist/nowplayingdatagrid.js b/public/js/playlist/nowplayingdatagrid.js index 749738bb0..a558d13a7 100644 --- a/public/js/playlist/nowplayingdatagrid.js +++ b/public/js/playlist/nowplayingdatagrid.js @@ -73,7 +73,6 @@ function createDataGrid(){ "bInfo": false, "bLengthChange": false, "bPaginate": false, - "aaData": datagridData.rows, "aoColumns": columns, "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { if (aData[aData.length-2] == "t") @@ -83,7 +82,8 @@ function createDataGrid(){ else if (aData[0] == "b") $(nRow).attr("style", "background-color:#EE3B3B"); return nRow; - } + }, + "bAutoWidth":false } ); @@ -104,15 +104,23 @@ function getAJAXURL(){ return url; } -function updateData(){ +function updateDataTable(){ + var table = $('#nowplayingtable').dataTable(); + + table.fnClearTable(false); + table.fnAddData(datagridData.rows); + +} + +function getData(){ $.ajax({ url: getAJAXURL(), dataType:"json", success:function(data){ datagridData = data.entries; - createDataGrid(); + updateDataTable(); }}); } function init2(){ - updateData(); + getData(); if (typeof registerSongEndListener == 'function' && !registered){ registered = true; @@ -128,6 +136,8 @@ function redirect(url){ } $(document).ready(function() { + + createDataGrid(); if (viewType == "day"){ $('#now_view').click(function(){redirect('/Nowplaying/index')}); diff --git a/public/js/playlist/playlist.js b/public/js/playlist/playlist.js index de404356e..0c1dd227d 100644 --- a/public/js/playlist/playlist.js +++ b/public/js/playlist/playlist.js @@ -73,8 +73,6 @@ function nextShowStart(){ nextShowPrepare = true; currentShow[0] = nextShow.shift(); updatePlaybar(); - - //notifySongEndListener(); } /* Called every "uiUpdateInterval" mseconds. */ @@ -108,6 +106,9 @@ function updateProgressBarValue(){ if (nextSongs.length > 0 && nextSongPrepare){ var diff = nextSongs[0].songStartPosixTime - estimatedSchedulePosixTime; if (diff < serverUpdateInterval){ + + //sometimes the diff is negative (-100ms for example). Still looking + //into why this could sometimes happen. if (diff < 0) diff=0; @@ -195,22 +196,13 @@ function calcAdditionalShowData(show){ if (show.length > 0){ show[0].showStartPosixTime = convertDateToPosixTime(show[0].start_timestamp); show[0].showEndPosixTime = convertDateToPosixTime(show[0].end_timestamp); - - //hack to fix case where show end is next day, but we have it set - //as the same day. - if (show[0].showEndPosixTime - show[0].showStartPosixTime < 0) - show[0].showEndPosixTime += 1000*3600*24; - show[0].showLengthMs = show[0].showEndPosixTime - show[0].showStartPosixTime; } } function parseItems(obj){ APPLICATION_ENV = obj.env; - - var schedulePosixTime = convertDateToPosixTime(obj.schedulerTime); - schedulePosixTime += parseInt(obj.timezoneOffset)*1000; - + $('#time-zone').text(obj.timezone); previousSongs = obj.previous; @@ -227,10 +219,10 @@ function parseItems(obj){ calcAdditionalShowData(obj.currentShow); calcAdditionalShowData(obj.nextShow); - if (localRemoteTimeOffset == null){ - var date = new Date(); - localRemoteTimeOffset = date.getTime() - schedulePosixTime; - } + var schedulePosixTime = convertDateToPosixTime(obj.schedulerTime); + schedulePosixTime += parseInt(obj.timezoneOffset)*1000; + var date = new Date(); + localRemoteTimeOffset = date.getTime() - schedulePosixTime; }