Examples TOCexamples

Indeterminate Monitor

$Date: 2005/07/25 12:15:50 $

 Table of contents

Introduction

This example requires :

Be aware that:


This example will run a simple ProgressBar Monitor, with a function user callback. Its starts in indeterminate mode then switch back in determinate mode.

Color scheme came from a UI pre-set model (class) called Progress_ITDynamic, defined on lines 14 to 25.

The user callback defined on lines 27 to 47, and attached on progress bar at line 54, will run progress bar until its reached 60 then switch back to determinate mode to complete process. All 10%, we will echo result on monitor.

QF renderer rules are defined on lines 91 to 103.

[Top]

 Render options

Here are the progress attributes:
background-color = #EEE
HTML_Progress_UI::setProgressAttributes()
Here are the progress string attributes:
color            = navy
background-color = #EEE
HTML_Progress_UI::setStringAttributes()
Here are the progress cells attributes:
inactive-color = #FFF
active-color   = #444444
HTML_Progress_UI::setCellAttributes()

[Top]

 Output

Screenshot

[Top]

 PHP source syntax highlight

  1. <?php
  2. /**
  3.  * Monitor example with a new form template and progress bar
  4.  * color scheme. Used a function as user callback.
  5.  *
  6.  * @version    $Id: function_callback.php,v 1.2 2005/07/25 12:15:50 farell Exp $
  7.  * @author     Laurent Laville <pear@laurent-laville.org>
  8.  * @package    HTML_Progress
  9.  * @subpackage Examples
  10.  */
  11.  
  12. require_once 'HTML/Progress/monitor.php';
  13.  
  14. class Progress_ITDynamic extends HTML_Progress_UI
  15. {
  16.     function Progress_ITDynamic()
  17.     {
  18.         parent::HTML_Progress_UI();
  19.  
  20.         $this->setCellCount(20);
  21.         $this->setProgressAttributes('background-color=#EEE');
  22.         $this->setStringAttributes('background-color=#EEE color=navy');
  23.         $this->setCellAttributes('inactive-color=#FFF active-color=#444444');
  24.     }
  25. }
  26.  
  27. function myFunctionHandler($progressValue, &$bar)
  28. {
  29.     global $monitor;
  30.  
  31.     $bar->sleep();
  32.     if (!$bar->isIndeterminate()) {
  33.         if (fmod($progressValue,10) == 0) {
  34.             $monitor->setCaption("myFunctionHandler -> progress value is = $progressValue");
  35.         }
  36.     } else {
  37.         /* in case we have attached an indeterminate progress bar to the monitor ($obj)
  38.            after a first pass that reached 60%,
  39.            we swap from indeterminate mode to determinate mode
  40.            and run a standard progress bar from 0 to 100%
  41.         */
  42.         if ($progressValue == 60) {
  43.             $bar->setIndeterminate(false);
  44.             $bar->setString(null);           // show percent-info
  45.             $bar->setValue(0);
  46.         }
  47.     }
  48. }
  49.  
  50. $monitor = new HTML_Progress_Monitor('frmMonitor4', array(
  51.     'button' => array('style' => 'width:80px;')
  52.     )
  53. );
  54.  
  55. $progress = new HTML_Progress();
  56. $progress->setAnimSpeed(20);
  57. $progress->setUI('Progress_ITDynamic');// Attach a progress ui-model
  58. $progress->setStringPainted(true);     // get space for the string
  59. $progress->setString("");              // but don't paint it
  60. $progress->setIndeterminate(true);     // Progress start in indeterminate mode
  61. $progress->setProgressHandler('myFunctionHandler');
  62.  
  63. $monitor->setProgressElement($progress);
  64. ?>
  65. <html>
  66. <head>
  67. <title>ProgressBar Monitor - Default renderer </title>
  68. <style type="text/css">
  69. <!--
  70. body {
  71.     background-color: lightgrey;
  72.     font-family: Verdana, Arial;
  73. }
  74. .progressStatus {
  75.     color: navy;
  76.     font-size:10px;
  77. }
  78. <?php echo $monitor->getStyle(); ?>
  79. // -->
  80. </style>
  81. <script type="text/javascript">
  82. <!--
  83. <?php echo $monitor->getScript(); ?>
  84. //-->
  85. </script>
  86. </head>
  87. <body>
  88.  
  89.  
  90. <?php
  91. $renderer =& HTML_QuickForm::defaultRenderer();
  92. $renderer->setFormTemplate('
  93. <form{attributes}>
  94.  <table width="450" border="0" cellpadding="3" cellspacing="2" bgcolor="#EEEEEE">
  95.  {content}
  96.  </table>
  97. </form>
  98. ');
  99. $renderer->setHeaderTemplate('
  100.  <tr>
  101.    <td style="white-space:nowrap;background:#7B7B88;color:#ffc;" align="left" colspan="2"><b>{header}</b></td>
  102.  </tr>
  103. ');
  104. $monitor->accept($renderer);
  105.  
  106. echo $renderer->toHtml();
  107. $monitor->run();
  108. ?>
  109.  
  110. </body>
  111. </html>

[Top]