From f56a3799ded6b18c98eb9810d9e4c79a9c23c796 Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 19 Jan 2006 14:40:15 +0000 Subject: Updated "personal" demo. --- .gitattributes | 1 + demos/personal/protected/Pages/Home.php | 14 - demos/personal/protected/Pages/Layout.php | 5 + demos/personal/protected/Pages/Layout.tpl | 42 ++- demos/personal/protected/Pages/Settings.page | 4 + demos/personal/protected/Pages/UserLogin.page | 23 +- demos/personal/protected/Pages/UserLogin.php | 13 +- demos/personal/protected/Pages/config.xml | 3 + demos/personal/protected/application.xml | 6 +- framework/Log/TLogRouter.php | 3 +- framework/Web/UI/WebControls/TButton.php | 4 +- framework/pradolite.php | 351 +++++++++++++++++--------- 12 files changed, 314 insertions(+), 155 deletions(-) create mode 100644 demos/personal/protected/Pages/Settings.page diff --git a/.gitattributes b/.gitattributes index 6b78e1cf..2fd8cf6d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15,6 +15,7 @@ demos/personal/protected/Pages/Home.page -text demos/personal/protected/Pages/Home.php -text demos/personal/protected/Pages/Layout.php -text demos/personal/protected/Pages/Layout.tpl -text +demos/personal/protected/Pages/Settings.page -text demos/personal/protected/Pages/UserLogin.page -text demos/personal/protected/Pages/UserLogin.php -text demos/personal/protected/Pages/config.xml -text diff --git a/demos/personal/protected/Pages/Home.php b/demos/personal/protected/Pages/Home.php index cca7d57b..badbca73 100644 --- a/demos/personal/protected/Pages/Home.php +++ b/demos/personal/protected/Pages/Home.php @@ -2,20 +2,6 @@ class Home extends TPage { - public function onPreInit($param) - { - parent::onPreInit($param); - if(!$this->getUser()->getIsGuest()) - $this->setTheme(''); - } - - public function testClick($sender,$param) - { - if($sender->BackColor==='') - $sender->BackColor='blue'; - else - $sender->BackColor=''; - } } ?> \ No newline at end of file diff --git a/demos/personal/protected/Pages/Layout.php b/demos/personal/protected/Pages/Layout.php index ba96038b..37ed95d4 100644 --- a/demos/personal/protected/Pages/Layout.php +++ b/demos/personal/protected/Pages/Layout.php @@ -2,6 +2,11 @@ class Layout extends TTemplateControl { + public function logout($sender,$param) + { + $this->Application->getModule('auth')->logout(); + $this->Response->redirect($this->Service->constructUrl('Home')); + } } ?> \ No newline at end of file diff --git a/demos/personal/protected/Pages/Layout.tpl b/demos/personal/protected/Pages/Layout.tpl index db6dd242..f1064231 100644 --- a/demos/personal/protected/Pages/Layout.tpl +++ b/demos/personal/protected/Pages/Layout.tpl @@ -1,29 +1,45 @@ - -My Personal Website - + + + + +
-

Your Name Here

-

My Personal Site

- +

Your Name Here

+

My Personal Site

