Browse Source

Merge branch '7.x-3.x' of https://github.com/tripal/tripal into 7.x-3.x

Lacey Sanderson 8 years ago
parent
commit
86d63c4b9f

+ 2 - 2
tripal/includes/TripalEntity.inc

@@ -512,8 +512,8 @@ function tripal_entity_form_ajax_callback($form, $form_state) {
 
    // If the user is cancelling or deleting the entity then don't validate.
    if (array_key_exists('clicked_button', $form_state) and
-       $form_state['clicked_button']['#name'] =='cancel_data' or
-       $form_state['clicked_button']['#name'] =='delete_data') {
+       ($form_state['clicked_button']['#name'] == 'cancel_data' or
+        $form_state['clicked_button']['#name'] == 'delete_data')) {
      return;
    }
    // For adds and updates, perform validation.

+ 0 - 4
tripal/includes/TripalFieldQuery.inc

@@ -56,10 +56,6 @@ class TripalField {
     // is convenient for speed.  Fields that are slow should for loading
     // should ahve auto_attach set to FALSE so tha their values can be
     // attached asyncronously.
-    'auto_attach' => TRUE,
-    // Set to TRUE to turn on paging capabilities.  Implementations of
-    // a new field should honor this setting when loading results and
-    // when formatting for dipslay.
   );
 
   // The default widget for this field.

+ 4 - 5
tripal/includes/TripalFields/TripalFieldFormatter.inc

@@ -172,13 +172,12 @@ class TripalFieldFormatter {
    */
   protected function ajaxifyPager($pager, $entity) {
 
-    global $base_path;
-
-    $tmp_base_path = preg_replace('/\//', '\/', $base_path);
     $field_id = 'tripal-entity-' . $entity->id . '--' . $this->field['field_name'];
-    $pager = preg_replace('/href="' . $tmp_base_path . 'bio_data\/ajax\/field_attach\/' . $field_id . '\?page=(.+?)"/', 'href="javascript:void(0)" onclick="tripal_navigate_field_pager(\'' . $field_id . '\', $1)"', $pager);
-    $pager = preg_replace('/href="' . $tmp_base_path . 'bio_data\/ajax\/field_attach\/' . $field_id . '"/', 'href="javascript:void(0)" onclick="tripal_navigate_field_pager(\'' . $field_id . '\', 0)"', $pager);
 
+    $pager = preg_replace('/href="\/.+\?page=(.+?)"/', 'href="javascript:void(0)" onclick="tripal_navigate_field_pager(\'' . $field_id . '\', $1)"', $pager);
+    $pager = preg_replace('/href="\/.+"/', 'href="javascript:void(0)" onclick="tripal_navigate_field_pager(\'' . $field_id . '\', 0)"', $pager);
+
+    $pager = '<img src="/' . drupal_get_path('module', 'tripal') . '/theme/images/ajax-loader.gif" id="' . $field_id . '-spinner" class="tripal-field-ajax-spinner">' . $pager;
     return $pager;
   }
 

+ 4 - 2
tripal/includes/tripal.entity.inc

@@ -328,11 +328,13 @@ function tripal_entity_view($entity, $type, $view_mode, $langcode) {
       // the field.
       $instance = field_info_instance('TripalEntity', $child_name, $entity->bundle);
       if ($instance and array_key_exists('settings', $instance)) {
+        $class = '';
         if (array_key_exists('auto_attach', $instance['settings']) and
             $instance['settings']['auto_attach'] == FALSE) {
-          $entity->content[$child_name]['#prefix'] .= '<div id="tripal-entity-' . $entity->id . '--' . $child_name . '" class="tripal-entity-unattached">';
-          $entity->content[$child_name]['#suffix'] .= '</div>';
+          $class = 'class="tripal-entity-unattached"';
         }
+        $entity->content[$child_name]['#prefix'] .= '<div id="tripal-entity-' . $entity->id . '--' . $child_name . '" ' . $class . '>';
+        $entity->content[$child_name]['#suffix'] .= '</div>';
       }
     }
   }

+ 2 - 4
tripal/includes/tripal.field_storage.inc

@@ -72,9 +72,7 @@ div.messages.tripal-site-admin-only{
 /******************************************************************************
  * Spinner for paginated elements
  *****************************************************************************/
- #spinner {
-   position: absolute;
+ .tripal-field-ajax-spinner {
    display: none;
-   left: 24%;
-   bottom: 7%;
+   float: left;
  }

+ 8 - 7
tripal/theme/js/tripal.js

@@ -23,14 +23,15 @@
 
 })(jQuery);
 
