1: <?php
 2: /**
 3:  * CJuiProgressBar class file.
 4:  *
 5:  * @author Sebastian Thierer <sebathi@gmail.com>
 6:  * @link http://www.yiiframework.com/
 7:  * @copyright 2008-2013 Yii Software LLC
 8:  * @license http://www.yiiframework.com/license/
 9:  */
10: 
11: Yii::import('zii.widgets.jui.CJuiWidget');
12: 
13: /**
14:  * CJuiProgressBar displays a progress bar widget.
15:  *
16:  * CJuiProgressBar encapsulates the {@link http://jqueryui.com/progressbar/ JUI
17:  * Progressbar} plugin.
18:  *
19:  * To use this widget, you may insert the following code in a view:
20:  * <pre>
21:  * $this->widget('zii.widgets.jui.CJuiProgressBar',array(
22:  *     'value'=>75,
23:  *     // additional javascript options for the progress bar plugin
24:  *     'options'=>array(
25:  *         'change'=>new CJavaScriptExpression('function(event, ui) {...}'),
26:  *     ),
27:  *     'htmlOptions'=>array(
28:  *         'style'=>'height:20px;',
29:  *     ),
30:  * ));
31:  * </pre>
32:  *
33:  * By configuring the {@link options} property, you may specify the options
34:  * that need to be passed to the JUI progressbar plugin. Please refer to
35:  * the {@link http://api.jqueryui.com/progressbar/ JUI ProgressBar} documentation
36:  * for possible options (name-value pairs) and
37:  * {@link http://jqueryui.com/progressbar/ JUI ProgressBar page} for general
38:  * description and demo.
39:  *
40:  * @author Sebastian Thierer <sebathi@gmail.com>
41:  * @package zii.widgets.jui
42:  * @since 1.1
43:  */
44: class CJuiProgressBar extends CJuiWidget
45: {
46:     /**
47:      * @var string the name of the container element that contains the progress bar. Defaults to 'div'.
48:      */
49:     public $tagName='div';
50:     /**
51:      * @var integer the percentage of the progress. This must be an integer between 0 and 100. Defaults to 0.
52:      */
53:     public $value=0;
54: 
55:     /**
56:      * Run this widget.
57:      * This method registers necessary javascript and renders the needed HTML code.
58:      */
59:     public function run()
60:     {
61:         $id=$this->getId();
62:         if(isset($this->htmlOptions['id']))
63:             $id=$this->htmlOptions['id'];
64:         else
65:             $this->htmlOptions['id']=$id;
66: 
67:         echo CHtml::openTag($this->tagName,$this->htmlOptions);
68:         echo CHtml::closeTag($this->tagName);
69: 
70:         $this->options['value']=$this->value;
71:         $options=CJavaScript::encode($this->options);
72:         Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').progressbar($options);");
73:     }
74: }