summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TBulletedList.php
blob: f2540644c7ac6c53c54a32b905e570f6b2cde4ab (plain)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php

class TBulletedList extends TListControl implements IPostBackEventHandler
{
	private $_isEnabled;
	private $_postBackOptions;

	public function raisePostBackEvent($param)
	{
		if($this->getCausesValidation())
			$this->getPage()->validate($this->getValidationGroup());
		$this->onClick(new TBulletedListEventParameter((int)$param));
	}

	protected function getTagName()
	{
		switch($this->getBulletStyle())
		{
			case 'Numbered':
			case 'LowerAlpha':
			case 'UpperAlpha':
			case 'LowerRoman':
			case 'UpperRoman':
				return 'ol';
		}
		return 'ul';
	}

	protected function addAttributesToRender($writer)
	{
		$needStart=false;
		switch($this->getBulletStyle())
		{
			case 'Numbered':
				$writer->addStyleAttribute('list-style-type','decimal');
				$needStart=true;
				break;
			case 'LowerAlpha':
				$writer->addStyleAttribute('list-style-type','lower-alpha');
				$needStart=true;
				break;
			case 'UpperAlpha':
				$writer->addStyleAttribute('list-style-type','upper-alpha');
				$needStart=true;
				break;
			case 'LowerRoman':
				$writer->addStyleAttribute('list-style-type','lower-roman');
				$needStart=true;
				break;
			case 'UpperRoman':
				$writer->addStyleAttribute('list-style-type','upper-roman');
				$needStart=true;
				break;
			case 'Disc':
				$writer->addStyleAttribute('list-style-type','disc');
				break;
			case 'Circle':
				$writer->addStyleAttribute('list-style-type','circle');
				break;
			case 'Square':
				$writer->addStyleAttribute('list-style-type','square');
				break;
			case 'CustomImage':
				$url=$this->getBulletImageUrl();
				$writer->addStyleAttribute('list-style-image',"url($url)");
				break;
		}
		if($needStart && ($start=$this->getFirstBulletNumber())!=1)
			$writer->addAttribute('start',"$start");
		parent::addAttributesToRender($writer);
	}

	public function getBulletImageUrl()
	{
		return $this->getViewState('BulletImageUrl','');
	}

	public function setBulletImageUrl($value)
	{
		$this->setViewState('BulletImageUrl',$value,'');
	}

	public function getBulletStyle()
	{
		return $this->getViewState('BulletStyle','NotSet');
	}

	public function setBulletStyle($value)
	{
		$this->setViewState('BulletStyle',TPropertyValue::ensureEnum($value,'NotSet','Numbered','LowerAlpha','UpperAlpha','LowerRoman','UpperRoman','Disc','Circle','Square','CustomImage'),'NotSet');
	}

	public function getDisplayMode()
	{
		return $this->getViewState('DisplayMode','Text');
	}

	public function setDisplayMode($value)
	{
		$this->setViewState('DisplayMode',TPropertyValue::ensureEnum($value,'Text','HyperLink','LinkButton'),'Text');
	}

	public function getFirstBulletNumber()
	{
		return $this->getViewState('FirstBulletNumber',1);
	}

	public function setFirstBulletNumber($value)
	{
		$this->setViewState('FirstBulletNumber',TPropertyValue::ensureInteger($value),1);
	}

	public function onClick($param)
	{
		$this->raiseEvent('Click',$this,$param);
	}

	/**
	 * @return string the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
	 */
	public function getTarget()
	{
		return $this->getViewState('Target','');
	}

	/**
	 * Sets the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
	 * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
	 */
	public function setTarget($value)
	{
		$this->setViewState('Target',$value,'');
	}

	protected function render($writer)
	{
		if($this->getHasItems())
			parent::render($writer);
	}

	protected function renderContents($writer)
	{
		$this->_isEnabled=$this->getEnabled(true);
		$this->_postBackOptions=$this->getPostBackOptions();
		$writer->writeLine();
		foreach($this->getItems() as $index=>$item)
		{
			if($item->getHasAttributes())
			{
				foreach($item->getAttributes() as $name=>$value)
					$writer->addAttribute($name,$value);
			}
			$writer->renderBeginTag('li');
			$this->renderBulletText($writer,$item,$index);
			$writer->renderEndTag();
			$writer->writeLine();
		}
	}

	protected function renderBulletText($writer,$item,$index)
	{
		switch($this->getDisplayMode())
		{
			case 'Text':
				if($item->getEnabled())
					$writer->write(THttpUtility::htmlEncode($item->getText()));
				else
				{
					$writer->addAttribute('disabled','disabled');
					$writer->renderBeginTag('span');
					$writer->write(THttpUtility::htmlEncode($item->getText()));
					$writer->renderEndTag();
				}
				return;
			case 'HyperLink':
				if(!$this->_isEnabled || !$item->getEnabled())
					$writer->addAttribute('disabled','disabled');
				else
				{
					$writer->addAttribute('href',$item->getValue());
					if(($target=$this->getTarget())!=='')
						$writer->addAttribute('target',$target);
				}
				break;
			case 'LinkButton':
				if(!$this->_isEnabled || !$item->getEnabled())
					$writer->addAttribute('disabled','disabled');
				else
				{
					$postback=$this->getPage()->getClientScript()->getPostBackEventReference($this,"$index",$this->_postBackOptions);
					$writer->addAttribute('href',$postback);
				}
		}
		if(($accesskey=$this->getAccessKey())!=='')
			$writer->addAttribute('accesskey',$accesskey);
		$writer->renderBeginTag('a');
		$writer->write(THttpUtility::htmlEncode($item->getText()));
		$writer->renderEndTag();
	}

	protected function getPostBackOptions()
	{
		$option=new TPostBackOptions();
		$group = $this->getValidationGroup();
		$hasValidators = $this->getPage()->getValidators($group)->getCount()>0;
		if($this->getCausesValidation() && $hasValidators)
		{
			$options->setPerformValidation(true);
			$options->setValidationGroup($this->getValidationGroup());
			return $options;
		}
		else
			return null;
	}
}

class TBulletedListEventParameter extends TEventParameter
{
	private $_index;
	public function __construct($index)
	{
		$this->_index=$index;
	}

	public function getIndex()
	{
		return $this->_index;
	}
}
?>