This commit is contained in:
Champ Camba
2019-11-22 15:09:51 +08:00
7 changed files with 107 additions and 45 deletions
+7 -10
View File
@@ -255,15 +255,6 @@ function um_ajax_get_members( directory, args ) {
if ( typeof value_to != 'undefined' ) {
var val_to = value_to.split(':');
var minutes = val_to[1]*1;
// var minutes = Math.ceil( val_to[1] ) + 1;
// if ( minutes >= 60 ) {
// minutes = 0;
// val_to[0] = val_to[0]*1 + 1;
//
// if ( val_to[0] >= 24 ) {
// val_to[0] = 0;
// }
// }
var hours = val_to[0]*1;
if ( hours < 10 ) {
@@ -949,6 +940,9 @@ jQuery(document.body).ready( function() {
directory.data( 'searched', 1 );
directory.find( '.um-member-directory-sorting-options' ).prop( 'disabled', false );
directory.find( '.um-member-directory-view-type' ).removeClass( 'um-disabled' );
// if ( directory.find( '.um-search-filter select[data-um-parent="' + filter_name + '"]' ).length > 0 ) {
// jQuery(this).trigger('change');
// }
});
@@ -1067,7 +1061,6 @@ jQuery(document.body).ready( function() {
um_set_url_from_data( directory, 'filter_' + filter_name, current_value );
var select = jQuery( '.um-search-filter select[name="' + filter_name + '"]' );
select.find('option[value="' + removeItem + '"]').prop('disabled', false).show();
@@ -1077,6 +1070,10 @@ jQuery(document.body).ready( function() {
}
select.select2('destroy').select2();
if ( directory.find( '.um-search-filter select[data-um-parent="' + filter_name + '"]' ).length > 0 ) {
select.trigger('change');
}
} else if ( type === 'slider' ) {
um_set_url_from_data( directory, 'filter_' + filter_name + '_from','' );
um_set_url_from_data( directory, 'filter_' + filter_name + '_to', '' );
+1 -1
View File
File diff suppressed because one or more lines are too long
+62 -19
View File
@@ -465,22 +465,31 @@ jQuery(document).ready(function() {
/**
* Find all select fields with parent select fields
*/
jQuery('select[data-um-parent]').each(function(){
jQuery('select[data-um-parent]').each( function() {
var me = jQuery(this);
var parent_option = me.data('um-parent');
var um_ajax_url = me.data('um-ajax-url');
var um_ajax_source = me.data('um-ajax-source');
var original_value = me.val();
me.attr('data-um-init-field', true );
jQuery(document).on('change','select[name="'+parent_option+'"]',function(){
jQuery(document).on('change','select[name="' + parent_option + '"]',function() {
var parent = jQuery(this);
var form_id = parent.closest('form').find('input[type="hidden"][name="form_id"]').val();
var arr_key = parent.val();
var form_id = parent.closest( 'form' ).find( 'input[type="hidden"][name="form_id"]' ).val();
if ( parent.val() != '' && typeof um_select_options_cache[ arr_key ] != 'object' ) {
var arr_key;
if ( me.attr( 'data-member-directory' ) === 'yes' ) {
var directory = parent.parents('.um-directory');
arr_key = um_get_data_for_directory( directory, 'filter_' + parent_option );
if ( typeof arr_key != 'undefined' ) {
arr_key = arr_key.split('||');
}
} else {
arr_key = parent.val();
}
if ( typeof arr_key != 'undefined' && arr_key != '' && typeof um_select_options_cache[ arr_key ] != 'object' ) {
jQuery.ajax({
url: wp.ajax.settings.url,
@@ -488,19 +497,19 @@ jQuery(document).ready(function() {
data: {
action: 'um_select_options',
parent_option_name: parent_option,
parent_option: parent.val(),
parent_option: arr_key,
child_callback: um_ajax_source,
child_name: me.attr('name'),
members_directory: me.attr('data-mebers-directory'),
child_name: me.attr('name'),
members_directory: me.attr('data-member-directory'),
form_id: form_id,
nonce: um_scripts.nonce
},
success: function( data ){
if( data.status == 'success' && parent.val() != '' ){
um_field_populate_child_options( me, data, arr_key);
if ( data.status == 'success' && arr_key != '' ) {
um_field_populate_child_options( me, data, arr_key );
}
if( typeof data.debug !== 'undefined' ){
if ( typeof data.debug !== 'undefined' ) {
console.log( data );
}
},
@@ -512,19 +521,19 @@ jQuery(document).ready(function() {
}
if ( parent.val() != '' && typeof um_select_options_cache[ arr_key ] == 'object' ) {
if ( typeof arr_key != 'undefined' && arr_key != '' && typeof um_select_options_cache[ arr_key ] == 'object' ) {
var data = um_select_options_cache[ arr_key ];
um_field_populate_child_options( me, data, arr_key );
}
if ( parent.val() == '' ){
if ( typeof arr_key != 'undefined' || arr_key == '' ) {
me.find('option[value!=""]').remove();
me.val('').trigger('change');
}
});
jQuery('select[name="'+parent_option+'"]').trigger('change');
jQuery('select[name="' + parent_option + '"]').trigger('change');
});
@@ -535,6 +544,7 @@ jQuery(document).ready(function() {
* @param string key
*/
function um_field_populate_child_options( me, data, arr_key, arr_items ) {
var directory = me.parents('.um-directory');
var parent_option = me.data('um-parent');
var child_name = me.attr('name');
var parent_dom = jQuery('select[name="'+parent_option+'"]');
@@ -548,11 +558,10 @@ jQuery(document).ready(function() {
search_get = '';
if ( data.post.members_directory === 'yes' ) {
var urlParams = new URLSearchParams(window.location.search);
search_get = urlParams.get(data.post.child_name);
arr_items.push({id: '', text: '', selected: 1});
}
jQuery.each( data.items, function(k,v){
arr_items.push({id: k, text: v, selected: (v === search_get) });
arr_items.push({id: k, text: v, selected: (v === search_get)});
});
me.select2('destroy');
@@ -562,6 +571,41 @@ jQuery(document).ready(function() {
minimumResultsForSearch: 10
});
if ( data.post.members_directory === 'yes' ) {
me.find('option').each( function() {
if ( jQuery(this).html() !== '' ) {
jQuery(this).data( 'value_label', jQuery(this).html() ).attr( 'data-value_label', jQuery(this).html() );
}
});
var current_filter_val = um_get_data_for_directory( directory, 'filter_' + child_name );
if ( typeof current_filter_val != 'undefined' ) {
current_filter_val = current_filter_val.split('||');
var temp_filter_val = [];
jQuery.each( current_filter_val, function(i) {
if ( me.find('option[value="' + current_filter_val[ i ] + '"]').length ) {
temp_filter_val.push( current_filter_val[ i ] );
}
me.find('option[value="' + current_filter_val[ i ] + '"]').prop('disabled', true).hide();
if ( me.find('option:not(:disabled)').length === 1 ) {
me.prop('disabled', true);
}
me.select2('destroy').select2();
me.val('').trigger( 'change' );
});
temp_filter_val = temp_filter_val.join('||');
if ( current_filter_val !== temp_filter_val ) {
um_set_url_from_data( directory, 'filter_' + child_name, temp_filter_val );
um_ajax_get_members( directory );
}
}
um_change_tag( directory );
}
if ( data.post.members_directory !== 'yes' ) {
if ( typeof data.field.default !== 'undefined' && ! me.data('um-original-value') ) {
me.val( data.field.default ).trigger('change');
@@ -576,7 +620,6 @@ jQuery(document).ready(function() {
}
um_select_options_cache[ arr_key ] = data;
}
});
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -4
View File
@@ -1150,15 +1150,13 @@ if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) {
* @return boolean
*/
public function skip_field_validation( $skip, $post_input, $array ) {
if ( $post_input === '_options' && isset( $array['post']['_custom_dropdown_options_source'] ) ) {
$um_callback_func = $array['post']['_custom_dropdown_options_source'];
$skip = function_exists( $um_callback_func );
$skip = function_exists( $array['post']['_custom_dropdown_options_source'] );
}
return $skip;
}
/**
* Retrieves dropdown/multi-select options from a callback function
+10 -6
View File
@@ -1124,11 +1124,14 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$arr_options = $opts['options'];
} elseif ( function_exists( $data['custom_dropdown_options_source'] ) ) {
if ( isset( $data['parent_dropdown_relationship'] ) ) {
$_POST['parent_option_name'] = $data['parent_dropdown_relationship'];
$_POST['parent_option'] = um_user( $data['parent_dropdown_relationship'] );
$arr_options = call_user_func(
$data['custom_dropdown_options_source'],
( ! empty( $data['parent_dropdown_relationship'] ) ? $data['parent_dropdown_relationship'] : '' )
);
$arr_options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
} else {
$arr_options = call_user_func( $data['custom_dropdown_options_source'] );
}
}
if ( $has_custom_source || function_exists( $data['custom_dropdown_options_source'] ) ) {
@@ -2783,8 +2786,9 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
* }
* ?>
*/
$ajax_source_url = apply_filters( "um_custom_dropdown_options_source_url__{$form_key}", admin_url( 'admin-ajax.php' ), $data );
$atts_ajax .= ' data-um-ajax-url="' . esc_url( $ajax_source_url ) . '" ';
// todo maybe deprecate
// $ajax_source_url = apply_filters( "um_custom_dropdown_options_source_url__{$form_key}", admin_url( 'admin-ajax.php' ), $data );
// $atts_ajax .= ' data-um-ajax-url="' . esc_url( $ajax_source_url ) . '" ';
}
+24 -4
View File
@@ -523,12 +523,28 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
$custom_dropdown = '';
if ( ! empty( $attrs['custom_dropdown_options_source'] ) ) {
$attrs['custom'] = true;
if ( ! empty( $attrs['parent_dropdown_relationship'] ) ) {
$custom_dropdown .= ' data-member-directory="yes"';
$custom_dropdown .= ' data-um-parent="' . esc_attr( $attrs['parent_dropdown_relationship'] ) . '"';
if ( isset( $_GET[ 'filter_' . $attrs['parent_dropdown_relationship'] . '_' . $unique_hash ] ) ) {
$_POST['parent_option_name'] = $attrs['parent_dropdown_relationship'];
$_POST['parent_option'] = explode( '||', filter_input( INPUT_GET, 'filter_' . $attrs['parent_dropdown_relationship'] . '_' . $unique_hash ) );
}
}
$ajax_source = apply_filters( "um_custom_dropdown_options_source__{$filter}", $attrs['custom_dropdown_options_source'], $attrs );
$custom_dropdown .= ' data-um-ajax-source="' . esc_attr( $ajax_source ) . '" ';
$attrs['options'] = UM()->fields()->get_options_from_callback( $attrs, $attrs['type'] );
$custom_dropdown = ' data-um-ajax-source="' . esc_attr( $attrs['custom_dropdown_options_source'] ) . '"';
}
if ( $attrs['metakey'] != 'role_select' ) {
if ( $attrs['metakey'] != 'role_select' && empty( $custom_dropdown ) ) {
$attrs['options'] = array_intersect( $attrs['options'], $values_array );
} elseif ( ! empty( $custom_dropdown ) ) {
$attrs['options'] = array_intersect_key( $attrs['options'], array_flip( $values_array ) );
} else {
$attrs['options'] = array_intersect_key( $attrs['options'], array_flip( $values_array ) );
}
@@ -539,13 +555,17 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
return '';
}
if ( ! empty( $attrs['custom_dropdown_options_source'] ) && ! empty( $attrs['parent_dropdown_relationship'] ) ) {
$attrs['options'] = array();
}
if ( isset( $attrs['label'] ) ) {
$attrs['label'] = strip_tags( $attrs['label'] );
}
asort( $attrs['options'] ); ?>
<select class="um-s1" id="<?php echo $filter; ?>" name="<?php echo $filter; ?>"
<select class="um-s1" id="<?php echo esc_attr( $filter ); ?>" name="<?php echo esc_attr( $filter ); ?>"
data-placeholder="<?php esc_attr_e( stripslashes( $attrs['label'] ), 'ultimate-member' ); ?>"
<?php echo $custom_dropdown; ?>>
@@ -568,7 +588,7 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
<option value="<?php echo esc_attr( $opt ); ?>" data-value_label="<?php esc_attr_e( $v, 'ultimate-member' ); ?>"
<?php disabled( ! empty( $filter_from_url ) && in_array( $opt, $filter_from_url ) ) ?>
<?php selected( $opt == $default_value ) ?>>
<?php selected( $opt === $default_value ) ?>>
<?php _e( $v, 'ultimate-member' ); ?>
</option>