/**
  * Render the templates
  *
  * @param \Nette\Forms\Form $form
  * @param string $mode
  *
  * @return void
  */
 public function render(Nette\Forms\Form $form, $mode = NULL)
 {
     if ($this->form !== $form) {
         $this->form = $form;
         // translators
         if ($translator = $this->form->getTranslator()) {
             $this->template->setTranslator($translator);
         }
         // controls placeholders & classes
         foreach ($this->form->getControls() as $control) {
             $this->prepareControl($control);
         }
         $formEl = $form->getElementPrototype();
         if (!$formEl->class || stripos('form-', (string) $formEl->class) === FALSE) {
             $formEl->addClass('form-horizontal');
         }
     }
     $this->template->form = $this->form;
     $this->template->_form = $this->form;
     $this->template->renderer = $this;
     if ($mode === NULL) {
         $this->template->render();
     } elseif ($mode === 'begin') {
         FormMacros::renderFormBegin($this->form, array());
     } elseif ($mode === 'end') {
         FormMacros::renderFormEnd($this->form);
     } else {
         $this->template->setFile(__DIR__ . '/@parts.latte');
         $this->template->mode = $mode;
         $this->template->render();
         $this->template->setFile(__DIR__ . '/@form.latte');
     }
 }
 /**
  * Render the templates.
  * @param Form    $form
  * @param string  $mode
  * @param array   $args
  */
 public function render(Form $form, $mode = NULL, $args = NULL)
 {
     if ($this->template === NULL) {
         if ($presenter = $form->lookup('Nette\\Application\\UI\\Presenter', FALSE)) {
             /** @var \Nette\Application\UI\Presenter $presenter */
             $this->template = clone $presenter->getTemplate();
         } else {
             $this->template = new FileTemplate();
             $this->template->registerFilter(new \Nette\Latte\Engine());
         }
     }
     if ($this->form !== $form) {
         $this->form = $form;
         // translators
         if ($translator = $this->form->getTranslator()) {
             $this->template->setTranslator($translator);
         }
         // controls placeholders & classes
         foreach ($this->form->getControls() as $control) {
             $this->prepareControl($control);
         }
         $formEl = $form->getElementPrototype();
         if (!($classes = self::getClasses($formEl)) || stripos($classes, 'form-') === FALSE) {
             //$formEl->addClass('form-horizontal');
         }
     } elseif ($mode === 'begin') {
         foreach ($this->form->getControls() as $control) {
             /** @var \Nette\Forms\Controls\BaseControl $control */
             $control->setOption('rendered', FALSE);
         }
     }
     $this->template->setFile(__DIR__ . '/@form.latte');
     $this->template->setParameters(array_fill_keys(array('control', '_control', 'presenter', '_presenter'), NULL) + array('_form' => $this->form, 'form' => $this->form, 'renderer' => $this));
     if ($mode === NULL) {
         if ($args) {
             $this->form->getElementPrototype()->addAttributes($args);
         }
         $this->template->render();
     } elseif ($mode === 'begin') {
         FormMacros::renderFormBegin($this->form, (array) $args);
     } elseif ($mode === 'end') {
         FormMacros::renderFormEnd($this->form);
     } else {
         $attrs = array('input' => array(), 'label' => array());
         foreach ((array) $args as $key => $val) {
             if (stripos($key, 'input-') === 0) {
                 $attrs['input'][substr($key, 6)] = $val;
             } elseif (stripos($key, 'label-') === 0) {
                 $attrs['label'][substr($key, 6)] = $val;
             }
         }
         $this->template->setFile(__DIR__ . '/@parts.latte');
         $this->template->mode = $mode;
         $this->template->attrs = (array) $attrs;
         $this->template->render();
     }
 }
 /**
  * Render the templates
  *
  * @param \Nette\Forms\Form $form
  *
  * @return void
  */
 public function render(Nette\Forms\Form $form)
 {
     if ($this->form !== $form) {
         $this->form = $form;
         // translators
         if ($translator = $this->form->getTranslator()) {
             $this->template->setTranslator($translator);
         }
         // controls placeholders & classes
         foreach ($this->form->getControls() as $control) {
             $this->prepareControl($control);
         }
         $formEl = $form->getElementPrototype();
         if (stripos('form-', $formEl->class) === FALSE) {
             $formEl->addClass('form-horizontal');
         }
     }
     $this->template->form = $this->form;
     $this->template->renderer = $this;
     $this->template->render();
 }
 /**
  * Render the templates
  *
  * @param \Nette\Forms\Form $form
  * @param string $mode
  * @param array $args
  * @return void
  */
 public function render(Nette\Forms\Form $form, $mode = NULL, $args = NULL)
 {
     if ($this->template === NULL) {
         if ($presenter = $form->lookup('Nette\\Application\\UI\\Presenter', FALSE)) {
             /** @var \Nette\Application\UI\Presenter $presenter */
             $this->template = clone $presenter->getTemplate();
         } else {
             $this->template = new Nette\Bridges\ApplicationLatte\Template(new Nette\Latte\Engine());
         }
     }
     if ($this->form !== $form) {
         $this->form = $form;
         // translators
         if ($translator = $this->form->getTranslator()) {
             $this->template->setTranslator($translator);
         }
         // controls placeholders & classes
         foreach ($this->form->getControls() as $control) {
             $this->prepareControl($control);
         }
         $formEl = $form->getElementPrototype();
         if (!($classes = self::getClasses($formEl)) || stripos($classes, 'form-') === FALSE) {
             $this->horizontalMode = $this->mode === self::MODE_HORIZONTAL;
             if ($this->mode !== self::MODE_NO_CLASS) {
                 $formEl->addClass($this->mode);
             }
         }
     } elseif ($mode === 'begin') {
         foreach ($this->form->getControls() as $control) {
             /** @var \Nette\Forms\Controls\BaseControl $control */
             $control->setOption('rendered', FALSE);
         }
     }
     $this->template->setFile(__DIR__ . '/@form.latte');
     $this->template->setParameters(array_fill_keys(array('control', '_control', 'presenter', '_presenter'), NULL) + array('_form' => $this->form, 'form' => $this->form, 'renderer' => $this));
     if ($this->horizontalMode) {
         $this->template->labelCols = $this->labelColumns;
         $this->template->inputCols = $this->inputColumns;
         $this->template->labelClass = $this->columnClassPrefix . $this->labelColumns;
         $this->template->inputClass = $this->columnClassPrefix . $this->inputColumns;
         $this->template->skipClass = $this->columnClassPrefix . 'offset-' . $this->labelColumns;
     }
     if ($mode === NULL) {
         if ($args) {
             $this->form->getElementPrototype()->addAttributes($args);
         }
         $this->template->render();
     } elseif ($mode === 'begin') {
         FormMacros::renderFormBegin($this->form, (array) $args);
     } elseif ($mode === 'end') {
         FormMacros::renderFormEnd($this->form);
     } else {
         $attrs = array('input' => array(), 'label' => array(), 'pair' => array(), 'pair-class' => '');
         foreach ((array) $args as $key => $val) {
             if (stripos($key, 'input-') === 0) {
                 $attrs['input'][substr($key, 6)] = $val;
             } elseif (stripos($key, 'label-') === 0) {
                 $attrs['label'][substr($key, 6)] = $val;
             } elseif ($key === 'class') {
                 $attrs['pair-class'] = $val;
             } else {
                 $attrs['pair'][$key] = $val;
             }
         }
         if ($this->horizontalMode) {
             if (isset($attrs['label']['class'])) {
                 $attrs['label']['class'] .= ' ' . $this->columnClassPrefix . $this->labelColumns;
             } else {
                 $attrs['label']['class'] = $this->columnClassPrefix . $this->labelColumns;
             }
         }
         $this->template->setFile(__DIR__ . '/@parts.latte');
         $this->template->mode = $mode;
         $this->template->attrs = (array) $attrs;
         $this->template->render();
     }
 }
