CRM-12872 - Ajax-enable pager links
authorColeman Watts <coleman@civicrm.org>
Wed, 8 Jan 2014 02:06:50 +0000 (18:06 -0800)
committerColeman Watts <coleman@civicrm.org>
Wed, 8 Jan 2014 02:06:50 +0000 (18:06 -0800)
CRM/Contribute/Page/Tab.php
CRM/Utils/Pager.php
CRM/Utils/System.php
templates/CRM/Contact/Form/Search/Custom.tpl
templates/CRM/Contact/Form/Selector.tpl
templates/CRM/Contact/Page/View/Log.tpl
templates/CRM/Report/Form/Contact/Detail.tpl
templates/CRM/Report/Form/Event/Income.tpl
templates/CRM/Report/Form/Layout/Overlay.tpl
templates/CRM/Report/Form/Layout/Table.tpl
templates/CRM/common/pager.tpl

index ca154e71f032fcc7241650c428c7a14a7cbdb7ad..7edef06acc9e36deb1f0bed88a9de0086499bb3c 100644 (file)
@@ -166,7 +166,7 @@ class CRM_Contribute_Page_Tab extends CRM_Core_Page {
     $controller->reset();
     $controller->set('cid', $this->_contactId);
     $controller->set('crid', $this->_crid);
-    $controller->set('context', 'contribution');
+    $controller->set('context', 'Search');
     $controller->process();
     $controller->run();
 
index db8f3f4148c47d7d36c0c69086e5660993051488..08a6674c4d791ab7c89e57331acee271dfda29d0 100644 (file)
@@ -294,7 +294,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
     }
 
     $href = $this->makeURL(self::PAGE_ID, 1);
