Esempio n. 1
0
 /**
  * Build XHTML for a form control.
  *
  * \param $control
  *   An AnewtFormControl instance.
  */
 protected function _build_form_control_node($control)
 {
     $control_div = ax_div_class(null, 'form-control');
     $control_div->append_child($this->_build_description_node($control));
     $control_div->append_child($this->_build_error_node($control));
     /* Label and the widget itself are combined. Buttons do not have
      * explicit labels, since the label text is on the button itself. */
     $widget = $control->build_widget();
     $label_text = $control->_get('label');
     if (is_null($label_text) || $control instanceof AnewtFormControlButton) {
         /* No label (none set or this is a button) */
         $control_div->append_child($widget);
     } else {
         /* This control has a label */
         assert('is_string($label_text) || $label_text instanceof AnewtXMLDomNode');
         $label = new AnewtXHTMLLabel($label_text, array('class' => 'form-control'));
         /* Some composite widgets support allow the 'for=' attribute to be
          * filled in, even though they consist of multiple html widgets. */
         if ($control->get('composite')) {
             $composite_for = $control->get('composite-for');
             if (!is_null($composite_for)) {
                 $label->set_attribute('for', $composite_for);
             }
         } else {
             $label->set_attribute('for', $control->get('id'));
         }
         /* Help text */
         $help = $control->_get('help');
         if (!is_null($help)) {
             $help_text = to_string($help);
             $label->set_attribute('title', $help_text);
             $label->add_class('with-help');
         }
         $control_div->append_child($label);
         $control_div->append_child($widget);
         unset($label);
     }
     unset($widget);
     return $control_div;
 }
Esempio n. 2
0
 function build_widget()
 {
     $value = $this->_get('value');
     if (is_null($value)) {
         $value = "";
     }
     assert('is_string($value); // only plain strings can be used as field value: type: ' . gettype($value));
     $name = $this->get('name');
     $widgets = array();
     if ($this->get('show-img-preview') && $value) {
         $widgets[] = ax_div_class(ax_img_src($this->get('preview-dir') . $value), 'preview');
     } elseif ($this->get('show-link-preview') && $value) {
         $widgets[] = ax_div_class(ax_a_href($value, $this->get('preview-dir') . $value), 'preview');
     }
     $remove_label = $this->_get('remove-label');
     if ($remove_label && $value) {
         $subattr = array('type' => 'checkbox', 'name' => $name . '-remove');
         $widgets[] = new AnewtXHTMLInput(null, $subattr);
         $subattr = array('for' => $name . '-remove');
         $widgets[] = new AnewtXHTMLLabel($remove_label, $subattr);
         $widgets[] = ax_br();
     }
     /* XML tag attributes used both for single line and multiline */
     $attr = array('name' => $this->get('name'), 'id' => $this->get('id'), 'type' => 'file');
     if ($this->_get('readonly')) {
         $attr['readonly'] = 'readonly';
     }
     if ($this->_get('disabled')) {
         $attr['disabled'] = 'disabled';
     }
     $size = $this->_get('size');
     if (!is_null($size)) {
         assert('is_int($size);');
         $attr['size'] = (string) $size;
     }
     $maxlength = $this->_get('maxlength');
     if (!is_null($maxlength)) {
         assert('is_int($maxlength);');
         $attr['maxlength'] = (string) $maxlength;
     }
     $max_file_size = $this->_get('max_file_size');
     if (!is_null($max_file_size)) {
         $subattr = array('type' => 'hidden', 'name' => 'MAX_FILE_SIZE', 'value' => (string) $max_file_size);
         $widgets[] = new AnewtXHMTLInput(null, $subattr);
     }
     $widget = new AnewtXHTMLInput(null, $attr);
     /* Styling */
     $widget->add_class('fileupload');
     if (!$this->_get('required')) {
         $widget->add_class('optional');
     }
     /* Optional extra class value */
     $class = $this->_get('class');
     if (!is_null($class)) {
         $widget->add_class($class);
     }
     /* Help text, if any */
     $help = $this->_get('help');
     if (!is_null($help)) {
         $help_text = to_string($help);
         $widget->set_attribute('title', $help_text);
         $widget->add_class('with-help');
     }
     $widgets[] = $widget;
     /* Add secondary label, if any */
     $secondary_label = $this->_get('secondary-label');
     if (!is_null($secondary_label)) {
         $widgets[] = $secondary_label;
     }
     $out = ax_fragment($widgets);
     return $out;
 }