From d2783ee2227d1ef920243c4ade75aa85ebe503f4 Mon Sep 17 00:00:00 2001 From: Hoang Huu Date: Sat, 26 Oct 2019 16:36:18 +0700 Subject: [PATCH] Update information fields. --- assets/js/custom-fields.js | 76 +++++++++++ inc/admin/settings/property.php | 126 +++++++++++------- inc/ajax-functions.php | 19 +++ inc/function-search-fields.php | 71 ++++++++-- inc/property/class-metabox-property-admin.php | 32 ++--- templates/search-box/fields/group-info.php | 8 +- templates/shortcodes/ajax-map-search.php | 2 +- 7 files changed, 250 insertions(+), 84 deletions(-) create mode 100644 assets/js/custom-fields.js diff --git a/assets/js/custom-fields.js b/assets/js/custom-fields.js new file mode 100644 index 00000000..c5a34bdf --- /dev/null +++ b/assets/js/custom-fields.js @@ -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(); + } + } ); + } + } ); +} ); diff --git a/inc/admin/settings/property.php b/inc/admin/settings/property.php index 93cb14df..2f067503 100755 --- a/inc/admin/settings/property.php +++ b/inc/admin/settings/property.php @@ -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' => '
', - // 'after_row' => '
', - // ]; - // - // $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' ) . '
', + 'type' => 'opalestate_title', + 'id' => 'opalestate_title_general_settings_type_search', + 'before_row' => '
', + 'after_row' => '
', + ]; + + $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; diff --git a/inc/ajax-functions.php b/inc/ajax-functions.php index 4764d779..3892b379 100755 --- a/inc/ajax-functions.php +++ b/inc/ajax-functions.php @@ -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' ); diff --git a/inc/function-search-fields.php b/inc/function-search-fields.php index 11324c54..282bbea4 100755 --- a/inc/function-search-fields.php +++ b/inc/function-search-fields.php @@ -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 - - ' . esc_html( $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 .= ''; + + foreach ( $option_values as $value ) { + $selected = $value == $qvalue ? 'selected="selected"' : ''; + $template .= ''; + } + $template .= ''; + $template = sprintf( $template, $field, $label ); + + } elseif ( $display_type_search == 'text' ) { + $option_values = opalestate_options( $setting_search_default_text, '' ); + $qvalue = $qvalue ? $qvalue : $option_values; + + $template = ''; + + $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 = ''; + + $template .= ''; + $template = sprintf( $template, $field, $label ); } - $template .= ''; - $template = sprintf( $template, $field, $label ); break; } diff --git a/inc/property/class-metabox-property-admin.php b/inc/property/class-metabox-property-admin.php index 272218d6..8414e864 100755 --- a/inc/property/class-metabox-property-admin.php +++ b/inc/property/class-metabox-property-admin.php @@ -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' => '

' . ( is_admin() ? "" : esc_html__( 'Property Information', 'opalestate-pro' ) ) . '

', - // 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' => '
', - ], ]; @@ -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; diff --git a/templates/search-box/fields/group-info.php b/templates/search-box/fields/group-info.php index 0e2b26f0..edee1893 100755 --- a/templates/search-box/fields/group-info.php +++ b/templates/search-box/fields/group-info.php @@ -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 ): ?>
diff --git a/templates/shortcodes/ajax-map-search.php b/templates/shortcodes/ajax-map-search.php index 1b63a352..c6ae164c 100755 --- a/templates/shortcodes/ajax-map-search.php +++ b/templates/shortcodes/ajax-map-search.php @@ -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(); ?>