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', 'opalestate_settings_property_subtabs_nav',
[ [
'property_general' => esc_html__( 'General', 'opalestate-pro' ), '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' ), 'property_detail' => esc_html__( 'Single Page', 'opalestate-pro' ),
] ]
); );
@ -261,43 +261,75 @@ class Opalestate_Settings_Property_Tab extends Opalestate_Settings_Base_Tab {
]; ];
} }
// $fields[] = [ $fields[] = [
// 'name' => esc_html__( 'Vertical Search Fields', 'opalestate-pro' ), 'name' => esc_html__( 'Setting type fields search', 'opalestate-pro' ),
// 'type' => 'opalestate_title', 'desc' => esc_html__( 'Setting type fields search', 'opalestate-pro' ) . '<hr>',
// 'id' => 'opalestate_title_general_settings_2', 'type' => 'opalestate_title',
// 'before_row' => '<hr>', 'id' => 'opalestate_title_general_settings_type_search',
// 'after_row' => '<hr>', 'before_row' => '<hr>',
// ]; 'after_row' => '<hr>',
// ];
// $fields[] = [
// 'name' => esc_html__( 'Show Price', 'opalestate-pro' ), $metas = Opalestate_Property_MetaBox::metaboxes_info_fields();
// 'id' => OPALESTATE_PROPERTY_PREFIX . 'price_opt_v',
// 'type' => 'switch', wp_enqueue_script( 'opalestate-setting-custom-fields', OPALESTATE_PLUGIN_URL . 'assets/js/custom-fields.js', [ 'jquery' ], OPALESTATE_VERSION, false );
// 'options' => [
// 0 => esc_html__( 'Disable', 'opalestate-pro' ), foreach ( $metas as $meta ) {
// 1 => esc_html__( 'Enable', 'opalestate-pro' ), if ( $meta['id'] == OPALESTATE_PROPERTY_PREFIX . 'areasize' ) {
// ], continue;
// ]; }
//
// foreach ( $metas as $key => $meta ) { $fields[] = [
// $fields[] = [ 'name' => esc_html__( 'Search type ', 'opalestate-pro' ) . $meta['name'],
// 'name' => $meta['name'], 'options' => [
// 'id' => $meta['id'] . '_opt_v', 'select' => esc_html__( 'Select', 'opalestate-pro' ),
// 'type' => 'switch', 'range' => esc_html__( 'Range', 'opalestate-pro' ),
// 'options' => [ 'text' => esc_html__( 'Text', 'opalestate-pro' ),
// 0 => esc_html__( 'Disable', 'opalestate-pro' ), ],
// 1 => esc_html__( 'Enable', '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; return $fields;
} }
/** /**
* * Get subtab detail fields.
*/ */
private function get_subtab_detail_fields() { private function get_subtab_detail_fields() {
$fields = []; $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 must be outside the try block not to break phpunit tests.
wp_send_json_success( $response ); wp_send_json_success( $response );
} }
add_action( 'wp_ajax_opalestate_update_api_key', 'opalestate_update_api_key' ); 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' ) { function opalestate_property_render_field_template( $field, $label, $type = 'select' ) {
$qvalue = isset( $_GET['info'][ $field ] ) ? sanitize_text_field( $_GET['info'][ $field ] ) : ''; $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_render_search_field_template', $field, $label );
$template = apply_filters( 'opalestate_property_' . $field . '_field_template', $template ); $template = apply_filters( 'opalestate_property_' . $field . '_field_template', $template );
@ -39,10 +38,60 @@ function opalestate_property_render_field_template( $field, $label, $type = 'sel
<span class="btn-plus"><i class="fa fa-plus"></i></span> <span class="btn-plus"><i class="fa fa-plus"></i></span>
</div> </div>
</div> </div>
<?php
<?php break; break;
default: default:
$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';
$display_type_search = opalestate_options( $setting_search_type, 'select' );
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 = '<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>'; $template .= '<select class="form-control" name="info[%s]"><option value="">%s</option>';
@ -51,8 +100,10 @@ function opalestate_property_render_field_template( $field, $label, $type = 'sel
$template .= '<option ' . $selected . ' value="' . $i . '">' . $i . '</option>'; $template .= '<option ' . $selected . ' value="' . $i . '">' . $i . '</option>';
} }
$template .= '</select>'; $template .= '</select>';
$template = sprintf( $template, $field, $label ); $template = sprintf( $template, $field, $label );
}
break; break;
} }

View File

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

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 ); $showareasize = opalestate_options( OPALESTATE_PROPERTY_PREFIX . 'areasize_opt', 1 );
$showprice = opalestate_options( OPALESTATE_PROPERTY_PREFIX . 'price_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"> <div class="ajax-map-search full-width">