|  | @@ -371,6 +371,10 @@ function chado_data_form($form, &$form_state, $entity = NULL) {
 | 
	
		
			
				|  |  |        '#type'  => 'hidden',
 | 
	
		
			
				|  |  |        '#value' => $entity_id,
 | 
	
		
			
				|  |  |      );
 | 
	
		
			
				|  |  | +    $form['entity'] = array(
 | 
	
		
			
				|  |  | +      '#type'  => 'value',
 | 
	
		
			
				|  |  | +      '#value' => $entity,
 | 
	
		
			
				|  |  | +    );
 | 
	
		
			
				|  |  |      $form['record_id'] = array(
 | 
	
		
			
				|  |  |        '#type'  => 'hidden',
 | 
	
		
			
				|  |  |        '#value' => $entity->record_id,
 | 
	
	
		
			
				|  | @@ -435,17 +439,21 @@ function chado_data_form($form, &$form_state, $entity = NULL) {
 | 
	
		
			
				|  |  |        '#type'  => 'hidden',
 | 
	
		
			
				|  |  |        '#value' => $bundle_id,
 | 
	
		
			
				|  |  |      );
 | 
	
		
			
				|  |  | -    $form['cv_name_shown'] = array(
 | 
	
		
			
				|  |  | +    $form['details'] = array(
 | 
	
		
			
				|  |  | +      '#type' => 'fieldset',
 | 
	
		
			
				|  |  | +      '#title' => 'Record Type',
 | 
	
		
			
				|  |  | +      '#collapsable' => FALSE,
 | 
	
		
			
				|  |  | +      '#weight' => -100,
 | 
	
		
			
				|  |  | +    );
 | 
	
		
			
				|  |  | +    $form['details']['cv_name_shown'] = array(
 | 
	
		
			
				|  |  |        '#type' => 'item',
 | 
	
		
			
				|  |  |        '#title' => 'Vocabulary',
 | 
	
		
			
				|  |  |        '#markup' => $cvterm->cv_id->name,
 | 
	
		
			
				|  |  | -      '#weight' => -100,
 | 
	
		
			
				|  |  |      );
 | 
	
		
			
				|  |  | -    $form['term_name_shown'] = array(
 | 
	
		
			
				|  |  | +    $form['details']['term_name_shown'] = array(
 | 
	
		
			
				|  |  |        '#type' => 'item',
 | 
	
		
			
				|  |  | -      '#title' => 'Record Type',
 | 
	
		
			
				|  |  | +      '#title' => 'Term',
 | 
	
		
			
				|  |  |        '#markup' => $cvterm->name,
 | 
	
		
			
				|  |  | -      '#weight' => -100,
 | 
	
		
			
				|  |  |      );
 | 
	
		
			
				|  |  |  /*
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -528,14 +536,29 @@ function chado_data_form($form, &$form_state, $entity = NULL) {
 | 
	
		
			
				|  |  |      $form['#parents'] = array('attached');
 | 
	
		
			
				|  |  |      field_attach_form('chado_data', $entity, $form, $form_state);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    $form['submit'] = array(
 | 
	
		
			
				|  |  | -      '#type' => 'submit',
 | 
	
		
			
				|  |  | -      '#value' => t('Add a new ' . $cvterm->name),
 | 
	
		
			
				|  |  | -      '#name' => 'add_data',
 | 
	
		
			
				|  |  | -      '#weight' => 1000
 | 
	
		
			
				|  |  | -    );
 | 
	
		
			
				|  |  | +    if (!$entity_id) {
 | 
	
		
			
				|  |  | +      $form['submit'] = array(
 | 
	
		
			
				|  |  | +        '#type' => 'submit',
 | 
	
		
			
				|  |  | +        '#value' => t('Add a new ' . $cvterm->name),
 | 
	
		
			
				|  |  | +        '#name' => 'add_data',
 | 
	
		
			
				|  |  | +        '#weight' => 1000
 | 
	
		
			
				|  |  | +      );
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    else {
 | 
	
		
			
				|  |  | +      $form['submit'] = array(
 | 
	
		
			
				|  |  | +        '#type' => 'submit',
 | 
	
		
			
				|  |  | +        '#value' => t('Update'),
 | 
	
		
			
				|  |  | +        '#name' => 'update_data',
 | 
	
		
			
				|  |  | +        '#weight' => 1000
 | 
	
		
			
				|  |  | +      );
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +  $form['cancel'] = array(
 | 
	
		
			
				|  |  | +    '#type' => 'submit',
 | 
	
		
			
				|  |  | +    '#value' => t('Cancel'),
 | 
	
		
			
				|  |  | +    '#name' => 'cancel',
 | 
	
		
			
				|  |  | +    '#weight' => 1000
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  |    $form['#prefix'] = '<div id="chado_data_form">';
 | 
	
		
			
				|  |  |    $form['#suffix'] = '</div>';
 | 
	
		
			
				|  |  |    return $form;
 | 
	
	
		
			
				|  | @@ -811,10 +834,11 @@ function chado_data_form_ajax_callback($form, $form_state) {
 | 
	
		
			
				|  |  |   * Implements hook_validate() for the chado_data_form.
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  function chado_data_form_validate($form, &$form_state) {
 | 
	
		
			
				|  |  | -   if ($form_state['clicked_button']['#name'] == 'add_data') {
 | 
	
		
			
				|  |  | -     $chado_data = (object) $form_state['values'];
 | 
	
		
			
				|  |  | -     field_attach_form_validate('chado_data', $chado_data, $form, $form_state);
 | 
	
		
			
				|  |  | -   }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  if ($form_state['clicked_button']['#name'] == 'add_data') {
 | 
	
		
			
				|  |  | +    $chado_data = (object) $form_state['values'];
 | 
	
		
			
				|  |  | +    field_attach_form_validate('chado_data', $chado_data, $form, $form_state);
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -822,6 +846,16 @@ function chado_data_form_validate($form, &$form_state) {
 | 
	
		
			
				|  |  |   *
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  function chado_data_form_submit($form, &$form_state) {
 | 
	
		
			
				|  |  | +  if ($form_state['clicked_button']['#name'] == 'cancel') {
 | 
	
		
			
				|  |  | +    if (array_key_exists('entity_id', $form_state['values'])){
 | 
	
		
			
				|  |  | +      $entity = $form_state['values']['entity'];
 | 
	
		
			
				|  |  | +      $form_state['redirect'] = "chado_data/$entity->entity_id";
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    else {
 | 
	
		
			
				|  |  | +      $form_state['redirect'] = "admin/structure/chado_data/manage";
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    return;
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  |    if ($form_state['clicked_button']['#name'] == 'select_cvterm') {
 | 
	
		
			
				|  |  |      // don't do anything, we just need to know what the term name is.
 | 
	
		
			
				|  |  |      $form_state['rebuild'] = TRUE;
 |