diff --git a/VERSIONS_HOTLINE/116694 b/VERSIONS_HOTLINE/116694 new file mode 100644 index 0000000000000000000000000000000000000000..27b6acbeeead85dda5cd56ec6332b07b07910916 --- /dev/null +++ b/VERSIONS_HOTLINE/116694 @@ -0,0 +1 @@ + - ticket #116694 : Magasin de thèmes : Ajout d'une nouvelle option de défilement dans les carrousels. \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Carousel/Definition.php b/library/templates/Intonation/Library/Widget/Carousel/Definition.php index a84c7f6ef5e570d8024cc152def26e03f0e827ae..fa5c69bae570a4e891c3750aa3cdf4b4804f18e0 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Definition.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Definition.php @@ -109,6 +109,16 @@ class Intonation_Library_Widget_Carousel_Definition extends Class_Systeme_Module public function getLayouts() { return $this->getOrderedLayouts($this->getLayoutsList()); } + + + public function getCarouselLayouts() { + return array_filter($this->getLayouts(), + function($key) + { + return false !== strpos($key, 'carousel'); + }, + ARRAY_FILTER_USE_KEY); + } } diff --git a/library/templates/Intonation/Library/Widget/Carousel/Form.php b/library/templates/Intonation/Library/Widget/Carousel/Form.php index c09a7836af07611d3abebf4b56b82f82883a873d..6b4c366c3f40d50148e8e704e6f88a8620cb3b28 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Form.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Form.php @@ -28,7 +28,9 @@ abstract class Intonation_Library_Widget_Carousel_Form extends ZendAfi_Form_Conf Class_ScriptLoader::getInstance() ->addJQueryReady('toggleVisibilityForElement("#link_to_all_url", $("#all_layout, #all_rendering").closest("tr"), function(element) {return ! element.val();});') ->addJQueryReady('checkBoxToggleVisibilityForElement("#link_to_all", $("#all_layout, #all_rendering, #link_to_all_text, #link_to_all_title, #link_to_all_url, #link_to_all_to_main_title").closest("tr"), true);') - ->addJQueryReady('checkBoxToggleVisibilityForElement("#description_html", $("#description_length").closest("tr"), false);'); + ->addJQueryReady('checkBoxToggleVisibilityForElement("#description_html", $("#description_length").closest("tr"), false);') + ->addJQueryReady(sprintf('formSelectToggleVisibilityForElement("#layout", $("#cycle").closest("tr"), ["%s"]);', + $this->getCarouselLayouts())); $this @@ -107,6 +109,13 @@ abstract class Intonation_Library_Widget_Carousel_Form extends ZendAfi_Form_Conf 'all_rendering', ['label' => $this->_('Rendu d\'un document'), 'multiOptions' => $this->getRenderings()]) + + ->addElement('number', + 'cycle', + ['label' => $this->_('Défilement de gauche à droite en secondes ( 0 pour désactiver )'), + 'value' => 0, + 'min' => 0, + 'max' => 60]) ; } @@ -118,10 +127,11 @@ abstract class Intonation_Library_Widget_Carousel_Form extends ZendAfi_Form_Conf ->addToSelectionGroup(['data_sources']) - ->addToDisplaySettingsGroup(['rendering', - 'layout', + ->addToDisplaySettingsGroup(['layout', + 'rendering', 'size', - 'order']) + 'order', + 'cycle']) ->addToShareGroup(['rss', 'embeded_code', @@ -146,6 +156,12 @@ abstract class Intonation_Library_Widget_Carousel_Form extends ZendAfi_Form_Conf } + public function getCarouselLayouts() { + $layouts = (new Intonation_Library_Widget_Carousel_Definition)->getCarouselLayouts(); + return implode('", "', array_keys($layouts)); + } + + public function getAllLayouts() { return $this->getLayouts(); } diff --git a/library/templates/Intonation/Library/Widget/Carousel/Menu/View.php b/library/templates/Intonation/Library/Widget/Carousel/Menu/View.php index 40dc4ccbe0b75b0b6b85669985dee70d2b36f2e5..ee60a1cec480683bceef9e13b44fb8e12b6a6041 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/Menu/View.php +++ b/library/templates/Intonation/Library/Widget/Carousel/Menu/View.php @@ -84,7 +84,7 @@ class Intonation_Library_Widget_Carousel_Menu_View extends Intonation_Library_Wi if (in_array($layout, [Intonation_Library_Widget_Carousel_Menu_Definition::LAYOUT_VERTICAL, Intonation_Library_Widget_Carousel_Menu_Definition::LAYOUT_HORIZONTAL])) - $this->_layout_helper->setCarouselContext($this); + $this->_layout_helper->setRenderingOptions($this); return $this->_layout_helper; } diff --git a/library/templates/Intonation/Library/Widget/Carousel/View.php b/library/templates/Intonation/Library/Widget/Carousel/View.php index dfc5f3a9d7c35b2b9aa55b75bb35cb4aa650d5de..fdf1c4fb545f3095a0707778c96a40839febbe9c 100644 --- a/library/templates/Intonation/Library/Widget/Carousel/View.php +++ b/library/templates/Intonation/Library/Widget/Carousel/View.php @@ -226,7 +226,8 @@ abstract class Intonation_Library_Widget_Carousel_View extends Zendafi_View_Help $this->_layout_helper = new $helper_class; $this->_layout_helper - ->setView($this->view); + ->setView($this->view) + ->setRenderingOptions($this); if (in_array($layout, [Intonation_Library_Widget_Carousel_Definition::MAP, @@ -237,9 +238,6 @@ abstract class Intonation_Library_Widget_Carousel_View extends Zendafi_View_Help if ($layout === Intonation_Library_Widget_Carousel_Definition::MULTIPLE_CAROUSEL) $this->_layout_helper->setNumberOfColumns(3); - if ($layout === Intonation_Library_Widget_Carousel_Definition::LISTING_WITH_OPTIONS) - $this->_layout_helper->setCarouselContext($this); - return $this->_layout_helper; } diff --git a/library/templates/Intonation/Library/Widget/Nav/View.php b/library/templates/Intonation/Library/Widget/Nav/View.php index 9a78169e295470c059b2de95a78abb439c55b406..4792f27388bf5323766a36ed364093addfba2446 100644 --- a/library/templates/Intonation/Library/Widget/Nav/View.php +++ b/library/templates/Intonation/Library/Widget/Nav/View.php @@ -25,12 +25,9 @@ class Intonation_Library_Widget_Nav_View extends Intonation_Library_Widget_Carou protected function _getLayoutHelper($layout) { $helper_class = $this->_getLayoutHelperClass($layout); - $this->_layout_helper = new Intonation_View_Menu_RenderNav; - $this->_layout_helper - ->setView($this->view) - ->setCarouselContext($this); - - return $this->_layout_helper; + return $this->_layout_helper = (new Intonation_View_Menu_RenderNav) + ->setView($this->view) + ->setRenderingOptions($this); } diff --git a/library/templates/Intonation/View/Abstract/Carousel.php b/library/templates/Intonation/View/Abstract/Carousel.php index 05aef6b4d5519e51344ffd3785d66baacd16cc32..f18ec5a4f07a14a6bd01d4ffb14336ae5755f50a 100644 --- a/library/templates/Intonation/View/Abstract/Carousel.php +++ b/library/templates/Intonation/View/Abstract/Carousel.php @@ -20,7 +20,8 @@ */ -abstract class Intonation_View_Abstract_Carousel extends ZendAfi_View_Helper_BaseHelper { +abstract class Intonation_View_Abstract_Carousel extends Intonation_View_Abstract_Layout { + protected function _renderCarousel($collection, $callback) { if ($collection->isEmpty()) return ''; @@ -51,16 +52,28 @@ $("#%1$s").on("slid.bs.carousel", });', $id)); + if ($data_interval = $this->_getCarouselDataInterval()) + Class_ScriptLoader::getInstance() + ->addJqueryReady(sprintf('$("#%s").carousel("cycle")', + $id)); + return $this->_tag('div', $content, ['id' => $id, 'class' => $this->_carouselClasses(), - 'data-interval' => '0', + 'data-interval' => $data_interval, 'data-ride' => 'carousel']); } + protected function _getCarouselDataInterval() { + return ($cycle = $this->getRenderingOptions()->getCycle()) + ? 1000 * $cycle + : 0; + } + + protected function _indicators($count, $id) { if (1 >= $count) return ''; diff --git a/library/templates/Intonation/View/Abstract/Layout.php b/library/templates/Intonation/View/Abstract/Layout.php new file mode 100644 index 0000000000000000000000000000000000000000..6a14b261b7c4095beecbe96a4a815e745eeb33ba --- /dev/null +++ b/library/templates/Intonation/View/Abstract/Layout.php @@ -0,0 +1,39 @@ +<?php +/** + * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Intonation_View_Abstract_Layout extends ZendAfi_View_Helper_BaseHelper { + + protected $_rendering_options; + + + public function setRenderingOptions($context) { + $this->_rendering_options = $context; + return $this; + } + + + public function getRenderingOptions() { + return $this->_rendering_options + ? $this->_rendering_options + : new Intonation_Library_Widget_Carousel_NullContext; + } +} diff --git a/library/templates/Intonation/View/Menu/Abstract.php b/library/templates/Intonation/View/Menu/Abstract.php index 586212303da2aca939302b69b45be31df2ec3097..9879fc619ca481ff772f5fe208c58d7ee07efbed 100644 --- a/library/templates/Intonation/View/Menu/Abstract.php +++ b/library/templates/Intonation/View/Menu/Abstract.php @@ -20,11 +20,9 @@ */ -abstract class Intonation_View_Menu_Abstract extends ZendAfi_View_Helper_BaseHelper { +abstract class Intonation_View_Menu_Abstract extends Intonation_View_Abstract_Layout { - - protected $_carousel_context, - $_settings, + protected $_settings, $_menu_id, $_profile_id; @@ -55,10 +53,7 @@ abstract class Intonation_View_Menu_Abstract extends ZendAfi_View_Helper_BaseHel protected function _initFromContext() { - if ( ! $this->_carousel_context) - return null; - - if ( ! $this->_settings = $this->_carousel_context->getSettings()) + if ( ! $this->_settings = $this->getRenderingOptions()->getSettings()) return null; if ( ! $menu_id = $this->_settings->getMenu()) @@ -140,10 +135,4 @@ abstract class Intonation_View_Menu_Abstract extends ZendAfi_View_Helper_BaseHel protected function _getFlexColumn() { return ''; } - - - public function setCarouselContext($context) { - $this->_carousel_context = $context; - return $this; - } } \ No newline at end of file diff --git a/library/templates/Intonation/View/RenderAccordionCarousel.php b/library/templates/Intonation/View/RenderAccordionCarousel.php index e899a00a869a3756069a96d8db72a515f8c4562d..f667c013af9b3da13020627db9ba5f93e9d87a95 100644 --- a/library/templates/Intonation/View/RenderAccordionCarousel.php +++ b/library/templates/Intonation/View/RenderAccordionCarousel.php @@ -20,7 +20,7 @@ */ -class Intonation_View_RenderAccordionCarousel extends ZendAfi_View_Helper_BaseHelper { +class Intonation_View_RenderAccordionCarousel extends Intonation_View_Abstract_Layout { protected $_id; @@ -41,8 +41,8 @@ class Intonation_View_RenderAccordionCarousel extends ZendAfi_View_Helper_BaseHe foreach($elements as $element) { $html []= (new Intonation_View_RenderAccordionCarousel_Content($this->view, - $element, - $this->_id)) + $element, + $this->_id)) ->beCollapsed() ->render($content_callback); diff --git a/library/templates/Intonation/View/RenderGrid.php b/library/templates/Intonation/View/RenderGrid.php index f89f66e9f3caf5ca5debc72622d55497e17edd94..513a8a49fd8a99e24195b01cc96642f03302a887 100644 --- a/library/templates/Intonation/View/RenderGrid.php +++ b/library/templates/Intonation/View/RenderGrid.php @@ -20,7 +20,7 @@ */ -class Intonation_View_RenderGrid extends ZendAfi_View_Helper_BaseHelper { +class Intonation_View_RenderGrid extends Intonation_View_Abstract_Layout { public function renderGrid($collection, $callback) { diff --git a/library/templates/Intonation/View/RenderHorizontalList.php b/library/templates/Intonation/View/RenderHorizontalList.php index 592173a1ee8686afb120aa36ec7a0eb46dd598cb..c94554563cfb2ab66dbca7918f0907d5af26c832 100644 --- a/library/templates/Intonation/View/RenderHorizontalList.php +++ b/library/templates/Intonation/View/RenderHorizontalList.php @@ -20,7 +20,7 @@ */ -class Intonation_View_RenderHorizontalList extends ZendAfi_View_Helper_BaseHelper { +class Intonation_View_RenderHorizontalList extends Intonation_View_Abstract_Layout { public function renderHorizontalList($collection, $callback) { if ($collection->isEmpty()) diff --git a/library/templates/Intonation/View/RenderList.php b/library/templates/Intonation/View/RenderList.php index f7b5fee89e058f2932367f3945642bb25f6a816b..8ac6c4dad7aaad0cb1a6e1c22ee4192439ffdb02 100644 --- a/library/templates/Intonation/View/RenderList.php +++ b/library/templates/Intonation/View/RenderList.php @@ -20,7 +20,7 @@ */ -class Intonation_View_RenderList extends ZendAfi_View_Helper_BaseHelper { +class Intonation_View_RenderList extends Intonation_View_Abstract_Layout { public function setIdModule() { return $this; diff --git a/library/templates/Intonation/View/RenderMap.php b/library/templates/Intonation/View/RenderMap.php index 97074718305df2382c893263bc6b623f6497fbe3..630a55fd1919ccc17340601ff0cd9c0d1e5e82c2 100644 --- a/library/templates/Intonation/View/RenderMap.php +++ b/library/templates/Intonation/View/RenderMap.php @@ -20,7 +20,7 @@ */ -class Intonation_View_RenderMap extends ZendAfi_View_Helper_BaseHelper { +class Intonation_View_RenderMap extends Intonation_View_Abstract_Layout { protected $_id_module, $_osm_helper; diff --git a/library/templates/Intonation/View/RenderTruncateList.php b/library/templates/Intonation/View/RenderTruncateList.php index 68a195ae59007cb9e33fc11e7088b8bbea79a3e9..dae9aa91c8846458aca1886ff170a307654b51ff 100644 --- a/library/templates/Intonation/View/RenderTruncateList.php +++ b/library/templates/Intonation/View/RenderTruncateList.php @@ -20,7 +20,7 @@ */ -class Intonation_View_RenderTruncateList extends ZendAfi_View_Helper_BaseHelper { +class Intonation_View_RenderTruncateList extends Intonation_View_Abstract_Layout { protected $_min_size_for_tools = 3, @@ -29,8 +29,7 @@ class Intonation_View_RenderTruncateList extends ZendAfi_View_Helper_BaseHelper $_container_id, $_widget_id, $_top_tools_id, - $_bottom_tools_id, - $_carousel_context; + $_bottom_tools_id; public function renderTruncateList($collection, $callback, $page_size = 3) { @@ -140,23 +139,10 @@ class Intonation_View_RenderTruncateList extends ZendAfi_View_Helper_BaseHelper protected function _ajaxifyList($collection) { $helper = (new Intonation_Library_AjaxPaginatedListHelper) ->setView($this->view) - ->setCarouselContext($this->getCarouselContext()) + ->setCarouselContext($this->getRenderingOptions()) ->setCollection($collection) - ->setOrder($this->getCarouselContext()->getOrder()); + ->setOrder($this->getRenderingOptions()->getOrder()); return $this->view->renderAjaxPaginatedList($helper); } - - - public function setCarouselContext($carousel) { - $this->_carousel_context = $carousel; - return $this; - } - - - public function getCarouselContext() { - return $this->_carousel_context - ? $this->_carousel_context - : new Intonation_Library_Widget_Carousel_NullContext; - } } \ No newline at end of file diff --git a/library/templates/Intonation/View/RenderWall.php b/library/templates/Intonation/View/RenderWall.php index e70e416787399b6f3b1eafbbed371938763d681c..1c8385601cbd530ae32987d3ff8689f8ce5f7354 100644 --- a/library/templates/Intonation/View/RenderWall.php +++ b/library/templates/Intonation/View/RenderWall.php @@ -20,7 +20,7 @@ */ -class Intonation_View_RenderWall extends ZendAfi_View_Helper_BaseHelper { +class Intonation_View_RenderWall extends Intonation_View_Abstract_Layout { protected $_masonry_id, $_masonry_extra_class = ''; diff --git a/tests/scenarios/Templates/TemplatesArticlesTest.php b/tests/scenarios/Templates/TemplatesArticlesTest.php index cbc6470dc045d9137360510f50359805446e1d9b..c08533a98667dd51ef020853067232eeae20e7f2 100644 --- a/tests/scenarios/Templates/TemplatesArticlesTest.php +++ b/tests/scenarios/Templates/TemplatesArticlesTest.php @@ -146,6 +146,18 @@ class TemplatesArticlesEditWidgetTest extends TemplatesArticlesWidgetTestCase { public function formShouldContainsCheckboxDescriptionHtml() { $this->assertXPath('//input[@type="checkbox"][@name="description_html"][not(@checked)]'); } + + + /** @test */ + public function formCycleShouldBeEqualsToZero() { + $this->assertXPath('//input[@type="number"][@name="cycle"][@value="0"]'); + } + + + /** @test */ + public function cycleShouldBeVisibleWhenCarouselLayoutIsSelected() { + $this->assertXPathContentContains('//script', '$(function(){formSelectToggleVisibilityForElement("#layout", $("#cycle").closest("tr"), ["carousel", "multiple_carousel", "multiple_carousel_plus"]);});'); + } } diff --git a/tests/scenarios/Templates/TemplatesMenuTest.php b/tests/scenarios/Templates/TemplatesMenuTest.php index 888b6aea01b5746db2b859cdde2c060b429b3a0e..858bdb6e82bbd0a1dba0cf68b567fb4903c0f98c 100644 --- a/tests/scenarios/Templates/TemplatesMenuTest.php +++ b/tests/scenarios/Templates/TemplatesMenuTest.php @@ -324,7 +324,8 @@ class TemplatesMenuEditWidgetPostTest extends Admin_AbstractControllerTestCase { $profile->assertSave(); $this->postDispatch('/admin/widget/edit-widget/id/1/id_profil/4', - ['layout' => 'wall']); + ['layout' => 'wall', + 'cycle' => '2']); } @@ -337,6 +338,17 @@ class TemplatesMenuEditWidgetPostTest extends Admin_AbstractControllerTestCase { ->load() ->getLocalSettings()['layout']); } + + + /** @test */ + public function cycleOfMenuWidgetShouldBeTwo() { + Class_Systeme_Widget_Widget::reset(); + $this->assertEquals('2', (new Class_Systeme_Widget_Widget) + ->setId(1) + ->setProfileId(4) + ->load() + ->getLocalSettings()['cycle']); + } } @@ -459,6 +471,10 @@ class TemplatesMenuLayoutsTest extends TemplatesMenuTestCase { '//script', '.on("slid.bs.carousel",'], + ['multiple_carousel', + '//div[@class="carousel slide multiple_carousel"][@data-interval="2000"]', + 'Home'], + ['vertical', '//footer//ul[@class="nav navbar-nav flex-column list-unstyled"]//li', 'Home'], @@ -479,6 +495,7 @@ class TemplatesMenuLayoutsTest extends TemplatesMenuTestCase { Class_Profil::DIV_FOOTER, ['layout' => $layout, 'libelle' => 'menu carousel', + 'cycle' => 2, 'menu' => '7-' . $this->_menu_id]); $this->dispatch('/index'); diff --git a/tests/scenarios/Templates/TemplatesWidgetTest.php b/tests/scenarios/Templates/TemplatesWidgetTest.php index 8adc46b325f5b86b8654d89c3d313ddf2f8076ec..86647fdf29e6f4cdc97e36597c64ef7da0a908c1 100644 --- a/tests/scenarios/Templates/TemplatesWidgetTest.php +++ b/tests/scenarios/Templates/TemplatesWidgetTest.php @@ -1678,3 +1678,23 @@ class TemplatesWidgetCarouselWithDomainFindByIdsTest extends TemplatesWidgetCaro Class_Notice::getAttributesForLastCallOn('findAllByRequeteRecherche')); } } + + + + +class TemplatesWidgetWithTopHighlightLayoutAndCycleTest extends AbstractTemplatesWidgetWithHighlightLayoutTest { + + protected function _widgetSettings() { + return ['rendering' => 'card', + 'cycle' => 2, + 'order' => Class_Systeme_ModulesAccueil_Library::ORDER_ALPHA, + 'libraries' => implode(';', array_keys($this->_libraries)), + 'layout' => 'top_highlight_carousel']; + } + + + /** @test */ + public function carouselDataIntervalShouldBeTwoSecond() { + $this->assertXPath('//div[contains(@class, "boite library")]//div[contains(@class, "carousel slide top_highlight_carousel")][@data-interval="2000"]'); + } +} \ No newline at end of file