Update information fields.

This commit is contained in:
Hoang Huu 2019-10-26 16:36:18 +07:00
parent 930ce3d63a
commit d2783ee222
7 changed files with 250 additions and 84 deletions

View File

@ -0,0 +1,76 @@
jQuery( document ).ready( function ( $ ) {
$.ajax( {
type: 'post',
dataType: 'json',
url: ajaxurl,
data: { action: 'opalestate_setting_custom_fields' },
success: function ( response ) {
var arr_setting_fields = response.data;
for ( var i = 0; i < arr_setting_fields.length; i++ ) {
$( '#' + arr_setting_fields[ i ] ).addClass( 'search-control' );
$( 'input[name="' + arr_setting_fields[ i ] + '_search_type"]' ).addClass( 'search-type-ctrl' );
}
$( '.search-type-ctrl' ).each( function ( index, value ) {
if ( $( this ).prop( 'checked' ) ) {
var val = $( this ).val();
var name = $( this ).attr( 'name' );
if ( val === 'select' ) {
var res = name.replace( /_search_type/g, '' );
var res = res.replace( /_/g, '-' );
$( '.cmb2-id-' + res + '-options-value' ).show();
$( '.cmb2-id-' + res + '-min-range' ).hide();
$( '.cmb2-id-' + res + '-max-range' ).hide();
$( '.cmb2-id-' + res + '-default-text' ).hide();
}
if ( val === 'text' ) {
var res = name.replace( /_search_type/g, '' );
var res = res.replace( /_/g, '-' );
$( '.cmb2-id-' + res + '-default-text' ).show();
$( '.cmb2-id-' + res + '-min-range' ).hide();
$( '.cmb2-id-' + res + '-max-range' ).hide();
$( '.cmb2-id-' + res + '-options-value' ).hide();
}
if ( val === 'range' ) {
var name = $( this ).attr( 'name' );
var res = name.replace( /_search_type/g, '' );
var res = res.replace( /_/g, '-' );
$( '.cmb2-id-' + res + '-options-value' ).hide();
$( '.cmb2-id-' + res + '-min-range' ).show();
$( '.cmb2-id-' + res + '-max-range' ).show();
$( '.cmb2-id-' + res + '-default-text' ).hide();
}
}
} );
$( '.search-type-ctrl' ).on( 'change', function () {
var val = $( this ).val();
var name = $( this ).attr( 'name' );
var res = name.replace( /_search_type/g, '' );
var res = res.replace( /_/g, '-' );
if ( val == 'range' ) {
$( '.cmb2-id-' + res + '-options-value' ).hide();
$( '.cmb2-id-' + res + '-min-range' ).show();
$( '.cmb2-id-' + res + '-max-range' ).show();
$( '.cmb2-id-' + res + '-default-text' ).hide();
} else if ( val == 'text' ) {
$( '.cmb2-id-' + res + '-default-text' ).show();
$( '.cmb2-id-' + res + '-options-value' ).hide();
$( '.cmb2-id-' + res + '-min-range' ).hide();
$( '.cmb2-id-' + res + '-max-range' ).hide();
} else {
$( '.cmb2-id-' + res + '-options-value' ).show();
$( '.cmb2-id-' + res + '-min-range' ).hide();
$( '.cmb2-id-' + res + '-max-range' ).hide();
$( '.cmb2-id-' + res + '-default-text' ).hide();
}
} );
}
} );
} );

View File

