-synchronize

This commit is contained in:
martin 2010-12-30 09:41:52 -05:00
parent 8404fa4145
commit ffa508de34
3 changed files with 148 additions and 140 deletions

View file

@ -178,6 +178,7 @@ class ScheduleController extends Zend_Controller_Action
public function getSchedulerTimeAction() public function getSchedulerTimeAction()
{ {
$this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript'); $this->view->headScript()->appendFile('/js/playlist/playlist.js','text/javascript');
$this->view->headScript()->appendFile('/js/progressbar/jquery.progressbar.min.js','text/javascript');
} }
public function getCurrentPlaylistAction() public function getCurrentPlaylistAction()

View file

@ -6,5 +6,5 @@
}); });
</script> </script>
<div id="list0"></div> <div id="list0"></div>
<div id="spaceused1"></div>
</div> </div>

View file

@ -1,16 +1,34 @@
(function($) { (function($) {
// jQuery plugin definition // jQuery plugin definition
$.fn.playlistViewer = function(params) { $.fn.playlistViewer = function(params) {
// merge default and user parameters var cc = this;
params = $.extend( {minlength: 0, maxlength: 99999}, params); cc.estimatedSchedulePosixTime = -1;
cc.schedulePosixTime;
cc.previousSongs;
cc.currentSong;
cc.nextSongs;
var $t; cc.currentElem;
// traverse all nodes // traverse all nodes
return this.each(function() { return this.each(function() {
// express a single node as a jQuery object // express a single node as a jQuery object
$t = $(this); cc.currentElem = $(this);
var prevDiv = document.createElement('div');
prevDiv.setAttribute("id", "previous");
$(cc.currentElem).append(prevDiv);
var currDiv = document.createElement('div');
currDiv.setAttribute("id", "current");
$(cc.currentElem).append(currDiv);
var nextDiv = document.createElement('div');
nextDiv.setAttribute("id", "next");
$(cc.currentElem).append(nextDiv);
$('#spaceused1').progressBar(0);
getScheduleFromServer(); getScheduleFromServer();
updateProgressBarValue(); updateProgressBarValue();
@ -34,33 +52,25 @@
return Date.UTC(year, month, day, hour, minute, sec, msec); return Date.UTC(year, month, day, hour, minute, sec, msec);
} }
var estimatedSchedulePosixTime = -1;
var schedulePosixTime;
var previousSongs;
var currentSong;
var nextSongs;
function secondsTimer(){ function secondsTimer(){
estimatedSchedulePosixTime += 1000; cc.estimatedSchedulePosixTime += 1000;
updateProgressBarValue(); updateProgressBarValue();
} }
function updateProgressBarValue(){ function updateProgressBarValue(){
alert(estimatedSchedulePosixTime); if (cc.estimatedSchedulePosixTime != -1){
if (estimatedSchedulePosixTime != -1){ if (cc.currentSong.length > 0){
if (currentSong.length > 0){ var percentDone = (cc.estimatedSchedulePosixTime - cc.currentSong[0].songStartPosixTime)/cc.currentSong[0].songLengthMs*100;
var percentDone = (estimatedSchedulePosixTime - currentSong[0].songStartPosixTime)/currentSong[0].songLengthMs*100;
if (percentDone <= 100){ if (percentDone <= 100){
//$('#spaceused1').progressBar(percentDone); $('#spaceused1').progressBar(percentDone);
} else { } else {
if (nextSongs.length > 0){ if (nextSongs.length > 0){
currentSong[0] = nextSongs.shift(); cc.currentSong[0] = cc.nextSongs.shift();
} else { } else {
currentSong = new Array(); cc.currentSong = new Array();
} }
//$('#spaceused1').progressBar(0); $('#spaceused1').progressBar(0);
estimatedSchedulePosixTime = schedulePosixTime; cc.estimatedSchedulePosixTime = cc.schedulePosixTime;
} }
} }
updatePlaylist(); updatePlaylist();
@ -79,23 +89,23 @@
$('#previous').empty(); $('#previous').empty();
$('#current').empty(); $('#current').empty();
$('#next').empty(); $('#next').empty();
for (var i=0; i<previousSongs.length; i++){ for (var i=0; i<cc.previousSongs.length; i++){
//var divElem = document.createElement('div'); var divElem = document.createElement('div');
//divElem.innerHTML = createPlaylistElementString(previousSongs[i]); divElem.innerHTML = createPlaylistElementString(cc.previousSongs[i]);
$t.text(createPlaylistElementString(previousSongs[i])); $('#previous').append(divElem);
//$('#previous').append(divElem); //cc.currentElem.html(createPlaylistElementString(previousSongs[i]));
} }
for (var i=0; i<currentSong.length; i++){ for (var i=0; i<cc.currentSong.length; i++){
//var divElem = document.createElement('div'); var divElem = document.createElement('div');
//divElem.innerHTML = createPlaylistElementString(currentSong[i]); divElem.innerHTML = createPlaylistElementString(cc.currentSong[i]);
//$('#current').append(divElem); $('#current').append(divElem);
$t.text(createPlaylistElementString(currentSong[i])); //cc.currentElem.html(createPlaylistElementString(currentSong[i]));
} }
for (var i=0; i<nextSongs.length; i++){ for (var i=0; i<cc.nextSongs.length; i++){
//var divElem = document.createElement('div'); var divElem = document.createElement('div');
//divElem.innerHTML = createPlaylistElementString(nextSongs[i]); divElem.innerHTML = createPlaylistElementString(cc.nextSongs[i]);
//$('#next').append(divElem); $('#next').append(divElem);
$t.text(createPlaylistElementString(nextSongs[i])); //cc.currentElem.html(createPlaylistElementString(nextSongs[i]));
} }
} }
@ -114,21 +124,18 @@
} }
function parseItems(obj){ function parseItems(obj){
schedulePosixTime = convertDateToPosixTime(obj.schedulerTime); cc.schedulePosixTime = convertDateToPosixTime(obj.schedulerTime);
if (estimatedSchedulePosixTime == -1) if (cc.estimatedSchedulePosixTime == -1)
estimatedSchedulePosixTime = schedulePosixTime; cc.estimatedSchedulePosixTime = cc.schedulePosixTime;
previousSongs = obj.previous; cc.previousSongs = obj.previous;
currentSong = obj.current; cc.currentSong = obj.current;
nextSongs = obj.next; cc.nextSongs = obj.next;
calcAdditionalData(previousSongs); calcAdditionalData(cc.previousSongs);
calcAdditionalData(currentSong); calcAdditionalData(cc.currentSong);
calcAdditionalData(nextSongs); calcAdditionalData(cc.nextSongs);
//updatePlaylist();
//updateProgressBarValue();
} }
function getScheduleFromServer(){ function getScheduleFromServer(){