Changeset 126
- Timestamp:
- 04/01/06 23:09:19 (3 years ago)
- Files:
-
- trunk/build/manifests/jelix-lib.mn (modified) (2 diffs)
- trunk/build/manifests/testapp.mn (modified) (2 diffs)
- trunk/build/mkdist.php (modified) (4 diffs)
- trunk/lib/jelix/core/jErrorHandler.lib.php (modified) (1 diff)
- trunk/lib/jelix/core/response/jResponseRedirect.class.php (modified) (2 diffs)
- trunk/lib/jelix/core/response/jResponseRedirectUrl.class.php (modified) (2 diffs)
- trunk/lib/jelix/forms/jForms.class.php (modified) (1 diff)
- trunk/lib/jelix/forms/jFormsBase.class.php (added)
- trunk/lib/jelix/forms/jFormsCompiler.class.php (modified) (2 diffs)
- trunk/lib/jelix/forms/jFormsDataContainer.class.php (modified) (2 diffs)
- trunk/lib/jelix/tpl/jTpl.class.php (modified) (2 diffs)
- trunk/lib/jelix/utils/jDatatype.class.php (modified) (1 diff)
- trunk/Makefile (modified) (2 diffs)
- trunk/testapp/modules/testapp/controllers/forms.classic.php (modified) (5 diffs)
- trunk/testapp/modules/testapp/controllers/main.classic.php (modified) (2 diffs)
- trunk/testapp/modules/testapp/templates/blank.tpl (deleted)
- trunk/testapp/modules/testapp/templates/hello.tpl (modified) (1 diff)
- trunk/testapp/modules/testapp/templates/sampleform.tpl (modified) (1 diff)
- trunk/testapp/modules/testapp/templates/sampleformresult.tpl (added)
- trunk/testapp/modules/testapp/templates/sommaire.tpl (added)
- trunk/testapp/modules/testapp/zones/sommaire.zone.php (added)
- trunk/testapp/responses/myHtmlResponse.class.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/manifests/jelix-lib.mn
r113 r126 86 86 jEventListener.class.php 87 87 jEventListenerFactory.class.php 88 89 cd lib/jelix/forms 90 jForms.class.php 91 jFormsBase.class.php 92 jFormsCompiler.class.php 93 jFormsControl.class.php 94 jFormsDataContainer.class.php 95 jFormsDatasource.class.php 88 96 89 97 cd lib/jelix/tpl/ … … 129 137 jXmlRpc.class.php 130 138 jZone.class.php 139 jDatatype.class.php 131 140 132 141 cd lib/json trunk/build/manifests/testapp.mn
r101 r126 33 33 cd testapp/modules/testapp/controllers 34 34 main.classic.php 35 forms.classic.php 35 36 cd testapp/modules/testapp/templates 36 37 hello.tpl 37 38 main.tpl 38 blank.tpl39 39 error.tpl 40 40 testzone.tpl 41 sommaire.tpl 42 sampleform.tpl 43 sampleformresult.tpl 41 44 cd testapp/modules/testapp/zones 42 45 test.zone.php 46 sommaire.zone.php 47 cd testapp/modules/testapp/forms 48 sample.form.xml 43 49 cd testapp/modules/unittest 44 50 events.xml … … 70 76 cd testapp/var/themes/default/testapp 71 77 main.tpl 78 cd testapp/var/overloads/testapp/daos 79 cd testapp/var/overloads/testapp/locales 80 trunk/build/mkdist.php
r85 r126 35 35 $sw = substr(array_shift($_SERVER['argv']),1); 36 36 if($sw{0} =='D'){ 37 37 38 38 }else{ 39 39 $options['verbose'] = (strpos('v', $sw) !== false); 40 } 40 } 41 41 }else{ 42 42 break; … … 75 75 if($m[1] == 'dd'){ 76 76 $currentdestdir = normalizeDir($m[2]); 77 createDir($distdir.$currentdestdir); 77 78 }elseif($m[1] == 'sd'){ 78 79 $currentsrcdir = normalizeDir($m[2]); … … 80 81 $currentsrcdir = normalizeDir($m[2]); 81 82 $currentdestdir = normalizeDir($m[2]); 83 createDir($distdir.$currentdestdir); 82 84 }else{ 83 85 if($m[2] == ''){ … … 89 91 90 92 $destfile = $distdir.$currentdestdir.$m[3]; 91 createDir(dirname($destfile));92 93 93 94 if($m[1]=='*'){ trunk/lib/jelix/core/jErrorHandler.lib.php
r121 r126 65 65 '%msg%' => $errmsg, 66 66 '%file%' => $filename, 67 '%line%' => $linenum 67 '%line%' => $linenum, 68 '\t' =>"\t", 69 '\n' => "\n" 68 70 )); 69 71 trunk/lib/jelix/core/response/jResponseRedirect.class.php
r121 r126 31 31 32 32 public function output(){ 33 if($this->hasErrors()) return false; 33 if($this->hasErrors()) return false; 34 34 35 header ('location: '.jUrl::get($this->action, $this->params)); 35 36 return true; … … 37 38 38 39 public function fetch(){ 39 if($this->hasErrors()) return false;40 return 'location: '.jUrl::get($this->action, $this->params);40 if($this->hasErrors()) return false; 41 return 'location: '.jUrl::get($this->action, $this->params); 41 42 } 42 43 43 44 public function outputErrors(){ 44 45 include_once(JELIX_LIB_RESPONSE_PATH.'jResponseHtml.class.php'); 46 $resp = new jResponseHtml(); 47 $resp->outputErrors(); 45 48 } 46 49 trunk/lib/jelix/core/response/jResponseRedirectUrl.class.php
r121 r126 25 25 26 26 public function output(){ 27 if($this->hasErrors())return false;27 if($this->hasErrors()) return false; 28 28 header ('location: '.$this->url); 29 29 return true; … … 36 36 public function fetch(){ 37 37 if($this->hasErrors()) return false; 38 return 'location: '.$this->url;38 return 'location: '.$this->url; 39 39 } 40 40 41 41 public function outputErrors(){ 42 42 include_once(JELIX_LIB_RESPONSE_PATH.'jResponseHtml.class.php'); 43 $resp = new jResponseHtml(); 44 $resp->outputErrors(); 43 45 } 44 46 trunk/lib/jelix/forms/jForms.class.php
r97 r126 12 12 13 13 define('JFORMS_ID_PARAM','__forms_id__'); 14 15 14 require_once(JELIX_LIB_FORMS_PATH.'jFormsBase.class.php'); 15 require_once(JELIX_LIB_FORMS_PATH.'jFormsControl.class.php'); 16 require_once(JELIX_LIB_UTILS_PATH.'jDatatype.class.php'); 16 17 /** 17 18 * Classe abstraite pour g�r un formulaire 18 19 */ 19 abstractclass jForms {20 class jForms { 20 21 21 //------------- m�odes statiques22 private function __construct(){ } 22 23 23 static public create($formSel){ 24 $sel = new jSelectorForms($formSel); 24 25 public static function create($formSel , $idName=null) 26 { 27 $form = self::_getInstance($formSel,$idName, true); 28 return $form; 29 } 30 31 static public function get($formSel,$idName){ 32 $form = self::_getInstance($formSel,$idName); 33 return $form; 34 } 35 36 static public function fill($formSel,$idName){ 37 $form = self::_getInstance($formSel,$idName); 38 $form->initFromRequest(); 39 return $form; 40 } 41 42 43 static protected function _getInstance($formSel, $idName, $reset=false){ 44 global $gJCoord; 45 46 $sel = new jSelectorForm($formSel); 25 47 jIncluder::inc($sel); 26 48 $c = $sel->getClass(); 27 return new $c; 49 50 51 if(empty($idName)){ 52 $id = 0; 53 }else{ 54 $id = $gJCoord->request->getParam($idName); 55 } 56 $form = new $c($formSel,$id,$reset); 57 58 return $form; 28 59 } 29 60 30 static public get($formSel){31 $form = self::create($formSel);32 $form->initFromRequest($formSel);33 }34 35 static public destroy($formSel){36 global $gJCoord;37 $req = $gJCoord->request;38 $id = $gJCoord->request->getParam(JFORMS_ID_PARAM);39 if($id !== null && isset($_SESSION['JFORMS'][$id])){40 unset($_SESSION['JFORMS'][$id];41 }42 }43 44 //---------------- membres non statiques45 46 protected $_controls = array();47 protected $_container=null;48 protected $_readOnly = false;49 protected $_errors;50 51 public function __construct(){52 53 }54 55 protected function initFromRequest($formSel){56 global $gJCoord;57 $req = $gJCoord->request;58 $this->_container = $this->getDataContainer($req->getParam(JFORMS_ID_PARAM),$formSel);59 foreach($this->_controls as $name=>$ctrl){60 $value = $req->getParam($name);61 if($value !== null)62 $this->_container->set($name, $value);63 }64 }65 66 protected function getDataContainer($id==null, $formSel){67 if($id === null || ! isset($_SESSION['JFORMS'][$id])){68 $id=md5(uniqid(rand(), true));69 $_SESSION['JFORMS'][$id]= new jFormsDataContainer($id, $formSel);70 }71 return $_SESSION['JFORMS'][$id];72 }73 74 /**75 * @param $control jFormsControl76 */77 protected function addControl($control){78 $this->_controls [$control->ref] = $control;79 }80 81 public function check(){82 $this->_errors = array();83 foreach($this->_controls as $name=>$ctrl){84 $value=$this->_container->get($name);85 if($value === null && $ctrl->required){86 $this->_errors[$name]=2;87 }elseif($ctrl->datatype->check($value)){88 $this->_errors[$name]=1;89 }90 }91 return count($this->errors) == 0:92 }93 94 abstract public function save();95 96 public function setReadOnly($r = true){ $this->_readOnly = $r; }97 98 public function getErrors(){ return $this->_errors; }99 100 public function getDatas(){ return $this->_container->getDatas(); }101 102 }103 104 /**105 * Classe de gestion de formulaire bas�ur un DAO106 */107 class jFormsDAO extends jForms {108 109 110 public function __construct(){111 112 }113 114 public function save(){115 116 }117 118 public function init(){119 120 121 }122 61 123 62 } trunk/lib/jelix/forms/jFormsCompiler.class.php
r97 r126 35 35 36 36 $source=array(); 37 $source[]='<?php class '.$selector->getClass().' extends jForms {'; 38 $source[]=' public function __construct(){'; 37 $source[]='<?php class '.$selector->getClass().' extends jFormsBase {'; 38 $source[]=' public function __construct($formSel,$id=0, $reset = false){'; 39 $source[]=' parent::__construct($formSel,$id, $reset); '; 39 40 foreach($xml->children() as $controltype=>$control){ 40 41 … … 104 105 } 105 106 106 $source[]=' }'; 107 $source[]=' }'; 108 109 $source[]=' public function save(){ } '; 110 107 111 $source[]='} ?>'; 108 112 trunk/lib/jelix/forms/jFormsDataContainer.class.php
r86 r126 12 12 13 13 class jFormsDataContainer { 14 p rivate$datas = array();15 p rivate$id;16 p rivate$formSelector;14 public $datas = array(); 15 public $id; 16 public $formSelector; 17 17 18 18 function __construct($id, $formSelector){ … … 21 21 } 22 22 23 function getId(){ 24 return $id; 25 } 26 27 function getFormSelector(){ 28 return $id; 29 } 30 31 function setDatas($datas){ 32 $this->datas = $datas; 33 } 34 35 function getDatas($datas){ 36 return $this->datas; 37 } 38 function get($name){ 39 return $this->datas[$name]; 40 } 41 function set($name,$value){ 42 $this->datas[$name]=$value; 43 } 44 45 function unset($name){ 23 function unsetData($name){ 46 24 unset($this->datas[$name]); 47 25 } trunk/lib/jelix/tpl/jTpl.class.php
r124 r126 44 44 } 45 45 } 46 47 public function assignIfNone ($name, $value = null){ 48 if(is_array($name)){ 49 foreach ($name as $key => $val) { 50 if(!isset($this->_vars[$key])) 51 $this->_vars[$key] = $val; 52 } 53 }else{ 54 if(!isset($this->_vars[$name])) 55 $this->_vars[$name] = $value; 56 } 57 } 58 59 46 60 #ifndef JTPL_STANDALONE 47 61 function assignZone($name, $zoneName, $params=array()){ … … 90 104 #else 91 105 $tpl = JTPL_TEMPLATES_PATH . $tpl; 92 $filename = basename($tpl);93 $cachefile = JTPL_CACHE_PATH . $filename;94 95 $mustCompile = $GLOBALS['jTplConfig']['compilation_force']['force'] || !file_exists($cachefile);96 if (!$mustCompile) {97 if (filemtime($tpl) > filemtime($cachefile)) {98 $mustCompile = true;99 }100 }101 102 if ($mustCompile) {106 $filename = basename($tpl); 107 $cachefile = JTPL_CACHE_PATH . $filename; 108 109 $mustCompile = $GLOBALS['jTplConfig']['compilation_force']['force'] || !file_exists($cachefile); 110 if (!$mustCompile) { 111 if (filemtime($tpl) > filemtime($cachefile)) { 112 $mustCompile = true; 113 } 114 } 115 116 if ($mustCompile) { 103 117 include_once(JTPL_PATH . 'jTplCompiler.class.php'); 104 105 $compiler = new jTplCompiler();106 $compiler->compile($tpl); 107 }108 require_once($cachefile);109 $fct = 'template_'.md5($tpl);118 119 $compiler = new jTplCompiler(); 120 $compiler->compile($tpl); 121 } 122 require_once($cachefile); 123 $fct = 'template_'.md5($tpl); 110 124 #endif 111 125 $fct($this); trunk/lib/jelix/utils/jDatatype.class.php
r97 r126 115 115 */ 116 116 class jDatatypeBoolean extends jDatatype { 117 protected function _checkType($value) { return ($value == 'true' || $value=='false'); } ;117 protected function _checkType($value) { return ($value == 'true' || $value=='false'); } 118 118 protected function _checkValueFacets($value){ return true; } 119 119 protected function _checkFacets($value){ return true; } trunk/Makefile
r124 r126 11 11 12 12 ifeq ($(LIB_VERSION),SVN) 13 SVN_REVISION = $(shell svn info | grep "Revision"| cut -d " " -f 2)13 SVN_REVISION = $(shell svn info | grep -E "Revision|R�sion" -m 1 | cut -d ":" -f 2 | cut -d " " -f 2) 14 14 LIB_VERSION=SVN-$(SVN_REVISION) 15 15 endif 16 16 17 17 ifeq ($(JTPL_VERSION),SVN) 18 SVN_REVISION = $(shell svn info | grep "Revision"| cut -d " " -f 2)18 SVN_REVISION = $(shell svn info | grep -E "Revision|R�sion" -m 1 | cut -d ":" -f 2 | cut -d " " -f 2) 19 19 JTPL_VERSION=SVN-$(SVN_REVISION) 20 20 endif … … 29 29 30 30 default: 31 @echo "target: dist-all dist-jelix dist-testapp dist-myapp dev-all dev-jelix dev-myapp dev-testapp jtpl jtpl-dist" 31 @echo "target: " 32 @echo " dist-all dist-jelix dist-testapp dist-myapp" 33 @echo " dev-all dev-jelix dev-jelix-lib dev-myapp dev-testapp" 34 @echo " jtpl jtpl-dist" 35 @echo "param�es facultatifs (valeurs actuelles) :" 36 @echo " DIST : repertoire cible (" $(DIST) ")" 37 @echo " LIB_VERSION : num� de version de Jelix (" $(LIB_VERSION) ")" 38 @echo " JTPL_VERSION : num� de version de jtpl standalone (" $(JTPL_VERSION) ")" 39 @echo "r�rtoire de construction des projets:" 40 @echo " distributions jelix testapp myapp : " $(DISTJELIX) 41 @echo " developpement jelix testapp myapp : " $(DISTHACKER) 42 @echo " distribution jtpl : " $(DISTJTPL) 32 43 33 44 dist-all: dist-jelix dist-testapp dist-myapp jtpl-dist trunk/testapp/modules/testapp/controllers/forms.classic.php
r125 r126 23 23 function newform(){ 24 24 // cr�ion d'un formulaire vierge 25 $form = jForm ::create('sample');25 $form = jForms::create('sample'); 26 26 $rep= $this->getResponse("redirect"); 27 27 $rep->action="forms_show"; … … 32 32 33 33 function edit(){ 34 $form = jForm ::create('sample', 'id');34 $form = jForms::create('sample', 'id'); 35 35 // remplissage... 36 36 $rep= $this->getResponse("redirect"); … … 42 42 function show(){ 43 43 // recup� les donn� du formulaire dont l'id est dans le param�e id 44 $form = jForm ::get('sample','id');44 $form = jForms::get('sample','id'); 45 45 46 46 $rep = $this->getResponse('html'); … … 48 48 49 49 $tpl = new jTpl(); 50 $tpl->assign('form ulaire', $form);50 $tpl->assign('form', $form->getContainer()); 51 51 $rep->body->assign('MAIN',$tpl->fetch('sampleform')); 52 52 … … 65 65 66 66 function ok(){ 67 $form = jForms::get('sample','id'); 68 $datas=$form->getContainer()->datas; 69 67 70 $rep = $this->getResponse('html'); 68 71 $rep->title = 'Edition d\'un formulaire'; 69 $rep->body->assign('MAIN','<p>Fin du formulaire</p>'); 72 $tpl = new jTpl(); 73 $tpl->assign('nom', $datas['nom']); 74 $tpl->assign('prenom', $datas['prenom']); 75 76 77 78 $rep->body->assign('MAIN',$tpl->fetch('sampleformresult')); 70 79 return $rep; 71 80 } trunk/testapp/modules/testapp/controllers/main.classic.php
r101 r126 15 15 function index(){ 16 16 17 $rep = $this->getResponse('html'); 18 $rep->title = 'Accueil de TestApp'; 19 $rep->body->assignZone('MAIN','sommaire'); 20 return $rep; 21 } 22 23 function hello(){ 24 17 25 if($this->param('output') == 'text'){ 18 26 $rep = $this->getResponse('text'); … … 29 37 return $rep; 30 38 } 39 31 40 32 41 function testdao(){ trunk/testapp/modules/testapp/templates/hello.tpl
r71 r126 1 1 <h1>Hello {$person|upper} !</h1> 2 <p>Ceci est une simple page g�r�par {@jelix~jelix.framework.$value@}</p> 2 3 <p>This is a sample html page generated by {@jelix~jelix.framework.$value@}</p> 3 <p><a href="?module=unittest">Tests unitaires</a></p> 4 <p>D�s <a href="{jurl 'main_hello',array('person'=>'Bob')}">bonjour �ob</a>.</p> 5 6 7 <p><a href="{jurl 'main_index'}">Retour au sommaire</a></p> trunk/testapp/modules/testapp/templates/sampleform.tpl
r125 r126 6 6 <legend>Votre identit�legend> 7 7 <input type="hidden" name="id" value="{$form->id}" /> 8 <p><label for="nom">Nom :</label> <input type="text" name="nom" id="nom" /></p>9 <p><label for="prenom">Prenom :</label> <input type="text" name="prenom" id="prenom" /></p>8 <p><label for="nom">Nom :</label> <input type="text" name="nom" id="nom" value="{$form->datas['nom']}"/></p> 9 <p><label for="prenom">Prenom :</label> <input type="text" name="prenom" id="prenom" value="{$form->datas['prenom']}" /></p> 10 10 11 11 </fieldset> trunk/testapp/responses/myHtmlResponse.class.php
r67 r126 23 23 protected function _commonProcess(){ 24 24 $this->title .= ($this->title !=''?' - ':'').' My Test App !'; 25 26 $this->body->assignIfNone('person','you'); 27 $this->body->assignIfNone('MAIN','<p>No content</p>'); 25 28 } 26 29 }
