Changeset 1029 for branches
- Timestamp:
- 07/19/08 21:38:31 (1 month ago)
- Files:
-
- branches/experimental/jforms-groups/lib/jelix/docs/ns/jforms_1.1.rng (modified) (4 diffs)
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsCompiler_jf_1_1.class.php (modified) (2 diffs)
- branches/experimental/jforms-groups/lib/jelix/forms/jFormsDatasource.class.php (modified) (4 diffs)
- branches/experimental/jforms-groups/testapp/modules/jelix_tests/daos/products.dao.xml (modified) (1 diff)
- branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.compiler_1_1.html_cli.php (modified) (8 diffs)
- branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html_cli.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/experimental/jforms-groups/lib/jelix/docs/ns/jforms_1.1.rng
r984 r1029 148 148 </element> 149 149 </define> 150 150 151 151 <define name="checkbox"> 152 152 <element name="checkbox"> … … 274 274 </optional> 275 275 </define> 276 276 277 277 <define name="UI.attr.readonly"> 278 278 <optional><attribute name="readonly"><choice><value>true</value><value>false</value></choice></attribute></optional> … … 284 284 <optional><attribute name="defaultvalue" /></optional> 285 285 </define> 286 286 287 287 <define name="attr.length"> 288 288 <optional><attribute name="minlength"><data type="integer" /></attribute></optional> … … 355 355 <attribute name="daomethod" /> 356 356 <attribute name="labelproperty" /> 357 <optional><attribute name="labelseparator" /></optional> 357 358 <optional><attribute name="valueproperty" /></optional> 358 359 <optional> branches/experimental/jforms-groups/lib/jelix/forms/jFormsCompiler_jf_1_1.class.php
r985 r1029 192 192 193 193 if(isset($attrs['dao'])) { 194 if ( isset($attrs['profile']))195 $profile = ' \''.$attrs['profile'].'\'';194 if (isset($attrs['profile'])) 195 $profile = ',\''.$attrs['profile'].'\''; 196 196 else 197 $profile = ' \'\'';198 if (isset($attrs['valueproperty'])) {197 $profile = ',\'\''; 198 if (isset($attrs['valueproperty'])) { 199 199 $daovalue = $attrs['valueproperty']; 200 200 } else … … 206 206 207 207 if(isset($attrs['criteria'])) 208 $criteria=',\''.$attrs['criteria'].'\' ';208 $criteria=',\''.$attrs['criteria'].'\',null'; 209 209 elseif(isset($attrs['criteriafrom'])) 210 210 $criteria=',null,\''.$attrs['criteriafrom'].'\''; 211 211 else 212 $criteria=''; 212 $criteria=',null,null'; 213 if (isset($attrs['labelseparator'])) 214 $labelSeparator = ',\''.$attrs['labelseparator'].'\''; 215 else 216 $labelSeparator = ''; 213 217 214 218 $source[]='$ctrl->datasource = new jFormsDaoDatasource(\''.$attrs['dao'].'\',\''. 215 $attrs['method'].'\',\''.$attrs['labelproperty'].'\',\''.$daovalue.'\' ,'.$profile.$criteria.');';219 $attrs['method'].'\',\''.$attrs['labelproperty'].'\',\''.$daovalue.'\''.$profile.$criteria.$labelSeparator.');'; 216 220 if($controltype == 'submit'){ 217 221 $source[]='$ctrl->standalone=false;'; branches/experimental/jforms-groups/lib/jelix/forms/jFormsDatasource.class.php
r966 r1029 79 79 protected $selector; 80 80 protected $method; 81 protected $labelProperty; 81 protected $labelProperty = array(); 82 protected $labelSeparator; 82 83 protected $keyProperty; 83 84 protected $profile; 84 85 85 protected $criteria ;86 protected $criteriaF orm;86 protected $criteria = null; 87 protected $criteriaFrom = null; 87 88 88 89 protected $dao = null; 89 90 90 function __construct ($selector ,$method , $label, $key, $profile='', $criteria=null, $criteriaFrom=null ){91 function __construct ($selector ,$method , $label, $key, $profile='', $criteria=null, $criteriaFrom=null, $labelSeparator=''){ 91 92 $this->selector = $selector; 92 93 $this->profile = $profile; 93 94 $this->method = $method ; 94 $this->labelProperty = $label; 95 $this->criteria = $criteria; 96 $this->criteriaFrom = $criteriaFrom; 95 $this->labelProperty = preg_split('/[\s,]+/',$label); 96 $this->labelSeparator = $labelSeparator; 97 if ( $criteria !== null ) 98 $this->criteria = preg_split('/[\s,]+/',$criteria) ; 99 if ( $criteriaFrom !== null ) 100 $this->criteriaFrom = preg_split('/[\s,]+/',$criteriaFrom) ; 101 97 102 if($key == ''){ 98 103 $rec = jDao::createRecord($this->selector, $this->profile); … … 107 112 $this->dao = jDao::get($this->selector, $this->profile); 108 113 if($this->criteria !== null) { 109 $found = $this->dao->{$this->method}($this->criteria);114 $found = call_user_func_array( array($this->dao, $this->method), $this->criteria); 110 115 } else if ($this->criteriaFrom !== null) { 111 $found = $this->dao->{$this->method}($form->getData($this->criteriaFrom)); 116 $args = array() ; 117 foreach( (array)$this->criteriaFrom as $criteria ) { 118 array_push( $args, $form->getData($criteria) ) ; 119 } 120 $found = call_user_func_array( array($this->dao, $this->method), $args); 112 121 } else { 113 122 $found = $this->dao->{$this->method}(); … … 115 124 $result=array(); 116 125 foreach($found as $obj){ 117 $result[$obj->{$this->keyProperty}] = $obj->{$this->labelProperty}; 126 $label = '' ; 127 foreach( (array)$this->labelProperty as $property ) { 128 if (!empty( $obj->{$property})) 129 $label .= $obj->{$property}.$this->labelSeparator; 130 } 131 if ($this->labelSeparator != '') 132 $label = substr($label, 0, -strlen($this->labelSeparator)); 133 $result[$obj->{$this->keyProperty}] = $label ; 118 134 } 119 135 return $result; … … 123 139 if($this->dao === null) $this->dao = jDao::get($this->selector, $this->profile); 124 140 $rec = $this->dao->get($key); 125 if($rec) 126 return $rec->{$this->labelProperty}; 141 if ($rec) { 142 $label = '' ; 143 foreach( (array)$this->labelProperty as $property ) { 144 if (!empty( $rec->{$property})) 145 $label .= $rec->{$property}.$this->labelSeparator; 146 } 147 if ($this->labelSeparator != '') 148 $label = substr($label, 0, -strlen($this->labelSeparator)); 149 return $label ; 150 } 127 151 else 128 152 return null; 129 153 } 130 131 154 } 132 155 branches/experimental/jforms-groups/testapp/modules/jelix_tests/daos/products.dao.xml
r895 r1029 17 17 </conditions> 18 18 </method> 19 <method name="findBetweenId" type="select"> 20 <parameter name="minId" /> 21 <parameter name="maxId" /> 22 <conditions> 23 <gt property="id" expr="$minId" /> 24 <lt property="id" expr="$maxId" /> 25 </conditions> 26 </method> 19 27 </factory> 20 28 </dao> branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.compiler_1_1.html_cli.php
r994 r1029 4 4 * @subpackage unittest module 5 5 * @author Jouanneau Laurent 6 * @contributor Loic Mathaud 6 * @contributor Loic Mathaud, Dominique Papin 7 7 * @copyright 2007-2008 Jouanneau laurent 8 * @copyright 2007 Loic Mathaud 8 * @copyright 2007 Loic Mathaud, 2008 Dominique Papin 9 9 * @link http://www.jelix.org 10 10 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html … … 369 369 </item> 370 370 </choice>', 371 79=>'<menulist ref="nom" xmlns="http://jelix.org/ns/forms/1.1"> 372 <label>Votre nom</label> 373 <datasource dao="foo" method="bar" labelproperty="baz" valueproperty="plop" criteriafrom="prenom" profile="youp"/> 374 </menulist>', 375 80=>'<menulist ref="nom" xmlns="http://jelix.org/ns/forms/1.1"> 376 <label>Votre nom</label> 377 <datasource dao="foo" method="bar" labelproperty="baz,biz" valueproperty="plop" criteria="joe,dumb"/> 378 </menulist>', 379 81=>'<menulist ref="nom" xmlns="http://jelix.org/ns/forms/1.1"> 380 <label>Votre nom</label> 381 <datasource dao="foo" method="bar" labelproperty="baz,biz" valueproperty="plop" criteriafrom="prenom,nom"/> 382 </menulist>', 383 82=>'<menulist ref="nom" xmlns="http://jelix.org/ns/forms/1.1"> 384 <label>Votre nom</label> 385 <datasource dao="foo" method="bar" labelproperty="baz,biz" labelseparator=" - " valueproperty="plop" criteriafrom="prenom,nom"/> 386 </menulist>', 387 371 388 ); 372 389 … … 616 633 45=>'$ctrl= new jFormsControlsubmit(\'validation\'); 617 634 $ctrl->label=\'Type de validation\'; 618 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\' );635 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\',null,null); 619 636 $ctrl->standalone=false; 620 637 $this->addControl($ctrl);', … … 726 743 67=>'$ctrl= new jFormsControlcheckboxes(\'nom\'); 727 744 $ctrl->label=\'Votre nom\'; 728 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\' );745 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\',null,null); 729 746 $this->addControl($ctrl);', 730 747 68=>'$ctrl= new jFormsControlradiobuttons(\'nom\'); 731 748 $ctrl->label=\'Votre nom\'; 732 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\' );749 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\',null,null); 733 750 $this->addControl($ctrl);', 734 751 69=>'$ctrl= new jFormsControllistbox(\'nom\'); 735 752 $ctrl->label=\'Votre nom\'; 736 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\' );753 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\',null,null); 737 754 $this->addControl($ctrl);', 738 755 70=>'$ctrl= new jFormsControlmenulist(\'nom\'); 739 756 $ctrl->label=\'Votre nom\'; 740 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\' );757 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\',null,null); 741 758 $this->addControl($ctrl);', 742 759 71=>'$ctrl= new jFormsControllistbox(\'nom\'); 743 760 $ctrl->label=\'Votre nom\'; 744 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\' );761 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\',null,null); 745 762 $ctrl->multiple=true; 746 763 $this->addControl($ctrl);', 747 764 72=>'$ctrl= new jFormsControllistbox(\'nom\'); 748 765 $ctrl->label=\'Votre nom\'; 749 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\',\'toto\' );766 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\',\'toto\',null); 750 767 $this->addControl($ctrl);', 751 768 73=>'$ctrl= new jFormsControllistbox(\'nom\'); 752 769 $ctrl->label=\'Votre nom\'; 753 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'youp\',\'toto\' );770 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'youp\',\'toto\',null); 754 771 $this->addControl($ctrl);', 755 772 74=>'$ctrl= new jFormsControllistbox(\'nom\'); … … 773 790 $ctrl= new jFormsControllistbox(\'list\'); 774 791 $ctrl->label=\'a list\'; 775 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\' );792 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\',null,null); 776 793 $topctrl->addChildControl($ctrl); 777 794 $ctrl = $topctrl; … … 796 813 $ctrl= new jFormsControllistbox(\'list\'); 797 814 $ctrl->label=\'a list\'; 798 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\' );815 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'\',null,null); 799 816 $topctrl->addChildControl($ctrl,\'choix2\'); 800 817 $ctrl= new jFormsControlsecret(\'pwd\'); … … 805 822 $ctrl = $topctrl; 806 823 $this->addControl($ctrl);', 824 79=>'$ctrl= new jFormsControlmenulist(\'nom\'); 825 $ctrl->label=\'Votre nom\'; 826 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz\',\'plop\',\'youp\',null,\'prenom\'); 827 $this->addControl($ctrl);', 828 80=>'$ctrl= new jFormsControlmenulist(\'nom\'); 829 $ctrl->label=\'Votre nom\'; 830 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz,biz\',\'plop\',\'\',\'joe,dumb\',null); 831 $this->addControl($ctrl);', 832 81=>'$ctrl= new jFormsControlmenulist(\'nom\'); 833 $ctrl->label=\'Votre nom\'; 834 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz,biz\',\'plop\',\'\',null,\'prenom,nom\'); 835 $this->addControl($ctrl);', 836 82=>'$ctrl= new jFormsControlmenulist(\'nom\'); 837 $ctrl->label=\'Votre nom\'; 838 $ctrl->datasource = new jFormsDaoDatasource(\'foo\',\'bar\',\'baz,biz\',\'plop\',\'\',null,\'prenom,nom\',\' - \'); 839 $this->addControl($ctrl);', 807 840 ); 808 841 … … 1232 1265 $js.="jForms.tControl2.addControl(jForms.tControl, \'choix2\');\n"; 1233 1266 $js.="jForms.tForm.addControl(jForms.tControl2);\n";', 1267 79=>'$label = \'Votre nom\'; 1268 $js.="jForms.tControl = new jFormsControlString(\'nom\', \'".str_replace("\'","\\\'",$label)."\');\n"; 1269 $js.="jForms.tControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n"; 1270 $js.="jForms.tControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label))."\';\n"; 1271 $js.="jForms.tForm.addControl(jForms.tControl);\n";', 1272 80=>'$label = \'Votre nom\'; 1273 $js.="jForms.tControl = new jFormsControlString(\'nom\', \'".str_replace("\'","\\\'",$label)."\');\n"; 1274 $js.="jForms.tControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n"; 1275 $js.="jForms.tControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label))."\';\n"; 1276 $js.="jForms.tForm.addControl(jForms.tControl);\n";', 1277 81=>'$label = \'Votre nom\'; 1278 $js.="jForms.tControl = new jFormsControlString(\'nom\', \'".str_replace("\'","\\\'",$label)."\');\n"; 1279 $js.="jForms.tControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n"; 1280 $js.="jForms.tControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label))."\';\n"; 1281 $js.="jForms.tForm.addControl(jForms.tControl);\n";', 1282 82=>'$label = \'Votre nom\'; 1283 $js.="jForms.tControl = new jFormsControlString(\'nom\', \'".str_replace("\'","\\\'",$label)."\');\n"; 1284 $js.="jForms.tControl.errRequired=\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.required\',$label))."\';\n"; 1285 $js.="jForms.tControl.errInvalid =\'".str_replace("\'","\\\'",jLocale::get(\'jelix~formserr.js.err.invalid\', $label))."\';\n"; 1286 $js.="jForms.tForm.addControl(jForms.tControl);\n";', 1234 1287 1235 1288 ); branches/experimental/jforms-groups/testapp/modules/jelix_tests/tests/jforms.htmlbuilder.html_cli.php
r1028 r1029 4 4 * @subpackage unittest module 5 5 * @author Jouanneau Laurent 6 * @contributor 6 * @contributor Dominique Papin 7 7 * @copyright 2007-2008 Jouanneau laurent 8 * @copyright 2008 Dominique Papin 8 9 * @link http://www.jelix.org 9 10 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html … … 446 447 $this->assertEqualOrDiff($result, $out); 447 448 449 $this->form->setData('menulist1',""); 450 $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findByMaxId','name,price','id','','25',null); 451 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 452 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" size="1">'; 453 $result.='<option value="" selected="selected"></option>'; 454 $result.='<option value="10">foo12</option>'; 455 $result.='<option value="11">bar54</option>'; 456 $result.='<option value="23">baz97</option>'; 457 $result.='</select>'; 458 $this->assertEqualOrDiff($result, $out); 459 460 $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findByMaxId','name,price','id','','25',null,' - '); 461 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 462 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" size="1">'; 463 $result.='<option value="" selected="selected"></option>'; 464 $result.='<option value="10">foo - 12</option>'; 465 $result.='<option value="11">bar - 54</option>'; 466 $result.='<option value="23">baz - 97</option>'; 467 $result.='</select>'; 468 $this->assertEqualOrDiff($result, $out); 469 470 $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findBetweenId','name,price','id','','9,25',null,' - '); 471 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 472 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" size="1">'; 473 $result.='<option value="" selected="selected"></option>'; 474 $result.='<option value="10">foo - 12</option>'; 475 $result.='<option value="11">bar - 54</option>'; 476 $result.='<option value="23">baz - 97</option>'; 477 $result.='</select>'; 478 $this->assertEqualOrDiff($result, $out); 479 480 $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findBetweenId','name,price','id','','10,25',null,' - '); 481 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 482 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" size="1">'; 483 $result.='<option value="" selected="selected"></option>'; 484 $result.='<option value="11">bar - 54</option>'; 485 $result.='<option value="23">baz - 97</option>'; 486 $result.='</select>'; 487 $this->assertEqualOrDiff($result, $out); 488 489 $this->form->addControl(new jFormsControlHidden('hidden2')); 490 $this->form->setData('hidden1',"9"); 491 $this->form->setData('hidden2',"25"); 492 $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findBetweenId','name,price','id','',null,'hidden1,hidden2',' - '); 493 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 494 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" size="1">'; 495 $result.='<option value="" selected="selected"></option>'; 496 $result.='<option value="10">foo - 12</option>'; 497 $result.='<option value="11">bar - 54</option>'; 498 $result.='<option value="23">baz - 97</option>'; 499 $result.='</select>'; 500 $this->assertEqualOrDiff($result, $out); 501 502 $this->form->setData('hidden1',"10"); 503 $this->form->setData('hidden2',"25"); 504 $ctrl->datasource = new jFormsDaoDatasource('jelix_tests~products','findBetweenId','name,price','id','',null,'hidden1,hidden2',' - '); 505 ob_start();$this->builder->outputControl($ctrl);$out = ob_get_clean(); 506 $result='<select name="menulist1" id="'.$this->formname.'_menulist1" size="1">'; 507 $result.='<option value="" selected="selected"></option>'; 508 $result.='<option value="11">bar - 54</option>'; 509 $result.='<option value="23">baz - 97</option>'; 510 $result.='</select>'; 511 $this->assertEqualOrDiff($result, $out); 512 513 514 $this->form->removeControl('hidden2'); 515 $this->form->setData('hidden1',"11"); 448 516 } 449 517
