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 POSTBACK_FUNC='__doPostBack';
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($options,$javascriptPrefix=true)
{
$str=$javascriptPrefix?'javascript:':'';
if($options->AutoPostBack)
$str.="setTimeout('";
if(!$options->PerformValidation && !$options->TrackFocus && $options->ClientSubmit && $options->ActionUrl==='')
{
$this->registerPostBackScript();
$postback=self::POSTBACK_FUNC.'(\''.$options->TargetControl->getUniqueID().'\',\''.THttpUtility::quoteJavaScriptString($options->Argument).'\')';
if($options->AutoPostBack)
{
$str.=THttpUtility::quoteJavaScriptString($postback);
$str.="',0)";
}
else
$str.=$postback;
return $str;
}
$str.='WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("';
$str.=$options->TargetControl->getUniqueID().'", ';
if(($arg=$options->Argument)==='')
$str.='"", ';
else
$str.='"'.THttpUtility::quoteJavaScriptString($arg).'", ';
$flag=false;
if($options->PerformValidation)
{
$flag=true;
$str.='true, ';
}
else
$str.='false, ';
if($options->ValidationGroup!=='')
{
$flag=true;
$str.='"'.$options->ValidationGroup.'", ';
}
else
$str.='"", ';
if($options->ActionUrl!=='')
{
$flag=true;
$this->_owner->setContainsCrossPagePost(true);
$str.='"'.THttpUtility::quoteJavaScriptString($options->ActionUrl).'", ';
}
else
$str.='"", ';
if($options->TrackFocus)
{
$this->_owner->registerFocusScript();
$flag=true;
$str.='true, ';
}
else
$str.='false, ';
if($options->ClientSubmit)
{
$flag=true;
$this->_owner->registerPostBackScript();
$str.='true))';
}
else
$str.='false))';
if($options->AutoPostBack)
$str.="', 0)";
if($flag)
{
$this->_owner->registerWebFormsScript();
return $str;
}
else
return '';
}
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\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\n");
}
public function renderStartupScripts($writer)
{
if(count($this->_startupScripts))
{
$str="\n\n";
$writer->write($str);
}
}
public function renderHiddenFields($writer)
{
$str='';
foreach($this->_hiddenFields as $name=>$value)
{
$value=THttpUtility::htmlEncode($value);
$str.="\n";
}
if($str!=='')
$writer->write($str);
$this->_hiddenFields=array();
}
public function renderExpandoAttribute($writer)
{
if(count($this->_expandoAttributes))
{
$str="\n\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()
*/
public function registerPostBackScript()
{
$this->registerHiddenField('__EVENTTARGET','');
$this->registerHiddenField('__EVENTPARAM','');
$id=$this->_owner->getForm()->getUniqueID();
$script=<<registerStartupScript('form',$script);
}
}
?>