Commit d4a753e6 authored by Mat's avatar Mat
Browse files

le formulaire updateSorted est opérationnel

parent cda2a756
......@@ -3,6 +3,7 @@
namespace APIBundle\Controller;
use APIBundle\Form\LettreAPIType;
use APIBundle\Form\LettreSortedAPIType;
use APIBundle\Form\LettreStatusAPIType;
use PotageBundle\Entity\Lettre;
use Symfony\Component\HttpFoundation\Request;
......@@ -145,6 +146,36 @@ class LettreAPIController extends MasterAPIController
}
/**
* Form update (post) pour modifier la colonne 'sorted'
*
* @param Request $request
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function updateSortedAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$lettre = $em->getRepository('PotageBundle:Lettre')->findOneForSorted($id);
if ($lettre === null)
{
return $this->api('Not found', Response::HTTP_NOT_FOUND);
}
$form = $this->createForm( LettreSortedAPIType::class, $lettre);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$em->flush();
return $this->api([]);
}
return $this->api($form, Response::HTTP_BAD_REQUEST);
}
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
......
......@@ -204,6 +204,14 @@ api_lettre_update_status:
_controller: APIBundle:LettreAPI:updateStatus
methods: [ POST ]
api_lettre_update_sorted:
path: /lettre/{id}/sort
requirements:
id: \d+
defaults:
_controller: APIBundle:LettreAPI:updateSorted
methods: [ POST ]
api_lettre_delete:
path: /lettre/{id}
requirements:
......
......@@ -108,4 +108,23 @@ class LettreRepository extends \Doctrine\ORM\EntityRepository
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
/**
* @param $id
* @return mixed
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneForSorted($id)
{
$qb = $this->createQueryBuilder('l')
->where('l.id = :id')
->andWhere('l.status = :draft ')
->setParameters(array(
':id'=> $id,
':draft' => 'draft'
));
return $qb->getQuery()->getOneOrNullResult();
}
}
......@@ -62,9 +62,10 @@ sortForm.addEventListener('submit', function(e)
let items = document.querySelectorAll('.ui-state-default');
for (let i=0; i < items.length; i++)
{
list[i] = items[i].dataset.lettreInfosId;
list[i] = items[i].dataset.infoId;
}
console.log(list);
input.value = list;
let form = this;
......@@ -91,6 +92,9 @@ $( function() {
} );
/*
*
* Modifier le bloc Lettre (aside droite)
......
......@@ -135,8 +135,6 @@ $( function() {
/*
*
* Modifier le bloc Offre (aside droite)
......
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