convert judges scheduler status AJAX to JQuery

This commit is contained in:
james 2010-02-18 15:54:31 +00:00
parent 8e650a104d
commit 1a2fc19fca

View File

@ -29,7 +29,6 @@ ogram; see the file COPYING. If not, write to
'Administration' => 'admin/index.php',
'Judges' => 'admin/judges.php')
);
require_once("../ajax.inc.php");
?>
<script type="text/javascript">
@ -41,46 +40,29 @@ var avgtimeperpercent=0;
var remainingpercent=0;
var remainingtime=0;
function updateStatus()
{
document.getElementById('updatestatus').innerHTML="Updating...";
$(document).ready(function() {
updateStatus();
});
function updateStatus() {
var url="judges_scheduler_status_output.php";
http.open("GET",url,true);
http.readystate=0;
http.onreadystatechange=handleResponse;
http.send(null);
}
function clearUpdatingMessage()
{
document.getElementById('updatestatus').innerHTML="Waiting...";
}
function handleResponse()
{
try {
if(http.readyState==4)
{
var obj=http.responseText.split(":");
document.getElementById('schedulerstatus').innerHTML=obj[1];
if(obj[0]=="-1")
{
document.getElementById('schedulerpercent').innerHTML="100%";
document.getElementById('updatestatus').innerHTML="Scheduling Complete";
document.getElementById('schedulereta').innerHTML="Complete";
$("#updatestatus").html("Updating...");
$.get(url,null,function(data) {
var obj=data.split(":");
$("#schedulerstatus").html(obj[1]);
if(obj[0]=="-1") {
$("#schedulerpercent").html("100%");
$("#updatestatus").html("Scheduling Complete");
$("#schedulereta").html("Complete");
}
else
{
document.getElementById('schedulerpercent').innerHTML=obj[0]+"%";
else {
$("#schedulerpercent").html(obj[0]+"%");
setTimeout('updateStatus()',5000);
document.getElementById('updatestatus').innerHTML="Updating... Done!";
$("#updatestatus").html("Updating... Done!");
setTimeout('clearUpdatingMessage()',500);
var currentTime=new Date();
if(starttime==0)
{
if(starttime==0) {
starttime=currentTime.getTime();
startpercent=obj[0];
}
@ -91,32 +73,61 @@ function handleResponse()
remainingpercent=100-obj[0];
remainingtime=remainingpercent*avgtimeperpercent;
if(remainingtime && obj[0]>0)
document.getElementById('schedulereta').innerHTML=Math.round(remainingtime/1000)+" seconds";
$("#schedulereta").html(format_duration(Math.round(remainingtime/1000)));
else
document.getElementById('schedulereta').innerHTML="Calculating...";
$("#schedulereta").html("Calculating...");
}
}
}
catch(e)
{
alert('caught error'+e);
}
});
}
function clearUpdatingMessage() {
$("#updatestatus").html("Waiting...");
}
function format_duration(seconds) {
/*
'1 year|:count years' => 31536000,
'1 week|:count weeks' => 604800,
'1 day|:count days' => 86400,
'1 hour|:count hours' => 3600,
'1 min|:count min' => 60,
'1 sec|:count sec' => 1);
*/
var s=seconds;
var output=s+':';
if(s>86400) {
var days=Math.floor(s/86400)
s-=days*86400;
output+=days+' days ';
}
if(s>3600) {
var hours=Math.floor(s/3600)
s-=hours*3600;
output+=hours+' hours ';
}
if(s>60) {
var minutes=Math.floor(s/60)
s-=minutes*60;
output+=minutes+' minutes ';
}
output+=s+' seconds ';
return output;
}
</script>
<?
if($config['judge_scheduler_percent']=="-1")
{
if($config['judge_scheduler_percent']=="-1") {
echo i18n("The judge scheduler is not currently running");
echo "<br />";
echo "<br />";
echo "<a href=\"judges_schedulerconfig.php\">".i18n("Judges Scheduler Configuration")."</a>";
}
else
{
else {
echo "<table>";
echo "<tr><td>".i18n("Scheduler status").":</td><td><div id=\"schedulerstatus\" style=\"font-weight: bold;\"></div></td></tr>";
echo "<tr><td>".i18n("Scheduler percent").":</td><td><div id=\"schedulerpercent\" style=\"font-weight: bold;\"></div></td></tr>";
@ -134,10 +145,6 @@ echo "<br />";
echo "<a href=\"reports.php\">".i18n("Print/Export Reports")."</a>";
echo "<br />";
echo "<br />";
P
?>
<script type="text/javascript">updateStatus()</script>
<?
}
send_footer();