Skip to:
Content

BuddyPress.org

Ticket #3778: custom-order-profile-options-REV1.diff

File custom-order-profile-options-REV1.diff, 8.2 KB (added by humanshell, 14 years ago)
  • bp-xprofile/bp-xprofile-classes.php

     
    737737
    738738                        <div id="<?php echo $type; ?>" class="options-box" style="<?php echo $class; ?> margin-left: 15px;">
    739739                                <h4><?php _e( 'Please enter options for this Field:', 'buddypress' ); ?></h4>
    740                                 <p><label for="sort_order_<?php echo $type; ?>"><?php _e( 'Order By:', 'buddypress' ); ?></label>
     740                                <p><label for="sort_order_<?php echo $type; ?>"><?php _e( 'Sort Order:', 'buddypress' ); ?></label>
    741741                                        <select name="sort_order_<?php echo $type; ?>" id="sort_order_<?php echo $type; ?>" >
    742                                                 <option value="default" <?php if ( 'default' == $this->order_by ) {?> selected="selected"<?php } ?> ><?php _e( 'Order Entered', 'buddypress' ); ?></option>
    743                                                 <option value="asc" <?php if ( 'asc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Ascending', 'buddypress' ); ?></option>
    744                                                 <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Name - Descending', 'buddypress' ); ?></option>
     742                                                <option value="custom" <?php if ( 'custom' == $this->order_by ) {?> selected="selected"<?php } ?> ><?php _e( 'Custom', 'buddypress' ); ?></option>
     743                                                <option value="asc" <?php if ( 'asc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Ascending', 'buddypress' ); ?></option>
     744                                                <option value="desc" <?php if ( 'desc' == $this->order_by ) {?> selected="selected"<?php } ?>><?php _e( 'Descending', 'buddypress' ); ?></option>
    745745                                        </select>
    746746
    747747                                <?php if ( !$options = $this->get_children( true ) ) {
    … …  
    765765                                                if ( 'multiselectbox' == $type || 'checkbox' == $type )
    766766                                                        $default_name = '[' . $j . ']'; ?>
    767767
    768                                                 <p><?php _e( 'Option', 'buddypress' ); ?> <?php echo $j; ?>:
    769                                                    <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 ) ); ?>" />
    770                                                    <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' ); ?>
    771 
    772                                                         <?php if ( $j != 1 && $options[$i]->id != -1 ) : ?>
    773 
    774                                                                 <a href="admin.php?page=bp-profile-setup&amp;mode=delete_option&amp;option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id; ?>">[x]</a>
    775 
    776                                                         <?php endif; ?>
    777 
     768                                                <p class="sortable">
     769                                                        <span>&nbsp;&Xi;&nbsp;</span>
     770                                                  <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 ) ); ?>" />
     771                                                  <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; ?>" />
     772                                                  <span><?php _e( 'Default Value', 'buddypress' ); ?></span>
     773                                                        <a href="admin.php?page=bp-profile-setup&amp;mode=delete_option&amp;option_id=<?php echo $options[$i]->id ?>" class="ajax-option-delete" id="delete-<?php echo $options[$i]->id; ?>">[x]</a>
    778774                                                </p>
    779775
    780776                                        <?php } /* end for */ ?>
    … …  
    786782                                        if ( 'multiselectbox' == $type || 'checkbox' == $type )
    787783                                                $default_name = '[1]'; ?>
    788784
    789                                         <p><?php _e( 'Option', 'buddypress' ); ?> 1: <input type="text" name="<?php echo $type; ?>_option[1]" id="<?php echo $type; ?>_option1" />
    790                                         <input type="<?php echo $default_input; ?>" name="isDefault_<?php echo $type; ?>_option<?php echo $default_name; ?>" id="isDefault_<?php echo $type; ?>_option" value="1" /> <?php _e( 'Default Value', 'buddypress' ); ?>
    791                                         <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="2" />
     785                                        <p class="sortable">
     786                                                <span>&nbsp;&Xi;&nbsp;</span>
     787                                                <input type="text" name="<?php echo $type; ?>_option[1]" id="<?php echo $type; ?>_option1" />
     788                                                <input type="<?php echo $default_input; ?>" name="isDefault_<?php echo $type; ?>_option<?php echo $default_name; ?>" id="isDefault_<?php echo $type; ?>_option" value="1" />
     789                                                <span><?php _e( 'Default Value', 'buddypress' ); ?></span>
     790                                                <input type="hidden" name="<?php echo $type; ?>_option_number" id="<?php echo $type; ?>_option_number" value="2" />
     791                                        </p>
    792792
    793793                                <?php } /* end if */ ?>
    794794
  • bp-xprofile/admin/js/admin.dev.js

     
    33        var theId     = document.getElementById(forWhat + '_option_number').value;
    44        var newDiv    = document.createElement('p');
    55        var newOption = document.createElement('input');
    6         var label     = document.createElement( 'label' );
    7         var txt       = document.createTextNode( "Option " + theId + ": " );
     6        var span     = document.createElement( 'span' );
     7        var txt       = document.createTextNode( "\u00A0\u039E\u00A0" );
    88        var isDefault = document.createElement( 'input' );
    9         var label1    = document.createElement( 'label' );
     9        var span1    = document.createElement( 'span' );
    1010        var txt1      = document.createTextNode( " Default Value " );
    1111
    1212        newDiv.setAttribute('id', forWhat + '_div' + theId);
     13        newDiv.setAttribute('class', 'sortable');
    1314       
    1415        newOption.setAttribute( 'type', 'text' );
    1516        newOption.setAttribute( 'name', forWhat + '_option[' + theId + ']' );
    1617        newOption.setAttribute( 'id', forWhat + '_option' + theId );
    1718
    18         label.setAttribute( 'for', forWhat + '_option' + theId );
    19         label.appendChild( txt );
     19        span.appendChild( txt );
    2020
    2121        if ( forWhat == 'checkbox' || forWhat == 'multiselectbox' ) {
    2222                isDefault.setAttribute( 'type', 'checkbox' );
    … …  
    2828
    2929        isDefault.setAttribute( 'value', theId );
    3030
    31         label1.appendChild( txt1 );
    32         label1.setAttribute( 'for', 'isDefault_' + forWhat + '_option[]' );
     31        span1.appendChild( txt1 );
    3332
    3433        var toDelete     = document.createElement( 'a' );
    3534        var toDeleteText = document.createTextNode( '[x]' );
    … …  
    3837        toDelete.setAttribute( 'class', 'delete' );
    3938        toDelete.appendChild( toDeleteText );
    4039
    41         newDiv.appendChild( label );
     40        newDiv.appendChild( span );
    4241        newDiv.appendChild( newOption );
    4342        newDiv.appendChild( document.createTextNode( " " ) );
    4443        newDiv.appendChild( isDefault );
    45         newDiv.appendChild( label1 );
     44        newDiv.appendChild( span1 );
    4645        newDiv.appendChild( toDelete );
    4746        holder.appendChild( newDiv );
    4847
     48        // re-initialize the sorable ui
     49        enableSortableFieldOptions( forWhat );
    4950
    5051        theId++;
    5152
    … …  
    8586        return ui;
    8687};
    8788
    88 // Set up deleting options ajax
     89function enableSortableFieldOptions( forWhat ) {
     90        if ( jQuery( '#' + forWhat + ' p.sortable' ).length > 1 ) {
     91                jQuery( '.options-box' ).sortable( {
     92                        items: 'p.sortable',
     93                        tolerance: 'pointer',
     94                        axis: 'y',
     95                        handle: 'span'
     96                });
     97
     98                jQuery( '.sortable span' ).css( 'cursor', 'move' );
     99        }
     100}
     101
     102function destroySortableFieldOptions() {
     103        jQuery( '.options-box' ).sortable( 'destroy' );
     104        jQuery( '.sortable span' ).css( 'cursor', 'default' );
     105}
     106
    89107jQuery( document ).ready( function() {
    90108
     109        // Set up deleting options ajax
    91110        jQuery( 'a.ajax-option-delete' ).click(
    92111                function() {
    93112                        var theId = this.id.split( '-' );
    … …  
    103122                }
    104123        );
    105124
     125        //
     126        jQuery( '[id^="sort_order_"]' ).change(function() {
     127                if ( jQuery( this ).val() != 'custom' ) {
     128                        destroySortableFieldOptions();
     129                } else {
     130                        enableSortableFieldOptions( jQuery('#fieldtype :selected').val() );
     131                }
     132        });
     133
    106134        // Show object if JS is enabled
    107135        jQuery( 'ul#field-group-tabs' ).show();
    108136
    … …  
    150178        // Change cursor to move if JS is enabled
    151179        .css( 'cursor', 'move' );
    152180
     181        // Allow reordering of field options
     182        enableSortableFieldOptions( jQuery('#fieldtype :selected').val() );
     183
    153184        // tabs init with a custom tab template and an "add" callback filling in the content
    154185        var $tab_items;
    155186        var $tabs = jQuery( '#tabs' ).tabs();