Commit da6c16d3 authored by Mat's avatar Mat
Browse files

Effacer des offres, organisation de la page

parent 8debcdc3
......@@ -100,4 +100,24 @@ class OffreAPIController extends MasterAPIController
return $this->api($form, Response::HTTP_BAD_REQUEST);
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function deleteAction($id)
{
$em = $this->getDoctrine()->getManager();
$offre = $em->getRepository('PotageBundle:Offre')
->findOneForDelete($id);
if ($offre !== null)
{
$em->remove($offre);
$em->flush();
}
return $this->api([]);
}
}
......@@ -74,3 +74,11 @@ api_offre_update_status:
_controller: APIBundle:OffreAPI:updateStatus
methods: [ POST ]
api_offre_delete:
path: /offre/{id}
requirements:
id: \d+
defaults:
_controller: APIBundle:OffreAPI:delete
methods: [ DELETE ]
......@@ -55,6 +55,22 @@ class OffreRepository extends \Doctrine\ORM\EntityRepository
':status' => 'draft'
));
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneForDelete($id)
{
$qb = $this->createQueryBuilder('o')
->where('o.id = :id')
->andWhere('o.status = :status ')
->setParameters(array(
':id'=> $id,
':status' => 'draft'
));
return $qb->getQuery()->getOneOrNullResult();
}
}
......@@ -6,7 +6,7 @@
{% block searchbar %}
<nav class="navbar navbar-expand-lg navbar-light bg-light navbar-search">
<form class="form-inline my-2 my-lg-0" style="margin: auto;">
{#<form class="form-inline my-2 my-lg-0" style="margin: auto;">
<div class="input-group input-group-lg">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroup-sizing-lg"><i class="fas fa-search"></i></span>
......@@ -14,7 +14,7 @@
<input id="search" type="search" class="form-control" placeholder="Rechercher"
aria-label="LargeSearch" aria-describedby="inputGroup-sizing-sm">
</div>
</form>
</form>#}
</nav>
{% endblock %}
......@@ -22,20 +22,17 @@
<div class="row">
<div class="col left hd-1">
<h1>{{ block('title') }}</h1>
<div>
<span id="t_rows">Nombre d'</span> offres
<span id="t_pages"></span>
</div>
</div>
<div class="col right hd-1">
<div style="margin-top: 0.65em;">
{#
<a href="javascript: void(0);" class="btn btn-outline-dark btn-sm btn-reload">
<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>
#}
<a href="javascript: void(0);" class="btn btn-dark btn-sm btn-create"
<a href="javascript: void(0);" class="btn btn-dark btn-sm mb-2 btn-create"
data-toggle="modal" data-target=".form-offre-modal">
<i class="fas fa-plus"></i>
Créer une nouvelle offre
......@@ -48,7 +45,53 @@
{% block sidebarContent %}
<div class="row">
<aside class="col-3">
<h3>Titre</h3>
<div class="card">
<div class="card-body">
<h3 class="card-title"><i class="fas fa-question-circle fa-fw"></i> Info</h3>
<p class="card-text">Les offres sont d'abord <span class="badge badge-pill badge-secondary">1</span> peuplées de légumes,
puis <span class="badge badge-pill badge-secondary">2</span> mise en publication,
puis <span class="badge badge-pill badge-secondary">3</span> insérée dans une infolettre à l'attention d'un groupe.</p>
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<a class="nav-link active" id="v-pills-actuel-tab" data-toggle="pill" href="#v-pills-actuel" role="tab"
aria-controls="v-pills-actuel" aria-selected="true">En ce moment</a>
<a class="nav-link" id="v-pills-archives-tab" data-toggle="pill" href="#v-pills-archives" role="tab"
aria-controls="v-pills-archives" aria-selected="false">Archives</a>
</div>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
3 offres en cours
</li>
<li class="list-group-item">
La prochaine offre périme dans :<br>
X jours Y heures Z minutes
</li>
<li class="list-group-item">
<span id="t_rows">Nombre total d'</span> offres
</li>
<li class="list-group-item">L'heure des clôtures par défaut :
<form id="hour_default">
<label class="sr-only" for="inlineFormInputGroupUsername2">Username</label>
<div class="input-group input-group-sm mb-2 mr-sm-2">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-clock"></i></div>
</div>
<input type="text" class="form-control" id="inlineFormInputGroupUsername2" placeholder="Heure" value="12:00">
</div>
</form>
</li>
</ul>
<div class="card-body">
<a href="{{ path('potage_legume_ajax_display') }}" class="card-link"><i class="fas fa-long-arrow-alt-left fa-fw"></i>Les légumes</a>
<a href="#" class="card-link">Les infolettres<i class="fas fa-long-arrow-alt-right fa-fw"></i></a>
</div>
</div>
</aside>
{% endblock %}
......@@ -58,30 +101,58 @@
{% include '@Potage/Offre/ajaxForm.html.twig' %}
<h2>En préparation</h2>
<table id="maintab-draft" class="table offres table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Référence</th>
<th scope="col">Créée le</th>
<th scope="col">Date de clôture</th>
<th scope="col">Statut</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<h2>En cours</h2>
<table id="maintab-current" class="table offres table-striped">
<tbody>
</tbody>
</table>
<h2>Archives</h2>
<table id="maintab-closed" class="table offres table-striped">
<tbody>
</tbody>
</table>
<div class="tab-content" id="v-pills-tabContent">
<div class="tab-pane fade show active" id="v-pills-actuel" role="tabpanel" aria-labelledby="v-pills-actuel-tab">
<h2>En préparation</h2>
<table id="maintab-draft" class="table offres table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Référence</th>
<th scope="col">Créée le</th>
<th scope="col">Date de clôture</th>
<th scope="col">Contenu</th>
<th scope="col">Statut</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<h2>En cours</h2>
<table id="maintab-current" class="table offres table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Référence</th>
<th scope="col">Créée le</th>
<th scope="col">Date de clôture</th>
<th scope="col">Contenu</th>
<th scope="col">Statut</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="tab-pane fade" id="v-pills-archives" role="tabpanel" aria-labelledby="v-pills-archives-tab">
<h2>Archives</h2>
<table id="maintab-closed" class="table offres table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Référence</th>
<th scope="col">Créée le</th>
<th scope="col">Date de clôture</th>
<th scope="col">Contenu</th>
<th scope="col">Statut</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</section>
</div>
......@@ -123,7 +194,10 @@
tr.appendChild(td1);
let td2 = document.createElement('td');
td2.textContent = json[i].reference;
let refBtn = document.createElement('button');
refBtn.classList.add('btn', 'btn-outline-dark', 'btn-sm');
refBtn.textContent = json[i].reference;
td2.appendChild(refBtn);
tr.appendChild(td2);
let td3 = document.createElement('td');
......@@ -134,16 +208,20 @@
td4.textContent = formatStringDate(json[i].ended_at);
tr.appendChild(td4);
let td6 = document.createElement('td');
td6.textContent = json[i].offre_legumes.length + (json[i].offre_legumes.length > 1 ? ' légumes' : ' légume' );
tr.appendChild(td6);
let td5 = document.createElement('td');
let listStatus = {
'draft': 'En préparation',
'current': 'En cours',
'closed': 'Terminé',
//'trash': 'poubelle'
'closed': 'Terminée'
};
for (let statut in listStatus) {
if (statut === json[i].status) {
if (json[i].status === 'draft')
if (json[i].status === 'draft' && json[i].offre_legumes.length > 0)
{
/*
......@@ -153,8 +231,7 @@
editForm.addEventListener('change', function(e)
{
sleep(500).then(() => {
let ask = confirm("L'offre contient XX légumes.\n" +
"Attention, une fois celle-ci publiée,\n" +
let ask = confirm("Attention, une fois l'offre publiée,\n" +
"vous ne pourrez plus revenir en arrière !\n" +
"Êtes-vous sûr de vouloir changer son statut ?"
);
......@@ -177,9 +254,50 @@
}
else {
td5.textContent = listStatus[statut];
/*
* Affiche statut
*/
let fa;
let couleurs = {'draft': 'text-warning', 'current': 'text-success', 'closed': 'text-muted'};
for (let couleur in couleurs) {
if (json[i].status === couleur) {
fa = couleurs[couleur];
}}
td5.innerHTML = '<i class="fas fa-square '+ fa +'"></i> ' + listStatus[statut];
}
}}
/*
* Supprimer l'offre
*/
if (json[i].status === 'draft')
{
let deleteBtn = document.createElement('button');
deleteBtn.setAttribute('title', 'Supprimer');
deleteBtn.innerHTML = '<i class="fas fa-trash fa-fw"></i>';
deleteBtn.classList.add('btn', 'btn-danger', 'btn-sm', 'ml-2', 'btn-delete');
deleteBtn.dataset.offreId = json[i].id;
deleteBtn.addEventListener('click', function()
{
let offreId = this.dataset.offreId;
let ask = confirm("Effacer l'offre n°" + offreId
+ "\nCette action n'est pas réversible. Souhaitez-vous continuer ?\n");
if (ask === true)
{
AJAX('DELETE',
Routing.generate('api_offre_delete', {'id': offreId }),
function() {
reloadTableOffre('draft');
}
);
}
});
td5.appendChild(deleteBtn);
}
}
}
tr.appendChild(td5);
tbody.appendChild(tr);
......@@ -204,21 +322,20 @@
editForm.appendChild(divForm);
let selectForm = document.createElement('select');
selectForm.setAttribute('id', 'offre_status_status');
selectForm.setAttribute('name', 'offre_status[status]');
selectForm.classList.add('form-control', 'form-control-sm');
selectForm.classList.add('form-control', 'form-control-sm', 'offre_status', 'bg-warning');
divForm.appendChild(selectForm);
let optionValue = {
'draft': 'En préparation',
'current': 'Publier',
//'trash': 'Poubelle'
'current': 'Publier'
};
for (let value in optionValue)
{
let optionForm = document.createElement('option');
optionForm.setAttribute('value', value);
optionForm.textContent = optionValue[value];
optionForm.innerHTML = optionValue[value];
optionForm.classList.add(value);
selectForm.appendChild(optionForm);
}
return editForm;
......
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