Commit 973218a9 authored by Mat's avatar Mat

lettreInfos: insère le menu dans la liste des actus, en fonction de son ordre

parent b0fc54b8
...@@ -162,6 +162,7 @@ class LettreAPIController extends MasterAPIController ...@@ -162,6 +162,7 @@ class LettreAPIController extends MasterAPIController
if (!empty($sorted)) if (!empty($sorted))
{ {
$infos = $em->getRepository('PotageBundle:Info')->findAllForLettreReadInfosSorted($id, $sorted); $infos = $em->getRepository('PotageBundle:Info')->findAllForLettreReadInfosSorted($id, $sorted);
} }
else { else {
$infos = $em->getRepository('PotageBundle:Info')->findAllForLettreReadInfos($id); $infos = $em->getRepository('PotageBundle:Info')->findAllForLettreReadInfos($id);
...@@ -171,6 +172,23 @@ class LettreAPIController extends MasterAPIController ...@@ -171,6 +172,23 @@ class LettreAPIController extends MasterAPIController
} }
/**
* @param $id
* @return \Symfony\Component\HttpFoundation\JsonResponse
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function sortInfosAction($id)
{
$em = $this->getDoctrine()->getManager();
// Récupère l'ordre de tri
$sorted = $em->getRepository('PotageBundle:Lettre')->findOneForSorted($id)->getSorted();
return $this->api($sorted);
}
/** /**
* Form update (post) pour modifier la colonne 'sorted' * Form update (post) pour modifier la colonne 'sorted'
* *
......
...@@ -196,6 +196,13 @@ api_lettre_infos_read: ...@@ -196,6 +196,13 @@ api_lettre_infos_read:
_controller: APIBundle:LettreAPI:readInfos _controller: APIBundle:LettreAPI:readInfos
methods: [ GET ] methods: [ GET ]
api_lettre_infos_sort:
path: /lettre/{id}/sort
requirements:
id: \d+
defaults:
_controller: APIBundle:LettreAPI:sortInfos
methods: [ GET ]
api_lettre_update: api_lettre_update:
path: /lettre/{id} path: /lettre/{id}
......
...@@ -9,36 +9,50 @@ function reloadGridInfos() ...@@ -9,36 +9,50 @@ function reloadGridInfos()
sortable.innerHTML = null; sortable.innerHTML = null;
let URL = Routing.generate('api_lettre_infos_read', {'id': id_lettre }); let URL = Routing.generate('api_lettre_infos_read', {'id': id_lettre });
AJAX('GET', URL, function(request) AJAX('GET', URL, function(request)
{ {
let json = JSON.parse(request.responseText); let json = JSON.parse(request.responseText);
for(let i = 0; i < json.length; i++ ) for(let i = 0; i < json.length; i++ )
{ {
let div = buildItemLettreInfos(json[i]); //console.log(json[i]);
sortable.appendChild(div);
let info = document.createElement('div');
info.classList.add('ui-state-default', 'info');
info.dataset.infoId = json[i].id;
displayBodyOneInfo(info, json[i]);
sortable.appendChild(info);
} }
let offre = getDisplayOffreLegumes(id_lettre); insertOffre();
sortable.appendChild(offre);
}); });
} }
/* /*
* Construit un bloc d'actualité *
* @param json object jsonRow */
*/ function insertOffre()
function buildItemLettreInfos(jsonRow)
{ {
console.log(jsonRow); let infoItem = sortable.querySelectorAll('div.ui-state-default');
let div = document.createElement('div'); AJAX('GET',
div.classList.add('ui-state-default', 'info'); Routing.generate('api_lettre_infos_sort', {'id': id_lettre}),
div.dataset.infoId = jsonRow.id; function(request)
{
let json = JSON.parse(request.responseText);
let order = json.split(',');
displayBodyOneInfo(div, jsonRow); for (let i = 0; i < order.length; i++)
{
if (parseInt(order[i]) === -1)
{
let offre = getDisplayOffreLegumes(id_lettre);
sortable.insertBefore(offre, infoItem[i]);
}
return div; }
}
);
} }
...@@ -47,12 +61,12 @@ function buildItemLettreInfos(jsonRow) ...@@ -47,12 +61,12 @@ function buildItemLettreInfos(jsonRow)
*/ */
function getDisplayOffreLegumes(id_lettre) function getDisplayOffreLegumes(id_lettre)
{ {
console.log(id_lettre); //console.log(id_lettre);
let div = document.createElement('div'); let div = document.createElement('div');
div.classList.add('ui-state-default', 'info', 'offre'); div.classList.add('ui-state-default', 'info', 'offre');
div.dataset.infoId = -1; div.dataset.infoId = -1;
div.textContent = "OFFRE DE LEGUMES"; div.textContent = "OFFRE DE LEGUMES, liée à la lettre " + id_lettre;
return div; return div;
} }
...@@ -64,7 +78,6 @@ function getDisplayOffreLegumes(id_lettre) ...@@ -64,7 +78,6 @@ function getDisplayOffreLegumes(id_lettre)
* ================================= * =================================
*/ */
// recharge la grillle // recharge la grillle
reloadGridInfos(); reloadGridInfos();
......
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