Skip to:
Content

BuddyPress.org

Changeset 1798


Ignore:
Timestamp:
09/06/2009 01:07:21 AM (17 years ago)
Author:
apeatling
Message:

Added profile field re-ordering

Location:
trunk/bp-xprofile
Files:
5 added
1 deleted
4 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/bp-xprofile/admin/css/admin.css

    r1366 r1798  
     1table.field-group tbody {
     2        cursor: move;
     3}
     4        table.field-group tbody tr.nodrag {
     5                cursor: default !important;
     6        }
     7
     8table.field-group tbody tr:hover {
     9        background-color: #fffee9;
     10}
     11       
    112tr.header td {
    213        border-bottom: 2px solid #eee;
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r1643 r1798  
    4242                <p><?php _e('NOTE: Any fields in the first group will appear on the signup page.', 'buddypress'); ?></p>
    4343               
    44                 <?php
    45                         if ( $message != '' ) {
    46                                 $type = ( $type == 'error' ) ? 'error' : 'updated';
    47                 ?>
    48                         <div id="message" class="<?php echo $type; ?> fade">
    49                                 <p><?php echo wp_specialchars( $message ); ?></p>
    50                         </div>
    51                 <?php }
    52                
    53                 if ( $groups ) { ?>
    54                         <?php
    55                         for ( $i = 0; $i < count($groups); $i++ ) { // TODO: foreach
     44                <form action="" id="profile-field-form" method="post">
     45                       
     46                        <?php wp_nonce_field( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); ?>
     47                                       
     48                        <?php
     49                                if ( $message != '' ) {
     50                                        $type = ( $type == 'error' ) ? 'error' : 'updated';
    5651                        ?>
    57                                 <p>
    58                                 <table id="group_<?php echo $groups[$i]->id;?>" class="widefat">
    59                                         <thead>
    60                                             <tr class="nodrag">
    61                                                 <th scope="col" colspan="<?php if ( $groups[$i]->can_delete ) { ?>3<?php } else { ?>5<?php } ?>"><?php echo $groups[$i]->name; ?></th>
    62                                                         <?php if ( $groups[$i]->can_delete ) { ?>       
    63                                                                 <th scope="col"><a class="edit" href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;mode=edit_group&amp;group_id=<?php echo $groups[$i]->id; ?>"><?php _e( 'Edit', 'buddypress' ) ?></a></th>
    64                                                         <th scope="col"><a class="delete" href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;mode=delete_group&amp;group_id=<?php echo $groups[$i]->id; ?>"><?php _e( 'Delete', 'buddypress' ) ?></a></th>
     52                                <div id="message" class="<?php echo $type; ?> fade">
     53                                        <p><?php echo wp_specialchars( attribute_escape( $message ) ); ?></p>
     54                                </div>
     55                        <?php }
     56               
     57                        if ( $groups ) { ?>
     58                                <?php
     59                                for ( $i = 0; $i < count($groups); $i++ ) { // TODO: foreach
     60                                ?>
     61                                        <p>
     62                                        <table id="group_<?php echo $groups[$i]->id;?>" class="widefat field-group">
     63                                                <thead>
     64                                                    <tr>
     65                                                                <th scope="col">&nbsp;</th>
     66                                                        <th scope="col" colspan="<?php if ( $groups[$i]->can_delete ) { ?>3<?php } else { ?>5<?php } ?>"><?php echo attribute_escape( $groups[$i]->name ); ?></th>
     67                                                                <?php if ( $groups[$i]->can_delete ) { ?>       
     68                                                                        <th scope="col"><a class="edit" href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;mode=edit_group&amp;group_id=<?php echo attribute_escape( $groups[$i]->id ); ?>"><?php _e( 'Edit', 'buddypress' ) ?></a></th>
     69                                                                <th scope="col"><a class="delete" href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;mode=delete_group&amp;group_id=<?php echo attribute_escape( $groups[$i]->id ); ?>"><?php _e( 'Delete', 'buddypress' ) ?></a></th>
     70                                                                <?php } ?>
     71                                                        </tr>
     72                                                        <tr class="header">
     73                                                                <td>&nbsp;</td>
     74                                                        <td><?php _e( 'Field Name', 'buddypress' ) ?></td>
     75                                                        <td width="14%"><?php _e( 'Field Type', 'buddypress' ) ?></td>
     76                                                        <td width="6%"><?php _e( 'Required?', 'buddypress' ) ?></td>
     77                                                        <td colspan="2" width="10%" style="text-align:center;"><?php _e( 'Action', 'buddypress' ) ?></td>
     78                                                    </tr>
     79                                                </thead>
     80                                                <tbody id="the-list">
     81                                               
     82                                                  <?php if ( $groups[$i]->fields ) { ?>
     83                                                       
     84                                                        <?php for ( $j = 0; $j < count($groups[$i]->fields); $j++ ) { ?>
     85                                               
     86                                                                        <?php if ( 0 == $j % 2 ) { $class = ""; } else { $class = "alternate"; } ?>         
     87                                                                        <?php $field = new BP_XProfile_Field($groups[$i]->fields[$j]->id); ?>
     88                                                                        <?php if ( !$field->can_delete ) { $class .= ' core'; } ?>
     89                                                       
     90                                                                        <tr id="field_<?php echo attribute_escape( $field->id ); ?>" class="sortable<?php if ( $class ) { echo ' ' . $class; } ?>">
     91                                                                        <td width="10"><img src="<?php echo BP_PLUGIN_URL ?>/bp-xprofile/admin/images/move.gif" alt="<?php _e( 'Drag', 'buddypress' ) ?>" /></td>
     92                                                                                <td><span title="<?php echo $field->desc; ?>"><?php echo attribute_escape( $field->name ); ?> <?php if(!$field->can_delete) { ?>(Core)<?php } ?></span></td>
     93                                                                        <td><?php echo attribute_escape( $field->type ); ?></td>
     94                                                                        <td style="text-align:center;"><?php if ( $field->is_required ) { echo '<img src="' . BP_PLUGIN_URL . '/bp-xprofile/admin/images/tick.gif" alt="' . __( 'Yes', 'buddypress' ) . '" />'; } else { ?>--<?php } ?></td>
     95                                                                        <td style="text-align:center;"><?php if ( !$field->can_delete ) { ?><strike><?php _e( 'Edit', 'buddypress' ) ?></strike><?php } else { ?><a class="edit" href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;group_id=<?php echo attribute_escape( $groups[$i]->id ); ?>&amp;field_id=<?php echo attribute_escape( $field->id ); ?>&amp;mode=edit_field"><?php _e( 'Edit', 'buddypress' ) ?></a><?php } ?></td>
     96                                                                        <td style="text-align:center;"><?php if ( !$field->can_delete ) { ?><strike><?php _e( 'Delete', 'buddypress' ) ?></strike><?php } else { ?><a class="delete" href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;field_id=<?php echo attribute_escape( $field->id ); ?>&amp;mode=delete_field"><?php _e( 'Delete', 'buddypress' ) ?></a><?php } ?></td>
     97                                                                    </tr>
     98                                                       
     99                                                                <?php } ?>
     100                                                       
     101                                                        <?php } else { ?>
     102                                                       
     103                                                                <tr class="nodrag">
     104                                                                        <td colspan="6"><?php _e( 'There are no fields in this group.', 'buddypress' ) ?></td>
     105                                                                </tr>
     106                                                       
    65107                                                        <?php } ?>
    66                                                 </tr>
    67                                         </thead>
    68                                         <tbody id="the-list">
    69                                            <tr class="header nodrag">
    70                                                 <td><?php _e( 'Field Name', 'buddypress' ) ?></td>
    71                                                 <td width="14%"><?php _e( 'Field Type', 'buddypress' ) ?></td>
    72                                                 <td width="6%"><?php _e( 'Required?', 'buddypress' ) ?></td>
    73                                                 <td colspan="2" width="10%" style="text-align:center;"><?php _e( 'Action', 'buddypress' ) ?></td>
    74                                             </tr>
    75 
    76                                                   <?php if ( $groups[$i]->fields ) { ?>
    77                                                 <?php for ( $j = 0; $j < count($groups[$i]->fields); $j++ ) { ?>
    78                                                                         <?php if ( 0 == $j % 2 ) { $class = ""; } else { $class = "alternate"; } ?>
    79                                                             <?php $field = new BP_XProfile_Field($groups[$i]->fields[$j]->id); ?>
    80                                                             <?php if ( !$field->can_delete ) { $class .= ' core'; } ?>
    81                                                        
    82                                                                         <tr id="field_<?php echo $field->id; ?>" <?php if ( $class ) { echo 'class="' . $class . '"'; } ?>>
    83                                                                 <td><span title="<?php echo $field->desc; ?>"><?php echo $field->name; ?> <?php if(!$field->can_delete) { ?>(Core)<?php } ?></span></td>
    84                                                                 <td><?php echo $field->type; ?></td>
    85                                                                 <td style="text-align:center;"><?php if ( $field->is_required ) { echo '<img src="' . $bp->profile->image_base . '/tick.gif" alt="' . _e( 'Yes', 'buddypress' ) . '" />'; } else { ?>--<?php } ?></td>
    86                                                                 <td style="text-align:center;"><?php if ( !$field->can_delete ) { ?><strike><?php _e( 'Edit', 'buddypress' ) ?></strike><?php } else { ?><a class="edit" href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;group_id=<?php echo $groups[$i]->id; ?>&amp;field_id=<?php echo $field->id; ?>&amp;mode=edit_field"><?php _e( 'Edit', 'buddypress' ) ?></a><?php } ?></td>
    87                                                                 <td style="text-align:center;"><?php if ( !$field->can_delete ) { ?><strike><?php _e( 'Delete', 'buddypress' ) ?></strike><?php } else { ?><a class="delete" href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;field_id=<?php echo $field->id; ?>&amp;mode=delete_field"><?php _e( 'Delete', 'buddypress' ) ?></a><?php } ?></td>
    88                                                             </tr>
    89                                                        
    90                                                         <?php } ?>
    91                                                 <?php } else { ?>
    92                                                         <tr class="nodrag">
    93                                                                 <td colspan="6"><?php _e( 'There are no fields in this group.', 'buddypress' ) ?></td>
    94                                                         </tr>
    95                                                 <?php } ?>
    96                                                         <tr class="nodrag">
    97                                                                 <td colspan="6"><a href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;group_id=<?php echo $groups[$i]->id; ?>&amp;mode=add_field"><?php _e( 'Add New Field', 'buddypress' ) ?></a></td>
    98                                                         </tr>
    99                                         </tbody>
    100                                 </table>
    101                                 </p>
    102                                
    103                         <?php } /* End For */ ?>
    104                        
    105                                 <p>
    106                                         <a href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;mode=add_group"><?php _e( 'Add New Group', 'buddypress' ) ?></a>
    107                                 </p>
    108                                
    109                 <?php } else { ?>
    110                         <div id="message" class="error"><p><?php _e('You have no groups.', 'buddypress' ); ?></p></div>
    111                         <p><a href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;mode=add_group"><?php _e( 'Add New Group', 'buddypress' ) ?></a></p>
    112                 <?php } ?>
     108                                       
     109                                                </tbody>
     110                                       
     111                                                <tfoot>
     112                                               
     113                                                                <tr class="nodrag">
     114                                                                        <td colspan="6"><a href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;group_id=<?php echo attribute_escape( $groups[$i]->id ); ?>&amp;mode=add_field"><?php _e( 'Add New Field', 'buddypress' ) ?></a></td>
     115                                                                </tr>
     116                                               
     117                                                </tfoot>
     118                                       
     119                                        </table>
     120                                        </p>
     121                               
     122                                <?php } /* End For */ ?>
     123                       
     124                                        <p>
     125                                                <a class="button" href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;mode=add_group"><?php _e( 'Add New Field Group', 'buddypress' ) ?></a>
     126                                        </p>
     127                               
     128                        <?php } else { ?>
     129                                <div id="message" class="error"><p><?php _e('You have no groups.', 'buddypress' ); ?></p></div>
     130                                <p><a href="admin.php?page=<?php echo BP_PLUGIN_DIR ?>/bp-xprofile.php&amp;mode=add_group"><?php _e( 'Add New Group', 'buddypress' ) ?></a></p>
     131                        <?php } ?>
     132               
     133                </form>
     134               
    113135        </div>
    114136<?php
     
    255277        xprofile_admin($message, $type);
    256278}
     279
     280function xprofile_ajax_reorder_fields() {
     281        global $bp;
     282       
     283        /* Check the nonce */
     284        check_admin_referer( 'bp_reorder_fields', '_wpnonce_reorder_fields' );
     285       
     286        if ( empty( $_POST['field_order'] ) )
     287                return false;
     288       
     289        parse_str($_POST['field_order'], $order );
     290
     291        foreach ( (array) $order['field'] as $position => $field_id ) {
     292                xprofile_update_field_position( (int) $field_id, (int) $position );
     293        }
     294}
     295add_action( 'wp_ajax_xprofile_reorder_fields', 'xprofile_ajax_reorder_fields' );
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r1728 r1798  
    8282
    8383                // Get field ids for the current group.
    84                 if ( !$fields = $wpdb->get_results( $wpdb->prepare("SELECT id, type FROM {$bp->profile->table_name_fields} WHERE group_id = %d AND parent_id = 0 ORDER BY id", $this->id ) ) )
     84                if ( !$fields = $wpdb->get_results( $wpdb->prepare("SELECT id, type FROM {$bp->profile->table_name_fields} WHERE group_id = %d AND parent_id = 0 ORDER BY field_order", $this->id ) ) )
    8585                        return false;
    8686               
     
    128128
    129129                if ( !$this->id ) {
    130                         $title = __('Add Group', 'buddypress');
     130                        $title = __('Add New Field Group', 'buddypress');
    131131                        $action = "admin.php?page=" . BP_PLUGIN_DIR . "/bp-xprofile.php&amp;mode=add_group";
    132132                } else {
    133                         $title = __('Edit Group', 'buddypress');
     133                        $title = __('Edit Field Group', 'buddypress');
    134134                        $action = "admin.php?page=" . BP_PLUGIN_DIR . "/bp-xprofile.php&amp;mode=edit_group&amp;group_id=" . $this->id;                 
    135135                }
     
    152152                               
    153153                                <div id="titlediv">
    154                                         <label for="group_name"><?php _e("Profile Group Name", 'buddypress') ?></label>
     154                                        <label for="group_name"><?php _e( "Field Group Name", 'buddypress') ?></label>
    155155                                        <div>
    156156                                                <input type="text" name="group_name" id="group_name" value="<?php echo attribute_escape( $this->name ) ?>" style="width:50%" />
     
    372372                $wpdb->query($sql);
    373373        }
     374       
     375        // Static Functions
    374376               
    375377        function get_type( $field_id ) {
     
    411413               
    412414                return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", $field_name ) );
     415        }
     416       
     417        function update_position( $field_id, $position ) {
     418                global $wpdb, $bp;
     419               
     420                if ( !is_numeric( $position ) )
     421                        return false;
     422               
     423                return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET field_order = %d WHERE id = %d", $position, $field_id ) );
    413424        }
    414425       
  • trunk/bp-xprofile/bp-xprofile-cssjs.php

    r1636 r1798  
    22
    33function xprofile_add_admin_css() {
     4        wp_enqueue_style( 'xprofile-admin-css', BP_PLUGIN_URL . '/bp-xprofile/admin/css/admin.css' );
     5}
     6add_action( 'admin_menu', 'xprofile_add_admin_css' );
     7
     8function xprofile_add_admin_js() {
    49        if ( strpos( $_GET['page'], 'xprofile' ) !== false ) {
    5                 echo '<link rel="stylesheet" href="' . BP_PLUGIN_URL . '/bp-xprofile/css/admin.css' . '" type="text/css" />';
     10                wp_enqueue_script( array( "jquery-ui-sortable" ) );
     11                wp_enqueue_script( 'xprofile-admin-js', BP_PLUGIN_URL . '/bp-xprofile/admin/js/admin.js', array( 'jquery' ) );
    612        }
    713}
    8 add_action( 'admin_head', 'xprofile_add_admin_css' );
    9 
    10 function xprofile_add_admin_js() {
    11         if ( strpos( $_GET['page'], 'xprofile' ) !== false )
    12                 echo '<script type="text/javascript" src="' . BP_PLUGIN_URL . '/bp-xprofile/js/admin.js' . '"></script>';
    13 }
    14 add_action( 'admin_head', 'xprofile_add_admin_js' );
     14add_action( 'admin_menu', 'xprofile_add_admin_js', 1 );
    1515
    1616?>
Note: See TracChangeset for help on using the changeset viewer.