diff --git a/application/modules/opac/controllers/IndexController.php b/application/modules/opac/controllers/IndexController.php index 1d9fc7afc4923cd4881a9b8e1548f36ad926fa7c..473c7aae284e738638dfaa2ebaf0a995077d2586 100644 --- a/application/modules/opac/controllers/IndexController.php +++ b/application/modules/opac/controllers/IndexController.php @@ -122,7 +122,11 @@ class IndexController extends ZendAfi_Controller_Action { session_write_close(); if (! $helper = Intonation_Library_AjaxPaginatedListHelper::find($this->_getParam('id'))) - return $this->_javascriptRedirectToReferrer(); + return $this->_helper + ->ajax(function() + { + return $this->view->renderAjaxPaginatedList((new Intonation_Library_AjaxPaginatedListHelper)->beDeprecated()); + }); $callback = function() use ($helper) { $helper diff --git a/library/Class/WebService/SIGB/Exemplaire.php b/library/Class/WebService/SIGB/Exemplaire.php index 812900a9abc249f82bf82dde9094a90a70feef61..9bd569b8291ad9a1a2c8cf677a0c73da1023086b 100644 --- a/library/Class/WebService/SIGB/Exemplaire.php +++ b/library/Class/WebService/SIGB/Exemplaire.php @@ -184,7 +184,7 @@ class Class_WebService_SIGB_Exemplaire { * @return Class_Notice */ public function getNoticeOPAC() { - if (!isset($this->_notice_opac) && + if ((null == $this->_notice_opac) && ($exemplaire_opac = $this->getExemplaireOPAC())) $this->setNoticeOPAC($exemplaire_opac->getNotice()); diff --git a/library/templates/Intonation/Assets/css/intonation.css b/library/templates/Intonation/Assets/css/intonation.css index 4e994b7da9a17d58ea138d703a47d388d54cb54c..3b3a6fa87c59a8cf5a4736fc6521c3f68bfcf60f 100644 --- a/library/templates/Intonation/Assets/css/intonation.css +++ b/library/templates/Intonation/Assets/css/intonation.css @@ -960,6 +960,10 @@ address { position: relative; } +.loading_data { + min-height: 100px; +} + .loading_data:before { font-family: "Font Awesome 5 Free"; content: '\f110'; diff --git a/library/templates/Intonation/Library/AjaxPaginatedListHelper.php b/library/templates/Intonation/Library/AjaxPaginatedListHelper.php index 579ab93da04b68ec7b59df2a9461910aa87f593b..462951de562f3130de1cacb5dfdf61093c155b7e 100644 --- a/library/templates/Intonation/Library/AjaxPaginatedListHelper.php +++ b/library/templates/Intonation/Library/AjaxPaginatedListHelper.php @@ -36,7 +36,8 @@ class Intonation_Library_AjaxPaginatedListHelper { $_order, $_new_order, $_has_been_sliced = false, - $_count_search_result; + $_count_search_result, + $_deprecated = false; public static function find($id) { @@ -57,6 +58,22 @@ class Intonation_Library_AjaxPaginatedListHelper { } + public function __construct() { + $this->_collection = new Storm_Collection; + } + + + public function beDeprecated() { + $this->_deprecated = true; + return $this; + } + + + public function isDeprecated() { + return $this->_deprecated; + } + + public function getId() { if ($this->_id) return $this->_id; diff --git a/library/templates/Intonation/Library/View/Wrapper/Loan.php b/library/templates/Intonation/Library/View/Wrapper/Loan.php index 6d3cba5632920ddb5812b8c312beb30f69db186a..c0fbd6282a780a79c95aef404fb6c4e8e420b910 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Loan.php +++ b/library/templates/Intonation/Library/View/Wrapper/Loan.php @@ -243,15 +243,6 @@ class Intonation_Library_View_Wrapper_Loan extends Intonation_Library_View_Wrapp } - public function getContentForJSSearch() { - return $this->_in_js_search - ? $this->_view->dNone(strtolower($this->_model->getRowTitle() - .$this->_model->getRowAuthor() - . $this->getBadges())) - : ''; - } - - public function getOsmData() { return null; } diff --git a/library/templates/Intonation/Library/View/Wrapper/PNBLoan.php b/library/templates/Intonation/Library/View/Wrapper/PNBLoan.php index 08ce8567a832775feb0abf1322809eb85de8d0be..2e61e8b558371ce18354d01d73e64b17550baac4 100644 --- a/library/templates/Intonation/Library/View/Wrapper/PNBLoan.php +++ b/library/templates/Intonation/Library/View/Wrapper/PNBLoan.php @@ -119,16 +119,6 @@ class Intonation_Library_View_Wrapper_PNBLoan extends Intonation_Library_View_Wr } - public function getContentForJSSearch() { - return $this->_in_js_search - ? $this->_view->dNone(implode(' ', [$this->getMainTitle(), - $this->getSecondaryTitle(), - $this->getDescription(), - '%s'])) - : ''; - } - - public function getModelId() { $id = ($user = $this->_model->getUser()) ? $user->getId() diff --git a/library/templates/Intonation/View/RenderAjaxPaginatedList.php b/library/templates/Intonation/View/RenderAjaxPaginatedList.php index e88d224bc64c8ce6c16edea3c8dc685c85767958..e21c46a19e924ed713637d1b5a07e6cc40b792b7 100644 --- a/library/templates/Intonation/View/RenderAjaxPaginatedList.php +++ b/library/templates/Intonation/View/RenderAjaxPaginatedList.php @@ -39,24 +39,38 @@ class Intonation_View_RenderAjaxPaginatedList extends ZendAfi_View_Helper_BaseHe return call_user_func_array([$this->view, $helper->getRendering()], [$element]); }; + $html_collection = + $this->view->div(['class' => 'list-group bg-transparent no_border', + 'data-deprecated' => $helper->isDeprecated()], + $this->view->renderList($sub_collection, $callback)); + + $html_content = implode([$this->_renderTools($helper, $sub_collection), + $pager, + $html_collection]); + + return + $this->view->div(['id' => 'ajax_paginated_list_' . $this->_id], + $this->view->div(['class' => 'ajax_content'], + $html_content)) + . $this->_getScripts($helper); + } + + + protected function _getScripts($helper) { + if ($helper->isDeprecated()) + return ''; + $url = Class_Url::relative('/public/opac/js/ajaxifyPaginatedList/ajaxifyPaginatedList.js'); - $scripts = Class_ScriptLoader::getInstance() + return Class_ScriptLoader::getInstance() ->addJQueryReady(sprintf('if (undefined == $.fn.ajaxifyPaginatedList) {var script = document.createElement("script"); script.type = "text/javascript"; script.src = "%s"; $("head").append(script);}', $url)) ->addJQueryReady(sprintf('setTimeout(function() {$("#ajax_paginated_list_%s:not(.ajaxified)").ajaxifyPaginatedList();}, 100);', - $this->_id)); + $this->_id)) + ->html(); - return - $this->view->div(['id' => 'ajax_paginated_list_' .$this->_id], - $this->view->div(['class' => 'ajax_content'], - $this->_renderTools($helper, $sub_collection) - . $pager - . $this->view->div(['class' => 'list-group bg-transparent no_border'], - $this->view->renderList($sub_collection, $callback)))) - . $scripts->html(); } diff --git a/public/opac/js/ajaxifyPaginatedList/ajaxifyPaginatedList.js b/public/opac/js/ajaxifyPaginatedList/ajaxifyPaginatedList.js index 2fe150973f7d88c9c09027fcd59014acbb2821c3..76d77e0d5ec9573950ed5c9a6809661d83aa9d08 100644 --- a/public/opac/js/ajaxifyPaginatedList/ajaxifyPaginatedList.js +++ b/public/opac/js/ajaxifyPaginatedList/ajaxifyPaginatedList.js @@ -43,6 +43,12 @@ var onLoadComplete = function() { + if (ajax_content.find('[data-deprecated="1"]').length) { + ajax_content.addClass('loading_data'); + location.reload(); + return; + } + if (undefined != $.fn.masonry) widget.masonry(); diff --git a/tests/scenarios/Templates/TemplatesAjaxPaginatedListTest.php b/tests/scenarios/Templates/TemplatesAjaxPaginatedListTest.php index bfd668fc0b3f88d3f22406395d5c2dfc7e9f47ba..55b794a69d32c88fd33f7987cf39c63599d79f86 100644 --- a/tests/scenarios/Templates/TemplatesAjaxPaginatedListTest.php +++ b/tests/scenarios/Templates/TemplatesAjaxPaginatedListTest.php @@ -28,6 +28,7 @@ class TemplatesAjaxPaginatedListNoCacheTest extends AbstractControllerTestCase { public function setUp() { parent::setUp(); + $this->_buildTemplateProfil(['id' => '34']); Storm_Cache::beVolatile(); $this->dispatch('/opac/index/ajax-paginated-list/id/123123'); } @@ -41,8 +42,8 @@ class TemplatesAjaxPaginatedListNoCacheTest extends AbstractControllerTestCase { /** @test */ - public function shouldReloadPageByJavascript() { - $this->assertXPathContentContains('//script', 'location.reload();'); + public function htmlShouldContainsAxaifyHtmlWithDataDeprecated() { + $this->assertXPath('//div[@class="ajax_content"]//div[@data-deprecated="1"]'); } } @@ -76,6 +77,11 @@ abstract class TemplatesAjaxPaginatedListTestCase extends AbstractControllerTest $this->_ajax_paginated_list_helper_id = $this->_ajax_paginated_list_helper->getId(); + $this->_dispatch(); + } + + + protected function _dispatch() { $this->dispatch('/opac/index/ajax-paginated-list/id/' . $this->_ajax_paginated_list_helper_id); } @@ -107,6 +113,12 @@ abstract class TemplatesAjaxPaginatedListTestCase extends AbstractControllerTest } + /** @test */ + public function htmlShouldContainsAjaxifyHtmlWithoutDataDeprecated() { + $this->assertXPath('//div[@class="ajax_content"]//div[@data-deprecated=""]'); + } + + protected function _getCollection() { if ($this->_collection_cache) return $this->_collection_cache; @@ -864,4 +876,36 @@ class TemplatesAjaxPaginatedListWithCorruptedSaveInCacheTest extends TemplatesAj public function shouldContainsSpanTitleWithPerformanceLimitedMessage() { $this->assertXPath('//span[@title="Le nombre d\'éléments a été volontairement réduit pour des raisons de performances"]'); } +} + + + + +class TemplatesAjaxPaginatedListWithLoanAndSearchTest extends TemplatesAjaxPaginatedListTestCase { + + protected function _getCollectionAsArray() { + $item = new Class_WebService_SIGB_Exemplaire(1); + $loan = new Class_WebService_SIGB_Emprunt(1, $item); + $user = $this->fixture(Class_Users::class, + ['id' => 1, + 'login'=> 'log', + 'password' => 'pass']); + + $card_operation_decorator = new Class_User_CardsOperationDecorator($loan, $user); + return [new Intonation_Library_View_Wrapper_Loan($card_operation_decorator)]; + } + + + protected function _dispatch() { + $this->dispatch('/opac/index/ajax-paginated-list/search/log/id/' . $this->_ajax_paginated_list_helper_id); + } + + + /** @test */ + public function dataToCacheShouldBeLowerThanExpectedSize() { + $data = $this->_ajax_paginated_list_helper->getDataToCache(); + $serialized = serialize($data); + $size = mb_strlen($serialized); + $this->assertTrue('1524' > $size); + } } \ No newline at end of file