Bladeren bron

Chado Node API: Moved into vertical tabs and added summary text.

Lacey Sanderson 10 jaren geleden
bovenliggende
commit
ba36bef2b8

+ 44 - 8
tripal_core/api/tripal_core.chado_nodes.dbxrefs.api.inc

@@ -125,7 +125,7 @@
 function chado_add_node_form_dbxrefs(&$form, &$form_state, $details) {
 
   // Set defaults for optional fields
-  $details['fieldset_title'] = 'Additional Database References';
+  $details['fieldset_title'] = 'External References';
   $details['additional_instructions'] = '';
 
   // Get the list of databases to display in the dropdown.
@@ -156,6 +156,16 @@ function chado_add_node_form_dbxrefs(&$form, &$form_state, $details) {
     array('return_html' => TRUE)
   );
 
+  // Group all of the chado node api fieldsets into vertical tabs.
+  $form['chado_node_api'] = array(
+    '#type' => 'vertical_tabs',
+    '#attached' => array(
+      'css' => array(
+        'chado-node-api' => drupal_get_path('module', 'tripal_core') . '/theme/css/chado_node_api.css',
+      ),
+    ),
+  );
+
   // the fieldset of the dbxref elements
   $form['addtl_dbxrefs'] = array(
     '#type' => 'fieldset',
@@ -164,9 +174,16 @@ function chado_add_node_form_dbxrefs(&$form, &$form_state, $details) {
       selecting a database reference type from the dropdown and adding text.  You may add
       as many database references as desired by clicking the add button on the right.  To
       remove a database reference, click the remove button. ' . $details['additional_instructions']),
-    '#prefix' => "<div id='addtl-dbxrefs-fieldset'>",
-    '#suffix' => '</div>',
-    '#weight'      => 9
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#group' => 'chado_node_api',
+    '#weight'      => 9,
+    '#attributes' => array('class' => array('chado-node-api','dbxrefs')),
+    '#attached' => array(
+      'js' => array(
+        'chado-node-api-vertical-tabs' => drupal_get_path('module', 'tripal_core') . '/theme/js/chadoNodeApi_updateVerticalTabSummary.js',
+      ),
+    ),
   );
 
   $form['addtl_dbxrefs']['admin_message'] = array(
@@ -245,18 +262,29 @@ function chado_add_node_form_dbxrefs(&$form, &$form_state, $details) {
    * Loop on the array elements of the $existing_dbxrefs array and add
    * an element to the form for each one.
    */
+  $num_dbxrefs = 0;
   foreach ($existing_dbxrefs as $dbxref) {
-
     if (array_key_exists($dbxref->db_id, $db_options)) {
+      $num_dbxrefs++;
 
       $form['addtl_dbxrefs']['dbxref_table'][$dbxref->db_id]['#type'] = 'markup';
       $form['addtl_dbxrefs']['dbxref_table'][$dbxref->db_id]['#value'] = '';
 
-      $form['addtl_dbxrefs']['dbxref_table'][$dbxref->db_id][$dbxref->dbxref_id] = array(
-        '#type' => 'markup',
-        '#value' => ''
+      $form['addtl_dbxrefs']['dbxref_table'][$dbxref->db_id][$dbxref->dbxref_id]['#type'] = 'markup';
+      $form['addtl_dbxrefs']['dbxref_table'][$dbxref->db_id][$dbxref->dbxref_id]['#value'] = '';
+      $form['addtl_dbxrefs']['dbxref_table'][$dbxref->db_id][$dbxref->dbxref_id]['#attributes'] = array(
+        'class' => array('dbxref', 'saved')
       );
 
+      // Determine whether this dbxref is unsaved or not.
+      // We can tell this by looking at the dbxref_id: if it's not
+      // saved yet we will have entered a TEMP###.
+      if (preg_match('/^TEMP/', $dbxref->dbxref_id)) {
+        $form['addtl_dbxrefs']['dbxref_table'][$dbxref->db_id][$dbxref->dbxref_id]['#attributes'] = array(
+          'class' => array('dbxref', 'unsaved')
+        );
+      }
+
       $form['addtl_dbxrefs']['dbxref_table'][$dbxref->db_id][$dbxref->dbxref_id]['db_id'] = array(
         '#type' => 'hidden',
         '#value' => $dbxref->db_id
@@ -322,6 +350,13 @@ function chado_add_node_form_dbxrefs(&$form, &$form_state, $details) {
     }
   }
 
+  // Quickly add a hidden field stating how many dbxrefs are currently added.
+  $form['addtl_dbxrefs']['num_dbxrefs'] = array(
+    '#type' => 'hidden',
+    '#value' => $num_dbxrefs,
+    '#attributes' => array('class' => 'num-dbxrefs')
+  );
+
   // Form elements for adding a new dbxref
   //---------------------------------------------
   $form['addtl_dbxrefs']['dbxref_table']['new'] = array(
@@ -542,6 +577,7 @@ function theme_chado_add_node_form_dbxrefs_table($variables) {
         $row = array();
 
         $row['data'] = array();
+        $row['class'] = $element[$db_id][$version]['#attributes']['class'];
         foreach ($header as $fieldname => $title) {
           $row['data'][] = drupal_render($element[$db_id][$version][$fieldname]);
         }

+ 43 - 4
tripal_core/api/tripal_core.chado_nodes.properties.api.inc

@@ -310,6 +310,16 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
     );
   }
 
+  // Group all of the chado node api fieldsets into vertical tabs.
+  $form['chado_node_api'] = array(
+    '#type' => 'vertical_tabs',
+    '#attached' => array(
+      'css' => array(
+        'chado-node-api' => drupal_get_path('module', 'tripal_core') . '/theme/css/chado_node_api.css',
+      ),
+    ),
+  );
+
   // the fieldset of the property elements
   $form['properties'] = array(
     '#type' => 'fieldset',
@@ -317,9 +327,16 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
     '#description' => t('Add properties by selecting a type
       from the dropdown, enter a value and click the "Add" button. To
       remove a property, click the remove button.' . $details['additional_instructions']),
-    '#prefix' => "<div id='properties-fieldset'>",
-    '#suffix' => '</div>',
-    '#weight'      => 8
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#group' => 'chado_node_api',
+    '#weight'      => 8,
+    '#attributes' => array('class' => array('chado-node-api','properties')),
+    '#attached' => array(
+      'js' => array(
+        'chado-node-api-vertical-tabs' => drupal_get_path('module', 'tripal_core') . '/theme/js/chadoNodeApi_updateVerticalTabSummary.js',
+      ),
+    ),
   );
 
   $form['properties']['admin_message'] = array(
@@ -435,14 +452,28 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
    * an element to the form for each one as long as it's also in the
    * $properties_options array.
    */
+  $num_properties = 0;
   foreach ($existing_properties as $property) {
     if (array_key_exists($property->type_id, $property_options)) {
+      $num_properties++;
 
       $form['properties']['property_table'][$property->type_id]['#type'] = 'markup';
       $form['properties']['property_table'][$property->type_id]['#value'] = '';
 
       $form['properties']['property_table'][$property->type_id][$property->property_id]['#type'] = 'markup';
       $form['properties']['property_table'][$property->type_id][$property->property_id]['#value'] = '';
+      $form['properties']['property_table'][$property->type_id][$property->property_id]['#attributes'] = array(
+        'class' => array('property', 'saved')
+      );
+
+      // Determine whether this property is unsaved or not.
+      // We can tell this by looking at the property_id: if it's not
+      // saved yet we will have entered a TEMP###.
+      if (preg_match('/^TEMP/', $property->property_id)) {
+        $form['properties']['property_table'][$property->type_id][$property->property_id]['#attributes'] = array(
+          'class' => array('property', 'unsaved')
+        );
+      }
 
       $form['properties']['property_table'][$property->type_id][$property->property_id]['prop_type_id'] = array(
         '#type' => 'hidden',
@@ -509,11 +540,18 @@ function chado_add_node_form_properties(&$form, &$form_state, $details) {
         // added form).
         '#limit_validation_errors' => array(
           array('property_table')  // Validate all fields within $form_state['values']['property_table']
-        )
+        ),
       );
     }
   }
 
+  // Quickly add a hidden field stating how many properties are currently added.
+  $form['properties']['num_properties'] = array(
+    '#type' => 'hidden',
+    '#value' => $num_properties,
+    '#attributes' => array('class' => 'num-properties')
+  );
+
   // Form elements for adding a new property
   //---------------------------------------------
   $form['properties']['property_table']['new'] = array(
@@ -753,6 +791,7 @@ function theme_chado_add_node_form_properties($variables) {
         $row = array();
 
         $row['data'] = array();
+        $row['class'] = $element[$type_id][$version]['#attributes']['class'];
         foreach ($header as $fieldname => $title) {
           $row['data'][] = drupal_render($element[$type_id][$version][$fieldname]);
         }

+ 44 - 3
tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -275,12 +275,29 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
     );
   }
 
+  // Group all of the chado node api fieldsets into vertical tabs.
+  $form['chado_node_api'] = array(
+    '#type' => 'vertical_tabs',
+    '#attached' => array(
+      'css' => array(
+        'chado-node-api' => drupal_get_path('module', 'tripal_core') . '/theme/css/chado_node_api.css',
+      ),
+    ),
+  );
+
   $form['relationships'] = array(
     '#type' => 'fieldset',
     '#title' => t($details['fieldset_title']),
-    '#prefix' => "<div id='relationships-fieldset'>",
-    '#suffix' => '</div>',
-    '#weight'      => 10
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#group' => 'chado_node_api',
+    '#weight'      => 10,
+    '#attributes' => array('class' => array('chado-node-api','relationships')),
+    '#attached' => array(
+      'js' => array(
+        'chado-node-api-vertical-tabs' => drupal_get_path('module', 'tripal_core') . '/theme/js/chadoNodeApi_updateVerticalTabSummary.js',
+      ),
+    ),
   );
 
   $form['relationships']['descrip'] = array(
@@ -384,14 +401,28 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
    * Loop on the array elements of the $existing_rels array and add
    * an element to the form for each one.
    */
+  $num_relationships = 0;
   foreach ($existing_rels as $relationship) {
     if (array_key_exists($relationship->type_id, $type_options)) {
+      $num_relationships++;
 
       $form['relationships']['relationship_table'][$relationship->type_id]['#type'] = 'markup';
       $form['relationships']['relationship_table'][$relationship->type_id]['#type'] = '';
 
       $form['relationships']['relationship_table'][$relationship->type_id][$relationship->relationship_id]['#type'] = 'markup';
       $form['relationships']['relationship_table'][$relationship->type_id][$relationship->relationship_id]['#value'] = '';
+      $form['relationships']['relationship_table'][$relationship->type_id][$relationship->relationship_id]['#attributes'] = array(
+        'class' => array('relationship', 'saved')
+      );
+
+      // Determine whether this relationship is unsaved or not.
+      // We can tell this by looking at the relationship_id: if it's not
+      // saved yet we will have entered a TEMP###.
+      if (preg_match('/^TEMP/', $relationship->relationship_id)) {
+        $form['relationships']['relationship_table'][$relationship->type_id][$relationship->relationship_id]['#attributes'] = array(
+          'class' => array('relationship', 'unsaved')
+        );
+      }
 
       $form['relationships']['relationship_table'][$relationship->type_id][$relationship->relationship_id]['relationship_id'] = array(
         '#type' => 'markup',
@@ -463,6 +494,15 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
     }
   }
 
+  // Quickly add a hidden field stating how many relationships are currently added.
+  $form['relationships']['num_relationships'] = array(
+    '#type' => 'hidden',
+    '#value' => $num_relationships,
+    '#attributes' => array('class' => 'num-relationships')
+  );
+
+  // Form elements for adding a new relationship
+  //---------------------------------------------
   $form['relationships']['relationship_table']['new']['object_name'] = array(
     '#type' => 'textfield',
     '#autocomplete_path' => 'tripal_ajax/relationship_nodeform/' . $details['base_table'] . '/' . $details['base_name_field'].'/name_to_id'
@@ -823,6 +863,7 @@ function theme_chado_add_node_form_relationships_table($variables) {
         $row = array();
 
         $row['data'] = array();
+        $row['class'] = $element[$type_id][$rank]['#attributes']['class'];
         foreach ($header as $fieldname => $title) {
           $row['data'][] = drupal_render($element[$type_id][$rank][$fieldname]);
         }

+ 11 - 0
tripal_core/theme/css/chado_node_api.css

@@ -0,0 +1,11 @@
+
+.chado-node-api.new {
+  color: #3A7127;
+  font-style: italic;
+  font-weight: bold;
+}
+.chado-node-api.removed {
+  color: #680000;
+  font-style: italic;
+  font-weight: bold;
+}

+ 90 - 0
tripal_core/theme/js/chadoNodeApi_updateVerticalTabSummary.js

@@ -0,0 +1,90 @@
+
+(function ($) {
+
+  Drupal.behaviors.chadoNodeApiFieldsetSummaries = {
+    attach: function (context) {
+    	
+      // Properties Tab
+      $('fieldset.chado-node-api.properties', context).drupalSetSummary(function (context) {
+        return ChadoNodeApi_getSummary({
+          machineName: {
+            plural: 'properties',
+            singular:'property'
+          },
+          readableName: {
+            plural: 'properties',
+            singular:'property'
+          }
+        });
+      });
+
+      // External References Tab
+      $('fieldset.chado-node-api.dbxrefs', context).drupalSetSummary(function (context) {
+        return ChadoNodeApi_getSummary({
+          machineName: {
+            plural: 'dbxrefs',
+            singular:'dbxref'
+          },
+          readableName: {
+            plural: 'references',
+            singular:'reference'
+          }
+        });
+      });
+ 
+      // Relationships Tab
+      $('fieldset.chado-node-api.relationships', context).drupalSetSummary(function (context) {
+        return ChadoNodeApi_getSummary({
+          machineName: {
+            plural: 'relationships',
+            singular:'relationship'
+          },
+          readableName: {
+            plural: 'relationships',
+            singular:'relationship'
+          }
+        });
+      });
+
+      function ChadoNodeApi_getSummary(api) {
+
+        var numCurrent = $('tr.' + api.machineName.singular).length;
+        var numOriginal = $('input.num-' + api.machineName.plural, context).val();
+        var numSaved = $('tr.saved.' + api.machineName.singular).length;
+        var numUnsaved = $('tr.unsaved.' + api.machineName.singular).length;
+        var numRemoved = numOriginal - numSaved;
+
+
+        // If there are no rows then tell the user that.
+        if (numCurrent == 0) {
+          if (numRemoved == 0) {
+            return Drupal.t('No ' + api.readableName.plural);
+          }
+          else {
+            return Drupal.t('No ' + api.readableName.plural + ' (<span class="chado-node-api removed">' + numRemoved + ' removed</span>)');
+          }
+        }
+        // Otherwise, give them a breakdown of the current, new and removed rows
+        // NOTE: Removed rows include only those that were original and have since been removed.
+        else {
+          var apiReadable = api.readableName.plural;
+          if (numCurrent == 1) {
+            apiReadable = api.readableName.singular;
+          }
+
+          if (numUnsaved != 0 && numRemoved != 0) {
+            return Drupal.t(numCurrent + ' ' + apiReadable + ' (<span class="chado-node-api new">' + numUnsaved + ' new</span>; <span class="chado-node-api removed">' + numRemoved + ' removed</span>)');
+          }
+          else if (numRemoved != 0) {
+            return Drupal.t(numCurrent + ' ' + apiReadable + ' (<span class="chado-node-api removed">' + numRemoved + ' removed</span>)');
+          }
+          else if (numUnsaved != 0) {
+            return Drupal.t(numCurrent + ' ' + apiReadable + ' (<span class="chado-node-api new">' + numUnsaved + ' new</span>)');
+          }
+          else {
+            return Drupal.t(numCurrent + ' ' + apiReadable);
+          }
+        }
+      }
+  }};
+})(jQuery);