+// Used for ajax update of fields by links in a pager.
 function tripal_navigate_field_pager(id, page) {
-    jQuery(document).ajaxStart(function () {
-        jQuery('#spinner').show();
-    }).ajaxComplete(function () {
-        jQuery('#spinner').hide();
-    });
+  jQuery(document).ajaxStart(function () {
+    jQuery('#' + id + '-spinner').show();
+  }).ajaxComplete(function () {
+    jQuery('#' + id + '-spinner').hide();
+  });
 
-    jQuery.ajax({
+  jQuery.ajax({
     type: "GET",
     url: Drupal.settings["basePath"] + "bio_data/ajax/field_attach/" + id,
     data: { 'page' : page },
@@ -38,4 +39,4 @@ function tripal_navigate_field_pager(id, page) {
       jQuery("#" + id + ' .field-items').replaceWith(response['content']);
     }
   });
-}
+}

+ 19 - 7
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship.inc

@@ -35,12 +35,22 @@ class sbo__relationship extends ChadoField {
     // type. This will create form elements when editing the field instance
     // to allow the site admin to change the term settings above.
     'term_fixed' => FALSE,
+    // Inidates if this field should be automatically attached to display
+    // or web services or if this field should be loaded separately. This
+    // is convenient for speed.  Fields that are slow should for loading
+    // should ahve auto_attach set to FALSE so tha their values can be
+    // attached asyncronously.
+    'auto_attach' => FALSE,
+    // Settings to help the site admin control how relationship types and
+    // valid subject/objects can be selected by the user.
     'relationships' => array(
       'option1_vocabs' => '',
       'option2_vocab' => '',
       'option2_parent' => '',
       'relationship_types' => '',
     ),
+    // The number of items to show on a page.
+    'items_per_page' => 10,
   );
 
   // The default widget for this field.
@@ -175,11 +185,6 @@ class sbo__relationship extends ChadoField {
     if (array_key_exists('rank', $schema['fields'])) {
       $options['order_by'] = array('rank' => 'ASC');
     }
-    // We want a pager for relationships.
-    $options['pager'] = array(
-      'limit' => 25,
-      'element' => $this->getPagerElementID(),
-    );
     $record = chado_expand_var($record, 'table', $rel_table, $options);
     if (!$record->$rel_table) {
       return;
@@ -521,9 +526,16 @@ class sbo__relationship extends ChadoField {
    *
    * @see TripalField::settingsForm()
    */
-  public function settingsForm($has_data) {
+  public function instanceSettingsForm() {
     $element = parent::instanceSettingsForm();
 
+    $element['items_per_page'] = array(
+      '#type' => 'textfield',
+      '#title' => 'Items per Page',
+      '#description' => t('The number of items that should appear on each page.  A pager is provided if more than this number of items exist.'),
+      '#default_value' => $this->instance['settings']['items_per_page'],
+    );
+
     //$element = parent::instanceSettingsForm();
     $element['relationships'] = array(
       '#type' => 'fieldset',
@@ -609,7 +621,7 @@ class sbo__relationship extends ChadoField {
    * @param unknown $form
    * @param unknown $form_state
    */
-  public function settingsFormValidate($form, &$form_state) {
+  public function instanceSettingsFormValidate($form, &$form_state) {
     // Get relationships settings
     $settings = $form_state['values']['instance']['settings']['relationships'];
     $form_state['values']['instance']['settings']['relationships']['relationship_types']= trim($settings['relationship_types']);

+ 23 - 16
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -100,20 +100,30 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       );
     }
 
-    //$pager = $this->generate_pager(count($rows), $per_page);
-    // Get the total number of records from the pager query.
-    $total_records = chado_pager_get_count($this->getPagerElementID());
+    // Build the pager
+    $items_per_page = array_key_exists('items_per_page', $this->instance['settings']) ? $this->instance['settings']['items_per_page'] : 10;
+    $total_records = count($items);
+    $total_pages = (int) ($total_records / $items_per_page) + 1;
+    $pelement = 0; //$this->getPagerElementID();
+    $current_page = pager_default_initialize($total_records, $items_per_page, $pelement);
     $pager = theme('pager', array(
       'tags' => array(),
-      'element' => $this->getPagerElementID(),
+      'element' => $pelement,
       'parameters' => array(),
-      'quantity' => ($total_records / 25) + 1,
+      'quantity' => $total_pages,
     ));
     $pager = $this->ajaxifyPager($pager, $entity);
+    $page_items = array_chunk($rows, $items_per_page);
 
-    $table = theme_table(array(
+    if (count($items) == 1) {
+      $content = 'There is ' . count($items) . ' relationship.';
+    }
+    else {
+      $content = 'There are ' . count($items) . ' relationships.';
+    }
+    $content .= theme_table(array(
       'header' => $headers,
-      'rows' => $rows, //$current_page ? $chunks[$current_page] : array(),
+      'rows' => $page_items[$current_page],
       'attributes' => array(
         'id' => 'sbo--relationship-table',
       ),
@@ -123,14 +133,11 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       'empty' => $settings['empty'],
     ));
 
-    // Once we have our table array structure defined, we call Drupal's theme_table()
-    // function to generate the table.
-    if (count($items) > 0) {
-      $element[0] = array(
-        '#type' => 'markup',
-        '#markup' => $table . $pager,
-        '#suffix' => '<img src=\'/sites/all/modules/tripal-7.x-3.x/tripal/theme/images/ajax-loader.gif\' id=\'spinner\'/>' . $pager,
-      );
-    }
+    $element[0] = array(
+      '#type' => 'markup',
+      '#markup' => $content . $pager,
+    );
   }
 }
+
+

+ 6 - 2
tripal_chado/includes/TripalFields/schema__publication/schema__publication_formatter.inc

@@ -22,8 +22,12 @@ class schema__publication_formatter extends ChadoFieldFormatter {
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
     $list_items = array();
     $chado_table = $this->instance['settings']['chado_table'];
+
     foreach ($items as $delta => $item) {
 
+      if (empty($item['value'])) {
+        continue;
+      }
       $title = isset($item['value']['TPUB:0000039']) ? $item['value']['TPUB:0000039'] : '';
       $citation = isset($item['value']['TPUB:0000003']) ? $item['value']['TPUB:0000003'] : '';
       $entity = array_key_exists('entity', $item['value']) ? $item['value']['entity'] : '';
@@ -39,10 +43,10 @@ class schema__publication_formatter extends ChadoFieldFormatter {
       $list_items[] = $citation;
     }
 
+    $list = '';
     krsort($list_items, SORT_NUMERIC);
-
     if (count($list_items) == 0) {
-      $list = 'There are no publications.';
+      $list = 'There are no publications associated with this record.';
     }
     if (count($list_items) == 1) {
       $list = $list_items[0];

+ 2 - 4
tripal_chado/includes/TripalFields/schema__publication/schema__publication_widget.inc

@@ -25,15 +25,13 @@ class schema__publication_widget extends ChadoFieldWidget {
     $fkey = $fkeys[0];
 
     // Get the field defaults.
-    $record_id = '';
-    $fkey_value = array_key_exists('#entity', $element) and $element['#entity'] ? $element['#entity']->chado_record_id : NULL;
+    $fkey_value = (array_key_exists('#entity', $element) and is_object($element['#entity'])) ? $element['#entity']->chado_record_id : NULL;
     $pub_id = '';
     $uname = '';
 
     // If the field already has a value then it will come through the $items
     // array.  This happens when editing an existing record.
     if (count($items) > 0 and array_key_exists($delta, $items)) {
-      $record_id = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__' . $pkey, $record_id);
       $pub_id = tripal_get_field_item_keyval($items, $delta, 'chado-' . $table_name . '__pub_id', $pub_id);
       $uname = tripal_get_field_item_keyval($items, $delta, 'uniquename', $uname);
     }
@@ -52,7 +50,7 @@ class schema__publication_widget extends ChadoFieldWidget {
 
     $widget['chado-' . $table_name . '__' . $pkey] = array(
       '#type' => 'value',
-      '#default_value' => $record_id,
+      '#default_value' => '',
     );
     $widget['chado-' . $table_name . '__' . $fkey] = array(
       '#type' => 'value',

+ 1 - 0
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -42,6 +42,7 @@ function tripal_chado_field_storage_write($entity_type, $entity, $op, $fields) {
 
   // Convert the fields into a key/value list of fields and their values.
   $field_vals = tripal_chado_field_storage_write_merge_fields($fields, $entity_type, $entity);
+dpm($field_vals);
 
   // First, write the record for the base table.  If we have a record id then
   // this is an update and we need to set the primary key.  If not, then this