Changeset 126

Show
Ignore:
Timestamp:
04/01/06 23:09:19 (3 years ago)
Author:
laurentj
Message:

premier essai de jforms, ajout aide dans le makefile, cd dans les mn creer le repertoire, testapp page d'accueil, prise en compte des slash t slash n dans messageLogFormat, affichage des erreurs pour les réponses jResponseRedirect*, ajout jtpl assignIfNone

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/build/manifests/jelix-lib.mn

    r113 r126  
    8686  jEventListener.class.php 
    8787  jEventListenerFactory.class.php 
     88 
     89cd 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 
    8896 
    8997cd lib/jelix/tpl/ 
     
    129137  jXmlRpc.class.php 
    130138  jZone.class.php 
     139  jDatatype.class.php 
    131140 
    132141cd lib/json 
  • trunk/build/manifests/testapp.mn

    r101 r126  
    3333cd testapp/modules/testapp/controllers 
    3434  main.classic.php 
     35  forms.classic.php 
    3536cd testapp/modules/testapp/templates 
    3637  hello.tpl 
    3738  main.tpl 
    38   blank.tpl 
    3939  error.tpl 
    4040  testzone.tpl 
     41  sommaire.tpl 
     42  sampleform.tpl 
     43  sampleformresult.tpl 
    4144cd testapp/modules/testapp/zones 
    4245  test.zone.php 
     46  sommaire.zone.php 
     47cd testapp/modules/testapp/forms 
     48  sample.form.xml 
    4349cd testapp/modules/unittest 
    4450  events.xml 
     
    7076cd testapp/var/themes/default/testapp 
    7177  main.tpl 
     78cd testapp/var/overloads/testapp/daos 
     79cd testapp/var/overloads/testapp/locales 
     80 
  • trunk/build/mkdist.php

    r85 r126  
    3535    $sw = substr(array_shift($_SERVER['argv']),1); 
    3636    if($sw{0} =='D'){ 
    37        
     37 
    3838    }else{ 
    3939      $options['verbose'] = (strpos('v', $sw) !== false); 
    40     }     
     40    } 
    4141  }else{ 
    4242    break; 
     
    7575    if($m[1] == 'dd'){ 
    7676      $currentdestdir = normalizeDir($m[2]); 
     77      createDir($distdir.$currentdestdir); 
    7778    }elseif($m[1] == 'sd'){ 
    7879      $currentsrcdir = normalizeDir($m[2]); 
     
    8081      $currentsrcdir = normalizeDir($m[2]); 
    8182      $currentdestdir = normalizeDir($m[2]); 
     83      createDir($distdir.$currentdestdir); 
    8284    }else{ 
    8385      if($m[2] == ''){ 
     
    8991 
    9092      $destfile = $distdir.$currentdestdir.$m[3]; 
    91       createDir(dirname($destfile)); 
    9293 
    9394      if($m[1]=='*'){ 
  • trunk/lib/jelix/core/jErrorHandler.lib.php

    r121 r126  
    6565        '%msg%'  => $errmsg, 
    6666        '%file%' => $filename, 
    67         '%line%' => $linenum 
     67        '%line%' => $linenum, 
     68        '\t' =>"\t", 
     69        '\n' => "\n" 
    6870    )); 
    6971 
  • trunk/lib/jelix/core/response/jResponseRedirect.class.php

    r121 r126  
    3131 
    3232    public function output(){ 
    33         if($this->hasErrors()) return false; 
     33       if($this->hasErrors()) return false; 
     34 
    3435        header ('location: '.jUrl::get($this->action, $this->params)); 
    3536        return true; 
     
    3738 
    3839    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); 
    4142    } 
    4243 
    4344    public function outputErrors(){ 
    44  
     45         include_once(JELIX_LIB_RESPONSE_PATH.'jResponseHtml.class.php'); 
     46         $resp = new jResponseHtml(); 
     47         $resp->outputErrors(); 
    4548    } 
    4649 
  • trunk/lib/jelix/core/response/jResponseRedirectUrl.class.php

    r121 r126  
    2525 
    2626    public function output(){ 
    27         if($this->hasErrors()) return false; 
     27       if($this->hasErrors())  return false; 
    2828        header ('location: '.$this->url); 
    2929        return true; 
     
    3636    public function fetch(){ 
    3737       if($this->hasErrors()) return false; 
    38            return 'location: '.$this->url; 
     38       return 'location: '.$this->url; 
    3939    } 
    4040 
    4141    public function outputErrors(){ 
    42  
     42         include_once(JELIX_LIB_RESPONSE_PATH.'jResponseHtml.class.php'); 
     43         $resp = new jResponseHtml(); 
     44         $resp->outputErrors(); 
    4345    } 
    4446 
  • trunk/lib/jelix/forms/jForms.class.php

    r97 r126  
    1212 
    1313define('JFORMS_ID_PARAM','__forms_id__'); 
    14  
    15  
     14require_once(JELIX_LIB_FORMS_PATH.'jFormsBase.class.php'); 
     15require_once(JELIX_LIB_FORMS_PATH.'jFormsControl.class.php'); 
     16require_once(JELIX_LIB_UTILS_PATH.'jDatatype.class.php'); 
    1617/** 
    1718 * Classe abstraite pour g�r un formulaire 
    1819 */ 
    19 abstract class jForms { 
     20class jForms { 
    2021 
    21    //------------- m�odes statiques 
     22   private function __construct(){ } 
    2223 
    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); 
    2547      jIncluder::inc($sel); 
    2648      $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; 
    2859   } 
    2960 
    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 statiques 
    45  
    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 jFormsControl 
    76    */ 
    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 DAO 
    106  */ 
    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    } 
    12261 
    12362} 
  • trunk/lib/jelix/forms/jFormsCompiler.class.php

    r97 r126  
    3535 
    3636      $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); '; 
    3940      foreach($xml->children() as $controltype=>$control){ 
    4041 
     
    104105      } 
    105106 
    106       $source[]=' }'; 
     107      $source[]='  }'; 
     108 
     109      $source[]=' public function save(){ } '; 
     110 
    107111      $source[]='} ?>'; 
    108112 
  • trunk/lib/jelix/forms/jFormsDataContainer.class.php

    r86 r126  
    1212 
    1313class jFormsDataContainer { 
    14    private $datas = array(); 
    15    private $id; 
    16    private $formSelector; 
     14   public $datas = array(); 
     15   public $id; 
     16   public $formSelector; 
    1717 
    1818   function __construct($id, $formSelector){ 
     
    2121   } 
    2222 
    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){ 
    4624      unset($this->datas[$name]); 
    4725   } 
  • trunk/lib/jelix/tpl/jTpl.class.php

    r124 r126  
    4444        } 
    4545    } 
     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 
    4660#ifndef JTPL_STANDALONE 
    4761    function assignZone($name, $zoneName, $params=array()){ 
     
    90104#else 
    91105        $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) { 
    103117            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); 
    110124#endif 
    111125        $fct($this); 
  • trunk/lib/jelix/utils/jDatatype.class.php

    r97 r126  
    115115 */ 
    116116class jDatatypeBoolean extends jDatatype { 
    117   protected function _checkType($value) { return ($value == 'true' || $value=='false'); }; 
     117  protected function _checkType($value) { return ($value == 'true' || $value=='false'); } 
    118118  protected function _checkValueFacets($value){ return true; } 
    119119  protected function _checkFacets($value){ return true; } 
  • trunk/Makefile

    r124 r126  
    1111 
    1212ifeq ($(LIB_VERSION),SVN) 
    13 SVN_REVISION = $(shell svn info | grep "Revision" | cut -d " " -f 2) 
     13SVN_REVISION = $(shell svn info | grep -E "Revision|R�sion" -m 1 | cut -d ":" -f 2 | cut -d " " -f 2) 
    1414LIB_VERSION=SVN-$(SVN_REVISION) 
    1515endif 
    1616 
    1717ifeq ($(JTPL_VERSION),SVN) 
    18 SVN_REVISION = $(shell svn info | grep "Revision" | cut -d " " -f 2) 
     18SVN_REVISION = $(shell svn info | grep -E "Revision|R�sion" -m 1 | cut -d ":" -f 2 | cut -d " " -f 2) 
    1919JTPL_VERSION=SVN-$(SVN_REVISION) 
    2020endif 
     
    2929 
    3030default: 
    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) 
    3243 
    3344dist-all: dist-jelix dist-testapp dist-myapp jtpl-dist 
  • trunk/testapp/modules/testapp/controllers/forms.classic.php

    r125 r126  
    2323  function newform(){ 
    2424      // cr�ion d'un formulaire vierge 
    25       $form = jForm::create('sample'); 
     25      $form = jForms::create('sample'); 
    2626      $rep= $this->getResponse("redirect"); 
    2727      $rep->action="forms_show"; 
     
    3232 
    3333  function edit(){ 
    34      $form = jForm::create('sample', 'id'); 
     34     $form = jForms::create('sample', 'id'); 
    3535     // remplissage... 
    3636     $rep= $this->getResponse("redirect"); 
     
    4242  function show(){ 
    4343      // 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'); 
    4545 
    4646      $rep = $this->getResponse('html'); 
     
    4848 
    4949      $tpl = new jTpl(); 
    50       $tpl->assign('formulaire', $form); 
     50      $tpl->assign('form', $form->getContainer()); 
    5151      $rep->body->assign('MAIN',$tpl->fetch('sampleform')); 
    5252 
     
    6565 
    6666   function ok(){ 
     67      $form = jForms::get('sample','id'); 
     68      $datas=$form->getContainer()->datas; 
     69 
    6770      $rep = $this->getResponse('html'); 
    6871      $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')); 
    7079      return $rep; 
    7180   } 
  • trunk/testapp/modules/testapp/controllers/main.classic.php

    r101 r126  
    1515  function index(){ 
    1616 
     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 
    1725      if($this->param('output') == 'text'){ 
    1826         $rep = $this->getResponse('text'); 
     
    2937      return $rep; 
    3038   } 
     39 
    3140 
    3241   function testdao(){ 
  • trunk/testapp/modules/testapp/templates/hello.tpl

    r71 r126  
    11<h1>Hello {$person|upper} !</h1> 
     2<p>Ceci est une simple page g�r�par {@jelix~jelix.framework.$value@}</p> 
    23<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  
    66   <legend>Votre identit�legend> 
    77    <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> 
    1010 
    1111</fieldset> 
  • trunk/testapp/responses/myHtmlResponse.class.php

    r67 r126  
    2323   protected function _commonProcess(){ 
    2424       $this->title .= ($this->title !=''?' - ':'').' My Test App !'; 
     25 
     26       $this->body->assignIfNone('person','you'); 
     27       $this->body->assignIfNone('MAIN','<p>No content</p>'); 
    2528   } 
    2629} 
Download in other formats: Unified Diff Zip Archive