| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TDataListItemRenderer class file
|
|
|
4 |
*
|
|
|
5 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TDataListItemRenderer.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
10 |
* @package System.Web.UI.WebControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
Prado::using('System.Web.UI.WebControls.TDataList');
|
|
|
14 |
Prado::using('System.Web.UI.WebControls.TItemDataRenderer');
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* TDataListItemRenderer class
|
|
|
18 |
*
|
|
|
19 |
* TDataListItemRenderer can be used as a convenient base class to
|
|
|
20 |
* define an item renderer class specific for {@link TDataList}.
|
|
|
21 |
*
|
|
|
22 |
* TDataListItemRenderer extends {@link TItemDataRenderer} and implements
|
|
|
23 |
* the bubbling scheme for the OnCommand event of data list items.
|
|
|
24 |
*
|
|
|
25 |
* TDataListItemRenderer also implements the {@link IStyleable} interface,
|
|
|
26 |
* which allows TDataList to apply CSS styles to the renders.
|
|
|
27 |
*
|
|
|
28 |
* @author Qiang Xue <qiang.xue@gmail.com>
|
|
|
29 |
* @version $Id: TDataListItemRenderer.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
30 |
* @package System.Web.UI.WebControls
|
|
|
31 |
* @since 3.1.0
|
|
|
32 |
*/
|
|
|
33 |
class TDataListItemRenderer extends TItemDataRenderer implements IStyleable
|
|
|
34 |
{
|
|
|
35 |
/**
|
|
|
36 |
* Creates a style object to be used by the control.
|
|
|
37 |
* This method may be overriden by controls to provide customized style.
|
|
|
38 |
* @return TStyle
|
|
|
39 |
*/
|
|
|
40 |
protected function createStyle()
|
|
|
41 |
{
|
|
|
42 |
return new TTableItemStyle;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* @return boolean whether the control has defined any style information
|
|
|
47 |
*/
|
|
|
48 |
public function getHasStyle()
|
|
|
49 |
{
|
|
|
50 |
return $this->getViewState('Style',null)!==null;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* @return TStyle the object representing the css style of the control
|
|
|
55 |
*/
|
|
|
56 |
public function getStyle()
|
|
|
57 |
{
|
|
|
58 |
if($style=$this->getViewState('Style',null))
|
|
|
59 |
return $style;
|
|
|
60 |
else
|
|
|
61 |
{
|
|
|
62 |
$style=$this->createStyle();
|
|
|
63 |
$this->setViewState('Style',$style,null);
|
|
|
64 |
return $style;
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* Removes all style data.
|
|
|
70 |
*/
|
|
|
71 |
public function clearStyle()
|
|
|
72 |
{
|
|
|
73 |
$this->clearViewState('Style');
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
* This method overrides parent's implementation by wrapping event parameter
|
|
|
78 |
* for <b>OnCommand</b> event with item information.
|
|
|
79 |
* @param TControl the sender of the event
|
|
|
80 |
* @param TEventParameter event parameter
|
|
|
81 |
* @return boolean whether the event bubbling should stop here.
|
|
|
82 |
*/
|
|
|
83 |
public function bubbleEvent($sender,$param)
|
|
|
84 |
{
|
|
|
85 |
if($param instanceof TCommandEventParameter)
|
|
|
86 |
{
|
|
|
87 |
$this->raiseBubbleEvent($this,new TDataListCommandEventParameter($this,$sender,$param));
|
|
|
88 |
return true;
|
|
|
89 |
}
|
|
|
90 |
else
|
|
|
91 |
return false;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Returns the tag name used for this control.
|
|
|
96 |
* By default, the tag name is 'span'.
|
|
|
97 |
* You can override this method to provide customized tag names.
|
|
|
98 |
* If the tag name is empty, the opening and closing tag will NOT be rendered.
|
|
|
99 |
* @return string tag name of the control to be rendered
|
|
|
100 |
*/
|
|
|
101 |
protected function getTagName()
|
|
|
102 |
{
|
|
|
103 |
return 'span';
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
/**
|
|
|
107 |
* Adds attribute name-value pairs to renderer.
|
|
|
108 |
* By default, this method renders the style string.
|
|
|
109 |
* The method can be overriden to provide customized attribute rendering.
|
|
|
110 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
111 |
*/
|
|
|
112 |
protected function addAttributesToRender($writer)
|
|
|
113 |
{
|
|
|
114 |
if($style=$this->getViewState('Style',null))
|
|
|
115 |
$style->addAttributesToRender($writer);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
/**
|
|
|
119 |
* Renders the control.
|
|
|
120 |
* This method overrides the parent implementation by replacing it with
|
|
|
121 |
* the following sequence:
|
|
|
122 |
* - {@link renderBeginTag}
|
|
|
123 |
* - {@link renderContents}
|
|
|
124 |
* - {@link renderEndTag}
|
|
|
125 |
* If the {@link getTagName TagName} is empty, only {@link renderContents} is invoked.
|
|
|
126 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
127 |
*/
|
|
|
128 |
public function render($writer)
|
|
|
129 |
{
|
|
|
130 |
if($this->getTagName()!=='')
|
|
|
131 |
{
|
|
|
132 |
$this->renderBeginTag($writer);
|
|
|
133 |
$this->renderContents($writer);
|
|
|
134 |
$this->renderEndTag($writer);
|
|
|
135 |
}
|
|
|
136 |
else
|
|
|
137 |
$this->renderContents($writer);
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
/**
|
|
|
141 |
* Renders the openning tag for the control (including attributes)
|
|
|
142 |
* This method is invoked when {@link getTagName TagName} is not empty.
|
|
|
143 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
144 |
*/
|
|
|
145 |
public function renderBeginTag($writer)
|
|
|
146 |
{
|
|
|
147 |
$this->addAttributesToRender($writer);
|
|
|
148 |
$writer->renderBeginTag($this->getTagName());
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
/**
|
|
|
152 |
* Renders the body content enclosed between the control tag.
|
|
|
153 |
* By default, child controls and text strings will be rendered.
|
|
|
154 |
* You can override this method to provide customized content rendering.
|
|
|
155 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
156 |
*/
|
|
|
157 |
public function renderContents($writer)
|
|
|
158 |
{
|
|
|
159 |
parent::renderChildren($writer);
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
/**
|
|
|
163 |
* Renders the closing tag for the control
|
|
|
164 |
* This method is invoked when {@link getTagName TagName} is not empty.
|
|
|
165 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
166 |
*/
|
|
|
167 |
public function renderEndTag($writer)
|
|
|
168 |
{
|
|
|
169 |
$writer->renderEndTag();
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
|