3 * TActiveTableRow and TActiveTableRowEventParameter class file
5 * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
6 * @link http://www.landwehr-software.de/
7 * @copyright Copyright © 2009 LANDWEHR Computer und Software GmbH
8 * @license http://www.pradosoft.com/license/
9 * @package System.Web.UI.ActiveControls
14 * Includes the following used classes
16 Prado::using('System.Web.UI.WebControls.TTableRow');
17 Prado::using('System.Web.UI.ActiveControls.TActiveControlAdapter');
18 Prado::using('System.Web.UI.ActiveControls.TCallbackEventParameter');
21 * TActiveTableRow class.
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.
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.
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.
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.
40 * function callback_request($sender, $param)
42 * $this->active_row->render($param->getNewWriter());
46 * Please refer to the original documentation of the regular counterpart for usage.
48 * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
49 * @package System.Web.UI.ActiveControls
53 class TActiveTableRow extends TTableRow implements ICallbackEventHandler, IActiveControl
57 * @var TTable parent table control containing the row
62 * Creates a new callback control, sets the adapter to TActiveControlAdapter.
64 public function __construct()
66 parent::__construct();
67 $this->setAdapter(new TActiveControlAdapter($this));
71 * @return TBaseActiveCallbackControl standard callback control options.
73 public function getActiveControl()
75 return $this->getAdapter()->getBaseActiveControl();
79 * @return TCallbackClientSide client side request options.
81 public function getClientSide()
83 return $this->getAdapter()->getBaseActiveControl()->getClientSide();
87 * @return string corresponding javascript class name for this TActiveTableRow.
89 protected function getClientClassName()
91 return 'Prado.WebUI.TActiveTableRow';
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
99 * This method is mainly used by framework and control developers.
100 * @param TCallbackEventParameter the event parameter
102 public function raiseCallbackEvent($param)
104 $parameter = new TActiveTableRowEventParameter($this->getResponse(), $param->getCallbackParameter(), $this->getRowIndex());
105 $this->onRowSelected($parameter);
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.
116 public function bubbleEvent($sender, $param)
118 if ($param instanceof TActiveTableCellEventParameter)
120 $this->raiseCallbackEvent($param);
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
133 public function onRowSelected($param)
135 $this->raiseEvent('OnRowSelected', $this, $param);
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
144 protected function addAttributesToRender($writer)
146 parent::addAttributesToRender($writer);
147 $writer->addAttribute('id', $this->getClientID());
148 if ($this->hasEventHandler('OnRowSelected'))
149 $this->getActiveControl()->registerCallbackClientScript($this->getClientClassName(), $this->getPostBackOptions());
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
157 * @param THtmlWriter html writer
159 public function render($writer)
161 if ($this->getHasPreRendered())
163 parent::render($writer);
164 if ($this->getActiveControl()->canUpdateClientSide())
165 $this->getPage()->getCallbackClient()->replaceContent($this, $writer);
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())
174 foreach ($this->findControlsByType('IActiveControl', false) as $control)
175 $control->getActiveControl()->setEnableUpdate(false);
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.
185 protected function getPostBackOptions()
187 $options['ID'] = $this->getClientID();
188 $options['EventTarget'] = $this->getUniqueID();
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
198 public function getRowIndex()
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());
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
210 public function getTable()
212 if ($this->_table === null)
214 $table = $this->getParent();
215 while (!($table instanceof TTable) && $table !== null)
217 $table = $table->getParent();
219 if ($table instanceof TTable) $this->_table = $table;
220 else throw new TConfigurationException('tactivetablerow_control_outoftable', get_class($this), $this->getUniqueID());
222 return $this->_table;
228 * TActiveTableRowEventParameter class.
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.
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).
240 * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
241 * @package System.Web.UI.ActiveControls
244 class TActiveTableRowEventParameter extends TCallbackEventParameter
247 * @var integer the zero-based index of the row.
249 private $_selectedRowIndex = -1;
252 * Creates a new TActiveTableRowEventParameter.
254 public function __construct($response, $parameter, $index=-1)
256 parent::__construct($response, $parameter);
257 $this->_selectedRowIndex = $index;
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.
265 public function getSelectedRowIndex()
267 return $this->_selectedRowIndex;