From 37ee96a8538606bebf08038c93b6aef9c000e0a1 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Fri, 8 Oct 2021 11:06:22 +0200 Subject: [PATCH] hotline MT #140071 fix render ajax scripts order --- VERSIONS_HOTLINE/140071 | 1 + .../View/Wrapper/RichContent/Section.php | 4 +- .../templates/Intonation/View/RenderAjax.php | 6 ++- .../TemplatesDigitalResourcesTest.php | 39 +++++++++++++++++++ .../Templates/TemplatesJumbotronTest.php | 18 ++++----- 5 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 VERSIONS_HOTLINE/140071 diff --git a/VERSIONS_HOTLINE/140071 b/VERSIONS_HOTLINE/140071 new file mode 100644 index 00000000000..692f4fc28b2 --- /dev/null +++ b/VERSIONS_HOTLINE/140071 @@ -0,0 +1 @@ + - ticket #140071 : Magasin de thèmes : correction des liens de consultation et d'emprunt des prêts numériques en bibliothèque. \ No newline at end of file diff --git a/library/templates/Intonation/Library/View/Wrapper/RichContent/Section.php b/library/templates/Intonation/Library/View/Wrapper/RichContent/Section.php index f67c28889b0..b82a6d4b2d2 100644 --- a/library/templates/Intonation/Library/View/Wrapper/RichContent/Section.php +++ b/library/templates/Intonation/Library/View/Wrapper/RichContent/Section.php @@ -185,8 +185,8 @@ abstract class Intonation_Library_View_Wrapper_RichContent_Section { if ($class = $this->getClass()) $js = sprintf('$(\'.loading_icon\').parent().remove(); - if ($(\'.%1$s [data-ajax-content] > *\').length) - return $(\'.%1$s\').removeClass(\'d-none text-black-50 disabled\');', + if ($(\'.%1$s [data-ajax-content] > *\').length) { + return $(\'.%1$s\').removeClass(\'d-none text-black-50 disabled\');}', $class); if ($html) diff --git a/library/templates/Intonation/View/RenderAjax.php b/library/templates/Intonation/View/RenderAjax.php index aa00ff7a024..8dc2469e082 100644 --- a/library/templates/Intonation/View/RenderAjax.php +++ b/library/templates/Intonation/View/RenderAjax.php @@ -28,7 +28,11 @@ class Intonation_View_RenderAjax extends ZendAfi_View_Helper_BaseHelper { 'action' => $action], $params); - $js_callback .= 'initializePopups();setupAnchorsTarget();'.Class_AdminVar_Cookies::manager()->triggers(); + $js_callback = 'initializePopups();setupAnchorsTarget();' + . Class_AdminVar_Cookies::manager()->triggers() + . ';' + . $js_callback; + if (($ig = Zend_Controller_Front::getInstance() ->getPlugin('ZendAfi_Controller_Plugin_InspectorGadget')) && ($ig->isEnabled())) diff --git a/tests/scenarios/Templates/TemplatesDigitalResourcesTest.php b/tests/scenarios/Templates/TemplatesDigitalResourcesTest.php index 808327b6a99..afbe25fbc0d 100644 --- a/tests/scenarios/Templates/TemplatesDigitalResourcesTest.php +++ b/tests/scenarios/Templates/TemplatesDigitalResourcesTest.php @@ -240,10 +240,17 @@ class TemplatesDigitalResourcesDilicomItemTest extends TemplatesDigitalResources public function consultLinkShouldBeDisabled() { $this->assertXPathContentContains('//a[@data-disabled]', 'Consulter le livre en ligne'); } + + + /** @test */ + public function initializePopupsScriptsAndSetupAnchorsTargetShouldBePresent() { + $this->assertXPathContentContains('//script', 'setTimeout(function(){initializePopups();setupAnchorsTarget();}, 5);'); + } } + /** @see http://forge.afi-sa.fr/issues/115415 */ class TemplatesDigitalResourcesWrongIndexationTest extends AbstractControllerTestCase { protected $_storm_default_to_volatile = true; @@ -515,3 +522,35 @@ class TemplatesDigitalResourcesAudioRecordTest extends AbstractControllerTestCas $this->assertXPathContentContains('//div[@class="list-group-item bg-transparent px-0 mb-3"]//a[@class="audio_track card-title text-secondary"][contains(@data-track-url,"bib-numerique/play-ressource/id/4.mp3")]/span[@class="track_title"]', 'The prophecy'); } } + + + + +class TemplatesDigitalResourcesDilicomRecordItemTest extends TemplatesDigitalResourcesDilicomTestCase { + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_Notice', + ['id' => 123, + 'type_doc' => Class_TypeDoc::LIVRE_NUM]); + + $this->fixture('Class_Exemplaire', + ['id' => 8, + 'id_origine' => 3, + 'id_notice' => 123]); + + (new DilicomFixtures())->albumTotemThora(); + RessourcesNumeriquesFixtures::activateDilicom(); + + $this->dispatch('record/items/id/123'); + } + + + /** @test */ + public function initializePopupsScriptsShouldBeDoneBeforeReturn() { + $this->assertXPathContentContains('//script', '.load("/noticeajax/resources/id/123", function() {initializePopups();setupAnchorsTarget();;$(\'.loading_icon\').parent().remove(); + if ($(\'.document_items [data-ajax-content] > *\').length) { + return $(\'.document_items\').removeClass(\'d-none text-black-50 disabled\');}});}'); + } +} \ No newline at end of file diff --git a/tests/scenarios/Templates/TemplatesJumbotronTest.php b/tests/scenarios/Templates/TemplatesJumbotronTest.php index 49b4036dbd2..dd663521163 100644 --- a/tests/scenarios/Templates/TemplatesJumbotronTest.php +++ b/tests/scenarios/Templates/TemplatesJumbotronTest.php @@ -40,9 +40,9 @@ class TemplatesRecordsDispatchItemsTest extends AbstractControllerTestCase { /** @test */ public function shouldJsLoadItemsWithInitializePopupAndSetupAnchorTarget() { $this->dispatch('/record/items/id/1'); - $this->assertXPathContentContains('//script', '.load("/noticeajax/resources/id/1", function() {$(\'.loading_icon\').parent().remove(); - if ($(\'.document_items [data-ajax-content] > *\').length) - return $(\'.document_items\').removeClass(\'d-none text-black-50 disabled\');initializePopups();setupAnchorsTarget();});}, 5);'); + $this->assertXPathContentContains('//script', '.load("/noticeajax/resources/id/1", function() {initializePopups();setupAnchorsTarget();;$(\'.loading_icon\').parent().remove(); + if ($(\'.document_items [data-ajax-content] > *\').length) { + return $(\'.document_items\').removeClass(\'d-none text-black-50 disabled\');}});}, 5);'); } @@ -50,8 +50,8 @@ class TemplatesRecordsDispatchItemsTest extends AbstractControllerTestCase { public function shouldJsLoadHasAuthor() { $this->dispatch('/record/items/id/1'); $this->assertXPathContentContains('//script', '.load("/noticeajax/has-author/id/1", function() {$(\'.loading_icon\').parent().remove(); - if ($(\'.document_author [data-ajax-content] > *\').length) - return $(\'.document_author\').removeClass(\'d-none text-black-50 disabled\');});}, 5);'); + if ($(\'.document_author [data-ajax-content] > *\').length) { + return $(\'.document_author\').removeClass(\'d-none text-black-50 disabled\');}});}, 5);'); } @@ -59,8 +59,8 @@ class TemplatesRecordsDispatchItemsTest extends AbstractControllerTestCase { public function shouldJsLoadHasMedia() { $this->dispatch('/record/items/id/1'); $this->assertXPathContentContains('//script', '.load("/noticeajax/has-media/id/1", function() {$(\'.loading_icon\').parent().remove(); - if ($(\'.document_media [data-ajax-content] > *\').length) - return $(\'.document_media\').removeClass(\'d-none text-black-50 disabled\');});}, 5);'); + if ($(\'.document_media [data-ajax-content] > *\').length) { + return $(\'.document_media\').removeClass(\'d-none text-black-50 disabled\');}});}, 5);'); } @@ -118,8 +118,8 @@ class TemplatesRecordsDispatchItemsTest extends AbstractControllerTestCase { $this->dispatch('/abonne/selections/id/2'); $this->assertXPathContentContains('//script', 'load("/abonne/has-loan/id/2", function() {$(\'.loading_icon\').parent().remove(); - if ($(\'.user_loans [data-ajax-content] > *\').length) - return $(\'.user_loans\').removeClass(\'d-none text-black-50 disabled\');});});'); + if ($(\'.user_loans [data-ajax-content] > *\').length) { + return $(\'.user_loans\').removeClass(\'d-none text-black-50 disabled\');}});});'); } -- GitLab