Browse Source

Updates Create Template Form: added AHAH for field type change

laceysanderson 14 years ago
parent
commit
a2b0765498

+ 33 - 0
tripal_bulk_loader/tripal_bulk_loader.admin.inc

@@ -97,6 +97,8 @@ function tripal_bulk_loader_create_template_base_form (&$form_state = NULL) {
     $form['add_fields'] = array(
       '#type' => 'fieldset',
       '#title' => t('Step 2: Add Fields'),
+      '#prefix' => '<div id="tripal-bulk-loader-field">',
+      '#suffix' => '</div>',
     );
 
     $field_type = ($form_state['storage']['field_type'])? $form_state['storage']['field_type'] : 'column';
@@ -108,6 +110,11 @@ function tripal_bulk_loader_create_template_base_form (&$form_state = NULL) {
         'constant' => t('Field which remains Constant throughout the Spreadsheet'),
       ),
       '#default_value' => $field_type,
+      '#ahah' => array(
+        'path' => 'admin/tripal/tripal_bulk_loader_template/add/field_type_ahah',
+        'wrapper' => 'tripal-bulk-loader-field',
+        'effect' => 'fade'
+        ),
     );
     
     $form['add_fields']['field_title'] = array(
@@ -342,6 +349,32 @@ function tripal_bulk_loader_chado_column_ahah () {
   $output = theme('status_messages');
   $output .= drupal_render($form_element);
 
+  // Final rendering callback.
+  print drupal_json(array('status' => TRUE, 'data' => $output));
+  exit();
+}
+
+function tripal_bulk_loader_field_type_ahah () {
+
+  $form_state = array('storage' => NULL, 'submitted' => FALSE);
+  $form_build_id = $_POST['form_build_id'];
+  $form = form_get_cache($form_build_id, $form_state);
+  $args = $form['#parameters'];
+  $form_id = array_shift($args);
+  $form_state['post'] = $form['#post'] = $_POST;
+  // Enable the submit/validate handlers to determine whether AHAH-submittted.
+  $form_state['ahah_submission'] = TRUE;
+  $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);
+  
+  $form_element = $form['add_fields'];
+  // Remove the wrapper so we don't double it up.
+  unset($form_element['#prefix'], $form_element['#suffix']);
+
+  $output = theme('status_messages');
+  $output .= drupal_render($form_element);
+
   // Final rendering callback.
   print drupal_json(array('status' => TRUE, 'data' => $output));
   exit();

+ 7 - 1
tripal_bulk_loader/tripal_bulk_loader.module

@@ -37,9 +37,15 @@ function tripal_bulk_loader_menu() {
       'type' => MENU_NORMAL_ITEM,   
 		'file' => 'tripal_bulk_loader.admin.inc',
 	);
-		$items['admin/tripal/tripal_bulk_loader_template/add/chado_column_ahah'] = array(
+	$items['admin/tripal/tripal_bulk_loader_template/add/chado_column_ahah'] = array(
       'page callback' => 'tripal_bulk_loader_chado_column_ahah',
       'access arguments' => array('administer site configuration'),
+      'type' => MENU_CALLBACK,   
+		  'file' => 'tripal_bulk_loader.admin.inc',
+	);
+	$items['admin/tripal/tripal_bulk_loader_template/add/field_type_ahah'] = array(
+      'page callback' => 'tripal_bulk_loader_field_type_ahah',
+      'access arguments' => array('administer site configuration'),
       'type' => MENU_CALLBACK,   
 		  'file' => 'tripal_bulk_loader.admin.inc',
 	);