From ba7368b9832890ac259116403787dd2f8c4ce16e Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Thu, 17 Oct 2013 13:34:04 +0000
Subject: [PATCH] Modification d'un catalogue dynamique depuis le front /
 kiosque de notices

---
 .../admin/controllers/CatalogueController.php |  4 +-
 .../admin/views/scripts/catalogue/form.phtml  | 11 +++--
 library/Class/Catalogue.php                   |  5 +++
 .../ZendAfi/View/Helper/Accueil/Kiosque.php   | 25 ++++++++++-
 public/opac/css/global.css                    | 26 ++++++++++++
 public/opac/js/subModal.js                    |  3 ++
 .../controllers/CatalogueControllerTest.php   | 34 +++++++++++++--
 tests/library/Class/CatalogueTest.php         |  2 +-
 .../View/Helper/Accueil/KiosqueTest.php       | 41 +++++++++++++++++--
 9 files changed, 136 insertions(+), 15 deletions(-)

diff --git a/application/modules/admin/controllers/CatalogueController.php b/application/modules/admin/controllers/CatalogueController.php
index 662bcba5b89..08ff2f45239 100644
--- a/application/modules/admin/controllers/CatalogueController.php
+++ b/application/modules/admin/controllers/CatalogueController.php
@@ -22,7 +22,7 @@
 // OPAC3 - Controleur CATALOGUES DYNAMIQUES
 //////////////////////////////////////////////////////////////////////////////////////////
 
-class Admin_CatalogueController extends Zend_Controller_Action {
+class Admin_CatalogueController extends ZendAfi_Controller_Action {
 	use Trait_Translator;
 
 	function indexAction()	{
@@ -98,7 +98,7 @@ class Admin_CatalogueController extends Zend_Controller_Action {
 		}
 		if ($this->isSaved($catalogue)) {
 			$this->_helper->notify($this->_('Domaine %s sauvegardé', $catalogue->getLibelle()));
-			$this->_redirect("admin/catalogue/index");
+			$this->_redirect("admin/catalogue/edit/id_catalogue/".$catalogue->getId());
 			return;
 		}
 
diff --git a/application/modules/admin/views/scripts/catalogue/form.phtml b/application/modules/admin/views/scripts/catalogue/form.phtml
index 3475fc72a77..6942fc10800 100644
--- a/application/modules/admin/views/scripts/catalogue/form.phtml
+++ b/application/modules/admin/views/scripts/catalogue/form.phtml
@@ -1,6 +1,9 @@
 <center>
 <div class="form" align="center" >
-	<form name="form" method="post">
+	<form name="form" method="post" action="<?php echo $this->url(['module' => 'admin',
+																																 'controller' => 'catalogue',
+																																 'action' => 'edit',
+																																 'id_catalogue' => $this->catalogue->getId()]); ?>">
 
 		<fieldset>
 			<legend><?php echo $this->traduire('Domaine'); ?> </legend>
@@ -24,7 +27,7 @@
 
 					<tr>
 						<td class="droite" style="width:150px;"><?php echo $this->traduire('Description'); ?></td>
-						<td class="gauche"><textarea name="description" rows='10' onchange="setFlagMaj(true)"><?php echo $this->catalogue->getDescription()?></textarea></td>
+						<td class="gauche"><textarea name="description" cols=40 rows=10 onchange="setFlagMaj(true)"><?php echo $this->catalogue->getDescription()?></textarea></td>
 					</tr>
 
 					<tr>
@@ -130,7 +133,7 @@
 				<table border="0" cellpadding="5" cellspacing="0">
 
 					<tr>
-						<td colspan="2" class="info">Les critères ci-dessous se cumulent entre eux (opérateur logique "ou"). La dewey et la pcdm4 incluent automatiquement tous leurs sous-indices. Les mots matières incluent toutes les sous-vedettes du mot choisi.</td>
+						<td colspan="2" class="info">Les critères ci-dessous se cumulent entre eux (opérateur logique "ou").<br>La dewey et la pcdm4 incluent automatiquement tous leurs sous-indices.<br>Les mots matières incluent toutes les sous-vedettes du mot choisi.</td>
 					</tr>
 
 					<tr>
@@ -183,7 +186,7 @@
 							}
 ?>
 </td>
