Changeset 442

Show
Ignore:
Timestamp:
05/22/07 23:18:05 (2 years ago)
Author:
laurentj
Message:

work on jforms: new jtpl plugins to display label and html controls

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/experimental/jforms/build/manifests/jelix-lib.mn

    r441 r442  
    155155  function.diff.php 
    156156  block.form.php 
     157  block.formcontrols.php 
     158  function.ctrl_control.php 
     159  function.ctrl_label.php 
     160  function.ctrl_value.php 
    157161 
    158162cd lib/jelix/tpl/plugins/ltx2pdf 
  • branches/experimental/jforms/build/manifests/jelix-lib.mn

    r441 r442  
    155155  function.diff.php 
    156156  block.form.php 
     157  block.formcontrols.php 
     158  function.ctrl_control.php 
     159  function.ctrl_label.php 
     160  function.ctrl_value.php 
    157161 
    158162cd lib/jelix/tpl/plugins/ltx2pdf 
  • branches/experimental/jforms/lib/jelix/docs/ns/jforms-controls.rng

    r437 r442  
    3838         <attribute name="appearance"> 
    3939             <choice> 
    40                  <value>full</value> 
    41                  <value>compact</value> 
    42                  <value>minimal</value> 
     40                 <value>full</value>  checkbox /radiobox 
     41                 <value>compact</value> listbox multiple /listbox 
     42                 <value>minimal</value>  listbox multiple / combobox 
    4343             </choice> 
    4444         </attribute> 
     
    150150       <ref name="UI.Common" /> 
    151151       <ref name="List.UI.Common" /> 
    152         <optional> 
     152       <optional> 
     153         <attribute name="appearance"> 
     154             <choice> 
     155                 <value>full</value> 
     156                 <value>radiobox</value> 
     157                 <value>compact</value> 
     158                 <value>listbox</value> 
     159                 <value>minimal</value> 
     160                 <value>menulist</value> 
     161             </choice> 
     162         </attribute> 
     163      </optional>  
     164 
     165       <!-- <optional> 
    153166           <attribute name="selection"> 
    154167             <choice> 
     
    157170              </choice> 
    158171           </attribute> 
    159        </optional> 
     172       </optional>--> 
    160173     </element> 
    161174  </define> 
     
    167180       <ref name="List.UI.Common" /> 
    168181       <optional> 
     182         <attribute name="appearance"> 
     183             <choice> 
     184                 <value>full</value> 
     185                 <value>checkbox</value> 
     186                 <value>compact</value> 
     187                 <value>listbox</value> 
     188             </choice> 
     189         </attribute> 
     190      </optional>  
     191       <!--<optional> 
    169192           <attribute name="selection"> 
    170193             <choice> 
     
    173196              </choice> 
    174197           </attribute> 
    175        </optional> 
     198       </optional>--> 
    176199     </element> 
    177200  </define> 
  • branches/experimental/jforms/lib/jelix/docs/ns/jforms-controls.rng

    r437 r442  
    3838         <attribute name="appearance"> 
    3939             <choice> 
    40                  <value>full</value> 
    41                  <value>compact</value> 
    42                  <value>minimal</value> 
     40                 <value>full</value>  checkbox /radiobox 
     41                 <value>compact</value> listbox multiple /listbox 
     42                 <value>minimal</value>  listbox multiple / combobox 
    4343             </choice> 
    4444         </attribute> 
     
    150150       <ref name="UI.Common" /> 
    151151       <ref name="List.UI.Common" /> 
    152         <optional> 
     152       <optional> 
     153         <attribute name="appearance"> 
     154             <choice> 
     155                 <value>full</value> 
     156                 <value>radiobox</value> 
     157                 <value>compact</value> 
     158                 <value>listbox</value> 
     159                 <value>minimal</value> 
     160                 <value>menulist</value> 
     161             </choice> 
     162         </attribute> 
     163      </optional>  
     164 
     165       <!-- <optional> 
    153166           <attribute name="selection"> 
    154167             <choice> 
     
    157170              </choice> 
    158171           </attribute> 
    159        </optional> 
     172       </optional>--> 
    160173     </element> 
    161174  </define> 
     
    167180       <ref name="List.UI.Common" /> 
    168181       <optional> 
     182         <attribute name="appearance"> 
     183             <choice> 
     184                 <value>full</value> 
     185                 <value>checkbox</value> 
     186                 <value>compact</value> 
     187                 <value>listbox</value> 
     188             </choice> 
     189         </attribute> 
     190      </optional>  
     191       <!--<optional> 
    169192           <attribute name="selection"> 
    170193             <choice> 
     
    173196              </choice> 
    174197           </attribute> 
    175        </optional> 
     198       </optional>--> 
    176199     </element> 
    177200  </define> 
  • branches/experimental/jforms/lib/jelix/forms/jFormsBuilderBase.class.php

    r441 r442  
    5555    } 
    5656 
     57    public function getName(){ return  $this->_name; } 
    5758 
    5859    abstract public function outputHeader(); 
    5960 
    6061    abstract public function outputFooter(); 
     62 
     63    abstract public function outputControl($ctrl); 
     64    abstract public function outputControlLabel($ctrl); 
    6165 
    6266    public static function generateFormName(){ 
     
    8791    } 
    8892 
     93    public function outputControlLabel($ctrl){ 
     94        if($ctrl->type == 'output'){ 
     95            echo htmlspecialchars($ctrl->label); 
     96        } 
     97        if($ctrl->type != 'submit'){ 
     98            $id = $this->_name.'_'.$ctrl->ref; 
     99            echo '<label for="'.$id.'">'.htmlspecialchars($ctrl->label).'</label>'; 
     100        } 
     101    } 
     102 
     103    public function outputControl($ctrl){ 
     104        $id = 'name="'.$ctrl->ref.'" id="'$this->_name.'_'.$ctrl->ref.'"'; 
     105        $readonly = ($ctrl->readonly?' readonly="readonly"':''); 
     106        switch($ctrl->type){ 
     107        case 'input': 
     108            echo '<input type="text" ',$id,$readonly,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
     109            break; 
     110        case 'select1': 
     111            break; 
     112        case 'select': 
     113            break; 
     114        case 'textarea': 
     115            echo '<textarea ',$id,$readonly,'>',htmlspecialchars($this->_form->getData($ctrl->ref)),'</textarea>'; 
     116            break; 
     117        case 'secret': 
     118            echo '<input type="password" ',$id,$readonly,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
     119            break; 
     120        case 'output': 
     121            echo '<input type="hidden" ',$id,$readonly,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
     122            echo htmlspecialchars($this->_form->getData($ctrl->ref)); 
     123            break; 
     124        case 'upload': 
     125            echo '<input type="file" ',$id,$readonly,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
     126            break; 
     127        case 'submit': 
     128            echo '<button type="submit" ',$id,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'">',htmlspecialchars($ctrl->label),'</button>'; 
     129            break; 
     130        } 
     131    } 
     132 
     133 
    89134    abstract public function getJavascriptCheck(); 
    90135} 
  • branches/experimental/jforms/lib/jelix/forms/jFormsBuilderBase.class.php

    r441 r442  
    5555    } 
    5656 
     57    public function getName(){ return  $this->_name; } 
    5758 
    5859    abstract public function outputHeader(); 
    5960 
    6061    abstract public function outputFooter(); 
     62 
     63    abstract public function outputControl($ctrl); 
     64    abstract public function outputControlLabel($ctrl); 
    6165 
    6266    public static function generateFormName(){ 
     
    8791    } 
    8892 
     93    public function outputControlLabel($ctrl){ 
     94        if($ctrl->type == 'output'){ 
     95            echo htmlspecialchars($ctrl->label); 
     96        } 
     97        if($ctrl->type != 'submit'){ 
     98            $id = $this->_name.'_'.$ctrl->ref; 
     99            echo '<label for="'.$id.'">'.htmlspecialchars($ctrl->label).'</label>'; 
     100        } 
     101    } 
     102 
     103    public function outputControl($ctrl){ 
     104        $id = 'name="'.$ctrl->ref.'" id="'$this->_name.'_'.$ctrl->ref.'"'; 
     105        $readonly = ($ctrl->readonly?' readonly="readonly"':''); 
     106        switch($ctrl->type){ 
     107        case 'input': 
     108            echo '<input type="text" ',$id,$readonly,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
     109            break; 
     110        case 'select1': 
     111            break; 
     112        case 'select': 
     113            break; 
     114        case 'textarea': 
     115            echo '<textarea ',$id,$readonly,'>',htmlspecialchars($this->_form->getData($ctrl->ref)),'</textarea>'; 
     116            break; 
     117        case 'secret': 
     118            echo '<input type="password" ',$id,$readonly,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
     119            break; 
     120        case 'output': 
     121            echo '<input type="hidden" ',$id,$readonly,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
     122            echo htmlspecialchars($this->_form->getData($ctrl->ref)); 
     123            break; 
     124        case 'upload': 
     125            echo '<input type="file" ',$id,$readonly,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
     126            break; 
     127        case 'submit': 
     128            echo '<button type="submit" ',$id,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'">',htmlspecialchars($ctrl->label),'</button>'; 
     129            break; 
     130        } 
     131    } 
     132 
     133 
    89134    abstract public function getJavascriptCheck(); 
    90135} 
  • branches/experimental/jforms/lib/jelix/forms/jFormsCompiler.class.php

    r441 r442  
    132132             $label=''; 
    133133             $labellocale=(string)$control->label['locale']; 
    134              $source[]='$ctrl->labellocale=\''.$labellocale.'\';'; 
     134             $source[]='$ctrl->label=jLocale::get(\''.$labellocale.'\');'; 
    135135         }else{ 
    136136             $label=(string)$control->label; 
     
    201201        } 
    202202 
    203 /*          
    204  
     203/* 
    205204         switch($controltype){ 
    206205            case 'secret': 
     
    301300        $js.="jForms.declareForm(gForm);\n"; 
    302301 
    303         // le code php qui génère le php 
    304  
    305         $js="gForm = new jFormsForm('".$this->getFormName()."');\n"; 
    306         $js.="gForm.setDecorator(new jFormsErrorDecoratorAlert());\n"; 
    307         $label = 'a label'; 
    308         ou 
    309         $label = jLocale::get('mod~cle_locale_user'); 
    310         $js.="gControl = new jFormsControl('name', '".str_replace("'","\\'", $label)."', 'datatype');\n"; 
    311         $js.="gControl.required = true;\n"; 
    312  
    313         $invalid = jLocale::get('jelix~forms.check.invalid',$label)); 
    314         ou 
    315         $invalid = jLocale::get('mod~cle_locale_user'); 
    316         ou 
    317         $invalid = 'bla bla'; 
    318         $js.="gControl.errInvalid='".str_replace("'","\\'",$invalid)."';\n"; 
    319  
    320  
    321         $required = jLocale::get('jelix~forms.check.required',$label)); 
    322         ou 
    323         $required = jLocale::get('mod~cle_locale_user'); 
    324         ou 
    325         $required = 'bla bla'; 
    326  
    327         $js.="gControl.errRequired='".str_replace("'","\\'",$required)."';\n"; 
    328         $js.="gForm.addControl( gControl);\n"; 
    329         ... 
    330         $js.="jForms.declareForm(gForm);\n"; 
    331  
    332  
    333  
    334302        */ 
    335  
    336      
    337303} 
    338304 
    339 /** 
    340  * 
    341  * @package     jelix 
    342  * @subpackage  forms 
    343  * @experimental 
    344  */ 
    345 interface jIFormGenerator { 
    346  
    347    // on indique un objet form 
    348    // il renvoi dans un tableau le code généré correspondant 
    349    /* 
    350    startform : code généré pour le debut du formulaire (balise <form> en html) Peut contenir %ATTR% 
    351    head : code généré à ajouter dans l'en-tête de page 
    352    controls : tableau assoc de chaque contrôle généré. Peuvent contenir %ATTR% 
    353    endform : code généré pour la fin du formulaire 
    354  
    355  
    356    %ATTR% : remplacés par les attributs supplémentaires indiqués par l'utilisateur dans le template 
    357    */ 
    358    function buildForm($formObject); 
    359  
    360 } 
    361  
    362  
    363305?> 
  • branches/experimental/jforms/lib/jelix/forms/jFormsCompiler.class.php

    r441 r442  
    132132             $label=''; 
    133133             $labellocale=(string)$control->label['locale']; 
    134              $source[]='$ctrl->labellocale=\''.$labellocale.'\';'; 
     134             $source[]='$ctrl->label=jLocale::get(\''.$labellocale.'\');'; 
    135135         }else{ 
    136136             $label=(string)$control->label; 
     
    201201        } 
    202202 
    203 /*          
    204  
     203/* 
    205204         switch($controltype){ 
    206205            case 'secret': 
     
    301300        $js.="jForms.declareForm(gForm);\n"; 
    302301 
    303         // le code php qui génère le php 
    304  
    305         $js="gForm = new jFormsForm('".$this->getFormName()."');\n"; 
    306         $js.="gForm.setDecorator(new jFormsErrorDecoratorAlert());\n"; 
    307         $label = 'a label'; 
    308         ou 
    309         $label = jLocale::get('mod~cle_locale_user'); 
    310         $js.="gControl = new jFormsControl('name', '".str_replace("'","\\'", $label)."', 'datatype');\n"; 
    311         $js.="gControl.required = true;\n"; 
    312  
    313         $invalid = jLocale::get('jelix~forms.check.invalid',$label)); 
    314         ou 
    315         $invalid = jLocale::get('mod~cle_locale_user'); 
    316         ou 
    317         $invalid = 'bla bla'; 
    318         $js.="gControl.errInvalid='".str_replace("'","\\'",$invalid)."';\n"; 
    319  
    320  
    321         $required = jLocale::get('jelix~forms.check.required',$label)); 
    322         ou 
    323         $required = jLocale::get('mod~cle_locale_user'); 
    324         ou 
    325         $required = 'bla bla'; 
    326  
    327         $js.="gControl.errRequired='".str_replace("'","\\'",$required)."';\n"; 
    328         $js.="gForm.addControl( gControl);\n"; 
    329         ... 
    330         $js.="jForms.declareForm(gForm);\n"; 
    331  
    332  
    333  
    334302        */ 
    335  
    336      
    337303} 
    338304 
    339 /** 
    340  * 
    341  * @package     jelix 
    342  * @subpackage  forms 
    343  * @experimental 
    344  */ 
    345 interface jIFormGenerator { 
    346  
    347    // on indique un objet form 
    348    // il renvoi dans un tableau le code généré correspondant 
    349    /* 
    350    startform : code généré pour le debut du formulaire (balise <form> en html) Peut contenir %ATTR% 
    351    head : code généré à ajouter dans l'en-tête de page 
    352    controls : tableau assoc de chaque contrôle généré. Peuvent contenir %ATTR% 
    353    endform : code généré pour la fin du formulaire 
    354  
    355  
    356    %ATTR% : remplacés par les attributs supplémentaires indiqués par l'utilisateur dans le template 
    357    */ 
    358    function buildForm($formObject); 
    359  
    360 } 
    361  
    362  
    363305?> 
  • branches/experimental/jforms/lib/jelix/forms/jFormsControl.class.php

    r432 r442  
    2323   public $readonly=false; 
    2424   public $label=''; 
    25    public $labellocale=''; 
    2625 
    2726   public $value=''; 
  • branches/experimental/jforms/lib/jelix/forms/jFormsControl.class.php

    r432 r442  
    2323   public $readonly=false; 
    2424   public $label=''; 
    25    public $labellocale=''; 
    2625 
    2726   public $value=''; 
  • branches/experimental/jforms/lib/jelix/tpl/jTpl.class.php

    r436 r442  
    2323     */ 
    2424    public $_vars = array (); 
     25 
     26    /** 
     27     * temporary template variables for plugins. Public because Internal use. Don't touch it :-) 
     28     * @var array 
     29     */ 
     30    public $_privateVars = array (); 
     31 
    2532 
    2633    /** 
  • branches/experimental/jforms/lib/jelix/tpl/jTpl.class.php

    r436 r442  
    2323     */ 
    2424    public $_vars = array (); 
     25 
     26    /** 
     27     * temporary template variables for plugins. Public because Internal use. Don't touch it :-) 
     28     * @var array 
     29     */ 
     30    public $_privateVars = array (); 
     31 
    2532 
    2633    /** 
  • branches/experimental/jforms/lib/jelix/tpl/plugins/html/block.form.php

    r441 r442  
    2424 
    2525    if(!$begin){ 
    26         return '$builder->outputFooter(); $form = null; $builder=null;'; 
     26        return '$t->_privateVars[\'__builder\']->outputFooter();  
     27unset($t->_privateVars[\'__form\']);  
     28unset($t->_privateVars[\'__builder\']);'; 
    2729    } 
    2830 
     
    3537    } 
    3638 
    37     $content = ' $form = '.$param[0].'; 
    38 $builder = $form->getBuilder(\'html\', '.$param[1].','.$param[2].'); 
    39 $builder->outputHeader(); 
     39    $content = ' $t->_privateVars[\'__form\'] = '.$param[0].'; 
     40$t->_privateVars[\'__builder\'] = $t->_privateVars[\'__form\']->getBuilder(\'html\', '.$param[1].','.$param[2].'); 
     41$t->_privateVars[\'__builder\']->outputHeader(); 
    4042'; 
    4143 
  • branches/experimental/jforms/lib/jelix/tpl/plugins/html/block.form.php

    r441 r442  
    2424 
    2525    if(!$begin){ 
    26         return '$builder->outputFooter(); $form = null; $builder=null;'; 
     26        return '$t->_privateVars[\'__builder\']->outputFooter();  
     27unset($t->_privateVars[\'__form\']);  
     28unset($t->_privateVars[\'__builder\']);'; 
    2729    } 
    2830 
     
    3537    } 
    3638 
    37     $content = ' $form = '.$param[0].'; 
    38 $builder = $form->getBuilder(\'html\', '.$param[1].','.$param[2].'); 
    39 $builder->outputHeader(); 
     39    $content = ' $t->_privateVars[\'__form\'] = '.$param[0].'; 
     40$t->_privateVars[\'__builder\'] = $t->_privateVars[\'__form\']->getBuilder(\'html\', '.$param[1].','.$param[2].'); 
     41$t->_privateVars[\'__builder\']->outputHeader(); 
    4042'; 
    4143 
  • branches/experimental/jforms/testapp/modules/testapp/controllers/sampleform.classic.php

    r441 r442  
    5353 
    5454      if($form){ 
    55         $datas=$form->getContainer()->datas; 
    56          
    5755        $tpl = new jTpl(); 
    58         $tpl->assign('nom', $datas['nom']); 
    59         $tpl->assign('prenom', $datas['prenom']); 
     56        $tpl->assign('form', $form); 
    6057        $rep->body->assign('MAIN',$tpl->fetch('sampleformresult')); 
    6158      }else{ 
  • branches/experimental/jforms/testapp/modules/testapp/controllers/sampleform.classic.php

    r441 r442  
    5353 
    5454      if($form){ 
    55         $datas=$form->getContainer()->datas; 
    56          
    5755        $tpl = new jTpl(); 
    58         $tpl->assign('nom', $datas['nom']); 
    59         $tpl->assign('prenom', $datas['prenom']); 
     56        $tpl->assign('form', $form); 
    6057        $rep->body->assign('MAIN',$tpl->fetch('sampleformresult')); 
    6158      }else{ 
  • branches/experimental/jforms/testapp/modules/testapp/forms/sample.form.xml

    r436 r442  
    1 <?xml version="1.0" encoding="iso-8859-1"?> 
     1<?xml version="1.0" encoding="utf-8"?> 
    22<forms xmlns="http://jelix.org/ns/forms/1.0"> 
    33 
  • branches/experimental/jforms/testapp/modules/testapp/forms/sample.form.xml

    r436 r442  
    1 <?xml version="1.0" encoding="iso-8859-1"?> 
     1<?xml version="1.0" encoding="utf-8"?> 
    22<forms xmlns="http://jelix.org/ns/forms/1.0"> 
    33 
  • branches/experimental/jforms/testapp/modules/testapp/templates/sampleform.tpl

    r441 r442  
    44<fieldset> 
    55   <legend>Votre identité</legend> 
    6     <p><label for="nom">Nom :</label> <input type="text" name="nom" id="nom" value="{$form->getData('nom')}"/></p> 
    7     <p><label for="prenom">Prenom :</label> <input type="text" name="prenom" id="prenom" value="{$form->getData('prenom')}" /></p> 
    8  
     6    {formcontrols} 
     7    <p>{ctrl_label}: {ctrl_control}</p> 
     8    {/formcontrols} 
    99</fieldset> 
    1010<p><input type="submit" value="ok" /></p> 
  • branches/experimental/jforms/testapp/modules/testapp/templates/sampleform.tpl

    r441 r442  
    44<fieldset> 
    55   <legend>Votre identité</legend> 
    6     <p><label for="nom">Nom :</label> <input type="text" name="nom" id="nom" value="{$form->getData('nom')}"/></p> 
    7     <p><label for="prenom">Prenom :</label> <input type="text" name="prenom" id="prenom" value="{$form->getData('prenom')}" /></p> 
    8  
     6    {formcontrols} 
     7    <p>{ctrl_label}: {ctrl_control}</p> 
     8    {/formcontrols} 
    99</fieldset> 
    1010<p><input type="submit" value="ok" /></p> 
  • branches/experimental/jforms/testapp/modules/testapp/templates/sampleformresult.tpl

    r310 r442  
    22<p>Contenu du formulaire :</p> 
    33<dl> 
    4    <dt>Nom :</dt> 
    5    <dd>{$nom}</dd
    6    <dt>Prenom :</dt
    7    <dd>{$prenom}</dd> 
     4    {formcontrols $form} 
     5    <dt>{ctrl_label}</dt
     6    <dd>{ctrl_value}</dd
     7    {/formcontrols} 
    88</dl> 
  • branches/experimental/jforms/testapp/modules/testapp/templates/sampleformresult.tpl

    r310 r442  
    22<p>Contenu du formulaire :</p> 
    33<dl> 
    4    <dt>Nom :</dt> 
    5    <dd>{$nom}</dd
    6    <dt>Prenom :</dt
    7    <dd>{$prenom}</dd> 
     4    {formcontrols $form} 
     5    <dt>{ctrl_label}</dt
     6    <dd>{ctrl_value}</dd
     7    {/formcontrols} 
    88</dl> 
  • branches/experimental/jforms/testapp/modules/unittest/classes/utjforms.class.php

    r439 r442  
    1431433=>'$ctrl= new jFormsControlinput(\'nom\'); 
    144144$ctrl->datatype= new jDatatypeString(); 
    145 $ctrl->labellocale=\'foo~bar\'
     145$ctrl->label=jLocale::get(\'foo~bar\')
    146146$this->addControl($ctrl);', 
    147147 
  • branches/experimental/jforms/testapp/modules/unittest/classes/utjforms.class.php

    r439 r442  
    1431433=>'$ctrl= new jFormsControlinput(\'nom\'); 
    144144$ctrl->datatype= new jDatatypeString(); 
    145 $ctrl->labellocale=\'foo~bar\'
     145$ctrl->label=jLocale::get(\'foo~bar\')
    146146$this->addControl($ctrl);', 
    147147 
Download in other formats: Unified Diff Zip Archive