CJuiDialog.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * CJuiDialog 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. * CJuiDialog displays a dialog widget.
  13. *
  14. * CJuiDialog encapsulates the {@link http://jqueryui.com/dialog/ JUI Dialog}
  15. * plugin.
  16. *
  17. * To use this widget, you may insert the following code in a view:
  18. * <pre>
  19. * $this->beginWidget('zii.widgets.jui.CJuiDialog',array(
  20. * 'id'=>'mydialog',
  21. * // additional javascript options for the dialog plugin
  22. * 'options'=>array(
  23. * 'title'=>'Dialog box 1',
  24. * 'autoOpen'=>false,
  25. * ),
  26. * ));
  27. *
  28. * echo 'dialog content here';
  29. *
  30. * $this->endWidget('zii.widgets.jui.CJuiDialog');
  31. *
  32. * // the link that may open the dialog
  33. * echo CHtml::link('open dialog', '#', array(
  34. * 'onclick'=>'$("#mydialog").dialog("open"); return false;',
  35. * ));
  36. * </pre>
  37. *
  38. * By configuring the {@link options} property, you may specify the options
  39. * that need to be passed to the JUI dialog plugin. Please refer to
  40. * the {@link http://api.jqueryui.com/dialog/ JUI Dialog API} documentation
  41. * for possible options (name-value pairs) and
  42. * {@link http://jqueryui.com/dialog/ JUI Dialog page} for general description
  43. * and demo.
  44. *
  45. * @author Sebastian Thierer <sebathi@gmail.com>
  46. * @package zii.widgets.jui
  47. * @since 1.1
  48. */
  49. class CJuiDialog extends CJuiWidget
  50. {
  51. /**
  52. * @var string the name of the container element that contains all panels. Defaults to 'div'.
  53. */
  54. public $tagName='div';
  55. /**
  56. * Renders the open tag of the dialog.
  57. * This method also registers the necessary javascript code.
  58. */
  59. public function init()
  60. {
  61. parent::init();
  62. $id=$this->getId();
  63. if(isset($this->htmlOptions['id']))
  64. $id=$this->htmlOptions['id'];
  65. else
  66. $this->htmlOptions['id']=$id;
  67. $options=CJavaScript::encode($this->options);
  68. Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').dialog($options);");
  69. echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
  70. }
  71. /**
  72. * Renders the close tag of the dialog.
  73. */
  74. public function run()
  75. {
  76. echo CHtml::closeTag($this->tagName);
  77. }
  78. }