]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TActivePanel.php
baculum: Update PRADO framework from v3.2.3 to v3.2.4
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TActivePanel.php
1 <?php
2 /**
3  * TActivePanel file.
4  *
5  * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6  * @link http://www.pradosoft.com/
7  * @copyright Copyright &copy; 2005-2014 PradoSoft
8  * @license http://www.pradosoft.com/license/
9  * @package System.Web.UI.ActiveControls
10  */
11
12 /**
13  * Load active control adapter.
14  */
15 Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
16
17 /**
18  * TActivePanel is the TPanel active control counterpart.
19  *
20  * TActivePanel allows the client-side panel contents to be updated during a
21  * callback response using the {@link render} method.
22  *
23  * Example: Assume $param is an instance of TCallbackEventParameter attached to
24  * the OnCallback event of a TCallback with ID "callback1", and
25  * "panel1" is the ID of a TActivePanel.
26  * <code>
27  * function callback1_requested($sender, $param)
28  * {
29  *         $this->panel1->render($param->getNewWriter());
30  * }
31  * </code>
32  *
33  * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
34  * @package System.Web.UI.ActiveControls
35  * @since 3.1
36  */
37 class TActivePanel extends TPanel implements IActiveControl
38 {
39         /**
40          * Creates a new callback control, sets the adapter to
41          * TActiveControlAdapter. If you override this class, be sure to set the
42          * adapter appropriately by, for example, by calling this constructor.
43          */
44         public function __construct()
45         {
46                 parent::__construct();
47                 $this->setAdapter(new TActiveControlAdapter($this));
48         }
49
50         /**
51          * @return TBaseActiveControl standard active control options.
52          */
53         public function getActiveControl()
54         {
55                 return $this->getAdapter()->getBaseActiveControl();
56         }
57
58         /**
59          * Adds attribute id to the renderer.
60          * @param THtmlWriter the writer used for the rendering purpose
61          */
62         protected function addAttributesToRender($writer) {
63             $writer->addAttribute('id',$this->getClientID());
64             parent::addAttributesToRender($writer);
65         }
66
67         /**
68          * Renders and replaces the panel's content on the client-side.
69          * When render() is called before the OnPreRender event, such as when render()
70          * is called during a callback event handler, the rendering
71          * is defered until OnPreRender event is raised.
72          * @param THtmlWriter html writer
73          */
74         public function render($writer)
75         {
76                 if($this->getHasPreRendered())
77                 {
78                         parent::render($writer);
79                         if($this->getActiveControl()->canUpdateClientSide())
80                                 $this->getPage()->getCallbackClient()->replaceContent($this,$writer);
81                 }
82                 else
83                 {
84                         $this->getPage()->getAdapter()->registerControlToRender($this,$writer);
85                         if ($this->getHasControls())
86                         {
87                                 // If we update a TActivePanel on callback,
88                                 // We shouldn't update all childs, because the whole content will be replaced by
89                                 // the parent
90                                 foreach ($this->findControlsByType('IActiveControl', false) as $control)
91                                 {
92                                                 $control->getActiveControl()->setEnableUpdate(false);
93                                 }
94                         }
95                 }
96         }
97 }
98