Changeset 540

Show
Ignore:
Timestamp:
08/26/07 23:08:46 (1 year ago)
Author:
laurentj
Message:

ticket #209: implementation of confirmation for secret tag in jforms
made few improvements in jforms compilation

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix-www/js/jforms.js

    r530 r540  
    1313usage : 
    1414 
    15 gForm = new jFormsForm('name');                         // create a form descriptor 
    16 gForm.setErrorDecorator(new jFormsErrorDecoratorAlert());    // declare an error handler 
     15jForms.tForm = new jFormsForm('name');                         // create a form descriptor 
     16jForms.tForm.setErrorDecorator(new jFormsErrorDecoratorAlert());    // declare an error handler 
    1717 
    1818    // declare a form control 
    19 gControl = new jFormsControl('name', 'a label', 'datatype'); 
    20 gControl.required = true; 
    21 gControl.errInvalid=''; 
    22 gControl.errRequired=''; 
    23 gForm.addControl( gControl); 
     19jForms.tControl = new jFormsControl('name', 'a label', 'datatype'); 
     20jForms.tControl.required = true; 
     21jForms.tControl.errInvalid=''; 
     22jForms.tControl.errRequired=''; 
     23jForms.tForm.addControl( gControl); 
    2424... 
    2525 
    2626    // declare the form now 
    27 jForms.declareForm(gForm); 
     27jForms.declareForm(jForms.tForm); 
    2828 
    2929On a form tag : 
     
    3232*/ 
    3333 
    34  
    35 var gForm, gControl; 
    36  
    3734/* 
    3835 
     
    4037var jForms = { 
    4138    _forms: {}, 
     39 
     40    tForm: null, 
     41    tControl: null, 
     42    tControl2: null, 
    4243 
    4344    declareForm : function(aForm){ 
     
    202203                } 
    203204            } 
     205            if(c.isConfirmField){ 
     206                var val2 = this._getValue(frmElt.elements[c.confirmFieldOf]); 
     207                if(val != val2){ 
     208                    f.errorDecorator.addError(c, 2); 
     209                    valid = false; 
     210                } 
     211            } 
    204212        } 
    205213        if(!valid) 
     
    309317    this.errRequired = ''; 
    310318    this.help=''; 
     319    this.isConfirmField = false; 
     320    this.confirmFieldOf = ''; 
    311321} 
    312322 
  • trunk/lib/jelix-www/js/jforms.js

    r530 r540  
    1313usage : 
    1414 
    15 gForm = new jFormsForm('name');                         // create a form descriptor 
    16 gForm.setErrorDecorator(new jFormsErrorDecoratorAlert());    // declare an error handler 
     15jForms.tForm = new jFormsForm('name');                         // create a form descriptor 
     16jForms.tForm.setErrorDecorator(new jFormsErrorDecoratorAlert());    // declare an error handler 
    1717 
    1818    // declare a form control 
    19 gControl = new jFormsControl('name', 'a label', 'datatype'); 
    20 gControl.required = true; 
    21 gControl.errInvalid=''; 
    22 gControl.errRequired=''; 
    23 gForm.addControl( gControl); 
     19jForms.tControl = new jFormsControl('name', 'a label', 'datatype'); 
     20jForms.tControl.required = true; 
     21jForms.tControl.errInvalid=''; 
     22jForms.tControl.errRequired=''; 
     23jForms.tForm.addControl( gControl); 
    2424... 
    2525 
    2626    // declare the form now 
    27 jForms.declareForm(gForm); 
     27jForms.declareForm(jForms.tForm); 
    2828 
    2929On a form tag : 
     
    3232*/ 
    3333 
    34  
    35 var gForm, gControl; 
    36  
    3734/* 
    3835 
     
    4037var jForms = { 
    4138    _forms: {}, 
     39 
     40    tForm: null, 
     41    tControl: null, 
     42    tControl2: null, 
    4243 
    4344    declareForm : function(aForm){ 
     
    202203                } 
    203204            } 
     205            if(c.isConfirmField){ 
     206                var val2 = this._getValue(frmElt.elements[c.confirmFieldOf]); 
     207                if(val != val2){ 
     208                    f.errorDecorator.addError(c, 2); 
     209                    valid = false; 
     210                } 
     211            } 
    204212        } 
    205213        if(!valid) 
     
    309317    this.errRequired = ''; 
    310318    this.help=''; 
     319    this.isConfirmField = false; 
     320    this.confirmFieldOf = ''; 
    311321} 
    312322 
  • trunk/lib/jelix/docs/ns/jforms-controls.rng

    r528 r540  
    164164       <ref name="UI.attr.readonly" /> 
    165165       <ref name="UI.attr.required" /> 
     166       <optional> 
     167          <element name="confirm"> 
     168                <empty/> 
     169                <choice> 
     170                    <attribute name="label" /> 
     171                    <attribute name="labellocale" /> 
     172                </choice> 
     173          </element> 
     174       </optional> 
    166175     </element> 
    167176  </define> 
     
    193202  </define> 
    194203 
    195 <!-- 
    196   <define name="select1"> 
    197      <element name="select1"> 
    198        <ref name="UI.Common" /> 
    199        <ref name="List.UI.Common" /> 
    200        <optional> 
    201          <attribute name="appearance"> 
    202              <choice> 
    203                  <value>radiobuttons</value> 
    204                  <value>listbox</value> 
    205                  <value>menulist</value> 
    206              </choice> 
    207          </attribute> 
    208       </optional>  
    209      </element> 
    210   </define> 
    211 --> 
    212204  <define name="radiobuttons"> 
    213205     <element name="radiobuttons"> 
     
    242234     </element> 
    243235  </define> 
    244  
    245    
    246 <!--  <define name="select"> 
    247      <element name="select"> 
    248        <ref name="UI.Common" /> 
    249        <ref name="List.UI.Common" /> 
    250        <optional> 
    251          <attribute name="appearance"> 
    252              <choice> 
    253                  <value>checkbox</value> 
    254                  <value>listbox</value> 
    255              </choice> 
    256          </attribute> 
    257       </optional>  
    258      </element> 
    259   </define>--> 
    260236   
    261237  <define name="output"> 
     
    263239       <ref name="UI.Common" /> 
    264240       <ref name="UI.attr.defaultvalue" /> 
    265        <!--<optional><attribute name="value"/></optional>--> 
    266241     </element> 
    267242  </define> 
     
    270245     <element name="submit"> 
    271246       <ref name="UI.Common" /> 
    272        <!--<optional><attribute name="value"/></optional>--> 
    273      </element> 
    274   </define> 
    275 --> 
     247     </element> 
     248  </define> 
     249 
    276250   
    277251  <!-- 
  • trunk/lib/jelix/docs/ns/jforms-controls.rng

    r528 r540  
    164164       <ref name="UI.attr.readonly" /> 
    165165       <ref name="UI.attr.required" /> 
     166       <optional> 
     167          <element name="confirm"> 
     168                <empty/> 
     169                <choice> 
     170                    <attribute name="label" /> 
     171                    <attribute name="labellocale" /> 
     172                </choice> 
     173          </element> 
     174       </optional> 
    166175     </element> 
    167176  </define> 
     
    193202  </define> 
    194203 
    195 <!-- 
    196   <define name="select1"> 
    197      <element name="select1"> 
    198        <ref name="UI.Common" /> 
    199        <ref name="List.UI.Common" /> 
    200        <optional> 
    201          <attribute name="appearance"> 
    202              <choice> 
    203                  <value>radiobuttons</value> 
    204                  <value>listbox</value> 
    205                  <value>menulist</value> 
    206              </choice> 
    207          </attribute> 
    208       </optional>  
    209      </element> 
    210   </define> 
    211 --> 
    212204  <define name="radiobuttons"> 
    213205     <element name="radiobuttons"> 
     
    242234     </element> 
    243235  </define> 
    244  
    245    
    246 <!--  <define name="select"> 
    247      <element name="select"> 
    248        <ref name="UI.Common" /> 
    249        <ref name="List.UI.Common" /> 
    250        <optional> 
    251          <attribute name="appearance"> 
    252              <choice> 
    253                  <value>checkbox</value> 
    254                  <value>listbox</value> 
    255              </choice> 
    256          </attribute> 
    257       </optional>  
    258      </element> 
    259   </define>--> 
    260236   
    261237  <define name="output"> 
     
    263239       <ref name="UI.Common" /> 
    264240       <ref name="UI.attr.defaultvalue" /> 
    265        <!--<optional><attribute name="value"/></optional>--> 
    266241     </element> 
    267242  </define> 
     
    270245     <element name="submit"> 
    271246       <ref name="UI.Common" /> 
    272        <!--<optional><attribute name="value"/></optional>--> 
    273      </element> 
    274   </define> 
    275 --> 
     247     </element> 
     248  </define> 
     249 
    276250   
    277251  <!-- 
  • trunk/lib/jelix/forms/jFormsBase.class.php

    r530 r540  
    99* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
    1010*/ 
    11  
    12 /** 
    13  * 
    14 */ 
    15  
    16 define('JFORM_ERRDATA_INVALID',1); 
    17 define('JFORM_ERRDATA_REQUIRED',2); 
    1811 
    1912/** 
     
    10194        $this->_container->errors = array(); 
    10295        foreach($this->_controls as $name=>$ctrl){ 
    103             $value=$this->_container->datas[$name]; 
    104             if(is_array($value)){ 
    105                 if(count($value) == 0 && $ctrl->required){ 
    106                     $this->_container->errors[$name]=JFORM_ERRDATA_REQUIRED; 
    107                 }else{ 
    108                     foreach($value as $v){ 
    109                         if(!$ctrl->datatype->check($v)){ 
    110                             $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 
    111                             break; 
    112                         } 
    113                     } 
    114                 } 
    115             }else{ 
    116                 if($value == '' && $ctrl->required){ 
    117                     $this->_container->errors[$name]=JFORM_ERRDATA_REQUIRED; 
    118                 }else{ 
    119                     if($ctrl->type == 'checkbox'){ 
    120                         if($value != $ctrl->valueOnCheck && $value != $ctrl->valueOnUncheck) 
    121                             $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 
    122                     }elseif(!$ctrl->datatype->check($value)){ 
    123                         $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 
    124                     } 
    125                 } 
    126             } 
     96            $err = $ctrl->check($this->_container->datas[$name], $this); 
     97            if($err !== null) 
     98                $this->_container->errors[$name]= $err; 
    12799        } 
    128100        return count($this->_container->errors) == 0; 
     
    351323        if($this->_controls[$name]->type == 'checkbox') { 
    352324            if($value != $this->_controls[$name]->valueOnCheck){ 
    353                 $value = $this->_controls[$name]->valueOnUncheck; 
     325                if($value =='on') 
     326                    $value = $this->_controls[$name]->valueOnCheck; 
     327                else 
     328                    $value = $this->_controls[$name]->valueOnUncheck; 
    354329            } 
    355330        } 
  • trunk/lib/jelix/forms/jFormsBase.class.php

    r530 r540  
    99* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
    1010*/ 
    11  
    12 /** 
    13  * 
    14 */ 
    15  
    16 define('JFORM_ERRDATA_INVALID',1); 
    17 define('JFORM_ERRDATA_REQUIRED',2); 
    1811 
    1912/** 
     
    10194        $this->_container->errors = array(); 
    10295        foreach($this->_controls as $name=>$ctrl){ 
    103             $value=$this->_container->datas[$name]; 
    104             if(is_array($value)){ 
    105                 if(count($value) == 0 && $ctrl->required){ 
    106                     $this->_container->errors[$name]=JFORM_ERRDATA_REQUIRED; 
    107                 }else{ 
    108                     foreach($value as $v){ 
    109                         if(!$ctrl->datatype->check($v)){ 
    110                             $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 
    111                             break; 
    112                         } 
    113                     } 
    114                 } 
    115             }else{ 
    116                 if($value == '' && $ctrl->required){ 
    117                     $this->_container->errors[$name]=JFORM_ERRDATA_REQUIRED; 
    118                 }else{ 
    119                     if($ctrl->type == 'checkbox'){ 
    120                         if($value != $ctrl->valueOnCheck && $value != $ctrl->valueOnUncheck) 
    121                             $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 
    122                     }elseif(!$ctrl->datatype->check($value)){ 
    123                         $this->_container->errors[$name]=JFORM_ERRDATA_INVALID; 
    124                     } 
    125                 } 
    126             } 
     96            $err = $ctrl->check($this->_container->datas[$name], $this); 
     97            if($err !== null) 
     98                $this->_container->errors[$name]= $err; 
    12799        } 
    128100        return count($this->_container->errors) == 0; 
     
    351323        if($this->_controls[$name]->type == 'checkbox') { 
    352324            if($value != $this->_controls[$name]->valueOnCheck){ 
    353                 $value = $this->_controls[$name]->valueOnUncheck; 
     325                if($value =='on') 
     326                    $value = $this->_controls[$name]->valueOnCheck; 
     327                else 
     328                    $value = $this->_controls[$name]->valueOnUncheck; 
    354329            } 
    355330        } 
  • trunk/lib/jelix/forms/jFormsBuilderBase.class.php

    r527 r540  
    264264            break; 
    265265        case 'secret': 
     266        case 'secretconfirm': 
    266267            echo '<input type="password"',$id,$readonly,$hint,$class,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
    267268            break; 
  • trunk/lib/jelix/forms/jFormsBuilderBase.class.php

    r527 r540  
    264264            break; 
    265265        case 'secret': 
     266        case 'secretconfirm': 
    266267            echo '<input type="password"',$id,$readonly,$hint,$class,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
    267268            break; 
  • trunk/lib/jelix/forms/jFormsCompiler.class.php

    r530 r540  
    6262 
    6363      $srcjs=array(); 
    64       $srcjs[]='$js="gForm = new jFormsForm(\'".$this->_name."\');\n";'; 
    65       $srcjs[]='$js.="gForm.setErrorDecorator(new ".$errorDecoratorName."());\n";'; 
    66       $srcjs[]='$js.="gForm.setHelpDecorator(new ".$helpDecoratorName."());\n";'; 
     64      $srcjs[]='$js="jForms.tForm = new jFormsForm(\'".$this->_name."\');\n";'; 
     65      $srcjs[]='$js.="jForms.tForm.setErrorDecorator(new ".$errorDecoratorName."());\n";'; 
     66      $srcjs[]='$js.="jForms.tForm.setHelpDecorator(new ".$helpDecoratorName."());\n";'; 
    6767      foreach($xml->children() as $controltype=>$control){ 
    6868            $source[] = $this->generatePHPControl($controltype, $control); 
     
    7676 
    7777      jFile::write($cachefile, implode("\n", $source)); 
    78       $srcjs[]='$js.="jForms.declareForm(gForm);\n";'; 
     78      $srcjs[]='$js.="jForms.declareForm(jForms.tForm);\n";'; 
    7979 
    8080      $srcHtmlBuilder[]=' public function getJavascriptCheck($errorDecoratorName, $helpDecoratorName){'; 
     
    115115               throw new jException('jelix~formserr.datatype.unknow',array($dt,$controltype,$this->sourceFile)); 
    116116            } 
    117             $source[]='$ctrl->datatype= new jDatatype'.$dt.'();'; 
     117            if($dt != 'string') 
     118                $source[]='$ctrl->datatype= new jDatatype'.$dt.'();'; 
    118119        }else if($controltype == 'checkbox') { 
    119120            $source[]='$ctrl->datatype= new jDatatypeBoolean();'; 
    120         }else{ 
    121             $source[]='$ctrl->datatype= new jDatatypeString();'; 
    122         } 
     121        } 
     122         
    123123        // readonly support 
    124124        if(isset($control['readonly'])){ 
     
    170170            } 
    171171        } 
     172        $alertInvalid=''; 
     173        $alertRequired=''; 
    172174        if(isset($control->alert)){ 
    173             $alertInvalid=''; 
    174             $alertRequired=''; 
    175  
    176175            foreach($control->alert as $alert){ 
    177176                if(isset($alert['locale'])){ 
     
    193192            if($alertInvalid !='') $source[]=$alertInvalid; 
    194193        } 
    195  
    196         // support of static datas or daos 
     194        $hasCtrl2 = false; 
    197195        switch($controltype){ 
    198196            case 'checkboxes': 
     
    200198            case 'menulist': 
    201199            case 'listbox': 
     200                // support of static datas or daos 
    202201                if(isset($control['selectedvalue']) && isset($control->selectedvalues)){ 
    203202                    throw new jException('jelix~formserr.attribute.not.allowed',array('selectedvalue',$controltype,$this->sourceFile)); 
     
    263262 
    264263               break; 
     264            case 'secret': 
     265                if(isset($control->confirm)) { 
     266                    $label=''; 
     267                    if(isset($control->confirm['label'])){ 
     268                        $label = "'".str_replace("'","\\'",(string)$control->confirm['label'])."';"; 
     269                    }elseif(isset($control->confirm['labellocale'])){ 
     270                        $label = "jLocale::get('".(string)$control->confirm['labellocale']."');"; 
     271                    }else{ 
     272                        throw new jException('jelix~formserr.attribute.missing',array('label','confirm',$this->sourceFile)); 
     273                    } 
     274                    $source[]='$ctrl2 = new jFormsControlSecretConfirm(\''.(string)$control['ref'].'_confirm\');'; 
     275                    $source[]='$ctrl2->primarySecret = \''.(string)$control['ref'].'\';'; 
     276                    $source[]='$ctrl2->label='.$label; 
     277                    $source[]='$ctrl2->required = $ctrl->required;'; 
     278                    $source[]='$ctrl2->readonly = $ctrl->readonly;'; 
     279                    if($alertInvalid!='') 
     280                        $source[]='$ctrl2->alertInvalid = $ctrl->alertInvalid;'; 
     281                    if($alertRequired!='') 
     282                        $source[]='$ctrl2->alertRequired = $ctrl->alertRequired;'; 
     283                     
     284                    if(isset($control->help)){ 
     285                        $source[]='$ctrl2->hasHelp=true;'; 
     286                    } 
     287                    if(isset($control->hint)){ 
     288                        $source[]='$ctrl2->hint=$ctrl->hint;'; 
     289                    } 
     290                    $hasCtrl2 = true; 
     291                } 
     292                break; 
    265293        } 
    266294 
     
    292320 
    293321        $source[]='$this->addControl($ctrl);'; 
     322        if($hasCtrl2) 
     323            $source[]='$this->addControl($ctrl2);'; 
    294324        return implode("\n", $source); 
    295325    } 
     
    299329            return ''; 
    300330 
     331        if(isset($control->confirm) && $controltype == 'secret') { 
     332            $hasConfirm = true; 
     333        }else{ 
     334            $hasConfirm = false; 
     335        } 
     336         
    301337        $source = array(); 
    302338 
     
    314350        } 
    315351        if($controltype == 'checkboxes' || ($controltype == 'listbox' && isset($control['multiple']) && 'true' == (string)$control['multiple'])) 
    316             $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'[]\', \'".$label."\', \''.$dt.'\');\n";'; 
    317         else 
    318             $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'\', \'".$label."\', \''.$dt.'\');\n";'; 
     352            $source[]='$js.="jForms.tControl = new jFormsControl(\''.(string)$control['ref'].'[]\', \'".$label."\', \''.$dt.'\');\n";'; 
     353        else{ 
     354            $source[]='$js.="jForms.tControl = new jFormsControl(\''.(string)$control['ref'].'\', \'".$label."\', \''.$dt.'\');\n";'; 
     355            if($hasConfirm){ 
     356                if(isset($control->confirm['label'])){ 
     357                    $source[]='$label2 = str_replace("\'","\\\'",\''.str_replace("'","\\'",(string)$control->confirm['label']).'\');'; 
     358                }else{ 
     359                    $source[]='$label2 = str_replace("\'","\\\'",jLocale::get(\''.(string)$control->confirm['labellocale'].'\'));'; 
     360                } 
     361                $source[]='$js.="jForms.tControl2 = new jFormsControl(\''.(string)$control['ref'].'_confirm\', \'".$label2."\', \''.$dt.'\');\n";'; 
     362            } 
     363        } 
    319364 
    320365        if($dt == 'localedate' || $dt =='localedatetime' || $dt =='localetime'){ 
    321             $source[]='$js.="gControl.lang=\'".$GLOBALS[\'gJConfig\']->defaultLocale."\';\n";'; 
     366            $source[]='$js.="jForms.tControl.lang=\'".$GLOBALS[\'gJConfig\']->defaultLocale."\';\n";'; 
    322367        } 
    323368 
    324369        if(isset($control['readonly']) && 'true' == (string)$control['readonly']){ 
    325             $source[]='$js.="gControl.readonly = true;\n";'; 
     370            $source[]='$js.="jForms.tControl.readonly = true;\n";'; 
     371            if($hasConfirm) $source[]='$js.="jForms.tControl2.readonly = true;\n";'; 
    326372        } 
    327373        if(isset($control['required']) && 'true' == (string)$control['required']){ 
    328             $source[]='$js.="gControl.required = true;\n";'; 
     374            $source[]='$js.="jForms.tControl.required = true;\n";'; 
     375            if($hasConfirm) $source[]='$js.="jForms.tControl2.required = true;\n";'; 
    329376        } 
    330377 
     
    335382                $help='str_replace("\'","\\\'",\''.str_replace("'","\\'",(string)$control->help).'\')'; 
    336383            } 
    337             $source[]='$js.="gControl.help=\'".'.$help.'."\';\n";'; 
     384            $source[]='$js.="jForms.tControl.help=\'".'.$help.'."\';\n";'; 
     385            if($hasConfirm) $source[]='$js.="jForms.tControl2.help=jForms.tControl.help;\n";'; 
    338386        } 
    339387 
     
    360408        } 
    361409 
    362         $source[]='$js.="gControl.errRequired=\'".'.$alertRequired.'."\';\n";'; 
    363         $source[]='$js.="gControl.errInvalid =\'".'.$alertInvalid.'."\';\n";'; 
     410        $source[]='$js.="jForms.tControl.errRequired=\'".'.$alertRequired.'."\';\n";'; 
     411        $source[]='$js.="jForms.tControl.errInvalid =\'".'.$alertInvalid.'."\';\n";'; 
     412        if($hasConfirm){ 
     413            $alertInvalid='str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label2))'; 
     414            $alertRequired='str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label2))'; 
     415            $source[]='$js.="jForms.tControl2.errRequired=\'".'.$alertRequired.'."\';\n";'; 
     416            $source[]='$js.="jForms.tControl2.errInvalid =\'".'.$alertInvalid.'."\';\n";'; 
     417        } 
     418         
    364419        if(isset($control['multiple']) && 'true' == (string)$control['multiple']){ 
    365             $source[]='$js.="gControl.multiple = true;\n";'; 
    366         } 
    367  
    368         $source[]='$js.="gForm.addControl( gControl);\n";'; 
     420            $source[]='$js.="jForms.tControl.multiple = true;\n";'; 
     421        } 
     422        $source[]='$js.="jForms.tForm.addControl( jForms.tControl);\n";'; 
     423        if($hasConfirm) { 
     424            $source[]='$js.="jForms.tControl2.isConfirmField=true;\njForms.tControl2.confirmFieldOf=\''.(string)$control['ref'].'\';\n";'; 
     425            $source[]='$js.="jForms.tForm.addControl( jForms.tControl2);\n";'; 
     426        } 
    369427 
    370428        return implode("\n", $source); 
     
    377435        au final, le javascript généré dans la page html doit ressembler à cela 
    378436 
    379         gForm = new jFormsForm('name'); 
    380         gForm.setDecorator(new jFormsErrorDecoratorAlert()); 
     437        jForms.tForm = new jFormsForm('name'); 
     438        jForms.tForm.setDecorator(new jFormsErrorDecoratorAlert()); 
    381439         
    382         gControl = new jFormsControl('name', 'a label', 'datatype'); 
    383         gControl.required = true; 
    384         gControl.errInvalid=''; 
    385         gControl.errRequired=''; 
    386         gForm.addControl( gControl); 
     440        jForms.tControl = new jFormsControl('name', 'a label', 'datatype'); 
     441        jForms.tControl.required = true; 
     442        jForms.tControl.errInvalid=''; 
     443        jForms.tControl.errRequired=''; 
     444        jForms.tForm.addControl( jForms.tControl); 
    387445        ... 
    388         jForms.declareForm(gForm); 
     446        jForms.declareForm(jForms.tForm); 
    389447 
    390448 
     
    394452        // le code php généré dans le builder 
    395453 
    396         $js="gForm = new jFormsForm('".$this->getFormName()."');\n"; 
    397         $js.="gForm.setDecorator(new jFormsErrorDecoratorAlert());\n"; 
     454        $js="jForms.tForm = new jFormsForm('".$this->getFormName()."');\n"; 
     455        $js.="jForms.tForm.setDecorator(new jFormsErrorDecoratorAlert());\n"; 
    398456        $label = 'a label'; 
    399457        ou 
    400458        $label = jLocale::get('mod~cle_locale_user'); 
    401         $js.="gControl = new jFormsControl('name', '".str_replace("'","\\'", $label)."', 'datatype');\n"; 
    402         $js.="gControl.required = true;\n"; 
     459        $js.="jForms.tControl = new jFormsControl('name', '".str_replace("'","\\'", $label)."', 'datatype');\n"; 
     460        $js.="jForms.tControl.required = true;\n"; 
    403461 
    404462        $invalid = jLocale::get('jelix~forms.check.invalid',$label)); 
     
    407465        ou 
    408466        $invalid = 'bla bla'; 
    409         $js.="gControl.errInvalid='".str_replace("'","\\'",$invalid)."';\n"; 
     467        $js.="jForms.tControl.errInvalid='".str_replace("'","\\'",$invalid)."';\n"; 
    410468 
    411469 
     
    416474        $required = 'bla bla'; 
    417475 
    418         $js.="gControl.errRequired='".str_replace("'","\\'",$required)."';\n"; 
    419         $js.="gForm.addControl( gControl);\n"; 
     476        $js.="jForms.tControl.errRequired='".str_replace("'","\\'",$required)."';\n"; 
     477        $js.="jForms.tForm.addControl( jForms.tControl);\n"; 
    420478        ... 
    421         $js.="jForms.declareForm(gForm);\n"; 
     479        $js.="jForms.declareForm(jForms.tForm);\n"; 
    422480 
    423481        */ 
  • trunk/lib/jelix/forms/jFormsCompiler.class.php

    r530 r540  
    6262 
    6363      $srcjs=array(); 
    64       $srcjs[]='$js="gForm = new jFormsForm(\'".$this->_name."\');\n";'; 
    65       $srcjs[]='$js.="gForm.setErrorDecorator(new ".$errorDecoratorName."());\n";'; 
    66       $srcjs[]='$js.="gForm.setHelpDecorator(new ".$helpDecoratorName."());\n";'; 
     64      $srcjs[]='$js="jForms.tForm = new jFormsForm(\'".$this->_name."\');\n";'; 
     65      $srcjs[]='$js.="jForms.tForm.setErrorDecorator(new ".$errorDecoratorName."());\n";'; 
     66      $srcjs[]='$js.="jForms.tForm.setHelpDecorator(new ".$helpDecoratorName."());\n";'; 
    6767      foreach($xml->children() as $controltype=>$control){ 
    6868            $source[] = $this->generatePHPControl($controltype, $control); 
     
    7676 
    7777      jFile::write($cachefile, implode("\n", $source)); 
    78       $srcjs[]='$js.="jForms.declareForm(gForm);\n";'; 
     78      $srcjs[]='$js.="jForms.declareForm(jForms.tForm);\n";'; 
    7979 
    8080      $srcHtmlBuilder[]=' public function getJavascriptCheck($errorDecoratorName, $helpDecoratorName){'; 
     
    115115               throw new jException('jelix~formserr.datatype.unknow',array($dt,$controltype,$this->sourceFile)); 
    116116            } 
    117             $source[]='$ctrl->datatype= new jDatatype'.$dt.'();'; 
     117            if($dt != 'string') 
     118                $source[]='$ctrl->datatype= new jDatatype'.$dt.'();'; 
    118119        }else if($controltype == 'checkbox') { 
    119120            $source[]='$ctrl->datatype= new jDatatypeBoolean();'; 
    120         }else{ 
    121             $source[]='$ctrl->datatype= new jDatatypeString();'; 
    122         } 
     121        } 
     122         
    123123        // readonly support 
    124124        if(isset($control['readonly'])){ 
     
    170170            } 
    171171        } 
     172        $alertInvalid=''; 
     173        $alertRequired=''; 
    172174        if(isset($control->alert)){ 
    173             $alertInvalid=''; 
    174             $alertRequired=''; 
    175  
    176175            foreach($control->alert as $alert){ 
    177176                if(isset($alert['locale'])){ 
     
    193192            if($alertInvalid !='') $source[]=$alertInvalid; 
    194193        } 
    195  
    196         // support of static datas or daos 
     194        $hasCtrl2 = false; 
    197195        switch($controltype){ 
    198196            case 'checkboxes': 
     
    200198            case 'menulist': 
    201199            case 'listbox': 
     200                // support of static datas or daos 
    202201                if(isset($control['selectedvalue']) && isset($control->selectedvalues)){ 
    203202                    throw new jException('jelix~formserr.attribute.not.allowed',array('selectedvalue',$controltype,$this->sourceFile)); 
     
    263262 
    264263               break; 
     264            case 'secret': 
     265                if(isset($control->confirm)) { 
     266                    $label=''; 
     267                    if(isset($control->confirm['label'])){ 
     268                        $label = "'".str_replace("'","\\'",(string)$control->confirm['label'])."';"; 
     269                    }elseif(isset($control->confirm['labellocale'])){ 
     270                        $label = "jLocale::get('".(string)$control->confirm['labellocale']."');"; 
     271                    }else{ 
     272                        throw new jException('jelix~formserr.attribute.missing',array('label','confirm',$this->sourceFile)); 
     273                    } 
     274                    $source[]='$ctrl2 = new jFormsControlSecretConfirm(\''.(string)$control['ref'].'_confirm\');'; 
     275                    $source[]='$ctrl2->primarySecret = \''.(string)$control['ref'].'\';'; 
     276                    $source[]='$ctrl2->label='.$label; 
     277                    $source[]='$ctrl2->required = $ctrl->required;'; 
     278                    $source[]='$ctrl2->readonly = $ctrl->readonly;'; 
     279                    if($alertInvalid!='') 
     280                        $source[]='$ctrl2->alertInvalid = $ctrl->alertInvalid;'; 
     281                    if($alertRequired!='') 
     282                        $source[]='$ctrl2->alertRequired = $ctrl->alertRequired;'; 
     283                     
     284                    if(isset($control->help)){ 
     285                        $source[]='$ctrl2->hasHelp=true;'; 
     286                    } 
     287                    if(isset($control->hint)){ 
     288                        $source[]='$ctrl2->hint=$ctrl->hint;'; 
     289                    } 
     290                    $hasCtrl2 = true; 
     291                } 
     292                break; 
    265293        } 
    266294 
     
    292320 
    293321        $source[]='$this->addControl($ctrl);'; 
     322        if($hasCtrl2) 
     323            $source[]='$this->addControl($ctrl2);'; 
    294324        return implode("\n", $source); 
    295325    } 
     
    299329            return ''; 
    300330 
     331        if(isset($control->confirm) && $controltype == 'secret') { 
     332            $hasConfirm = true; 
     333        }else{ 
     334            $hasConfirm = false; 
     335        } 
     336         
    301337        $source = array(); 
    302338 
     
    314350        } 
    315351        if($controltype == 'checkboxes' || ($controltype == 'listbox' && isset($control['multiple']) && 'true' == (string)$control['multiple'])) 
    316             $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'[]\', \'".$label."\', \''.$dt.'\');\n";'; 
    317         else 
    318             $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'\', \'".$label."\', \''.$dt.'\');\n";'; 
     352            $source[]='$js.="jForms.tControl = new jFormsControl(\''.(string)$control['ref'].'[]\', \'".$label."\', \''.$dt.'\');\n";'; 
     353        else{ 
     354            $source[]='$js.="jForms.tControl = new jFormsControl(\''.(string)$control['ref'].'\', \'".$label."\', \''.$dt.'\');\n";'; 
     355            if($hasConfirm){ 
     356                if(isset($control->confirm['label'])){ 
     357                    $source[]='$label2 = str_replace("\'","\\\'",\''.str_replace("'","\\'",(string)$control->confirm['label']).'\');'; 
     358                }else{ 
     359                    $source[]='$label2 = str_replace("\'","\\\'",jLocale::get(\''.(string)$control->confirm['labellocale'].'\'));'; 
     360                } 
     361                $source[]='$js.="jForms.tControl2 = new jFormsControl(\''.(string)$control['ref'].'_confirm\', \'".$label2."\', \''.$dt.'\');\n";'; 
     362            } 
     363        } 
    319364 
    320365        if($dt == 'localedate' || $dt =='localedatetime' || $dt =='localetime'){ 
    321             $source[]='$js.="gControl.lang=\'".$GLOBALS[\'gJConfig\']->defaultLocale."\';\n";'; 
     366            $source[]='$js.="jForms.tControl.lang=\'".$GLOBALS[\'gJConfig\']->defaultLocale."\';\n";'; 
    322367        } 
    323368 
    324369        if(isset($control['readonly']) && 'true' == (string)$control['readonly']){ 
    325             $source[]='$js.="gControl.readonly = true;\n";'; 
     370            $source[]='$js.="jForms.tControl.readonly = true;\n";'; 
     371            if($hasConfirm) $source[]='$js.="jForms.tControl2.readonly = true;\n";'; 
    326372        } 
    327373        if(isset($control['required']) && 'true' == (string)$control['required']){ 
    328             $source[]='$js.="gControl.required = true;\n";'; 
     374            $source[]='$js.="jForms.tControl.required = true;\n";'; 
     375            if($hasConfirm) $source[]='$js.="jForms.tControl2.required = true;\n";'; 
    329376        } 
    330377 
     
    335382                $help='str_replace("\'","\\\'",\''.str_replace("'","\\'",(string)$control->help).'\')'; 
    336383            } 
    337             $source[]='$js.="gControl.help=\'".'.$help.'."\';\n";'; 
     384            $source[]='$js.="jForms.tControl.help=\'".'.$help.'."\';\n";'; 
     385            if($hasConfirm) $source[]='$js.="jForms.tControl2.help=jForms.tControl.help;\n";'; 
    338386        } 
    339387 
     
    360408        } 
    361409 
    362         $source[]='$js.="gControl.errRequired=\'".'.$alertRequired.'."\';\n";'; 
    363         $source[]='$js.="gControl.errInvalid =\'".'.$alertInvalid.'."\';\n";'; 
     410        $source[]='$js.="jForms.tControl.errRequired=\'".'.$alertRequired.'."\';\n";'; 
     411        $source[]='$js.="jForms.tControl.errInvalid =\'".'.$alertInvalid.'."\';\n";'; 
     412        if($hasConfirm){ 
     413            $alertInvalid='str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label2))'; 
     414            $alertRequired='str_replace("\'","\\\'",jLocale::get(\