Exemple #1
0
 public function getJsField($content, $with_values = true)
 {
     parent::getJsField($content);
     $target_content = $this->getTargetName();
     if ($this['format']['render_type'] == 'livesearch') {
         $this->_js_field['type'] = 'livesearch';
         $this->_js_field['params'] = array('content_type' => $target_content);
         $c_val = $content[$this['keyword']];
         if ($c_val) {
             $c_val_obj = fx::data($target_content)->where('id', $c_val)->one();
             if ($c_val_obj) {
                 $this->_js_field['value'] = array('id' => $c_val_obj['id'], 'name' => $c_val_obj['name']);
             }
         }
         return $this->_js_field;
     }
     $this->_js_field['type'] = 'select';
     if (!$with_values) {
         return $this->_js_field;
     }
     $finder = fx::data($target_content);
     $name_prop = $finder->getNameField();
     if (!$name_prop) {
         if ($target_content !== 'lang') {
             $finder->where('site_id', $content['site_id']);
             $name_prop = 'name';
         } else {
             $name_prop = 'en_name';
         }
     }
     $val_items = $finder->all();
     $this->_js_field['values'] = $val_items->getValues($name_prop, 'id');
     return $this->_js_field;
 }
Exemple #2
0
 public function getJsField($content)
 {
     parent::getJsField($content);
     if (isset($this['format']) && isset($this['format']['html']) && $this['format']['html']) {
         $this->_js_field['wysiwyg'] = true;
         $this->_js_field['nl2br'] = $this['format']['nl2br'];
     }
     return $this->_js_field;
 }
Exemple #3
0
 public function getJsField($content)
 {
     parent::getJsField($content);
     $this->_js_field['values'] = $this->getSelectValues();
     if ($this->format['show'] == 'radio') {
         $this->_js_field['type'] = 'radio';
     }
     $this->_js_field['value'] = $content[$this['keyword']];
     return $this->_js_field;
 }
Exemple #4
0
 public function getJsField($content)
 {
     parent::getJsField($content);
     $this->_js_field['type'] = 'file';
     $this->_js_field['field_id'] = $this['id'];
     $val = $this->_js_field['value'];
     $abs = fx::path()->abs($val);
     if (fx::path()->exists($abs)) {
         $this->_js_field['value'] = array('path' => $val, 'filename' => fx::path()->fileName($abs), 'size' => fx::files()->readableSize($abs));
     }
     return $this->_js_field;
 }
Exemple #5
0
 public function getJsField($content)
 {
     parent::getJsField($content);
     $render_type = $this['format']['render_type'];
     if ($render_type == 'livesearch') {
         $this->_js_field['type'] = 'livesearch';
         $this->_js_field['is_multiple'] = true;
         $this->_js_field['params'] = array('content_type' => $this->getEndDataType());
         $rel = $this->getRelation();
         $related_relation = fx::data($rel[1])->relations();
         $linker_field = $related_relation[$rel[3]][2];
         $this->_js_field['name_postfix'] = $linker_field;
         if (isset($content[$this['keyword']])) {
             $this->_js_field['value'] = array();
             $linkers = $content[$this['keyword']]->linkers;
             foreach ($content[$this['keyword']] as $num => $v) {
                 $this->_js_field['value'][] = array('id' => $v['id'], 'name' => $v['name'], 'value_id' => $linkers[$num]['id']);
             }
         }
     } elseif ($render_type == 'table') {
         $rel = $this->getRelation();
         $entity = fx::data($rel[1])->create();
         $entity_fields = $entity->getFormFields();
         $this->_js_field['tpl'] = array();
         $this->_js_field['labels'] = array();
         foreach ($entity_fields as $ef) {
             if ($ef['name'] == $rel[2]) {
                 continue;
             }
             // do not show "is published" flag in this table
             if ($ef['name'] == 'is_published') {
                 continue;
             }
             $this->_js_field['tpl'][] = $ef;
             $this->_js_field['labels'][] = $ef['label'];
         }
         $this->_js_field['values'] = array();
         if (isset($content[$this['keyword']])) {
             if ($rel[0] === System\Finder::HAS_MANY) {
                 $linkers = $content[$this['keyword']];
             } else {
                 $linkers = $content[$this['keyword']]->linkers;
             }
             foreach ($linkers as $linker) {
                 $linker_fields = $linker->getFormFields();
                 $val_array = array('_index' => $linker['id']);
                 foreach ($linker_fields as $lf) {
                     // skip the relation field
                     if ($lf['name'] == $rel[2]) {
                         continue;
                     }
                     // do not show "is published" flag in this table
                     if ($lf['name'] == 'is_published') {
                         continue;
                     }
                     // form field has "name" prop instead of "keyword"
                     $val_array[$lf['name']] = $lf['value'];
                 }
                 $this->_js_field['values'][] = $val_array;
             }
         }
         $this->_js_field['type'] = 'set';
     }
     return $this->_js_field;
 }