diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php index 3c7e4a3cfd9d00d0a3003cae53efbe1a8b1a582b..134c25d8cc2c3f24c67e12aa18ff8fe0112653f0 100644 --- a/application/modules/admin/controllers/CmsController.php +++ b/application/modules/admin/controllers/CmsController.php @@ -205,7 +205,7 @@ class Admin_CmsController extends ZendAfi_Controller_Action { $this->updateConfigBoiteNews($id_module,$article); $this->_helper->notify('Article ajouté '.$article->getNotifyMessage()); - $this->_redirect(sprintf('admin/cms/newsedit/id/%d', $article->getId())); + $this->_redirectClose(sprintf('admin/cms/newsedit/id/%d', $article->getId())); return; } @@ -240,7 +240,7 @@ class Admin_CmsController extends ZendAfi_Controller_Action { if ($this->_isArticleSaved($article)) { $this->_helper->notify('Article sauvegardé '.$article->getNotifyMessage()); - $this->_redirect(sprintf('admin/cms/newsedit/id/%d', $article->getId())); + $this->_redirectClose(sprintf('admin/cms/newsedit/id/%d', $article->getId())); return; } diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index 910e314317d9b665cdd9fe84c9210996ce09aa5d..ea25ef3a7e66a3b317d24b012ccbf0adcb606c19 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -49,12 +49,11 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { protected function _redirect($url, array $options = array()) { if ($this->isPopupRequest() && $this->_request->isPost()) { - $this->getHelper('flashMessenger')->addMessage([ZendAfi_Controller_Action_Helper_FlashMessenger::POPUP => ['url' => $this->view->absoluteUrl($url).'/render/popup']]); - $this->getHelper('ViewRenderer')->setNoRender(); - $this->getResponse()->setHeader('Content-Type', 'application/json'); - $this->getResponse()->setBody(json_encode(['result' => 'CONTENT', - 'title' => $this->view->_('Sauvegarde en cours'), - 'content' => '<script>window.location="'.$this->_request->getServer('HTTP_REFERER').'"</script><p>'.$this->view->_('Veuillez patienter...').'</p><img style="display: block;margin:10px auto;" src="'.URL_ADMIN_IMG.'patience.gif">'])); + $this + ->getHelper('flashMessenger') + ->addMessage([ZendAfi_Controller_Action_Helper_FlashMessenger::POPUP => [ + 'url' => $this->view->absoluteUrl($url).'/render/popup']]); + $this->_javascriptRedirectToReferrer(); return; } @@ -62,6 +61,27 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { } + protected function _javascriptRedirectToReferrer() { + $this->getHelper('ViewRenderer')->setNoRender(); + $this->getResponse()->setHeader('Content-Type', 'application/json'); + $this->getResponse()->setBody(json_encode( + ['result' => 'CONTENT', + 'title' => $this->view->_('Sauvegarde en cours'), + 'content' => + '<script>window.location="' + .$this->_request->getServer('HTTP_REFERER').'"</script><p>'.$this->view->_('Veuillez patienter...') + .'</p><img style="display: block;margin:10px auto;" src="'.URL_ADMIN_IMG.'patience.gif">'])); + } + + + protected function _redirectClose($url, array $options = array()) { + if (!$this->isPopupRequest()) + return parent::_redirect($url, $options); + + $this->_javascriptRedirectToReferrer(); + } + + public function getRessourceDefinitions() { return []; } diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php index 8df4bfa4490e292d37d6dcb43502c4dc9ddcd6a6..690a7071691d92aa06d7210567dc407388b430ca 100644 --- a/tests/application/modules/admin/controllers/CmsControllerTest.php +++ b/tests/application/modules/admin/controllers/CmsControllerTest.php @@ -989,8 +989,8 @@ class CmsControllerArticleConcertEditActionPostRenderPopupTest extends CmsContro /** @test */ - public function flashMessengerShouldContainsPopupWithCmsEditUrl() { - $this->assertFlashMessengerContainsPopup('http://localhost'.BASE_URL.'/admin/cms/newsedit/id/4/render/popup'); + public function flashMessengerShouldNotContainsPopupl() { + $this->assertNotFlashMessengerPopup(); } } @@ -1047,6 +1047,11 @@ class CmsControllerArticleConcertEditActionPostWithWrongDataRenderPopupTest exte '//span[@class="error"]', "le champ 'Titre'"); } + + + public function flashMessengerShouldContainsPopupWithCmsEditUrl() { + $this->assertFlashMessengerContainsPopup('http://localhost'.BASE_URL.'/admin/cms/newsedit/id/4/render/popup'); + } }