예제 #1
0
 /**
  * Covert Image to HTML string
  */
 public function getString()
 {
     $name = $this->getNameAttributeString();
     $this->setAttribute('class', 'photo-picker');
     $value = $this->getValue();
     $this->removeAttribute('name');
     $generator = new Generator();
     if (!$this->getSetting('button')) {
         $this->setSetting('button', 'Insert Image');
     }
     if ($value != "") {
         $class = $this->mediaProviderClass;
         $img = new $class();
         if ($img instanceof MediaProvider && $img instanceof Model) {
             /** @var $img MediaProvider */
             $img = $img->find($value);
             $src = $img->getThumbSrc();
             $image = "<img src=\"{$src}\" />";
         } else {
             throw new \Exception('Media field requires an Eloquent Model implementing TypeRocket\\MediaProvider');
         }
     } else {
         $image = '';
     }
     if (empty($image)) {
         $value = '';
     }
     $html = $generator->newInput('hidden', $name, $value, $this->getAttributes())->getString();
     $html .= '<div class="btn-group">';
     $html .= $generator->newElement('input', array('type' => 'button', 'class' => 'image-picker-button btn btn-default', 'value' => $this->getSetting('button')))->getString();
     $html .= $generator->newElement('input', array('type' => 'button', 'class' => 'image-picker-clear btn btn-default', 'value' => 'Clear'))->getString();
     $html .= '</div>';
     $html .= $generator->newElement('div', array('class' => 'image-picker-placeholder'), $image)->getString();
     return $html;
 }
예제 #2
0
 private function getSelectHtml()
 {
     $name = $this->getName();
     $options = $this->getOptions();
     $options = $options ? $options : $this->setOptionsFromFolder()->getOptions();
     if ($options) {
         $generator = new Generator();
         $generator->newElement('select', array('data-mxid' => $this->mxid, 'class' => "matrix-select-{$name}", 'data-group' => $this->getForm()->getGroup()));
         $default = $this->getSetting('default');
         foreach ($options as $name => $value) {
             $attr['value'] = $value;
             if ($default === $value) {
                 $attr['selected'] = 'selected';
             } else {
                 unset($attr['selected']);
             }
             $generator->appendInside('option', $attr, $name);
         }
         $select = $generator->getString();
     } else {
         $paths = Config::getPaths();
         $dir = $paths['matrix_folder'] . '/' . $name;
         $select = "<div class=\"tr-dev-alert-helper\"><i class=\"icon tr-icon-bug\"></i> Add a files for Matrix <code>{$dir}</code> and add your matrix files to it.</div>";
     }
     return $select;
 }
예제 #3
0
 /**
  * Covert Image to HTML string
  */
 public function getString()
 {
     $input = new Generator();
     $name = $this->getNameAttributeString();
     $value = $this->getValue();
     return $input->newInput('file', $name, $value, $this->getAttributes())->getString();
 }
예제 #4
0
 /**
  * Covert Select to HTML string
  */
 public function getString()
 {
     $default = $this->getSetting('default');
     $this->setAttribute('name', $this->getNameAttributeString());
     $option = $this->getValue();
     $option = !is_null($option) ? $option : $default;
     $generator = new Generator();
     $generator->newElement('select', $this->getAttributes());
     foreach ($this->options as $key => $value) {
         if (is_array($value)) {
             $optgroup = new Generator();
             $optgroup->newElement('optgroup', ['label' => $key]);
             foreach ($value as $k => $v) {
                 $attr['value'] = $v;
                 if ($option == $v && isset($option)) {
                     $attr['selected'] = 'selected';
                 } else {
                     unset($attr['selected']);
                 }
                 $optgroup->appendInside('option', $attr, (string) $k);
             }
             $generator->appendInside($optgroup);
         } else {
             $attr['value'] = $value;
             if ($option == $value && isset($option)) {
                 $attr['selected'] = 'selected';
             } else {
                 unset($attr['selected']);
             }
             $generator->appendInside('option', $attr, (string) $key);
         }
     }
     return $generator->getString();
 }
예제 #5
0
 /**
  * Covert Textarea to HTML string
  */
 public function getString()
 {
     $generator = new Generator();
     $this->setAttribute('name', $this->getNameAttributeString());
     $value = $this->getValue();
     $value = $this->sanitize($value, 'textarea');
     $max = $this->getMaxlength($value, $this->getAttribute('maxlength'));
     return $generator->newElement('textarea', $this->getAttributes(), $value)->getString() . $max;
 }
예제 #6
0
파일: Text.php 프로젝트: typerocket/laravel
 /**
  * Covert Test to HTML string
  */
 public function getString()
 {
     $input = new Generator();
     $name = $this->getNameAttributeString();
     $value = $this->getValue();
     $value = $this->sanitize($value, 'raw');
     $max = $this->getMaxlength($value, $this->getAttribute('maxlength'));
     return $input->newInput($this->getType(), $name, Sanitize::attribute($value), $this->getAttributes())->getString() . $max;
 }
