From f56a3799ded6b18c98eb9810d9e4c79a9c23c796 Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 19 Jan 2006 14:40:15 +0000 Subject: Updated "personal" demo. --- framework/pradolite.php | 351 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 237 insertions(+), 114 deletions(-) (limited to 'framework/pradolite.php') diff --git a/framework/pradolite.php b/framework/pradolite.php index cccf61f2..f2fe9dcf 100644 --- a/framework/pradolite.php +++ b/framework/pradolite.php @@ -5496,18 +5496,10 @@ protected function addAttributesToRender($writer) $writer->addAttribute('action',$this->getRequest()->getRequestURI()); if(($enctype=$this->getEnctype())!=='') $writer->addAttribute('enctype',$enctype); - $attributes->remove('name'); - $attributes->remove('method'); $attributes->remove('action'); $page=$this->getPage(); if($this->getDefaultButton()!=='') - { $control=$this->findControl($this->getDefaultButton()); - if(!$control) - $control=$page->findControl($this->getDefaultButton()); - if($control instanceof IButtonControl) - $page->getClientScript()->registerDefaultButtonScript($control,$writer,false); - else - throw new Exception('Only IButtonControl can be default button.'); + { } $writer->addAttribute('id',$this->getClientID()); foreach($attributes as $name=>$value) @@ -5555,14 +5547,6 @@ public function setEnctype($value) { $this->setViewState('Enctype',$value,''); } -public function getSubmitDisabledControls() - { - return $this->getViewState('SubmitDisabledControls',false); - } -public function setSubmitDisabledControls($value) - { - $this->setViewState('SubmitDisabledControls',TPropertyValue::ensureBoolean($value),false); - } public function getName() { return $this->getUniqueID(); @@ -7785,7 +7769,7 @@ protected function addAttributesToRender($writer) if(!$this->getEnabled(true) && $this->getEnabled()) $writer->addAttribute('disabled','disabled'); if($this->getAutoPostBack() && $page->getClientSupportsJavaScript()) { - $writer->addAttribute('id',$this->getClientID()); + $writer->addAttribute('id',$this->getClientID()); $this->getPage()->getClientScript()->registerPostBackControl($this); } parent::addAttributesToRender($writer); @@ -10359,7 +10343,7 @@ parent::addAttributesToRender($writer); if($this->getEnabled(true)) { $url = $this->getPostBackUrl(); - $nop = "javascript:;//".$this->getClientID(); + $nop = "#".$this->getClientID(); $writer->addAttribute('href', $url ? $url : $nop); $this->getPage()->getClientScript()->registerPostBackControl($this); } @@ -10370,7 +10354,8 @@ public function getPostBackOptions() $options['EventTarget'] = $this->getUniqueID(); $options['CausesValidation'] = $this->getCausesValidation(); $options['ValidationGroup'] = $this->getValidationGroup(); - $options['PostBackUrl'] = $this->getPostBackUrl(); + $options['PostBackUrl'] = $this->getPostBackUrl(); + $options['StopEvent'] = true; return $options; } protected function renderContents($writer) @@ -10449,7 +10434,7 @@ public function onCommand($param) abstract class TBaseValidator extends TLabel implements IValidator { private $_isValid=true; - private $_registered=false; +private $_registered=false; public function __construct() { parent::__construct(); @@ -10493,21 +10478,20 @@ protected function getClientScriptOptions() protected function onPreRender($param) { $scripts = $this->getPage()->getClientScript(); - $scriptKey = "TBaseValidator"; + $formID=$this->getPage()->getForm()->getClientID(); + $scriptKey = "TBaseValidator:$formID"; if($this->getEnableClientScript() && !$scripts->isEndScriptRegistered($scriptKey)) { - $scripts->registerClientScript('validator'); - $formID=$this->getPage()->getForm()->getClientID(); - $js = "Prado.Validation.AddForm('$formID');"; - $scripts->registerEndScript($scriptKey, $js); + $scripts->registerClientScript('validator'); + $scripts->registerEndScript($scriptKey, "Prado.Validation.AddForm('$formID');"); } if($this->getEnableClientScript()) - $this->renderClientScriptValidator(); + $this->registerClientScriptValidator(); parent::onPreRender($param); } -protected function renderClientScriptValidator() +protected function registerClientScriptValidator() { - if($this->getEnabled(true) && $this->getEnableClientScript()) + if($this->getEnabled(true)) { $class = get_class($this); $scriptKey = "prado:".$this->getClientID(); @@ -10547,12 +10531,12 @@ public function setEnableClientScript($value) } public function getErrorMessage() { - return $this->getText(); - } + return $this->getViewState('ErrorMessage',''); + } public function setErrorMessage($value) { - $this->setText($value); - } + $this->setViewState('ErrorMessage',$value,''); + } public function getControlToValidate() { return $this->getViewState('ControlToValidate',''); @@ -10597,10 +10581,10 @@ public function setIsValid($value) } protected function getValidationTarget() { - if(($id=$this->getControlToValidate())!=='') - return $this->findControl($id); + if(($id=$this->getControlToValidate())!=='' && ($control=$this->findControl($id))!==null) + return $control; else - return null; + throw new TConfigurationException('basevalidator_controltovalidate_invalid'); } protected function getValidationValue($control) { @@ -10621,12 +10605,21 @@ public function validate() return $this->getIsValid(); } abstract protected function evaluateIsValid(); +protected function renderContents($writer) + { + if(($text=$this->getText())!=='') + $writer->write($text); + else if(($text=$this->getErrorMessage())!=='') + $writer->write($text); + else + parent::renderContents($writer); + } } ?>getViewState('InitialValue',''); } @@ -10636,13 +10629,8 @@ public function setInitialValue($value) } protected function evaluateIsValid() { - if(($control=$this->getValidationTarget())!==null) - { - $value=$this->getValidationValue($control); - return trim($value)!==trim($this->getInitialValue()); - } - else - throw new TInvalidDataValueException('requiredfieldvalidator_controltovalidate_invalid'); + $value=$this->getValidationValue($this->getValidationTarget()); + return trim($value)!==trim($this->getInitialValue()); } protected function getClientScriptOptions() { @@ -10697,9 +10685,7 @@ public function getDateFormat() } public function evaluateIsValid() { - if(($control=$this->getValidationTarget())===null) - throw new TInvalidDataValueException('comparevalidator_controltovalidate_invalid'); - if(($value=$this->getValidationValue($control))==='') + if(($value=$this->getValidationValue($this->getValidationTarget()))==='') return true; if($this->getOperator()==='DataTypeCheck') return $this->evaluateDataTypeCheck($value); @@ -10811,17 +10797,12 @@ public function setRegularExpression($value) } public function evaluateIsValid() { - if(($control=$this->getValidationTarget())!==null) - { - if(($value=$this->getValidationValue($control))==='') - return true; - if(($expression=$this->getRegularExpression())!=='') - return preg_match("/^$expression\$/",$value); - else - return true; - } + if(($value=$this->getValidationValue($this->getValidationTarget()))==='') + return true; + if(($expression=$this->getRegularExpression())!=='') + return preg_match("/^$expression\$/",$value); else - throw new TInvalidDataValueException('regularexpressionvalidator_controltovalidate_invalid'); + return true; } protected function getClientScriptOptions() { @@ -10833,8 +10814,8 @@ protected function getClientScriptOptions() ?>getControlToValidate())!=='') - { - if(($control=$this->findControl($id))!==null) - $value=$this->getValidationValue($control); - else - throw new TInvalidDataValueException('customvalidator_controltovalidate_invalid'); - return $this->onServerValidate($value); - } - else - throw new TInvalidDataValueException('customvalidator_controltovalidate_required'); + $value=$this->getValidationValue($this->getValidationTarget()); + return $this->onServerValidate($value); } public function onServerValidate($value) { @@ -10923,15 +10896,6 @@ public function setIsValid($value) ?>getViewState('HeaderText',''); @@ -10996,21 +10960,6 @@ public function setValidationGroup($value) { $this->setViewState('ValidationGroup',$value,''); } -protected function getValidators() - { - $groupID = $this->getGroup(); - if(empty($groupID)) return $this->getPage()->getValidators(); -$parent = $this->getParent(); - $group = $parent->findObject($groupID); -$validators = array(); -foreach($group->getMembers() as $member) - { - $control = $parent->findObject($member); - if(!is_null($control)) - $validators[] = $control; - } - return $validators; - } protected function addAttributesToRender($writer) { $writer->addAttribute('id',$this->getClientID()); @@ -11094,11 +11043,13 @@ protected function renderBulletList($writer) $header=$this->getHeaderText(); $messages=$this->getErrorMessages(); $content = $header; - $show = count($messages) > 0; - if($show) $content .= "