Browse Source

Fixed issue #285

Stephen Ficklin 7 years ago
parent
commit
06217513fb
2 changed files with 51 additions and 15 deletions
  1. 40 15
      tripal_chado/includes/tripal_chado.cv.inc
  2. 11 0
      tripal_chado/tripal_chado.module

+ 40 - 15
tripal_chado/includes/tripal_chado.cv.inc

@@ -105,13 +105,12 @@ function tripal_cv_cv_edit_form($form, &$form_state) {
     tripal_cv_add_cv_form_fields($form, $form_state, $cv_id);
 
     $form['update'] = array(
-      '#type'         => 'submit',
-      '#value'        => t('Update'),
+      '#type' => 'submit',
+      '#value' => t('Update'),
     );
     $form['delete'] = array(
-      '#type'         => 'submit',
-      '#value'        => t('Delete'),
-      '#attributes'   => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),
+      '#type' => 'markup',
+      '#markup' => l('delete', 'admin/tripal/loaders/chado_vocabs/chado_cv/delete/' . $cv_id),
     );
   }
   else {
@@ -273,16 +272,6 @@ function tripal_cv_cv_edit_form_submit($form, &$form_state) {
       drupal_set_message(t("Failed to update controlled vocabulary."));
     }
   }
-  if (strcmp($op, 'Delete')==0) {
-    $match = array('cv_id' => $cv_id);
-    $success = chado_delete_record('cv', $match);
-    if ($success) {
-      drupal_set_message(t("Controlled vocabulary deleted"));
-    }
-    else {
-      drupal_set_message(t("Failed to delete controlled vocabulary."));
-    }
-  }
 }
 
 /**
@@ -822,4 +811,40 @@ function tripal_cv_cvtermpath_form_submit($form, &$form_state) {
     tripal_add_job("Update cvtermpath: $cv->name", 'tripal_cv',
         'tripal_update_cvtermpath', $job_args, $user->uid, 10);
   }
+}
+
+/**
+ * A confirmation form for deleting a controlled vocabulary.
+ */
+function tripal_cv_cv_delete_form($form, &$form_state, $cv_id) {
+
+  $cv = tripal_get_cv(array('cv_id' => $cv_id));
+
+  $form['cv_id'] = array(
+    '#type' => 'value',
+    '#value' => $cv_id,
+  );
+
+  return confirm_form($form,
+    t('Confirm removal of the vocabulary: "' . $cv->name . '"? '),
+    'admin/tripal/loaders/chado_vocabs/chado_cv/edit/' . $cv_id,
+    t('WARNING: removal of a vocabulary will result in removal of all terms, and any associations used for other records in the site that use those terms.')
+  );
+}
+
+/**
+ * Implements the submit hook for tripal_cv_cv_delete_form.
+ */
+function tripal_cv_cv_delete_form_submit($form, &$form_state) {
+  $cv_id = $form_state['values']['cv_id'];
+
+  try {
+    $match = array('cv_id' => $cv_id);
+    $success = chado_delete_record('cv', $match);
+    drupal_set_message(t("Controlled vocabulary deleted"));
+    drupal_goto('admin/tripal/loaders/chado_vocabs/chado_cv');
+  }
+  catch (Exception $e) {
+    drupal_set_message(t("Failed to delete controlled vocabulary."), 'error');
+  }
 }

+ 11 - 0
tripal_chado/tripal_chado.module

@@ -606,6 +606,17 @@ function tripal_chado_menu() {
     'file path' => drupal_get_path('module', 'tripal_chado'),
     'type' => MENU_CALLBACK,
   );
+  $items['admin/tripal/loaders/chado_vocabs/chado_cv/delete/%'] = array(
+    'title' => 'Delete a Controlled Vocabulary',
+    'description' => 'Delete a controlled vocabulary.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_cv_cv_delete_form', 6),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer controlled vocabularies'),
+    'file' => 'includes/tripal_chado.cv.inc',
+    'file path' => drupal_get_path('module', 'tripal_chado'),
+    'type' => MENU_CALLBACK,
+  );
   $items['admin/tripal/loaders/chado_vocabs/chado_cv/add'] = array(
     'title' => 'Add a Controlled Vocabulary',
     'description' => 'Manually a new controlled vocabulary.',