From 47085af714ffddede5ab5b7056b0e6a3c0167c11 Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Sat, 8 Apr 2017 01:12:10 +0200 Subject: [PATCH] CIP #57952 add continue button + improve edition ihm --- .../admin/controllers/ModulesController.php | 4 +- library/ZendAfi/Controller/Action.php | 3 +- .../Controller/Plugin/Manager/Album.php | 8 +-- .../Controller/Plugin/Manager/Article.php | 8 +-- .../Controller/Plugin/Manager/DataProfile.php | 6 +-- .../Controller/Plugin/Manager/Manager.php | 10 ++-- .../View/Helper/Admin/Button/Continue.php | 38 +++++++++++++ .../ZendAfi/View/Helper/Admin/RenderForm.php | 3 ++ .../ZendAfi/View/Helper/Button/Continue.php | 53 +++++++++++++++++++ library/ZendAfi/View/Helper/Button/Submit.php | 14 ++--- public/admin/skins/bokeh74/form.css | 4 ++ public/opac/js/subModal.js | 24 ++++++++- tests/scenarios/Widgets/WidgetsTest.php | 31 +++++++++++ 13 files changed, 180 insertions(+), 26 deletions(-) create mode 100644 library/ZendAfi/View/Helper/Admin/Button/Continue.php create mode 100644 library/ZendAfi/View/Helper/Button/Continue.php diff --git a/application/modules/admin/controllers/ModulesController.php b/application/modules/admin/controllers/ModulesController.php index 9dfd8207184..a54a769d66e 100644 --- a/application/modules/admin/controllers/ModulesController.php +++ b/application/modules/admin/controllers/ModulesController.php @@ -438,7 +438,9 @@ class Admin_ModulesController extends ZendAfi_Controller_Action { if($this->profil->setCfgModules($cfg_modules)->save()) $this->_helper->notify($this->_('La configuration a été enregistrée')); - $this->_redirectClose(Class_Url::absolute()); + return ('1' === $this->_getParam('styles_reload')) + ? $this->_redirect(Class_Url::absolute()) + : $this->_redirectClose(Class_Url::absolute()); } diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index e300a544703..a62e7bab6e6 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -96,7 +96,7 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } - protected function _redirectClose($url, array $options = array()) { + protected function _redirectClose($url, array $options = []) { if (!$this->isPopupRequest()) return $this->_redirect($url, $options); @@ -169,7 +169,6 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } - protected function _stayOnPage() { $this->_redirect($this->_request->getServer('HTTP_REFERER')); } diff --git a/library/ZendAfi/Controller/Plugin/Manager/Album.php b/library/ZendAfi/Controller/Plugin/Manager/Album.php index a758f092aeb..8f2e3c23c22 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Album.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Album.php @@ -512,10 +512,10 @@ class ZendAfi_Controller_Plugin_Manager_Album extends ZendAfi_Controller_Plugin_ protected function _getEditUrl($model) { - return Class_Url::absolute(['action' => 'edit_album', - 'id' => $model->getId(), - 'page' => $this->_getParam('page'), - 'title_search' => $this->_getParam('title_search')]); + return array_merge(parent::_getEditUrl($model), + ['action' => 'edit_album', + 'page' => $this->_getParam('page', null), + 'title_search' => $this->_getParam('title_search', null)]); } diff --git a/library/ZendAfi/Controller/Plugin/Manager/Article.php b/library/ZendAfi/Controller/Plugin/Manager/Article.php index 23c8a088e24..be9b2e21cea 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Article.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Article.php @@ -218,10 +218,10 @@ class ZendAfi_Controller_Plugin_Manager_Article extends ZendAfi_Controller_Plugi protected function _getEditUrl($model) { $this->_request->setParamSources(['_GET']); - $url = parent::_getEditUrl($model) - . (($page = $this->_getParam('page')) ? '/page/'.$page : '') - . (($id_cat = $this->_getParam('id_cat')) ? '/id_cat/'.$id_cat : '') - . (($title_search = $this->_getParam('title_search')) ? '/title_search/' . $title_search : ''); + $url = array_merge(parent::_getEditUrl($model), + ['page' => $this->_getParam('page', null), + 'id_cat' => $this->_getParam('id_cat', null), + 'title_search' => $this->_getParam('title_search', null)]); $this->_request->setParamSources(['_GET', '_POST']); return $url; } diff --git a/library/ZendAfi/Controller/Plugin/Manager/DataProfile.php b/library/ZendAfi/Controller/Plugin/Manager/DataProfile.php index 5dd9ea36309..93122b347f3 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/DataProfile.php +++ b/library/ZendAfi/Controller/Plugin/Manager/DataProfile.php @@ -76,9 +76,9 @@ class ZendAfi_Controller_Plugin_Manager_DataProfile extends ZendAfi_Controller_P } - protected function _getEditUrl($model) { - return sprintf('/cosmo/%s/edit/id/%s', - $this->_request->getControllerName(), $model->getId()); + protected function _redirectToEdit($model) { + $this->_redirectClose(sprintf('/cosmo/%s/edit/id/%s', + $this->_request->getControllerName(), $model->getId())); } } ?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Manager.php b/library/ZendAfi/Controller/Plugin/Manager/Manager.php index 890c1b9b6ad..c527268bbaf 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Manager.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Manager.php @@ -165,15 +165,15 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi protected function _getEditUrl($model) { - return sprintf('/%s/%s/edit/id/%s', - $this->_request->getModuleName(), - $this->_request->getControllerName(), - $model->getId()); + return ['id' => $model->getId()]; } protected function _redirectToEdit($model) { - $this->_redirectClose($this->_getEditUrl($model)); + $url = $this->_view->url($this->_getEditUrl($model)); + return ('1' === $this->_getParam('styles_reload')) + ? $this->_redirect($url) + : $this->_redirectClose($url); } diff --git a/library/ZendAfi/View/Helper/Admin/Button/Continue.php b/library/ZendAfi/View/Helper/Admin/Button/Continue.php new file mode 100644 index 00000000000..88c427d0b65 --- /dev/null +++ b/library/ZendAfi/View/Helper/Admin/Button/Continue.php @@ -0,0 +1,38 @@ +<?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_Button_Continue extends ZendAfi_View_Helper_Button_Continue { + protected function _getDefaultAttribs() { + return array_merge(parent::_getDefaultAttribs(), + ['class' => 'continue', + 'disabled' => 'disabled']); + } + + + protected function _getDefaultButton($attribs) { + return parent::_getDefaultButton($attribs) + ->setImage($this->view->tagImg(Class_Admin_Skin::current() + ->renderIconUrlOn('buttons', + 'validate'))) + ->setOnFormChange('$(\'button.continue\').removeAttr(\'disabled\');'); + } +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Admin/RenderForm.php b/library/ZendAfi/View/Helper/Admin/RenderForm.php index 2d7ea5d7730..61b2d420170 100644 --- a/library/ZendAfi/View/Helper/Admin/RenderForm.php +++ b/library/ZendAfi/View/Helper/Admin/RenderForm.php @@ -62,6 +62,9 @@ class ZendAfi_View_Helper_Admin_RenderForm extends ZendAfi_View_Helper_RenderFor protected function _renderDefaultButtons($form, $buttons = []) { + if($this->view->isPopup()) + $buttons = array_merge([$this->view->Button_Continue()], + $buttons); return $this->_tag('div', implode($buttons), ['class' => 'admin-buttons']); diff --git a/library/ZendAfi/View/Helper/Button/Continue.php b/library/ZendAfi/View/Helper/Button/Continue.php new file mode 100644 index 00000000000..765b9144911 --- /dev/null +++ b/library/ZendAfi/View/Helper/Button/Continue.php @@ -0,0 +1,53 @@ +<?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_Button_Continue extends ZendAfi_View_Helper_Button_Submit { + public function Button_Continue($settings = null) { + $button = $this->_getDefaultButton($this->_getDefaultAttribs()); + + if($settings) + $button->updateAttributes($settings->toArray()); + + return $this->view->button($button); + } + + + protected function _getDefaultButton($attribs) { + return parent::_getDefaultButton($attribs) + ->setText($this->_('Valider et continuer')); + } + + + protected function _getDefaultAttribs() { + return array_merge(parent::_getDefaultAttribs(), + ['title' => $this->_('Enregistrer mes modifications et poursuivre mes modifications'), + 'class' => 'bouton continue']); + } + + + protected function _getAjax() { + return $this->view->isPopup() + ? sprintf('form.attr(\'action\', form.attr(\'action\') + \'/styles_reload/1\');%s', + parent::_getAjax()) + : ''; + } +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Button/Submit.php b/library/ZendAfi/View/Helper/Button/Submit.php index f74fe9736c2..951cb26c75c 100644 --- a/library/ZendAfi/View/Helper/Button/Submit.php +++ b/library/ZendAfi/View/Helper/Button/Submit.php @@ -32,18 +32,20 @@ class ZendAfi_View_Helper_Button_Submit extends ZendAfi_View_Helper_BaseHelper { protected function _getDefaultAttribs() { - $ajax = $this->view->isPopup() - ? 'initializeAjaxFormSubmit(form);' - : ''; - - return ['onclick' => sprintf("var form=$(this).parents('form'); if (!form.size()) form=$(this).parents('.boutons, .admin-buttons').prevAll('form');if (!form.size()) form=$(this).parents('.boutons, .admin-buttons').nextAll('form');%sform.submit(); return false;", - $ajax), + return ['onclick' => sprintf("var form=$(this).parents('form'); if (!form.size()) form=$(this).parents('.boutons, .admin-buttons').prevAll('form');if (!form.size()) form=$(this).parents('.boutons, .admin-buttons').nextAll('form');%sform.submit(); return false;", $this->_getAjax()), 'class' => 'bouton validate', 'type' => 'submit', 'title' => $this->_('Enregistrer mes modifications')]; } + protected function _getAjax() { + return $this->view->isPopup() + ? 'initializeAjaxFormSubmit(form);' + : ''; + } + + protected function _getDefaultButton($attribs) { return (new Class_Entity()) ->setText($this->_('Valider')) diff --git a/public/admin/skins/bokeh74/form.css b/public/admin/skins/bokeh74/form.css index 5eb9f3637bc..d5cf63bc54b 100644 --- a/public/admin/skins/bokeh74/form.css +++ b/public/admin/skins/bokeh74/form.css @@ -35,6 +35,10 @@ width: 15em; } +.admin-form [size] { + width: auto !important; +} + .admin-form tr { line-height: 1.5em; } diff --git a/public/opac/js/subModal.js b/public/opac/js/subModal.js index 4fccbd1ac2c..e4981dbef65 100644 --- a/public/opac/js/subModal.js +++ b/public/opac/js/subModal.js @@ -101,7 +101,7 @@ var refreshPage = function() { - window.location.reload(true); + location.reload(true); } @@ -177,8 +177,30 @@ window.addLoadingClass = function () { + + var initCurrentAnchor = function() { + if (current_anchor != undefined) + return current_anchor; + + var dialog_form = $('#opac-dialog form'); + if (!dialog_form.length) + return undefined; + + current_anchor = undefined; + var action = dialog_form[0].getAttribute('action'); + $('body').find('a[class*="edit_"], .configuration_module a').each(function() { + var href = $(this)[0].getAttribute('href'); + if(action.indexOf(href) > -1) { + return current_anchor = $(this); + } + }); + return current_anchor; + }; + + current_anchor = initCurrentAnchor(); if (current_anchor == undefined) return; + current_anchor.addClass(loading); current_anchor.closest('.boite, .menu_horizontal, article, .colContenu').addClass('current_edition'); } diff --git a/tests/scenarios/Widgets/WidgetsTest.php b/tests/scenarios/Widgets/WidgetsTest.php index 313e03e008b..7b698b4a7fe 100644 --- a/tests/scenarios/Widgets/WidgetsTest.php +++ b/tests/scenarios/Widgets/WidgetsTest.php @@ -536,4 +536,35 @@ class WidgetsDeleteMenuTest extends WidgetsSimpleTestCase { $cfg = Class_Profil::getCurrentProfil()->getCfgMenusAsArray(); $this->assertFalse(isset($cfg['V'])); } +} + + + +class WidgetsPopupMenuTest extends WidgetsSimpleTestCase { + + public function setUp() { + parent::setUp(); + $this->dispatch('admin/widget/edit-menu/id/H/id_profil/2/render/popup', true); + } + + + /** @test */ + public function continueButtonShouldBePresent() { + $this->assertContains('Valider et continuer', $this->_response->getBody()); + } +} + + +class WidgetsButtonsTest extends WidgetsNavSimpleTestCase { + + public function setUp() { + parent::setUp(); + $this->dispatch('admin/widget/edit-menu/id/H/id_profil/2', true); + } + + + /** @test */ + public function continueButtonShouldNotBePresent() { + $this->assertNotXPathContentContains('//button', 'Valider et continuer'); + } } \ No newline at end of file -- GitLab