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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
<?php
class TPostBackOptions extends TComponent
{
public $ActionUrl;
public $Argument;
public $AutoPostBack;
public $ClientSubmit;
public $PerformValidation;
public $TargetControl;
public $TrackFocus;
public $ValidationGroup;
public function __construct($targetControl=null,
$argument='',
$actionUrl='',
$autoPostBack=false,
$trackFocus=false,
$clientSubmit=true,
$performValidation=false,
$validationGroup='')
{
$this->ActionUrl=$actionUrl;
$this->Argument=$argument;
$this->AutoPostBack=$autoPostBack;
$this->ClientSubmit=$clientSubmit;
$this->PerformValidation=$performValidation;
$this->TargetControl=$targetControl;
$this->TrackFocus=$trackFocus;
$this->ValidationGroup=$validationGroup;
}
}
class TClientScriptManager extends TComponent
{
const SCRIPT_DIR='Web/Javascripts/js';
const POSTBACK_FUNC='Prado.PostBack.perform';
const POSTBACK_OPTIONS='Prado.PostBack.Options';
const FIELD_POSTBACK_TARGET='PRADO_POSTBACK_TARGET';
const FIELD_POSTBACK_PARAMETER='PRADO_POSTBACK_PARAMETER';
const FIELD_LASTFOCUS='PRADO_LASTFOCUS';
const FIELD_PAGE_STATE='PRADO_PAGE_STATE';
private $_owner;
private $_hiddenFields=array();
private $_scriptBlocks=array();
private $_startupScripts=array();
private $_scriptIncludes=array();
private $_onSubmitStatements=array();
private $_arrayDeclares=array();
private $_expandoAttributes=array();
public function __construct(TPage $owner)
{
$this->_owner=$owner;
}
public function getPostBackEventReference($control,$parameter='',$options=null,$javascriptPrefix=true)
{
if($options)
{
$flag=false;
$opt='new '.self::POSTBACK_OPTIONS.'(';
if($options->PerformValidation)
{
$flag=true;
$this->registerValidationScript();
$opt.='true,';
}
else
$opt.='false,';
if($options->ValidationGroup!=='')
{
$flag=true;
$opt.='"'.$options->ValidationGroup.'",';
}
else
$opt.='"",';
if($options->ActionUrl!=='')
{
$flag=true;
$this->_owner->setCrossPagePostBack(true);
$opt.='"'.THttpUtility::quoteJavaScriptString($options->ActionUrl).'",';
}
else
$opt.='"",';
if($options->TrackFocus)
{
$flag=true;
$this->registerFocusScript();
$opt.='true,';
}
else
$opt.='false,';
if($options->ClientSubmit)
{
$flag=true;
$opt.='true)';
}
else
$opt.='false)';
//if(!$flag)
// return '';
}
else
$opt='null';
$this->registerPostBackScript();
$formID=$this->_owner->getForm()->getUniqueID();
$postback=self::POSTBACK_FUNC.'(\''.$formID.'\',\''.$control->getUniqueID().'\',\''.THttpUtility::quoteJavaScriptString($parameter).'\','.$opt.')';
if($options && $options->AutoPostBack)
$postback='setTimeout(\''.THttpUtility::quoteJavaScriptString($postback).'\',0)';
return $javascriptPrefix?'javascript:'.$postback:$postback;
}
protected function registerPostBackScript()
{
$this->registerHiddenField(self::FIELD_POSTBACK_TARGET,'');
$this->registerHiddenField(self::FIELD_POSTBACK_PARAMETER,'');
$am=$this->_owner->getService()->getAssetManager();
$url=$am->publishFilePath(Prado::getFrameworkPath().'/'.self::SCRIPT_DIR.'/base.js');
$this->registerScriptInclude('prado:base',$url);
}
public function registerFocusScript()
{
// need Focus.js
}
public function registerScrollScript()
{
$this->registerHiddenField(self::FIELD_SCROLL_X,$this->_owner->getScrollPositionX());
$this->registerHiddenField(self::FIELD_SCROLL_Y,$this->_owner->getScrollPositionY());
/*
this.ClientScript.RegisterStartupScript(typeof(Page), "PageScrollPositionScript", "\r\ntheForm.oldSubmit = theForm.submit;\r\ntheForm.submit = WebForm_SaveScrollPositionSubmit;\r\n\r\ntheForm.oldOnSubmit = theForm.onsubmit;\r\ntheForm.onsubmit = WebForm_SaveScrollPositionOnSubmit;\r\n" + (this.IsPostBack ? "\r\ntheForm.oldOnLoad = window.onload;\r\nwindow.onload = WebForm_RestoreScrollPosition;\r\n" : string.Empty), true);
need base.js
*/
}
public function registerValidationScript()
{
}
public function isHiddenFieldRegistered($key)
{
return isset($this->_hiddenFields[$key]);
}
public function isScriptBlockRegistered($key)
{
return isset($this->_scriptBlocks[$key]);
}
public function isScriptIncludeRegistered($key)
{
return isset($this->_scriptIncludes[$key]);
}
public function isStartupScriptRegistered($key)
{
return isset($this->_startupScripts[$key]);
}
public function isOnSubmitStatementRegistered($key)
{
return isset($this->_onSubmitStatements[$key]);
}
public function registerArrayDeclaration($name,$value)
{
$this->_arrayDeclares[$name][]=$value;
}
public function registerScriptBlock($key,$script)
{
$this->_scriptBlocks[$key]=$script;
}
public function registerScriptInclude($key,$url)
{
$this->_scriptIncludes[$key]=$url;
}
public function registerHiddenField($name,$value)
{
$this->_hiddenFields[$name]=$value;
}
public function registerOnSubmitStatement($key,$script)
{
$this->_onSubmitStatements[$key]=$script;
}
public function registerStartupScript($key,$script)
{
$this->_startupScripts[$key]=$script;
}
public function registerExpandoAttribute($controlID,$name,$value)
{
$this->_expandoAttributes[$controlID][$name]=$value;
}
public function renderArrayDeclarations($writer)
{
if(count($this->_arrayDeclares))
{
$str="\n<script type=\"text/javascript\">\n<!--\n";
foreach($this->_arrayDeclares as $name=>$array)
{
$str.="var $name=new Array(";
$flag=true;
foreach($array as $value)
{
if($flag)
{
$flag=false;
$str.=$value;
}
else
$str.=','.$value;
}
$str.=");\n";
}
$str.="// -->\n</script>\n";
$writer->write($str);
}
}
public function renderScriptBlocks($writer)
{
$str='';
foreach($this->_scriptBlocks as $script)
$str.="\n".$script;
if($this->_owner->getClientOnSubmitEvent()!=='' && $this->_owner->getClientSupportsJavaScript())
{
$str.="\nfunction WebForm_OnSubmit() {\n";
foreach($this->_onSubmitStatements as $script)
$str.=$script;
$str.="\nreturn true;\n}";
}
if($str!=='')
$writer->write("\n<script type=\"text/javascript\">\n<!--\n".$str."// -->\n</script>\n");
}
public function renderStartupScripts($writer)
{
$str='';
foreach($this->_scriptIncludes as $include)
$str.="\n<script type=\"text/javascript\" src=\"".THttpUtility::htmlEncode($include)."\"></script>";
if(count($this->_startupScripts))
{
$str.="\n<script type=\"text/javascript\">\n<!--\n";
foreach($this->_startupScripts as $script)
$str.=$script;
$str.="// -->\n</script>\n";
$writer->write($str);
}
}
public function renderHiddenFields($writer)
{
$str='';
foreach($this->_hiddenFields as $name=>$value)
{
$value=THttpUtility::htmlEncode($value);
$str.="\n<input type=\"hidden\" name=\"$name\" id=\"$name\" value=\"$value\" />";
}
if($str!=='')
$writer->write($str);
$this->_hiddenFields=array();
}
public function renderExpandoAttribute($writer)
{
if(count($this->_expandoAttributes))
{
$str="\n<script type=\"text/javascript\">\n<!--\n";
foreach($this->_expandoAttributes as $controlID=>$attrs)
{
$str.="var $controlID = document.all ? document.all[\"$controlID\"] : document.getElementById(\"$controlID\");\n";
foreach($attrs as $name=>$value)
{
if($value===null)
$str.="{$key}[\"$name\"]=null;\n";
else
$str.="{$key}[\"$name\"]=\"$value\";\n";
}
}
$str.="// -->\n</script>\n";
$writer->write($str);
}
}
public function getHasHiddenFields()
{
return count($this->_hiddenFields)>0;
}
public function getHasSubmitStatements()
{
return count($this->_onSubmitStatements)>0;
}
/*
internal void RenderWebFormsScript(HtmlTextWriter writer)
private void EnsureEventValidationFieldLoaded();
internal string GetEventValidationFieldValue();
public string GetWebResourceUrl(Type type, string resourceName);
public void RegisterClientScriptResource(Type type, string resourceName);
internal void RegisterDefaultButtonScript(Control button, $writer, bool useAddAttribute);
public function SaveEventValidationField();
public void ValidateEvent(string uniqueId, string argument);
public function getCallbackEventReference()
*/
}
?>
|