Commit 2939da3e authored by Mat's avatar Mat

scinde le form OffreAPIType, en créant OffreUpdateAPIType ->

possible que ça crée bugs ou effets de bords !! à vérifier
parent 400392d2
......@@ -6,6 +6,7 @@ namespace APIBundle\Controller;
use APIBundle\Form\OffreAPIType;
use APIBundle\Form\OffreSortedAPIType;
use APIBundle\Form\OffreStatusAPIType;
use APIBundle\Form\OffreUpdateAPIType;
use PotageBundle\Entity\Offre;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
......@@ -103,7 +104,7 @@ class OffreAPIController extends MasterAPIController
$em = $this->getDoctrine()->getManager();
$offre = $em->getRepository('PotageBundle:Offre')->findOneForUpdate($id);
$form = $this->createForm(OffreAPIType::class, $offre);
$form = $this->createForm(OffreUpdateAPIType::class, $offre);
$form->handleRequest($request);
if ($offre === null) {
......
<?php
namespace APIBundle\Form;
use PotageBundle\Form\Offre\OffreUpdateType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class OffreUpdateAPIType extends OffreUpdateType
{
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver->setDefault('csrf_protection', false);
// TODO temporaire, le temps de régler les validations au niveau des Asserts et des FormType
$resolver->setDefault('attr', array('novalidate' => true));
}
}
......@@ -3,8 +3,8 @@
namespace PotageBundle\Controller;
//use APIBundle\Form\OffreLegumesAPIType;
use APIBundle\Form\OffreAPIType;
use APIBundle\Form\OffreSortedAPIType;
use APIBundle\Form\OffreUpdateAPIType;
class OffreLegumesController extends MasterController
{
......@@ -25,7 +25,7 @@ class OffreLegumesController extends MasterController
}
//$form = $this->createForm(OffreLegumesAPIType::class);
$formOffre = $this->createForm(OffreAPIType::class);
$formOffre = $this->createForm(OffreUpdateAPIType::class);
$formSorted = $this->createForm(OffreSortedAPIType::class);
return $this->render('@Potage/OffreLegumes/ajaxDisplay.html.twig', array(
......
<?php
namespace PotageBundle\Form\Offre;
use PotageBundle\Entity\Offre;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class OffreUpdateType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('status', ChoiceType::class, array(
'label' => 'Statut',
'choices' => array(
'En préparation' => 'draft',
'En cours' => 'current',
'Terminé' => 'closed',
//'Poubelle' => 'trash',
),
'label_attr' => array('class' => 'col-form-label'),
'attr' => array(
'class' => 'form-control form-control-sm',
),
));
$builder->add('endedAt', DateType::class, array(
'label' => "Date de clôture de l'offre",
'widget' => 'single_text',
'label_attr' => array('class' => 'col-form-label'),
'attr' => array(
'class' => 'form-control form-control-sm',
),
));
$builder->add('sauver', SubmitType::class, array(
'label' => 'Enregistrer',
'attr' => array('class' => 'btn btn-dark mb-2')
));
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver->setDefault('data_class', Offre::class);
$resolver->setDefault('attr', array(
'class' => 'formulaire formulaire_offre',
));
}
/**
* @return null|string
*/
public function getBlockPrefix()
{
return "offre";
}
}
\ No newline at end of file
......@@ -21,8 +21,7 @@
{% endblock %}
{% block headerContent %}
{# la modale est dans le dossier à côté, dans Offre #}
{% include '@Potage/Offre/modalForm.html.twig' %}
{% include 'PotageBundle:OffreLegumes:modalFormUpdate.html.twig' %}
{% endblock %}
{% block sidebarContent %}
......@@ -41,14 +40,6 @@
<i class="fas fa-sync-alt"></i>
Rafraîchir la liste
</a>
{#
<a href="javascript: void(0);" class="btn btn-dark mb-2 btn-create"
data-toggle="modal" data-target=".form-offre-modal">
<i class="fas fa-plus"></i>
Ajouter un légume
</a>
#}
</div>
</div>
</div>
......@@ -101,7 +92,7 @@
{% if offre.status == 'draft' %}
<div class="card-footer">
<button class="btn btn-dark btn-sm mb-1 mr-1" title="Éditer" data-vivaldi-spatnav-clickable="1"
data-toggle="modal" data-target=".form-offre-modal" data-offre-id="{{ id }}">
data-toggle="modal" data-target=".form-offre-update-modal" data-offre-id="{{ id }}">
<i class="fas fa-pencil-alt fa-fw"></i> Modifier
</button>
</div>
......
......@@ -158,7 +158,7 @@ function reloadBlocOffre()
function(request) {
let json = JSON.parse(request.responseText);
let listStatus = { 'draft': 'Brouillon', 'current': 'Publiée', 'closed': 'Expirée', 'trash': 'Poubelle' };
let listStatus = { 'draft': 'En préparation', 'current': 'Publiée', 'closed': 'Expirée', 'trash': 'Poubelle' };
let colors = {'draft': 'warning', 'current': 'success', 'closed': 'secondary', 'trash': 'danger'};
fieldsOffre[0].textContent = formatStringDateTime(json.createdAt, true, true, false, false);
fieldsOffre[1].textContent = json.updatedAt ? formatStringDateTime(json.updatedAt, true, true, false, false) : null;
......@@ -180,7 +180,7 @@ function editBlocOffre()
formTitle.textContent = "Modifier l'offre " + json.reference;
form.querySelector('#offre_status').value = json.status;
form.querySelector('#offre_endedAt').value = json.endedAt;
form.querySelector('#offre_endedAt').value = formatDateISO(json.endedAt);
submitURL = Routing.generate('api_offre_update', {'id': id_offre});
});
}
......@@ -199,6 +199,6 @@ form.addEventListener('submit', function(e)
e.preventDefault();
AJAX('POST', submitURL, function() {
reloadBlocOffre();
$('.form-offre-modal').modal('hide'); // en jquery
$('.form-offre-update-modal').modal('hide'); // en jquery
}, form);
});
\ No newline at end of file
<div class="modal fade form-offre-update-modal" tabindex="-1" role="dialog" aria-labelledby="FormOffreUpdateModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title" id="form-offre"></h2>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{{ form_start(formOffre) }}
<div class="modal-body">
{{ form_errors(formOffre) }}
<div class="form-group row">
<div class="col-sm-4">
{{ form_label(formOffre.status) }}
</div>
<div class="col-sm-8">
{{ form_widget(formOffre.status) }}
{{ form_errors(formOffre.status) }}
</div>
</div>
<div class="form-group row">
<div class="col-sm-4">
{{ form_label(formOffre.endedAt) }}
</div>
<div class="col-sm-8">
{{ form_widget(formOffre.endedAt) }}
{{ form_errors(formOffre.endedAt) }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary mb-2" data-dismiss="modal">Fermer</button>
{{ form_label(formOffre.sauver) }}
{{ form_widget(formOffre.sauver) }}
</div>
{{ form_rest(formOffre) }}
{{ form_end(formOffre) }}
</div>
</div>
</div>
Markdown is supported
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