From 7d7892df2dbc1489ed096378050244739fef17f7 Mon Sep 17 00:00:00 2001 From: gloas <gloas@git-test.afi-sa.fr> Date: Wed, 25 Sep 2013 16:51:59 +0000 Subject: [PATCH] rel #9930 ajout fonction visualiser reponse dans admin/modo/formulaires --- .gitattributes | 2 + .../admin/controllers/ModoController.php | 14 +++- .../modules/admin/views/scripts/head.phtml | 14 +++- .../views/scripts/modo/formulaires.phtml | 7 +- library/ZendAfi/Controller/Action.php | 9 ++- .../ZendAfi/View/Helper/ReponseFormulaire.php | 57 +++++++++++++ public/admin/css/global.css | 40 +++++++++ public/opac/js/subModal.js | 10 ++- .../ModoControllerFormulaireTest.php | 51 +++++++++++- .../View/Helper/ReponseFormulaireTest.php | 81 +++++++++++++++++++ 10 files changed, 269 insertions(+), 16 deletions(-) create mode 100644 library/ZendAfi/View/Helper/ReponseFormulaire.php create mode 100644 tests/library/ZendAfi/View/Helper/ReponseFormulaireTest.php diff --git a/.gitattributes b/.gitattributes index 59a818bc1e6..554c09cb5f0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2872,6 +2872,7 @@ library/ZendAfi/View/Helper/RenderAlbum.php -text library/ZendAfi/View/Helper/RenderDateRange.php -text library/ZendAfi/View/Helper/RenderForm.php -text library/ZendAfi/View/Helper/RenderLieu.php -text +library/ZendAfi/View/Helper/ReponseFormulaire.php -text library/ZendAfi/View/Helper/ReseauxSociaux.php -text library/ZendAfi/View/Helper/ShareByMail.php -text library/ZendAfi/View/Helper/SocialShare.php -text @@ -6179,6 +6180,7 @@ tests/library/ZendAfi/View/Helper/PageContextTest.php -text tests/library/ZendAfi/View/Helper/RenderAlbumTest.php -text tests/library/ZendAfi/View/Helper/RenderFormTest.php -text tests/library/ZendAfi/View/Helper/RenderLieuTest.php -text +tests/library/ZendAfi/View/Helper/ReponseFormulaireTest.php -text tests/library/ZendAfi/View/Helper/ReseauxSociauxTest.php -text tests/library/ZendAfi/View/Helper/SocialShareTest.php -text tests/library/ZendAfi/View/Helper/SubwordsTest.php -text diff --git a/application/modules/admin/controllers/ModoController.php b/application/modules/admin/controllers/ModoController.php index cd739627e05..f1b1e8f2afd 100644 --- a/application/modules/admin/controllers/ModoController.php +++ b/application/modules/admin/controllers/ModoController.php @@ -18,7 +18,7 @@ * along with AFI-OPAC 2.0; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class Admin_ModoController extends Zend_Controller_Action { +class Admin_ModoController extends ZendAfi_Controller_Action { use Trait_Translator; private $_count = 10; @@ -613,6 +613,16 @@ class Admin_ModoController extends Zend_Controller_Action { } + public function visualiserReponseAjaxAction() { + $formulaire = Class_Formulaire::find($this->_getParam('id')); + $article = Class_Article::find($this->_getParam('id_article')); + + $this->renderPopupResult($this->view->_('Réponse au formulaire: ').$article->getTitre(), + $this->view->reponseFormulaire($formulaire), + ['width' => '400', + 'modal_atrib' => 'false']); + } + public function deleteFormulaireAction() { $formulaire_to_delete = Class_Formulaire::find($this->_getParam('id')); $formulaire_to_delete->delete(); @@ -628,7 +638,7 @@ class Admin_ModoController extends Zend_Controller_Action { $this->_redirect('admin/modo/formulaires/id_article/'.$formulaire_to_validate->getIdArticle()); } - + public function exportCsvFormulaireAction() { $this->getHelper('ViewRenderer')->setNoRender(); diff --git a/application/modules/admin/views/scripts/head.phtml b/application/modules/admin/views/scripts/head.phtml index 654ef386ee1..23e7cc6b715 100644 --- a/application/modules/admin/views/scripts/head.phtml +++ b/application/modules/admin/views/scripts/head.phtml @@ -12,9 +12,17 @@ ->loadJQueryUI() ->addInlineScript(sprintf('var baseUrl="%s"; var imagesUrl="%s"; var cssUrl="%s"; var userFilesUrl="%s"', BASE_URL, URL_ADMIN_IMG, URL_ADMIN_CSS, USERFILESURL)) - ->addAdminScripts(array('onload_utils', 'global', 'toolbar')) - ->loadPrettyPhoto() - ->showNotifications(); + ->addAdminScripts(array('onload_utils', 'global', 'toolbar', 'common', 'subModal')) + ->addOPACScripts(array('abonne', 'menu', 'bib', 'avis', 'recherche', 'jquery.placeholder.min', 'accessibility', 'subModal')) + ->loadPrettyPhoto() + ->showNotifications() + ->addJQueryReady(' + $("input").placeholder(); + setupAnchorsTarget(); + autoHideShowConfigurationModule(); + initializeNoticeMurAnimation(); + initializeImgHover(); + initializePopups()'); $script_loader = Class_ScriptLoader::getInstance(); $head_scripts->renderStyleSheets(); diff --git a/application/modules/admin/views/scripts/modo/formulaires.phtml b/application/modules/admin/views/scripts/modo/formulaires.phtml index 1e341b9793b..def5fc8b210 100644 --- a/application/modules/admin/views/scripts/modo/formulaires.phtml +++ b/application/modules/admin/views/scripts/modo/formulaires.phtml @@ -15,8 +15,7 @@ else 'id_article'=>$this->article->getId(), 'liste'=>'all']), $this->_('Afficher toutes les réponses')); -?> -<?php + echo $this->tagAnchor($this->url(['module'=>'admin', 'controller'=>'modo', 'action'=>'export-csv-formulaire', @@ -52,12 +51,16 @@ echo $this->tagAnchor($this->url(['module'=>'admin', foreach($datas as $data) echo '<td>'.$data.'</td>'; echo '<td>'; + echo $this->tagAnchor(['action' => 'visualiser-reponse-ajax', + 'id' => $formulaire->getId()], $this->boutonIco('type=show'), + ['data-popup'=>'true']); echo $this->tagAnchor(['action' => 'delete-formulaire', 'id' => $formulaire->getId()], $this->boutonIco('type=del')); if (!$formulaire->isValidated()) echo $this->tagAnchor(['action' => 'validate-formulaire', 'id' => $formulaire->getId()], $this->boutonIco('type=validate')); + echo '</td>'; echo '</tr>'; } diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php index ffba856e55e..95aa7cb63a2 100644 --- a/library/ZendAfi/Controller/Action.php +++ b/library/ZendAfi/Controller/Action.php @@ -148,12 +148,13 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action { - public function renderPopupResult($title, $content) { + public function renderPopupResult($title, $content, $attribs = []) { $this->getHelper('ViewRenderer')->setNoRender(); $this->getResponse()->setHeader('Content-Type', 'application/json'); - $this->getResponse()->setBody(json_encode(['result' => 'CONTENT', - 'title' => $title, - 'content' => $content])); + $this->getResponse()->setBody(json_encode(array_merge($attribs, + ['result' => 'CONTENT', + 'title' => $title, + 'content' => $content]))); } } ?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/ReponseFormulaire.php b/library/ZendAfi/View/Helper/ReponseFormulaire.php new file mode 100644 index 00000000000..923ef3448a3 --- /dev/null +++ b/library/ZendAfi/View/Helper/ReponseFormulaire.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_View_Helper_ReponseFormulaire extends Zend_View_Helper_HtmlElement { + + protected $_formulaire; + + public function reponseFormulaire($formulaire) { + $this->_formulaire = $formulaire; + $html=''; + $html.= $this->buildReponseContent($this->_formulaire->getDatas()); + $html.= $this->addActionButton(); + + return $html; + } + + public function buildReponseContent($datas) { + $html='<dl>'; + foreach($datas as $name => $value){ + $html.= '<dt>'.$name.'</dt>'; + $html.= '<dd>'.$value.'</dd>'; + } + return $html.='</dl>'; + } + + + public function addActionButton() { + $html=''; + $html.= $this->view->tagAnchor(['action' => 'delete-formulaire', + 'id' => $this->_formulaire->getId()], $this->view->boutonIco('type=del')); + if (!$this->_formulaire->isValidated()) + $html.= $this->view->tagAnchor(['action' => 'validate-formulaire', + 'id' => $this->_formulaire->getId()], + $this->view->boutonIco('type=validate')); + return $html; + } +} + +?> \ No newline at end of file diff --git a/public/admin/css/global.css b/public/admin/css/global.css index ddbde200803..47fb3684ec1 100644 --- a/public/admin/css/global.css +++ b/public/admin/css/global.css @@ -1088,3 +1088,43 @@ div.modules div.pager span { padding-left: 26px; } + + + +#opac-dialog dl + a, +#opac-dialog dl + a + a { + display:inline-block; + padding:10px; +} + +#opac-dialog dl + a { + margin-left:140px; +} + +#opac-dialog dl + a + a { + margin-left:40px; +} + +span.ui-dialog-title { + color:#0058A5; + width: 350px; + text-align:center; +} + +#opac-dialog dl dt { + float:left; + color:#FF6600; + padding:5px; + font-weight:bold; + padding:0px; + margin:0px; +} + +#opac-dialog dl dd, +#opac-dialog dl dt { + padding:5px; +} + +#opac-dialog dl dd { + padding-left:45px; +} \ No newline at end of file diff --git a/public/opac/js/subModal.js b/public/opac/js/subModal.js index b8db498b69b..673aa03a7a5 100644 --- a/public/opac/js/subModal.js +++ b/public/opac/js/subModal.js @@ -31,6 +31,7 @@ function opacDialogFromUrl(url) { function opacDialogFromData(data) { + opacDialogClose(); opacDialog($('<div id="opac-dialog"></div>'), data); } @@ -43,12 +44,17 @@ function opacDialogClose() { function opacDialog(container, data, dialogClass, closeFunc, openFunc, width, height) { var modal_size = initModalSize(width, height); + var modal_atrib=true; var titre = data['title']; - container[0].innerHTML = data['content']; + container[0].innerHTML = data['content']; + if(data['width']) + modal_size['width'] = data['width']; + if(data['modal_atrib'] && data['modal_atrib']=='false') + modal_atrib=false; var modal = container.dialog({ width:modal_size['width'], height:modal_size['height'], - modal:true, + modal:modal_atrib, title: titre, dialogClass: dialogClass, close: closeFunc, diff --git a/tests/application/modules/admin/controllers/ModoControllerFormulaireTest.php b/tests/application/modules/admin/controllers/ModoControllerFormulaireTest.php index 2f7f98f6fcb..d175308d18c 100644 --- a/tests/application/modules/admin/controllers/ModoControllerFormulaireTest.php +++ b/tests/application/modules/admin/controllers/ModoControllerFormulaireTest.php @@ -77,7 +77,12 @@ abstract class ModoControllerFormulaireForArticleTestCase extends Admin_Abstract 'validated' => false]) ->answers([$formulaire_de_lefort]) - ; + ->whenCalled('countNotValidated') + ->answers(1) + + ->whenCalled('find') + ->with('5') + ->answers($formulaire_de_bougie); } } @@ -397,7 +402,7 @@ class ModoControllerFormulaireForArticleListTest extends ModoControllerFormulair public function setUp() { parent::setUp(); - $this->dispatch('admin/modo/formulaires/id_article/12', true); + $this->dispatch('admin/modo/formulaires/id_article/12'); } @@ -410,7 +415,7 @@ class ModoControllerFormulaireForArticleListTest extends ModoControllerFormulair /** @test */ public function lefortShouldBeDisplay() { - $this->assertXPathContentContains('//td', 'Lefort'); + $this->assertXPathContentContains('//td', 'Lefort',$this->_response->getBody()); } @@ -431,6 +436,46 @@ class ModoControllerFormulaireForArticleListTest extends ModoControllerFormulair $this->assertXPath('//tbody//tr[1]//td/a[contains(@href, "admin/modo/validate-formulaire/id_article/12/id/6")]'); } + + /** @test */ + public function aTDShouldContainsActionToVisualiserFormulaireLefort() { + $this->assertXPath('//tbody//tr[1]//td/a[contains(@href, "admin/modo/visualiser-reponse-ajax/id_article/12/id/6")]',$this->_response->getBody()); + } +} + + + +class ModoControllerFormulaireVisualiserReponseArticleTest extends ModoControllerFormulaireForArticleTestCase { + + + public function setUp() { + parent::setUp(); + + $this->dispatch('admin/modo/visualiser-reponse-ajax/id_article/12/id/5', true); + } + + + /** @test **/ + public function actionShouldDisplayDdBougie() { + $result = json_decode($this->_response->getBody()); + $this->assertContains('<dl><dt>nom</dt><dd>Bougie</dd><dt>Prenom</dt><dd>Mireille</dd>',$result->content); + } + + + /** @test **/ + public function actionShouldDisplayDeleteFormulaire() { + $result = json_decode($this->_response->getBody()); + $this->assertContains('delete-formulaire',$result->content); + } + + + /** @test **/ + public function actionShouldDisplayValidateFormulaire() { + $result = json_decode($this->_response->getBody()); + $this->assertContains('validate-formulaire',$result->content); + } + + } ?> diff --git a/tests/library/ZendAfi/View/Helper/ReponseFormulaireTest.php b/tests/library/ZendAfi/View/Helper/ReponseFormulaireTest.php new file mode 100644 index 00000000000..a7d130cb7dc --- /dev/null +++ b/tests/library/ZendAfi/View/Helper/ReponseFormulaireTest.php @@ -0,0 +1,81 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_View_HelperReponseFormulaireTest extends ViewHelperTestCase { + + protected $_html; + + public function setup() { + parent::setup(); + + $zork = + Class_Users::newInstanceWithId(34, + ['login' => 'zork', + 'bib' => Class_Bib::newInstanceWithId(4, ['libelle' => 'Annecy'])]); + + $article = Class_Article::newInstanceWithId(12, ['titre' => 'Inscrivez vous au Hackaton']); + + $formulaire_de_bougie = + Class_Formulaire::newInstanceWithId(5, ['data' => serialize(['nom' => 'Bougie', + 'Prenom' => 'Mireille']), + 'date_creation' => '2012-12-06 10:00:01', + 'article' => $article, + 'validated' => false, + 'user' => $zork]); + + $this->_helper = new ZendAfi_View_Helper_ReponseFormulaire(); + $this->_helper->setView(new ZendAfi_Controller_Action_Helper_View()); + + $this->_html = $this->_helper->reponseFormulaire($formulaire_de_bougie); + } + + + /** @test **/ + public function aDtShouldContainNom() { + $this->assertXPathContentContains($this->_html, + '//dt', + 'nom'); + } + + /** @test **/ + public function aDdShouldContainBougie() { + $this->assertXPathContentContains($this->_html, + '//dd', + 'Bougie'); + } + + /** @test **/ + public function aDtShouldContainPrenom() { + $this->assertXPathContentContains($this->_html, + '//dt', + 'nom'); + } + + /** @test **/ + public function aDdShouldContainMireill() { + $this->assertXPathContentContains($this->_html, + '//dd', + 'Mireille'); + } + +} + +?> \ No newline at end of file -- GitLab