summaryrefslogtreecommitdiff
path: root/framework/Web/UI/ActiveControls/TCallbackClientSideOptions.php
blob: 1e1bd52f289cd83438b9484c1c7d9ebcd7dad190 (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
<?php
/*
 * Created on 1/05/2006
 */

class TClientSideOptions extends TComponent
{
	private $_options;
	
	public function __construct()
	{
		$this->_options = Prado::createComponent('System.Collections.TMap');
	}
	
	protected function setFunction($name, $code)
	{
		$this->_options->add($name, $this->ensureFunction($code));
	}
	
	protected function getOption($name)
	{
		return $this->_options->itemAt($name);
	}
	
	public function getOptions()
	{
		return $this->_options;
	}
	
	protected function ensureFunction($javascript)
	{
		return $javascript;
	}
}

/**
 * TCallbackClientSideOptions class.
 * 
 * The following client side events are executing in order if the callback
 * request and response are send and received successfuly.
 * 
 * - <b>onUninitialized</b> executed when callback request is uninitialized. 
 * - <b>onLoading</b> executed when callback request is initiated 
 * - <b>onLoaded</b> executed when callback request begins. 
 * - <b>onInteractive</b> executed when callback request is in progress. 
 * - <b>onComplete</b>executed when callback response returns.
 * 
 * The <tt>OnSuccess</tt> and <tt>OnFailure</tt> events are raised when the
 * response is returned. A successful request/response will raise
 * <tt>OnSuccess</tt> event otherwise <tt>OnFailure</tt> will be raised.
 * 
 * - <b>onSuccess</b> executed when callback request returns and is successful. 
 * - <b>onFailure</b> executed when callback request returns and fails.
 * - <b>onException</b> raised when callback request fails due to
 * request/response errors.
 * 
 */
class TCallbackClientSideOptions extends TClientSideOptions
{
	/**
	 * Returns javascript statement enclosed within a javascript function.
	 * @param string javascript statement, if string begins within
	 * "javascript:" the whole string is assumed to be a function.
	 * @return string javascript statement wrapped in a javascript function
	 */
	protected function ensureFunction($javascript)
	{
		if(TJavascript::isFunction($javascript))
			return $javascript;
		else
		{
			$code = "function(request, result){ {$javascript} }";
			return TJavascript::quoteFunction($code);
		}
	}
	
	/**
	 * @return string javascript code for client-side onUninitialized event
	 */
	public function getOnUninitialized()
	{
		return $this->getOption('onUninitialized');
	}
	
	/**
	 * @param string javascript code for client-side onUninitialized event.
	 */
	public function setOnUninitialized($javascript)
	{
		$this->setFunction('onUninitialized', $javascript);
	}
	
	/**
	 * @return string javascript code for client-side onLoading event
	 */
	public function getOnLoading()
	{
		return $this->getOption('onLoading');
	}
	
	/**
	 * @param string javascript code for client-side onLoading event.
	 */
	public function setOnLoading($javascript)
	{
		$this->setFunction('onLoading', $javascript);
	}
		
	/**
	 * @return string javascript code for client-side onLoaded event
	 */
	public function getOnLoaded()
	{
		return $this->getOption('onLoaded');
	}
	
	/**
	 * @param string javascript code for client-side onLoaded event.
	 */
	public function setOnLoaded($javascript)
	{
		$this->setFunction('onLoaded', $javascript);
	}
	/**
	 * @return string javascript code for client-side onInteractive event
	 */
	public function getOnInteractive()
	{
		return $this->getOption('onInteractive');
	}
	
	/**
	 * @param string javascript code for client-side onInteractive event.
	 */
	public function setonInteractive($javascript)
	{
		$this->setFunction('onInteractive', $javascript);
	}
	/**
	 * @return string javascript code for client-side onComplete event
	 */
	public function getOnComplete()
	{
		return $this->getOption('onComplete');
	}
	
	/**
	 * @param string javascript code for client-side onComplete event.
	 */
	public function setOnComplete($javascript)
	{
		$this->setFunction('onComplete', $javascript);
	}
	/**
	 * @return string javascript code for client-side onSuccess event
	 */
	public function getOnSuccess()
	{
		return $this->getOption('onSuccess');
	}
	
	/**
	 * @param string javascript code for client-side onSuccess event.
	 */
	public function setOnSuccess($javascript)
	{
		$this->setFunction('onSuccess', $javascript);
	}

	/**
	 * @return string javascript code for client-side onFailure event
	 */
	public function getOnFailure()
	{
		return $this->getOption('onFailure');
	}
	
	/**
	 * @param string javascript code for client-side onFailure event.
	 */
	public function setOnFailure($javascript)
	{
		$this->setFunction('onFailure', $javascript);
	}
	
	/**
	 * @return string javascript code for client-side onException event
	 */
	public function getOnException()
	{
		return $this->getOption('onException');
	}
	
	/**
	 * @param string javascript code for client-side onException event.
	 */
	public function setOnException($javascript)
	{
		$this->setFunction('onException', $javascript);
	}	
	
	/**
	 * @return boolean true to post the state on callback, default is post the
	 * state on callback.
	 */
	public function getPostState()
	{
		return $this->getOption('PostState');
	}
	
	/**
	 * @param boolean true to post the state of the form with callback requests.
	 * Default is to post the state.
	 */
	public function setPostState($value)
	{
		$this->getOptions()->add('PostState', TPropertyValue::ensureBoolean($value));
	}
} 

?>