Commit 3e774809 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Formulaires multipages : améliorations et modifications (rupture de compatibilité probable)

parent 955f9333
Pipeline #7296 failed with stages
in 24 seconds
......@@ -10,6 +10,7 @@ use Zend\Form\Element\Submit;
* Boutons présents selon le contexte : "Précédent", "Suivant", "Terminer", "Annuler".
*
* @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
* @deprecated Remplacé par {@see MultipageFormNavFieldset}
*/
class MultipageFormNavElement extends Element
{
......@@ -47,36 +48,93 @@ class MultipageFormNavElement extends Element
/**
* @var boolean
*/
private $activatePrevious = false;
private $previousEnabled = false;
/**
* @var boolean
*/
private $activateNext = true;
private $nextEnabled = true;
/**
* @var boolean
*/
private $activateSubmit = false;
private $submitEnabled = false;
/**
* @var boolean
*/
private $activateCancel = true;
private $cancelEnabled = true;
/**
* @var boolean
*/
private $activateConfirm = false;
private $confirmEnabled = false;
/**
* {@inheritDoc}
*/
public function __construct($name = self::NAME, $options = array())
private function __construct($name = null, $options = [])
{
parent::__construct($name, $options);
$this->setPreviousEnabled(false)
->setNextEnabled(true)
->setSubmitEnabled(false)
->setCancelEnabled(true)
->setConfirmEnabled(false);
// $this->getNextButton();
$this->getPreviousButton();
// $this->getCancelButton();
// $this->getSubmitButton();
// $this->getConfirmButton();
$this
->setPreviousEnabled(false)
->setNextEnabled(true)
->setSubmitEnabled(false)
->setCancelEnabled(true)
->setConfirmEnabled(false);
}
/**
* @param array $options
* @return self
*/
static public function create(array $options = []): self
{
return new static(static::NAME, $options);
}
/**
* @param MultipageFormNavElement $prototype
* @return self
*/
static public function createFromPrototype(MultipageFormNavElement $prototype)
{
$instance = clone $prototype;
$instance->setAttributes($prototype->getAttributes());
$instance->setOptions($prototype->getOptions());
$instance->setLabelOptions($prototype->getLabelOptions());
$instance->setValue($prototype->getValue());
$instance->setLabel($prototype->getLabel());
$instance
->setPreviousEnabled(false)
->setNextEnabled(true)
->setSubmitEnabled(false)
->setCancelEnabled(true)
->setConfirmEnabled(false);
return $instance;
}
/**
* @param MultipageFormNavElement $prototype
* @return self
*/
static public function createFromPrototypePrec(MultipageFormNavElement $prototype)
{
$instance = static::create();
$instance->setAttributes($prototype->getAttributes());
$instance->setOptions($prototype->getOptions());
$instance->setLabelOptions($prototype->getLabelOptions());
$instance->setValue($prototype->getValue());
$instance->setLabel($prototype->getLabel());
return $instance;
}
/**
......@@ -87,15 +145,16 @@ class MultipageFormNavElement extends Element
if ($this->nextButton === null) {
$name = $this->getName();
$labelNext = ("Suivant >");
$titleNext = ("Passer à l'étape suivante");
$label = ("Suivant >");
$title = ("Passer à l'étape suivante");
$this->nextButton = new Submit(
$name . '[' . MultipageFormNavElement::NEXT . ']'
$name . '[' . MultipageFormNavElement::NEXT . ']',
['label' => $label]
);
$this->nextButton->setValue($labelNext);
$this->nextButton->setValue($label);
$this->nextButton->setAttributes([
'title' => $titleNext,
'title' => $title,
'class' => 'multipage-nav next']);
}
......@@ -110,16 +169,16 @@ class MultipageFormNavElement extends Element
if ($this->previousButton === null) {
$name = $this->getName();
$labelPrev = ("< Précédent");
$titlePrev = ("Revenir à l'étape précédente");
$label = ("< Précédent");
$title = ("Revenir à l'étape précédente");
$this->previousButton = new Submit(
$name . '[' . MultipageFormNavElement::PREVIOUS . ']',
['label' => $labelPrev]
['label' => $label]
);
$this->previousButton->setValue($labelPrev);
$this->previousButton->setValue($label);
$this->previousButton->setAttributes([
'title' => $titlePrev,
'title' => $title,
'class' => 'multipage-nav previous', 'style'=>'float: left;']);
}
......@@ -134,16 +193,16 @@ class MultipageFormNavElement extends Element
if ($this->cancelButton === null) {
$name = $this->getName();
$labelCancel = ("Annuler");
$titleCancel = ("Abandonner définitivement la saisie");
$label = ("Annuler");
$title = ("Abandonner définitivement la saisie");
$this->cancelButton = new Submit(
$name . '[' . MultipageFormNavElement::CANCEL . ']',
['label' => $labelCancel]
['label' => $label]
);
$this->cancelButton->setValue($labelCancel);
$this->cancelButton->setValue($label);
$this->cancelButton->setAttributes([
'title' => $titleCancel,
'title' => $title,
'class' => 'multipage-nav cancel',
'onclick' => 'askConfirmation(this)',
]);
......@@ -160,16 +219,16 @@ class MultipageFormNavElement extends Element
if ($this->submitButton === null) {
$name = $this->getName();
$labelSubmit = ("Terminer");
$titleSubmit = ("Terminer la saisie");
$label = ("Terminer");
$title = ("Terminer la saisie");
$this->submitButton = new Submit(
$name . '[' . MultipageFormNavElement::SUBMIT . ']',
['label' => $labelSubmit]
['label' => $label]
);
$this->submitButton->setValue($labelSubmit);
$this->submitButton->setValue($label);
$this->submitButton->setAttributes([
'title' => $titleSubmit,
'title' => $title,
'class' => 'multipage-nav submit']);
}
......@@ -184,16 +243,16 @@ class MultipageFormNavElement extends Element
if ($this->confirmButton === null) {
$name = $this->getName();
$labelConfirm = ("Confirmer et enregistrer");
$titleConfirm = ("Confirmer et enregistrer la saisie");
$label = ("Confirmer et enregistrer");
$title = ("Confirmer et enregistrer la saisie");
$this->confirmButton = new Submit(
$name . '[' . MultipageFormNavElement::CONFIRM . ']',
['label' => $labelConfirm]
['label' => $label]
);
$this->confirmButton->setValue($labelConfirm);
$this->confirmButton->setValue($label);
$this->confirmButton->setAttributes([
'title' => $titleConfirm,
'title' => $title,
'class' => 'multipage-nav confirm']);
}
......@@ -208,7 +267,8 @@ class MultipageFormNavElement extends Element
*/
public function setPreviousEnabled($value = true)
{
$this->activatePrevious = $value;
$this->previousEnabled = $value;
return $this;
}
......@@ -220,7 +280,8 @@ class MultipageFormNavElement extends Element
*/
public function setNextEnabled($value = true)
{
$this->activateNext = $value;
$this->nextEnabled = $value;
return $this;
}
......@@ -232,7 +293,8 @@ class MultipageFormNavElement extends Element
*/
public function setSubmitEnabled($value = true)
{
$this->activateSubmit = $value;
$this->submitEnabled = $value;
return $this;
}
......@@ -244,7 +306,8 @@ class MultipageFormNavElement extends Element
*/
public function setCancelEnabled($value = true)
{
$this->activateCancel = $value;
$this->cancelEnabled = $value;
return $this;
}
......@@ -256,7 +319,8 @@ class MultipageFormNavElement extends Element
*/
public function setConfirmEnabled($value = true)
{
$this->activateConfirm = $value;
$this->confirmEnabled = $value;
return $this;
}
......@@ -267,7 +331,7 @@ class MultipageFormNavElement extends Element
*/
public function isPreviousEnabled()
{
return $this->activatePrevious;
return $this->previousEnabled;
}
/**
......@@ -277,7 +341,7 @@ class MultipageFormNavElement extends Element
*/
public function isNextEnabled()
{
return $this->activateNext;
return $this->nextEnabled;
}
/**
......@@ -287,7 +351,7 @@ class MultipageFormNavElement extends Element
*/
public function isSubmitEnabled()
{
return $this->activateSubmit;
return $this->submitEnabled;
}
/**
......@@ -297,7 +361,7 @@ class MultipageFormNavElement extends Element
*/
public function isCancelEnabled()
{
return $this->activateCancel;
return $this->cancelEnabled;
}
/**
......@@ -307,6 +371,6 @@ class MultipageFormNavElement extends Element
*/
public function isConfirmEnabled()
{
return $this->activateConfirm;
return $this->confirmEnabled;
}
}
\ No newline at end of file
<?php
namespace UnicaenApp\Form\Fieldset;
use Zend\Form\Fieldset;
/**
* Classe des fieldsets de récapitulatif / confirmation de saisie dans un formulaire multipage.
*
* @author Unicaen
*/
class MultipageFormConfirmFieldset extends Fieldset
{
}
\ No newline at end of file
<?php
namespace UnicaenApp\Form\Fieldset;
use Zend\Form\Element\Submit;
use Zend\Form\Fieldset;
/**
* Fieldset de navigation au sein d'un formulaire multi-page.
*
* Boutons présents selon la situation : "Précédent", "Suivant", "Terminer", "Confirmer", "Annuler".
*
* @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
*/
class MultipageFormNavFieldset extends Fieldset
{
const NAME = '_nav';
const PREFIX_IN_NAME = '_';
const NAME_NEXT = '_next';
const NAME_PREVIOUS = '_previous';
const NAME_SUBMIT = '_submit';
const NAME_CANCEL = '_cancel';
const NAME_CONFIRM = '_confirm';
/**
* @var boolean
*/
private $previousEnabled = false;
/**
* @var boolean
*/
private $nextEnabled = true;
/**
* @var boolean
*/
private $submitEnabled = false;
/**
* @var boolean
*/
private $cancelEnabled = true;
/**
* @var boolean
*/
private $confirmEnabled = false;
/**
* {@inheritDoc}
*/
private function __construct($name = null, $options = [])
{
parent::__construct($name, $options);
$this
->setPreviousEnabled(false)
->setNextEnabled(true)
->setSubmitEnabled(false)
->setCancelEnabled(true)
->setConfirmEnabled(false);
$this->init();
}
/**
* @param array $options
* @return self
*/
static public function create(array $options = []): self
{
return new static(static::NAME, $options);
}
/**
* @inheritDoc
*/
public function init()
{
parent::init();
$this->add($this->createNextButton());
$this->add($this->createPreviousButton());
$this->add($this->createCancelButton());
$this->add($this->createSubmitButton());
$this->add($this->createConfirmButton());
}
/**
* @return Submit
*/
protected function createNextButton() : Submit
{
$label = ("Suivant >");
$title = ("Passer à l'étape suivante");
$submit = new Submit(
self::NAME_NEXT,
['label' => $label]
);
$submit->setValue($label);
$submit->setAttributes([
'title' => $title,
'class' => 'multipage-nav next']);
return $submit;
}
/**
* @return Submit
*/
public function getNextButton() : Submit
{
/** @var Submit $submit */
$submit = $this->get(self::NAME_NEXT);
return $submit;
}
/**
* @return Submit
*/
protected function createPreviousButton() : Submit
{
$label = ("< Précédent");
$title = ("Revenir à l'étape précédente");
$submit = new Submit(
self::NAME_PREVIOUS,
['label' => $label]
);
$submit->setValue($label);
$submit->setAttributes([
'title' => $title,
'class' => 'multipage-nav previous', 'style'=>'float: left;']);
return $submit;
}
/**
* @return Submit
*/
public function getPreviousButton() : Submit
{
/** @var Submit $submit */
$submit = $this->get(self::NAME_PREVIOUS);
return $submit;
}
/**
* @return Submit
*/
protected function createCancelButton() : Submit
{
$label = ("Annuler");
$title = ("Abandonner définitivement la saisie");
$submit = new Submit(
self::NAME_CANCEL,
['label' => $label]
);
$submit->setValue($label);
$submit->setAttributes([
'title' => $title,
'class' => 'multipage-nav cancel',
'onclick' => 'askConfirmation(this)',
]);
return $submit;
}
/**
* @return Submit
*/
public function getCancelButton() : Submit
{
/** @var Submit $submit */
$submit = $this->get(self::NAME_CANCEL);
return $submit;
}
/**
* @return Submit
*/
protected function createSubmitButton() : Submit
{
$label = ("Terminer");
$title = ("Terminer la saisie");
$submit = new Submit(
self::NAME_SUBMIT,
['label' => $label]
);
$submit->setValue($label);
$submit->setAttributes([
'title' => $title,
'class' => 'multipage-nav submit']);
return $submit;
}
/**
* @return Submit
*/
public function getSubmitButton() : Submit
{
/** @var Submit $submit */
$submit = $this->get(self::NAME_SUBMIT);
return $submit;
}
/**
* @return Submit
*/
protected function createConfirmButton() : Submit
{
$label = ("Confirmer et enregistrer");
$title = ("Confirmer et enregistrer la saisie");
$submit = new Submit(
self::NAME_CONFIRM,
['label' => $label]
);
$submit->setValue($label);
$submit->setAttributes([
'title' => $title,
'class' => 'multipage-nav confirm']);
return $submit;
}
/**
* @return Submit
*/
public function getConfirmButton() : Submit
{
/** @var Submit $submit */
$submit = $this->get(self::NAME_CONFIRM);
return $submit;
}
/**
* Active ou non le bouton "Précédent".
*
* @param boolean $value
* @return self
*/
public function setPreviousEnabled($value = true)
{
$this->previousEnabled = $value;
return $this;
}
/**
* Active ou non le bouton "Suivant".
*
* @param boolean $value
* @return self
*/
public function setNextEnabled($value = true)
{
$this->nextEnabled = $value;
return $this;
}
/**
* Active ou non le bouton "Terminer".
*
* @param boolean $value
* @return self