]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TActiveRepeater.php
08aeefabbc80e63a04338b6386253b1f1d64d036
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TActiveRepeater.php
1 <?php
2 /**
3  * TActiveRepeater class file
4  *
5  * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
6  * @package System.Web.UI.ActiveControls
7  * @since 3.1.9
8  */
9
10 /**
11  * TActiveRepeater class
12  *
13  * TActiveRepeater represents a data bound and updatable grid control which is the
14  * active counterpart to the original {@link TRepeater} control.
15  *
16  * This component can be used in the same way as the regular datagrid, the only
17  * difference is that the active repeater uses callbacks instead of postbacks
18  * for interaction.
19  *
20  * Please refer to the original documentation of the regular counterparts for usage.
21  *
22  * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
23  * @package System.Web.UI.ActiveControls
24  * @since 3.1.9
25  */
26 class TActiveRepeater extends TRepeater implements IActiveControl, ISurroundable {
27
28 /**
29  * Creates a new callback control, sets the adapter to
30  * TActiveControlAdapter.
31  */
32         public function __construct() {
33                 parent::__construct();
34                 $this->setAdapter(new TActiveControlAdapter($this));
35         }
36
37         /**
38          * @return TBaseActiveControl standard active control options.
39          */
40         public function getActiveControl() {
41                 return $this->getAdapter()->getBaseActiveControl();
42         }
43
44         /**
45          * Sets the data source object associated with the repeater control.
46          * In addition, the render method of all connected pagers is called so they
47          * get updated when the data source is changed. Also the repeater registers
48          * itself for rendering in order to get it's content replaced on client side.
49          * @param Traversable|array|string data source object
50          */
51         public function setDataSource($value) {
52                 parent::setDataSource($value);
53                 if($this->getActiveControl()->canUpdateClientSide()) {
54                         $this->renderPager();
55                         $this->getPage()->getAdapter()->registerControlToRender($this,$this->getResponse()->createHtmlWriter());
56                 }
57         }
58
59         /**
60          * Returns the id of the surrounding container (span).
61          * @return string container id
62          */
63         public function getSurroundingTagID() {
64                 return $this->ClientID.'_Container';
65         }
66
67         /**
68          * Renders the repeater.
69          * If the repeater did not pass the prerender phase yet, it will register itself for rendering later.
70          * Else it will call the {@link renderRepeater()} method which will do the rendering of the repeater.
71          * @param THtmlWriter writer for the rendering purpose
72          */
73         public function render($writer) {
74                 if($this->getHasPreRendered()) {
75                         $this->renderRepeater($writer);
76                         if($this->getActiveControl()->canUpdateClientSide()) $this->getPage()->getCallbackClient()->replaceContent($this->getSurroundingTagId(),$writer);
77                 }
78                 else {
79                         $this->getPage()->getAdapter()->registerControlToRender($this,$writer);
80                 }
81         }
82
83         /**
84          * Loops through all {@link TActivePager} on the page and registers the ones which are set to paginate
85          * the repeater for rendering. This is to ensure that the connected pagers are also rendered if the
86          * data source changed.
87          */
88         private function renderPager() {
89                 $pager=$this->getPage()->findControlsByType('TActivePager', false);
90                 foreach($pager as $item) {
91                         if($item->ControlToPaginate==$this->ID) {
92                                 $writer=$this->getResponse()->createHtmlWriter();
93                                 $this->getPage()->getAdapter()->registerControlToRender($item,$writer);
94                         }
95                 }
96         }
97
98         /**
99          * Renders the repeater by writing a span tag with the container id obtained from {@link getSurroundingTagID()}
100          * which will be called by the replacement method of the client script to update it's content.
101          * @param THtmlWriter writer for the rendering purpose
102          */
103         private function renderRepeater($writer) {
104                 $writer->addAttribute('id',$this->getSurroundingTagID());
105                 $writer->renderBeginTag('span');
106                 parent::render($writer);
107                 $writer->renderEndTag();
108         }
109
110 }
111