CJuiProgressBar.php 2.2 KB

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