@ -19,7 +19,7 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
'opalestate_settings_property_subtabs_nav',
[
'property_general' => esc_html__( 'General', 'opalestate-pro' ),
'property_search' => esc_html__( 'Search Page', 'opalestate-pro' ),
'property_search' => esc_html__( 'Search', 'opalestate-pro' ),
'property_detail' => esc_html__( 'Single Page', 'opalestate-pro' ),
]
);
@ -115,11 +115,11 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
if ( $metas ) {
$fields[] = [
'name' => esc_html__( 'User Share Search', 'opalestate-pro' ),
'desc' => esc_html__( 'Display Share Search Link Management', 'opalestate-pro' ),
'id' => 'enable_share_earch',
'type' => 'switch',
'options' => [
'name' => esc_html__( 'User Share Search', 'opalestate-pro' ),
'desc' => esc_html__( 'Display Share Search Link Management', 'opalestate-pro' ),
'id' => 'enable_share_earch',
'type' => 'switch',
'options' => [
'on' => esc_html__( 'Enable', 'opalestate-pro' ),
'off' => esc_html__( 'Disable', 'opalestate-pro' ),
],
@ -261,43 +261,75 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
];
}
// $fields[] = [
// 'name' => esc_html__( 'Vertical Search Fields', 'opalestate-pro' ),
// 'type' => 'opalestate_title',
// 'id' => 'opalestate_title_general_settings_2',
// 'before_row' => '<hr>',
// 'after_row' => '<hr>',
// ];
//
// $fields[] = [
// 'name' => esc_html__( 'Show Price', 'opalestate-pro' ),
// 'id' => OPALESTATE_PROPERTY_PREFIX . 'price_opt_v',
// 'type' => 'switch',
// 'options' => [
// 0 => esc_html__( 'Disable', 'opalestate-pro' ),
// 1 => esc_html__( 'Enable', 'opalestate-pro' ),
// ],
// ];
//
// foreach ( $metas as $key => $meta ) {
// $fields[] = [
// 'name' => $meta['name'],
// 'id' => $meta['id'] . '_opt_v',
// 'type' => 'switch',
// 'options' => [
// 0 => esc_html__( 'Disable', 'opalestate-pro' ),
// 1 => esc_html__( 'Enable', 'opalestate-pro' ),
// ],
//
// ];
// }
$fields[] = [
'name' => esc_html__( 'Setting type fields search', 'opalestate-pro' ),
'desc' => esc_html__( 'Setting type fields search', 'opalestate-pro' ) . '<hr>',
'type' => 'opalestate_title',
'id' => 'opalestate_title_general_settings_type_search',
'before_row' => '<hr>',
'after_row' => '<hr>',
];
$metas = Opalestate_Property_MetaBox::metaboxes_info_fields();
wp_enqueue_script( 'opalestate-setting-custom-fields', OPALESTATE_PLUGIN_URL . 'assets/js/custom-fields.js', [ 'jquery' ], OPALESTATE_VERSION, false );
foreach ( $metas as $meta ) {
if ( $meta['id'] == OPALESTATE_PROPERTY_PREFIX . 'areasize' ) {
continue;
}
$fields[] = [
'name' => esc_html__( 'Search type ', 'opalestate-pro' ) . $meta['name'],
'options' => [
'select' => esc_html__( 'Select', 'opalestate-pro' ),
'range' => esc_html__( 'Range', 'opalestate-pro' ),
'text' => esc_html__( 'Text', 'opalestate-pro' ),
],
'id' => $meta['id'] . '_search_type',
'type' => 'radio_inline',
'default' => 'select',
];
$fields[] = [
'name' => esc_html__( 'Options select ', 'opalestate-pro' ) . $meta['name'],
'description' => esc_html__( 'Options value select. Use "," to separate values.', 'opalestate-pro' ),
'id' => $meta['id'] . '_options_value',
'type' => 'text',
'default' => '1,2,3,4,5,6,7,8,9,10',
];
$fields[] = [
'name' => esc_html__( 'Min range ', 'opalestate-pro' ) . $meta['name'],
'description' => esc_html__( 'Min range', 'opalestate-pro' ),
'id' => $meta['id'] . '_min_range',
'type' => 'text',
'default' => 1,
];
$fields[] = [
'name' => esc_html__( 'Max range ', 'opalestate-pro' ) . $meta['name'],
'description' => esc_html__( 'Max range', 'opalestate-pro' ),
'id' => $meta['id'] . '_max_range',
'type' => 'text',
'default' => 10000000,
];
$fields[] = [
'name' => esc_html__( 'Default text ', 'opalestate-pro' ) . $meta['name'],
'description' => esc_html__( 'Default text value', 'opalestate-pro' ),
'id' => $meta['id'] . '_default_text',
'type' => 'text',
'default' => '',
];
}
}
return $fields;
}
/**
*
* Get subtab detail fields.
*/
private function get_subtab_detail_fields() {
$fields = [];
@ -470,19 +502,19 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
];
$fields[] = [
'name' => esc_html__( 'Related properties layout', 'opalestate-pro' ),
'desc' => esc_html__( 'Select a layout for related properties.', 'opalestate-pro' ),
'id' => 'single_related_properties_layout',
'type' => 'select',
'options' => opalestate_get_loop_property_layouts(),
'name' => esc_html__( 'Related properties layout', 'opalestate-pro' ),
'desc' => esc_html__( 'Select a layout for related properties.', 'opalestate-pro' ),
'id' => 'single_related_properties_layout',
'type' => 'select',
'options' => opalestate_get_loop_property_layouts(),
];
$fields[] = [
'name' => esc_html__( 'Nearby properties layout', 'opalestate-pro' ),
'desc' => esc_html__( 'Select a layout for nearby properties.', 'opalestate-pro' ),
'id' => 'single_nearby_properties_layout',
'type' => 'select',
'options' => opalestate_get_loop_property_layouts(),
'name' => esc_html__( 'Nearby properties layout', 'opalestate-pro' ),
'desc' => esc_html__( 'Select a layout for nearby properties.', 'opalestate-pro' ),
'id' => 'single_nearby_properties_layout',
'type' => 'select',
'options' => opalestate_get_loop_property_layouts(),
];
return $fields;