+ +
+
+
+
+ \ No newline at end of file diff --git a/demos/personal/protected/Pages/Settings.page b/demos/personal/protected/Pages/Settings.page new file mode 100644 index 00000000..48dfde96 --- /dev/null +++ b/demos/personal/protected/Pages/Settings.page @@ -0,0 +1,4 @@ + +Welcome, User->Name %> />! +This page contains site settings accessible only to site admin. + \ No newline at end of file diff --git a/demos/personal/protected/Pages/UserLogin.page b/demos/personal/protected/Pages/UserLogin.page index 588b8f6a..4bad6780 100644 --- a/demos/personal/protected/Pages/UserLogin.page +++ b/demos/personal/protected/Pages/UserLogin.page @@ -1,7 +1,18 @@ -Username:
-Password:
- - -
- +Username: + + +
+Password:
+ + + + \ No newline at end of file diff --git a/demos/personal/protected/Pages/UserLogin.php b/demos/personal/protected/Pages/UserLogin.php index 70cbc986..0dd2cd79 100644 --- a/demos/personal/protected/Pages/UserLogin.php +++ b/demos/personal/protected/Pages/UserLogin.php @@ -5,10 +5,15 @@ class UserLogin extends TPage public function login($sender,$param) { $manager=$this->Application->getModule('auth'); - if($manager->login($this->username->Text,$this->password->Text)) - $this->Application->Response->redirect($this->Application->Request->Items['ReturnUrl']); - else - $this->error->Text='login failed'; + if(!$manager->login($this->Username->Text,$this->Password->Text)) + $param->IsValid=false; + } + + public function onLoadComplete($param) + { + parent::onLoadComplete($param); + if($this->IsPostBack && $this->IsValid) + $this->Response->redirect($this->Request->Items['ReturnUrl']); } } diff --git a/demos/personal/protected/Pages/config.xml b/demos/personal/protected/Pages/config.xml index ca63c17b..fa047ceb 100644 --- a/demos/personal/protected/Pages/config.xml +++ b/demos/personal/protected/Pages/config.xml @@ -1,5 +1,8 @@ + + + \ No newline at end of file diff --git a/demos/personal/protected/application.xml b/demos/personal/protected/application.xml index dbb51264..84467e98 100644 --- a/demos/personal/protected/application.xml +++ b/demos/personal/protected/application.xml @@ -7,6 +7,10 @@ --> + + + + @@ -18,7 +22,7 @@ - + diff --git a/framework/Log/TLogRouter.php b/framework/Log/TLogRouter.php index 5e54e939..6979849f 100644 --- a/framework/Log/TLogRouter.php +++ b/framework/Log/TLogRouter.php @@ -68,6 +68,7 @@ class TLogRouter extends TModule throw new TConfigurationException('logrouter_configfile_invalid',$this->_configFile); } $this->loadConfig($config); + //$this->getApplication()->attachEventHandler('Error',array($this,'collectLogs')); $this->getApplication()->attachEventHandler('EndRequest',array($this,'collectLogs')); } @@ -317,7 +318,7 @@ class TFileLogRoute extends TLogRoute /** * @var integer maximum log file size */ - private $_maxFileSize=1024; // in KB + private $_maxFileSize=512; // in KB /** * @var integer number of log files used for rotation */ diff --git a/framework/Web/UI/WebControls/TButton.php b/framework/Web/UI/WebControls/TButton.php index bffb4009..9c364af8 100644 --- a/framework/Web/UI/WebControls/TButton.php +++ b/framework/Web/UI/WebControls/TButton.php @@ -101,10 +101,10 @@ class TButton extends TWebControl implements IPostBackEventHandler public function getPostBackOptions() { $options['CausesValidation'] = $this->getCausesValidation(); - $options['ValidationGroup'] = $this->getValidationGroup(); + $options['ValidationGroup'] = $this->getValidationGroup(); $options['PostBackUrl'] = $this->getPostBackUrl(); $options['ClientSubmit'] = !$this->getUseSubmitBehavior(); - + return $options; } 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 .= "
    \n"; - foreach($messages as $message) - $content.= '
  • '.$message."
  • \n"; - if($show) $content .= "
\n"; + if(count($messages)>0) + { + $content .= "
    \n"; + foreach($messages as $message) + $content.= '
  • '.$message."
  • \n"; + $content .= "