예제 #7
0
 /**
  * Get the max length for text type fields
  *
  * @param $value
  * @param $maxLength
  *
  * @return string|\TypeRocket\Html\Generator
  */
 public function getMaxlength($value, $maxLength)
 {
     if ($maxLength != null && $maxLength > 0) {
         $left = (int) $maxLength - mb_strlen($value);
         $max = new Generator();
         $max->newElement('p', ['class' => 'tr-maxlength'], 'Characters left: ')->appendInside('span', [], $left);
         $max = $max->getString();
     } else {
         $max = '';
     }
     return $max;
 }
예제 #8
0
 /**
  * Covert Submit to HTML string
  */
 public function getString()
 {
     $name = '_tr_submit_form';
     $this->removeAttribute('id');
     $this->setAttribute('id', $name);
     $value = $this->getAttribute('value');
     $this->removeAttribute('value');
     $this->removeAttribute('name');
     $this->appendStringToAttribute('class', ' btn btn-primary');
     $generator = new Html\Generator();
     return $generator->newInput('submit', $name, $value, $this->getAttributes())->getString();
 }
예제 #9
0
 /**
  * Covert Items to HTML string
  */
 public function getString()
 {
     $name = $this->getNameAttributeString();
     $this->appendStringToAttribute('class', ' items-list');
     // $this->attr['class'] = 'items-list';
     $items = $this->getValue();
     $this->removeAttribute('name');
     $generator = new Generator();
     if (!$this->getSetting('button')) {
         $this->setSetting('button', 'Insert Item');
     }
     $list = '';
     if (is_array($items)) {
         foreach ($items as $value) {
             $sanitize = "\\TypeRocket\\Sanitize::" . $this->getSetting('sanitize', 'attribute');
             if (is_callable($sanitize)) {
                 $value = call_user_func($sanitize, $value);
             }
             $input = $generator->newInput('text', $name . '[]', $value)->getString();
             $remove = '#remove';
             $list .= $generator->newElement('li', array('class' => 'item'), '<div class="move glyphicon glyphicon-menu-hamburger"></div><a href="' . $remove . '" class="glyphicon glyphicon-remove remove" title="Remove Item"></a>' . $input)->getString();
         }
     }
     $this->removeAttribute('id');
     $html = $generator->newInput('hidden', $name, '0', $this->getAttributes())->getString();
     $html .= '<div class="btn-group">';
     $html .= $generator->newElement('input', array('type' => 'button', 'class' => 'items-list-button btn btn-default', 'value' => $this->getSetting('button')))->getString();
     $html .= $generator->newElement('input', array('type' => 'button', 'class' => 'items-list-clear btn btn-default', 'value' => 'Clear'))->getString();
     $html .= '</div>';
     if (is_null($name) && is_string($this->getAttribute('data-name'))) {
         $name = $this->getAttribute('data-name');
     }
     $html .= $generator->newElement('ul', array('data-name' => $name, 'class' => 'tr-items-list cf'), $list)->getString();
     return $html;
 }
예제 #10
0
 /**
  * Covert Editor to HTML string
  */
 public function getString()
 {
     $max = '';
     $generator = new Generator();
     $this->setAttribute('name', $this->getNameAttributeString());
     $value = $this->getValue();
     $this->appendStringToAttribute('class', ' typerocket-editor ');
     $sanitize = "\\TypeRocket\\Sanitize::" . $this->getSetting('sanitize', 'editor');
     if (is_callable($sanitize)) {
         $value = call_user_func($sanitize, $value);
     }
     $maxLength = $this->getAttribute('maxlength');
     if ($maxLength != null && $maxLength > 0) {
         $left = (int) $maxLength - strlen(utf8_decode($value));
         $max = new Generator();
         $max->newElement('p', array('class' => 'tr-maxlength'), 'Characters left: ')->appendInside('span', array(), $left);
         $max = $max->getString();
     }
     return $generator->newElement('textarea', $this->getAttributes(), $value)->getString() . $max;
 }
예제 #11
0
 /**
  * Covert Checkbox to HTML string
  */
 public function getString()
 {
     $name = $this->getNameAttributeString();
     $this->removeAttribute('name');
     $default = $this->getSetting('default');
     $option = $this->getValue();
     $checkbox = new Generator();
     $field = new Generator();
     if ($option == '1' || !is_null($option) && $option === $this->getAttribute('value')) {
         $this->setAttribute('checked', 'checked');
     } elseif ($default === true && is_null($option)) {
         $this->setAttribute('checked', 'checked');
     }
     $checkbox->newInput('checkbox', $name, '1', $this->getAttributes());
     $field->newElement('label')->appendInside($checkbox)->appendInside('span', array(), $this->getSetting('text'));
     if ($default !== false) {
         $hidden = new Generator();
         $field->prependInside($hidden->newInput('hidden', $name, '0'));
     }
     return $field->getString();
 }