-				<td align="left" style="padding-left:5px;"> <?php echo $this->bouton('id=29','picto=del.gif','texte=Annuler','url='.BASE_URL.'/admin/catalogue','largeur=120px'); ?></td>
+				<td align="left" style="padding-left:5px;"> <?php echo $this->bouton('id=29','picto=back.gif','texte=Retour','url='.BASE_URL.'/admin/catalogue','largeur=120px'); ?></td>
 			</tr>
 		</table>
 	</form>
diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php
index b4d6245de06..2ab4c612a63 100644
--- a/library/Class/Catalogue.php
+++ b/library/Class/Catalogue.php
@@ -440,6 +440,11 @@ class Class_Catalogue extends Storm_Model_Abstract {
 // Rend les notices selon les preferences (kiosques)
 //------------------------------------------------------------------------------
 	public function getNoticesByPreferences($preferences,$cache_vignette=false)	{
+		if (isset($preferences['id_catalogue']) 
+				&& ($catalogue = Class_Catalogue::getLoader()->find($preferences['id_catalogue']))) {
+			$preferences['catalogue_cache_key'] = serialize($catalogue->toArray());
+		}
+
 		$notices = $this->getNoticesFromCacheByPreferences($preferences, $cache_vignette);
 
 		if ((int)$preferences["aleatoire"] !== 1) 
diff --git a/library/ZendAfi/View/Helper/Accueil/Kiosque.php b/library/ZendAfi/View/Helper/Accueil/Kiosque.php
index 79d6a3e68e0..492bfc80e3c 100644
--- a/library/ZendAfi/View/Helper/Accueil/Kiosque.php
+++ b/library/ZendAfi/View/Helper/Accueil/Kiosque.php
@@ -34,7 +34,8 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba
 
 
 	public function shouldCacheContent() {
-		return parent::shouldCacheContent() && in_array($this->preferences['style_liste'], ['mur', 'vignettes']);
+		return parent::shouldCacheContent() && in_array($this->preferences['style_liste'], 
+																										['mur', 'vignettes', 'chrono']);
 	}
 
 	public function isModeMur() {
@@ -59,12 +60,31 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba
 		$this->contenu = 	(in_array($this->preferences['style_liste'], ['mur', 'vignettes', 'chrono']))
 			? $this->getKiosqueHtml()
 			: $this->getKiosqueIFrame();
-		$this->contenu = $this->getChangeSelectForm().$this->contenu;
+		$this->contenu = 
+			$this->getAddEditLinks()
+			.$this->getChangeSelectForm()
+			.$this->contenu;
 
 		return $this->getHtmlArray();
 	}
 
 
+	public function getAddEditLinks() {
+		if (!Class_Users::isCurrentUserCanAccesBackend())
+			return '';
+
+		if (!$this->preferences['id_catalogue'])
+			return '';
+
+		return $this->view->tagAnchor($this->view->url(['module' => 'admin',
+																										'controller' => 'catalogue',
+																										'action' => 'edit',
+																										'id_catalogue' => $this->preferences['id_catalogue']]),
+																  $this->view->tagImg(URL_ADMIN_IMG.'ico/edit.gif',['title' => $this->view->_('Modifier la sélection')]), 
+																	['data-popup' => 'true']);
+	}
+
+
 	public function getChangeSelectForm() {
 		if (!Class_Users::isCurrentUserCanAccesBackend())
 			return '<div style="display:none"></div>';
@@ -99,6 +119,7 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba
 		// Proprietes en fonction du type de liste
 		$args = array("id_module" => $this->id_module, 
 									'id_profil' => Class_Profil::getCurrentProfil()->getId());
+
 		$action = "kiosque";
 		switch($style_liste) {
 		case "slide_show":
diff --git a/public/opac/css/global.css b/public/opac/css/global.css
index 3a8f19f9bc1..00b4ee34fcc 100644
--- a/public/opac/css/global.css
+++ b/public/opac/css/global.css
@@ -2217,4 +2217,30 @@ table.tablesorter span {
 
 #my_vid {
     text-align: center;
+}
+
+
+
+.form div.tag_selection {
+    width: 400px;
+    border: 1px solid rgb(200, 200, 200);
+    min-height: 15px;
+    background-color: rgb(255, 255, 255);
+    padding: 2px;
+}
+
+
+.form div.tag_saisie {
+    border-right: 1px solid rgb(200, 200, 200);
+    border-width: medium 1px 1px;
+    border-style: none solid solid;
+    border-image: none;
+    min-height: 15px;
+    padding: 5px;
+    margin-left: 5px;
+    display: none;
+    width: auto;
+    background-color: rgb(255, 255, 255);
+    overflow: auto;
+    max-height: 244px;
 }
\ No newline at end of file
diff --git a/public/opac/js/subModal.js b/public/opac/js/subModal.js
index ed7de68b410..420d8ceec29 100644
--- a/public/opac/js/subModal.js
+++ b/public/opac/js/subModal.js
@@ -33,6 +33,9 @@
 
 
 	var  updateAndDestroyCKEditor = function() {
+		if (undefined == window.CKEDITOR)
+			return;
+
 		for ( instance in CKEDITOR.instances )
 			CKEDITOR.instances[instance].updateElement();
 
diff --git a/tests/application/modules/admin/controllers/CatalogueControllerTest.php b/tests/application/modules/admin/controllers/CatalogueControllerTest.php
index 57a9948110c..9ba4e752554 100644
--- a/tests/application/modules/admin/controllers/CatalogueControllerTest.php
+++ b/tests/application/modules/admin/controllers/CatalogueControllerTest.php
@@ -489,6 +489,33 @@ class CatalogueControllerEditCatalogueTest extends AdminCatalogueControllerTestC
 	public function thesaurusGenreInputShouldDisplayPolar() {
 		$this->assertXPathContentContains('//div[@id="GENR_aff"]',"Polar",$this->_response->getBody());
 	}
+
+
+	/** @test */
+	public function formActionShouldBeAdminCatalogueEditIdCatalogueSix() {
+		$this->assertXPath('//form[contains(@action, "/admin/catalogue/edit/id_catalogue/6")]');
+	}
+}
+
+
+
+
+class CatalogueControllerEditCatalogueInPopupTest extends AdminCatalogueControllerTestCase { 
+	protected
+		$_json;
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->dispatch('/admin/catalogue/edit/id_catalogue/6/render/popup', true);
+		$this->_json = json_decode($this->_response->getBody());
+	}
+
+
+	/** @test */
+	public function titleShouldBeModificationDuDomaine() {
+		$this->assertEquals('Modification du domaine: Adultes', $this->_json->title);
+	}
 }
 
 
@@ -530,7 +557,6 @@ class CatalogueControllerEditCataloguePostTest extends AdminCatalogueControllerT
 
 
 
-
 	/** @test */
 	public function catalogueShouldHaveBeenSaved() {
 		$this->assertTrue(Class_Catalogue::getLoader()->methodHasBeenCalled('save'));
@@ -538,12 +564,14 @@ class CatalogueControllerEditCataloguePostTest extends AdminCatalogueControllerT
 
 
 	/** @test */
-	public function responseShouldRedirectToIndex() {
-		$this->assertRedirectTo('/admin/catalogue/index');
+	public function responseShouldRedirectToEditCatalogue() {
+		$this->assertRedirectTo('/admin/catalogue/edit/id_catalogue/6');
 	}
 }
 
 
+
+
 class CatalogueControllerDuplicateCatalogueTest extends AdminCatalogueControllerTestCase { 
 	public function setUp() {
 		parent::setUp();
diff --git a/tests/library/Class/CatalogueTest.php b/tests/library/Class/CatalogueTest.php
index 01cd4944ddf..d87f8cb6783 100644
--- a/tests/library/Class/CatalogueTest.php
+++ b/tests/library/Class/CatalogueTest.php
@@ -510,7 +510,7 @@ class CatalogueTestGetNoticesByPreferences extends ModelTestCase {
 	public function getNoticesWithCachePresentShouldNotCallThem() {
 		$this->mock_cache 
 			->whenCalled('load')
-			->with('2bb98c572bd26113e33aa0516e1d68c1')
+			->with('00b65147ddbdec5da01bebd5e954b42d')
 			->answers(serialize(array('test')))
 
 			->beStrict();
diff --git a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php
index 36a3151b78e..90fa8c0e297 100644
--- a/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php
+++ b/tests/library/ZendAfi/View/Helper/Accueil/KiosqueTest.php
@@ -130,6 +130,37 @@ class ZendAfi_View_Helper_Accueil_KiosqueVignettesWithCatalogueTest extends Zend
 
 
 
+class ZendAfi_View_Helper_Accueil_KiosqueCubeAsRedacteurWithCatalogueTest extends ZendAfi_View_Helper_Accueil_KiosqueTestCase {
+	public function setUp() {
+		parent::setUp();
+
+		ZendAfi_Auth::getInstance()->logUser(Class_Users::newInstanceWithId(54)
+																				 ->beModoBib());
+
+
+		$this->_html = $this->_helper->getBoite();
+	}
+
+
+	public function getPreferences() {
+		return ['type_module' => 'KIOSQUE',
+						'division' => 3,
+						'preferences' => ['id_catalogue' => 12,
+															'style_liste' => 'cube']];
+	}
+
+
+	/** @test */
+	public function linkToEditCatalogueShouldBeVisible() {
+		$this->assertXPath($this->_html,
+											 '//a[contains(@href, "admin/catalogue/edit/id_catalogue/12")]',
+											 $this->_html);
+	}
+}
+
+
+
+
 class ZendAfi_View_Helper_Accueil_KiosqueMurWithPanierAndTriTest extends ZendAfi_View_Helper_Accueil_KiosqueMurTestCase {
 	public function getExtraPreferences() {
 		return ['id_panier' => 15,
@@ -237,7 +268,7 @@ abstract class ZendAfi_View_Helper_Accueil_KiosqueRequetesTestCase extends ZendA
 
 
 
-class ZendAfi_View_Helper_Accueil_KiosqueRequetesAsAdminTest extends ZendAfi_View_Helper_Accueil_KiosqueRequetesTestCase {
+class ZendAfi_View_Helper_Accueil_KiosqueRequetesAsRedacteurTest extends ZendAfi_View_Helper_Accueil_KiosqueRequetesTestCase {
 
 	protected $_catalogue_cinema;
 
@@ -262,14 +293,18 @@ class ZendAfi_View_Helper_Accueil_KiosqueRequetesAsAdminTest extends ZendAfi_Vie
 		$this->assertXPathContentContains($this->_html, '//a', 'Harry Potter et le prisonnier d\'Azkaban');
 	}
 
+
 	/** @test **/
 	public function boiteKiosqueWithAdminLoggedShouldContainsChangeSelectForm() {
 		$this->assertXPath($this->_html, '//div[@class="boite kiosque"]//form[@id="kiosque_selection"]', $this->_html);
 	}
 
 
-
-
+	/** @test */
+	public function linkToEditCatalogueShouldNotBeVisible() {
+		$this->assertNotXPath($this->_html,
+											 '//a[contains(@href, "admin/catalogue/edit/")]');
+	}
 }
 
 
-- 
GitLab