Ejemplo n.º 1
0
 /**
  * @param $conditions string[] the key is the name of the condition, the value is the name of the
  *   value that enables the condition
  * @param $filters string[] the key is the name of the filter, the value is the name of the form
  *   element containing its value
  * @return string
  */
 public function buildObject($conditions = null, $filters = null)
 {
     $class_name = $this->type->asString();
     // visible input
     $input = new Input(null, strval($this->value));
     $input->setAttribute('autocomplete', 'off');
     $input->setAttribute('data-combo-class', Names::classToSet($class_name));
     if (!$this->readonly) {
         if ($filters) {
             $html_filters = [];
             $old_name = $this->name;
             foreach ($filters as $filter_name => $filter_value) {
                 $this->name = $filter_value;
                 $name = $this->getFieldName('', false);
                 $html_filters[] = $filter_name . '=' . $name;
             }
             $this->name = $old_name;
             $input->setAttribute('data-combo-filters', join(',', $html_filters));
         }
         if ($conditions) {
             $html_conditions = [];
             $old_name = $this->name;
             foreach ($conditions as $condition_name => $condition_value) {
                 $this->name = $condition_name;
                 $name = $this->getFieldName('', false);
                 $html_conditions[] = $name . '=' . $condition_value;
             }
             $this->name = $old_name;
             $input->setAttribute('data-conditions', join(';', $html_conditions));
         }
         $input->addClass('autowidth');
         $input->addClass('combo');
         // id input
         $id_input = new Input($this->getFieldName('id_'), $this->value ? Dao::getObjectIdentifier($this->value) : '');
         $id_input->setAttribute('type', 'hidden');
         $id_input->addClass('id');
         // 'add' / 'edit' anchor
         $fill_combo = isset($this->template) ? ['fill_combo' => $this->template->getFormId() . DOT . $this->getFieldName('id_', false)] : '';
         $edit = new Anchor(View::current()->link($this->value ? get_class($this->value) : $class_name, Feature::F_ADD, null, $fill_combo), 'edit');
         $edit->addClass('edit');
         $edit->setAttribute('target', Target::BLANK);
         $edit->setAttribute('title', '|Edit ¦' . Names::classToDisplay($class_name) . '¦|');
         // 'more' button
         $more = new Button('more');
         $more->addClass('more');
         $more->setAttribute('tabindex', -1);
         $this->setOnChangeAttribute($id_input);
         return $id_input . $input . $more . $edit;
     }
     return $input;
 }