예제 #12
0
 /**
  * Covert Radio to HTML string
  */
 public function getString()
 {
     $name = $this->getNameAttributeString();
     $default = $this->getSetting('default');
     $option = $this->getValue();
     $option = !is_null($option) ? $this->getValue() : $default;
     $this->removeAttribute('name');
     $this->removeAttribute('id');
     $generator = new Html\Generator();
     $field = '<ul class="data-full">';
     foreach ($this->options as $key => $value) {
         if ($option === $value) {
             $this->setAttribute('checked', 'checked');
         } else {
             $this->removeAttribute('checked');
         }
         $field .= "<li><label>";
         $field .= $generator->newInput('radio', $name, $value, $this->getAttributes())->getString();
         $field .= "<span>{$key}</span></label>";
     }
     $field .= '</ul>';
     return $field;
 }
예제 #13
0
 /**
  * Covert Repeater to HTML string
  */
 public function getString()
 {
     $this->setAttribute('name', $this->getNameAttributeString());
     $form = $this->getForm();
     $settings = $this->getSettings();
     $name = $this->getName();
     $form->setDebugStatus(false);
     $html = '';
     // add controls
     if (isset($settings['help'])) {
         $help = "<div class=\"help\"> <p>{$settings['help']}</p> </div>";
         $this->removeSetting('help');
     } else {
         $help = '';
     }
     // add button settings
     if (isset($settings['add_button'])) {
         $add_button_value = $settings['add_button'];
     } else {
         $add_button_value = "Add New";
     }
     // template for repeater groups
     $href = '#remove';
     $openContainer = '<div class="repeater-controls"><div class="collapse glyphicon glyphicon-chevron-down"></div><div class="glyphicon glyphicon-menu-hamburger move"></div><a href="' . $href . '" class="glyphicon glyphicon-remove remove" title="remove"></a></div><div class="repeater-inputs">';
     $endContainer = '</div>';
     $html .= '<div class="control-section tr-repeater">';
     // start tr-repeater
     // setup repeater
     $cache_group = $form->getGroup();
     $cache_sub = $form->getSub();
     $root_group = $this->getBrackets();
     $form->setGroup($this->getBrackets() . "[{{ {$name} }}]");
     // add controls (add, flip, clear all)
     $generator = new Generator();
     $default_null = $generator->newInput('hidden', $this->getAttribute('name'), null)->getString();
     $html .= "<div class=\"controls\"><div class=\"tr-repeater-button-add\"><input type=\"button\" value=\"{$add_button_value}\" class=\"btn btn-default add\" /></div><div class=\"btn-group\"><input type=\"button\" value=\"Flip\" class=\"flip btn btn-default\" /><input type=\"button\" value=\"Contract\" class=\"tr_action_collapse btn btn-default\"><input type=\"button\" value=\"Clear All\" class=\"clear btn btn-default\" /></div>{$help}<div>{$default_null}</div></div>";
     // replace name attr with data-name so fields are not saved
     $templateFields = str_replace(' name="', ' data-name="', $this->getTemplateFields());
     // render js template data
     $html .= "<div class=\"tr-repeater-group-template\" data-id=\"{$name}\">";
     $html .= $openContainer . $templateFields . $endContainer;
     $html .= '</div>';
     // render saved data
     $html .= '<div class="tr-repeater-fields">';
     // start tr-repeater-fields
     $repeats = $this->getValue();
     if (is_array($repeats)) {
         foreach ($repeats as $k => $array) {
             $html .= '<div class="tr-repeater-group">';
             $html .= $openContainer;
             $form->setGroup($root_group . "[{$k}]");
             $html .= $form->getFromFieldsString($this->fields);
             $html .= $endContainer;
             $html .= '</div>';
         }
     }
     $html .= '</div>';
     // end tr-repeater-fields
     $form->setGroup($cache_group);
     $form->setSub($cache_sub);
     $html .= '</div>';
     // end tr-repeater
     return $html;
 }
예제 #14
0
파일: Form.php 프로젝트: typerocket/laravel
 /**
  * Close the From Element and add a submit button if value is string
  *
  * @param null|string $value
  *
  * @return string
  */
 public function close($value = null)
 {
     $html = '';
     if (is_string($value)) {
         $generator = new Generator();
         $html .= $generator->newInput('submit', '_tr_submit_form', $value, array('id' => '_tr_submit_form', 'class' => 'btn btn-primary'))->getString();
     }
     $html .= '</form>';
     return $html;
 }