Example #1
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;
 }
Example #2
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;
 }
Example #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();
 }
Example #4
0
 /**
  * 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;
 }
Example #5
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();
 }
Example #6
0
 /**
  * Covert Matrix to HTML string
  */
 public function getString()
 {
     $this->setAttribute('name', $this->getNameAttributeString());
     // setup select list of files
     $select = $this->getSelectHtml();
     $name = $this->getName();
     $settings = $this->getSettings();
     $blocks = $this->getMatrixBlocks();
     // add controls
     if (isset($settings['help'])) {
         $help = "<div class=\"help\"> <p>{$settings['help']}</p> </div>";
         $this->removeSetting('help');
     } else {
         $help = '';
     }
     $generator = new Generator();
     $default_null = $generator->newInput('hidden', $this->getAttribute('name'), null)->getString();
     // add it all
     $html = "\n<div class='tr-matrix control-section tr-repeater'>\n<div class='matrix-controls controls'>\n{$select}\n<div class=\"tr-repeater-button-add\">\n<input type=\"button\" value=\"Add New\" data-id='{$this->mxid}' data-folder='{$name}' class=\"btn btn-default matrix-button\">\n</div>\n<div class=\"btn-group\">\n<input type=\"button\" value=\"Flip\" class=\"flip btn btn-default\">\n<input type=\"button\" value=\"Contract\" class=\"tr_action_collapse btn btn-default\">\n<input type=\"button\" value=\"Clear All\" class=\"clear btn btn-default\">\n</div>\n{$help}\n</div>\n<div>{$default_null}</div>\n<div id=\"{$this->mxid}\" class='matrix-fields tr-repeater-fields ui-sortable'>{$blocks}</div></div>";
     return $html;
 }
Example #7
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();
 }
Example #8
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;
 }
Example #9
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;
 }
Example #10
0
 /**
  * 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;
 }