From f69c381ffc4c10a26007f1fd8b4b37a7179b8602 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Wed, 5 Apr 2017 18:23:00 +0200 Subject: [PATCH] CIP #57952 allow menu full configuration in back --- .../views/scripts/profil/menusindex.phtml | 66 +---------- library/Class/ScriptLoader.php | 4 +- .../View/Helper/Accueil/MenuVertical.php | 2 +- library/ZendAfi/View/Helper/Admin/Menus.php | 105 ++++++++++++++++++ library/ZendAfi/View/Helper/TagEditMenu.php | 3 +- public/admin/skins/bokeh74/form.css | 25 ++++- public/admin/skins/bokeh74/global.css | 28 +++++ public/admin/skins/bokeh74/jquery.css | 14 --- .../controllers/ProfilControllerTest.php | 22 ++-- 9 files changed, 175 insertions(+), 94 deletions(-) create mode 100644 library/ZendAfi/View/Helper/Admin/Menus.php diff --git a/application/modules/admin/views/scripts/profil/menusindex.phtml b/application/modules/admin/views/scripts/profil/menusindex.phtml index 761796d9b35..e2c6a4a28b8 100644 --- a/application/modules/admin/views/scripts/profil/menusindex.phtml +++ b/application/modules/admin/views/scripts/profil/menusindex.phtml @@ -1,67 +1,13 @@ -<?php echo $this->partial('profil/_profil_panel.phtml', - array('profil' => $this->profil)); ?> - - +<?php +Class_ScriptLoader::getInstance()->addSearchInputToContent($this->_('Filtrer les menus ')); +echo $this->partial('profil/_profil_panel.phtml', + ['profil' => $this->profil]); -<center> - <div align="center"><br\> - <?php - echo $this->Button_New((new Class_Entity()) +echo $this->Button_New((new Class_Entity()) ->setUrl($this->url(['module' => 'admin', 'controller' => 'widget', 'action' => 'add-menu'], null, true)) ->setText($this->_('Ajouter un menu'))); - ?> - </div> -</center> - - -<br /> -<table cellspacing="0" cellpadding="0"> - <tr class="soustitre"> - <td width="30px">Picto.</td> - <td>Libellé</td> - <td width="20px"> </td> - <td width="20px"> </td> - </tr> - <tr> - <td colspan="3" class="separ"></td> - </tr> - -<?php -$ligne=0; -foreach($this->menus as $id_menu => $menu) -{ - if ($ligne & 1) $class="first"; else $class="second"; - echo '<tr class="'.$class.'" style="height:30px">'; - echo '<td align="center">'; - echo '<img src="'.$this->path_img.$menu["picto"].'">'; - echo '</td>'; - echo '<td>'.$menu["libelle"].'</td>'; - echo '<td align="center">' . - $this->tagEditMenu($id_menu, - $this->profil->getId(), - null) . '</td>'; - - if($id_menu=="H") - echo '<td align="center"><a href="'.$this->url(['action' => 'duplicate-horizontal-menu', - 'id_profil' => $this->profil->getId() ]).'" - onclick="javascript:if(!confirm(\''.$this->traduire('Êtes vous sûr de vouloir dupliquer la configuration du menu horizontal à tous les autres profils ? Cela supprimera la configuration existante pour les autres profils').'\')) return false;" >'. - '<img src="'.URL_ADMIN_IMG.'ico/page_copy.png" alt="Dupliquer le menu horizontal" title="Dupliquer le menu horizontal à tous les autres profils" /></a>'; - - - else - echo '<td align="center"><a href="'.$this->url(array('action' => 'menusmaj', - 'id_profil' => $this->profil->getId(), - 'id_menu' => $id_menu, - 'mode' => 'delete')).'">' . - $this->boutonIco("type=del") . - '</a></td>'; - print('</tr>'); - $ligne ++ ; -} +echo $this->menus(); ?> - -</table> -<br /> diff --git a/library/Class/ScriptLoader.php b/library/Class/ScriptLoader.php index acfb2ad49a5..afce522a3e9 100644 --- a/library/Class/ScriptLoader.php +++ b/library/Class/ScriptLoader.php @@ -808,7 +808,7 @@ class Class_ScriptLoader { return $this->_addSearchInput('.main > .modules', 'input_content_menu', $label, - 'table, thead, th , .form, .form *, center, center *, br, .bouton, a *, a, img, h1, h3, h3 + div , .error, h3 + div *, .soustitre, .soustitre *, tr *, #progressbar, #progressbar *'); + 'table, thead, th , .form, .form *, center, center *, br, .bouton, a *, a, img, h1, h3, h3 + div , .error, h3 + div *, .soustitre, .soustitre *, tr *, #progressbar, #progressbar *, button'); } @@ -816,7 +816,7 @@ class Class_ScriptLoader { return $this->_addSearchInput('.main > .left', 'input_search_menu', $label, - '.menuGaucheAdmin tr, .titre, img, table, tbody, td'); + '.menuGaucheAdmin tr, .titre, img, table, tbody, td, button'); } diff --git a/library/ZendAfi/View/Helper/Accueil/MenuVertical.php b/library/ZendAfi/View/Helper/Accueil/MenuVertical.php index fbb164aa980..6667e2f3c01 100644 --- a/library/ZendAfi/View/Helper/Accueil/MenuVertical.php +++ b/library/ZendAfi/View/Helper/Accueil/MenuVertical.php @@ -53,7 +53,7 @@ class ZendAfi_View_Helper_Accueil_MenuVertical extends ZendAfi_View_Helper_Accue : [Class_Profil::getCurrentProfil()->getId(), $menu]; if (!$profil = Class_profil::find($id_profil)) - return $this->retourErreur($this->translate()->_('Ce menu ne contient aucune entrée.')); + return $this->retourErreur($this->_('Ce menu ne contient aucune entrée.')); $this->_menu_id_profil = $id_profil; $this->_menu_id = $menu; diff --git a/library/ZendAfi/View/Helper/Admin/Menus.php b/library/ZendAfi/View/Helper/Admin/Menus.php new file mode 100644 index 00000000000..8513a05b257 --- /dev/null +++ b/library/ZendAfi/View/Helper/Admin/Menus.php @@ -0,0 +1,105 @@ +<?php +/** + * Copyright (c) 2012-2017, 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 ZendAfi_View_Helper_Admin_Menus extends Zendafi_View_Helper_Basehelper { + protected $_profil; + + public function menus() { + $this->_profil = Class_Profil::getCurrentProfil(); + $datas = $this->_profil->getCfgMenusAsArray(); + $datas['H']['menus'] = (new Class_Systeme_MenuHorizontal($datas['H']['menus']))->asCfgProfil(); + $html = [$this->_renderNav($datas['H'])]; + unset($datas['H']); + + foreach($datas as $id => $params) { + $params['libelle'] .= $this->_tagDeleteMenu($id); + $html[] = $this->_renderMenu($id, $params); + } + + return $this->_tag('div', + implode($html), + ['class' => 'menus']); + } + + + protected function _renderNav($params) { + $params['libelle'] = $this->_tagDuplicateNav() . $params['libelle']; + return $this->_renderMenu('H', $params); + } + + + protected function _tagDuplicateNav() { + return $this->view->tagAnchor($this->view->url(['action' => 'duplicate-horizontal-menu']), + $this->view->tagImg(Class_Admin_Skin::current() + ->renderIconUrlOn('actions', + 'copy_module')), + ['onclick' => sprintf('if(!confirm(\'%s\'))return false;', + $this->_('Êtes vous sûr de vouloir dupliquer la configuration du menu horizontal à tous les autres profils ? Cela supprimera la configuration existante pour les autres profils')), + 'title' => $this->_('Dupliquer le menu horizontal à tous les autres profils')]); + } + + + protected function _tagDeleteMenu($id) { + return $this->view->tagAnchor($this->view->url(['action' => 'menusmaj', + 'mode' => 'delete', + 'id_menu' => $id]), + $this->view->tagImg(Class_Admin_Skin::current() + ->renderIconUrlOn('actions', + 'delete')), + ['onclick' => sprintf('if(!confirm(\'%s\'))return false;', + $this->_('Êtes vous sûr de vouloir supprimer le menu ?')), + 'title' => $this->_('Supprimer le menu')]); + } + + + protected function _renderMenu($id, $params) { + return $this->_tag('div', $this->_tag('h4', + $this->view->tagEditMenu($id, $this->_profil->getId()) . + $params['libelle']) + . $this->_renderChildren($params['menus'], $id)); + } + + + protected function _renderChildren($children, $parent) { + if(empty($children)) + return ''; + + $html = []; + foreach($children as $key => $child) { + if(isset($child['id_module'])) + $key = $child['id_module']; + + $entry = + $this->view->tagEditMenu($key, $this->_profil->getId(), $parent) . + $child['libelle']; + + if(isset($child['sous_menus']) && (!empty($child['sous_menus']))) { + $entry .= $this->_renderChildren($child['sous_menus'], $parent); + } + + $html[] = $this->_tag('li', $entry); + } + + return $this->_tag('ul', + implode($html)); + } +} diff --git a/library/ZendAfi/View/Helper/TagEditMenu.php b/library/ZendAfi/View/Helper/TagEditMenu.php index b1929bd48ce..d13d1984380 100644 --- a/library/ZendAfi/View/Helper/TagEditMenu.php +++ b/library/ZendAfi/View/Helper/TagEditMenu.php @@ -47,7 +47,8 @@ class ZendAfi_View_Helper_TagEditMenu extends ZendAfi_View_Helper_BaseHelper { $ico = 'edit'; $title = $this->_('Modifier l\'entrée : %s', $menu->getLabel()); - if(null !== $menu->getChildren()) { + if(($menu->getChildren() && is_array($menu->getChildren())) + || (null == $parent_id)) { $title = $this->_('Modifier le menu : %s', $menu->getLabel()); $ico = 'menu_configuration'; } diff --git a/public/admin/skins/bokeh74/form.css b/public/admin/skins/bokeh74/form.css index fa4f6b93c2f..a8a32b9d7e8 100644 --- a/public/admin/skins/bokeh74/form.css +++ b/public/admin/skins/bokeh74/form.css @@ -83,4 +83,27 @@ z-index: 100; display: block; top: 0; -} \ No newline at end of file +} + +.admin-form #liste_picto_picto td { + width: 20px; +} + +.admin-form #liste_picto_picto td img { + width: 16px; + height: 16px; +} + +.admin-form table td { + border: none !important; +} + +.admin-form table td.gauche > *, +.admin-form table td.gauche { + text-align: left !important; +} + +.admin-form table td.droite > *, +.admin-form table td.droite { + text-align: right !important; +} diff --git a/public/admin/skins/bokeh74/global.css b/public/admin/skins/bokeh74/global.css index c443318cd3a..c8dd050dda3 100755 --- a/public/admin/skins/bokeh74/global.css +++ b/public/admin/skins/bokeh74/global.css @@ -62,6 +62,8 @@ td[id*="menu_item"] { background-color: var(--even-line-highlight); } +.modules .menus > div:hover, +.modules .menus > div li:hover, [class*=edit-multiple] .modules form tr:hover, .modules .profils ul li li:hover, .modules [class*="models"] tbody tr:hover, @@ -844,4 +846,30 @@ form .droite { .modules .bokeh-days > a { font-size: 1.1em; +} + +.modules .menus ul { + padding-left: 2em; +} + +.modules .menus > div img { + height: 16px; + width: 16px; +} + +.modules .menus > div { + display: inline-block; + width: 32%; + overflow: hidden; + vertical-align: top; +} + +.profils.form { + max-height: 15em; + overflow-y: auto; + overflow-x: hidden; +} + +.modules .menus h4 { + margin: 0.5em; } \ No newline at end of file diff --git a/public/admin/skins/bokeh74/jquery.css b/public/admin/skins/bokeh74/jquery.css index 65d5cb57a62..b0f420d9de9 100644 --- a/public/admin/skins/bokeh74/jquery.css +++ b/public/admin/skins/bokeh74/jquery.css @@ -167,20 +167,6 @@ body .ui-state-active .ui-accordion-header-icon { transform: rotate(-90deg); } -body .ui-dialog table td { - border: none !important; -} - -body .ui-dialog table td.gauche *, -body .ui-dialog table td.gauche { - text-align: left !important; -} - -body .ui-dialog table td.droite *, -body .ui-dialog table td.droite { - text-align: right !important; -} - body .ui-front { z-index: 101; } \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/ProfilControllerTest.php b/tests/application/modules/admin/controllers/ProfilControllerTest.php index adb8fe9c2c6..15dd576dab0 100644 --- a/tests/application/modules/admin/controllers/ProfilControllerTest.php +++ b/tests/application/modules/admin/controllers/ProfilControllerTest.php @@ -684,22 +684,14 @@ class Admin_ProfilControllerProfilJeunesseTestMenusIndex extends Admin_ProfilCon ->whenCalled('findAllByZoneAndBib') ->answers(array($profil_portail, $this->profil_jeunesse, $profil_vide)); - $this->dispatch('/admin/profil/menusindex?id_profil=5'); - } - - - /** @test */ - public function menusindexPageShouldDisplayMenuVerticalAndHorizontal() { - $this->assertQueryContentContains("tr.second td", "Menu horizontal"); - $this->assertQueryContentContains("tr.first td", "Menu"); + $this->dispatch('/admin/profil/menusindex/id_profil/5'); } /** @test */ public function profilJeunessePanelShouldBeVisible() { $this->assertXPathContentContains("//div[contains(@class,'profils')]//ul//li//div", - "Profil Jeunesse", - $this->_response->getBody()); + "Profil Jeunesse"); } @@ -710,29 +702,29 @@ class Admin_ProfilControllerProfilJeunesseTestMenusIndex extends Admin_ProfilCon /** @test */ public function editMenuHorizontalLink() { - $this->assertXPath("//tr[@class='second']//td//a[contains(@href, 'admin/widget/edit-menu/id/H/id_profil/5')]"); + $this->assertXPath("//a[contains(@href, 'admin/widget/edit-menu/id/H/id_profil/5')]"); } /** @test */ public function duplicateHorizontalMenu() { - $this->assertXPath("//tr[@class='second']//td//a[contains(@href, 'admin/profil/duplicate-horizontal-menu/id_profil/5')]"); + $this->assertXPath("//a[contains(@href, 'admin/profil/duplicate-horizontal-menu/id_profil/5')]"); } /** @test */ public function cannotDeleteMenuHorizontalLink() { - $this->assertNotXPath("//tr[@class='second']//td//a[contains(@href, 'menusmaj/id_profil/5/id_menu/H/mode/delete')]"); + $this->assertNotXPath("//a[contains(@href, 'menusmaj/id_profil/5/id_menu/H/mode/delete')]"); } /** @test */ public function editMenuVerticalLink() { - $this->assertXPath("//tr[@class='first']//td//a[contains(@href, 'admin/widget/edit-menu/id/V/id_profil/5/backUrl')]"); + $this->assertXPath("//a[contains(@href, 'admin/widget/edit-menu/id/V/id_profil/5/backUrl')]"); } /** @test */ public function deleteMenuHorizontalLink() { - $this->assertXPath("//tr[@class='first']//td//a[contains(@href, 'menusmaj/id_profil/5/id_menu/V/mode/delete')]"); + $this->assertXPath("//a[contains(@href, 'menusmaj/id_profil/5/mode/delete/id_menu/V')]"); } -- GitLab