Commit 79842bd9 authored by Mat's avatar Mat

Lettre: affichage, ajoute un statut relecture, form create et update

* diverses corrections et améliorations
* wip.. le delete ne fonctionne pas encore bien
parent 27e209a4
......@@ -22,7 +22,8 @@ class LettreStatusType extends AbstractType
'label' => 'Statut',
'choices' => array(
'En préparation' => 'draft',
'Envoyer' => 'current',
'Pour Relecture' => 'current',
'Envoyer' => 'sent',
),
'label_attr' => array('class' => 'col-form-label'),
'attr' => array(
......@@ -43,7 +44,7 @@ class LettreStatusType extends AbstractType
parent::configureOptions($resolver);
$resolver->setDefault('data_class', Lettre::class);
$resolver->setDefault('attr', array(
'class' => 'formulaire formulaire_offre_status',
'class' => 'formulaire formulaire_lettre_status',
));
}
......@@ -52,6 +53,6 @@ class LettreStatusType extends AbstractType
*/
public function getBlockPrefix()
{
return 'offre_status';
return 'lettre_status';
}
}
......@@ -23,7 +23,6 @@ class LettreType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
// offre
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event)
......@@ -43,24 +42,21 @@ class LettreType extends AbstractType
->orderBy('o.status', 'ASC');
},
'choice_label' => 'getReferenceMore',
'placeholder' => '',
'label' => "À laquelle on joint une offre",
'label_attr' => array('class' => 'col-form-label'),
'attr' => array('class' => 'form-control form-control-sm'),
));
}
);
// infos
/*
$builder->add('infos', EntityType::class, array(
'class' => Info::class,
'label' => "Dans laquelle on glisse des infos",
'label_attr' => array('class' => 'col-form-label'),
'attr' => array('class' => 'form-control form-control-sm'),
));
$builder->add('infos', EntityType::class, array(
'class' => Info::class,
'label' => "Dans laquelle on glisse des infos",
'label_attr' => array('class' => 'col-form-label'),
'attr' => array('class' => 'form-control form-control-sm'),
));
*/
// groupe
$builder->add('groupe', EntityType::class, array(
'class' => Groupe::class,
'choice_label' => 'getNom',
......@@ -69,15 +65,11 @@ class LettreType extends AbstractType
'label_attr' => array('class' => 'col-form-label'),
'attr' => array('class' => 'form-control form-control-sm'),
));
// subject
$builder->add('subject', TextType::class, array(
'label' => "Sujet ",
'label_attr' => array('class' => 'col-form-label'),
'attr' => array('class' => 'form-control form-control-sm'),
));
// startedAt
$builder->add('startedAt', DateType::class, array(
'label' => "Début de la période",
'widget' => 'single_text',
......@@ -85,8 +77,6 @@ class LettreType extends AbstractType
'label_attr' => array('class' => 'col-form-label'),
'attr' => array('class' => 'form-control form-control-sm'),
));
// endedAt
$builder->add('endedAt', DateType::class, array(
'label' => "Fin de la période",
'widget' => 'single_text',
......@@ -94,8 +84,6 @@ class LettreType extends AbstractType
'label_attr' => array('class' => 'col-form-label'),
'attr' => array('class' => 'form-control form-control-sm'),
));
// status enum ('draft', 'current', 'sent', 'closed', 'trash')
$builder->add('status', ChoiceType::class, array(
'label' => "Statut de l'infolettre",
'label_attr' => array('class' => 'col-form-label'),
......
......@@ -64,8 +64,14 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository
public function findOneForAPIUpdate($id)
{
$qb = $this->createQueryBuilder('l')
->where('l.id = :id')
->setParameter(':id', $id);
->where('l.status = :draft')
->orWhere('l.status = :current')
->andWhere('l.id = :id')
->setParameters(array(
':id' => $id,
':draft' => 'draft',
':current' => 'current'
));
return $qb->getQuery()->getOneOrNullResult();
}
......@@ -79,7 +85,11 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository
{
$qb = $this->createQueryBuilder('l')
->where('l.id = :id')
->setParameter(':id', $id);
->andWhere('l.status = :draft')
->setParameters(array(
':id' => $id,
':draft' => 'draft'
));
return $qb->getQuery()->getOneOrNullResult();
}
}
......@@ -105,7 +105,7 @@
<tbody>
</tbody>
</table>
<h2><i class="fas fa-angle-down fa-fw"></i> En cours d'envoi</h2>
<h2><i class="fas fa-angle-down fa-fw"></i> Pour relecture</h2>
<table id="maintab-current" class="table lettres table-striped">
<thead>
<tr>
......@@ -120,6 +120,21 @@
<tbody>
</tbody>
</table>
<h2><i class="fas fa-angle-down fa-fw"></i> En cours d'envoi</h2>
<table id="maintab-sent" class="table lettres table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Infolettre</th>
<th scope="col">Groupe</th>
<th scope="col">Sujet</th>
<th scope="col">Pièce jointe</th>
<th scope="col">Actions</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><i class="fas fa-angle-down fa-fw"></i> Envoyées</h2>
......@@ -189,18 +204,19 @@
tr.appendChild(td1);
let td7 = document.createElement('td');
let listStatus = { 'draft': 'En préparation', 'current': 'Publiée', 'closed': 'Terminée' };
let listStatus = { 'draft': 'En préparation', 'current': 'Prête', 'sent': 'Envoyée', 'closed': 'Archivée' };
for (let statut in listStatus)
{
if (statut === jsonRow.status)
{
if (jsonRow.status === 'draft' && typeof jsonRow.offre !== 'undefined')
if (jsonRow.status === 'draft' || jsonRow.status === 'current'
&& typeof jsonRow.offre !== 'undefined')
{
td7.appendChild(changeStatus(jsonRow));
}
else
{
let couleurs = {'draft': 'warning', 'current': 'success', 'closed': 'muted'};
let couleurs = {'draft': 'warning', 'current': 'danger', 'sent': 'success', 'closed': 'muted'};
let fa = buildColorSquare(jsonRow.status, couleurs);
td7.innerHTML = fa + listStatus[statut];
}
......@@ -224,8 +240,10 @@
tr.appendChild(td3);
let td6 = document.createElement('td');
td6.appendChild(displayEditLettre(jsonRow));
td6.appendChild(displayDeleteLettre(jsonRow));
(jsonRow.status === 'draft' || jsonRow.status === 'current') ?
td6.appendChild(displayEditLettre(jsonRow)) : null;
(jsonRow.status === 'draft') ?
td6.appendChild(displayDeleteLettre(jsonRow)) : null;
tr.appendChild(td6);
return tr;
......@@ -235,30 +253,33 @@
/*
* Construit et affiche le formulaire d'édition
*/
function buildEditStatusForm()
function buildEditStatusForm(status)
{
let editForm = document.createElement('form');
editForm.setAttribute('name', 'offre_status');
editForm.setAttribute('name', 'lettre_status');
editForm.setAttribute('method', 'post');
editForm.setAttribute('novalidate', '1');
let divForm = document.createElement('div');
divForm.setAttribute('id', 'offre_status');
divForm.setAttribute('id', 'lettre_status');
divForm.setAttribute('novalidate', 'novalidate');
editForm.appendChild(divForm);
let selectForm = document.createElement('select');
selectForm.setAttribute('name', 'lettre_status[status]');
selectForm.classList.add('form-control', 'form-control-sm', 'offre_status', 'bg-warning');
selectForm.classList.add('form-control', 'form-control-sm', 'lettre_status', 'bg-warning');
divForm.appendChild(selectForm);
let optionValue = {'draft': 'En préparation', 'current': 'Envoyer'};
let optionValue = {'draft': 'En préparation', 'current': 'Pour Relecture', 'sent': 'Envoyer'};
for (let value in optionValue)
{
let optionForm = document.createElement('option');
optionForm.setAttribute('value', value);
optionForm.innerHTML = optionValue[value];
optionForm.classList.add(value);
if (status === value) {
optionForm.setAttribute('selected', 'selected');
}
selectForm.appendChild(optionForm);
}
return editForm;
......@@ -271,15 +292,21 @@
*/
function changeStatus(jsonRow)
{
let editForm = buildEditStatusForm();
let editForm = buildEditStatusForm(jsonRow.status);
editForm.addEventListener('change', function()
{
let ask = false;
let selected = this[0].options[this[0].selectedIndex].value;
sleep(500).then(() => {
let ask = confirm(
"Attention, une fois la lettre envoyée,\n" +
"vous ne pourrez forcément plus revenir en arrière !\n" +
"Êtes-vous sûr de vouloir changer son statut ?"
);
if (selected === 'sent') {
ask = confirm(
"Attention, une fois la lettre envoyée,\n" +
"vous ne pourrez forcément plus revenir en arrière !\n" +
"Êtes-vous sûr de vouloir changer son statut ?"
);
} else {
ask = true;
}
if (ask === true)
{
AJAX('POST',
......@@ -291,9 +318,10 @@
);
}
else {
reloadTableLettre('draft');
reloadTables();
}
});
});
return editForm;
}
......@@ -315,12 +343,13 @@
AJAX('GET', submitURL, function(request) {
let json = JSON.parse(request.responseText);
titleForm.textContent = 'Lettre # ' + lettreId;
form.querySelector('#lettre_groupe').value = json.groupe;
form.querySelector('#lettre_subject').value = json.subject;
form.querySelector('#lettre_offre').value = json.offre;
form.querySelector('#lettre_started_at').value = json.started_at;
form.querySelector('#lettre_ended_at').value = json.ended_at;
form.querySelector('#lettre_startedAt').value = formatDateISO(json.started_at);
form.querySelector('#lettre_endedAt').value = formatDateISO(json.ended_at);
form.querySelector('#lettre_groupe').value = json.groupe.id;
form.querySelector('#lettre_offre').value = json.offre.id;
form.querySelector('#lettre_status').value = json.status;
});
});
return editBtn;
......@@ -358,7 +387,7 @@
*/
function reloadTables()
{
let tables = ['draft', 'current', 'closed'];
let tables = ['draft', 'current', 'sent', 'closed'];
for (let status of tables) {
reloadTableLettre(status);
}
......@@ -383,6 +412,12 @@
createButton(function(){
titleForm.textContent = 'Nouvelle infolettre';
form.querySelector('#lettre_subject').value = null;
form.querySelector('#lettre_startedAt').value = null;
form.querySelector('#lettre_endedAt').value = null;
form.querySelector('#lettre_groupe').value = null;
form.querySelector('#lettre_offre').value = null;
form.querySelector('#lettre_status').value = 'draft';
submitURL = Routing.generate('api_lettre_create');
});
......@@ -411,7 +446,7 @@
let form = this;
e.preventDefault();
AJAX('POST', submitURL, function() {
reloadTableLettre('draft');
reloadTables();
$('.form-lettre-modal').modal('hide'); // en jquery
}, form);
});
......
......@@ -29,6 +29,14 @@ function formatDate(date, weekWord = false, monthWord = false)
+ date.getFullYear();
}
function formatDateISO(string)
{
let date = new Date(string);
return date.getFullYear()
+ '-' + formatNumber(date.getMonth()+1, 2)
+ '-' + formatNumber(date.getDate(), 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