Feature #1386 » custom-order-profile-options-2.diff
| bp-xprofile/admin/js/admin.dev.js (working copy) | ||
|---|---|---|
| 150 | 150 |
// Change cursor to move if JS is enabled |
| 151 | 151 |
.css( 'cursor', 'move' ); |
| 152 | 152 | |
| 153 |
// Allow reordering of field options |
|
| 154 |
jQuery( '.options-box' ).sortable( {
|
|
| 155 |
cursor: 'move', |
|
| 156 |
opacity: 0.3, |
|
| 157 |
items: 'p.sortable', |
|
| 158 |
tolerance: 'pointer', |
|
| 159 | ||
| 160 |
update: function() {
|
|
| 161 |
jQuery.post( ajaxurl, {
|
|
| 162 |
action: 'xprofile_reorder_field_options', |
|
| 163 |
'cookie': encodeURIComponent( document.cookie ), |
|
| 164 |
'_wpnonce': jQuery( 'input#_wpnonce' ).val(), |
|
| 165 |
'option_order': jQuery( this ).sortable( 'serialize' ) // because sortable's serialize method isn't working |
|
| 166 |
}, |
|
| 167 |
function( response ) {
|
|
| 168 |
console.log(response); |
|
| 169 | ||
| 170 |
// we need to reset the label counts |
|
| 171 |
jQuery( '.sortable' ).each(function(i) {
|
|
| 172 |
jQuery(this).find('span').text('Option ' + ( i + 1 ) + ':');
|
|
| 173 |
}); |
|
| 174 |
}); |
|
| 175 | ||
| 176 |
} |
|
| 177 |
}).disableSelection().css( 'cursor', 'move' ); |
|
| 178 | ||
| 153 | 179 |
// tabs init with a custom tab template and an "add" callback filling in the content |
| 154 | 180 |
var $tab_items; |
| 155 | 181 |
var $tabs = jQuery( '#tabs' ).tabs(); |
| bp-xprofile/bp-xprofile-admin.php (working copy) | ||
|---|---|---|
| 352 | 352 |
add_action( 'wp_ajax_xprofile_reorder_fields', 'xprofile_ajax_reorder_fields' ); |
| 353 | 353 | |
| 354 | 354 |
/** |
| 355 |
* Handles the ajax reordering of options within a field |
|
| 356 |
*/ |
|
| 357 |
function xprofile_ajax_reorder_field_options() {
|
|
| 358 |
global $wpdb, $bp; |
|
| 359 | ||
| 360 |
// Check the nonce |
|
| 361 |
// check_admin_referer( 'bp_reorder_field_options', '_wpnonce_reorder_field_options' ); |
|
| 362 | ||
| 363 |
if ( empty( $_POST['option_order'] ) ) |
|
| 364 |
return false; |
|
| 365 | ||
| 366 |
parse_str( $_POST['option_order'], $order ); |
|
| 367 | ||
| 368 |
foreach ( (array) $order['option'] as $position => $option_id ) {
|
|
| 369 |
$wpdb->query( |
|
| 370 |
$wpdb->prepare( |
|
| 371 |
"UPDATE {$bp->profile->table_name_fields}
|
|
| 372 |
SET option_order = $position |
|
| 373 |
WHERE id = $option_id" |
|
| 374 |
) |
|
| 375 |
); |
|
| 376 |
} |
|
| 377 |
} |
|
| 378 |
add_action( 'wp_ajax_xprofile_reorder_field_options', 'xprofile_ajax_reorder_field_options' ); |
|
| 379 | ||
| 380 |
/** |
|
| 355 | 381 |
* Handles the reordering of field groups |
| 356 | 382 |
*/ |
| 357 | 383 |
function xprofile_ajax_reorder_field_groups() {
|
| bp-xprofile/bp-xprofile-classes.php (working copy) | ||
|---|---|---|
| 739 | 739 | |
| 740 | 740 |
<div id="<?php echo $type; ?>" class="options-box" style="<?php echo $class; ?> margin-left: 15px;"> |
| 741 | 741 |
<h4><?php _e( 'Please enter options for this Field:', 'buddypress' ); ?></h4> |
| 742 |
<p><label for="sort_order_<?php echo $type; ?>"><?php _e( 'Order By:', 'buddypress' ); ?></label>
|
|
| 742 |
<p><label for="sort_order_<?php echo $type; ?>"><?php _e( 'Sort Order:', 'buddypress' ); ?></label>
|
|
| 743 | 743 |
<select name="sort_order_<?php echo $type; ?>" id="sort_order_<?php echo $type; ?>" > |
| 744 |
<option value="default" <?php if ( 'default' == $this->order_by ) {?> selected="selected"<?php } ?> ><?php _e( 'Order Entered', 'buddypress' ); ?></option>
|
|
| 745 |
<option value="asc" <?php if ( 'asc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Ascending', 'buddypress' ); ?></option>
|
|
| 746 |
<option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ); ?></option>
|
|
| 744 |
<option value="default" <?php if ( 'default' == $this->order_by ) {?> selected="selected"<?php } ?> ><?php _e( 'Custom', 'buddypress' ); ?></option>
|
|
| 745 |
<option value="asc" <?php if ( 'asc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Ascending', 'buddypress' ); ?></option>
|
|
| 746 |
<option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Descending', 'buddypress' ); ?></option>
|
|
| 747 | 747 |
</select> |
| 748 | 748 | |
| 749 | 749 |
<?php if ( !$options = $this->get_children( true ) ) {
|
| ... | ... | |
| 767 | 767 |
if ( 'multiselectbox' == $type || 'checkbox' == $type ) |
| 768 | 768 |
$default_name = '[' . $j . ']'; ?> |
| 769 | 769 | |
| 770 |
<p><?php _e( 'Option', 'buddypress' ); ?> <?php echo $j; ?>: |
|
| 771 |
<input type="text" name="<?php echo $type; ?>_option[<?php echo $j; ?>]" id="<?php echo $type; ?>_option<?php echo $j; ?>" value="<?php echo stripslashes( esc_attr( $options[$i]->name ) ); ?>" /> |
|
| 772 |
<input type="<?php echo $default_input; ?>" name="isDefault_<?php echo $type; ?>_option<?php echo $default_name; ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j; ?>" /> <?php _e( 'Default Value', 'buddypress' ); ?>
|
|
| 770 |
<p class="sortable" id="option_<?php echo $options[$i]->id; ?>"> |
|
| 771 |
<span><?php _e( 'Option', 'buddypress' ); ?> <?php echo $j; ?>:</span> |
|
| 772 |
<input type="text" name="<?php echo $type; ?>_option[<?php echo $j; ?>]" id="<?php echo $type; ?>_option<?php echo $j; ?>" value="<?php echo stripslashes( esc_attr( $options[$i]->name ) ); ?>" /> |
|
| 773 |
<input type="<?php echo $default_input; ?>" name="isDefault_<?php echo $type; ?>_option<?php echo $default_name; ?>" <?php if ( (int) $options[$i]->is_default_option ) {?> checked="checked"<?php } ?> " value="<?php echo $j; ?>" /> <?php _e( 'Default Value', 'buddypress' ); ?>
|
|
| 773 | 774 | |
| 774 | 775 |
<?php if ( $j != 1 && $options[$i]->id != -1 ) : ?> |
| 775 | 776 | |