<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [1798] trunk/bp-xprofile: Added profile field re-ordering</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>1798</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-09-06 01:07:21 +0000 (Sun, 06 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Added profile field re-ordering</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpxprofileadmincssadmincss">trunk/bp-xprofile/admin/css/admin.css</a></li>
<li><a href="#trunkbpxprofilebpxprofileadminphp">trunk/bp-xprofile/bp-xprofile-admin.php</a></li>
<li><a href="#trunkbpxprofilebpxprofileclassesphp">trunk/bp-xprofile/bp-xprofile-classes.php</a></li>
<li><a href="#trunkbpxprofilebpxprofilecssjsphp">trunk/bp-xprofile/bp-xprofile-cssjs.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li>trunk/bp-xprofile/admin/</li>
<li>trunk/bp-xprofile/admin/css/</li>
<li>trunk/bp-xprofile/admin/images/</li>
<li><a href="#trunkbpxprofileadminimagesmovegif">trunk/bp-xprofile/admin/images/move.gif</a></li>
<li><a href="#trunkbpxprofileadminimagestickgif">trunk/bp-xprofile/admin/images/tick.gif</a></li>
<li>trunk/bp-xprofile/admin/js/</li>
<li><a href="#trunkbpxprofileadminjsadminjs">trunk/bp-xprofile/admin/js/admin.js</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li>trunk/bp-xprofile/css/</li>
<li><a href="#trunkbpxprofiledeprecatedimagestickgif">trunk/bp-xprofile/deprecated/images/tick.gif</a></li>
<li>trunk/bp-xprofile/js/</li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpxprofileadmincssfromrev1789trunkbpxprofilecss"></a>
<div class="copfile"><h4>Copied: trunk/bp-xprofile/admin/css (from rev 1789, trunk/bp-xprofile/css)</h4></div>
<a id="trunkbpxprofileadmincssadmincss"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/admin/css/admin.css (1789 => 1798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/css/admin.css        2009-09-04 18:30:04 UTC (rev 1789)
+++ trunk/bp-xprofile/admin/css/admin.css        2009-09-06 01:07:21 UTC (rev 1798)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+table.field-group tbody {
+        cursor: move;
+}
+        table.field-group tbody tr.nodrag {
+                cursor: default !important;
+        }
+
+table.field-group tbody tr:hover {
+        background-color: #fffee9;
+}
+        
</ins><span class="cx"> tr.header td {
</span><span class="cx">         border-bottom: 2px solid #eee;
</span><span class="cx">         font-weight: bold;
</span></span></pre></div>
<a id="trunkbpxprofileadminimagesmovegif"></a>
<div class="binary"><h4>Added: trunk/bp-xprofile/admin/images/move.gif</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Property changes on: trunk/bp-xprofile/admin/images/move.gif
</span><span class="cx">___________________________________________________________________
</span><span class="cx">Name: svn:mime-type
</span><span class="cx"> + application/octet-stream
</span><a id="trunkbpxprofileadminimagestickgiffromrev1789trunkbpxprofiledeprecatedimagestickgif"></a>
<div class="binary"><h4>Copied: trunk/bp-xprofile/admin/images/tick.gif (from rev 1789, trunk/bp-xprofile/deprecated/images/tick.gif)</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<a id="trunkbpxprofileadminjsadminjs"></a>
<div class="addfile"><h4>Added: trunk/bp-xprofile/admin/js/admin.js (0 => 1798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/admin/js/admin.js         (rev 0)
+++ trunk/bp-xprofile/admin/js/admin.js        2009-09-06 01:07:21 UTC (rev 1798)
</span><span class="lines">@@ -0,0 +1,136 @@
</span><ins>+function add_option(forWhat) {
+        var holder = document.getElementById(forWhat + "_more");
+        var theId = document.getElementById(forWhat + '_option_number').value;
+
+        var newDiv = document.createElement('p');
+        newDiv.setAttribute('id', forWhat + '_div' + theId);
+
+        var newOption = document.createElement('input');
+        newOption.setAttribute('type', 'text');
+        newOption.setAttribute('name', forWhat + '_option[' + theId + ']');
+        newOption.setAttribute('id', forWhat + '_option' + theId);
+
+        var label = document.createElement('label');
+        label.setAttribute('for', forWhat + '_option' + theId);
+        
+        var txt = document.createTextNode("Option " + theId + ": ");
+        label.appendChild(txt);
+        
+        var isDefault = document.createElement('input');
+        
+        if(forWhat == 'checkbox' || forWhat == 'multiselectbox') {
+                isDefault.setAttribute('type', 'checkbox');
+                isDefault.setAttribute('name', 'isDefault_' + forWhat + '_option[' + theId + ']');
+        } else {
+                isDefault.setAttribute('type', 'radio');
+                isDefault.setAttribute('name', 'isDefault_' + forWhat + '_option');                                        
+        }
+        
+        isDefault.setAttribute('value', theId);
+
+        var label1 = document.createElement('label');
+        var txt1 = document.createTextNode(" Default Value ");
+        
+        label1.appendChild(txt1);
+        label1.setAttribute('for', 'isDefault_' + forWhat + '_option[]');
+        toDelete = document.createElement('a');
+        
+        toDeleteText = document.createTextNode('[x]');
+        toDelete.setAttribute('href',"javascript:hide('" + forWhat + '_div' + theId + "')");
+        
+        toDelete.setAttribute('class','delete');
+
+        toDelete.appendChild(toDeleteText);
+
+        newDiv.appendChild(label);
+        newDiv.appendChild(newOption);
+        newDiv.appendChild(document.createTextNode(" "));
+        newDiv.appendChild(isDefault);
+        newDiv.appendChild(label1);        
+        newDiv.appendChild(toDelete);        
+        holder.appendChild(newDiv);
+        
+        
+        theId++
+        document.getElementById(forWhat + "_option_number").value = theId;
+}
+
+function show_options(forWhat) {
+        document.getElementById("radio").style.display = "none";
+        document.getElementById("selectbox").style.display = "none";
+        document.getElementById("multiselectbox").style.display = "none";
+        document.getElementById("checkbox").style.display = "none";
+        
+        if(forWhat == "radio") {
+                document.getElementById("radio").style.display = "";
+        }
+        
+        if(forWhat == "selectbox") {
+                document.getElementById("selectbox").style.display = "";                                                
+        }
+        
+        if(forWhat == "multiselectbox") {
+                document.getElementById("multiselectbox").style.display = "";                                                
+        }
+        
+        if(forWhat == "checkbox") {
+                document.getElementById("checkbox").style.display = "";                                                
+        }
+}
+
+function hide(id) {
+        if ( !document.getElementById(id) ) return false;
+        
+        document.getElementById(id).style.display = "none";
+        document.getElementById(id).value = '';
+}
+
+// Set up deleting options ajax
+jQuery(document).ready( function() {
+        
+        jQuery("a.ajax-option-delete").click(
+                function() {
+                        var theId = this.id.split('-');
+                        theId = theId[1];
+                        
+                        jQuery.post( ajaxurl, {
+                                action: 'xprofile_delete_option',
+                                'cookie': encodeURIComponent(document.cookie),
+                                '_wpnonce': jQuery("input#_wpnonce").val(),
+                                
+                                'option_id': theId
+                        },
+                        function(response)
+                        {});
+                }
+        );                                
+});
+
+var fixHelper = function(e, ui) {
+        ui.children().each(function() {
+                jQuery(this).width( jQuery(this).width() );
+        });
+        return ui;
+};
+
+jQuery(document).ready( function() {
+        jQuery("table.field-group tbody").sortable( {
+                cursor: 'move',
+                axis: 'y',
+                helper: fixHelper,
+                distance: 1,
+                cancel: 'tr.nodrag',
+                update: function() {
+                        jQuery.post( ajaxurl, {
+                                action: 'xprofile_reorder_fields',
+                                'cookie': encodeURIComponent(document.cookie),
+                                '_wpnonce_reorder_fields': jQuery("input#_wpnonce_reorder_fields").val(),
+                                
+                                'field_order': jQuery(this).sortable('serialize')
+                        },
+                        function(response)
+                        {});
+
+                }
+        });
+} );
</ins></span></pre></div>
<a id="trunkbpxprofilebpxprofileadminphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-admin.php (1797 => 1798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-admin.php        2009-09-05 14:11:06 UTC (rev 1797)
+++ trunk/bp-xprofile/bp-xprofile-admin.php        2009-09-06 01:07:21 UTC (rev 1798)
</span><span class="lines">@@ -41,75 +41,97 @@
</span><span class="cx">                         
</span><span class="cx">                 <p><?php _e('NOTE: Any fields in the first group will appear on the signup page.', 'buddypress'); ?></p>
</span><span class="cx">                 
</span><del>-                <?php
-                        if ( $message != '' ) {
-                                $type = ( $type == 'error' ) ? 'error' : 'updated';
-                ?>
-                        <div id="message" class="<?php echo $type; ?> fade">
-                                <p><?php echo wp_specialchars( $message ); ?></p>
-                        </div>
-                <?php }
</del><ins>+                <form action="" id="profile-field-form" method="post">
+                        
+                        <?php wp_nonce_field( 'bp_reorder_fields', '_wpnonce_reorder_fields' ); ?>
+                                        
+                        <?php
+                                if ( $message != '' ) {
+                                        $type = ( $type == 'error' ) ? 'error' : 'updated';
+                        ?>
+                                <div id="message" class="<?php echo $type; ?> fade">
+                                        <p><?php echo wp_specialchars( attribute_escape( $message ) ); ?></p>
+                                </div>
+                        <?php }
</ins><span class="cx">                 
</span><del>-                if ( $groups ) { ?>
-                        <?php
-                        for ( $i = 0; $i < count($groups); $i++ ) { // TODO: foreach
-                        ?>
-                                <p>
-                                <table id="group_<?php echo $groups[$i]->id;?>" class="widefat">
-                                        <thead>
-                                         <tr class="nodrag">
-                                                 <th scope="col" colspan="<?php if ( $groups[$i]->can_delete ) { ?>3<?php } else { ?>5<?php } ?>"><?php echo $groups[$i]->name; ?></th>
-                                                        <?php if ( $groups[$i]->can_delete ) { ?>         
-                                                                <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>
-                                                         <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>
-                                                        <?php } ?>
-                                                </tr>
-                                        </thead>
-                                        <tbody id="the-list">
-                                         <tr class="header nodrag">
-                                                 <td><?php _e( 'Field Name', 'buddypress' ) ?></td>
-                                                 <td width="14%"><?php _e( 'Field Type', 'buddypress' ) ?></td>
-                                                 <td width="6%"><?php _e( 'Required?', 'buddypress' ) ?></td>
-                                                 <td colspan="2" width="10%" style="text-align:center;"><?php _e( 'Action', 'buddypress' ) ?></td>
-                                         </tr>
-
</del><ins>+                        if ( $groups ) { ?>
+                                <?php
+                                for ( $i = 0; $i < count($groups); $i++ ) { // TODO: foreach
+                                ?>
+                                        <p>
+                                        <table id="group_<?php echo $groups[$i]->id;?>" class="widefat field-group">
+                                                <thead>
+                                                 <tr>
+                                                                <th scope="col">&nbsp;</th>
+                                                         <th scope="col" colspan="<?php if ( $groups[$i]->can_delete ) { ?>3<?php } else { ?>5<?php } ?>"><?php echo attribute_escape( $groups[$i]->name ); ?></th>
+                                                                <?php if ( $groups[$i]->can_delete ) { ?>         
+                                                                        <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>
+                                                                 <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>
+                                                                <?php } ?>
+                                                        </tr>
+                                                        <tr class="header">
+                                                                <td>&nbsp;</td>
+                                                         <td><?php _e( 'Field Name', 'buddypress' ) ?></td>
+                                                         <td width="14%"><?php _e( 'Field Type', 'buddypress' ) ?></td>
+                                                         <td width="6%"><?php _e( 'Required?', 'buddypress' ) ?></td>
+                                                         <td colspan="2" width="10%" style="text-align:center;"><?php _e( 'Action', 'buddypress' ) ?></td>
+                                                 </tr>
+                                                </thead>
+                                                <tbody id="the-list">
+                                                
</ins><span class="cx">                                                  <?php if ( $groups[$i]->fields ) { ?>
</span><del>-                                                 <?php for ( $j = 0; $j < count($groups[$i]->fields); $j++ ) { ?>
-                                                                        <?php if ( 0 == $j % 2 ) { $class = ""; } else { $class = "alternate"; } ?>
-                                                         <?php $field = new BP_XProfile_Field($groups[$i]->fields[$j]->id); ?>
-                                                         <?php if ( !$field->can_delete ) { $class .= ' core'; } ?>
</del><span class="cx">                                                         
</span><del>-                                                                        <tr id="field_<?php echo $field->id; ?>" <?php if ( $class ) { echo 'class="' . $class . '"'; } ?>>
-                                                                 <td><span title="<?php echo $field->desc; ?>"><?php echo $field->name; ?> <?php if(!$field->can_delete) { ?>(Core)<?php } ?></span></td>
-                                                                 <td><?php echo $field->type; ?></td>
-                                                                 <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>
-                                                                 <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>
-                                                                 <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>
-                                                         </tr>
</del><ins>+                                                         <?php for ( $j = 0; $j < count($groups[$i]->fields); $j++ ) { ?>
+                                                
+                                                                        <?php if ( 0 == $j % 2 ) { $class = ""; } else { $class = "alternate"; } ?>        
+                                                                        <?php $field = new BP_XProfile_Field($groups[$i]->fields[$j]->id); ?>
+                                                                        <?php if ( !$field->can_delete ) { $class .= ' core'; } ?>
</ins><span class="cx">                                                         
</span><ins>+                                                                        <tr id="field_<?php echo attribute_escape( $field->id ); ?>" class="sortable<?php if ( $class ) { echo ' ' . $class; } ?>">
+                                                                         <td width="10"><img src="<?php echo BP_PLUGIN_URL ?>/bp-xprofile/admin/images/move.gif" alt="<?php _e( 'Drag', 'buddypress' ) ?>" /></td>
+                                                                                <td><span title="<?php echo $field->desc; ?>"><?php echo attribute_escape( $field->name ); ?> <?php if(!$field->can_delete) { ?>(Core)<?php } ?></span></td>
+                                                                         <td><?php echo attribute_escape( $field->type ); ?></td>
+                                                                         <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>
+                                                                         <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>
+                                                                         <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>
+                                                                 </tr>
+                                                        
+                                                                <?php } ?>
+                                                        
+                                                        <?php } else { ?>
+                                                        
+                                                                <tr class="nodrag">
+                                                                        <td colspan="6"><?php _e( 'There are no fields in this group.', 'buddypress' ) ?></td>
+                                                                </tr>
+                                                        
</ins><span class="cx">                                                         <?php } ?>
</span><del>-                                                <?php } else { ?>
-                                                        <tr class="nodrag">
-                                                                <td colspan="6"><?php _e( 'There are no fields in this group.', 'buddypress' ) ?></td>
-                                                        </tr>
-                                                <?php } ?>
-                                                        <tr class="nodrag">
-                                                                <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>
-                                                        </tr>
-                                        </tbody>
-                                </table>
-                                </p>
</del><ins>+                                        
+                                                </tbody>
+                                        
+                                                <tfoot>
+                                                
+                                                                <tr class="nodrag">
+                                                                        <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>
+                                                                </tr>
+                                                
+                                                </tfoot>
+                                        
+                                        </table>
+                                        </p>
</ins><span class="cx">                                 
</span><del>-                        <?php } /* End For */ ?>
</del><ins>+                                <?php } /* End For */ ?>
</ins><span class="cx">                         
</span><del>-                                <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>
</del><ins>+                                        <p>
+                                                <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>
+                                        </p>
</ins><span class="cx">                                 
</span><del>-                <?php } else { ?>
-                        <div id="message" class="error"><p><?php _e('You have no groups.', 'buddypress' ); ?></p></div>
-                        <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>
-                <?php } ?>
</del><ins>+                        <?php } else { ?>
+                                <div id="message" class="error"><p><?php _e('You have no groups.', 'buddypress' ); ?></p></div>
+                                <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>
+                        <?php } ?>
+                
+                </form>
+                
</ins><span class="cx">         </div>
</span><span class="cx"> <?php
</span><span class="cx">         }
</span><span class="lines">@@ -254,3 +276,20 @@
</span><span class="cx">         unset($_GET['mode']);
</span><span class="cx">         xprofile_admin($message, $type);
</span><span class="cx"> }
</span><ins>+
+function xprofile_ajax_reorder_fields() {
+        global $bp;
+        
+        /* Check the nonce */
+        check_admin_referer( 'bp_reorder_fields', '_wpnonce_reorder_fields' );
+        
+        if ( empty( $_POST['field_order'] ) )
+                return false;
+        
+        parse_str($_POST['field_order'], $order );
+
+        foreach ( (array) $order['field'] as $position => $field_id ) {
+                xprofile_update_field_position( (int) $field_id, (int) $position );
+        }
+}
+add_action( 'wp_ajax_xprofile_reorder_fields', 'xprofile_ajax_reorder_fields' );
</ins></span></pre></div>
<a id="trunkbpxprofilebpxprofileclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-classes.php (1797 => 1798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-classes.php        2009-09-05 14:11:06 UTC (rev 1797)
+++ trunk/bp-xprofile/bp-xprofile-classes.php        2009-09-06 01:07:21 UTC (rev 1798)
</span><span class="lines">@@ -81,7 +81,7 @@
</span><span class="cx">                 global $wpdb, $bp;
</span><span class="cx">
</span><span class="cx">                 // Get field ids for the current group.
</span><del>-                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 ) ) )
</del><ins>+                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 ) ) )
</ins><span class="cx">                         return false;
</span><span class="cx">                 
</span><span class="cx">                 return $fields;
</span><span class="lines">@@ -127,10 +127,10 @@
</span><span class="cx">                 global $message;
</span><span class="cx">
</span><span class="cx">                 if ( !$this->id ) {
</span><del>-                        $title = __('Add Group', 'buddypress');
</del><ins>+                        $title = __('Add New Field Group', 'buddypress');
</ins><span class="cx">                         $action = "admin.php?page=" . BP_PLUGIN_DIR . "/bp-xprofile.php&amp;mode=add_group";
</span><span class="cx">                 } else {
</span><del>-                        $title = __('Edit Group', 'buddypress');
</del><ins>+                        $title = __('Edit Field Group', 'buddypress');
</ins><span class="cx">                         $action = "admin.php?page=" . BP_PLUGIN_DIR . "/bp-xprofile.php&amp;mode=edit_group&amp;group_id=" . $this->id;                        
</span><span class="cx">                 }
</span><span class="cx">         ?>
</span><span class="lines">@@ -151,7 +151,7 @@
</span><span class="cx">                         <form action="<?php echo attribute_escape( $action ); ?>" method="post">
</span><span class="cx">                                 
</span><span class="cx">                                 <div id="titlediv">
</span><del>-                                        <label for="group_name"><?php _e("Profile Group Name", 'buddypress') ?></label>
</del><ins>+                                        <label for="group_name"><?php _e( "Field Group Name", 'buddypress') ?></label>
</ins><span class="cx">                                         <div>
</span><span class="cx">                                                 <input type="text" name="group_name" id="group_name" value="<?php echo attribute_escape( $this->name ) ?>" style="width:50%" />
</span><span class="cx">                                         </div>
</span><span class="lines">@@ -371,6 +371,8 @@
</span><span class="cx">
</span><span class="cx">                 $wpdb->query($sql);
</span><span class="cx">         }
</span><ins>+        
+        // Static Functions
</ins><span class="cx">                 
</span><span class="cx">         function get_type( $field_id ) {
</span><span class="cx">                 global $wpdb, $bp;
</span><span class="lines">@@ -412,6 +414,15 @@
</span><span class="cx">                 return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s", $field_name ) );
</span><span class="cx">         }
</span><span class="cx">         
</span><ins>+        function update_position( $field_id, $position ) {
+                global $wpdb, $bp;
+                
+                if ( !is_numeric( $position ) )
+                        return false;
+                
+                return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->profile->table_name_fields} SET field_order = %d WHERE id = %d", $position, $field_id ) );
+        }
+        
</ins><span class="cx">         // ADMIN AREA HTML. TODO: Get this out of here.
</span><span class="cx">         
</span><span class="cx">         function render_admin_form_children() {
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofilecssjsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-cssjs.php (1797 => 1798)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-cssjs.php        2009-09-05 14:11:06 UTC (rev 1797)
+++ trunk/bp-xprofile/bp-xprofile-cssjs.php        2009-09-06 01:07:21 UTC (rev 1798)
</span><span class="lines">@@ -1,16 +1,16 @@
</span><span class="cx"> <?php
</span><span class="cx">
</span><span class="cx"> function xprofile_add_admin_css() {
</span><del>-        if ( strpos( $_GET['page'], 'xprofile' ) !== false ) {
-                echo '<link rel="stylesheet" href="' . BP_PLUGIN_URL . '/bp-xprofile/css/admin.css' . '" type="text/css" />';
-        }
</del><ins>+        wp_enqueue_style( 'xprofile-admin-css', BP_PLUGIN_URL . '/bp-xprofile/admin/css/admin.css' );
</ins><span class="cx"> }
</span><del>-add_action( 'admin_head', 'xprofile_add_admin_css' );
</del><ins>+add_action( 'admin_menu', 'xprofile_add_admin_css' );
</ins><span class="cx">
</span><span class="cx"> function xprofile_add_admin_js() {
</span><del>-        if ( strpos( $_GET['page'], 'xprofile' ) !== false )
-                echo '<script type="text/javascript" src="' . BP_PLUGIN_URL . '/bp-xprofile/js/admin.js' . '"></script>';
</del><ins>+        if ( strpos( $_GET['page'], 'xprofile' ) !== false ) {
+                wp_enqueue_script( array( "jquery-ui-sortable" ) );
+                wp_enqueue_script( 'xprofile-admin-js', BP_PLUGIN_URL . '/bp-xprofile/admin/js/admin.js', array( 'jquery' ) );
+        }
</ins><span class="cx"> }
</span><del>-add_action( 'admin_head', 'xprofile_add_admin_js' );
</del><ins>+add_action( 'admin_menu', 'xprofile_add_admin_js', 1 );
</ins><span class="cx">
</span><span class="cx"> ?>
</span></span></pre></div>
<a id="trunkbpxprofiledeprecatedimagestickgif"></a>
<div class="binary"><h4>Deleted: trunk/bp-xprofile/deprecated/images/tick.gif</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
</div>
</body>
</html>