Changeset 437
- Timestamp:
- 05/09/07 18:21:13 (2 years ago)
- Files:
-
- branches/experimental/jforms/build/manifests/jelix-lib.mn (modified) (1 diff)
- branches/experimental/jforms/build/manifests/testapp.mn (modified) (2 diffs)
- branches/experimental/jforms/lib/jelix-www/js/jforms.js (modified) (2 diffs)
- branches/experimental/jforms/lib/jelix/core/jSelector.class.php (modified) (1 diff)
- branches/experimental/jforms/lib/jelix/docs/ns/jforms-controls.rng (modified) (16 diffs)
- branches/experimental/jforms/lib/jelix/docs/ns/jforms.rng (modified) (2 diffs)
- branches/experimental/jforms/lib/jelix/forms/jFormsBase.class.php (modified) (2 diffs)
- branches/experimental/jforms/lib/jelix/forms/jFormsBuilderBase.class.php (modified) (2 diffs)
- branches/experimental/jforms/lib/jelix/forms/jFormsCompiler.class.php (modified) (7 diffs)
- branches/experimental/jforms/lib/jelix/tpl/plugins/html/block.form.php (modified) (2 diffs)
- branches/experimental/jforms/testapp/modules/unittest/classes/unittestservice.class.php (modified) (1 diff)
- branches/experimental/jforms/testapp/modules/unittest/classes/utjforms.class.php (added)
- branches/experimental/jforms/testapp/modules/unittest/controllers/jforms.classic.php (added)
- branches/experimental/jforms/testapp/modules/unittest/templates/menu.tpl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/experimental/jforms/build/manifests/jelix-lib.mn
r436 r437 111 111 jForms.class.php 112 112 jFormsBase.class.php 113 jFormsBuilderBase.class.php 113 114 jFormsCompiler.class.php 114 115 jFormsControl.class.php 115 116 jFormsDataContainer.class.php 116 117 jFormsDatasource.class.php 118 jforms_jstemplate.php 117 119 118 120 cd lib/jelix/tpl/ branches/experimental/jforms/build/manifests/testapp.mn
r436 r437 84 84 utjaclusergroup.class.php 85 85 test.iface.php 86 utjforms.class.php 86 87 cd testapp/modules/unittest/classes/tests 87 88 foo.class.php … … 109 110 tpl.classic.php 110 111 acl.classic.php 112 jforms.classic.php 111 113 112 114 cd testapp/var branches/experimental/jforms/lib/jelix-www/js/jforms.js
r432 r437 32 32 */ 33 33 34 35 var gForm, gControl; 34 36 35 37 /* … … 234 236 this.datatype = datatype; 235 237 this.required = false; 238 this.readonly = false; 236 239 this.errInvalid = ''; 237 240 this.errRequired = ''; branches/experimental/jforms/lib/jelix/core/jSelector.class.php
r436 r437 652 652 } 653 653 654 public function getCompiledBuild FilePath (){655 return JELIX_APP_TEMP_PATH.'compiled/'.$this->_dirname.$this->module.'~'.$this->resource.'_ htmlbuilder'.$this->_cacheSuffix;;654 public function getCompiledBuilderPath ($type){ 655 return JELIX_APP_TEMP_PATH.'compiled/'.$this->_dirname.$this->module.'~'.$this->resource.'_builder_'.$type.$this->_cacheSuffix; 656 656 } 657 657 } branches/experimental/jforms/lib/jelix/docs/ns/jforms-controls.rng
r436 r437 6 6 <attribute name="ref" /> 7 7 <ref name="label" /> 8 < zeroOrMore>8 <!--<zeroOrMore> 9 9 <choice> 10 10 <ref name="help" /> 11 11 <ref name="hint" /> 12 12 <ref name="alert" /> 13 < !--<ref name="actions" />-->13 <ref name="actions" /> 14 14 </choice> 15 </zeroOrMore> 16 </define> 17 15 </zeroOrMore>--> 16 </define> 17 <!-- 18 18 <define name="UI.Common.Attrs"> 19 19 20 </define> 20 </define>--> 21 21 22 22 … … 27 27 </define> 28 28 29 29 30 <define name="List.UI.Common"> 30 31 <choice> … … 34 35 <ref name="daodatasource" /> 35 36 </choice> 36 <optional>37 <!-- <optional> 37 38 <attribute name="appearance"> 38 39 <choice> … … 42 43 </choice> 43 44 </attribute> 44 </optional> 45 </define> 46 45 </optional> --> 46 </define> 47 <define name="item"> 48 <element name="item"> 49 <optional> 50 <choice> 51 <attribute name="label" /> 52 <attribute name="labellocale" /> 53 </choice> 54 </optional> 55 <attribute name="value" /> 56 </element> 57 </define> 58 47 59 <define name="datatypes"> 48 < choice>60 <!--<choice>--> 49 61 <ref name="datatype.attr"/> 50 <element name="datatype">62 <!-- <element name="datatype"> 51 63 <ref name="datatype.attr"/> 52 64 <optional><attribute name="length" /></optional> … … 57 69 <optional><attribute name="minvalue" /></optional> 58 70 <empty /> 59 </element> 71 </element>--> 60 72 </define> 61 73 … … 84 96 <attribute name="daovalueproperty" /> 85 97 </define> 86 98 87 99 <!-- Controls --> 88 89 90 100 <define name="controls"> 91 101 <oneOrMore> … … 112 122 <element name="input"> 113 123 <ref name="UI.Common" /> 124 <ref name="UI.Common.data" /> 114 125 </element> 115 126 </define> … … 131 142 <element name="upload"> 132 143 <ref name="UI.Common" /> 133 < attribute name="mediatype" /> <!-- indique les types autorisés-->144 <!--<attribute name="mediatype" /> --> 134 145 </element> 135 146 </define> … … 138 149 <element name="select1"> 139 150 <ref name="UI.Common" /> 140 <ref name="UI.Common.Attrs" />141 151 <ref name="List.UI.Common" /> 142 <!-- saisie libre autorisée --> 143 <!--<optional> 152 <optional> 144 153 <attribute name="selection"> 145 154 <choice> … … 148 157 </choice> 149 158 </attribute> 150 </optional> -->159 </optional> 151 160 </element> 152 161 </define> … … 156 165 <element name="select"> 157 166 <ref name="UI.Common" /> 158 <ref name="UI.Common.Attrs" />159 167 <ref name="List.UI.Common" /> 160 < !--<optional>168 <optional> 161 169 <attribute name="selection"> 162 170 <choice> … … 165 173 </choice> 166 174 </attribute> 167 </optional> -->175 </optional> 168 176 </element> 169 177 </define> … … 172 180 <element name="output"> 173 181 <ref name="UI.Common" /> 174 <ref name="UI.Common.Attrs" /> 175 <optional><attribute name="value"/></optional> 182 <!--<optional><attribute name="value"/></optional>--> 176 183 </element> 177 184 </define> … … 180 187 <element name="submit"> 181 188 <ref name="UI.Common" /> 182 <ref name="UI.Common.Attrs" /> 183 <optional><attribute name="value"/></optional> 184 </element> 185 </define> 186 189 <!--<optional><attribute name="value"/></optional>--> 190 </element> 191 </define> 192 --> 187 193 188 194 <!-- … … 217 223 <define name="label"> 218 224 <element name="label"> 219 <choice> 220 <ref name="message.content" /> 221 <attribute name="locale" /> 222 </choice> 223 </element> 224 </define> 225 225 <ref name="message.content" /> 226 </element> 227 </define> 228 229 <!-- 226 230 <define name="hint"> 227 231 <element name="hint"> … … 241 245 </element> 242 246 </define> 243 244 <define name="item"> 245 <element name="item"> 246 <choice> 247 <ref name="label" /> 248 <attribute name="label" /> 249 <attribute name="labellocale" /> 250 </choice> 251 <attribute name="value" /> 252 </element> 253 </define> 247 --> 248 254 249 255 250 </grammar> branches/experimental/jforms/lib/jelix/docs/ns/jforms.rng
r436 r437 12 12 </element> 13 13 </start> 14 14 <!-- 15 15 <define name="Common.Attributes"> 16 16 17 17 </define> 18 19 20 18 --> 19 <!-- 21 20 <define name="any"> 22 21 <element> … … 33 32 </element> 34 33 </define> 35 34 --> 36 35 </grammar> branches/experimental/jforms/lib/jelix/forms/jFormsBase.class.php
r432 r437 44 44 */ 45 45 protected $_readOnly = false; 46 47 /** 48 * content list of available form builder 49 * @var boolean 50 */ 51 protected $_builders = array(); 52 53 46 54 47 55 /** … … 193 201 194 202 203 /** 204 * @param string $buildertype the type name of a form builder 205 * @return jFormsBuilderBase 206 */ 207 public function getBuilder($buildertype){ 208 if(isset($this->_builders[$buildertype])){ 209 include_once ($this->_builders[$buildertype][0]); 210 $c = $this->_builders[$buildertype][1]; 211 return new $c($this); 212 }else{ 213 throw new Exception('invalid form builder type'); 214 } 215 } 195 216 196 217 } branches/experimental/jforms/lib/jelix/forms/jFormsBuilderBase.class.php
r374 r437 41 41 * @param jFormsBase $form a form object 42 42 * @param string $action action selector where form will be submit 43 * @param array $actionParams parameters for the action 43 44 */ 44 public function __construct($form, $action ){45 public function __construct($form, $action, $actionParams){ 45 46 $this->_form = $form; 46 47 $this->_action = $action; 48 $this->_actionParams = $actionParams; 47 49 } 48 50 49 51 50 protected function getFormName(){ 52 abstract public function outputHeader(); 53 54 abstract public function outputFooter(); 55 56 public static function getFormName(){ 51 57 static $number = 0; 52 58 $number++; … … 55 61 } 56 62 57 abstract class jForms BuilderBase extends jFormsHtmlBuilderBase {63 abstract class jFormsHtmlBuilderBase extends jFormsBuilderBase { 58 64 59 65 public function outputHeader(){ 66 $url = jUrl::get($this->_action, $this->_actionParams, 2); // retourne le jurl correspondant 67 68 echo '<form action="'.$url->scriptName . $url->pathInfo.'" method="POST" name="'. jFormsBuilderBase::getFormName().'">'; 69 if(count($url->params)){ 70 echo '<div>'; 71 foreach ($url->params as $p_name => $p_value) { 72 echo '<input type="hidden" name="'. $p_name .'" value="'. htmlspecialchars($p_value) .'"/>', "\n"; 73 } 74 echo '</div>'; 75 } 76 77 } 78 79 public function outputFooter(){ 80 echo '</form>'; 81 } 60 82 61 83 abstract public function getJavascriptCheck(); branches/experimental/jforms/lib/jelix/forms/jFormsCompiler.class.php
r436 r437 32 32 $this->sourceFile = $selector->getPath(); 33 33 $cachefile = $selector->getCompiledFilePath(); 34 $cache buildfile = $selector->getCompiledBuildFilePath ();34 $cacheHtmlBuilderFile = $selector->getCompiledBuildFilePath ('html'); 35 35 36 36 // compilation du fichier xml … … 47 47 48 48 $source=array(); 49 $source[]='<?php class '.$selector->getClass().' extends jFormsBase {'; 49 $source[]='<?php '; 50 $source[]='class '.$selector->getClass().' extends jFormsBase {'; 51 $source[]=' protected $_builders = array( '; 52 $source[]=' \'html\'=>array(\''.$cacheHtmlBuilderFile.'\',\''.$selector->getClass().'_builder_html\'), '; 53 $source[]=' );'; 50 54 $source[]=' public function __construct(&$container, $reset = false){'; 51 55 $source[]=' parent::__construct($container, $reset); '; 52 56 53 57 54 $src build=array();55 $src build[]='<?php class '.$selector->getClass().'_HtmlBuilderextends jFormsHtmlBuilderBase {';56 $src build[]=' public function __construct($form, $action){';57 $src build[]=' parent::__construct($form, $action); ';58 $src build[]=' }';58 $srcHtmlBuilder=array(); 59 $srcHtmlBuilder[]='<?php class '.$selector->getClass().'_builder_html extends jFormsHtmlBuilderBase {'; 60 $srcHtmlBuilder[]=' public function __construct($form, $action){'; 61 $srcHtmlBuilder[]=' parent::__construct($form, $action); '; 62 $srcHtmlBuilder[]=' }'; 59 63 60 64 $srcjs=array(); … … 63 67 foreach($xml->children() as $controltype=>$control){ 64 68 $source[] = $this->generatePHPControl($controltype, $control); 69 $srcjs[] = $this->generateJsControl($control); 65 70 } 66 71 … … 74 79 75 80 76 $src build[]=' public function getJavascriptCheck(){';77 $src build[]= implode("\n", $srcjs);78 $src build[]=' return $verif; }';79 $src build[]='} ?>';80 81 jFile::write($cache buildfile, implode("\n", $srcbuild));81 $srcHtmlBuilder[]=' public function getJavascriptCheck(){'; 82 $srcHtmlBuilder[]= implode("\n", $srcjs); 83 $srcHtmlBuilder[]=' return $verif; }'; 84 $srcHtmlBuilder[]='} ?>'; 85 86 jFile::write($cacheHtmlBuilderFile, implode("\n", $srcHtmlBuilder)); 82 87 83 88 return true; 84 }89 } 85 90 86 91 87 92 protected function generatePHPControl($controltype, $control){ 88 93 89 $source []= array();94 $source = array(); 90 95 $class = 'jFormsControl'.$controltype; 91 96 … … 133 138 } 134 139 135 if(!isset($control->label)){136 throw new jException('jelix~formserr.tag.missing',array('label',$controltype,$this->sourceFile));137 }138 139 if(isset($control->label['locale'])){140 $label='';141 $labellocale=(string)$control->label['locale'];142 $source[]='$ctrl->labellocale=\''.$labellocale.'\';';143 }else{144 $label=(string)$control->label;145 $labellocale='';146 $source[]='$ctrl->label=\''.str_replace("'","\\'",$label).'\';';147 }148 149 140 switch($controltype){ 150 141 case 'input': … … 169 160 $daovalue = (string)$control['daovalueproperty']; 170 161 $source[]='$ctrl->datasource = new jFormDaoDatasource(\''.$daoselector.'\',\''. 171 $daomethod.'\',\''.$daolabel.'\',\''.$daovalue.'\' ,);';162 $daomethod.'\',\''.$daolabel.'\',\''.$daovalue.'\');'; 172 163 173 164 }else{ 174 165 $source[]='$ctrl->datasource= new jFormStaticDatasource();'; 175 $source[]='$ctrl->datasource-> array(';166 $source[]='$ctrl->datasource->datas = array('; 176 167 177 168 foreach($control->item as $item){ … … 198 189 199 190 protected function generateJsControl($control){ 200 191 $source = array(); 192 193 if(isset($control['type'])){ 194 $dt = (string)$control['type']; 195 }else{ 196 $dt = 'string'; 197 } 198 199 if(isset($control->label['locale'])){ 200 $label='\'".str_replace("\'","\\\'",jLocale::get(\''.(string)$control->label['locale'].'\'))."\''; 201 }else{ 202 $label="'".str_replace("'","\\'",(string)$control->label)."'"; 203 $label=str_replace('"','\"',$label); 204 } 205 $source[]='$js.="gControl = new jFormsControl(\''.(string)$control['ref'].'\', '.$label.', \''.$dt.'\');\n";'; 206 207 208 if(isset($control['readonly'])){ 209 $readonly=(string)$control['readonly']; 210 $source[]='$js.="gControl.readonly = '.($readonly=='true'?'true':'false').';\n";'; 211 } 212 if(isset($control['required'])){ 213 $required=(string)$control['required']; 214 $source[]='$js.="gControl.required = '.($required=='true'?'true':'false').';\n";'; 215 } 216 217 /* 218 219 switch($controltype){ 220 case 'input': 221 break; 222 case 'textarea': 223 break; 224 case 'secret': 225 break; 226 case 'output': 227 //attr value 228 break; 229 case 'upload': 230 // attr mediatype 231 break; 232 case 'select1': 233 case 'select': 234 // recuperer les <items> attr label|labellocale value 235 if(isset($control['dao'])){ 236 $daoselector = (string)$control['dao']; 237 $daomethod = (string)$control['daomethod']; 238 $daolabel = (string)$control['daolabelproperty']; 239 $daovalue = (string)$control['daovalueproperty']; 240 $source[]='$ctrl->datasource = new jFormDaoDatasource(\''.$daoselector.'\',\''. 241 $daomethod.'\',\''.$daolabel.'\',\''.$daovalue.'\',);'; 242 243 }else{ 244 $source[]='$ctrl->datasource= new jFormStaticDatasource();'; 245 $source[]='$ctrl->datasource->array('; 246 247 foreach($control->item as $item){ 248 $value ="'".str_replace("'","\\'",(string)$item['value'])."'=>"; 249 if(isset($item['label'])){ 250 $source[] = $value."'".str_replace("'","\\'",(string)$item['label'])."',"; 251 }elseif(isset($item['labellocale'])){ 252 $source[] = $value."jLocale::get('".(string)$item['labellocale']."'),"; 253 }else{ 254 $source[] = $value."'".str_replace("'","\\'",(string)$item['value'])."',"; 255 } 256 } 257 $source[]=");"; 258 } 259 break; 260 case 'submit': 261 // attr value 262 break; 263 }*/ 264 $source[]='$js.="gForm.addControl( gControl);\n";'; 265 266 return implode("\n", $source); 201 267 202 268 branches/experimental/jforms/lib/jelix/tpl/plugins/html/block.form.php
r374 r437 12 12 * a block to display an html form, with datas from a jforms 13 13 * 14 * usage : {form $theformobject,'submit_action' } here form content {/form}14 * usage : {form $theformobject,'submit_action', $submit_action_params} here form content {/form} 15 15 * 16 16 * @param jTplCompiler $compiler the template compiler … … 22 22 function jtpl_block_form($compiler, $begin, $param=array()) 23 23 { 24 static $formNumber =0;25 24 26 25 if(!$begin){ 27 return ' </form>';26 return '$builder->outputFooter();'; 28 27 } 29 28 30 if(count($param) != 2){29 if(count($param) != 3){ 31 30 $compiler->doError2('errors.tplplugin.block.bad.argument.number','form',2); 32 31 return ''; 33 32 } 34 33 35 $formNumber ++; 36 37 $formName = 'jform_'.$formNumber; 38 39 40 $content = '<form action="" method="POST" name="'.$formName.'">'; 41 42 43 34 $content = ' $form = '.$param[0].'; 35 $builder = $form->getBuilder(\'html\', '.$param[1].','.$param[2].'); 36 $builder->outputHeader(); 37 '; 44 38 return $content; 45 39 } branches/experimental/jforms/testapp/modules/unittest/classes/unittestservice.class.php
r436 r437 102 102 } 103 103 104 function jformsTest(){ 105 $test = jClasses::create("utjforms"); 106 $test->run(new jHtmlRespReporter($this->_rep)); 107 } 108 104 109 } 105 110 ?> branches/experimental/jforms/testapp/modules/unittest/templates/menu.tpl
r436 r437 50 50 </ul> 51 51 52 <h3>jForms</h3> 53 <ul> 54 <li><a href="?module=unittest&action=jforms_parseControls">compilateur</a></li> 55 </ul> 56 57 52 58 <h3>Utilitaires</h3> 53 59 <ul>
