Examples TOCexamples

ITDynamic 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 class-method user callback, that simulate a picture file upload operation.

Color scheme came from a UI pre-set model (class) called Progress_ITDynamic, defined on lines 16 to 27, and attached on progress bar at line 66.

The user callback defined on lines 29 to 55, and attached on progress bar at line 68, will simulate a picture file upload operation at 10%, 45% and 70%.

[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 using ITDynamic QF renderer, and
  4.  * a class-method as user callback.
  5.  *
  6.  * @version    $Id: itdynamic.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. require_once 'HTML/QuickForm/Renderer/ITDynamic.php';
  14. require_once 'HTML/Template/ITX.php';
  15.  
  16. class Progress_ITDynamic extends HTML_Progress_UI
  17. {
  18.     function Progress_ITDynamic()
  19.     {
  20.         parent::HTML_Progress_UI();
  21.  
  22.         $this->setCellCount(20);
  23.         $this->setProgressAttributes('background-color=#EEE');
  24.         $this->setStringAttributes('background-color=#EEE color=navy');
  25.         $this->setCellAttributes('inactive-color=#FFF active-color=#444444');
  26.     }
  27. }
  28.  
  29. class my2ClassHandler
  30. {
  31.     function my1Method($progressValue, &$bar)
  32.     {
  33.         global $monitor;
  34.  
  35.         switch ($progressValue) {
  36.          case 10:
  37.             $pic = 'picture1.jpg';
  38.             break;
  39.          case 45:
  40.             $pic = 'picture2.jpg';
  41.             break;
  42.          case 70:
  43.             $pic = 'picture3.jpg';
  44.             break;
  45.          default:
  46.             $pic = null;
  47.         }
  48.         if (!is_null($pic)) {
  49.             $monitor->setCaption('upload <b>%file%</b> in progress ... Start at %percent%%',
  50.                                  array('file'=>$pic, 'percent'=>$progressValue)
  51.                                 );
  52.         }
  53.         $bar->sleep();  // slow animation because we do noting else
  54.     }
  55. }
  56. $obs = new my2ClassHandler();
  57.  
  58. $monitor = new HTML_Progress_Monitor('frmMonitor5', array(
  59.     'title'  => 'Upload your pictures',
  60.     'start'  => 'Upload',
  61.     'cancel' => 'Stop',
  62.     'button' => array('style' => 'width:80px;')
  63. ));
  64.  
  65. $progress = new HTML_Progress();
  66. $progress->setUI('Progress_ITDynamic');
  67. $progress->setAnimSpeed(50);
  68. $progress->setProgressHandler(array(&$obs, 'my1Method'));
  69.  
  70. $monitor->setProgressElement($progress);
  71.  
  72. $tpl =& new HTML_Template_ITX('../templates');
  73.  
  74. $tpl->loadTemplateFile('itdynamic_monitor.html');
  75.  
  76. $tpl->setVariable(array(
  77.     'qf_style'  => "body {font-family: Verdana, Arial; } \n" . $monitor->getStyle(),
  78.     'qf_script' => $monitor->getScript()
  79.     )
  80. );
  81.  
  82. $renderer =& new HTML_QuickForm_Renderer_ITDynamic($tpl);
  83. $renderer->setElementBlock(array(
  84.     'buttons'     => 'qf_buttons'
  85. ));
  86.  
  87. $monitor->accept($renderer);
  88.  
  89. // Display progress uploader dialog box
  90. $tpl->show();
  91.  
  92. $monitor->run();
  93.  
  94. ?>

[Top]