From e37d440cc49d788d76749275d80fb87dfed23b8a Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Wed, 30 Mar 2016 14:27:41 +0200
Subject: [PATCH] dev #35088 plug new cosmo controller

---
 .../controllers/DataProfileController.php     | 14 ++++++--
 .../views/scripts/data-profile/add.phtml      |  4 +++
 .../views/scripts/data-profile/edit.phtml     |  1 +
 .../views/scripts/data-profile/index.phtml    | 11 ++++++
 .../modules/cosmo/views/scripts/module.phtml  |  2 ++
 .../controllers/DataProfileControllerTest.php | 36 +++++++++++++++++++
 cosmogramme/php/_menu.php                     |  2 +-
 7 files changed, 67 insertions(+), 3 deletions(-)
 create mode 100644 cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/add.phtml

diff --git a/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php b/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php
index e08bc38c87f..3a4d37a1dcf 100644
--- a/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php
+++ b/cosmogramme/cosmozend/application/modules/cosmo/controllers/DataProfileController.php
@@ -28,10 +28,11 @@ class Cosmo_DataProfileController extends ZendAfi_Controller_Action {
                         'order' => 'libelle'],
 
             'messages' => ['successful_save' => $this->_('Profil "%s" sauvegardé'),
-                           'successful_add' => $this->_('Profil "%s" ajouté'),],
+                           'successful_add' => $this->_('Profil "%s" ajouté'),
+                           'successful_delete' => $this->_('Profil "%s" supprimé')],
 
             'actions' => ['add' => ['title' => $this->_('Nouveau profil de données')],
-                          'edit' => ['title' => $this->_('Modifier un profil de données')],
+                          'edit' => ['title' => $this->_('Modifier le profil de données : %s')],
                           'index' => ['title' => $this->_('Profils de données')]],
 
             'form_class_name' => 'ZendAfi_Form_Cosmo_DataProfile'];
@@ -99,5 +100,14 @@ class Cosmo_DataProfileController extends ZendAfi_Controller_Action {
     return sprintf('/cosmo/%s/edit/id/%s',
                    $this->_request->getControllerName(), $model->getId());
   }
+
+
+  protected function _redirectToIndex() {
+    $url = '/cosmo/'.$this->_request->getControllerName().'/index';
+    if (($scope_field = $this->_definitions->getScope())
+        && ($scope_value = $this->_getParam($scope_field)))
+      $url .= '/'.$scope_field.'/'.$scope_value;
+    $this->_redirect($url);
+  }
 }
 ?>
\ No newline at end of file
diff --git a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/add.phtml b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/add.phtml
new file mode 100644
index 00000000000..a4574386fb4
--- /dev/null
+++ b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/add.phtml
@@ -0,0 +1,4 @@
+<?php
+echo $this->tag('h1', $this->titre);
+echo $this->renderForm($this->form);
+?>
diff --git a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/edit.phtml b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/edit.phtml
index fb242e29dad..a4574386fb4 100644
--- a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/edit.phtml
+++ b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/edit.phtml
@@ -1,3 +1,4 @@
 <?php
+echo $this->tag('h1', $this->titre);
 echo $this->renderForm($this->form);
 ?>
diff --git a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/index.phtml b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/index.phtml
index afd70c056c5..8b9209d6acc 100644
--- a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/index.phtml
+++ b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/data-profile/index.phtml
@@ -1,4 +1,15 @@
 <?php
+echo $this->tag('h1', $this->titre);
+echo $this->tag('div',
+                $this->bouton('id=add',
+                              'picto=add',
+                              'texte=' . $this->_('Ajouter une profil'),
+                              'url=' . $this->url(['module' => 'cosmo',
+                                                         'controller' => 'data-profile',
+                                                         'action' => 'add'], null, true),
+                              'largeur=220px'),
+                ['style' => 'text-align:center']);
+
 echo $this->tagModelTable($this->data_profiles,
                           [$this->_('Libellé'),
                            $this->_('Type de fichier')],
diff --git a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/module.phtml b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/module.phtml
index ee688fff280..578aaff9899 100644
--- a/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/module.phtml
+++ b/cosmogramme/cosmozend/application/modules/cosmo/views/scripts/module.phtml
@@ -33,6 +33,8 @@ $cosmo_image_url = $cosmo_base_url . 'images/';
 $scripts = Class_ScriptLoader::newInstance()
                                     ->loadJQuery()
                                     ->loadJQueryUI()
+                                    ->loadNotificationJS()
+                                    ->showNotifications()
                                     ->addStyleSheets([$cosmo_base_url . 'css/main.css',
                                                       $cosmo_base_url . 'css/menu.css',
                                                       $cosmo_base_url . 'css/form.css',
diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php
index 4f3595867a6..3cf3ef81669 100644
--- a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php
+++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/DataProfileControllerTest.php
@@ -78,6 +78,11 @@ class Cosmo_DataProfileControllerIndexTest extends Cosmo_DataProfileControllerTe
   }
 
 
+  public function addNewProfileShouldBePresent() {
+    $this->assertXPath('//div', 'Ajouter un profil');
+  }
+
+
   /** @test */
   public function firstTrShouldContainsKoha() {
     $this->assertXPathContentContains('//table//tr[1]/td', 'Koha');
@@ -554,3 +559,34 @@ class Cosmo_DataProfileControllerPostEditFieldsTest extends Cosmo_DataProfileCon
     $this->assertEquals(['code' => '1', 'label' => 'am;af;bb', 'zone_995' => 'z;t;u'], Class_IntProfilDonnees::find(105)->getItemDocTypesPrefs()[1]);
   }
 }
+
+
+class Cosmo_DataProfileControllerAddActionTest extends Cosmo_DataProfileControllerTestCase {
+
+  public function setUp() {
+    parent::setUp();
+    $this->dispatch('/cosmo/data-profile/add', true);
+  }
+
+
+  /** @test */
+  public function formShouldBePresent() {
+    $this->assertXPath('//form');
+  }
+}
+
+
+
+class Cosmo_DataProfileControllerDeleteActionTest extends Cosmo_DataProfileControllerTestCase {
+
+  public function setUp() {
+    parent::setUp();
+    $this->dispatch('/cosmo/data-profile/delete/id/56', true);
+  }
+
+
+  /** @test */
+  public function shouldRedirectToCosmoSlashDataProfileSlashIndex() {
+    $this->assertRedirectTo('/cosmo/data-profile/index');
+  }
+}
diff --git a/cosmogramme/php/_menu.php b/cosmogramme/php/_menu.php
index 0b27b143552..4e8ed257ab3 100644
--- a/cosmogramme/php/_menu.php
+++ b/cosmogramme/php/_menu.php
@@ -94,7 +94,7 @@ else
 	ligneMenu("Variables","config_variables.php");
 	ligneMenu("Démarrer un nouvel OPAC","../cosmozend/cosmo/integration/generate");
 	ligneMenu("Annexes","codif_annexe.php");
-	ligneMenu("Profils de données","config_profil_donnees.php");
+	ligneMenu("Profils de données","../cosmozend/cosmo/data-profile");
 	ligneMenu("Intégrations programmées","config_integrations.php");
 	ligneMenu("Plannification des intégrations","integre_plannification.php");
 	?>
-- 
GitLab