Source for file html.jformsbuilder.php

Documentation is available at html.jformsbuilder.php

  1. <?php
  2. /**
  3. @package     jelix
  4. @subpackage  forms
  5. @author      Laurent Jouanneau
  6. @contributor Julien Issler, Dominique Papin, Olivier Demah
  7. @copyright   2006-2012 Laurent Jouanneau
  8. @copyright   2008 Julien Issler, 2008 Dominique Papin
  9. @copyright   2009 Olivier Demah
  10. @link        http://www.jelix.org
  11. @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  12. */
  13.  
  14. include_once(JELIX_LIB_PATH.'forms/jFormsBuilderHtml.class.php');
  15.  
  16. /**
  17.  * HTML form builder
  18.  * @package     jelix
  19.  * @subpackage  jelix-plugins
  20.  */
  21. class htmlJformsBuilder extends jFormsBuilderHtml {
  22.  
  23.     protected $jFormsJsVarName = 'jFormsJQ';
  24.  
  25.     public function outputMetaContent($t{
  26.  
  27.         $respjApp::coord()->response;
  28.         if($resp === null || $resp->getType(!='html'){
  29.             return;
  30.         }
  31.         $confUrlEngine &jApp::config()->urlengine;
  32.         $confHtmlEditor &jApp::config()->htmleditors;
  33.         $confDate &jApp::config()->datepickers;
  34.         $confWikiEditor &jApp::config()->wikieditors;
  35.         $www $confUrlEngine['jelixWWWPath'];
  36.         $jq $confUrlEngine['jqueryPath'];
  37.         $bp $confUrlEngine['basePath'];
  38.         $resp->addJSLink($jq.'jquery.js');
  39.         $resp->addJSLink($jq.'include/jquery.include.js');
  40.         $resp->addJSLink($www.'js/jforms_jquery.js');
  41.         $resp->addCSSLink($www.'design/jform.css');
  42.         foreach($t->_vars as $k=>$v){
  43.             if(!$v instanceof jFormsBase)
  44.                 continue;
  45.             foreach($v->getHtmlEditors(as $ed{
  46.                 if(isset($confHtmlEditor[$ed->config.'.engine.file'])){
  47.                     if(is_array($confHtmlEditor[$ed->config.'.engine.file'])){
  48.                         foreach($confHtmlEditor[$ed->config.'.engine.file'as $url{
  49.                             $resp->addJSLink($bp.$url);
  50.                         }
  51.                     }else
  52.                         $resp->addJSLink($bp.$confHtmlEditor[$ed->config.'.engine.file']);
  53.                 }
  54.                 
  55.                 if(isset($confHtmlEditor[$ed->config.'.config']))
  56.                     $resp->addJSLink($bp.$confHtmlEditor[$ed->config.'.config']);
  57.  
  58.                 $skin $ed->config.'.skin.'.$ed->skin;
  59.  
  60.                 if(isset($confHtmlEditor[$skin]&& $confHtmlEditor[$skin!= '')
  61.                     $resp->addCSSLink($bp.$confHtmlEditor[$skin]);
  62.             }
  63.  
  64.             $datepicker_default_config jApp::config()->forms['datepicker'];
  65.             
  66.             foreach($v->getControls(as $ctrl){
  67.                 if($ctrl instanceof jFormsControlDate || get_class($ctrl->datatype== 'jDatatypeDate' || get_class($ctrl->datatype== 'jDatatypeLocaleDate'){
  68.                     $config = isset($ctrl->datepickerConfig)?$ctrl->datepickerConfig:$datepicker_default_config;
  69.                     $resp->addJSLink($bp.$confDate[$config]);
  70.                 }
  71.             }
  72.  
  73.             foreach($v->getWikiEditors(as $ed{
  74.                 if(isset($confWikiEditor[$ed->config.'.engine.file']))
  75.                     $resp->addJSLink($bp.$confWikiEditor[$ed->config.'.engine.file']);
  76.                 if(isset($confWikiEditor[$ed->config.'.config.path'])) {
  77.                     $p $bp.$confWikiEditor[$ed->config.'.config.path'];
  78.                     $resp->addJSLink($p.jApp::config()->locale.'.js');
  79.                     $resp->addCSSLink($p.'style.css');
  80.                 }
  81.                 if(isset($confWikiEditor[$ed->config.'.skin']))
  82.                     $resp->addCSSLink($bp.$confWikiEditor[$ed->config.'.skin']);
  83.             }
  84.         }
  85.     }
  86.  
  87.     protected function outputHeaderScript(){
  88.         $conf jApp::config()->urlengine;
  89.         // no scope into an anonymous js function, because jFormsJQ.tForm is used by other generated source code
  90.         echo '<script type="text/javascript">
  91. //<![CDATA[
  92. jFormsJQ.selectFillUrl=\''.jUrl::get('jelix~jforms:getListData').'\';
  93. jFormsJQ.config = {locale:'.$this->escJsStr(jApp::config()->locale).
  94.     ',basePath:'.$this->escJsStr($conf['basePath']).
  95.     ',jqueryPath:'.$this->escJsStr($conf['jqueryPath']).
  96.     ',jelixWWWPath:'.$this->escJsStr($conf['jelixWWWPath']).'};
  97. jFormsJQ.tForm = new jFormsJQForm(\''.$this->_name.'\',\''.$this->_form->getSelector().'\',\''.$this->_form->getContainer()->formId.'\');
  98. jFormsJQ.tForm.setErrorDecorator(new '.$this->options['errorDecorator'].'());
  99. jFormsJQ.declareForm(jFormsJQ.tForm);
  100. //]]>
  101. </script>';
  102.     }
  103.  
  104.     protected function commonJs($ctrl{
  105.         if ($ctrl->isReadOnly()) {
  106.             $this->jsContent .="c.readOnly = true;\n";
  107.         }
  108.  
  109.         if($ctrl->required){
  110.             $this->jsContent .="c.required = true;\n";
  111.             if($ctrl->alertRequired){
  112.                 $this->jsContent .="c.errRequired=".$this->escJsStr($ctrl->alertRequired).";\n";
  113.             }
  114.             else {
  115.                 $this->jsContent .="c.errRequired=".$this->escJsStr(jLocale::get('jelix~formserr.js.err.required'$ctrl->label)).";\n";
  116.             }
  117.         }
  118.  
  119.         if($ctrl->alertInvalid){
  120.             $this->jsContent .="c.errInvalid=".$this->escJsStr($ctrl->alertInvalid).";\n";
  121.         }
  122.         else {
  123.             $this->jsContent .="c.errInvalid=".$this->escJsStr(jLocale::get('jelix~formserr.js.err.invalid'$ctrl->label)).";\n";
  124.         }
  125.  
  126.         if($ctrl instanceof jFormsControlDate || get_class($ctrl->datatype== 'jDatatypeDate' || get_class($ctrl->datatype== 'jDatatypeLocaleDate'){
  127.             $config = isset($ctrl->datepickerConfig)?$ctrl->datepickerConfig:jApp::config()->forms['datepicker'];
  128.             $this->jsContent .= 'jelix_datepicker_'.$config."(c, jFormsJQ.config);\n";
  129.         }
  130.  
  131.         if ($this->isRootControl$this->jsContent .="jFormsJQ.tForm.addControl(c);\n";
  132.     }
  133.  
  134.     protected function jsMenulist($ctrl{
  135.  
  136.         $this->jsContent .="c = new jFormsJQControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  137.         if ($ctrl instanceof jFormsControlDatasource
  138.             && $ctrl->datasource instanceof jFormsDaoDatasource{
  139.             $dependentControls $ctrl->datasource->getDependentControls();
  140.             if ($dependentControls{
  141.                 $this->jsContent .="c.dependencies = ['".implode("','",$dependentControls)."'];\n";
  142.                 $this->lastJsContent .= "jFormsJQ.tForm.declareDynamicFill('".$ctrl->ref."');\n";
  143.             }
  144.         }
  145.  
  146.         $this->commonJs($ctrl);
  147.     }
  148.  
  149.     protected function jsWikieditor($ctrl{
  150.         $this->jsTextarea($ctrl);
  151.         $engine jApp::config()->wikieditors[$ctrl->config.'.engine.name'];
  152.         $this->jsContent .= '$("#'.$this->_name.'_'.$ctrl->ref.'").markItUp(markitup_'.$engine.'_settings);'."\n";
  153.     }
  154.  
  155. }

Documentation generated on Mon, 26 Oct 2015 21:51:24 +0100 by phpDocumentor 1.4.3