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