/**
 *
 * Build a div structure like this:
 
        <div class="form-group">
            <label for="inputAccount" class="col-lg-2 control-label">* 帳號</label>
            <div class="col-lg-10">
                <input id="inputAccount" type="text" name="account" placeholder="ariel123" readoly="" autocomplete="off" class="form-control">
            </div>
        </div>
 */
 public function build()
 {
     $wrapper = new Div(array('class' => $this->wrapperClass));
     $widget = $this->column->createWidget(null, $this->widgetAttributes);
     $widget->addClass('form-control');
     $widgetId = $widget->getSerialId();
     $wrapper->addClass($widget->convertClassToCssClassName());
     /*
     if ( $widget instanceof CheckboxInput ) {
         $label = $this->column->createLabelWidget();
         $label->prepend($widget);
         $wrapper->append($label);
     */
     if ($widget instanceof HiddenInput) {
         // $wrapper->append( $widget );
         return $widget;
     } else {
         $inputDiv = new Div(array('class' => $this->inputWrapperClass));
         $inputDiv->append($widget);
         $label = $this->column->createLabelWidget();
         $label->setAttributes(array('class' => $this->labelClass, 'for' => $widgetId));
         $wrapper->append($label);
         $wrapper->append($inputDiv);
         if ($this->column->hint) {
             $hintEl = new Span(array('class' => $this->hintClass));
             $hintEl->append($this->column->hint);
             $inputDiv->append($hintEl);
         }
     }
     return $wrapper;
 }
示例#2
0
 /**
 *
 * Build a div structure like this:
 
        <div class="v-field">
            <div class="label">{% trans 'Role' %}</div>
            <div class="input">
                <select name="role">
                    <option value="user">User</option>
                    <option value="admin">Admin</option>
                </select>
            </div>
        </div>
 */
 public function build()
 {
     $wrapper = new Div(array('class' => $this->wrapperClass));
     $widget = $this->column->createWidget(null, $this->widgetAttributes);
     $wrapper->addClass($widget->convertClassToCssClassName());
     if ($widget instanceof CheckboxInput) {
         $label = $this->column->createLabelWidget();
         $label->prepend($widget);
         $wrapper->append($label);
     } elseif ($widget instanceof HiddenInput) {
         $wrapper->append($widget);
     } else {
         $labelDiv = new Div(array('class' => $this->labelClass));
         $inputDiv = new Div(array('class' => $this->inputClass));
         $inputDiv->append($widget);
         $label = $this->column->createLabelWidget();
         $labelDiv->append($label);
         $wrapper->append($labelDiv);
         $wrapper->append($inputDiv);
         if ($this->column->hint) {
             $hintEl = new Span(array('class' => $this->hintClass));
             $hintEl->append($this->column->hint);
             $wrapper->append($hintEl);
         }
     }
     return $wrapper;
 }
示例#3
0
 public function init($a)
 {
     $this->style = array('clear' => 'both');
     parent::init($a);
 }
示例#4
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);
         }
     }
 }