TJuiResizable::raiseCallbackEvent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * TJuiResizable class file.
5
 *
6
 * @author Fabio Bas <ctrlaltca[at]gmail[dot]com>
7
 * @link https://github.com/pradosoft/prado
8
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
9
 */
10
11
namespace Prado\Web\UI\JuiControls;
12
13
use Prado\Prado;
14
use Prado\Web\Javascripts\TJavaScript;
15
use Prado\Web\UI\ActiveControls\ICallbackEventHandler;
16
use Prado\Web\UI\ActiveControls\TActivePanel;
17
use Prado\Web\UI\ActiveControls\TCallbackEventParameter;
18
19
/**
20
 * TJuiResizable class.
21
 *
22
 * TJuiResizable is an extension to {@see \Prado\Web\UI\ActiveControls\TActivePanel} based on jQuery-UI's
23
 * {@see http://jqueryui.com/resizable/ Resizable} interaction.
24
 * A small handle is shown on the bottom right corner of the panel, that permits
25
 * the panel to be resized using the mouse.
26
 *
27
 * ```php
28
 * <com:TJuiResizable
29
 *     ID="resize1"
30
 *     Style="border: 1px solid green; width:100px;height:100px;background-color: #00dd00"
31
 *     Options.maxHeight="250"
32
 *     Options.maxWidth="350"
33
 *     Options.minHeight="150"
34
 *     Options.minWidth="200"
35
 * >
36
 * resize me
37
 * </com:TJuiResizable>
38
 * ```
39
 *
40
 * @author Fabio Bas <ctrlaltca[at]gmail[dot]com>
41
 * @since 3.3
42
 */
43
class TJuiResizable extends TActivePanel implements IJuiOptions, ICallbackEventHandler
44
{
45
	protected $_options;
46
47
	/**
48
	 * Creates a new callback control, sets the adapter to
49
	 * TActiveControlAdapter. If you override this class, be sure to set the
50
	 * adapter appropriately by, for example, by calling this constructor.
51
	 */
52
	public function __construct()
53
	{
54
		parent::__construct();
55
		$this->setAdapter(new TJuiControlAdapter($this));
56
	}
57
58
	/**
59
	 * @return string the name of the jQueryUI widget method
60
	 */
61
	public function getWidget()
62
	{
63
		return 'resizable';
64
	}
65
66
	/**
67
	 * @return string the clientid of the jQueryUI widget element
68
	 */
69
	public function getWidgetID()
70
	{
71
		return $this->getClientID();
72
	}
73
74
	/**
75
	 * Object containing defined javascript options
76
	 * @return TJuiControlOptions
77
	 */
78
	public function getOptions()
79
	{
80
		if (($options = $this->getViewState('JuiOptions')) === null) {
81
			$options = new TJuiControlOptions($this);
82
			$this->setViewState('JuiOptions', $options);
83
		}
84
		return $options;
85
	}
86
87
	/**
88
	 * Array containing valid javascript options
89
	 * @return array
90
	 */
91
	public function getValidOptions()
92
	{
93
		return ['alsoResize', 'animate', 'animateDuration', 'animateEasing', 'aspectRatio', 'autoHide', 'cancel', 'containment', 'delay', 'disabled', 'distance', 'ghost', 'grid', 'handles', 'helper', 'maxHeight', 'maxWidth', 'minHeight', 'minWidth'];
94
	}
95
96
	/**
97
	 * Array containing valid javascript events
98
	 * @return array
99
	 */
100
	public function getValidEvents()
101
	{
102
		return ['create', 'resize', 'start', 'stop'];
103
	}
104
105
	/**
106
	 * @return array list of callback options.
107
	 */
108
	protected function getPostBackOptions()
109
	{
110
		$options = $this->getOptions()->toArray();
111
		return $options;
112
	}
113
114
	/**
115
	 * Ensure that the ID attribute is rendered and registers the javascript code
116
	 * for initializing the active control.
117
	 * @param mixed $writer
118
	 */
119
	protected function addAttributesToRender($writer)
120
	{
121
		parent::addAttributesToRender($writer);
122
123
		$writer->addAttribute('id', $this->getClientID());
124
		$options = TJavaScript::encode($this->getPostBackOptions());
125
		$cs = $this->getPage()->getClientScript();
126
		$code = "jQuery('#" . $this->getWidgetID() . "')." . $this->getWidget() . "(" . $options . ");";
127
		$cs->registerEndScript(sprintf('%08X', crc32($code)), $code);
128
	}
129
130
	/**
131
	 * Raises callback event. This method is required by the {@see \Prado\Web\UI\ActiveControls\ICallbackEventHandler}
132
	 * interface.
133
	 * @param TCallbackEventParameter $param the parameter associated with the callback event
134
	 */
135
	public function raiseCallbackEvent($param)
136
	{
137
		$this->getOptions()->raiseCallbackEvent($param);
138
	}
139
140
	/**
141
	 * Raises the OnCreate event
142
	 * @param object $params event parameters
143
	 */
144
	public function onCreate($params)
145
	{
146
		$this->raiseEvent('OnCreate', $this, $params);
147
	}
148
149
	/**
150
	 * Raises the OnResize event
151
	 * @param object $params event parameters
152
	 */
153
	public function onResize($params)
154
	{
155
		$this->raiseEvent('OnResize', $this, $params);
156
	}
157
158
	/**
159
	 * Raises the OnStart event
160
	 * @param object $params event parameters
161
	 */
162
	public function onStart($params)
163
	{
164
		$this->raiseEvent('OnStart', $this, $params);
165
	}
166
167
	/**
168
	 * Raises the OnStop event
169
	 * @param object $params event parameters
170
	 */
171
	public function onStop($params)
172
	{
173
		$this->raiseEvent('OnStop', $this, $params);
174
	}
175
}
176