Changeset 453

Show
Ignore:
Timestamp:
06/04/07 23:38:09 (1 year ago)
Author:
laurentj
Message:

jforms, worked on new tags : checkbox, menulist, listbox, radiobuttons

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/experimental/jforms/lib/jelix/docs/ns/jforms-controls.rng

    r442 r453  
    2323  <define name="UI.Common.data"> 
    2424      <optional><ref name="datatypes" /></optional> 
     25      <ref name="UI.attr.readonly" /> 
     26      <optional><attribute name="required"><choice><value>true</value><value>false</value></choice></attribute></optional> 
     27  </define> 
     28   
     29  <define name="UI.attr.readonly"> 
    2530      <optional><attribute name="readonly"><choice><value>true</value><value>false</value></choice></attribute></optional> 
    26       <optional><attribute name="required"><choice><value>true</value><value>false</value></choice></attribute></optional> 
    2731  </define> 
    2832 
     
    3539        <ref name="daodatasource" /> 
    3640    </choice> 
    37     <!-- <optional> 
    38          <attribute name="appearance"> 
    39              <choice> 
    40                  <value>full</value>  checkbox /radiobox 
    41                  <value>compact</value> listbox multiple /listbox 
    42                  <value>minimal</value>  listbox multiple / combobox 
    43              </choice> 
    44          </attribute> 
    45       </optional> --> 
    46   </define> 
     41  </define> 
     42   
    4743  <define name="item"> 
    4844     <element name="item"> 
     
    106102            <ref name="output" /> 
    107103            <ref name="upload" /> 
    108             <ref name="select1" /> 
    109             <ref name="select" /> 
    110104            <ref name="submit" /> 
     105            <ref name="checkbox" /> 
     106            <ref name="checkboxes" /> 
     107            <ref name="listbox" /> 
     108            <ref name="radiobuttons"/> 
     109            <ref name="menulist" /> 
    111110            <!-- 
    112111            <ref name="range" /> 
     
    145144     </element> 
    146145  </define> 
    147  
     146   
     147  <define name="checkbox"> 
     148     <element name="checkbox"> 
     149       <ref name="UI.Common" /> 
     150       <ref name="UI.attr.readonly" /> 
     151     </element> 
     152  </define> 
     153 
     154<!-- 
    148155  <define name="select1"> 
    149156     <element name="select1"> 
     
    153160         <attribute name="appearance"> 
    154161             <choice> 
    155                  <value>full</value> 
    156                  <value>radiobox</value> 
    157                  <value>compact</value> 
     162                 <value>radiobuttons</value> 
    158163                 <value>listbox</value> 
    159                  <value>minimal</value> 
    160164                 <value>menulist</value> 
    161165             </choice> 
    162166         </attribute> 
    163167      </optional>  
    164  
    165        <!-- <optional> 
    166            <attribute name="selection"> 
    167              <choice> 
    168                  <value>open</value> 
    169                  <value>close</value> 
    170               </choice> 
    171            </attribute> 
    172        </optional>--> 
    173      </element> 
    174   </define> 
    175  
    176  
    177   <define name="select"> 
     168     </element> 
     169  </define> 
     170--> 
     171  <define name="radiobuttons"> 
     172     <element name="radiobuttons"> 
     173       <ref name="UI.Common" /> 
     174       <ref name="List.UI.Common" /> 
     175     </element> 
     176  </define> 
     177 
     178  <define name="listbox"> 
     179     <element name="radiobuttons"> 
     180       <ref name="UI.Common" /> 
     181       <ref name="List.UI.Common" /> 
     182       <optional> 
     183            <attribute name="multiple"> 
     184                <choice><value>true</value><value>false</value></choice> 
     185            </attribute> 
     186       </optional> 
     187     </element> 
     188  </define> 
     189 
     190  <define name="menulist"> 
     191     <element name="radiobuttons"> 
     192       <ref name="UI.Common" /> 
     193       <ref name="List.UI.Common" /> 
     194     </element> 
     195  </define> 
     196 
     197<!--  <define name="select"> 
    178198     <element name="select"> 
    179199       <ref name="UI.Common" /> 
     
    182202         <attribute name="appearance"> 
    183203             <choice> 
    184                  <value>full</value> 
    185204                 <value>checkbox</value> 
    186                  <value>compact</value> 
    187205                 <value>listbox</value> 
    188206             </choice> 
    189207         </attribute> 
    190208      </optional>  
    191        <!--<optional
    192            <attribute name="selection"
    193              <choice> 
    194                  <value>open</value
    195                  <value>close</value
    196               </choice
    197            </attribute
    198        </optional>--
    199      </element
    200   </define> 
    201  
     209     </element
     210  </define>--
     211 
     212  <define name="checkboxes"
     213     <element name="checkboxes"
     214       <ref name="UI.Common" /
     215       <ref name="List.UI.Common" /
     216     </element
     217  </define
     218 
     219   
    202220  <define name="output"> 
    203221     <element name="output"> 
  • branches/experimental/jforms/lib/jelix/docs/ns/jforms-controls.rng

    r442 r453  
    2323  <define name="UI.Common.data"> 
    2424      <optional><ref name="datatypes" /></optional> 
     25      <ref name="UI.attr.readonly" /> 
     26      <optional><attribute name="required"><choice><value>true</value><value>false</value></choice></attribute></optional> 
     27  </define> 
     28   
     29  <define name="UI.attr.readonly"> 
    2530      <optional><attribute name="readonly"><choice><value>true</value><value>false</value></choice></attribute></optional> 
    26       <optional><attribute name="required"><choice><value>true</value><value>false</value></choice></attribute></optional> 
    2731  </define> 
    2832 
     
    3539        <ref name="daodatasource" /> 
    3640    </choice> 
    37     <!-- <optional> 
    38          <attribute name="appearance"> 
    39              <choice> 
    40                  <value>full</value>  checkbox /radiobox 
    41                  <value>compact</value> listbox multiple /listbox 
    42                  <value>minimal</value>  listbox multiple / combobox 
    43              </choice> 
    44          </attribute> 
    45       </optional> --> 
    46   </define> 
     41  </define> 
     42   
    4743  <define name="item"> 
    4844     <element name="item"> 
     
    106102            <ref name="output" /> 
    107103            <ref name="upload" /> 
    108             <ref name="select1" /> 
    109             <ref name="select" /> 
    110104            <ref name="submit" /> 
     105            <ref name="checkbox" /> 
     106            <ref name="checkboxes" /> 
     107            <ref name="listbox" /> 
     108            <ref name="radiobuttons"/> 
     109            <ref name="menulist" /> 
    111110            <!-- 
    112111            <ref name="range" /> 
     
    145144     </element> 
    146145  </define> 
    147  
     146   
     147  <define name="checkbox"> 
     148     <element name="checkbox"> 
     149       <ref name="UI.Common" /> 
     150       <ref name="UI.attr.readonly" /> 
     151     </element> 
     152  </define> 
     153 
     154<!-- 
    148155  <define name="select1"> 
    149156     <element name="select1"> 
     
    153160         <attribute name="appearance"> 
    154161             <choice> 
    155                  <value>full</value> 
    156                  <value>radiobox</value> 
    157                  <value>compact</value> 
     162                 <value>radiobuttons</value> 
    158163                 <value>listbox</value> 
    159                  <value>minimal</value> 
    160164                 <value>menulist</value> 
    161165             </choice> 
    162166         </attribute> 
    163167      </optional>  
    164  
    165        <!-- <optional> 
    166            <attribute name="selection"> 
    167              <choice> 
    168                  <value>open</value> 
    169                  <value>close</value> 
    170               </choice> 
    171            </attribute> 
    172        </optional>--> 
    173      </element> 
    174   </define> 
    175  
    176  
    177   <define name="select"> 
     168     </element> 
     169  </define> 
     170--> 
     171  <define name="radiobuttons"> 
     172     <element name="radiobuttons"> 
     173       <ref name="UI.Common" /> 
     174       <ref name="List.UI.Common" /> 
     175     </element> 
     176  </define> 
     177 
     178  <define name="listbox"> 
     179     <element name="radiobuttons"> 
     180       <ref name="UI.Common" /> 
     181       <ref name="List.UI.Common" /> 
     182       <optional> 
     183            <attribute name="multiple"> 
     184                <choice><value>true</value><value>false</value></choice> 
     185            </attribute> 
     186       </optional> 
     187     </element> 
     188  </define> 
     189 
     190  <define name="menulist"> 
     191     <element name="radiobuttons"> 
     192       <ref name="UI.Common" /> 
     193       <ref name="List.UI.Common" /> 
     194     </element> 
     195  </define> 
     196 
     197<!--  <define name="select"> 
    178198     <element name="select"> 
    179199       <ref name="UI.Common" /> 
     
    182202         <attribute name="appearance"> 
    183203             <choice> 
    184                  <value>full</value> 
    185204                 <value>checkbox</value> 
    186                  <value>compact</value> 
    187205                 <value>listbox</value> 
    188206             </choice> 
    189207         </attribute> 
    190208      </optional>  
    191        <!--<optional
    192            <attribute name="selection"
    193              <choice> 
    194                  <value>open</value
    195                  <value>close</value
    196               </choice
    197            </attribute
    198        </optional>--
    199      </element
    200   </define> 
    201  
     209     </element
     210  </define>--
     211 
     212  <define name="checkboxes"
     213     <element name="checkboxes"
     214       <ref name="UI.Common" /
     215       <ref name="List.UI.Common" /
     216     </element
     217  </define
     218 
     219   
    202220  <define name="output"> 
    203221     <element name="output"> 
  • branches/experimental/jforms/lib/jelix/forms/jFormsBuilderBase.class.php

    r452 r453  
    9696 
    9797    public function outputControlLabel($ctrl){ 
    98         if($ctrl->type == 'output'){ 
     98        if($ctrl->type == 'output' || $ctrl->type == 'checkboxes'){ 
    9999            echo htmlspecialchars($ctrl->label); 
    100100        } 
     
    112112            echo '<input type="text" ',$id,$readonly,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
    113113            break; 
    114         case 'select1': 
     114        case 'checkbox': 
     115            if($this->_form->getData($ctrl->ref)){ 
     116                $v=' checked="checked"'; 
     117            }else{ 
     118                $v=""; 
     119            } 
     120            echo '<input type="checkbox" ',$id,$readonly,$v,' value="true"/>'; 
    115121            break; 
    116         case 'select': 
     122        /*case 'checkboxes': 
     123            $i=0; 
     124            $id=' name="'.$ctrl->ref.'[]" id="'.$this->_name.'_'.$ctrl->ref.'_'; 
     125            $value = $this->_form->getData($ctrl->ref); 
     126            foreach($ctrl->datasource->getDatas() as $v=>$label){ 
     127                $i++; 
     128                echo '<input type="checkbox"',$id,$i,'" value="',htmlspecialchars($v),'" checked="checked" /><label for="',$id,$i,'">',htmlspecialchars($label),'</label>'; 
     129            } 
     130            break;*/ 
     131        case 'radiobuttons': 
     132            $i=0; 
     133            $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 
     134            $value = $this->_form->getData($ctrl->ref); 
     135            foreach($ctrl->datasource->getDatas() as $v=>$label){ 
     136                $i++; 
     137                echo '<input type="radio"',$id,$i,'" value="',htmlspecialchars($v),'" ',($v==$value?'checked="checked"':''),' />'; 
     138                echo '<label for="',$this->_name,'_',$ctrl->ref,'_',$i,'">',htmlspecialchars($label),'</label>'; 
     139            } 
     140            break; 
     141        case 'menulist': 
     142            echo '<select ',$id,$readonly,' size="1">'; 
     143            $value = $this->_form->getData($ctrl->ref); 
     144            foreach($ctrl->datasource->getDatas() as $v=>$label){ 
     145                echo '<option value="',htmlspecialchars($v),'"',($v==$value?'selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     146            } 
     147            echo '</select>'; 
     148            break; 
     149        case 'listbox': 
     150            /*if($ctrl->multiple){ 
     151                echo '<select ',$id,$readonly,' size="3" multiple="multiple">'; 
     152                $value = $this->_form->getData($ctrl->ref); 
     153                foreach($ctrl->datasource->getDatas() as $v=>$label){ 
     154                    echo '<option value="',htmlspecialchars($v),'"',($v==$value?'selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     155                } 
     156                echo '</select>'; 
     157            }else{*/ 
     158                echo '<select ',$id,$readonly,' size="4">'; 
     159                $value = $this->_form->getData($ctrl->ref); 
     160                foreach($ctrl->datasource->getDatas() as $v=>$label){ 
     161                    echo '<option value="',htmlspecialchars($v),'"',($v==$value?'selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     162                } 
     163                echo '</select>'; 
     164            //} 
    117165            break; 
    118166        case 'textarea': 
  • branches/experimental/jforms/lib/jelix/forms/jFormsBuilderBase.class.php

    r452 r453  
    9696 
    9797    public function outputControlLabel($ctrl){ 
    98         if($ctrl->type == 'output'){ 
     98        if($ctrl->type == 'output' || $ctrl->type == 'checkboxes'){ 
    9999            echo htmlspecialchars($ctrl->label); 
    100100        } 
     
    112112            echo '<input type="text" ',$id,$readonly,' value="',htmlspecialchars($this->_form->getData($ctrl->ref)),'"/>'; 
    113113            break; 
    114         case 'select1': 
     114        case 'checkbox': 
     115            if($this->_form->getData($ctrl->ref)){ 
     116                $v=' checked="checked"'; 
     117            }else{ 
     118                $v=""; 
     119            } 
     120            echo '<input type="checkbox" ',$id,$readonly,$v,' value="true"/>'; 
    115121            break; 
    116         case 'select': 
     122        /*case 'checkboxes': 
     123            $i=0; 
     124            $id=' name="'.$ctrl->ref.'[]" id="'.$this->_name.'_'.$ctrl->ref.'_'; 
     125            $value = $this->_form->getData($ctrl->ref); 
     126            foreach($ctrl->datasource->getDatas() as $v=>$label){ 
     127                $i++; 
     128                echo '<input type="checkbox"',$id,$i,'" value="',htmlspecialchars($v),'" checked="checked" /><label for="',$id,$i,'">',htmlspecialchars($label),'</label>'; 
     129            } 
     130            break;*/ 
     131        case 'radiobuttons': 
     132            $i=0; 
     133            $id=' name="'.$ctrl->ref.'" id="'.$this->_name.'_'.$ctrl->ref.'_'; 
     134            $value = $this->_form->getData($ctrl->ref); 
     135            foreach($ctrl->datasource->getDatas() as $v=>$label){ 
     136                $i++; 
     137                echo '<input type="radio"',$id,$i,'" value="',htmlspecialchars($v),'" ',($v==$value?'checked="checked"':''),' />'; 
     138                echo '<label for="',$this->_name,'_',$ctrl->ref,'_',$i,'">',htmlspecialchars($label),'</label>'; 
     139            } 
     140            break; 
     141        case 'menulist': 
     142            echo '<select ',$id,$readonly,' size="1">'; 
     143            $value = $this->_form->getData($ctrl->ref); 
     144            foreach($ctrl->datasource->getDatas() as $v=>$label){ 
     145                echo '<option value="',htmlspecialchars($v),'"',($v==$value?'selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     146            } 
     147            echo '</select>'; 
     148            break; 
     149        case 'listbox': 
     150            /*if($ctrl->multiple){ 
     151                echo '<select ',$id,$readonly,' size="3" multiple="multiple">'; 
     152                $value = $this->_form->getData($ctrl->ref); 
     153                foreach($ctrl->datasource->getDatas() as $v=>$label){ 
     154                    echo '<option value="',htmlspecialchars($v),'"',($v==$value?'selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     155                } 
     156                echo '</select>'; 
     157            }else{*/ 
     158                echo '<select ',$id,$readonly,' size="4">'; 
     159                $value = $this->_form->getData($ctrl->ref); 
     160                foreach($ctrl->datasource->getDatas() as $v=>$label){ 
     161                    echo '<option value="',htmlspecialchars($v),'"',($v==$value?'selected="selected"':''),'>',htmlspecialchars($label),'</option>'; 
     162                } 
     163                echo '</select>'; 
     164            //} 
    117165            break; 
    118166        case 'textarea': 
  • branches/experimental/jforms/lib/jelix/forms/jFormsCompiler.class.php

    r452 r453  
    6666      foreach($xml->children() as $controltype=>$control){ 
    6767            $source[] = $this->generatePHPControl($controltype, $control); 
    68             $srcjs[] =  $this->generateJsControl($control); 
     68            $srcjs[] =  $this->generateJsControl($controltype, $control); 
    6969      } 
    7070      $source[]='  }'; 
     
    111111            } 
    112112            $source[]='$ctrl->datatype= new jDatatype'.$dt.'();'; 
     113         }else if($controltype == 'checkbox') { 
     114            $source[]='$ctrl->datatype= new jDatatypeBoolean();'; 
    113115         }else{ 
    114116            $source[]='$ctrl->datatype= new jDatatypeString();'; 
     
    116118 
    117119         if(isset($control['readonly'])){ 
    118             $readonly=(string)$control['readonly']; 
    119  
    120             $source[]='$ctrl->readonly='.($readonly=='true'?'true':'false').';'; 
     120            if('true' == (string)$control['readonly']) 
     121                $source[]='$ctrl->readonly=true;'; 
    121122         } 
    122123         if(isset($control['required'])){ 
    123             $required=(string)$control['required']; 
    124             $source[]='$ctrl->required='.($required=='true'?'true':'false').';'; 
     124            if($controltype == 'checkbox'){ 
     125                throw new jException('jelix~formserr.attribute.not.allowed',array('required','checkbox',$this->sourceFile)); 
     126            } 
     127            if('true' == (string)$control['required']) 
     128                $source[]='$ctrl->required=true;'; 
    125129         } 
    126130 
     
    140144 
    141145         switch($controltype){ 
    142             case 'select1': 
    143             case 'select': 
     146            case 'checkboxes': 
     147            case 'radiobuttons': 
     148            case 'menulist': 
     149            case 'listbox': 
    144150                // recuperer les <items> attr label|labellocale value 
    145151                if(isset($control['dao'])){ 
     
    169175               break; 
    170176         } 
     177 
     178         if(isset($control['multiple'])){ 
     179            if($controltype != 'listbox'){ 
     180                throw new jException('jelix~formserr.attribute.not.allowed',array('multiple',$controltype,$this->sourceFile)); 
     181            } 
     182            if('true' == (string)$control['multiple']) 
     183                $source[]='$ctrl->multiple=true;'; 
     184         } 
     185 
    171186         $source[]='$this->addControl($ctrl);'; 
    172  
    173187         return implode("\n", $source); 
    174188    } 
    175189 
    176     protected function generateJsControl($control){ 
     190    protected function generateJsControl($controltype, $control){ 
    177191        $source = array(); 
    178192 
     
    180194            $dt = (string)$control['type']; 
    181195        }else{ 
    182             $dt = 'string'; 
     196            if($controltype == 'checkbox') 
     197                $dt = 'boolean'; 
     198            else 
     199                $dt = 'string'; 
    183200        } 
    184201 
     
    190207        $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'\', \'".$label."\', \''.$dt.'\');\n";'; 
    191208 
    192         if(isset($control['readonly'])){ 
    193             $readonly=(string)$control['readonly']; 
    194             $source[]='$js.="gControl.readonly = '.($readonly=='true'?'true':'false').';\n";'; 
    195         } 
    196         if(isset($control['required'])){ 
    197             $required=(string)$control['required']; 
    198             $source[]='$js.="gControl.required = '.($required=='true'?'true':'false').';\n";'; 
     209        if(isset($control['readonly']) && 'true' == (string)$control['readonly']){ 
     210            $source[]='$js.="gControl.readonly = true;\n";'; 
     211        } 
     212        if(isset($control['required']) && 'true' == (string)$control['required']){ 
     213            $source[]='$js.="gControl.required = true;\n";'; 
    199214        } 
    200215 
    201216        $source[]='$js.="gControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n";'; 
    202217        $source[]='$js.="gControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label))."\';\n";'; 
    203  
    204 /* 
    205          switch($controltype){ 
    206             case 'secret': 
    207                break; 
    208             case 'output': 
    209                 //attr value 
    210                break; 
    211             case 'upload': 
    212                 // attr mediatype 
    213                break; 
    214             case 'select1': 
    215             case 'select': 
    216                 // recuperer les <items> attr label|labellocale value 
    217                 if(isset($control['dao'])){ 
    218                     $daoselector = (string)$control['dao']; 
    219                     $daomethod = (string)$control['daomethod']; 
    220                     $daolabel = (string)$control['daolabelproperty']; 
    221                     $daovalue = (string)$control['daovalueproperty']; 
    222                     $source[]='$ctrl->datasource = new jFormDaoDatasource(\''.$daoselector.'\',\''. 
    223                         $daomethod.'\',\''.$daolabel.'\',\''.$daovalue.'\',);'; 
    224  
    225                 }else{ 
    226                     $source[]='$ctrl->datasource= new jFormStaticDatasource();'; 
    227                     $source[]='$ctrl->datasource->array('; 
    228  
    229                     foreach($control->item as $item){ 
    230                         $value ="'".str_replace("'","\\'",(string)$item['value'])."'=>"; 
    231                         if(isset($item['label'])){ 
    232                             $source[] = $value."'".str_replace("'","\\'",(string)$item['label'])."',"; 
    233                         }elseif(isset($item['labellocale'])){ 
    234                             $source[] = $value."jLocale::get('".(string)$item['labellocale']."'),"; 
    235                         }else{ 
    236                             $source[] = $value."'".str_replace("'","\\'",(string)$item['value'])."',"; 
    237                         } 
    238                     } 
    239                     $source[]=");"; 
    240                 } 
    241                break; 
    242             case 'submit': 
    243                 // attr value 
    244                break; 
    245          }*/ 
     218        if(isset($control['multiple']) && 'true' == (string)$control['multiple']){ 
     219            $source[]='$js.="gControl.multiple = true;\n";'; 
     220        } 
     221 
    246222         $source[]='$js.="gForm.addControl( gControl);\n";'; 
    247223 
    248224         return implode("\n", $source); 
    249  
    250  
    251225    } 
    252226 
  • branches/experimental/jforms/lib/jelix/forms/jFormsCompiler.class.php

    r452 r453  
    6666      foreach($xml->children() as $controltype=>$control){ 
    6767            $source[] = $this->generatePHPControl($controltype, $control); 
    68             $srcjs[] =  $this->generateJsControl($control); 
     68            $srcjs[] =  $this->generateJsControl($controltype, $control); 
    6969      } 
    7070      $source[]='  }'; 
     
    111111            } 
    112112            $source[]='$ctrl->datatype= new jDatatype'.$dt.'();'; 
     113         }else if($controltype == 'checkbox') { 
     114            $source[]='$ctrl->datatype= new jDatatypeBoolean();'; 
    113115         }else{ 
    114116            $source[]='$ctrl->datatype= new jDatatypeString();'; 
     
    116118 
    117119         if(isset($control['readonly'])){ 
    118             $readonly=(string)$control['readonly']; 
    119  
    120             $source[]='$ctrl->readonly='.($readonly=='true'?'true':'false').';'; 
     120            if('true' == (string)$control['readonly']) 
     121                $source[]='$ctrl->readonly=true;'; 
    121122         } 
    122123         if(isset($control['required'])){ 
    123             $required=(string)$control['required']; 
    124             $source[]='$ctrl->required='.($required=='true'?'true':'false').';'; 
     124            if($controltype == 'checkbox'){ 
     125                throw new jException('jelix~formserr.attribute.not.allowed',array('required','checkbox',$this->sourceFile)); 
     126            } 
     127            if('true' == (string)$control['required']) 
     128                $source[]='$ctrl->required=true;'; 
    125129         } 
    126130 
     
    140144 
    141145         switch($controltype){ 
    142             case 'select1': 
    143             case 'select': 
     146            case 'checkboxes': 
     147            case 'radiobuttons': 
     148            case 'menulist': 
     149            case 'listbox': 
    144150                // recuperer les <items> attr label|labellocale value 
    145151                if(isset($control['dao'])){ 
     
    169175               break; 
    170176         } 
     177 
     178         if(isset($control['multiple'])){ 
     179            if($controltype != 'listbox'){ 
     180                throw new jException('jelix~formserr.attribute.not.allowed',array('multiple',$controltype,$this->sourceFile)); 
     181            } 
     182            if('true' == (string)$control['multiple']) 
     183                $source[]='$ctrl->multiple=true;'; 
     184         } 
     185 
    171186         $source[]='$this->addControl($ctrl);'; 
    172  
    173187         return implode("\n", $source); 
    174188    } 
    175189 
    176     protected function generateJsControl($control){ 
     190    protected function generateJsControl($controltype, $control){ 
    177191        $source = array(); 
    178192 
     
    180194            $dt = (string)$control['type']; 
    181195        }else{ 
    182             $dt = 'string'; 
     196            if($controltype == 'checkbox') 
     197                $dt = 'boolean'; 
     198            else 
     199                $dt = 'string'; 
    183200        } 
    184201 
     
    190207        $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'\', \'".$label."\', \''.$dt.'\');\n";'; 
    191208 
    192         if(isset($control['readonly'])){ 
    193             $readonly=(string)$control['readonly']; 
    194             $source[]='$js.="gControl.readonly = '.($readonly=='true'?'true':'false').';\n";'; 
    195         } 
    196         if(isset($control['required'])){ 
    197             $required=(string)$control['required']; 
    198             $source[]='$js.="gControl.required = '.($required=='true'?'true':'false').';\n";'; 
     209        if(isset($control['readonly']) && 'true' == (string)$control['readonly']){ 
     210            $source[]='$js.="gControl.readonly = true;\n";'; 
     211        } 
     212        if(isset($control['required']) && 'true' == (string)$control['required']){ 
     213            $source[]='$js.="gControl.required = true;\n";'; 
    199214        } 
    200215 
    201216        $source[]='$js.="gControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n";'; 
    202217        $source[]='$js.="gControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label))."\';\n";'; 
    203  
    204 /* 
    205          switch($controltype){ 
    206             case 'secret': 
    207                break; 
    208             case 'output': 
    209                 //attr value 
    210                break; 
    211             case 'upload': 
    212                 // attr mediatype 
    213                break; 
    214             case 'select1': 
    215             case 'select': 
    216                 // recuperer les <items> attr label|labellocale value 
    217                 if(isset($control['dao'])){ 
    218                     $daoselector = (string)$control['dao']; 
    219                     $daomethod = (string)$control['daomethod']; 
    220                     $daolabel = (string)$control['daolabelproperty']; 
    221                     $daovalue = (string)$control['daovalueproperty']; 
    222                     $source[]='$ctrl->datasource = new jFormDaoDatasource(\''.$daoselector.'\',\''. 
    223                         $daomethod.'\',\''.$daolabel.'\',\''.$daovalue.'\',);'; 
    224  
    225                 }else{ 
    226                     $source[]='$ctrl->datasource= new jFormStaticDatasource();'; 
    227                     $source[]='$ctrl->datasource->array('; 
    228  
    229                     foreach($control->item as $item){ 
    230                         $value ="'".str_replace("'","\\'",(string)$item['value'])."'=>"; 
    231                         if(isset($item['label'])){ 
    232                             $source[] = $value."'".str_replace("'","\\'",(string)$item['label'])."',"; 
    233                         }elseif(isset($item['labellocale'])){ 
    234                             $source[] = $value."jLocale::get('".(string)$item['labellocale']."'),"; 
    235                         }else{ 
    236                             $source[] = $value."'".str_replace("'","\\'",(string)$item['value'])."',"; 
    237                         } 
    238                     } 
    239                     $source[]=");"; 
    240                 } 
    241                break; 
    242             case 'submit': 
    243                 // attr value 
    244                break; 
    245          }*/ 
     218        if(isset($control['multiple']) && 'true' == (string)$control['multiple']){ 
     219            $source[]='$js.="gControl.multiple = true;\n";'; 
     220        } 
     221 
    246222         $source[]='$js.="gForm.addControl( gControl);\n";'; 
    247223 
    248224         return implode("\n", $source); 
    249  
    250  
    251225    } 
    252226 
  • branches/experimental/jforms/lib/jelix/forms/jFormsControl.class.php

    r442 r453  
    6363 * @experimental 
    6464 */ 
    65 class jFormsControlSelect extends jFormsControlSelect1 { 
     65/*class jFormsControlSelect extends jFormsControlSelect1 { 
    6666   public $type="select"; 
     67}*/ 
     68 
     69/** 
     70 * 
     71 * @package     jelix 
     72 * @subpackage  forms 
     73 * @experimental 
     74 */ 
     75class jFormsControlCheckboxes extends jFormsControlSelect1 { 
     76   public $type="checkboxes"; 
     77} 
     78 
     79/** 
     80 * 
     81 * @package     jelix 
     82 * @subpackage  forms 
     83 * @experimental 
     84 */ 
     85class jFormsControlRadiobuttons extends jFormsControlSelect1 { 
     86   public $type="radiobuttons"; 
     87} 
     88 
     89/** 
     90 * 
     91 * @package     jelix 
     92 * @subpackage  forms 
     93 * @experimental 
     94 */ 
     95class jFormsControlListbox extends jFormsControlSelect1 { 
     96   public $type="listbox"; 
     97   public $multiple = false; 
     98} 
     99 
     100/** 
     101 * 
     102 * @package     jelix 
     103 * @subpackage  forms 
     104 * @experimental 
     105 */ 
     106class jFormsControlMenulist extends jFormsControlSelect1 { 
     107   public $type="menulist"; 
    67108} 
    68109 
     
    85126class jFormsControlSecret extends jFormsControl { 
    86127   public $type='secret'; 
     128} 
     129 
     130/** 
     131 * 
     132 * @package     jelix 
     133 * @subpackage  forms 
     134 * @experimental 
     135 */ 
     136class jFormsControlCheckbox extends jFormsControl { 
     137   public $type='checkbox'; 
    87138} 
    88139 
  • branches/experimental/jforms/lib/jelix/forms/jFormsControl.class.php

    r442 r453  
    6363 * @experimental 
    6464 */ 
    65 class jFormsControlSelect extends jFormsControlSelect1 { 
     65/*class jFormsControlSelect extends jFormsControlSelect1 { 
    6666   public $type="select"; 
     67}*/ 
     68 
     69/** 
     70 * 
     71 * @package     jelix 
     72 * @subpackage  forms 
     73 * @experimental 
     74 */ 
     75class jFormsControlCheckboxes extends jFormsControlSelect1 { 
     76   public $type="checkboxes"; 
     77} 
     78 
     79/** 
     80 * 
     81 * @package     jelix 
     82 * @subpackage  forms 
     83 * @experimental 
     84 */ 
     85class jFormsControlRadiobuttons extends jFormsControlSelect1 { 
     86   public $type="radiobuttons"; 
     87} 
     88 
     89/** 
     90 * 
     91 * @package     jelix 
     92 * @subpackage  forms 
     93 * @experimental 
     94 */ 
     95class jFormsControlListbox extends jFormsControlSelect1 { 
     96   public $type="listbox"; 
     97   public $multiple = false; 
     98} 
     99 
     100/** 
     101 * 
     102 * @package     jelix 
     103 * @subpackage  forms 
     104 * @experimental 
     105 */ 
     106class jFormsControlMenulist extends jFormsControlSelect1 { 
     107   public $type="menulist"; 
    67108} 
    68109 
     
    85126class jFormsControlSecret extends jFormsControl { 
    86127   public $type='secret'; 
     128} 
     129 
     130/** 
     131 * 
     132 * @package     jelix 
     133 * @subpackage  forms 
     134 * @experimental 
     135 */ 
     136class jFormsControlCheckbox extends jFormsControl { 
     137   public $type='checkbox'; 
    87138} 
    88139 
  • branches/experimental/jforms/lib/jelix/forms/jFormsDatasource.class.php

    r324 r453  
    5757   public function getDatas(){ 
    5858      $dao = jDao::get($this->daoselector); 
    59       $found = $dao->${$this->daomethod}();