Commit b2a2ee0b authored by Mat's avatar Mat

Gestion des entités Depot aussi dans la page Groupe/ajaxDisplay

parent a55251df
......@@ -91,6 +91,7 @@ fos_js_routing:
- api_legume_*
- api_offre_*
- api_groupe_*
- api_depot_*
- api_lettre_*
- api_info_*
- potage_offre_legumes_ajax_display
......
......@@ -2,7 +2,7 @@
namespace PotageBundle\Controller;
use APIBundle\Form\DepotAPIType;
use APIBundle\Form\GroupeAPIType;
class GroupeController extends MasterController
......@@ -14,9 +14,11 @@ class GroupeController extends MasterController
public function ajaxDisplayAction()
{
$form = $this->createForm(GroupeAPIType::class);
$formDepot = $this->createForm(DepotAPIType::class);
return $this->render('PotageBundle:Groupe:ajaxDisplay.html.twig', array(
'formGroupe' => $form->createView()
'formGroupe' => $form->createView(),
'formDepot' => $formDepot->createView()
));
}
}
......@@ -18,29 +18,32 @@ class DepotType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
/*
$builder->add('groupe', EntityType::class, array(
'class' => Groupe::class,
'choice_label' => 'getNom',
'placeholder' => 'Associer le point de dépôt à un groupe',
'choice_value' => function (Groupe $groupe = null) {
return $groupe ? $groupe->getId() : '';
},
'label' => 'Groupe',
//'disabled' => true,
'attr' => array('class' => 'form-control form-control-sm'),
));
*/
$builder->add('localisation', TextType::class, array(
'label' => "Localisation",
'label_attr' => array('class' => 'col-form-label'),
'attr' => array(
'class' => 'form-control form-control-sm',
),
));
)); /*
$builder->add('responsable', TextType::class, array(
'label' => "Propriétaire ou personne responsable",
'label_attr' => array('class' => 'col-form-label'),
'attr' => array(
'class' => 'form-control form-control-sm',
),
));
)); */
$builder->add('jourPanier', ChoiceType::class, array(
'label' => "Jour de livraison",
'choices' => array(
......@@ -61,6 +64,7 @@ class DepotType extends AbstractType
$builder->add('heurePanier', TimeType::class, array(
'label' => "Heure de livraison",
'widget' => 'single_text',
//'input' => 'string',
//'data' => new \DateTime('now'),
'label_attr' => array('class' => 'col-form-label'),
'attr' => array(
......
......@@ -21,8 +21,8 @@ class GroupeType extends AbstractType
$builder->add('depot', EntityType::class, array(
'class' => Depot::class,
'choice_label' => 'getNom',
'placeholder' => 'Associer le groupe à un point de dépôt',
'choice_label' => 'getLocalisation',
'placeholder' => '',
'label' => 'Point de dépôt',
'attr' => array('class' => 'form-control form-control-sm'),
));
......
......@@ -30,6 +30,9 @@ class DepotRepository extends \Doctrine\ORM\EntityRepository
public function findOneForAPIReadOne($id)
{
$qb = $this->createQueryBuilder('d')
->select('d.id', 'd.localisation', 'd.heurePanier', 'd.jourPanier')
->join('d.groupe', 'g')
->addSelect('g.id idGroupe', 'g.nom nomGroupe', 'g.slug slugGroupe')
->where('d.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
......
{{ form(formDepot) }}
\ No newline at end of file
<div class="modal fade form-depot-modal" tabindex="-1" role="dialog" aria-labelledby="FormDepotModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title" id="form-depot"></h2>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
{{ form_start(formDepot) }}
<div class="modal-body">
{{ form_errors(formDepot) }}
<div class="form-group row">
<div class="col-sm-4">
{{ form_label(formDepot.localisation) }}
</div>
<div class="col-sm-8">
{{ form_widget(formDepot.localisation) }}
{{ form_errors(formDepot.localisation) }}
</div>
</div>{#
<div class="form-group row">
<div class="col-sm-4">
{{ form_label(formDepot.responsable) }}
</div>
<div class="col-sm-8">
{{ form_widget(formDepot.responsable) }}
{{ form_errors(formDepot.responsable) }}
</div>
</div>#}
<div class="form-group row">
<div class="col-sm-4">
{{ form_label(formDepot.jourPanier) }}
</div>
<div class="col-sm-8">
{{ form_widget(formDepot.jourPanier) }}
{{ form_errors(formDepot.jourPanier) }}
</div>
</div>
<div class="form-group row">
<div class="col-sm-4">
{{ form_label(formDepot.heurePanier) }}
</div>
<div class="col-sm-8">
{{ form_widget(formDepot.heurePanier) }}
{{ form_errors(formDepot.heurePanier) }}
</div>
</div>
<div class="form-group row">
<div class="col-sm-4">
{{ form_label(formDepot.groupe) }}
</div>
<div class="col-sm-8">
{{ form_widget(formDepot.groupe) }}
{{ form_errors(formDepot.groupe) }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-secondary mb-2" data-dismiss="modal">Fermer</button>
{{ form_label(formDepot.sauver) }}
{{ form_widget(formDepot.sauver) }}
</div>
{{ form_rest(formDepot) }}
{{ form_end(formDepot) }}
</div>
</div>
</div>
......@@ -6,63 +6,53 @@
{% block searchbar %}
<nav class="navbar navbar-expand-lg navbar-light navbar-search">
<a href="{{ path('potage_lettre_ajax_display') }}" class="nav-laterale left text-secondary"><i class="fas fa-long-arrow-alt-left fa-fw"></i> Les infolettres</a>
<a href="#" class="nav-laterale right text-secondary">Les utilisateurs <i class="fas fa-long-arrow-alt-right fa-fw"></i></a>
</nav>
{% endblock %}
{% block headerContent %}
{% include '@Potage/Groupe/ajaxForm.html.twig' %}
{% endblock %}
{% block sidebarContent %}
<div class="row">
<aside class="col-3">
<div class="card text-white bg-dark" id="card-button-ajouter">
<div class="card-header">
<a href="javascript: void(0);" class="btn btn-dark btn-block btn-create"
<div class="row">
<div class="col left hd-1">
<h1>{{ block('title') }}</h1>
</div>
<div class="col right hd-1">
<div style="margin-top: 0.65em; margin-bottom: 1em;">
<a href="javascript: void(0);" class="btn btn-outline-dark mb-2 btn-reload">
<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-groupe-modal">
<i class="fas fa-plus"></i>
Créer une nouveau groupe
</a>
</div>
</div>
</aside>
</div>
{% endblock %}
{% block sectionContent %}
<section class="col-9">
<div class="row">
<div class="col left hd-1">
<h1>{{ block('title') }}</h1>
{% block sidebarContent %}
{% include '@Potage/Groupe/ajaxForm.html.twig' %}
{% include '@Potage/Depot/ajaxForm.html.twig' %}
{% endblock %}
</div>
<div class="col right hd-1">
<div style="margin-top: 0.65em;">
{##}
<a href="javascript: void(0);" class="btn btn-outline-dark mb-2 btn-sm btn-reload">
<i class="fas fa-sync-alt"></i>
Rafraîchir la liste
</a>
</div>
</div>
</div>
<table id="maintab" class="table groupes table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Nom</th>
<th scope="col">Description</th>
<th scope="col">Dépôt</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</section>
</div>
{% block sectionContent %}
<section>
<table id="maintab" class="table groupes table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Nom</th>
<th scope="col">Description</th>
<th scope="col">Dépôt</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</section>
{% endblock %}
{% block customJS %}
......@@ -114,11 +104,16 @@
tr.appendChild(td3);
let td4 = document.createElement('td');
td4.textContent = jsonRow.depot;
if (typeof jsonRow.depot !== 'undefined') {
td4.innerHTML = 'Adresse: ' + jsonRow.depot.localisation
+ '<br>Livraison: ' + getFrDow(jsonRow.depot.jour_panier)
+ ', à partir de ' + formatTimeISO(jsonRow.depot.heure_panier);
}
tr.appendChild(td4);
let td5 = document.createElement('td');
td5.appendChild(displayEditGroupe(jsonRow));
td5.appendChild(displayManageDepot(jsonRow));
td5.appendChild(displayDeleteGroupe(jsonRow));
tr.appendChild(td5);
......@@ -152,6 +147,73 @@
}
/*
* Affiche un bouton pour gérer le dépôt associé
* @param json object jsonRow
*/
function displayManageDepot(jsonRow)
{
let btn = document.createElement('button');
btn.classList.add('btn', 'btn-sm', 'mb-1', 'mr-1');
btn.dataset.groupeId = jsonRow.id;
btn.dataset.toggle = "modal";
btn.dataset.target = ".form-depot-modal";
if (typeof jsonRow.depot === 'undefined')
{
btn.innerHTML = '<i class="fas fa-link fa-fw"></i> Associer un point de dépôt';
btn.classList.add('btn-info');
btn.addEventListener('click', function()
{
titleFormDepot.textContent = "Associer un nouveau point de dépôt";
submitURL = Routing.generate('api_depot_create');
formDepot.querySelector('#depot_localisation').value = null;
//formDepot.querySelector('#depot_responsable').value = null;
formDepot.querySelector('#depot_heurePanier').value = null;
formDepot.querySelector('#depot_jourPanier').value = null;
/* test */
formDepot.querySelector('select#depot_groupe').value = jsonRow.id;
setFormSelectBoolValue(formDepot, 'select#depot_groupe', jsonRow.id);
let selGroupe = formDepot.querySelector('select#depot_groupe');
console.log(selGroupe.value);
console.log(selGroupe.selectedIndex);
console.log(selGroupe.options[selGroupe.selectedIndex].innerHTML);
});
}
else
{
btn.innerHTML = '<i class="fas fa-edit fa-fw"></i> Modifier le point de dépôt';
btn.classList.add('btn-dark');
btn.dataset.depotId = jsonRow.depot.id;
btn.addEventListener('click', function()
{
titleFormDepot.textContent = "Modifier le point de dépôt n°" + jsonRow.depot.id;
submitURL = Routing.generate('api_depot_update', {'id': jsonRow.depot.id});
AJAX('GET', submitURL, function(request)
{
let json = JSON.parse(request.responseText);
formDepot.querySelector('#depot_localisation').value = json.localisation;
//formDepot.querySelector('#depot_responsable').value = json.responsable;
formDepot.querySelector('#depot_heurePanier').value = formatTimeISO(json.heurePanier);
formDepot.querySelector('#depot_jourPanier').value = json.jourPanier;
formDepot.querySelector('select#depot_groupe').value = json.idGroupe;
console.log(json);
});
});
}
return btn;
}
/*
* Affiche un bouton pour supprimer une rangée
* @param json object jsonRow
......@@ -188,14 +250,19 @@
let table = document.querySelector('table#maintab.groupes');
let tbody = table.querySelector('tbody');
let form = document.querySelector('form[name=groupe]');
let titleForm = document.querySelector('#form-groupe');
let formDepot = document.querySelector('form[name=depot]');
let titleFormDepot = document.querySelector('#form-depot');
reloadTableGroupe();
reloadButton(function() {
reloadTableGroupe();
});
let form = document.querySelector('form[name=groupe]');
let titleForm = document.querySelector('#form-groupe');
createButton(function() {
titleForm.textContent = 'Nouveau groupe';
......@@ -221,6 +288,18 @@
form);
});
formDepot.addEventListener('submit', function(e)
{
let formDepot = this;
e.preventDefault();
AJAX('POST', submitURL, function()
{
reloadTableGroupe();
$('.form-depot-modal').modal('hide'); // en jquery
},
formDepot);
});
</script>
{% endblock %}
......
......@@ -10,19 +10,30 @@ function formatNumber(number, charSize)
/*
* fonction de date
*/
function getFrDow(key)
{
let listWeekDay = ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'];
return listWeekDay[key];
}
function getFrMonth(key)
{
let listMonth = ['janvier','février','mars','avril','mai','juin','juillet','août','septembre','octobre','novembre','décembre'];
return listMonth[key];
}
function formatDate(date, weekWord = false, monthWord = false)
{
let weekDay = '';
if (weekWord === true) {
let listWeekDay = ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'];
weekDay = listWeekDay[date.getDay()] + ' ';
weekDay = getFrDow(date.getDay()) + ' ';
}
let month = '/' + formatNumber(date.getMonth()+1, 2) + '/';
if (monthWord === true) {
let listMonth = ['janvier','février','mars','avril','mai','juin','juillet','août','septembre','octobre','novembre','décembre'];
month = ' ' + listMonth[date.getMonth()] + ' ';
month = ' ' + getFrMonth(date.getMonth()) + ' ';
}
return weekDay
+ formatNumber(date.getDate(), 2)
+ month
......@@ -37,6 +48,14 @@ function formatDateISO(string)
+ '-' + formatNumber(date.getDate(), 2);
}
function formatTimeISO(string)
{
let date = new Date(string);
return formatNumber(date.getHours(), 2)
+ ':' + formatNumber(date.getMinutes(), 2);
}
/*
* fonction de date
*/
......
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