\n"; + } $writer->write($content); } } @@ -12765,6 +12716,54 @@ public function valid() } } ?>_count=$count; + } +public function getCount() + { + return $this->_count; + } +public function getIterator() + { + return new TDummyDataSourceIterator($this->_count); + } +} +class TDummyDataSourceIterator implements Iterator +{ + private $_index; + private $_count; +public function __construct($count) + { + $this->_count=$count; + $this->_index=0; + } +public function rewind() + { + $this->_index=0; + } +public function key() + { + return $this->_index; + } +public function current() + { + return null; + } +public function next() + { + $this->_index++; + } +public function valid() + { + return $this->_index<$this->_count; + } +} +?>setViewState('ItemCount',$this->_items->getCount(),0); else $this->clearViewState('ItemCount'); + if($this->_autoColumns) + { + $state=array(); + foreach($this->_autoColumns as $column) + $state[]=$column->saveState(); + $this->setViewState('ColumnState',$state,array()); + } + else + $this->clearViewState('ColumnState'); } protected function onLoadState($param) { if(!$this->getIsDataBound()) - $this->restoreItemsFromViewState(); + { + $state=$this->getViewState('ColumnState',array()); + $columns=$this->getAutoColumns(); + foreach($state as $st) + { + $column=new TBoundColumn; + $column->loadState($st); + $columns->add($column); + } + $this->restoreGridFromViewState(); + } $this->clearViewState('ItemCount'); } private function createPagedDataSource() @@ -13163,16 +13181,26 @@ public function reset() protected function restoreGridFromViewState() { $this->reset(); + if(($itemCount=$this->getViewState('ItemCount',0))<=0) + return; $this->_pagedDataSource=$ds=$this->createPagedDataSource(); - if($columns->getCount()>0) + if($ds->getAllowCustomPaging()) + $ds->setDataSource(new TDummyDataSource($itemCount)); + else + $ds->setDataSource(new TDummyDataSource($this->getViewState('DataSourceCount',0)); +$columns=new TList($this->getColumns()); + $columns->mergeWith($this->_autoColumns); +if($columns->getCount()>0) { foreach($columns as $column) $column->initialize(); - $allowPaging=$ds->getAllowPaging(); if($allowPaging) - $selectedIndex=$this->getSelectedItemIndex(); + $this->createPager(-1,-1,$columnCount,$ds); + $this->createItemInternal(-1,-1,'Header',false,null,$columns); + $selectedIndex=$this->getSelectedItemIndex(); $editIndex=$this->getEditItemIndex(); $index=0; + $dsIndex=$ds->getAllowPaging()?$ds->getFirstIndexInPage():0; foreach($ds as $data) { if($index===$editIndex) @@ -13183,9 +13211,14 @@ protected function restoreGridFromViewState() $itemType='AlternatingItem'; else $itemType='Item'; - $index++; + $items->add($this->createItemInternal($index,$dsIndex,$itemType,false,null,$columns)); + $index++; + $dsIndex++; } - } + $this->createItemInternal(-1,-1,'Footer',false,null,$columns); + if($allowPaging) + $this->createPager(-1,-1,$columnCount,$ds); + } $this->_pagedDataSource=null; } protected function performDataBinding($data) @@ -13199,8 +13232,10 @@ protected function performDataBinding($data) $allowPaging=$ds->getAllowPaging(); if($allowPaging && $ds->getCurrentPageIndex()>=$ds->getPageCount()) throw new TInvalidDataValueException('datagrid_currentpageindex_invalid'); - $columns=$this->getAllColumns($ds); - $items=$this->getItems(); + $columns=new TList($this->getColumns()); + $autoColumns=$this->createAutoColumns($ds); + $columns->mergeWith($autoColumns); +$items=$this->getItems(); if(($columnCount=$columns->getCount())>0) { foreach($columns as $column) @@ -13411,15 +13446,9 @@ if($pageCount>$endPageIndex) $controls->add($button); } } -protected function getAllColumns($dataSource) - { - $list=new TList($this->getColumns()); - $list->mergeWith($this->createAutoColumns($dataSource)); - return $list; - } protected function createAutoColumns($dataSource) { - if(!$dataSource || $dataSource->getCount()<=0) + if(!$dataSource) return null; $autoColumns=$this->getAutoColumns(); $autoColumns->clear(); @@ -13448,6 +13477,100 @@ protected function createAutoColumns($dataSource) break; } return $autoColumns; + } +protected function applyItemStyles() + { + $headerStyle=$this->getViewState('HeaderStyle',null); + $footerStyle=$this->getViewState('FooterStyle',null); + $pagerStyle=$this->getViewState('PagerStyle',null); + $separatorStyle=$this->getViewState('SeparatorStyle',null); + $itemStyle=$this->getViewState('ItemStyle',null); + $alternatingItemStyle=$this->getViewState('AlternatingItemStyle',null); + if($itemStyle!==null) + { + if($alternatingItemStyle===null) + $alternatingItemStyle=new TTableItemStyle; + $alternatingItemStyle->mergeWith($itemStyle); + } + $selectedItemStyle=$this->getViewState('SelectedItemStyle',null); + if($alternatingItemStyle!==null) + { + if($selectedItemStyle===null) + $selectedItemStyle=new TTableItemStyle; + $selectedItemStyle->mergeWith($alternatingItemStyle); + } + $editItemStyle=$this->getViewState('EditItemStyle',null); + if($selectedItemStyle!==null) + { + if($editItemStyle===null) + $editItemStyle=new TTableItemStyle; + $editItemStyle->mergeWith($selectedItemStyle); + } +foreach($this->getControls() as $index=>$control) + { + switch($control->getItemType()) + { + case 'Header': + if($headerStyle) + $control->getStyle()->mergeWith($headerStyle); + if(!$this->getShowHeader()) + $control->setVisible(false); + break; + case 'Footer': + if($footerStyle) + $control->getStyle()->mergeWith($footerStyle); + if(!$this->getShowFooter()) + $control->setVisible(false); + break; + case 'Separator': + if($separatorStyle) + $control->getStyle()->mergeWith($separatorStyle); + break; + case 'Item': + if($itemStyle) + $control->getStyle()->mergeWith($itemStyle); + break; + case 'AlternatingItem': + if($alternatingItemStyle) + $control->getStyle()->mergeWith($alternatingItemStyle); + break; + case 'SelectedItem': + if($selectedItemStyle) + $control->getStyle()->mergeWith($selectedItemStyle); + break; + case 'EditItem': + if($editItemStyle) + $control->getStyle()->mergeWith($editItemStyle); + break; + case 'Pager': + if($pagerStyle) + { + $control->getStyle()->mergeWith($pagerStyle); + $mode=$pagerStyle->getMode(); + if($index===0) + { + if($mode==='Bottom') + $control->setVisible(false); + } + else + { + if($mode==='Top') + $control->setVisible(false); + } + } + break; + default: + break; + } + } + } +protected function renderContents($writer) + { + if($this->getHasControls()) + { + $this->applyItemStyles(); + parent::renderContents($writer); + } } } class TDataGridItemEventParameter extends TEventParameter -- cgit v1.2.3