diff --git a/application/modules/admin/controllers/WidgetController.php b/application/modules/admin/controllers/WidgetController.php index 443b3ea71703de37fbdbc3a66614c3b16947d266..9dd126b6c498fa6da32af9da8896fa596ac2e66e 100644 --- a/application/modules/admin/controllers/WidgetController.php +++ b/application/modules/admin/controllers/WidgetController.php @@ -41,7 +41,7 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { || (!$profil = Class_Profil::find($this->_getParam('id_profil')))) return $this->_redirectClose($this->_getReferer()); - if ($this->_request->isPost()) { + if ($this->_request->isPost() && ('' != $this->_getParam('module_type'))) { $new_id = $profil->createNewModuleAccueilId(); $profil->updateModuleConfigAccueil($new_id, ['type_module' => $this->_getParam('module_type'), @@ -53,11 +53,11 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { $profil->getModulePositionInDiv($sibling, $division) + 1); $profil->save(); $this->_setParam('id', $new_id); - return $this->_edit(new Class_Systeme_Widget_Widget()); + return $this->_redirectCloseWithReload(); } $this->view->form = ZendAfi_Form_Configuration_Widget_Add::newWith([]); - $this->view->form->setAction($this->view->url()); + $this->view->form->setAction($this->view->url(['styles_reload' => null])); $this->renderScript('render-form.phtml'); } @@ -84,7 +84,7 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { public function addMenuAction() { (new Class_Systeme_ModulesAccueil_MenuVertical())->addMenu(); $this->_helper->notify($this->_('Menu ajouté')); - return $this->_redirectClose($this->_getReferer()); + return $this->_redirectCloseWithReload($this->_getReferer()); } @@ -127,7 +127,7 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { protected function _render($widget) { $this->view->titre = $widget->getTitle(); $this->view->form = $form = call_user_func_array([$widget->getForm(), 'newWith'], [$widget->forForm()]); - $form->setAction($this->view->url()); + $form->setAction($this->view->url(['styles_reload' => null])); if ($this->_request->isPost() && $form->isValid($this->_getParams($widget))) return $this->_update($widget->setNewDatas($this->_request->getPost())); @@ -149,9 +149,17 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { ? $this->_helper->notify($widget->getSuccessSaveMessage()) : $this->_helper->notify($this->_('Echec de la sauvegarde de la configuration de %s', $widget->getLabel())); + return $this->_redirectCloseWithReload(); + } + + + protected function _redirectCloseWithReload() { + $url = Class_Url::absolute(['styles_reload' => null]); + if('1' === $this->_getParam('styles_reload')) { + return $this->_redirect($url); + } - return ('1' === $this->_getParam('styles_reload')) - ? $this->_redirect(Class_Url::absolute()) - : $this->_redirectClose(Class_Url::absolute()); + $this->_request->setParam('styles_reload' , null); + return $this->_redirectClose($url); } } \ No newline at end of file diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php index 49621af55141715845247ee69be3288b419f8e43..279d4d0525c57f8a5638380da6926fedc4ad5c78 100644 --- a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php @@ -201,6 +201,7 @@ class AnnexeControllerPostEditActionTest extends AnnexeControllerTestCase { /** @test */ public function shouldRedirectToEdit() { + $this->assertRedirect(); $this->assertRedirectTo('/cosmo/annexe/edit/id/98'); } diff --git a/library/ZendAfi/Controller/Plugin/Manager/Annexe.php b/library/ZendAfi/Controller/Plugin/Manager/Annexe.php index 2a845497d240f496fb645c54df83685e2ffdfc15..47a73019831925645f2246df215c291a97014683 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Annexe.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Annexe.php @@ -33,5 +33,11 @@ class ZendAfi_Controller_Plugin_Manager_Annexe extends ZendAfi_Controller_Plugin 'anchorOptions' => ['onclick' => sprintf('return confirm(\'%s\')', $this->_('Etes-vous sûr de vouloir supprimer cette annexe ?'))]]]; } + + + 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 0dc6c8028711afc34d2ceff1f2126a71aa69f012..da4180eb6c7ccfd6758fdc2957d9f72a5ee598db 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Manager.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Manager.php @@ -191,7 +191,7 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi array_merge($this->_getFormValues($model), $this->_request->getParams()), $custom_form ); - $form->setAction($this->_view->url()); + $form->setAction($this->_view->url(['styles_reload' => null])); return $form; } diff --git a/library/ZendAfi/Form/Configuration/Widget/Add.php b/library/ZendAfi/Form/Configuration/Widget/Add.php index 5410991ff287ed4a1466c92986e9686f7f020d53..f56116b4001ae4c8ba3b400d59cc4f7d1bc8a9b8 100644 --- a/library/ZendAfi/Form/Configuration/Widget/Add.php +++ b/library/ZendAfi/Form/Configuration/Widget/Add.php @@ -29,8 +29,10 @@ class ZendAfi_Form_Configuration_Widget_Add extends ZendAfi_Form_Configuration_W $this->addElement('select', 'module_type', ['label' => $this->_('Type de boite à ajouter'), + 'required' => true, 'registerInArrayValidator' => false, - 'multiOptions' => $widgets]) + 'multiOptions' => array_merge(['' => $this->_('Veuillez sélectionner une boite')], + $widgets)]) ->addToSelectionGroup(['module_type']); } } diff --git a/tests/application/modules/admin/controllers/WidgetControllerTest.php b/tests/application/modules/admin/controllers/WidgetControllerTest.php index 235fec888876ff67e9bd633f47acf4df2ea2824c..25d33040816ba2b0866360155ae27d6101b937b0 100644 --- a/tests/application/modules/admin/controllers/WidgetControllerTest.php +++ b/tests/application/modules/admin/controllers/WidgetControllerTest.php @@ -2002,3 +2002,23 @@ class WidgetControllerAddMenuActionTest extends WidgetControllerWidgetConfigurat $this->assertRedirect(); } } + + + + +class WidgetControllerAddActionEmptyPostDispatchTest extends WidgetControllerWidgetConfigurationTestCase { + public function setUp() { + parent::setUp(); + $this->postDispatch('/admin/widget/add/after/6/division/3/id_profil/5', + ['titre' => 'mon titre', + 'boite' => 'red_widget', + 'module_type' => '']); + Class_Profil::clearCache(); + } + + + /** @test */ + public function formShouldBeReload() { + $this->assertXPath('//form'); + } +}