3 * TActiveTableCell 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 * TActiveTableCell class.
23 * TActiveTableCell is the active counterpart to the original {@link TTableCell} control
24 * and displays a table cell. The horizontal and vertical alignments of the cell
25 * are specified via {@link setHorizontalAlign HorizontalAlign} and
26 * {@link setVerticalAlign VerticalAlign} properties, respectively.
28 * TActiveTableCell allows the contents of the table cell to be changed during callback. When
29 * {@link onCellSelected CellSelected} property is set, selecting (clicking on) the cell will
30 * perform a callback request causing {@link onCellSelected OnCellSelected} event to be fired.
32 * It will also bubble the {@link onCellSelected OnCellSelected} event up to it's parent
33 * {@link TActiveTableRow} control which will fire up the event handlers if implemented.
35 * TActiveTableCell allows the client-side cell contents to be updated during a
36 * callback response by getting a new writer, invoking the render method and flushing the
37 * output, similar to a {@link TActivePanel} control.
39 * function callback_request($sender, $param)
41 * $this->active_cell->render($param->getNewWriter());
45 * Please refer to the original documentation of the regular counterpart for usage.
47 * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
48 * @package System.Web.UI.ActiveControls
52 class TActiveTableCell extends TTableCell implements ICallbackEventHandler, IActiveControl
56 * @var TTable parent row control containing the cell
61 * Creates a new callback control, sets the adapter to TActiveControlAdapter.
63 public function __construct()
65 parent::__construct();
66 $this->setAdapter(new TActiveControlAdapter($this));
70 * @return TBaseActiveCallbackControl standard callback control options.
72 public function getActiveControl()
74 return $this->getAdapter()->getBaseActiveControl();
78 * @return TCallbackClientSide client side request options.
80 public function getClientSide()
82 return $this->getAdapter()->getBaseActiveControl()->getClientSide();
86 * @return string corresponding javascript class name for this TActiveTableCell.
88 protected function getClientClassName()
90 return 'Prado.WebUI.TActiveTableCell';
94 * Raises the callback event. This method is required by {@link ICallbackEventHandler}
95 * interface. It will raise {@link onCellSelected OnCellSelected} event with a
96 * {@link TActiveTableCellEventParameter} containing the zero-based index of the
98 * This method is mainly used by framework and control developers.
99 * @param TCallbackEventParameter the event parameter
101 public function raiseCallbackEvent($param)
103 $parameter = new TActiveTableCellEventParameter($this->getResponse(), $param->getCallbackParameter(), $this->getCellIndex());
104 $this->onCellSelected($parameter);
105 $this->raiseBubbleEvent($this, $parameter);
109 * This method is invoked when a callback is requested. The method raises
110 * 'OnCellSelected' event to fire up the event handlers. If you override this
111 * method, be sure to call the parent implementation so that the event
112 * handler can be invoked.
113 * @param TActiveTableCellEventParameter event parameter to be passed to the event handlers
115 public function onCellSelected($param)
117 $this->raiseEvent('OnCellSelected', $this, $param);
121 * Ensure that the ID attribute is rendered and registers the javascript code
122 * for initializing the active control if the event handler for the
123 * {@link onCellSelected OnCellSelected} event is set.
124 * @param THtmlWriter the writer responsible for rendering
126 protected function addAttributesToRender($writer)
128 parent::addAttributesToRender($writer);
129 $writer->addAttribute('id', $this->getClientID());
130 if ($this->hasEventHandler('OnCellSelected'))
131 $this->getActiveControl()->registerCallbackClientScript($this->getClientClassName(), $this->getPostBackOptions());
135 * Renders and replaces the cell's content on the client-side. When render() is
136 * called before the OnPreRender event, such as when render() is called during
137 * a callback event handler, the rendering is defered until OnPreRender event
139 * @param THtmlWriter html writer
141 public function render($writer)
143 if ($this->getHasPreRendered())
145 parent::render($writer);
146 if ($this->getActiveControl()->canUpdateClientSide())
147 $this->getPage()->getCallbackClient()->replaceContent($this, $writer);
150 $this->getPage()->getAdapter()->registerControlToRender($this, $writer);
151 // If we update a TActiveTableCell on callback, we shouldn't update all childs,
152 // because the whole content will be replaced by the parent.
153 if ($this->getHasControls())
155 foreach ($this->findControlsByType('IActiveControl', false) as $control)
156 $control->getActiveControl()->setEnableUpdate(false);
162 * Returns postback specifications for the table cell.
163 * This method is used by framework and control developers.
164 * @return array parameters about how the row defines its postback behavior.
166 protected function getPostBackOptions()
168 $options['ID'] = $this->getClientID();
169 $options['EventTarget'] = $this->getUniqueID();
174 * Returns the zero-based index of the TActiveTableCell within the {@link TTableCellCollection}
175 * of the parent {@link TTableRow} control. Raises a {@link TConfigurationException} if the cell
176 * is no member of the cell collection.
177 * @return integer the zero-based index of the cell
179 public function getCellIndex()
181 foreach ($this->getRow()->getCells() as $key => $row)
182 if ($row == $this) return $key;
183 throw new TConfigurationException('tactivetablecell_control_notincollection', get_class($this), $this->getUniqueID());
187 * Returns the parent {@link TTableRow} control by looping through all parents until a {@link TTableRow}
188 * is found. Raises a {@link TConfigurationException} if no row control is found.
189 * @return TTableRow the parent row control
191 public function getRow()
193 if ($this->_row === null)
195 $row = $this->getParent();
196 while (!($row instanceof TTableRow) && $row !== null)
198 $row = $row->getParent();
200 if ($row instanceof TTableRow) $this->_row = $row;
201 else throw new TConfigurationException('tactivetablecell_control_outoftable', get_class($this), $this->getUniqueID());
209 * TActiveTableCellEventParameter class.
211 * The TActiveTableCellEventParameter provides the parameter passed during the callback
212 * requestion in the {@link getCallbackParameter CallbackParameter} property. The
213 * callback response content (e.g. new HTML content) must be rendered
214 * using an THtmlWriter obtained from the {@link getNewWriter NewWriter}
215 * property, which returns a <b>NEW</b> instance of TCallbackResponseWriter.
217 * The {@link getSelectedCellIndex SelectedCellIndex} is a zero-based index of the
218 * TActiveTableCell , -1 if the cell is not part of the cell collection (this shouldn't
219 * happen though since an exception is thrown before).
221 * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
222 * @package System.Web.UI.ActiveControls
225 class TActiveTableCellEventParameter extends TCallbackEventParameter
229 * @var integer the zero-based index of the cell.
231 private $_selectedCellIndex = -1;
234 * Creates a new TActiveTableRowEventParameter.
236 public function __construct($response, $parameter, $index=-1)
238 parent::__construct($response, $parameter);
239 $this->_selectedCellIndex = $index;
243 * Returns the zero-based index of the {@link TActiveTableCell} within the
244 * {@link TTableCellCollection} of the parent {@link TTableRow} control.
245 * @return integer the zero-based index of the cell.
247 public function getSelectedCellIndex()
249 return $this->_selectedCellIndex;