? .DS_Store
? actions_14.patch
? actions_help.patch
? block_dnd-add_drag_drop_to_blocks-181066-86.patch
? block_sane_help.patch
? book_ahahapi_4.patch
? comment_notice.patch
? draggable-menu-181126-16.patch
? drupal_drag_and_drop_12.patch
? drupal_drag_and_drop_14.patch
? files
? fix_garland_and_menu_theme.patch
? form_expand_ahah.patch
? install_profile_notice.patch
? jquery_upgrade.patch
? lower_13.patch
? lower_14.patch
? menu-itunes_interface-191360-7.patch
? menu_drag_and_drop_0.patch
? menu_parent_selector_1.patch
? poll-drag-drop.patch
? powered_by_drupal.patch
? powered_by_drupal_2.patch
? tracker-union-2.patch
? upload_weight.patch
? misc/draggable.png
? misc/tabledrag.js
? misc/tree-bottom.png
? misc/tree.png
? modules/.DS_Store
? modules/block/.DS_Store
? modules/block/block.js
? modules/menu/.DS_Store
? modules/tracker/.DS_Store
? modules/translation/.DS_Store
? profiles/.DS_Store
? profiles/single_user_blog
? sites/.DS_Store
? sites/views
? sites/all/.DS_Store
? sites/all/modules
? sites/all/themes
? sites/default/settings.php
? themes/.DS_Store
? themes/engines/.DS_Store
? themes/garland/.DS_Store
Index: modules/menu/menu.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu/menu.admin.inc,v
retrieving revision 1.7
diff -u -p -r1.7 menu.admin.inc
--- modules/menu/menu.admin.inc	17 Nov 2007 14:25:23 -0000	1.7
+++ modules/menu/menu.admin.inc	18 Nov 2007 02:41:45 -0000
@@ -162,7 +162,6 @@ function theme_menu_overview_form($form)
  * Menu callback; Build the menu link editing form.
  */
 function menu_edit_item(&$form_state, $type, $item, $menu) {
-
   $form['menu'] = array(
     '#type' => 'fieldset',
     '#title' => t('Menu settings'),
@@ -233,18 +232,13 @@ function menu_edit_item(&$form_state, $t
   );
 
   // Generate a list of possible parents (not including this item or descendants).
-  $options = menu_parent_options(menu_get_menus(), $item);
   $default = $item['menu_name'] .':'. $item['plid'];
   if (!isset($options[$default])) {
     $default = 'navigation:0';
   }
-  $form['menu']['parent'] = array(
-    '#type' => 'select',
-    '#title' => t('Parent item'),
-    '#default_value' => $default,
-    '#options' => $options,
-    '#description' => t('The maximum depth for an item and all its children is fixed at !maxdepth.  Some menu items may not be available as parents if selecting them would exceed this limit.', array('!maxdepth' => MENU_MAX_DEPTH)),
-    '#attributes' => array('class' => 'menu-title-select'),
+  $form['menu']['parents'] = array(
+    '#type' => 'menu_parent_select',
+    '#mlid' => $item['mlid'],
   );
   $form['menu']['weight'] = array(
     '#type' => 'weight',
@@ -293,11 +287,21 @@ function menu_item_delete_submit($form, 
 function menu_edit_item_submit($form, &$form_state) {
   $item = $form_state['values']['menu'];
   $item['options']['attributes']['title'] = $item['description'];
-  list($item['menu_name'], $item['plid']) = explode(':', $item['parent']);
+  $max_depth = -1;
+  $form = $form['menu']['parents']['parents'];
+  foreach (element_children($form) as $plid) {
+    $element = $form[$plid];
+    if (isset($element['select']) && $element['select']['#value'] > 0 && $element['#depth'] > $max_depth) {
+      $item['plid'] = $element['select']['#value'];
+      $max_depth = $element['#depth'];
+    }
+  }
   if (!menu_link_save($item)) {
     drupal_set_message(t('There was an error saving the menu link.'), 'error');
   }
   $form_state['redirect'] = 'admin/build/menu-customize/'. $item['menu_name'];
+  // As long as the storage is not empty, Form API rebuilds the form.
+  unset($form_state['storage']['mlid']);
 }
 
 /**
@@ -541,4 +545,3 @@ function menu_configure() {
 
   return system_settings_form($form);
 }
-
Index: modules/menu/menu.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/menu/menu.module,v
retrieving revision 1.148
diff -u -p -r1.148 menu.module
--- modules/menu/menu.module	17 Nov 2007 14:25:23 -0000	1.148
+++ modules/menu/menu.module	18 Nov 2007 02:41:45 -0000
@@ -136,7 +136,12 @@ function menu_menu() {
     'type' => MENU_CALLBACK,
     'file' => 'menu.admin.inc',
   );
-
+  $items['menu/js'] = array(
+    'title' => 'Menu JavaScript callback',
+    'page callback' => 'menu_form_js',
+    'access arguments' => array('administer menu'),
+    'type' => MENU_CALLBACK,
+  );
   return $items;
 }
 
@@ -189,55 +194,115 @@ function menu_load($menu_name) {
   return db_fetch_array(db_query("SELECT * FROM {menu_custom} WHERE menu_name = '%s'", $menu_name));
 }
 
+function menu_elements() {
+  $types['menu_parent_select'] = array(
+    '#process' => array('menu_parent_select_process'),
+    '#input' => TRUE,
+    // Does not really matter but we set a #value just in case someone themes
+    // this element.
+    '#value' => '',
+    '#tree' => TRUE,
+  );
+  return $types;
+}
+
 /**
- * Return a list of menu items that are valid possible parents for the given menu item.
- *
- * @param $menus
- *   An array of menu names and titles, such as from menu_get_menus().
- * @param $item
- *   The menu item for which to generate a list of parents.
- *   If $item['mlid'] == 0 then the complete tree is returned.
- * @return
- *   An array of menu link titles keyed on the a string containing the menu name
- *   and mlid. The list excludes the given item and its children.
+ * Creates a parent selector fieldset for a given menu link.
  */
-function menu_parent_options($menus, $item) {
-
-  // If the item has children, there is an added limit to the depth of valid parents.
-  if (isset($item['parent_depth_limit'])) {
-    $limit = $item['parent_depth_limit'];
+function menu_parent_select_process($form, $edit, &$form_state) {
+  static $js_included;
+  if (!isset($js_included)) {
+    drupal_add_js(drupal_get_path('module', 'menu') .'/menu.js');
+    drupal_add_css(drupal_get_path('module', 'menu') .'/menu.css');
+    $js_included = TRUE;
+  }
+  drupal_add_js(array('menuParents' => array($form['#id'])), 'setting');
+  
+  $form['#prefix'] = '<div id="'. $form['#id'] .'" class="menu-parent-select">';
+  $form['#suffix'] = '</div>';
+  
+  $original_mlid = $form['#mlid'];
+  if (isset($form_state['storage']['mlid'])) {
+    $mlid = $form_state['storage']['mlid'];
+    $collapsed = FALSE;
   }
   else {
-    $limit = _menu_parent_depth_limit($item);
+    $mlid = $original_mlid;
+    $collapsed = TRUE;
   }
-
-  foreach ($menus as $menu_name => $title) {
-    $tree = menu_tree_all_data($menu_name, NULL);
-    $options[$menu_name .':0'] = '<'. $title .'>';
-    _menu_parents_recurse($tree, $menu_name, '--', $options, $item['mlid'], $limit);
-  }
-  return $options;
+  $item = menu_link_load($mlid);
+  $tree = menu_tree_all_data($item['menu_name'], $item);
+  if (!$form) {var_export(debug_backtrace());}
+  $form = array_merge($form, array(
+    '#type' => 'fieldset',
+    '#title' => t('Parents'),
+    '#collapsible' => TRUE,
+    '#collapsed' => $collapsed,
+  ));
+  $form['parents'] = _menu_parent_select_recurse($tree, $original_mlid, TRUE);
+  $form['parent_submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Update'),
+    '#menu_parent_select' => &$form['parents'],
+    '#submit' => array('_menu_parent_selector_update'),
+    '#ahah' => array(
+      'path' => 'menu/js',
+      'wrapper' => $form['#id'],
+      'selector' => '#'. $form['#id'] .' select',
+    ),
+  );
+  return $form;
 }
-
-/**
- * Recursive helper function for menu_parent_options().
- */
-function _menu_parents_recurse($tree, $menu_name, $indent, &$options, $exclude, $depth_limit) {
-  foreach ($tree as $data) {
-    if ($data['link']['depth'] > $depth_limit) {
-      // Don't iterate through any links on this level.
-      break;
-    }
-    if ($data['link']['mlid'] != $exclude && $data['link']['hidden'] >= 0) {
-      $title = $indent .' '. truncate_utf8($data['link']['title'], 30, TRUE, FALSE);
-      if ($data['link']['hidden']) {
-        $title .= ' ('. t('disabled') .')';
+function _menu_parent_select_recurse($tree, $original_mlid, $reset = FALSE) {
+  static $form;
+  if ($reset) {
+    $form = array();
+  }
+  foreach ($tree as $item) {
+    if (isset($item['link'])) {
+      $link = $item['link'];
+      // Skip the current element and all its children.
+      if ($link['mlid'] == $original_mlid) {
+        continue;
       }
-      $options[$menu_name .':'. $data['link']['mlid']] = $title;
-      if ($data['below']) {
-        _menu_parents_recurse($data['below'], $menu_name, $indent .'--', $options, $exclude, $depth_limit);
+      if (!$link['hidden']) {
+        $plid = $link['plid'];
+        $mlid = $link['mlid'];
+        if (!isset($form[$plid])) {
+          $form[$plid]['select'] = array(
+            '#type' => 'select',
+            '#default_value' => -1,
+          );
+          $depth = $link['depth'];
+          if ($depth > 1) {
+            $form[$plid]['select']['#options'][-1] = t('Disregard this level');
+          }
+          $form[$plid]['#depth'] = $depth;
+        }
+        $form[$plid]['select']['#options'][$mlid] = $link['title'];
+        if ($link['in_active_trail']) {
+          $form[$plid]['select']['#default_value'] = $mlid;
+        }
       }
     }
+    if (!empty($item['below'])) {
+      _menu_parent_select_recurse($item['below'], $original_mlid);
+    }
+  }
+  return $form;
+}
+
+function _menu_parent_selector_update($form, &$form_state) {
+  // We took care to make our selects easily findable.
+  $form = $form_state['clicked_button']['#menu_parent_select'];
+  $min_depth = MENU_MAX_DEPTH + 1;
+  // We need the first element that was changed.
+  foreach (element_children($form) as $plid) {
+    $element = $form[$plid];
+    if (isset($element['select']) && $element['select']['#default_value'] != $element['select']['#value'] && $element['select']['#value'] > 0 && $element['#depth'] < $min_depth) {
+      $form_state['storage']['mlid'] = $element['select']['#value'];
+      $min_depth = $element['#depth'];
+    }
   }
 }
 
@@ -255,6 +320,23 @@ function menu_reset_item($item) {
 }
 
 /**
+ * Javascript callback for the menu form
+ */
+function menu_form_js() {
+  $cache = cache_get('form_'. $_POST['form_build_id'], 'cache_form');
+  $form = $cache->data;
+  
+  
+  // CHX - ALTER THE FORM HERE.  YOU HAVE $form BUT NO $form_state.
+  // ALSO $_POST HAS THE DATA/SELECTED ELEMENTS
+  
+  cache_set('form_'. $_POST['form_build_id'], $form, 'cache_form', $cache->expire);
+  $output = theme('status_messages') . drupal_render($choice_form);
+
+  drupal_json(array('status' => TRUE, 'data' => $output));
+}
+
+/**
  * Implementation of hook_block().
  */
 function menu_block($op = 'list', $delta = 0) {
