From 149b3269183bf1917927622ae8c581310a376274 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Mon, 16 Dec 2013 10:38:47 +0000
Subject: [PATCH] =?UTF-8?q?En=20front,=20lorsque=20un=20article=20est=20sa?=
 =?UTF-8?q?uvegard=C3=A9=20et=20valide,=20la=20fen=C3=AAtre=20ne=20se=20r?=
 =?UTF-8?q?=C3=A9ouvre=20pas?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../admin/controllers/CmsController.php       |  4 +--
 library/ZendAfi/Controller/Action.php         | 32 +++++++++++++++----
 .../admin/controllers/CmsControllerTest.php   |  9 ++++--
 3 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php
index 3c7e4a3cfd9..134c25d8cc2 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 910e314317d..ea25ef3a7e6 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 8df4bfa4490..690a7071691 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');
+	}
 }
 
 
-- 
GitLab