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
if (!empty($sorted))
{
$infos = $em->getRepository('PotageBundle:Info')->findAllForLettreReadInfosSorted($id, $sorted);
}
else {
$infos = $em->getRepository('PotageBundle:Info')->findAllForLettreReadInfos($id);
......@@ -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'
*
......
......@@ -196,6 +196,13 @@ api_lettre_infos_read:
_controller: APIBundle:LettreAPI:readInfos
methods: [ GET ]
api_lettre_infos_sort:
path: /lettre/{id}/sort
requirements:
id: \d+
defaults:
_controller: APIBundle:LettreAPI:sortInfos
methods: [ GET ]
api_lettre_update:
path: /lettre/{id}
......
......@@ -9,36 +9,50 @@ function reloadGridInfos()
sortable.innerHTML = null;
let URL = Routing.generate('api_lettre_infos_read', {'id': id_lettre });
AJAX('GET', URL, function(request)
{
let json = JSON.parse(request.responseText);
for(let i = 0; i < json.length; i++ )
{
let div = buildItemLettreInfos(json[i]);
sortable.appendChild(div);
//console.log(json[i]);
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);
sortable.appendChild(offre);
insertOffre();
});
}
/*
* Construit un bloc d'actualité
* @param json object jsonRow
*/
function buildItemLettreInfos(jsonRow)
*
*/
function insertOffre()
{
console.log(jsonRow);
let infoItem = sortable.querySelectorAll('div.ui-state-default');
let div = document.createElement('div');
div.classList.add('ui-state-default', 'info');
div.dataset.infoId = jsonRow.id;
AJAX('GET',
Routing.generate('api_lettre_infos_sort', {'id': id_lettre}),
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)
*/
function getDisplayOffreLegumes(id_lettre)
{
console.log(id_lettre);
//console.log(id_lettre);
let div = document.createElement('div');
div.classList.add('ui-state-default', 'info', 'offre');
div.dataset.infoId = -1;
div.textContent = "OFFRE DE LEGUMES";
div.textContent = "OFFRE DE LEGUMES, liée à la lettre " + id_lettre;
return div;
}
......@@ -64,7 +78,6 @@ function getDisplayOffreLegumes(id_lettre)
* =================================
*/
// recharge la grillle
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