Drupal AHAH progress bar percentage response

The Drupal forms API 6.x has no good example and the book Pro Drupal Development from 2008 is not correct in the way the 'url' item should be set. Here is an example of Drupal AHAH progress bar with working percentage.

<?php
/**
 * menu hook
 *
 * @return unknown
 */
function my_admin_menu() {

   
$items = array();
 
 
$items['testingprogress/%'] = array(
     
'page callback' => 'testingprogress',
     
'page arguments' => array(1),
     
'access arguments' => array('access administration pages'),
     
'type' => MENU_CALLBACK,
  );
 
 
 
$items['my_checkstatus/status/%'] = array(
     
'page callback' => 'my_checkstatus',
     
'page arguments' => array(2),
     
'access arguments' => array('access administration pages'),
     
'type' => MENU_CALLBACK,
  );

  return
$items;
}


/**
 * Run rebuild utilisation DW
 *
 * @param unknown_type $form_state
 * @param unknown_type $form
 * @return unknown
 */
function my_admin_rebuild_utilisation_dw_form(){

   
   
$form = array();
   
   
$form['rebuild_utilisation_all'] = array(
       
'#value' => t('Rebuild Utilisation Data warehouse (ALL)'),
       
'#type' => 'submit',
       
'#weight' => 8,
       
'#attributes' => array('class' => "log-button"),
       
'#ahah' => array(
             
'event' => 'click',
             
'path' => 'testingprogress/all', //testingprogress
             
'wrapper' => 'my-testingprogress',
             
'effect' => 'fade',
             
'progress' => array(
                           
'type' => 'bar',
                           
'message' => t('Rebuilding...'),
                           
'interval' => 1,
                           
'url' => "/my_checkstatus/status/all",
                            ),

            ),
        
'#suffix' => '<div id="my-testingprogress">[Status area]</div>',   
    );
   

   
    return
$form;
}


function
testingprogress($arg = FALSE){
   
   
variable_set("checkstatus_".$arg, 5);
   
sleep(2);   
   
variable_set("checkstatus_".$arg, 40);
   
sleep(2);   
   
variable_set("checkstatus_".$arg, 60);
   
sleep(2);
   
variable_del("checkstatus_".$arg);
   
drupal_json(array('status' => TRUE, 'data' => "done"));

}

function
my_checkstatus($arg = ""){
   
$p = variable_get("checkstatus_".$arg, 0);
   
drupal_json(array('percentage' => $p));

}
?>
Knowledge keywords: