Index: content_admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content_admin.inc,v
retrieving revision 1.30
diff -u -r1.30 content_admin.inc
--- content_admin.inc	29 Nov 2006 19:04:55 -0000	1.30
+++ content_admin.inc	9 Dec 2006 21:21:35 -0000
@@ -34,44 +34,106 @@
   return $output;
 }
 
+
 /**
  * Menu callback; presents a listing of fields for a content type.
  */
 function _content_admin_field_overview($type_name) {
 
+  //$form = form_builder('_content_admin_field_overview_form', _content_admin_field_overview_form($type_name));
+  return drupal_get_form('content_admin_field_overview_form', $type_name);
+}
+
+function content_admin_field_overview_form($type_name) {
+  $form = array();
+
   $type = content_types($type_name);
   $field_types = _content_field_types();
 
-  $header = array(t('Label'), t('Name'), t('Type'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2));
-  $rows = array();
+  $form['#rows'] = array();
   if ($type['has_title']) {
-    $rows[] = array(t($type['title_label']), 'title', '', '-5 '.t('(hardcoded)'), '', '');
+    $form['#rows'][-5][] = array( t($type['title_label']), 'title', '', array('form' => 'title'), '', '');
+    $form['weights']['title'] = _content_admin_field_weight(-5, TRUE);
+    $form['no_update']['#value'][] = 'title';
   }
   if ($type['has_body']) {
-    $rows[] = array(t($type['body_label']), 'body', '', '0 '.t('(hardcoded)'), '', '');
+    $form['#rows'][0][] = array(t($type['body_label']), 'body', '', array('form' => 'body'), '', '');
+    $form['weights']['body'] = _content_admin_field_weight(0, TRUE);
+    $form['no_update']['#value'][] = 'body';
   }
 
   $c = db_query(db_rewrite_sql("SELECT v.*, n.type FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", 'v', 'vid'), $type_name);
   while ($vocabulary = db_fetch_object($c)) {
-    $rows[] = array(check_plain($vocabulary->name), 'taxonomy', '', '', '', '');
+    $form['#rows'][-3][] = array( check_plain($vocabulary->name), 'taxonomy', '', array('form' => check_plain($vocabulary->name)), '', '');
+    $form['weights'][check_plain($vocabulary->name)] = _content_admin_field_weight(-3, TRUE);
+    $form['no_update']['#value'][] = check_plain($vocabulary->name);
   }
 
   foreach ($type['fields'] as $field) {
     $row = array();
+    $form['weights'][$field['field_name']] = _content_admin_field_weight($field['widget']['weight']);
     $row[] = $field['widget']['label'];
     $row[] = $field['field_name'];
     $row[] = $field_types[$field['type']]['label'];
-    $row[] = $field['widget']['weight'];
-
+    $row[] = array('form' => $field['field_name']);
+    
     $row[] = l(t('configure'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $field['field_name']);
     $row[] = l(t('remove'), 'admin/content/types/'. $type['url_str'] .'/fields/'. $field['field_name'] .'/remove');
 
-    $rows[] = $row;
+    $form['#rows'][$field['widget']['weight']][] = $row;
   }
+  ksort($form['#rows']);
+  $form[] = array(
+   '#type' => 'submit',
+   '#value' => t('Save Weight'),
+   );
+  $form['weights']['#tree'] = TRUE;
+  $form['no_update']['#type'] = 'hidden';
+  $form['no_update']['#value'] = serialize($form['no_update']['#value']);
+  $form['type_name']['#type'] = 'hidden';
+  $form['type_name']['#value'] = $type_name;
+  return $form;
 
-  $output = theme('table', $header, $rows);
+}
 
+function theme_content_admin_field_overview_form($form) {
+ 
+  $rows = array();
+  $i = 0;
+  foreach ($form['#rows'] as $weight => $item) {
+    foreach ($item as $delta => $form_rows) {
+      foreach ($form_rows as $col => $row) {
+        $rows[$i][] = array('data' => (is_array($row) ? drupal_render($form['weights'][$row['form']]) : $row));
+      }
+      $i++;
+    }
+  }
+  $header  = array(t('Label'), t('Name'), t('Type'), t('Weight'), array('data' => t('Operations'), 'colspan' => 2));
+  $output  = theme('table', $header, $rows);
+  $output .= drupal_render($form);
   return $output;
+
+}
+
+function _content_admin_field_weight($weight, $disabled = FALSE) {
+  $form = array(
+    '#type' => 'weight', 
+    '#default_value' => $weight,
+    );
+  if ($disabled) {
+    $form['#disabled'] = TRUE;
+  }
+  return $form;
+}
+
+function content_admin_field_overview_form_submit($form_id, $form_values) {
+  foreach ($form_values['weights'] as $key => $value) {
+    if (!in_array($key, unserialize($form_values['no_update']))) {
+      db_query("UPDATE {node_field_instance} SET weight = %d WHERE type_name = '%s' AND field_name = '%s'", $value, $form_values['type_name'], $key);
+      drupal_set_message(t('Updated field %field with weight %weight.', array('%field' => $key, '%weight' => $value)));
+    }
+  }
+  content_clear_type_cache();
 }
 
 /**
@@ -354,7 +416,7 @@
     '#required' => TRUE,
   );
   $form['widget']['weight'] = array(
-    '#type' => 'weight',
+    '#type' => 'hidden',
     '#title' => t('Weight'),
     '#default_value' => $field['widget']['weight'],
     '#description' => t('In the node editing form, the heavier fields will sink and the lighter fields will be positioned nearer the top.'),
