Skip to:
Content

BuddyPress.org

Changeset 2883


Ignore:
Timestamp:
03/29/2010 12:08:14 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Major XProfile UI upgrade. Add abilities to reorder field groups and move fields between groups. Core field and group names have been moved out of General Settings and into their respective Edit actions. Still some old code clean up to do.

Location:
trunk/bp-xprofile
Files:
4 added
1 deleted
6 edited

Legend:

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

    r2812 r2883  
    11/* Profile field group main admin page */
    2 table.field-group {
    3     margin-bottom: 20px;
    4     background-color: #fafafa;
    5     }
    6     table.field-group.ui-sortable-placeholder {
    7         border: 2px dashed #ddd;
     2#tabs {
     3    position: relative;
     4    }
     5    p.nofields {
     6        margin-top: 20px;
     7    }
     8
     9    /* Field group tabs */
     10    ul#field-group-tabs {
     11        float: left;
     12        padding: 0 0 0 15px;
     13        display: block;
     14    }
     15        ul#field-group-tabs li {
     16            float: left;
     17            margin-bottom: -1px;
     18            background-color: #F7F6F1;
     19            margin-right: 8px;
     20        }
     21        ul#field-group-tabs li.ui-state-hover {
     22            background-color: #fafafa;
     23        }
     24        ul#field-group-tabs li.ui-state-hover a.ui-tab {
     25            border-color: #bbb #bbb #ccc #bbb;
     26            color: #888;
     27        }
     28        ul#field-group-tabs li.ui-state-acceptable a.ui-tab {
     29            border-color: #5a5 #5a5 #ccc #5a5;
     30            color: #8a8;
     31            background-image: url(../images/plus.gif);
     32            background-color: #efe;
     33        }
     34            ul#field-group-tabs li.ui-tabs-selected.ui-state-acceptable a.ui-tab {
     35                background-color: #fff;
     36                background-image: url(../images/cross.gif);
     37            }
     38        ul#field-group-tabs li.drop-candidate a.ui-tab {
     39            background-color: #ffc;
     40            border-color: #aa5 #aa5 #ccc #aa5;
     41            color: #aa8;
     42        }
     43        ul#field-group-tabs li a.ui-tab {
     44            display: block;
     45            margin-top: 3px;
     46            padding: 8px 10px 8px 28px;
     47            border: 1px solid #ccc;
     48            border-bottom: none;
     49            -moz-border-radius: 5px 5px 0 0;
     50            -khtml-border-radius: 5px 5px 0 0;
     51            -webkit-border-radius: 5px 5px 0 0;
     52            border-radius: 5px 5px 0 0;
     53            text-decoration: none;
     54            background: url(../images/move-x.gif) 7px 55% no-repeat;
     55            color: #888;
     56        }
     57
     58        /* Selected tab */
     59        ul#field-group-tabs li.ui-tabs-selected {
     60            background-color: #fff;
     61        }
     62        ul#field-group-tabs li.ui-tabs-selected a.ui-tab {
     63            margin-top: -1px;
     64            padding: 10px 10px 10px 28px;
     65            border: 1px solid #bbb;
     66            border-bottom: 1px solid transparent;
     67            color: #000;
     68            font-weight: bold;
     69        }
     70
     71    /* Toolbar */
     72    .tab-toolbar {
     73        margin-top: 1px;
     74        clear: left;
     75        background-color: #fff;
     76        padding: 10px;
     77        border: 1px solid #bbb;
     78    }
     79
     80    div.tab-wrapper {
     81        clear: left;
     82    }
     83
     84    .tab-wrapper fieldset {
     85        border: 1px solid #ddd;
     86        -moz-border-radius: 5px;
     87        -khtml-border-radius: 5px;
     88        -webkit-border-radius: 5px;
     89        border-radius: 5px;
     90        padding: 0 10px 10px;
     91        margin: 10px 0 0 0;
     92        position: relative;
     93        background-color: #fff;
     94    }
     95    .tab-wrapper fieldset fieldset {
     96        cursor: move;
     97        padding: 10px 10px 20px 10px;
     98        background-color: #fcfcfc;
     99    }
     100        .field-group fieldset:hover {
     101            background-color: #fafafa;
     102            border-color: #ccc;
     103        }
     104        fieldset div.field-wrapper {
     105            padding-left: 30px;
     106            background: url(../images/move.gif) 0px 3px no-repeat transparent;
     107        }
     108    fieldset.radio div div,
     109    fieldset.checkbox div div {
     110        float: left;
     111    }
     112    fieldset.radio div div label,
     113    fieldset.checkbox div div label {
     114        margin-right: 20px;
     115    }
     116
     117    fieldset.clear-value {
     118        margin-left: 10px;
     119    }
     120    .field-group div.actions {
     121        display: none;
     122        position: absolute;
     123        right: 20px;
     124        top: 0;
     125    }
     126    .field-group fieldset:hover div.actions {
     127        display: block;
     128    }
     129    .field-group fieldset.ui-sortable-placeholder {
     130        border: 1px dashed #999;
     131        background-color: #eee;
    8132        visibility: visible !important;
    9         background-color: transparent;
    10         width: 100%;
    11         margin-bottom: 20px;
    12     }
    13     table.field-group thead tr.grabber,
    14     table.field-group tbody {
    15         cursor: move;
    16     }
    17     table.field-group tbody tr.nodrag {
    18         cursor: default !important;
    19     }
    20     table.field-group tbody tr.ui-sortable-placeholder {
    21         visibility: visible !important;
    22         display: block !important;
    23         background-color: #fafafa;
    24     }
    25     table.field-group td {
    26         background-color: #fff;
    27     }
    28     table.field-group tbody tr:hover td {
    29         background-color: #fffee9;
    30     }
    31     table.field-group tbody tr.nodrag:hover td {
    32         background-color: #fff;
    33     }
    34    
    35 tr.header td {
    36     border-bottom: 1px solid #eee;
    37     background-color: #fafafa;
    38     font-weight: bold;
    39     padding: 5px 6px;
    40 }
    41 
    42 tr.core td {
    43     color: #999;
    44 }
    45 tr td.center, tr th.center {
    46     text-align: center;
    47 }
    48 
    49 thead tr th {
    50     font-size: 16px;
    51 }
     133    }
    52134
    53135    ul.forTab {
  • trunk/bp-xprofile/admin/js/admin.js

    r2812 r2883  
    9898});
    9999
    100 var fixHelper = function(e, ui) {
    101     ui.children().each(function() {
    102         jQuery(this).width( jQuery(this).width() );
    103     });
    104     return ui;
    105 };
     100/* Main XProfile behavior layer */
     101jQuery(document).ready( function() {
    106102
    107 jQuery(document).ready( function() {
    108     jQuery("form#profile-field-form div#field-groups").sortable( {
     103    /* Allow reordering of field group tabs */
     104    jQuery( "ul#field-group-tabs" ).sortable( {
    109105        cursor: 'move',
    110         axis: 'y',
    111         helper: fixHelper,
     106        axis: 'x',
    112107        opacity: 0.6,
    113         items: 'table',
    114         cancel: 'tbody,tfoot',
     108        items: 'li',
    115109        tolerance: 'pointer',
     110
    116111        update: function() {
    117112            jQuery.post( ajaxurl, {
    118113                action: 'xprofile_reorder_groups',
    119114                'cookie': encodeURIComponent(document.cookie),
    120                 '_wpnonce_reorder_groups': jQuery("input#_wpnonce_reorder_groups").val(),
    121                 'group_order': jQuery(this).sortable('serialize')
     115                '_wpnonce_reorder_groups': jQuery( "input#_wpnonce_reorder_groups" ).val(),
     116                'group_order': jQuery(this).sortable( 'serialize' )
    122117            },
    123118            function(response){});
     
    125120    }).disableSelection();
    126121
    127     jQuery("table.field-group tbody").sortable( {
     122    /* Allow reordering of fields within groups */
     123    jQuery( "fieldset.field-group" ).sortable({
    128124        cursor: 'move',
    129         axis: 'y',
    130         helper: fixHelper,
    131         opacity: 0.6,
    132         items: 'tr',
    133         cancel: 'tr.nodrag,tr.core',
    134         connectWith: 'table.field-group tbody',
     125        opacity: 0.3,
     126        items: 'fieldset',
    135127        tolerance: 'pointer',
    136         update: function() {
     128
     129        update: function() {
    137130            jQuery.post( ajaxurl, {
    138131                action: 'xprofile_reorder_fields',
    139132                'cookie': encodeURIComponent(document.cookie),
    140                 '_wpnonce_reorder_fields': jQuery("input#_wpnonce_reorder_fields").val(),
    141                 'field_order': jQuery(this).sortable('serialize'),
    142                 'field_group_id': jQuery(this).attr('id')
     133                '_wpnonce_reorder_fields': jQuery( "input#_wpnonce_reorder_fields" ).val(),
     134                'field_order': jQuery(this).sortable( 'serialize' ),
     135                'field_group_id': jQuery(this).attr( 'id' )
    143136            },
    144137            function(response){});
     
    146139    }).disableSelection();
    147140
     141    var $tab_items;
     142   
     143    /* tabs init with a custom tab template and an "add" callback filling in the content */
     144    var $tabs = jQuery( "#tabs" ).tabs();
     145    set_tab_items( $tabs );
     146
     147    function set_tab_items( $tabs ) {
     148        $tab_items = jQuery( "ul:first li", $tabs ).droppable({
     149            accept: ".connectedSortable fieldset",
     150            hoverClass: "ui-state-hover",
     151            activeClass: "ui-state-acceptable",
     152            touch: "pointer",
     153            tolerance: "pointer",
     154
     155            /* When field is dropped on tab */
     156            drop: function( ev, ui ) {
     157                /* The tab */
     158                var $item = jQuery(this);
     159
     160                /* The tab body */
     161                var $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' );
     162
     163                /* Remove helper class */
     164                jQuery($item).removeClass( 'drop-candidate' );
     165
     166                /* Hide field, change selected tab, and show new placement */
     167                ui.draggable.hide( 'slow', function() {
     168
     169                    /* Select new tab as current */
     170                    $tabs.tabs( 'select', $tab_items.index( $item ) );
     171
     172                    /* Show new placement */
     173                    jQuery(this).appendTo($list).show( 'slow' ).animate( {opacity: "1"}, 500 );
     174
     175                    /* Refresh $list variable */
     176                    $list = jQuery( $item.find( 'a' ).attr( 'href' ) ).find( '.connectedSortable' );
     177                    jQuery($list).find( 'p.nofields' ).hide( 'slow' );
     178                });
     179
     180                jQuery.post( ajaxurl, {
     181                    action: 'xprofile_reorder_fields',
     182                    'cookie': encodeURIComponent(document.cookie),
     183                    '_wpnonce_reorder_fields': jQuery( "input#_wpnonce_reorder_fields" ).val(),
     184                    'field_order': jQuery( $list ).sortable( 'serialize' ),
     185                    'field_group_id': jQuery( $list ).attr( 'id' )
     186                },
     187                function(response){});
     188            },
     189            over: function( event, ui ) {
     190                jQuery(this).addClass( 'drop-candidate' );
     191            },
     192            out: function( event, ui ) {
     193                jQuery(this).removeClass( 'drop-candidate' );
     194            }
     195        });
     196    }
    148197});
  • trunk/bp-xprofile/bp-xprofile-admin.php

    r2813 r2883  
    4040    else {
    4141?>
     42
    4243    <div class="wrap">
    43         <h2><?php _e( 'Profile Field Setup', 'buddypress'); ?></h2>
     44        <div class="icon32" id="icon-tools"><br></div>
     45        <h2>
     46            <?php _e( 'Profile Field Setup', 'buddypress'); ?>
     47            <a id="add_group" class="button add-new-h2" href="admin.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Group', 'buddypress' ); ?></a>
     48        </h2>
    4449        <p><?php _e( 'Your users will distinguish themselves through their profile page. You must give them profile fields that allow them to describe themselves in a way that is relevant to the theme of your social network.', 'buddypress'); ?></p>
    45         <p><?php _e('NOTE: Any fields in the first group will appear on the signup page.', 'buddypress'); ?></p>
     50        <p><?php echo sprintf( __( 'NOTE: Any fields in the "%s" group will appear on the signup page.', 'buddypress' ), get_site_option( 'bp-xprofile-base-group-name' ) ); ?></p>
    4651
    4752        <form action="" id="profile-field-form" method="post">
     
    5156
    5257            if ( $message != '' ) :
    53                 $type = ( $type == 'error' ) ? 'error' : 'updated';
    54 ?>
     58                $type = ( $type == 'error' ) ? 'error' : 'updated'; ?>
    5559
    5660                <div id="message" class="<?php echo $type; ?> fade">
     
    5963<?php       endif; ?>
    6064
    61             <div id="field-groups">
     65            <div id="tabs">
     66                <ul id="field-group-tabs">
    6267<?php
    6368            if ( $groups ) :
    6469                foreach ( $groups as $group ) { ?>
    65 
    66                         <table id="group_<?php echo $group->id; ?>" class="widefat field-group sortable">
    67                             <thead>
    68                                 <tr class="grabber">
    69                                     <th scope="col" width="10"><img src="<?php echo BP_PLUGIN_URL; ?>/bp-xprofile/admin/images/move.gif" alt="<?php _e( 'Drag', 'buddypress' ); ?>" /></th>
    70                                     <th scope="col" colspan="3"><?php echo attribute_escape( $group->name ); ?></th>
    71 <?php
    72                                     if ( $group->can_delete ) :
    73 ?>
    74                                         <th scope="col" class="center"><a class="edit" href="admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=<?php echo attribute_escape( $group->id ); ?>"><?php _e( 'Edit', 'buddypress' ); ?></a></th>
    75                                         <th scope="col" class="center"><a class="delete" href="admin.php?page=bp-profile-setup&amp;mode=delete_group&amp;group_id=<?php echo attribute_escape( $group->id ); ?>"><?php _e( 'Delete', 'buddypress' ); ?></a></th>
    76 <?php
    77                                     else :
    78 ?>
    79                                         <th scope="col" class="center"><a class="edit" href="admin.php?page=bp-general-settings"><?php _e( 'Edit', 'buddypress' ); ?></a></th>
    80                                         <th scope="col" class="center">&nbsp;</th>
    81 <?php
    82                                     endif;
    83 ?>
    84 
    85                                 </tr>
    86                                 <tr class="header">
    87                                     <td>&nbsp;</td>
    88                                     <td><?php _e( 'Field Name', 'buddypress' ); ?></td>
    89                                     <td width="14%"><?php _e( 'Field Type', 'buddypress' ); ?></td>
    90                                     <td width="6%" class="center"><?php _e( 'Required?', 'buddypress' ); ?></td>
    91                                     <td colspan="2" width="10%" class="center"><?php _e( 'Actions', 'buddypress' ); ?></td>
    92                                 </tr>
    93                             </thead>
    94 
    95                             <tfoot>
    96                                 <tr class="nodrag">
    97                                     <td colspan="6"><a href="admin.php?page=bp-profile-setup&amp;group_id=<?php echo attribute_escape( $group->id ); ?>&amp;mode=add_field"><?php _e( 'Add New Field', 'buddypress' ); ?></a></td>
    98                                 </tr>
    99                             </tfoot>
    100 
    101                             <tbody id="<?php echo $group->id ?>">
    102  <?php
    103                                 if ( $group->fields ) :
    104                                     foreach ( $group->fields as $field ) {
    105                                         if ( 0 == $j % 2 )
    106                                             $class = '';
    107                                         else
    108                                             $class = 'alternate';
    109 
    110                                         $field = new BP_XProfile_Field( $field->id );
    111                                         if ( !$field->can_delete )
    112                                             $class .= ' core nodrag';
    113 ?>
    114 
    115                                         <tr id="field_<?php echo attribute_escape( $field->id ); ?>" class="sortable<?php if ( $class ) echo ' ' . $class;  ?>">
    116                                             <td width="10"><?php if ( $field->can_delete ) : ?><img src="<?php echo BP_PLUGIN_URL; ?>/bp-xprofile/admin/images/move.gif" alt="<?php _e( 'Drag', 'buddypress' ); ?>" /><?php endif; ?></td>
    117                                             <td><span title="<?php echo $field->description; ?>"><?php echo attribute_escape( $field->name ); ?> <?php if(!$field->can_delete) : ?> <?php _e( '(Core Field)', 'buddypress' ); endif; ?></span></td>
    118                                             <td><?php echo attribute_escape( $field->type ); ?></td>
    119                                             <td class="center"><?php if ( $field->is_required ) : echo '<img src="' . BP_PLUGIN_URL . '/bp-xprofile/admin/images/tick.gif" alt="' . __( 'Yes', 'buddypress' ) . '" />'; else : ?>-<?php endif; ?></td>
    120                                             <td class="center"><a class="edit" href="<?php if ( !$field->can_delete ) { ?>admin.php?page=bp-general-settings<?php } else { ?>admin.php?page=bp-profile-setup&amp;group_id=<?php echo attribute_escape( $group->id ); ?>&amp;field_id=<?php echo attribute_escape( $field->id ); ?>&amp;mode=edit_field<?php } ?>"><?php _e( 'Edit', 'buddypress' ); ?></a></td>
    121                                             <td class="center"><?php if ( !$field->can_delete ) : ?>&nbsp;<?php else : ?><a class="delete" href="admin.php?page=bp-profile-setup&amp;field_id=<?php echo attribute_escape( $field->id ); ?>&amp;mode=delete_field"><?php _e( 'Delete', 'buddypress' ); ?></a><?php endif; ?></td>
    122                                         </tr>
    123 <?php
    124                                     } /* end for */
    125 
    126                                 else : /* !$group->fields */
    127 ?>
    128 
    129                                     <tr class="nodrag">
    130                                         <td colspan="6"><?php _e( 'There are no fields in this group.', 'buddypress' ); ?></td>
    131                                     </tr>
     70                    <li id="group_<?php echo $group->id; ?>"><a href="#tabs-<?php echo $group->id; ?>" class="ui-tab"><?php echo attribute_escape( $group->name ); ?><?php if ( !$group->can_delete ) : ?> <?php _e( '(Core)', 'buddypress'); endif; ?></a></li>
     71<?php           }
     72            endif; ?>
     73                </ul>
     74
     75<?php       if ( $groups ) :
     76                foreach ( $groups as $group ) { ?>
     77
     78                    <div id="tabs-<?php echo $group->id; ?>" class="tab-wrapper">
     79                        <div class="tab-toolbar">
     80                            <div class="tab-toolbar-left">
     81                                <a class="button" href="admin.php?page=bp-profile-setup&amp;group_id=<?php echo attribute_escape( $group->id ); ?>&amp;mode=add_field"><?php _e( 'Add New Field', 'buddypress' ); ?></a>
     82                                <a class="button edit" href="admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=<?php echo attribute_escape( $group->id ); ?>"><?php _e( 'Edit Group', 'buddypress' ); ?></a>
     83<?php               if ( $group->can_delete ) : ?>
     84                                <a class="button delete" href="admin.php?page=bp-profile-setup&amp;mode=delete_group&amp;group_id=<?php echo attribute_escape( $group->id ); ?>"><?php _e( 'Delete Group', 'buddypress' ); ?></a>
     85<?php               endif; ?>
     86                            </div>
     87                        </div>
     88
     89                        <fieldset id="<?php echo $group->id; ?>" class="connectedSortable field-group">
     90<?php               if( $group->description ) : ?>
     91                            <legend><?php echo attribute_escape( $group->description ) ?></legend>
     92<?php               endif;
     93
     94                    if ( $group->fields ) :
     95                        foreach ( $group->fields as $field ) {
     96
     97                            /* Load the field */
     98                            $field = new BP_XProfile_Field( $field->id );
     99                            if ( !$field->can_delete )
     100                                $class .= ' core nodrag';
     101
     102                            /* This function handles the WYSIWYG profile field
     103                             * display for the xprofile admin setup screen
     104                             */
     105                            xprofile_admin_field( $field, $group );
     106
     107                        } /* end for */
     108
     109                    else : /* !$group->fields */
     110?>
     111
     112                            <p class="nodrag nofields"><?php _e( 'There are no fields in this group.', 'buddypress' ); ?></p>
    132113<?php
    133114                                endif; /* end $group->fields */
    134115?>
    135 
    136                             </tbody>
    137                         </table>
    138 <?php
    139                 } /* End For */ ?>
     116                        </fieldset>
    140117                    </div>
    141                     <p>
    142                         <a class="button" href="admin.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Field Group', 'buddypress' ); ?></a>
    143                     </p>
     118<?php
     119                    } /* End For */ ?>
     120                </div>
    144121<?php
    145122                else :
    146123?>
    147 
    148                 <div id="message" class="error"><p><?php _e('You have no groups.', 'buddypress' ); ?></p></div>
     124                <div id="message" class="error"><p><?php _e( 'You have no groups.', 'buddypress' ); ?></p></div>
    149125                <p><a href="admin.php?page=bp-profile-setup&amp;mode=add_group"><?php _e( 'Add New Group', 'buddypress' ); ?></a></p>
    150126<?php
    151127                endif;
    152128?>
    153 
    154         </form>
    155     </div>
     129            </form>
     130        </div>
    156131<?php
    157132    }
     
    169144    $group = new BP_XProfile_Group( $group_id );
    170145
    171     if ( isset( $_POST['saveGroup'] ) ) {
     146    if ( isset( $_POST['save_group'] ) ) {
    172147        if ( BP_XProfile_Group::admin_validate( $_POST ) ) {
    173             $group->name = wp_filter_kses( $_POST['group_name'] );
    174             $group->description = wp_filter_kses( $_POST['group_desc'] );
     148            $group->name        = wp_filter_kses( $_POST['group_name'] );
     149            $group->description = wp_filter_kses( $_POST['group_description'] );
    175150
    176151            if ( !$group->save() ) {
     
    216191    }
    217192
    218     unset( $_GET['mode'] ); /* TODO: wtf? */
     193    unset( $_GET['mode'] );
    219194    xprofile_admin( $message, $type );
    220195}
     
    242217
    243218            $field->field_order = $wpdb->get_var( $wpdb->prepare( "SELECT field_order FROM {$bp->profile->table_name_fields} WHERE id = %d", $field_id ) );
    244 
    245219            if ( !$field->field_order ) {
    246220                $field->field_order = (int) $wpdb->get_var( $wpdb->prepare( "SELECT max(field_order) FROM {$bp->profile->table_name_fields} WHERE group_id = %d", $group_id ) );
     
    278252 Handles the deletion of a profile field [or option].
    279253**************************************************************************/
    280 
    281254function xprofile_admin_delete_field( $field_id, $type = 'field' ) {
    282255    global $message, $type;
     
    303276}
    304277
     278/**************************************************************************
     279 xprofile_ajax_reorder_fields()
     280
     281 Handles the ajax reordering of fields within a group
     282**************************************************************************/
    305283function xprofile_ajax_reorder_fields() {
    306284    global $bp;
     
    321299add_action( 'wp_ajax_xprofile_reorder_fields', 'xprofile_ajax_reorder_fields' );
    322300
     301/**************************************************************************
     302 xprofile_ajax_reorder_field_groups()
     303
     304 Handles the reordering of field groups
     305**************************************************************************/
    323306function xprofile_ajax_reorder_field_groups() {
    324307    global $bp;
     
    337320}
    338321add_action( 'wp_ajax_xprofile_reorder_groups', 'xprofile_ajax_reorder_field_groups' );
     322
     323/**************************************************************************
     324 xprofile_admin_field()
     325
     326 Handles the WYSIWYG display of each profile field on the edit screen
     327**************************************************************************/
     328function xprofile_admin_field( $admin_field, $admin_group ) {
     329    global $field;
     330   
     331    $field = $admin_field;
     332?>
     333                        <fieldset id="field_<?php echo attribute_escape( $field->id ); ?>" class="sortable<?php echo ' ' . $field->type; if ( $class ) echo ' ' . $class; ?>">
     334                            <legend><?php bp_the_profile_field_name(); ?> <?php if( !$field->can_delete ) : ?> <?php _e( '(Core)', 'buddypress' ); endif; ?> <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php _e( '(required)', 'buddypress' ) ?><?php endif; ?></legend>
     335                            <div class="field-wrapper">
     336<?php
     337    switch ( $field->type ) {
     338        case 'textbox' : ?>
     339
     340                                <input type="text" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" value="" />
     341<?php       break; case 'textarea' : ?>
     342
     343                                <textarea rows="5" cols="40" name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>"></textarea>
     344<?php       break; case 'selectbox' : ?>
     345
     346                                <select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>">
     347                                    <?php bp_the_profile_field_options() ?>
     348
     349                                </select>
     350
     351<?php       break; case 'multiselectbox' : ?>
     352
     353                                <select name="<?php bp_the_profile_field_input_name() ?>" id="<?php bp_the_profile_field_input_name() ?>" multiple="multiple">
     354                                    <?php bp_the_profile_field_options() ?>
     355
     356                                </select>
     357
     358<?php       break; case 'radio' : ?>
     359
     360                                <?php bp_the_profile_field_options() ?>
     361
     362<?php           if ( !bp_get_the_profile_field_is_required() ) : ?>
     363
     364                                <a class="clear-value" href="javascript:clear( '<?php bp_the_profile_field_input_name() ?>' );"><?php _e( 'Clear', 'buddypress' ) ?></a>
     365<?php           endif; ?>
     366
     367<?php       break; case 'checkbox' : ?>
     368
     369<?php bp_the_profile_field_options(); ?>
     370
     371<?php       break; case 'datebox' : ?>
     372
     373                                <select name="<?php bp_the_profile_field_input_name(); ?>_day" id="<?php bp_the_profile_field_input_name(); ?>_day">
     374                                    <?php bp_the_profile_field_options( 'type=day' ); ?>
     375
     376                                </select>
     377
     378                                <select name="<?php bp_the_profile_field_input_name(); ?>_month" id="<?php bp_the_profile_field_input_name(); ?>_month">
     379                                    <?php bp_the_profile_field_options( 'type=month' ); ?>
     380
     381                                </select>
     382
     383                                <select name="<?php bp_the_profile_field_input_name(); ?>_year" id="<?php bp_the_profile_field_input_name(); ?>_year">
     384                                    <?php bp_the_profile_field_options( 'type=year' ); ?>
     385
     386                                </select>
     387
     388<?php       break; default : ?>
     389
     390<?php   do_action( 'xprofile_admin_field', $field, 1 ); ?>
     391
     392<?php } ?>
     393                                <div class="actions">
     394                                    <a class="button edit" href="admin.php?page=bp-profile-setup&amp;group_id=<?php echo attribute_escape( $admin_group->id ); ?>&amp;field_id=<?php echo attribute_escape( $field->id ); ?>&amp;mode=edit_field"><?php _e( 'Edit', 'buddypress' ); ?></a>
     395                                    <?php if ( !$field->can_delete ) : ?>&nbsp;<?php else : ?><a class="button delete" href="admin.php?page=bp-profile-setup&amp;field_id=<?php echo attribute_escape( $field->id ); ?>&amp;mode=delete_field"><?php _e( 'Delete', 'buddypress' ); ?></a><?php endif; ?>
     396
     397                                </div>
     398<?php if ( $field->description ) : ?>
     399                                <p class="description"><?php echo attribute_escape( $field->description ); ?></p>
     400<?php endif; ?>
     401                            </div>
     402                        </fieldset>
     403<?php
     404}
  • trunk/bp-xprofile/bp-xprofile-classes.php

    r2810 r2883  
    66    var $description;
    77    var $can_delete;
     8    var $group_order;
    89    var $fields;
    910
     
    1112        global $bp, $wpdb;
    1213
    13         if ( $id ) {
     14        if ( $id )
    1415            $this->populate( $id );
    15         }
     16
    1617    }
    1718
     
    2425            return false;
    2526
    26         $this->id = $group->id;
    27         $this->name = $group->name;
    28         $this->description = $group->description;
    29         $this->can_delete = $group->can_delete;
     27        $this->id           = $group->id;
     28        $this->name         = $group->name;
     29        $this->description  = $group->description;
     30        $this->can_delete   = $group->can_delete;
     31        $this->group_order  = $group->group_order;
    3032    }
    3133
     
    3335        global $wpdb, $bp;
    3436
    35         $this->name = apply_filters( 'xprofile_group_name_before_save', $this->name, $this->id );
    36         $this->description = apply_filters( 'xprofile_group_description_before_save', $this->description, $this->id );
     37        $this->name         = apply_filters( 'xprofile_group_name_before_save', $this->name, $this->id );
     38        $this->description  = apply_filters( 'xprofile_group_description_before_save', $this->description, $this->id );
    3739
    3840        do_action( 'xprofile_group_before_save', $this );
     
    4345            $sql = $wpdb->prepare( "INSERT INTO {$bp->profile->table_name_groups} (name, description, can_delete) VALUES (%s, %s, 1)", $this->name, $this->description );
    4446
    45         if ( !$wpdb->query($sql) )
     47        if ( !$wpdb->query( $sql ) )
    4648            return false;
    4749
     
    121123        if ( $fetch_field_data ) {
    122124            /* Fetch the field data for the user. */
    123             foreach( (array)$fields as $field ) {
     125            foreach( (array)$fields as $field )
    124126                $field_ids[] = $field->id;
    125             }
    126127
    127128            $field_ids = implode( ',', (array) $field_ids );
     
    172173    }
    173174
    174     /* ADMIN AREA HTML. TODO: Get this out of here. */
     175    /* ADMIN AREA HTML.
     176    * TODO: Get this out of here and replace with standard loops
     177    */
    175178
    176179    function render_admin_form() {
     
    178181
    179182        if ( !$this->id ) {
    180             $title = __('Add New Field Group', 'buddypress');
    181             $action = "admin.php?page=bp-profile-setup&amp;mode=add_group";
     183            $title  = __( 'Add New Field Group', 'buddypress' );
     184            $action = "admin.php?page=bp-profile-setup&amp;mode=add_group";
     185            $button = __( 'Create Field Group', 'buddypress' );
    182186        } else {
    183             $title = __('Edit Field Group', 'buddypress');
     187            $title = __( 'Edit Field Group', 'buddypress' );
    184188            $action = "admin.php?page=bp-profile-setup&amp;mode=edit_group&amp;group_id=" . $this->id;
     189            $button = __( 'Save Changes', 'buddypress' );
    185190        }
    186191?>
    187192        <div class="wrap">
    188 
     193            <div class="icon32" id="icon-tools"><br></div>
    189194            <h2><?php echo $title; ?></h2>
    190 <?php
    191                 if ( $message != '' ) {
    192                     $type = ( 'error' == $type ) ? 'error' : 'updated';
    193 ?>
    194 
     195            <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p>
     196
     197<?php if ( $message != '' ) :
     198        $type = ( 'error' == $type ) ? 'error' : 'updated'; ?>
    195199                <div id="message" class="<?php echo $type; ?> fade">
    196200                    <p><?php echo $message; ?></p>
    197201                </div>
    198 <?php } ?>
    199 
    200             <form action="<?php echo attribute_escape( $action ); ?>" method="post">
    201                 <div id="titlediv">
    202                     <label for="group_name"><?php _e( "Field Group Name", 'buddypress') ?></label>
    203                     <div>
    204                         <input type="text" name="group_name" id="group_name" value="<?php echo attribute_escape( $this->name ); ?>" style="width:50%" />
     202<?php endif; ?>
     203            <div id="poststuff">
     204                <form action="<?php echo attribute_escape( $action ); ?>" method="post">
     205                    <div id="titlediv">
     206                        <h3><label for="group_name"><?php _e( "Field Group Title", 'buddypress') ?> *</label></h3>
     207                        <div id="titlewrap">
     208                            <input type="text" name="group_name" id="title" value="<?php echo attribute_escape( $this->name ); ?>" style="width:50%" />
     209                        </div>
    205210                    </div>
    206                 </div>
    207 
    208                 <p class="submit" style="text-align: left">
    209                     <input type="submit" name="saveGroup" value="<?php echo attribute_escape( $title ); ?> &rarr;" />
    210                 </p>
    211             </form>
     211
     212<?php if ( '0' != $this->can_delete ) : ?>
     213                    <div id="titlediv">
     214                        <h3><label for="description"><?php _e( "Group Description", 'buddypress' ); ?></label></h3>
     215                        <div id="titlewrap">
     216                            <textarea name="group_description" id="group_description" rows="8" cols="60"><?php echo htmlspecialchars( $this->description ); ?></textarea>
     217                        </div>
     218                    </div>
     219<?php endif; ?>
     220
     221                    <p class="submit">
     222                        <input type="hidden" name="group_order" id="group_order" value="<?php echo attribute_escape( $this->group_order ); ?>" />
     223                        <input type="submit" name="save_group" value="<?php echo attribute_escape( $button ); ?>" class="button-primary"/>
     224                        <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a>
     225                    </p>
     226                </form>
     227            </div>
    212228        </div>
    213229<?php
     
    248264
    249265        if ( $field = $wpdb->get_row( $sql ) ) {
    250             $this->id = $field->id;
    251             $this->group_id = $field->group_id;
    252             $this->parent_id = $field->parent_id;
    253             $this->type = $field->type;
    254             $this->name = stripslashes($field->name);
    255             $this->description = stripslashes($field->description);
    256             $this->is_required = $field->is_required;
    257             $this->can_delete = $field->can_delete;
    258             $this->field_order = $field->field_order;
    259             $this->option_order = $field->option_order;
    260             $this->order_by = $field->order_by;
    261             $this->is_default_option = $field->is_default_option;
     266            $this->id                   = $field->id;
     267            $this->group_id             = $field->group_id;
     268            $this->parent_id            = $field->parent_id;
     269            $this->type                 = $field->type;
     270            $this->name                 = stripslashes($field->name);
     271            $this->description          = stripslashes($field->description);
     272            $this->is_required          = $field->is_required;
     273            $this->can_delete           = $field->can_delete;
     274            $this->field_order          = $field->field_order;
     275            $this->option_order         = $field->option_order;
     276            $this->order_by             = $field->order_by;
     277            $this->is_default_option    = $field->is_default_option;
    262278
    263279            if ( $get_data )
    264                 $this->data = $this->get_field_data( $user_id );
     280                $this->data             = $this->get_field_data( $user_id );
    265281
    266282        }
     
    291307        $error = false;
    292308
    293         $this->group_id = apply_filters( 'xprofile_field_group_id_before_save', $this->group_id, $this->id );
    294         $this->parent_id = apply_filters( 'xprofile_field_parent_id_before_save', $this->parent_id, $this->id );
    295         $this->type = apply_filters( 'xprofile_field_type_before_save', $this->type, $this->id );
    296         $this->name = apply_filters( 'xprofile_field_name_before_save', $this->name, $this->id );
    297         $this->description = apply_filters( 'xprofile_field_description_before_save', $this->description, $this->id );
    298         $this->is_required = apply_filters( 'xprofile_field_is_required_before_save', $this->is_required, $this->id );
    299         $this->order_by = apply_filters( 'xprofile_field_order_by_before_save', $this->order_by, $this->id );
    300         $this->field_order = apply_filters( 'xprofile_field_field_order_before_save', $this->field_order, $this->id );
     309        $this->group_id     = apply_filters( 'xprofile_field_group_id_before_save', $this->group_id, $this->id );
     310        $this->parent_id    = apply_filters( 'xprofile_field_parent_id_before_save', $this->parent_id, $this->id );
     311        $this->type         = apply_filters( 'xprofile_field_type_before_save', $this->type, $this->id );
     312        $this->name         = apply_filters( 'xprofile_field_name_before_save', $this->name, $this->id );
     313        $this->description  = apply_filters( 'xprofile_field_description_before_save', $this->description, $this->id );
     314        $this->is_required  = apply_filters( 'xprofile_field_is_required_before_save', $this->is_required, $this->id );
     315        $this->order_by     = apply_filters( 'xprofile_field_order_by_before_save', $this->order_by, $this->id );
     316        $this->field_order  = apply_filters( 'xprofile_field_field_order_before_save', $this->field_order, $this->id );
    301317
    302318        do_action( 'xprofile_field_before_save', $this );
     
    312328         */
    313329        if ( $wpdb->query( $sql ) !== null ) {
    314 
    315330            if ( $this->id )
    316331                $field_id = $this->id;
     
    340355
    341356                if ( 'radio' == $this->type ) {
    342                     $options = $_POST['radio_option'];
    343                     $defaults = $_POST['isDefault_radio_option'];
     357                    $options    = $_POST['radio_option'];
     358                    $defaults   = $_POST['isDefault_radio_option'];
    344359
    345360                } else if ( 'selectbox' == $this->type ) {
    346                     $options = $_POST['selectbox_option'];
    347                     $defaults = $_POST['isDefault_selectbox_option'];
     361                    $options    = $_POST['selectbox_option'];
     362                    $defaults   = $_POST['isDefault_selectbox_option'];
    348363
    349364                } else if ( 'multiselectbox' == $this->type ) {
    350                     $options = $_POST['multiselectbox_option'];
    351                     $defaults = $_POST['isDefault_multiselectbox_option'];
     365                    $options    = $_POST['multiselectbox_option'];
     366                    $defaults   = $_POST['isDefault_multiselectbox_option'];
    352367
    353368                } else if ( 'checkbox' == $this->type ) {
    354                     $options = $_POST['checkbox_option'];
    355                     $defaults = $_POST['isDefault_checkbox_option'];
    356 
     369                    $options    = $_POST['checkbox_option'];
     370                    $defaults   = $_POST['isDefault_checkbox_option'];
    357371                }
    358372
     
    379393                }
    380394            }
    381         } else {
    382             $error = true;
    383         }
    384 
    385         if ( !$error ) {
     395
    386396            do_action( 'xprofile_field_after_save', $this );
     397
    387398            return $field_id;
    388399        } else {
     
    486497    }
    487498
    488     /* ADMIN AREA HTML. TODO: Get this out of here. */
     499    /* ADMIN AREA HTML.
     500    * TODO: Get this out of here and replace with standard template loops
     501    */
    489502
    490503    /* This function populates the items for radio buttons checkboxes and drop down boxes */
     
    501514?>
    502515            <div id="<?php echo $type; ?>" class="options-box" style="<?php if ( $this->type != $type ) { ?>display: none;<?php } ?> margin-left: 15px;">
    503                 <h4><?php _e('Please enter options for this Field:', 'buddypress'); ?></h4>
     516                <h4><?php _e( 'Please enter options for this Field:', 'buddypress' ); ?></h4>
    504517                <p><?php _e( 'Order By:', 'buddypress' ); ?>
    505518                    <select name="sort_order_<?php echo $type; ?>" id="sort_order_<?php echo $type; ?>" >
     
    536549                           <input type="text" name="<?php echo $type; ?>_option[<?php echo $j; ?>]" id="<?php echo $type; ?>_option<?php echo $j; ?>" value="<?php echo attribute_escape( $options[$i]->name ); ?>" />
    537550                           <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' ); ?>
    538                             <?php if ( $j != 1 &&
    539                                 $options[$i]->id != -1 ) : ?><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><?php endif; ?></p>
     551<?php
     552                    if ( $j != 1 && $options[$i]->id != -1 ) : ?>
     553                            <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>
     554<?php               endif; ?>
    540555                        </p>
    541556<?php               } /* end for */ ?>
     
    564579        if ( !$this->id ) {
    565580            $title              = __( 'Add Field', 'buddypress' );
    566             $action             = "admin.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field";
     581            $action             = "admin.php?page=bp-profile-setup&amp;group_id=" . $this->group_id . "&amp;mode=add_field#tabs-" . $this->group_id;
    567582
    568583            $this->name         = $_POST['title'];
     
    571586            $this->type         = $_POST['fieldtype'];
    572587            $this->order_by     = $_POST["sort_order_{$this->type}"];
     588            $this->field_order  = $_POST['field_order'];
    573589        } else {
    574590            $title              = __( 'Edit Field', 'buddypress' );
    575             $action             = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id;
    576         }
    577     ?>
    578 
     591            $action             = "admin.php?page=bp-profile-setup&amp;mode=edit_field&amp;group_id=" . $this->group_id . "&amp;field_id=" . $this->id . "#tabs-" . $this->group_id;
     592        }
     593?>
    579594    <div class="wrap">
     595        <div id="icon-users" class="icon32"><br /></div>
    580596        <h2><?php echo $title; ?></h2>
     597        <p><?php _e( 'Fields marked * are required', 'buddypress' ) ?></p>
     598
    581599<?php
    582             if ( $message != '' ) {
     600        if ( $message != '' ) {
    583601?>
    584 
    585602            <div id="message" class="error fade">
    586603                <p><?php echo $message; ?></p>
    587604            </div>
    588 <?php } ?>
     605<?php   } ?>
    589606
    590607        <form action="<?php echo $action; ?>" method="post">
     
    596613                    </div>
    597614                </div>
    598 
    599                 <div id="titlediv" class="inside">
     615<?php
     616        if ( '0' != $this->can_delete ) {
     617?>
     618                <div id="titlediv">
    600619                    <h3><label for="description"><?php _e("Field Description", 'buddypress'); ?></label></h3>
    601620                    <div id="titlewrap">
     
    626645
    627646                <?php $this->render_admin_form_children(); ?>
    628 
     647<?php   } else { ?>
     648                <input type="hidden" name="required" id="required" value="1" />
     649                <input type="hidden" name="fieldtype" id="fieldtype" value="textbox" />
     650<?php   } ?>
    629651                <p class="submit">
    630                     &nbsp;<input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?> &rarr;" name="saveField" id="saveField" style="font-weight: bold" />
    631                      <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" style="color: red"><?php _e( 'Cancel', 'buddypress' ); ?></a>
     652                    <input type="hidden" name="field_order" id="field_order" value="<?php echo attribute_escape( $this->field_order ); ?>" />
     653                    <input type="submit" value="<?php _e( 'Save', 'buddypress' ); ?>" name="saveField" id="saveField" style="font-weight: bold" class="button-primary" />
     654                    <?php _e( 'or', 'buddypress' ); ?> <a href="admin.php?page=bp-profile-setup" class="deletion"><?php _e( 'Cancel', 'buddypress' ); ?></a>
    632655                </p>
    633656
    634657            </div>
    635 
    636             <div class="clear"></div>
    637658
    638659            <?php if ( function_exists( 'wp_nonce_field' ) ) wp_nonce_field( 'xprofile_delete_option' ); ?>
  • trunk/bp-xprofile/bp-xprofile-cssjs.php

    r2798 r2883  
    88function xprofile_add_admin_js() {
    99    if ( strpos( $_GET['page'], 'bp-profile-setup' ) !== false ) {
     10        wp_enqueue_script( 'jquery-ui-core' );
     11        wp_enqueue_script( 'jquery-ui-tabs' );
     12        wp_enqueue_script( 'jquery-ui-mouse' );
     13        wp_enqueue_script( 'jquery-ui-draggable' );
     14        wp_enqueue_script( 'jquery-ui-droppable' );
    1015        wp_enqueue_script( 'jquery-ui-sortable' );
    1116        wp_enqueue_script( 'xprofile-admin-js', BP_PLUGIN_URL . '/bp-xprofile/admin/js/admin.js', array( 'jquery', 'jquery-ui-sortable' ) );
     17        //wp_enqueue_script( 'xprofile-button-js', BP_PLUGIN_URL . '/bp-xprofile/admin/js/button.js', array( 'xprofile-admin-js' ) );
    1218    }
    1319}
Note: See TracChangeset for help on using the changeset viewer.