From 5216dc81722d7268f99ae0951b69497a38380b1d Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@afi-sa.fr>
Date: Thu, 29 Mar 2018 15:59:59 +0200
Subject: [PATCH] hotline #72999 fix library widget pagination links

---
 VERSIONS_HOTLINE/72999                        |  2 ++
 .../ZendAfi/View/Helper/Accueil/Library.php   |  3 ++-
 .../opac/js/renderFilters/ajaxifyFilters.js   |  8 ++++---
 .../View/Helper/Accueil/LibraryTest.php       | 23 ++++++++++++++++++-
 4 files changed, 31 insertions(+), 5 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/72999

diff --git a/VERSIONS_HOTLINE/72999 b/VERSIONS_HOTLINE/72999
new file mode 100644
index 00000000000..49789cbf486
--- /dev/null
+++ b/VERSIONS_HOTLINE/72999
@@ -0,0 +1,2 @@
+ - ticket #72999 : Boite bibliothèque : correction des liens de pagination.
+ 
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/Accueil/Library.php b/library/ZendAfi/View/Helper/Accueil/Library.php
index 0aa7fba3731..8d1770ce667 100644
--- a/library/ZendAfi/View/Helper/Accueil/Library.php
+++ b/library/ZendAfi/View/Helper/Accueil/Library.php
@@ -333,7 +333,8 @@ class ZendAfi_View_Helper_Accueil_Library extends ZendAfi_View_Helper_Accueil_Ba
                     'controller' => 'bib',
                     'action' => 'widget-page',
                     'id_module' => $this->id_module,
-                    'id_division' => $this->division];
+                    'id_division' => $this->division,
+                    'render' => 'ajax'];
 
     $paginator = (new Zend_Paginator(new Zend_Paginator_Adapter_Null(count($items))))
       ->setItemCountPerPage(max($items_by_page, 1))
diff --git a/public/opac/js/renderFilters/ajaxifyFilters.js b/public/opac/js/renderFilters/ajaxifyFilters.js
index 7f742be348c..351d4370b6d 100644
--- a/public/opac/js/renderFilters/ajaxifyFilters.js
+++ b/public/opac/js/renderFilters/ajaxifyFilters.js
@@ -27,10 +27,10 @@
       var url = node.attr(url_attr); 
       
       if (!url)
-	      return event.preventDefault(); 
+	return event.preventDefault(); 
 
       if (url == "#") 
-	      url = node.jqmData("href");
+	url = node.jqmData("href");
       
       widget.load(url + "/render/ajax .boite > *", onLoadComplete); 
       event.preventDefault();
@@ -40,7 +40,9 @@
     var onLoadComplete = function() {
       if ('onLoadComplete' in options)
         options.onLoadComplete(widget);
-      
+
+      initializePopups();
+      setupAnchorsTarget();
       widget.ajaxifyFilters(options);
     };
 
diff --git a/tests/library/ZendAfi/View/Helper/Accueil/LibraryTest.php b/tests/library/ZendAfi/View/Helper/Accueil/LibraryTest.php
index 8267dae8d37..ef941231249 100644
--- a/tests/library/ZendAfi/View/Helper/Accueil/LibraryTest.php
+++ b/tests/library/ZendAfi/View/Helper/Accueil/LibraryTest.php
@@ -73,8 +73,11 @@ abstract class ZendAfi_View_Helper_Accueil_LibraryTestCase extends ViewHelperTes
                'division' => 2,
                'preferences' => $preferences];
 
+    $view = new ZendAfi_Controller_Action_Helper_View();
+    $view->setScriptPath('application/modules/opac/views/scripts');
+
     $this->_helper = new ZendAfi_View_Helper_Accueil_Library(2, $params);
-    $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View());
+    $this->_helper->setView($view);
 
     $this->html = $this->_helper->getBoite();
   }
@@ -362,3 +365,21 @@ class ZendAfi_View_Helper_Accueil_LibraryCustomFieldsDisplayTest extends ZendAfi
                           $js);
   }
 }
+
+
+
+
+class ZendAfi_View_Helper_Accueil_LibraryPaginatorTest extends ZendAfi_View_Helper_Accueil_LibraryTestCase {
+  public function setUp() {
+    parent::setUp();
+    $this->_generateLibrary(['titre' => 'Bibliotheques',
+                             'libraries' => '4;1;2',
+                             'nb_aff' => 1]);
+  }
+
+
+  /** @test */
+  public function linkToPage2ShouldBeRenderAjax() {
+    $this->assertXPathContentContains($this->html, '//div[@class="paginationControl"]//a[contains(@href, "/render/ajax")]', '2');
+  }
+}
-- 
GitLab