Skip to content
Snippets Groups Projects
Commit 19899b40 authored by llaffont's avatar llaffont
Browse files

Amélioration workflow des écrans d'édition des plages d'ouverture

parent c1efe288
Branches
Tags
No related merge requests found
......@@ -35,24 +35,27 @@ class Admin_OuverturesController extends ZendAfi_Controller_Action {
$fields['id_site'] = array('element' => 'hidden');
return array(
'model' => array('class' => 'Class_Ouverture',
'name' => 'ouverture',
'order' => 'debut_matin',
'scope' => 'id_site'),
'messages' => array('successful_add' => 'Plage d\'ouverture %s ajoutée',
'successful_save' => 'Plage d\'ouverture %s sauvegardée',
'successful_delete' => 'Plage d\'ouverture %s supprimée'),
return [
'model' => ['class' => 'Class_Ouverture',
'name' => 'ouverture',
'order' => 'debut_matin',
'scope' => 'id_site'],
'messages' => ['successful_add' => 'Plage d\'ouverture %s ajoutée',
'successful_save' => 'Plage d\'ouverture %s sauvegardée',
'successful_delete' => 'Plage d\'ouverture %s supprimée'],
'actions' => array('edit' => array('title' => 'Modifier une plage d\'ouverture'),
'add' => array('title' => 'Ajouter une plage d\'ouverture'),
'index' => array('title' => 'Plages d\'ouverture')),
'after_add' => function() { $this->_redirectToIndex(); },
'after_edit' => function() { $this->_redirectToIndex(); },
'display_groups' => array('plage_ouverture' => array('legend' => 'Plage d\'ouverture',
'elements' => $fields
)
)
);
'actions' => ['edit' => ['title' => 'Modifier une plage d\'ouverture'],
'add' => ['title' => 'Ajouter une plage d\'ouverture'],
'index' => ['title' => 'Plages d\'ouverture']],
'display_groups' => ['plage_ouverture' => ['legend' => 'Plage d\'ouverture',
'elements' => $fields
]
]
];
}
......@@ -66,7 +69,6 @@ class Admin_OuverturesController extends ZendAfi_Controller_Action {
parent::indexAction();
}
}
?>
\ No newline at end of file
......@@ -34,6 +34,7 @@
* ZendForm
[[file:application/modules/admin/controllers/FormationController.php::->addElement('datePicker',%20'date_debut',%20array(][Exemple complet (datePicker, select, CKEditor)]]
[[file:library/ZendAfi/View/Helper/RenderForm.php::class%20ZendAfi_View_Helper_RenderForm%20extends%20ZendAfi_View_Helper_BaseHelper%20{][Helper_RenderForm]]
* A refactorer [0/1]
......
......@@ -21,8 +21,10 @@
class ZendAfi_Controller_Action extends Zend_Controller_Action {
protected $_definitions;
protected $_after_add_closure;
public function init() {
$this->_helper->redirector->setExit(false);
$this->_definitions = new ZendAfi_Controller_Action_RessourceDefinitions($this->getRessourceDefinitions());
}
......@@ -54,6 +56,7 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
if ($this->_setupFormAndSave($model)) {
$this->_helper->notify($this->_definitions->successfulSaveMessage($model));
$this->_redirectToEdit($model);
$this->_definitions->doAfterEdit();
}
$this->_postEditAction($model);
......@@ -67,12 +70,17 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
if ($this->_setupFormAndSave($model)) {
$this->_helper->notify($this->_definitions->successfulAddMessage($model));
$this->_redirectToEdit($model);
$this->_definitions->doAfterAdd();
}
}
protected function _redirectToIndex() {
$this->_redirect('/admin/'.$this->_request->getControllerName().'/index');
$url = '/admin/'.$this->_request->getControllerName().'/index';
if (($scope_field = $this->_definitions->getScope())
&& ($scope_value = $this->_getParam($scope_field)))
$url .= '/'.$scope_field.'/'.$scope_value;
$this->_redirect($url);
}
......
......@@ -50,6 +50,18 @@ class ZendAfi_Controller_Action_RessourceDefinitions {
return $this->getModelLoader()->newInstance();
}
public function doAfterAdd() {
if (isset($this->_definitions['after_add']))
$this->_definitions['after_add']();
}
public function doAfterEdit() {
if (isset($this->_definitions['after_edit']))
$this->_definitions['after_edit']();
}
public function successfulDeleteMessage($model) {
return sprintf($this->_definitions['messages']['successful_delete'],
......
......@@ -30,26 +30,22 @@ abstract class OuverturesControllerTestCase extends Admin_AbstractControllerTest
->whenCalled('save')
->answers(true)
->whenCalled('findAllBy')
->with(array('order' => 'debut_matin',
'id_site' => 1))
->answers(array(
$this->_ouverture_mardi_cran = Class_Ouverture::getLoader()
->newInstanceWithId(2)
->setDebutMatin('08:00:00')
->setFinMatin('12:00:00')
->setDebutApresMidi('13:30:00')
->setFinApresMidi('17:00:00')))
->whenCalled('findAllBy')
->with(array('order' => 'debut_matin',
'id_site' => 3))
->answers(array(
$this->_ouverture_jeudi_annecy = Class_Ouverture::getLoader()
->newInstanceWithId(45)
->setDebutMatin('08:30')
->setFinApresMidi('17:00:00')));
->whenCalled('findAllBy')->with(['order' => 'debut_matin', 'id_site' => 1])
->answers([
$this->_ouverture_mardi_cran = Class_Ouverture::getLoader()
->newInstanceWithId(2)
->setDebutMatin('08:00:00')
->setFinMatin('12:00:00')
->setDebutApresMidi('13:30:00')
->setFinApresMidi('17:00:00')])
->whenCalled('findAllBy')->with(['order' => 'debut_matin', 'id_site' => 3])
->answers([
$this->_ouverture_jeudi_annecy = Class_Ouverture::getLoader()
->newInstanceWithId(45)
->setDebutMatin('08:30')
->setFinApresMidi('17:00:00')]);
}
}
......@@ -162,14 +158,21 @@ class OuverturesControllerEditOuvertureMardiTest extends OuverturesControllerTes
class OuverturesControllerPostEditOuvertureMardiCranTest extends OuverturesControllerTestCase {
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/ouvertures/edit/id_site/1/id/2',
array('debut_matin' => '10:30'));
$this->postDispatch('/admin/ouvertures/edit/id/2',
['debut_matin' => '10:30',
'id_site' => 1]);
}
/** @test */
public function heureDebutMatinShouldBe_10_30() {
$this->assertEquals('10:30', $this->_ouverture_mardi_cran->getDebutMatin());
}
/** @test */
public function responseShouldRedirectToOuverturesIndexSiteOne() {
$this->assertRedirectTo('/admin/ouvertures/index/id_site/1');
}
}
......@@ -202,10 +205,15 @@ class OuverturesControllerPostAddOuvertureCranTest extends OuverturesControllerT
public function setUp() {
parent::setUp();
$this->postDispatch('/admin/ouvertures/add/id_site/3',
array('debut_matin' => '10:30',
'fin_matin' => '11:30',
'id_site' => 3));
Class_Ouverture::whenCalled('save')->willDo(function($model) {
$model->setId(99);
return true;
});
$this->postDispatch('/admin/ouvertures/add', ['debut_matin' => '10:30',
'fin_matin' => '11:30',
'id_site' => 3]);
$this->_new_ouverture = Class_Ouverture::getFirstAttributeForLastCallOn('save');
}
......@@ -214,6 +222,12 @@ class OuverturesControllerPostAddOuvertureCranTest extends OuverturesControllerT
public function newOuvertureSiteIdShouldBeThree() {
$this->assertEquals(3, $this->_new_ouverture->getIdSite());
}
/** @test */
public function responseShouldRedirectToOuverturesIndexSiteThree() {
$this->assertRedirectTo('/admin/ouvertures/index/id_site/3');
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment