CRM-12872 - Ajax pager fixes
authorColeman Watts <coleman@civicrm.org>
Wed, 8 Jan 2014 22:09:40 +0000 (14:09 -0800)
committerColeman Watts <coleman@civicrm.org>
Wed, 8 Jan 2014 22:09:40 +0000 (14:09 -0800)
templates/CRM/common/pager.tpl

index dd05e9b1d2dd4e4b8f7a7f32e43dfd6093da6eae..a3b7b75b0f9f8a7f910d9ede7c821a6cda1e6e3b 100644 (file)
             numPages = {$pager->_response.numPages},
             currentPage = {$pager->_response.currentPage},
             perPageCount = {$pager->_perPage},
-            currentLocation = {$pager->_response.currentLocation|json_encode};
+            currentLocation = {$pager->_response.currentLocation|json_encode},
+            spinning = null;
+            refreshing = false;
           {literal}
           function refresh(url) {
-            var options = url ? {url: url} : {};
-            $form.closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet(options).crmSnippet('refresh');
+            if (!refreshing) {
+              refreshing = true;
+              var options = url ? {url: url} : {};
+              $form.off().closest('.crm-ajax-container, #crm-main-content-wrapper').crmSnippet(options).crmSnippet('refresh');
+            }
           }
           function page(num) {
             num = parseInt(num, 10);
             })
             .on('change', function() {
               page($(this).spinner('value'));
-              return false;
             })
             .on('keyup keydown keypress', preventSubmit);
           $('input.crm-rows-per-page-select', $form)
             })
             .on('change', function() {
               changeCount($(this).spinner('value'));
-              return false;
             })
             .on('keyup keydown keypress', preventSubmit);
           $form
             .on('click', 'a.ui-spinner-button', function(e) {
-              if ($(this).is('.crm-pager a')) {
-                page($(this).siblings('input[name^=crmPID]').spinner('value'));
-              } else {
-                changeCount($(this).siblings('input.crm-rows-per-page-select').spinner('value'));
-              }
+              var $el = $(this);
+              // Update after a short delay to allow multiple clicks
+              spinning !== null && window.clearTimeout(spinning);
+              spinning = window.setTimeout(function() {
+                if ($el.is('.crm-pager a')) {
+                  page($el.siblings('input[name^=crmPID]').spinner('value'));
+                } else {
+                  changeCount($el.siblings('input.crm-rows-per-page-select').spinner('value'));
+                }
+              }, 200);
             })
             .on('click', 'a.crm-pager-link, #alpha-filter a', function() {
               refresh($(this).attr('href'));