1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
<?php
/**
* TAccordion class file.
*
* @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
* @link http://www.pradosoft.com/
* @copyright Copyright © 2005-2014 PradoSoft
* @license http://www.pradosoft.com/license/
* @package Prado\Web\UI\WebControls
* @since 3.2
*/
namespace Prado\Web\UI\WebControls;
use Prado\TPropertyValue;
/**
* Class TAccordionView.
*
* TAccordionView represents a single view in a {@link TAccordion}.
*
* TAccordionView is represented inside the {@link TAccordion} with an header label whose text is defined by
* the {@link setCaption Caption} property; optionally the label can be an hyperlink: use the
* {@link setNavigateUrl NavigateUrl} property to define the destination url.
*
* @author Gabor Berczi, DevWorx Hungary <gabor.berczi@devworx.hu>
* @package Prado\Web\UI\WebControls
* @since 3.2
*/
class TAccordionView extends \Prado\Web\UI\WebControls\TWebControl
{
private $_active=false;
/**
* @return the tag name for the view element
*/
protected function getTagName()
{
return 'div';
}
/**
* Adds attributes to renderer.
* @param THtmlWriter the renderer
*/
protected function addAttributesToRender($writer)
{
if(!$this->getActive() && $this->getPage()->getClientSupportsJavaScript())
$this->getStyle()->setStyleField('display','none');
$this->getStyle()->mergeWith($this->getParent()->getViewStyle());
parent::addAttributesToRender($writer);
$writer->addAttribute('id',$this->getClientID());
}
/**
* @return string the caption displayed on this header. Defaults to ''.
*/
public function getCaption()
{
return $this->getViewState('Caption','');
}
/**
* @param string the caption displayed on this header
*/
public function setCaption($value)
{
$this->setViewState('Caption',TPropertyValue::ensureString($value),'');
}
/**
* @return string the URL of the target page. Defaults to ''.
*/
public function getNavigateUrl()
{
return $this->getViewState('NavigateUrl','');
}
/**
* Sets the URL of the target page.
* If not empty, clicking on this header will redirect the browser to the specified URL.
* @param string the URL of the target page.
*/
public function setNavigateUrl($value)
{
$this->setViewState('NavigateUrl',TPropertyValue::ensureString($value),'');
}
/**
* @return string the text content displayed on this view. Defaults to ''.
*/
public function getText()
{
return $this->getViewState('Text','');
}
/**
* Sets the text content to be displayed on this view.
* If this is not empty, the child content of the view will be ignored.
* @param string the text content displayed on this view
*/
public function setText($value)
{
$this->setViewState('Text',TPropertyValue::ensureString($value),'');
}
/**
* @return boolean whether this accordion view is active. Defaults to false.
*/
public function getActive()
{
return $this->_active;
}
/**
* @param boolean whether this accordion view is active.
*/
public function setActive($value)
{
$this->_active=TPropertyValue::ensureBoolean($value);
}
/**
* Renders body contents of the accordion view.
* @param THtmlWriter the writer used for the rendering purpose.
*/
public function renderContents($writer)
{
if(($text=$this->getText())!=='')
$writer->write($text);
else if($this->getHasControls())
parent::renderContents($writer);
}
/**
* Renders the header associated with the accordion view.
* @param THtmlWriter the writer for rendering purpose.
*/
public function renderHeader($writer)
{
if($this->getVisible(false) && $this->getPage()->getClientSupportsJavaScript())
{
$writer->addAttribute('id',$this->getClientID().'_0');
$style=$this->getActive()?$this->getParent()->getActiveHeaderStyle():$this->getParent()->getHeaderStyle();
$style->addAttributesToRender($writer);
$writer->renderBeginTag($this->getTagName());
$this->renderHeaderContent($writer);
$writer->renderEndTag();
}
}
/**
* Renders the content in the header.
* By default, a hyperlink is displayed.
* @param THtmlWriter the HTML writer
*/
protected function renderHeaderContent($writer)
{
$url = $this->getNavigateUrl();
if(($caption=$this->getCaption())==='')
$caption=' ';
if ($url!='')
$writer->write("<a href=\"{$url}\">");
$writer->write("{$caption}");
if ($url!='')
$writer->write("</a>");
}
}
|