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-2010 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.         global $gJCoord$gJConfig;
  27.         $resp$gJCoord->response;
  28.         if($resp === null || $resp->getType(!='html'){
  29.             return;
  30.         }
  31.         $www $gJConfig->urlengine['jelixWWWPath'];
  32.         $jq $gJConfig->urlengine['jqueryPath'];
  33.         $bp $gJConfig->urlengine['basePath'];
  34.         $resp->addJSLink($jq.'jquery.js');
  35.         $resp->addJSLink($jq.'include/jquery.include.js');
  36.         $resp->addJSLink($www.'js/jforms_jquery.js');
  37.         $resp->addCSSLink($www.'design/jform.css');
  38.         foreach($t->_vars as $k=>$v){
  39.             if(!$v instanceof jFormsBase)
  40.                 continue;
  41.             foreach($v->getHtmlEditors(as $ed{
  42.                 if(isset($gJConfig->htmleditors[$ed->config.'.engine.file'])){
  43.                     if(is_array($gJConfig->htmleditors[$ed->config.'.engine.file'])){
  44.                         foreach($gJConfig->htmleditors[$ed->config.'.engine.file'as $url{
  45.                             $resp->addJSLink($bp.$url);
  46.                         }
  47.                     }else
  48.                         $resp->addJSLink($bp.$gJConfig->htmleditors[$ed->config.'.engine.file']);
  49.                 }
  50.                 if(isset($gJConfig->htmleditors[$ed->config.'.config']))
  51.                     $resp->addJSLink($bp.$gJConfig->htmleditors[$ed->config.'.config']);
  52.                 $skin $ed->config.'.skin.'.$ed->skin;
  53.                 if(isset($gJConfig->htmleditors[$skin]&& $gJConfig->htmleditors[$skin!= '')
  54.                     $resp->addCSSLink($bp.$gJConfig->htmleditors[$skin]);
  55.             }
  56.             $datepicker_default_config $gJConfig->forms['datepicker'];
  57.             foreach($v->getControls(as $ctrl){
  58.                 if($ctrl instanceof jFormsControlDate || get_class($ctrl->datatype== 'jDatatypeDate' || get_class($ctrl->datatype== 'jDatatypeLocaleDate'){
  59.                     $config = isset($ctrl->datepickerConfig)?$ctrl->datepickerConfig:$datepicker_default_config;
  60.                     $resp->addJSLink($bp.$gJConfig->datepickers[$config]);
  61.                 }
  62.             }
  63.  
  64.             foreach($v->getWikiEditors(as $ed{
  65.                 if(isset($gJConfig->wikieditors[$ed->config.'.engine.file']))
  66.                     $resp->addJSLink($bp.$gJConfig->wikieditors[$ed->config.'.engine.file']);
  67.                 if(isset($gJConfig->wikieditors[$ed->config.'.config.path'])) {
  68.                     $p $bp.$gJConfig->wikieditors[$ed->config.'.config.path'];
  69.                     $resp->addJSLink($p.$GLOBALS['gJConfig']->locale.'.js');
  70.                     $resp->addCSSLink($p.'style.css');
  71.                 }
  72.                 if(isset($gJConfig->wikieditors[$ed->config.'.skin']))
  73.                     $resp->addCSSLink($bp.$gJConfig->wikieditors[$ed->config.'.skin']);
  74.             }
  75.         }
  76.     }
  77.  
  78.     protected function outputHeaderScript(){
  79.         global $gJConfig;
  80.         // no scope into an anonymous js function, because jFormsJQ.tForm is used by other generated source code
  81.         echo '<script type="text/javascript">
  82. //<![CDATA[
  83. jFormsJQ.selectFillUrl=\''.jUrl::get('jelix~jforms:getListData').'\';
  84. jFormsJQ.config = {locale:'.$this->escJsStr($gJConfig->locale).
  85.     ',basePath:'.$this->escJsStr($gJConfig->urlengine['basePath']).
  86.     ',jqueryPath:'.$this->escJsStr($gJConfig->urlengine['jqueryPath']).
  87.     ',jelixWWWPath:'.$this->escJsStr($gJConfig->urlengine['jelixWWWPath']).'};
  88. jFormsJQ.tForm = new jFormsJQForm(\''.$this->_name.'\',\''.$this->_form->getSelector().'\',\''.$this->_form->getContainer()->formId.'\');
  89. jFormsJQ.tForm.setErrorDecorator(new '.$this->options['errorDecorator'].'());
  90. jFormsJQ.declareForm(jFormsJQ.tForm);
  91. //]]>
  92. </script>';
  93.     }
  94.  
  95.     protected function commonJs($ctrl{
  96.         if ($ctrl->isReadOnly()) {
  97.             $this->jsContent .="c.readOnly = true;\n";
  98.         }
  99.  
  100.         if($ctrl->required){
  101.             $this->jsContent .="c.required = true;\n";
  102.             if($ctrl->alertRequired){
  103.                 $this->jsContent .="c.errRequired=".$this->escJsStr($ctrl->alertRequired).";\n";
  104.             }
  105.             else {
  106.                 $this->jsContent .="c.errRequired=".$this->escJsStr(jLocale::get('jelix~formserr.js.err.required'$ctrl->label)).";\n";
  107.             }
  108.         }
  109.  
  110.         if($ctrl->alertInvalid){
  111.             $this->jsContent .="c.errInvalid=".$this->escJsStr($ctrl->alertInvalid).";\n";
  112.         }
  113.         else {
  114.             $this->jsContent .="c.errInvalid=".$this->escJsStr(jLocale::get('jelix~formserr.js.err.invalid'$ctrl->label)).";\n";
  115.         }
  116.  
  117.         if($ctrl instanceof jFormsControlDate || get_class($ctrl->datatype== 'jDatatypeDate' || get_class($ctrl->datatype== 'jDatatypeLocaleDate'){
  118.             $config = isset($ctrl->datepickerConfig)?$ctrl->datepickerConfig:$GLOBALS['gJConfig']->forms['datepicker'];
  119.             $this->jsContent .= 'jelix_datepicker_'.$config."(c, jFormsJQ.config);\n";
  120.         }
  121.  
  122.         if ($this->isRootControl$this->jsContent .="jFormsJQ.tForm.addControl(c);\n";
  123.     }
  124.  
  125.     protected function jsMenulist($ctrl{
  126.  
  127.         $this->jsContent .="c = new jFormsJQControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n";
  128.         if ($ctrl instanceof jFormsControlDatasource
  129.             && $ctrl->datasource instanceof jFormsDaoDatasource{
  130.             $dependentControls $ctrl->datasource->getDependentControls();
  131.             if ($dependentControls{
  132.                 $this->jsContent .="c.dependencies = ['".implode("','",$dependentControls)."'];\n";
  133.                 $this->lastJsContent .= "jFormsJQ.tForm.declareDynamicFill('".$ctrl->ref."');\n";
  134.             }
  135.         }
  136.  
  137.         $this->commonJs($ctrl);
  138.     }
  139.  
  140.     protected function jsWikieditor($ctrl{
  141.         $this->jsTextarea($ctrl);
  142.         $engine $GLOBALS['gJConfig']->wikieditors[$ctrl->config.'.engine.name'];
  143.         $this->jsContent .= '$("#'.$this->_name.'_'.$ctrl->ref.'").markItUp(markitup_'.$engine.'_settings);'."\n";
  144.     }
  145.  
  146. }

Documentation generated on Wed, 24 Sep 2014 21:55:39 +0200 by phpDocumentor 1.4.3