start POC of field types forms

This commit is contained in:
Leo Germani 2018-03-05 15:30:59 -03:00
parent 365f7f530f
commit f5d9806f0e
6 changed files with 40 additions and 31 deletions

View File

@ -266,6 +266,11 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
if($request['context'] === 'edit'){ if($request['context'] === 'edit'){
$item_arr['current_user_can_edit'] = $item->can_edit(); $item_arr['current_user_can_edit'] = $item->can_edit();
ob_start();
$item->get_field_type_object()->form();
$form = ob_get_clean();
$item_arr['edit_form'] = $form;
} }
return $item_arr; return $item_arr;

View File

@ -47,29 +47,33 @@ class Category extends Field_Type {
// TODO: form incomplete and not tested // TODO: form incomplete and not tested
?> ?>
<tr> <div class="field">
<td> <label class="label">
<label><?php echo __('Category','tainacan'); ?></label><br/> <?php _e('Category','tainacan'); ?>
<small><?php echo __('Select the category','tainacan'); ?></small> </label>
</td>
<td> <div class="control">
<select name="taxonomy_id"> <div class="select">
<?php foreach ($taxonomies as $tax): ?> <select name="field_type_options[taxonomy_id]">
<?php foreach ($taxonomies as $tax): ?>
<option value="<?php echo $tax->get_db_identifier(); ?>" <?php selected($this->get_option('taxonomy_id'), $tax->get_db_identifier()); ?> ><?php echo $tax->get_name(); ?></option>
<option value="<?php echo $tax->get_db_identifier(); ?>" <?php selected($this->get_option('taxonomy_id'), $tax->get_db_identifier()); ?> ><?php echo $tax->get_name(); ?></option>
<?php endforeach; ?>
</select> <?php endforeach; ?>
</td> </select>
<td> </div>
<label><?php echo __('Allow creation of new terms','tainacan'); ?></label><br/> </div>
<small><?php echo __('If checked, users may create new terms for this category, otherwise they can only selected from existing terms.','tainacan'); ?></small> </div>
</td>
<td> <div class="field">
<input type="checkbox" name="allow_new_terms" <?php checked(true, $this->get_option('allow_new_terms')); ?> > <div class="control">
<label>Allow</label> <label class="checkbox">
</td> <input type="checkbox" name="field_type_options[allow_new_terms]" <?php checked(true, $this->get_option('allow_new_terms')); ?> >
</tr> Allow
</label>
</div>
</div>
<?php <?php
} }

View File

@ -22,7 +22,7 @@ class Checkbox extends Field_Type {
*/ */
public function render( $itemMetadata ){ public function render( $itemMetadata ){
$options = ( isset( $this->options['options'] ) ) ? $this->options['options'] : ''; $options = $this->get_option('options');
return '<tainacan-checkbox options="'.$options.'" return '<tainacan-checkbox options="'.$options.'"
field_id ="'.$itemMetadata->get_field()->get_id().'" field_id ="'.$itemMetadata->get_field()->get_id().'"
item_id="'.$itemMetadata->get_item()->get_id().'" item_id="'.$itemMetadata->get_item()->get_id().'"
@ -41,7 +41,7 @@ class Checkbox extends Field_Type {
<small><?php echo __('Insert the options, separate by lines for the field value','tainacan'); ?></small> <small><?php echo __('Insert the options, separate by lines for the field value','tainacan'); ?></small>
</td> </td>
<td> <td>
<textarea name="field_type_checkbox[options]"><?php echo ( isset( $this->options['options'] ) ) ? $this->options['options'] : ''; ?></textarea> <textarea name="field_type_options[options]"><?php echo $this->get_option('options'); ?></textarea>
</td> </td>
</tr> </tr>
<?php <?php

View File

@ -33,7 +33,7 @@ class Date extends Field_Type {
* generate the fields for this field type * generate the fields for this field type
*/ */
public function form(){ public function form(){
$approx_date = ( $this->options['approximate_date'] ) ? $this->options['approximate_date'] : ''; $approx_date = $this->get_option('approximate_date');
?> ?>
<tr> <tr>
<td> <td>
@ -41,7 +41,7 @@ class Date extends Field_Type {
<small><?php echo __('Allow format approximate date','tainacan'); ?></small> <small><?php echo __('Allow format approximate date','tainacan'); ?></small>
</td> </td>
<td> <td>
<?php Helpers\HtmlHelpers::radio_field( $approx_date, 'field_type_date[approximate_date]' ) ?> <?php Helpers\HtmlHelpers::radio_field( $approx_date, 'field_type_options[approximate_date]' ) ?>
</td> </td>
</tr> </tr>
<?php <?php

View File

@ -22,7 +22,7 @@ class Radio extends Field_Type {
*/ */
public function render( $itemMetadata ){ public function render( $itemMetadata ){
$options = ( isset( $this->options['options'] ) ) ? $this->options['options'] : ''; $options = $this->get_option('options');
return '<tainacan-radio return '<tainacan-radio
options="' . $options . '" options="' . $options . '"
field_id ="'.$itemMetadata->get_field()->get_id().'" field_id ="'.$itemMetadata->get_field()->get_id().'"
@ -42,7 +42,7 @@ class Radio extends Field_Type {
<small><?php echo __('Insert the options, separate by lines for the field value','tainacan'); ?></small> <small><?php echo __('Insert the options, separate by lines for the field value','tainacan'); ?></small>
</td> </td>
<td> <td>
<textarea name="field_type_radio[options]"><?php echo ( isset( $this->options['options'] ) ) ? $this->options['options'] : ''; ?></textarea> <textarea name="field_type_options[options]"><?php echo $this->get_option('options'); ?></textarea>
</td> </td>
</tr> </tr>
<?php <?php

View File

@ -22,7 +22,7 @@ class Selectbox extends Field_Type {
*/ */
public function render( $itemMetadata ){ public function render( $itemMetadata ){
$options = ( isset( $this->options['options'] ) ) ? $this->options['options'] : ''; $options = $this->get_option('options');
return '<tainacan-selectbox return '<tainacan-selectbox
options="' . $options . '" options="' . $options . '"
field_id ="'.$itemMetadata->get_field()->get_id().'" field_id ="'.$itemMetadata->get_field()->get_id().'"
@ -42,7 +42,7 @@ class Selectbox extends Field_Type {
<small><?php echo __('Insert the options, separate by lines for the field value','tainacan'); ?></small> <small><?php echo __('Insert the options, separate by lines for the field value','tainacan'); ?></small>
</td> </td>
<td> <td>
<textarea name="field_type_selectbox[options]"><?php echo ( isset( $this->options['options'] ) ) ? $this->options['options'] : ''; ?></textarea> <textarea name="field_type_options[options]"><?php echo $this->get_option('options'); ?></textarea>
</td> </td>
</tr> </tr>
<?php <?php