Commit 60f49fd8 authored by Mat's avatar Mat

implémente l'action ajax sur les boutons supprimer

parent 93da61ff
...@@ -94,6 +94,23 @@ class ImageAPIController extends MasterAPIController ...@@ -94,6 +94,23 @@ class ImageAPIController extends MasterAPIController
} }
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function deleteOneAction($id)
{
$em = $this->getDoctrine()->getManager();
$image = $em->getRepository('TechnoBundle:Image')
->findOneForAPIdelete($id);
if ($image !== null)
{
$em->remove($image);
$em->flush();
}
return $this->api([]);
}
/* /*
......
...@@ -70,6 +70,13 @@ api_image_update: ...@@ -70,6 +70,13 @@ api_image_update:
_controller: APIBundle:ImageAPI:update _controller: APIBundle:ImageAPI:update
methods: [ POST ] methods: [ POST ]
api_image_delete_one:
path: /image/{id}
defaults:
_controller: APIBundle:ImageAPI:deleteOne
requirements:
id: \d+
methods: [ DELETE ]
## ##
## Note: ## Note:
## ##
......
...@@ -115,7 +115,23 @@ class ImageRepository extends \Doctrine\ORM\EntityRepository ...@@ -115,7 +115,23 @@ class ImageRepository extends \Doctrine\ORM\EntityRepository
return $qb->getQuery()->getOneOrNullResult(); return $qb->getQuery()->getOneOrNullResult();
} }
/**
* @param $id
* @return Image
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function findOneForAPIdelete($id)
{
$qb = $this->createQueryBuilder('i')
->join('i.owner', 'o')
->addSelect('o')
->where('i.id = :id')
->setParameter(':id', $id);
return $qb->getQuery()->getOneOrNullResult();
}
/** /**
* @param $id * @param $id
* @return Image * @return Image
......
...@@ -137,7 +137,17 @@ ...@@ -137,7 +137,17 @@
deleteBtn.addEventListener('click', function(e) deleteBtn.addEventListener('click', function(e)
{ {
let imageId = this.dataset.imageId;
let r = confirm('Are you sure ?');
if (r === true)
{
submitURL = Routing.generate('api_image_delete_one', {'id': imageId});
AJAX('DELETE', submitURL, function()
{
reloadGridImage();
});
}
}); });
modify.appendChild(deleteBtn); modify.appendChild(deleteBtn);
......
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