View File

@ -400,4 +400,23 @@ function opalestate_update_api_key() {
// wp_send_json_success must be outside the try block not to break phpunit tests.
wp_send_json_success( $response );
}
add_action( 'wp_ajax_opalestate_update_api_key', 'opalestate_update_api_key' );
function opalestate_ajax_setting_custom_fields() {
$metas = Opalestate_Property_MetaBox::metaboxes_info_fields();
$metabox_key = [];
if ( $metas ) {
foreach ( $metas as $meta_item ) {
$metabox_key[] = $meta_item['id'];
}
}
echo json_encode( [ 'data' => $metabox_key ] );
exit;
}
add_action( 'wp_ajax_opalestate_setting_custom_fields', 'opalestate_ajax_setting_custom_fields' );
add_action( 'wp_ajax_nopriv_opalestate_setting_custom_fields', 'opalestate_ajax_setting_custom_fields' );

View File

@ -19,7 +19,6 @@ if ( ! defined( 'ABSPATH' ) ) {
*/
function opalestate_property_render_field_template( $field, $label, $type = 'select' ) {
$qvalue = isset( $_GET['info'][ $field ] ) ? sanitize_text_field( $_GET['info'][ $field ] ) : '';
$template = '';
$template = apply_filters( 'opalestate_property_render_search_field_template', $field, $label );
$template = apply_filters( 'opalestate_property_' . $field . '_field_template', $template );
@ -39,20 +38,72 @@ function opalestate_property_render_field_template( $field, $label, $type = 'sel
<span class="btn-plus"><i class="fa fa-plus"></i></span>
</div>
</div>
<?php break;
<?php
break;
default:
$template = '<label class="opalestate-label opalestate-label--' . sanitize_html_class( $label ) . '">' . esc_html( $label ) . '</label>';
$setting_search_type = 'opalestate_ppt_' . $field . '_search_type';
$setting_search_type_options = 'opalestate_ppt_' . $field . '_options_value';
$setting_search_min_range = 'opalestate_ppt_' . $field . '_min_range';
$setting_search_max_range = 'opalestate_ppt_' . $field . '_max_range';
$setting_search_default_text = 'opalestate_ppt_' . $field . '_default_text';
$template .= '<select class="form-control" name="info[%s]"><option value="">%s</option>';
for ( $i = 1; $i <= 10; $i++ ) {
$selected = $i == $qvalue ? 'selected="selected"' : '';
$display_type_search = opalestate_options( $setting_search_type, 'select' );
$template .= '<option ' . $selected . ' value="' . $i . '">' . $i . '</option>';
if ( $display_type_search == 'select' ) {
$option_values = (array) explode( ',', opalestate_options( $setting_search_type_options, '1,2,3,4,5,6,7,8,9,10' ) );
$template = '<select class="form-control" name="info[%s]"><option value="">%s</option>';
foreach ( $option_values as $value ) {
$selected = $value == $qvalue ? 'selected="selected"' : '';
$template .= '<option ' . $selected . ' value="' . $value . '">' . $value . '</option>';
}
$template .= '</select>';
$template = sprintf( $template, $field, $label );
} elseif ( $display_type_search == 'text' ) {
$option_values = opalestate_options( $setting_search_default_text, '' );
$qvalue = $qvalue ? $qvalue : $option_values;
$template = '<input class="form-control" type="text" name="info[%s]" value="%s"/>';
$template = sprintf( $template, $field, $qvalue );
} elseif ( $display_type_search == 'range' ) {
$min_name = 'min_' . $field;
$max_name = 'max_' . $field;
$search_min = (int) isset( $_GET[ $min_name ] ) ? $_GET[ $min_name ] : opalestate_options( $setting_search_min_range, 0 );
$search_max = (int) isset( $_GET[ $max_name ] ) ? $_GET[ $max_name ] : opalestate_options( $setting_search_max_range, 1000 );
$data = [
'id' => $field,
'unit' => '',
'ranger_min' => opalestate_options( $setting_search_min_range, 0 ),
'ranger_max' => opalestate_options( $setting_search_max_range, 1000 ),
'input_min' => $search_min,
'input_max' => $search_max,
];
ob_start();
opalesate_property_slide_ranger_template( __( $label . ": ", 'opalestate-pro' ), $data );
$template = ob_get_contents();
ob_end_clean();
} else {
$template = '<label class="opalestate-label opalestate-label--' . sanitize_html_class( $label ) . '">' . esc_html( $label ) . '</label>';
$template .= '<select class="form-control" name="info[%s]"><option value="">%s</option>';
for ( $i = 1; $i <= 10; $i++ ) {
$selected = $i == $qvalue ? 'selected="selected"' : '';
$template .= '<option ' . $selected . ' value="' . $i . '">' . $i . '</option>';
}
$template .= '</select>';
$template = sprintf( $template, $field, $label );
}
$template .= '</select>';
$template = sprintf( $template, $field, $label );
break;
}

View File

@ -19,7 +19,7 @@ if ( ! defined( 'ABSPATH' ) ) {
class Opalestate_Property_MetaBox {
/**
*
* Register admin fields.
*/
public function register_admin_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
@ -40,7 +40,6 @@ class Opalestate_Property_MetaBox {
'tabs' => [],
];
$tabs_setting['tabs'][] = [
'id' => 'p-general',
'icon' => 'dashicons-admin-home',
@ -168,7 +167,7 @@ class Opalestate_Property_MetaBox {
}
/**
*
* Management fields.
*/
public function metaboxes_management_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
@ -196,7 +195,6 @@ class Opalestate_Property_MetaBox {
'sanitization_cb' => 'opal_map_sanitise',
'split_values' => true,
],
[
'name' => esc_html__( 'Postal Code / Zip', 'opalestate-pro' ),
'id' => $prefix . 'zipcode',
@ -212,7 +210,6 @@ class Opalestate_Property_MetaBox {
0 => esc_html__( 'No', 'opalestate-pro' ),
],
],
[
'name' => esc_html__( 'Address', 'opalestate-pro' ),
'id' => $prefix . 'address',
@ -221,8 +218,6 @@ class Opalestate_Property_MetaBox {
'required' => 'required',
],
],
[
'id' => "{$prefix}video",
'name' => esc_html__( 'Video', 'opalestate-pro' ),
@ -235,7 +230,7 @@ class Opalestate_Property_MetaBox {
}
/**
*
* Price fields.
*/
public function metaboxes_price_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
@ -287,7 +282,7 @@ class Opalestate_Property_MetaBox {
}
/**
*
* Information fields.
*/
public static function metaboxes_info_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
@ -300,7 +295,6 @@ class Opalestate_Property_MetaBox {
'description' => esc_html__( 'Enter built year', 'opalestate-pro' ),
'before_row' => '<div class="row-group-features group-has-three group-property-info clearfix"><h3>' . ( is_admin() ? "" : esc_html__( 'Property Information', 'opalestate-pro' ) ) . '</h3>',
// callback
],
[
'name' => esc_html__( 'Parking', 'opalestate-pro' ),
@ -312,7 +306,6 @@ class Opalestate_Property_MetaBox {
],
'description' => esc_html__( 'Enter number of Parking', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Bedrooms', 'opalestate-pro' ),
'id' => $prefix . 'bedrooms',
@ -351,7 +344,6 @@ class Opalestate_Property_MetaBox {
'type' => 'text',
'description' => esc_html__( 'Enter Orientation of property', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Living Rooms', 'opalestate-pro' ),
'id' => "{$prefix}livingrooms",
@ -362,7 +354,6 @@ class Opalestate_Property_MetaBox {
],
'description' => esc_html__( 'Enter Number of Living Rooms', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Kitchens', 'opalestate-pro' ),
'id' => "{$prefix}kitchens",
@ -373,7 +364,6 @@ class Opalestate_Property_MetaBox {
],
'description' => esc_html__( 'Enter Number of Kitchens', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Rooms', 'opalestate-pro' ),
'id' => "{$prefix}amountrooms",
@ -385,7 +375,6 @@ class Opalestate_Property_MetaBox {
'description' => esc_html__( 'Enter Number of Amount Rooms', 'opalestate-pro' ),
'after_row' => '</div>',
],
];
@ -393,7 +382,7 @@ class Opalestate_Property_MetaBox {
}
/**
*
* Facilites fields.
*/
public function metaboxes_public_facilities_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
@ -427,7 +416,7 @@ class Opalestate_Property_MetaBox {
}
/**
*
* Member fields.
*/
public function metaboxes_members_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
@ -487,7 +476,7 @@ class Opalestate_Property_MetaBox {
}
/**
*
* Assigment fields.
*/
public function metaboxes_assignment_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
@ -518,7 +507,7 @@ class Opalestate_Property_MetaBox {
}
/**
*
* Layout fields.
*/
public function metaboxes_layout_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
@ -533,7 +522,6 @@ class Opalestate_Property_MetaBox {
'options' => apply_filters( 'opalestate_single_layout_templates', [ '' => esc_html__( 'Inherit', 'opalestate-pro' ) ] ),
'description' => esc_html__( 'Select a layout to display full information of this property', 'opalestate-pro' ),
],
[
'name' => esc_html__( 'Preview Display', 'opalestate-pro' ),
'id' => "{$prefix}preview",
@ -547,7 +535,7 @@ class Opalestate_Property_MetaBox {
}
/**
*
* Floor plans fields.
*/
public function metaboxes_floor_plans() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
@ -617,7 +605,7 @@ class Opalestate_Property_MetaBox {
}
/**
*
* Apartment fields.
*/
public function metaboxes_apartments() {
$prefix = OPALESTATE_PROPERTY_PREFIX;

View File

@ -4,14 +4,14 @@ if ( ! $fields ) {
return;
}
$type = isset( $type ) ? $type : '';
$column = isset( $GLOBALS['group-info-column'] ) ? $GLOBALS['group-info-column'] : 3;
if( $type != 'input' ) {
$type = isset( $type ) ? $type : '';
$column = isset( $GLOBALS['group-info-column'] ) ? $GLOBALS['group-info-column'] : 3;
if ( $type != 'input' ) {
$col_class = 'col-lg-' . ( 12 / absint( $column ) ) . ' col-md-' . ( 12 / absint( $column ) ) . ' col-sm-' . ( 12 / absint( $column ) );
} else {
$col_class = 'column-item';
}
foreach ( $fields as $key => $label ): ?>
<?php if ( 'areasize' == $key ) : continue; endif; ?>
<div class="<?php echo esc_attr( $col_class ); ?>">

View File

@ -11,7 +11,7 @@ $search_max_price = isset( $_GET['max_price'] ) ? sanitize_text_field( $_GET['ma
$showareasize = opalestate_options( OPALESTATE_PROPERTY_PREFIX . 'areasize_opt', 1 );
$showprice = opalestate_options( OPALESTATE_PROPERTY_PREFIX . 'price_opt', 1 );
$fields = OpalEstate_Search::get_setting_search_fields( '_v' );
$fields = OpalEstate_Search::get_setting_search_fields();
?>
<div class="ajax-map-search full-width">