Browse Source

AJAX pagers for fields

Stephen Ficklin 8 years ago
parent
commit
6bd39e0dbc

+ 13 - 3
tripal/theme/js/tripal.js

@@ -1,7 +1,7 @@
 // Using the closure to map jQuery to $. 
 (function ($) {
   // Store our function as a property of Drupal.behaviors.
-  Drupal.behaviors.myModuleSecureLink = {
+  Drupal.behaviors.tripal = {
     attach: function (context, settings) {
 
       $(".tripal-entity-unattached .field-items").replaceWith('<div class="field-items">Loading... <img src="' + tripal_path + '/theme/images/ajax-loader.gif"></div>');
@@ -18,8 +18,18 @@
           }
         });
       });
-
     }
   }
 
-})(jQuery);
+})(jQuery);
+
+function tripal_navigate_field_pager(id, page) {
+  jQuery.ajax({
+    type: "GET",
+    url: Drupal.settings["basePath"] + "bio_data/ajax/field_attach/" + id,
+    data: { 'page' : page },
+    success: function(response) {
+      jQuery("#" + id + ' .field-items').replaceWith(response['content']);
+    }
+  });
+}

+ 3 - 4
tripal_chado/includes/TripalFields/sbo__relationship/sbo__relationship_formatter.inc

@@ -53,7 +53,6 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
   public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
     // Get the settings
     $settings = $display['settings'];
-
     $rows = array();
     $headers = array($settings['title']);
 
@@ -95,15 +94,15 @@ class sbo__relationship_formatter extends ChadoFieldFormatter {
       $rows[][] = array('data' => $phrase, 'class' => array('tripal-entity-unattached field-items'));
     }
 
-    $per_page = 10;
+    $per_page = 2;
     // Initialize the pager
     $current_page = pager_default_initialize(count($rows), $per_page);
     // Split your list into page sized chunks
-    $chunks = array_chunk($rows, '10', TRUE);
+    $chunks = array_chunk($rows, $per_page, TRUE);
     //format pager
     $pager = theme('pager', array('quantity', count($rows)));
 
-    //$pager = preg_replace("/href=\"(.*)\"/", 'href="javascript:void(0)" onclick="tripal_navigate_field_pager()"', $pager);
+    $pager = preg_replace("/href=\".*page=(.+?).*\"/", 'href="javascript:void(0)" onclick="tripal_navigate_field_pager(\'tripal-entity-' . $entity->id . '--' . $this->field['field_name'] . '\', $1)"', $pager);
     //$pager = preg_replace("/href=\"" . $tmp_base_path . "gensas\/load_job_view_panel\/" . $job_id . "\/\d\"/", 'href="javascript:void(0)" onclick="gensas.show_job_view_panel(\'' . $job_id . '\', \'' . $job->getName() . '\')"', $pager);
     // the $table array contains the headers and rows array as well as other
     // options for controlling the display of the table.  Additional

+ 0 - 5
tripal_chado/theme/js/tripal_chado_fields.js

@@ -1,5 +0,0 @@
-
-function tripal_navigate_field_pager($page) {
-    console.log($page);
-    jQuery("#ajax-target").load("bio_data/ajax/field_attach/"+$page);
-}

+ 0 - 1
tripal_chado/tripal_chado.info

@@ -11,7 +11,6 @@ files[] = views_handlers/chado_views_handler_sort.inc
 files[] = views_handlers/chado_views_handler_field_chado_base__organism_id.inc
 
 stylesheets[all][] = theme/css/tripal_chado.css
-scripts[]          = theme/js/tripal_chado_fields.js
 
 dependencies[] = tripal
 dependencies[] = date