/**
  * Render list item
  *
  * @param string $relationId   The relationship identity
  * @param BaseModel $item      Record object.
  * @return Element('li')
  */
 public function renderItem($relationId, $subset, $item, $on = false)
 {
     $id = $item->id;
     $li = new Element('li');
     $label = new Label();
     $hiddenId = new HiddenInput("{$relationId}[{$id}][_foreign_id]", array('value' => $id));
     $checkboxValue = $on ? 1 : 0;
     $checkbox = new CheckboxInput("{$relationId}[{$id}][_connect]", array('value' => $checkboxValue));
     if ($on) {
         $checkbox->check();
     }
     $label->append($checkbox);
     $label->append($item->dataLabel());
     $label->append($hiddenId);
     $li->append($label);
     return $li;
 }
Exemplo n.º 2
0
 /**
  * HTML structure
  *
  * <div class="formkit-widget formkit-widget-thumbimagefile formkit-image-wrapper">
  *    <div class="formkit-image-cover">
  *      <img src="...."/>
  *    </div>
  *    <input type="file"...>
  * </div>
  *
  */
 public function init($attributes)
 {
     $this->autoresize_types = array(_('Fit to Width') => 'max_width', _('Fit to Height') => 'max_height', _('Scale') => 'scale', _('Crop and Scale') => 'crop_and_scale');
     parent::init($attributes);
     $this->fileInput = new FileInput($this->name, $attributes);
     $this->imageCover = new Div(array('class' => 'formkit-image-cover'));
     $this->imageCover->setAttributeValue('data-width', $this->dataWidth ?: 200);
     $this->imageCover->setAttributeValue('data-height', $this->dataHeight);
     $this->inputWrapper = new Div();
     $this->inputWrapper->addClass('formkit-widget-thumbimagefile')->addClass('formkit-image-wrapper');
     // if it has a value, generate img
     if ($this->renderImageTag && $this->value) {
         $this->image = new Element('img', array('src' => $this->prefix . $this->value));
         $this->imageCover->append($this->image);
     }
     if ($this->value) {
         $this->fileInput->setAttributeValue('data-image-src', $this->prefix . $this->value);
     }
     if ($this->exif) {
         $this->fileInput->setAttributeValue('data-exif', 'true');
     }
     if ($this->autoresize) {
         $this->fileInput->setAttributeValue('data-autoresize', 'true');
     }
     if ($this->droppreview) {
         $this->fileInput->setAttributeValue('data-droppreview', 'true');
     }
     if ($this->dropupload) {
         $this->fileInput->setAttributeValue('data-dropupload', 'true');
     }
     $this->fileInput->setAttributeValue('data-width', $this->dataWidth);
     $this->fileInput->setAttributeValue('data-height', $this->dataHeight);
     $this->inputWrapper->append($this->imageCover);
     $this->inputWrapper->append($this->fileInput);
     if ($this->autoresize && $this->autoresize_input) {
         $this->fileInput->setAttributeValue('data-autoresize-input', 'true');
         $checkbox = new CheckboxInput($this->name . '_autoresize');
         $checkbox->addClass('autoresize-checkbox');
         if ($this->autoresize_input_check) {
             $checkbox->check();
         }
         $checkboxId = $checkbox->getSerialId();
         $label = new Label(_("Use auto-resize"));
         $label->for($checkboxId);
         $resizeWrapper = new Div();
         $resizeWrapper->append($checkbox);
         $resizeWrapper->append($label);
         $resizeWrapper->addClass("autoresize");
         $this->inputWrapper->append($resizeWrapper);
         if ($this->autoresize_type_input) {
             $resizeTypeWrapper = new Div();
             $resizeTypeWrapper->addClass('autoresize-type');
             $typeSelector = new SelectInput($this->name . '_autoresize_type', ['options' => $this->autoresize_types, 'value' => $this->autoresize_type]);
             $typeSelector->addClass('autoresize-type-selector');
             $resizeTypeWrapper->append($typeSelector);
             $this->inputWrapper->append($resizeTypeWrapper);
         }
     }
 }