-    return sprintf('<a href="%s" title="%s">%s</a>',
+    return sprintf('<a class="crm-pager-link" href="%s" title="%s">%s</a>',
       $href,
       str_replace('%d', 1, $this->_altFirst),
       $this->_firstPagePre . $this->_firstPageText . $this->_firstPagePost
@@ -307,7 +307,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
     }
 
     $href = $this->makeURL(self::PAGE_ID, $this->_totalPages);
-    return sprintf('<a href="%s" title="%s">%s</a>',
+    return sprintf('<a class="crm-pager-link" href="%s" title="%s">%s</a>',
       $href,
       str_replace('%d', $this->_totalPages, $this->_altLast),
       $this->_lastPagePre . $this->_lastPageText . $this->_lastPagePost
@@ -317,7 +317,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
   function getBackPageLink() {
     if ($this->_currentPage > 1) {
       $href = $this->makeURL(self::PAGE_ID, $this->getPreviousPageID());
-      return sprintf('<a href="%s" title="%s">%s</a>',
+      return sprintf('<a class="crm-pager-link" href="%s" title="%s">%s</a>',
         $href,
         $this->_altPrev, $this->_prevImg
       ) . $this->_spacesBefore . $this->_spacesAfter;
@@ -328,7 +328,7 @@ class CRM_Utils_Pager extends Pager_Sliding {
   function getNextPageLink() {
     if ($this->_currentPage < $this->_totalPages) {
       $href = $this->makeURL(self::PAGE_ID, $this->getNextPageID());
-      return $this->_spacesAfter . sprintf('<a href="%s" title="%s">%s</a>',
+      return $this->_spacesAfter . sprintf('<a class="crm-pager-link" href="%s" title="%s">%s</a>',
         $href,
         $this->_altNext, $this->_nextImg
       ) . $this->_spacesBefore . $this->_spacesAfter;
index 06ff598a79a92147de33a65e334aee9f345566ee..71bca4f36f9c249ad1555d0aaaf2b75953d305c2 100644 (file)
@@ -126,8 +126,14 @@ class CRM_Utils_System {
       $qs['force'] = 1;
     }
 
-    unset($qs['snippet']);
-    unset($qs['section']);
+    // Ok this is a big assumption but usually works
+    // If we are in snippet mode, retain the 'section' param, if not, get rid of it.
+    if (!empty($qs['snippet'])) {
+      unset($qs['snippet']);
+    }
+    else {
+      unset($qs['section']);
+    }
 
     if ($skipUFVar) {
       $config = CRM_Core_Config::singleton();
index 1db46eee55b95e31f1cf47b7e5c36f93ced3a8c5..3b1ab45a3c9f0175e4370f85970c3d1726883bfb 100644 (file)
@@ -178,6 +178,7 @@ function toggleContactSelection( name, qfKey, selection ){
     var formName = "{/literal}{$form.formName}{literal}";
     on_load_init_checkboxes(formName);
   }
+  return false;
 }
 </script>
 
index 21a2d27d887eca99dffc16836ac07f7f221c2e11..c218769f9c38acb39ad9c786c57224129b820dc3 100644 (file)
@@ -202,6 +202,7 @@ function toggleContactSelection(name, qfKey, selection) {
     params.name = name;
   }
   cj.getJSON(url, params, countSelections);
+  return false;
 }
 {/literal}
 </script>
index 7949821751521cb27af6d8ea45ba42a939272249..b940ff39516b0535964f4bea8650cd4eac20637d 100644 (file)
       $('#changeLog .instance_data').crmSnippet('refresh');
     };
     CRM.reloadChangeLogTab({/literal}"{$instanceUrl}"{literal});
-
-    $('#changeLog').on('click', '.report-pager .crm-pager-nav a', function(e) {
-      CRM.reloadChangeLogTab(this.href + '&section=2');
-      return false;
-    });
-
-    $('#changeLog').on('click', 'input[name="PagerBottomButton"], input[name="PagerTopButton"]', function(e) {
-      var url  = $('#changeLog .instance_data .report-pager .crm-pager-nav a:first').attr('href') + '&section=2';
-      CRM.reloadChangeLogTab(url + '&crmPID=' + $(this).siblings('input[type=text]').val());
-      return false;
-    });
   });
 
   </script>
index 40cf07a22059baf3e03a8225244f2d8dbcae615b..79fbe38af3bed893bee44256aef9e18cdf768688 100644 (file)
@@ -37,7 +37,7 @@
 {/if}
     {if $rows}
         <div class="report-pager">
-            {include file="CRM/common/pager.tpl" location="top" noForm=0}
+            {include file="CRM/common/pager.tpl" location="top"}
         </div>
 
         {* pre-compile section header here, rather than doing it every time under foreach *}
         {/foreach}
 
   <div class="report-pager">
-            {include file="CRM/common/pager.tpl" noForm=0}
+            {include file="CRM/common/pager.tpl"}
         </div>
         <br />
         {if $grandStat}
index d1785502cb3d763c12b1291b9e945fab5fff2de3..537e46d797df541eff49b07da5a5e8d1bb779434 100644 (file)
@@ -39,7 +39,7 @@
 
     {if $events}
         <div class="report-pager">
-            {include file="CRM/common/pager.tpl" location="top" noForm=0}
+            {include file="CRM/common/pager.tpl" location="top"}
         </div>
         {foreach from=$events item=eventID}
                   <table class="report-layout">
@@ -82,7 +82,7 @@
         {/foreach}
 
     <div class="report-pager">
-            {include file="CRM/common/pager.tpl" noForm=0}
+            {include file="CRM/common/pager.tpl"}
         </div>
         {if !$section }
             {*Statistics at the bottom of the page*}
index 3a6353bfebf02521ea53213bad3c7d02b9e5ca2e..3ab123dcb641f122570d2d59093ae1f3a8e33b1d 100644 (file)
@@ -26,7 +26,7 @@
 {if (!$chartEnabled || !$chartSupported )&& $rows}
     {if $pager and $pager->_response and $pager->_response.numPages > 1}
         <div class="report-pager">
-            {include file="CRM/common/pager.tpl" location="top" noForm=0}
+            {include file="CRM/common/pager.tpl" location="top"}
         </div>
     {/if}
     <div class="crm-report-overlay form-layout-compressed">
     </div>
     {if $pager and $pager->_response and $pager->_response.numPages > 1}
         <div class="report-pager">
-            {include file="CRM/common/pager.tpl"  noForm=0}
+            {include file="CRM/common/pager.tpl" }
         </div>
     {/if}
 {/if}
index b2c59e4cfa63b1cb95ff4789fd14d12fb3466c67..fb8faeee13a30be3d995a614751137ff26f7b349 100644 (file)
@@ -26,7 +26,7 @@
 {if (!$chartEnabled || !$chartSupported )&& $rows}
     {if $pager and $pager->_response and $pager->_response.numPages > 1}
         <div class="report-pager">
-            {include file="CRM/common/pager.tpl" location="top" noForm=0}
+            {include file="CRM/common/pager.tpl" location="top"}
         </div>
     {/if}
     <table class="report-layout display">
     </table>
     {if $pager and $pager->_response and $pager->_response.numPages > 1}
         <div class="report-pager">
-            {include file="CRM/common/pager.tpl"  noForm=0}
+            {include file="CRM/common/pager.tpl" }
         </div>
     {/if}
 {/if}
index 1ced52c0cd7d17b3a77fc14a9c261cd08a4c7b12..5464a00de1667561634e7d1e415637c27e33d1cf 100644 (file)
 {if $pager and $pager->_response}
     {if $pager->_response.numPages > 1}
         <div class="crm-pager">
-          {if empty($noForm)}
             <span class="element-right">
             {if $location eq 'top'}
-              {$pager->_response.titleTop}&nbsp;<input class="form-submit" name="{$pager->_response.buttonTop}" value="{ts}Go{/ts}" type="submit"/>
+              {$pager->_response.titleTop}
             {else}
-              {$pager->_response.titleBottom}&nbsp;<input class="form-submit" name="{$pager->_response.buttonBottom}" value="{ts}Go{/ts}" type="submit"/>
+              {$pager->_response.titleBottom}
             {/if}
             </span>
-          {/if}
+          </span>
           <span class="crm-pager-nav">
           {$pager->_response.first}&nbsp;
           {$pager->_response.back}&nbsp;
           </span>
 
         </div>
-      {if empty($noForm) and $location neq 'top'}
-      <script type="text/javascript">
-        cj('input[name^=crmPID]', '#{$form.formName}').spinner({ldelim}
-          min: 1,
-          max: {$pager->_response.numPages}
-        {rdelim});
-      </script>
-      {/if}
     {/if}
 
     {* Controller for 'Rows Per Page' *}
      <div class="clear"></div>
     {/if}
 
+    {if $location neq 'top'}
+      <script type="text/javascript">
+        {literal}
+        cj(function($) {
+          {/literal}
+          var $form = $('#{$form.formName}');
+          var numPages = {$pager->_response.numPages};
+          var currentPage = {$pager->_response.currentPage};
+          {literal}
+          function refresh(url) {
+            var options = url ? {url: url} : {};
+            $form.closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet(options).crmSnippet('refresh');
+          }
+          function page(num) {
+            num = parseInt(num, 10);
+            if (isNaN(num) || num < 1 || num > numPages || num === currentPage) {
+              return;
+            }
+            var url = $('a.crm-pager-link', $form).attr('href');
+            refresh(url.replace(/crmPID=\d/, 'crmPID=' + num));
+          }
+          $('input[name^=crmPID]', $form).spinner({
+            min: 1,
+            max: numPages
+          })
+            .on('change', function() {
+              page($(this).spinner('value'));
+            });
+          $form
+            .on('click', 'a.ui-spinner-button', function(e) {
+              page($(this).siblings('input[name^=crmPID]').spinner('value'));
+            })
+            .on('click', 'a.crm-pager-link, #alpha-filter a', function() {
+            refresh($(this).attr('href'));
+            return false;
+          });
+        });
+        {/literal}
+      </script>
+    {/if}
+
 {/if}