summaryrefslogtreecommitdiff
path: root/tests/FunctionalTests/tickets/protected/controls/ToggleImageButton.php
blob: 861a8e317dfd33f809a0cf6f6e39edc904a1f200 (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
<?php

/**
 *
 *
 * @author Christophe BOULAIN (Christophe.Boulain@ceram.fr)
 * @copyright Copyright &copy; 2007, CERAM Sophia Antipolis
 * @license url nameoflicense
 * @version $Id: ToggleImageButton.php 2043 2007-06-30 15:07:50Z xue $
 *
 */

class ToggleImageButton extends TImageButton {

	public function getState () {
		return $this->getViewState('state', ToggleImageButtonState::Down);
	}

	public function setState($value) {
		$this->setViewState('state', TPropertyValue::ensureEnum($value, 'ToggleImageButtonState'));
	}

	public function toggleState () {
		$this->setState(($this->getState()===ToggleImageButtonState::Down)?ToggleImageButtonState::Up:ToggleImageButtonState::Down);
	}

	public function onClick ($param) {
		$this->toggleState();
		parent::onClick($param);
	}

	public function getImageUrl () {
		$img=($this->getState()===ToggleImageButtonState::Down)?'down.gif':'up.gif';
		return $this->publishAsset($img,__CLASS__);
	}

	public function setImageUrl($url) {
		throw new TUnsupportedOperationException('ImageUrl property is read-only');
	}
}

class ToggleImageButtonState extends TEnumerable {
	const Down='Down';
	const Up='Up';
}

?>