getControl() public method

Generates control's HTML element.
public getControl ( ) : Nette\Utils\Html | string
return Nette\Utils\Html | string
Esempio n. 1
0
 public function getControl()
 {
     $container = Html::el();
     $container->add($this->wrappedControl->getControl());
     $container->add($this->applyButton->getControl($this->caption));
     return $container;
 }
 /**
  * Generates control's HTML element.
  *
  * @return string
  */
 public function getControl()
 {
     $items = $this->getItems();
     reset($items);
     $input = BaseControl::getControl();
     return Helpers::createInputList($this->translate ? $this->translate($items) : $items, array_merge($input->attrs, ['id' => NULL, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'required' => NULL, 'data-nette-rules:' => [key($items) => $input->attrs['data-nette-rules']]]), $this->label->attrs, $this->separator);
 }
Esempio n. 3
0
 /**
  * Generates control's HTML element.
  *
  * @return Html
  */
 public function getControl()
 {
     $parentControl = parent::getControl();
     $control = $this->getWrapperPrototype();
     $control->setId($parentControl->getId());
     $control->setHtml($this->getContent());
     return $control;
 }
 /**
  * Just remove translations from each option
  * @return Nette\Forms\Helpers
  */
 public function getControl()
 {
     $items = $this->prompt === FALSE ? array() : array('' => $this->translate($this->prompt));
     foreach ($this->options as $key => $value) {
         $items[is_array($value) ? $key : $key] = $value;
     }
     return Nette\Forms\Helpers::createSelectBox($items, array('selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL))->addAttributes(BaseControl::getControl()->attrs);
 }
Esempio n. 5
0
 /**
  * Generates control's HTML element.
  *
  * @return Html
  */
 public function getControl()
 {
     $parentControl = parent::getControl();
     $control = $this->getWrapperPrototype();
     $control->addAttributes(['id' => $parentControl->id]);
     $control->setHtml($this->getContent());
     return $control;
 }
Esempio n. 6
0
 /**
  * Generates control's HTML element.
  *
  * @return Html
  */
 public function getControl()
 {
     $items = $this->getPrompt() === FALSE ? [] : ['' => $this->translate($this->getPrompt())];
     foreach ($this->options as $key => $value) {
         $items[$this->translate && is_array($value) ? $this->translate($key) : $key] = $this->translate ? $this->translate($value) : $value;
     }
     return Helpers::createSelectBox($items, ['selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL])->addAttributes(BaseControl::getControl()->attrs);
 }
Esempio n. 7
0
 public function getTextboxControl($name)
 {
     $control = clone parent::getControl();
     $control->type = "text";
     $control->id = $name;
     $control->name .= "[{$name}]";
     $control->value = $this->value[$name];
     return $control;
 }
Esempio n. 8
0
 /**
  * Generates control's HTML element.
  *
  * @return Html
  */
 public function getControl()
 {
     $container = clone $this->container;
     parent::getControl();
     $control = Html::el("div", array("style" => "text-align:justify"));
     $control->setHtml($this->translate((string) $this->getValue()));
     $container->add($control);
     return $container;
 }
Esempio n. 9
0
 /**
  * Generates control's HTML element
  *
  * @return Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->addClass('checkbox3s');
     $val = $this->getValue();
     $control->data('lohini-state', $val ?: 0);
     if ($val == 1) {
         $control->checked = 'checked';
     }
     return Html::el('span')->add($control)->addClass('cb3s');
 }
Esempio n. 10
0
 public function getControl()
 {
     $el = parent::getControl();
     if ($this->emptyValue !== '') {
         $el->attrs['data-nette-empty-value'] = Strings::trim($this->translate($this->emptyValue));
     }
     if (isset($el->placeholder)) {
         $el->placeholder = $this->translate($el->placeholder);
     }
     return $el;
 }
Esempio n. 11
0
 /**
  * Generates control's HTML element.
  *
  * @return Html
  */
 public function getControl()
 {
     $input = BaseControl::getControl();
     $items = $this->getItems();
     $ids = [];
     if ($this->generateId) {
         foreach ($items as $value => $label) {
             $ids[$value] = $input->id . '-' . $value;
         }
     }
     return $this->container->setHtml(Helpers::createInputList($this->translate ? $this->translate($items) : $items, array_merge($input->attrs, ['id:' => $ids, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'data-nette-rules:' => [key($items) => $input->attrs['data-nette-rules']]]), ['for:' => $ids] + $this->itemLabel->attrs, $this->separator));
 }
Esempio n. 12
0
 /**
  * Generates control's HTML element.
  *
  * @author   Jan Tvrdík
  * @return   Nette\Web\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->addClass($this->className);
     //		list($min, $max) = $this->extractRangeRule($this->getRules());
     //		if ($min !== NULL) $control->min = $min->format(self::W3C_DATE_FORMAT);
     //		if ($max !== NULL) $control->max = $max->format(self::W3C_DATE_FORMAT);
     if ($this->value) {
         $control->value = $this->value->format(self::W3C_DATE_FORMAT);
     }
     return $control;
 }
Esempio n. 13
0
 public function getControl()
 {
     $control = parent::getControl();
     foreach ($this->getRules() as $rule) {
         if ($rule->type === Nette\Forms\Rule::VALIDATOR && !$rule->isNegative && ($rule->operation === Form::LENGTH || $rule->operation === Form::MAX_LENGTH)) {
             $control->maxlength = is_array($rule->arg) ? $rule->arg[1] : $rule->arg;
         }
     }
     if ($this->emptyValue !== '') {
         $control->data('nette-empty-value', $this->translate($this->emptyValue));
     }
     return $control;
 }
Esempio n. 14
0
 /**
  * Generates control's HTML element.
  */
 public function getControl()
 {
     parent::getControl();
     $days = array('' => 'Den') + array_combine(range(1, 31), range(1, 31));
     $yearsRange = range(date('Y'), date('Y') - 110);
     $years = array('' => 'Rok') + array_combine($yearsRange, $yearsRange);
     $monthsCzech = \JiriNapravnik\Common\DateCzech::getCzechMonthsNominativNumericKeys();
     $months = array('' => 'Měsíc');
     for ($i = 1; $i <= 12; $i++) {
         $months[$i] = $monthsCzech[$i];
     }
     $name = $this->getHtmlName();
     return Html::el()->add(Helpers::createSelectBox($days, array('selected?' => $this->day))->name($name . '[day]')->class('form-control day'))->add(Helpers::createSelectBox($months, array('selected?' => $this->month))->name($name . '[month]')->class('form-control month'))->add(Helpers::createSelectBox($years, array('selected?' => $this->year))->name($name . '[year]')->class('form-control year'));
 }
Esempio n. 15
0
 public function getControl()
 {
     $this->setOption('rendered', TRUE);
     $value = $this->value;
     foreach ($this->filters as $filter) {
         $value = $filter($value);
     }
     $p = parent::getControl()->id($this->getHtmlId())->addClass('form-control-static');
     if ($value instanceof Html) {
         return $p->setHtml($value->addClass('control-label'));
     } else {
         return $p->setText(Html::el('span')->addClass('control-label')->setText((string) $value));
     }
 }
Esempio n. 16
0
 /**
  * Generates control's HTML element.
  *
  * @author   Jan Tvrdík
  * @return   Nette\Utils\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     $control->addClass($this->className);
     list($min, $max) = $this->extractRangeRule($this->getRules());
     if ($min !== NULL) {
         $control->data['min'] = $min->format($this->format);
     }
     if ($max !== NULL) {
         $control->data['max'] = $max->format($this->format);
     }
     if ($this->value) {
         $control->value = $this->value->format($this->format);
     }
     return $control;
 }
Esempio n. 17
0
 /**
  * Generates control's HTML element.
  * @param  string
  * @return Nette\Utils\Html
  */
 public function getControl($caption = NULL)
 {
     $control = parent::getControl();
     $control->value = $this->translate($caption === NULL ? $this->caption : $caption);
     return $control;
 }
Esempio n. 18
0
 /**
  * @return Nette\Utils\Html
  */
 public function getControlPart()
 {
     return parent::getControl()->checked($this->value);
 }
Esempio n. 19
0
 /**
  * @return Html
  */
 public function getControl()
 {
     $selected = $this->getValue();
     $selected = $selected === NULL ? NULL : [$selected->id => TRUE];
     $control = parent::getControl();
     $option = Html::el('option');
     if ($this->prompt !== NULL) {
         $control->add((string) $option->value('')->setText($this->prompt));
     }
     foreach ($this->items as $key => $value) {
         $option->value($key)->setText($value->{$this->column})->selected(isset($selected[$key]));
         $control->add((string) $option);
     }
     return $control;
 }
Esempio n. 20
0
 protected function createInputPrototype()
 {
     return parent::getControl();
 }
Esempio n. 21
0
 /**
  * Generates control's HTML element.
  * @return Nette\Utils\Html
  */
 public function getControl()
 {
     $control = parent::getControl();
     if ($this->skipFirst) {
         reset($this->items);
         $control->data('nette-empty-value', $this->useKeys ? key($this->items) : current($this->items));
     }
     $selected = $this->getValue();
     $selected = is_array($selected) ? array_flip($selected) : array($selected => TRUE);
     $option = Nette\Utils\Html::el('option');
     foreach ($this->items as $key => $value) {
         if (!is_array($value)) {
             $value = array($key => $value);
             $dest = $control;
         } else {
             $dest = $control->create('optgroup')->label($key);
         }
         foreach ($value as $key2 => $value2) {
             if ($value2 instanceof Nette\Utils\Html) {
                 $dest->add((string) $value2->selected(isset($selected[$key2])));
             } else {
                 $key2 = $this->useKeys ? $key2 : $value2;
                 $value2 = $this->translate((string) $value2);
                 $dest->add((string) $option->value($key2 === $value2 ? NULL : $key2)->selected(isset($selected[$key2]))->setText($value2));
             }
         }
     }
     return $control;
 }
Esempio n. 22
0
 /**
  * Generates control's HTML element.
  *
  * @return Nette\Utils\Html
  */
 public function getControl()
 {
     if (!$this->itemsLoaded) {
         $this->loadEntities();
         $this->itemsLoaded = TRUE;
     }
     $control = parent::getControl();
     $option = Nette\Utils\Html::el('option');
     if ($this->prompt !== NULL) {
         $control->add($this->prompt instanceof Nette\Utils\Html ? $this->prompt->value('') : (string) $option->value('')->setText($this->translate((string) $this->prompt)));
     }
     $selected = (array) $this->getRawValue();
     foreach ($this->items as $key => $value) {
         if (!is_array($value)) {
             if ($value instanceof \DoctrineModule\Entities\IEntity) {
                 $value = array($value->id => $value);
             } else {
                 $value = array($value => $value);
             }
             $dest = $control;
         } else {
             $dest = $control->create('optgroup')->label($this->translate($key));
         }
         foreach ($value as $value2) {
             if ($value2 instanceof \DoctrineModule\Entities\IEntity) {
                 $key2 = $value2->id;
             } else {
                 $key2 = $value2;
             }
             if ($value2 instanceof Nette\Utils\Html) {
                 $dest->add((string) $value2->selected(isset($selected[$key2])));
             } else {
                 if ($value2 instanceof IOptionEntity) {
                     $value2 = $value2->__toOptionString();
                 }
                 $value2 = (string) $this->translate($value2);
                 $dest->add((string) $option->value($key2 === $value2 ? "" : $key2)->selected(in_array($key2, $selected))->setHtml($value2));
             }
         }
     }
     return $control;
 }
Esempio n. 23
0
 /**
  * @return Html
  */
 public function getControl()
 {
     $img = parent::getControl();
     $img->addAttributes(['src' => $this->getImage()]);
     return $img;
 }
Esempio n. 24
0
 /**
  * Generates control's HTML element.
  * @param  mixed
  * @return Nette\Utils\Html
  */
 public function getControl($key = NULL)
 {
     if ($key === NULL) {
         $container = clone $this->container;
         $separator = (string) $this->separator;
     } elseif (!isset($this->items[$key])) {
         return NULL;
     }
     $control = parent::getControl();
     $id = $control->id;
     $counter = -1;
     $value = $this->value === NULL ? NULL : (string) $this->getValue();
     $label = Html::el('label');
     foreach ($this->items as $k => $val) {
         $counter++;
         if ($key !== NULL && (string) $key !== (string) $k) {
             continue;
         }
         $control->id = $label->for = $id . '-' . $counter;
         $control->checked = (string) $k === $value;
         $control->value = $k;
         if ($val instanceof Html) {
             $label->setHtml($val);
         } else {
             $label->setText($this->translate((string) $val));
         }
         if ($key !== NULL) {
             return Html::el()->add($control)->add($label);
         }
         $container->add((string) $control . (string) $label . $separator);
         $control->data('nette-rules', NULL);
     }
     return $container;
 }
Esempio n. 25
0
 /**
  * Generates control's HTML element.
  *
  * @param mixed $key  Specify a key if you want to render just a single checkbox
  * @return \Nette\Utils\Html
  */
 public function getControl($key = NULL)
 {
     if ($key === NULL) {
         $container = clone $this->container;
         $separator = (string) $this->separator;
     } elseif (!isset($this->items[$key])) {
         return NULL;
     }
     $control = parent::getControl();
     $control->name .= '[]';
     $id = $control->id;
     $counter = -1;
     $values = $this->value === NULL ? NULL : (array) $this->getValue();
     $label = Html::el('label');
     foreach ($this->items as $k => $val) {
         $counter++;
         if ($key !== NULL && $key != $k) {
             continue;
         }
         // intentionally ==
         $control->id = $label->for = $id . '-' . $counter;
         $control->checked = count($values) > 0 ? in_array($k, $values) : false;
         $control->value = $k;
         if ($val instanceof Html) {
             $label->setHtml($val);
         } else {
             $label->setText($this->translate($val));
         }
         if ($key !== NULL) {
             return Html::el()->add($control)->add($label);
         }
         $container->add('<span>' . (string) $control . (string) $label . $separator . '</span>');
     }
     return $container;
 }
Esempio n. 26
0
 public function getControl()
 {
     $control = parent::getControl();
     $format = self::$formats[$this->type];
     if ($this->value !== null) {
         $control->value = $this->value->format($format);
     }
     if ($this->submitedValue !== null && is_string($this->submitedValue)) {
         $control->value = $this->submitedValue;
     }
     if ($this->range['min'] !== null) {
         $control->min = $this->range['min']->format($format);
     }
     if ($this->range['max'] !== null) {
         $control->max = $this->range['max']->format($format);
     }
     return $control;
 }
 /**
  * pseudo HAML:
  * div.inline-file-choice
  *  hidden#files
  *  div.file | div.image
  *      img.src="image|icon"
  *      a href="image|file" "file name"
  *      input type=hidden name=`getHtmlName`-id[] value=UID
  *          OR
  *      input type=hidden name=`getHtmlName`-removed[] value=UID
  *
  * @return Html
  */
 public function getControl()
 {
     $holder = Html::el('div', ['class' => 'mediastorage inline-file-choice']);
     $holder->data('mediastorage-filechoicer-init', json_encode(['name' => $this->getHtmlName() . $this->getHiddenUsedTail()]));
     $hidden_remove = $holder->create('input', ['type' => 'hidden']);
     $hidden_remove->name = $this->getHtmlName() . $this->getHiddenRemovedTail();
     $hidden_remove->data('mediastorage-role', 'removed-template');
     if ($this->withPrimary) {
         $hidden_primary = $holder->create('input', ['type' => 'hidden']);
         $hidden_primary->name = $this->getHtmlName() . $this->getHiddenPrimaryTail();
         $hidden_primary->data('mediastorage-role', 'primary-uid');
     }
     $fileHolder = Html::el('div');
     /** @property Presenter $presenter */
     $presenter = $this->form->getPresenter();
     /**
      * @var string $key
      * @var IFile $file
      */
     $count = 0;
     try {
         $files = $this->getFiles();
         foreach ($files as $key => $file) {
             $fh = clone $fileHolder;
             $fh->id = $file->getUID();
             $fh->data('original-title', $file->getName());
             $holder->addHtml($fh);
             $content = $fh->create('div', ['class' => 'content']);
             $image = $content->create('img');
             $footer = $fh->create('div', ['class' => 'footer']);
             $name = $footer->create('a');
             $hidden_added = $fh->create('input', ['type' => 'hidden']);
             $hidden_added->name = $this->getHtmlName() . $this->getHiddenUsedTail();
             $hidden_added->value = $file->getUID();
             if ($file->isImage()) {
                 $fh->class = 'mediastorage-frame image';
                 $image->src = $presenter->link(":MediaStorage:Images:", ['name' => $file, 'namespace' => $this->namespace, 'size' => $this->gridImageSize]);
                 $name->href = $presenter->link(":MediaStorage:Images:", ['name' => $file]);
             } else {
                 $fh->class = 'mediastorage-frame file';
                 $image->src = $presenter->link(":MediaStorage:Icons:", ['name' => $file->getIconName(), 'size' => $this->gridImageSize]);
                 $name->href = $presenter->link(":MediaStorage:Files:", ['name' => $file]);
             }
             $name->setText($file->getName());
             $overlay = $fh->create('div', ['class' => 'overlay']);
             $remover = $overlay->create('a');
             //$remover->setText($this->translate('Remove'));
             $remover->href = '#remove';
             $remover->class = 'remover glyphicon glyphicon-trash';
             $remover->data('mediastorage-uid', $file->getUID());
             if ($this->withPrimary) {
                 if ($file->isPrimary()) {
                     $unsetPrimary = $overlay->create('a');
                     $unsetPrimary->setText($this->translate('Remove primary'));
                     $unsetPrimary->href = '#unsetPrimary';
                     $unsetPrimary->class = 'unsetPrimary';
                     $unsetPrimary->data('mediastorage-uid', $file->getUID());
                     $hidden_primary->value = $file->getUID();
                 } else {
                     $setPrimary = $overlay->create('a');
                     $setPrimary->setText($this->translate('Set primary'));
                     $setPrimary->href = '#setPrimary';
                     $setPrimary->class = 'setPrimary';
                     $setPrimary->data('mediastorage-uid', $file->getUID());
                 }
             }
             $count++;
         }
     } catch (FileNotFoundException $e) {
         $div = $holder->create('div', ['class' => 'warning']);
         $div->setText($this->translate($e->getMessage()));
     }
     $popupAction = Html::el('a', ['class' => 'adder btn btn-info']);
     $popupAction->href = $presenter->link(':MediaStorage:MediaPopup:gridPopup');
     $popupAction->setText($this->translate('Select another file'));
     $holder->addHtml($popupAction);
     return $holder->addAttributes(parent::getControl()->attrs);
 }
Esempio n. 28
0
 /**
  * Generates control's HTML element.
  * @param  mixed
  * @return Nette\Utils\Html
  */
 public function getControl($key = NULL)
 {
     $input = parent::getControl();
     if ($key !== NULL) {
         $selected = array_flip((array) $this->value);
         return $input->addAttributes(array('id' => $input->id . '-' . $key, 'checked' => isset($selected[$key]), 'disabled' => is_array($this->disabled) ? isset($this->disabled[$key]) : $this->disabled, 'value' => $key));
     }
     $ids = $items = array();
     foreach ($this->items as $value => $label) {
         $items[$value] = $this->translate($label);
         $ids[$value] = $input->id . '-' . $value;
     }
     return $this->container->setHtml(Nette\Forms\Helpers::createInputList($items, array_merge($input->attrs, array('id:' => $ids, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'data-nette-rules:' => array(key($items) => $input->attrs['data-nette-rules']))), array('for:' => $ids) + $this->label->attrs, $this->separator));
 }
Esempio n. 29
0
 /**
  * Generates control's HTML element.
  *
  * @return Nette\Utils\Html
  */
 public function getControl()
 {
     $selected = $this->getValue();
     $selected = is_array($selected) ? array_flip($selected) : array($selected => true);
     $control = parent::getControl();
     $option = Nette\Utils\Html::el('option');
     if ($this->prompt !== false) {
         $control->add($this->prompt instanceof Nette\Utils\Html ? $this->prompt->value('') : (string) $option->value('')->setText($this->translate((string) $this->prompt)));
     }
     foreach ($this->items as $key => $value) {
         if (!is_array($value)) {
             $value = array($key => $value);
             $dest = $control;
         } else {
             $dest = $control->create('optgroup')->label($this->translate($key));
         }
         foreach ($value as $key2 => $value2) {
             if ($value2 instanceof Nette\Utils\Html) {
                 $dest->add((string) $value2->selected(isset($selected[$key2])));
             } else {
                 $key2 = $this->useKeys ? $key2 : $value2;
                 $value2 = $this->translate((string) $value2);
                 $dest->add((string) $option->value($key2)->selected(isset($selected[$key2]))->setText($value2));
             }
         }
     }
     return $control;
 }
Esempio n. 30
0
 /**
  * Generates control's HTML element.
  * @return Nette\Utils\Html
  */
 public function getControl()
 {
     $items = $this->prompt === FALSE ? array() : array('' => $this->translate($this->prompt));
     foreach ($this->items as $key => $value) {
         if (is_array($value)) {
             $key = $this->translate($key);
             foreach ($value as $k => $v) {
                 $items[$key][$k] = $this->translate($v);
             }
         } else {
             $items[$key] = $this->translate($value);
         }
     }
     return Nette\Forms\Helpers::createSelectBox($items, array('selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL))->addAttributes(parent::getControl()->attrs);
 }