? .DS_Store
? ajaxify_hierarchy_selectors_00.patch
? includes/.DS_Store
Index: index.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/index/Attic/index.module,v
retrieving revision 1.1.2.28
diff -u -p -r1.1.2.28 index.module
--- index.module	26 Dec 2009 22:07:24 -0000	1.1.2.28
+++ index.module	27 Dec 2009 23:21:27 -0000
@@ -92,6 +92,13 @@ function index_menu() {
     'file' => 'index.admin.inc',
     'file path' => drupal_get_path('module', 'index') . '/includes',
   );
+  $items['admin/build/index/hierarchy'] = array(
+    'access arguments' => array('administer index'),
+    'page callback' => 'index_form_add_hierarchy',
+    'type' => MENU_CALLBACK,
+    'file' => 'index.admin.inc',
+    'file path' => drupal_get_path('module', 'index') . '/includes',
+  );
 
   // Create menu items for all index pages.
   $result = db_query("SELECT iid, title, description, page_path FROM {index_index} WHERE page_enabled = 1");
@@ -164,6 +171,11 @@ function index_theme($existing, $type, $
         'form' => array(),
       ),
     ),
+    'index_form_add_layers' => array(
+      'arguments' => array(
+        'form' => array(),
+      ),
+    ),
     'index_form_add_layer_depth' => array(
       'arguments' => array(
         'depth' => 0,
Index: css/index.admin.css
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/index/css/Attic/index.admin.css,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 index.admin.css
--- css/index.admin.css	22 Dec 2009 22:38:22 -0000	1.1.2.9
+++ css/index.admin.css	27 Dec 2009 23:21:27 -0000
@@ -51,6 +51,10 @@
 	cursor: pointer;
 	padding-left: 20px;
 }
+.index-form-add-layer-remove.disabled {
+  background-image: url('../images/remove_disabled.png');
+  color: #999;
+}
 
 /* Make sure textfields aren't too wide */
 #edit-title {
Index: images/remove_disabled.png
===================================================================
RCS file: images/remove_disabled.png
diff -N images/remove_disabled.png
Binary files /dev/null and remove_disabled.png differ
Index: includes/index.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/index/includes/Attic/index.admin.inc,v
retrieving revision 1.1.2.21
diff -u -p -r1.1.2.21 index.admin.inc
--- includes/index.admin.inc	26 Dec 2009 21:26:26 -0000	1.1.2.21
+++ includes/index.admin.inc	27 Dec 2009 23:21:28 -0000
@@ -52,7 +52,8 @@ function index_form_add(array $form_stat
   index_load_include('view');
 
   // TODO: Construct a new index if the form has been rebuilt, to prevent the
-  // unsaved changes from affecting index pages and blocks.
+  // unsaved changes from affecting index pages and blocks. Also store the
+  // index in the form, so it can be reused by hook_form_alter().
   // Cast the IID to an integer, because the menu system passes it on as a
   // string.
   $index = new index((int) $iid);
@@ -61,6 +62,7 @@ function index_form_add(array $form_stat
   }
 
   $form = array(
+    '#cache' => TRUE,
     '#redirect' => 'admin/build/index',
     '#suffix' => '<div id="index-form-add-preview-page" class="index-form-add-preview"><h2>' . t('Page preview') . '</h2><div class="content">' . index_preview($index, 'page') . '</div></div><div id="index-form-add-preview-block" class="index-form-add-preview"><h2>' . t('Block preview') . '</h2><div class="content">' . index_preview($index, 'block') . '</div></div>',
   );
@@ -236,26 +238,37 @@ function index_form_add_update(array $fo
  * Theme index_form_add().
  */
 function theme_index_form_add(array $form) {
+  // Theme layers and unset them so they aren't rendered twice.
+  $layers = theme('index_form_add_layers', $form['layers']);
+  unset($form['layers']);
+
+  return drupal_render($form['identification']) . drupal_render($form['create']) . $layers . drupal_render($form);
+}
+
+/**
+ * Theme index_form_add()'s hierarchy selectors.
+ */
+function theme_index_form_add_layers(array $form) {
   $rows = array();
-  foreach ($form['layers']['lineages']['#value'] as $lineage) {
+  foreach ($form['lineages']['#value'] as $lineage) {
     $depth = count(explode('_', $lineage)) - 1;
     $rows[] = array(
-      theme('indentation', $depth - 1) . theme('index_form_add_layer_depth', $depth) . (isset($form['layers']["layer_type_item-$lineage"]) ? drupal_render($form['layers']["layer_type_item-$lineage"]) : drupal_render($form['layers']["layer_type-$lineage"])),
+      theme('indentation', $depth - 1) . theme('index_form_add_layer_depth', $depth) . (isset($form["layer_type_item-$lineage"]) ? drupal_render($form["layer_type_item-$lineage"]) : drupal_render($form["layer_type-$lineage"])),
       array(
-        'data' => drupal_render($form['layers']["layer_entity_count_only-$lineage"]),
+        'data' => drupal_render($form["layer_entity_count_only-$lineage"]),
         'class' => 'checkbox',
       ),
       array(
-        'data' => drupal_render($form['layers']["layer_hide_childless_entities-$lineage"]),
+        'data' => drupal_render($form["layer_hide_childless_entities-$lineage"]),
         'class' => 'checkbox',
       ),
-      drupal_render($form['layers']["layer_child_add-$lineage"]),
-      drupal_render($form['layers']["layer_remove-$lineage"]),
+      drupal_render($form["layer_child_add-$lineage"]),
+      drupal_render($form["layer_remove-$lineage"]),
     );
   }
   $rows[] = array(
     array(
-      'data' => drupal_render($form['layers']['layer_child_add']),
+      'data' => drupal_render($form['layer_child_add']),
       'colspan' => 5,
     ),
   );
@@ -268,9 +281,10 @@ function theme_index_form_add(array $for
       'colspan' => 2,
     ),
   );
-  $layers = theme('table', $header, $rows, array('id' => 'index-form-add-layers'), t('Hierarchy'));
 
-  return drupal_render($form['identification']) . drupal_render($form['create']) . $layers . drupal_render($form);
+  $warning = isset($form['warning']) ? drupal_render($form['warning']) : NULL;
+
+  return '<div id="index-form-add-layers">' . theme('table', $header, $rows, array(), t('Hierarchy')) . $warning . '</div>';
 }
 
 /**
@@ -729,4 +743,27 @@ function index_form_import_submit(array 
   index_load_include('classes');
   $index = unserialize(file_get_contents($_FILES['files']['tmp_name']['file']));
   $index->insert();
+}
+
+/**
+ * Build the hierarchy selectors.
+ */
+function index_form_add_hierarchy() {
+  // Build a fake $form_state and get the form.
+  $form_state = array(
+    'storage' => NULL,
+    'submitted' => FALSE,
+  );
+  $form_build_id = $_POST['form_build_id'];
+  $form = form_get_cache($form_build_id, $form_state);
+
+  // Process and rebuild the form.
+  $args = $form['#parameters'];
+  $form_id = array_shift($args);
+  $form_state['post'] = $form['#post'] = $_POST;
+  $form['#programmed'] = $form['#redirect'] = FALSE;
+  drupal_process_form($form_id, $form, $form_state);
+  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
+
+  drupal_json(theme('index_form_add_layers', $form['layers']));
 }
\ No newline at end of file
Index: js/index.admin.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/index/js/Attic/index.admin.js,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 index.admin.js
--- js/index.admin.js	23 Dec 2009 12:00:01 -0000	1.1.2.10
+++ js/index.admin.js	27 Dec 2009 23:21:28 -0000
@@ -1,5 +1,7 @@
-Drupal.behaviors.indexAdmin = function (context) {
-  // Hide and show behavior for page- and block-specific settings.
+/**
+ * Hide and show behavior for page- and block-specific settings.
+ */
+Drupal.behaviors.indexAdminCreateAs = function (context) {
   if (!$('#edit-page-enabled').attr('checked')) {
     $('#index-page-settings').hide();
   }
@@ -12,9 +14,12 @@ Drupal.behaviors.indexAdmin = function (
   $('#edit-block-enabled').change(function () {
     $('#index-block-settings').slideToggle();
   });
+};
 
-  // Live preview.
-  // Preparatory work.
+/**
+ * Attach the eventhandlers for the AJAX live preview.
+ */
+Drupal.behaviors.indexAdminLivePreview = function (context) {
   var throbber = '<span class="index-throbber"></span>';
   $('#index-form-add-preview-page > h2').html(throbber + Drupal.t('Live page preview'));
   $('#index-form-add-preview-block > h2').html(throbber + Drupal.t('Live block preview'));
@@ -25,26 +30,59 @@ Drupal.behaviors.indexAdmin = function (
 		return false;
 	});
   // Execute the preview.
-  $('#index-form-add input, #index-form-add textarea, #index-form-add select').change(function () {
-    // Activate the throbber.
-    if ($('#edit-page-enabled:checked').length) {
-      $('#index-form-add-preview-page .index-throbber').addClass('throbbing');
-    }
-    if ($('#edit-block-enabled:checked').length) {
-      $('#index-form-add-preview-block .index-throbber').addClass('throbbing');
-    }
-    $.get(Drupal.settings.basePath + 'admin/build/index/preview?',
-      $('#index-form-add').serialize(),
-      function (data) {
-        $('.index-throbber').removeClass('throbbing');
-        if (data.page) {
-          $('#index-form-add-preview-page .content').html(data.page);
-        }
-        if (data.block) {
-          $('#index-form-add-preview-block .content').html(data.block);
-        }
-      },
-      'json'
-    );
-  });
-};
\ No newline at end of file
+  $('#index-form-add input, #index-form-add textarea, #index-form-add select').change(Drupal.indexAdminLivePreview);
+};
+    
+/**
+ * Live preview.
+ */
+Drupal.indexAdminLivePreview = function() {
+  // Activate the throbber.
+  if ($('#edit-page-enabled:checked').length) {
+    $('#index-form-add-preview-page .index-throbber').addClass('throbbing');
+  }
+  if ($('#edit-block-enabled:checked').length) {
+    $('#index-form-add-preview-block .index-throbber').addClass('throbbing');
+  }
+  $.get(Drupal.settings.basePath + 'admin/build/index/preview?',
+    $('#index-form-add').serialize(),
+    function (data, textStatus) {
+      $('.index-throbber').removeClass('throbbing');
+      if (data.page) {
+        $('#index-form-add-preview-page .content').html(data.page);
+      }
+      if (data.block) {
+        $('#index-form-add-preview-block .content').html(data.block);
+      }
+    },
+    'json'
+  );
+};
+
+/**
+ * Attach the eventhandler for the AJAX layer update.
+ */
+Drupal.behaviors.indexAdminLayerUpdate = function () {
+  $('.index-form-add-layer-child-add, .index-form-add-layer-remove').click(Drupal.indexAdminLayerUpdate);
+}
+
+/**
+ * AJAX layer update.
+ */
+Drupal.indexAdminLayerUpdate = function() {
+  // serialize() ignores disabled elements, so call it before disabling
+  // elements.
+  var values = $('#index-form-add').serialize();
+  $('#index-form-add-layers input, #index-form-add-layers select').attr('disabled', 'disabled').addClass('disabled');
+  $.post(Drupal.settings.basePath + 'admin/build/index/hierarchy',
+    values,
+    function (data, textStatus) {
+      $('#index-form-add-layers').replaceWith(data);
+      Drupal.behaviors.indexAdminLayerUpdate();
+      Drupal.behaviors.indexAdminLivePreview();
+    },
+    'json'
+  );
+
+  return false;
+}
\ No newline at end of file