Example #5
0
 /**
  * draws the form element
  * @param array data
  * @param int repeat group counter
  * @return string returns element html
  */
 function render($data, $repeatCounter = 0)
 {
     $this->_repeatGroupCounter = $repeatCounter;
     $id = $this->getHTMLId($repeatCounter);
     $name = $this->getHTMLName($repeatCounter);
     $groupModel =& $this->getGroup();
     $element = $this->getElement();
     $params = $this->getParams();
     if ($element->hidden == '1') {
         return $this->getHiddenField($name, $data[$name], $id);
     }
     $str = '';
     $value = $this->getValue($data, $repeatCounter);
     $value = is_array($value) ? $value : FabrikWorker::JSONtoData($value, true);
     $ulDir = $params->get('ul_directory');
     $storage =& $this->getStorage();
     $formModel = $this->getFormModel();
     $formid = $formModel->get('id');
     $use_download_script = $params->get('fu_use_download_script', '0');
     if (!$this->_editable && ($use_download_script == FU_DOWNLOAD_SCRIPT_DETAIL || $use_download_script == FU_DOWNLOAD_SCRIPT_BOTH)) {
         return $this->downloadLink();
     }
     // $$$ rob - explode as it may be grouped data (if element is a repeating upload)
     $values = is_array($value) ? $value : FabrikWorker::JSONtoData($value, true);
     $render = new stdClass();
     $render->output = '';
     if ($params->get('fu_show_image') != '0' && !$params->get('ajax_upload') || !$this->_editable) {
         foreach ($values as $value) {
             $render =& $this->loadElement($value);
             if ($value != '' && ($storage->exists(COM_FABRIK_BASE . $value) || substr($value, 0, 4) == 'http')) {
                 $render->render($this, $params, $value);
             }
             if ($render->output != '') {
                 $str .= $render->output;
             }
         }
     }
     if (!$this->_editable) {
         if ($render->output == '' && $params->get('default_image') != '') {
             $render->output = "<img src=\"{$params->get('default_image')}\" alt=\"image\" />";
         }
     }
     if (!$this->_editable) {
         $str = "<div class=\"fabrikSubElementContainer\">{$str}";
         $str .= "</div>";
         return $str;
     } else {
         // $$$ rob dont wrap readonly in subElementContainer as it stops dataConsideredEmpty() working when testing ro values
     }
     $str .= '<input class="fabrikinput" name="' . $name . '" type="file" id="' . $id . '" />' . "\n";
     if ($params->get('upload_allow_folderselect') == '1') {
         $rDir = JPATH_SITE . DS . $params->get('ul_directory');
         $folders = JFolder::folders($rDir);
         $str .= FabrikHelperHTML::folderAjaxSelect($folders);
         if ($groupModel->canRepeat()) {
             $ulname = FabrikString::rtrimword($name, "[{$repeatCounter}]") . "[ul_end_dir][{$repeatCounter}]";
         } else {
             $ulname = $name . '[ul_end_dir]';
         }
         $str .= "<input name=\"{$ulname}\" type=\"hidden\" class=\"folderpath\"/>";
     }
     if ($params->get('ajax_upload')) {
         $str = $render->output . $this->plupload($str, $repeatCounter, $values);
     }
     $str = "<div class=\"fabrikSubElementContainer\">{$str}";
     $str .= "</div>";
     return $str;
 }