]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/ActiveControls/TActiveTableRow.php
6beeb27e3e6cc1fc0fad2ba820d3c258a6dc10fb
[bacula/bacula] / gui / baculum / framework / Web / UI / ActiveControls / TActiveTableRow.php
1 <?php
2 /**
3  * TActiveTableRow and TActiveTableRowEventParameter class file
4  *
5  * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
6  * @link http://www.landwehr-software.de/
7  * @copyright Copyright &copy; 2009 LANDWEHR Computer und Software GmbH
8  * @license http://www.pradosoft.com/license/
9  * @package System.Web.UI.ActiveControls
10  * @version $Id$
11  */
12
13 /**
14  * Includes the following used classes
15  */
16 Prado::using('System.Web.UI.WebControls.TTableRow');
17 Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
18 Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter');
19
20 /**
21  * TActiveTableRow class.
22  *
23  * TActiveTableRow is the active counterpart to the original {@link TTableRow} control
24  * and displays a table row. The table cells in the row can be accessed
25  * via {@link getCells Cells}. The horizontal and vertical alignments of the row
26  * are specified via {@link setHorizontalAlign HorizontalAlign} and
27  * {@link setVerticalAlign VerticalAlign} properties, respectively.
28  *
29  * TActiveTableRow allows the contents of the table row to be changed during callback. When
30  * {@link onRowSelected RowSelected} property is set, selecting (clicking on) the row will
31  * perform a callback request causing {@link onRowSelected OnRowSelected} event to be fired.
32  *
33  * It will also respond to a bubbled {@link onCellSelected OnCellSelected} event of a
34  * {@link TActiveTableCell} child control and fire a {@link onRowSelected OnRowSelected} event.
35  *
36  * TActiveTableRow allows the client-side row contents to be updated during a
37  * callback response by getting a new writer, invoking the render method and flushing the
38  * output, similar to a {@link TActivePanel} control.
39  * <code>
40  * function callback_request($sender, $param)
41  * {
42  *     $this->active_row->render($param->getNewWriter());
43  * }
44  * </code>
45  *
46  * Please refer to the original documentation of the regular counterpart for usage.
47  *
48  * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
49  * @package System.Web.UI.ActiveControls
50  * @version $Id$
51  * @since 3.1.9
52  */
53 class TActiveTableRow extends TTableRow implements ICallbackEventHandler, IActiveControl
54 {
55
56         /**
57          * @var TTable parent table control containing the row
58          */
59         private $_table;
60
61         /**
62          * Creates a new callback control, sets the adapter to TActiveControlAdapter.
63          * */
64         public function __construct()
65         {
66                 parent::__construct();
67                 $this->setAdapter(new TActiveControlAdapter($this));
68         }
69
70         /**
71          * @return TBaseActiveCallbackControl standard callback control options.
72          */
73         public function getActiveControl()
74         {
75                 return $this->getAdapter()->getBaseActiveControl();
76         }
77
78         /**
79          * @return TCallbackClientSide client side request options.
80          */
81         public function getClientSide()
82         {
83                 return $this->getAdapter()->getBaseActiveControl()->getClientSide();
84         }
85
86         /**
87          * @return string corresponding javascript class name for this TActiveTableRow.
88          */
89         protected function getClientClassName()
90         {
91                 return 'Prado.WebUI.TActiveTableRow';
92         }
93
94         /**
95          * Raises the callback event. This method is required by {@link ICallbackEventHandler}
96          * interface. It will raise {@link onRowSelected OnRowSelected} event with a
97          * {@link TActiveTableRowEventParameter} containing the zero-based index of the
98          * TActiveTableRow.
99          * This method is mainly used by framework and control developers.
100          * @param TCallbackEventParameter the event parameter
101          */
102         public function raiseCallbackEvent($param)
103         {
104                 $parameter = new TActiveTableRowEventParameter($this->getResponse(), $param->getCallbackParameter(), $this->getRowIndex());
105                 $this->onRowSelected($parameter);
106         }
107
108         /**
109          * This method overrides parent's implementation and raises the control's
110          * callback event. This will fire the {@link onRowSelected OnRowSelected}
111          * event if an appropriate event handler is implemented.
112          * @param TControl the sender of the event
113          * @param TEventParameter event parameter
114          * @return boolean whether the event bubbling should stop here.
115          */
116         public function bubbleEvent($sender, $param)
117         {
118                 if ($param instanceof TActiveTableCellEventParameter)
119                 {
120                         $this->raiseCallbackEvent($param);
121                         return true;
122                 }
123                 else return false;
124         }
125
126         /**
127          * This method is invoked when a callback is requested. The method raises
128          * 'OnRowSelected' event to fire up the event handlers. If you override this
129          * method, be sure to call the parent implementation so that the event
130          * handler can be invoked.
131          * @param TActiveTableRowEventParameter event parameter to be passed to the event handlers
132          */
133         public function onRowSelected($param)
134         {
135                 $this->raiseEvent('OnRowSelected', $this, $param);
136         }
137
138         /**
139          * Ensure that the ID attribute is rendered and registers the javascript code
140          * for initializing the active control if the event handler for the
141          * {@link onRowSelected OnRowSelected} event is set.
142          * @param THtmlWriter the writer responsible for rendering
143          */
144         protected function addAttributesToRender($writer)
145         {
146                 parent::addAttributesToRender($writer);
147                 $writer->addAttribute('id', $this->getClientID());
148                 if ($this->hasEventHandler('OnRowSelected'))
149                         $this->getActiveControl()->registerCallbackClientScript($this->getClientClassName(), $this->getPostBackOptions());
150         }
151
152         /**
153          * Renders and replaces the row's content on the client-side. When render() is
154          * called before the OnPreRender event, such as when render() is called during
155          * a callback event handler, the rendering is defered until OnPreRender event
156          * is raised.
157          * @param THtmlWriter html writer
158          */
159         public function render($writer)
160         {
161                 if ($this->getHasPreRendered())
162                 {
163                         parent::render($writer);
164                         if ($this->getActiveControl()->canUpdateClientSide())
165                                 $this->getPage()->getCallbackClient()->replaceContent($this, $writer);
166                 }
167                 else
168                 {
169                         $this->getPage()->getAdapter()->registerControlToRender($this, $writer);
170                         // If we update a TActiveTableRow on callback, we shouldn't update all childs,
171                         // because the whole content will be replaced by the parent.
172                         if ($this->getHasControls())
173                         {
174                                 foreach ($this->findControlsByType('IActiveControl', false) as $control)
175                                         $control->getActiveControl()->setEnableUpdate(false);
176                         }
177                 }
178         }
179
180         /**
181          * Returns postback specifications for the table row.
182          * This method is used by framework and control developers.
183          * @return array parameters about how the row defines its postback behavior.
184          */
185         protected function getPostBackOptions()
186         {
187                 $options['ID'] = $this->getClientID();
188                 $options['EventTarget'] = $this->getUniqueID();
189                 return $options;
190         }
191
192         /**
193          * Returns the zero-based index of the TActiveTableRow within the {@link TTableRowCollection}
194          * of the parent {@link TTable} control. Raises a {@link TConfigurationException} if the row
195          * is no member of the row collection.
196          * @return integer the zero-based index of the row
197          */
198         public function getRowIndex()
199         {
200                 foreach ($this->getTable()->getRows() as $key => $row)
201                         if ($row == $this) return $key;
202                 throw new TConfigurationException('tactivetablerow_control_notincollection', get_class($this), $this->getUniqueID());
203         }
204
205         /**
206          * Returns the parent {@link TTable} control by looping through all parents until a {@link TTable}
207          * is found. Raises a {@link TConfigurationException} if no table control is found.
208          * @return TTable the parent table control
209          */
210         public function getTable()
211         {
212                 if ($this->_table === null)
213                 {
214                         $table = $this->getParent();
215                         while (!($table instanceof TTable) && $table !== null)
216                         {
217                                 $table = $table->getParent();
218                         }
219                         if ($table instanceof TTable) $this->_table = $table;
220                         else throw new TConfigurationException('tactivetablerow_control_outoftable', get_class($this), $this->getUniqueID());
221                 }
222                 return $this->_table;
223         }
224
225 }
226
227 /**
228  * TActiveTableRowEventParameter class.
229  *
230  * The TActiveTableRowEventParameter provides the parameter passed during the callback
231  * requestion in the {@link getCallbackParameter CallbackParameter} property. The
232  * callback response content (e.g. new HTML content) must be rendered
233  * using an THtmlWriter obtained from the {@link getNewWriter NewWriter}
234  * property, which returns a <b>NEW</b> instance of TCallbackResponseWriter.
235  *
236  * The {@link getSelectedRowIndex SelectedRowIndex} is a zero-based index of the
237  * TActiveTableRow , -1 if the row is not part of the row collection (this shouldn't
238  * happen though since an exception is thrown before).
239  *
240  * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
241  * @package System.Web.UI.ActiveControls
242  * @since 3.1.9
243  */
244 class TActiveTableRowEventParameter extends TCallbackEventParameter
245 {
246         /**
247         * @var integer the zero-based index of the row.
248         */
249         private $_selectedRowIndex = -1;
250
251         /**
252          * Creates a new TActiveTableRowEventParameter.
253          */
254         public function __construct($response, $parameter, $index=-1)
255         {
256                 parent::__construct($response, $parameter);
257                 $this->_selectedRowIndex = $index;
258         }
259
260         /**
261          * Returns the zero-based index of the {@link TActiveTableRow} within the
262          * {@link TTableRowCollection} of the parent {@link TTable} control.
263          * @return integer the zero-based index of the row.
264          */
265         public function getSelectedRowIndex()
266         {
267                 return $this->_selectedRowIndex;
268         }
269
270 }