-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()
{
$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()

View file

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

View file

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