Bug : ordre des pages du menu standard a résoudre

This commit is contained in:
fredtempez 2022-03-08 13:46:55 +01:00
parent f57f9ec4bb
commit 3d243e3463
2 changed files with 27 additions and 39 deletions

View File

@ -389,19 +389,23 @@ class page extends common {
$hierarchy = $this->getInput('pageEditParentPageId') ? $this->getHierarchy($this->getInput('pageEditParentPageId')) : array_keys($this->getHierarchy()); $hierarchy = $this->getInput('pageEditParentPageId') ? $this->getHierarchy($this->getInput('pageEditParentPageId')) : array_keys($this->getHierarchy());
$position = $this->getInput('pageEditPosition', helper::FILTER_INT); $position = $this->getInput('pageEditPosition', helper::FILTER_INT);
foreach($hierarchy as $hierarchyPageId) { foreach($hierarchy as $hierarchyPageId) {
// Ignore la page en cours de modification et les pages dans le menu extra
if($hierarchyPageId === $this->getUrl(2) || // Ignore la page en cours de modification
$this->getData(['page', $hierarchyPageId, 'extraPosition']) === false ) { if($hierarchyPageId === $this->getUrl(2) ) {
continue; continue;
} }
// Incrémente de +1 pour laisser la place à la position de la page en cours de modification // Ne traite que les pages du menu standard
if($lastPosition === $position) { if ($this->getData(['page', $hierarchyPageId, 'extraPosition']) === false) {
// Incrémente de +1 pour laisser la place à la position de la page en cours de modification
if($lastPosition === $position) {
$lastPosition++;
}
// Change la position
$this->setData(['page', $hierarchyPageId, 'position', $lastPosition]);
// Incrémente pour la prochaine position
$lastPosition++; $lastPosition++;
} }
// Change la position
$this->setData(['page', $hierarchyPageId, 'position', $lastPosition]);
// Incrémente pour la prochaine position
$lastPosition++;
} }
if ($this->getinput('pageEditBlock') !== 'bar') { if ($this->getinput('pageEditBlock') !== 'bar') {
$barLeft = $this->getinput('pageEditBarLeft'); $barLeft = $this->getinput('pageEditBarLeft');

View File

@ -240,16 +240,7 @@ $( document ).ready(function() {
if ($("#pageEditExtraPosition").val() == 1 ) { if ($("#pageEditExtraPosition").val() == 1 ) {
var positionDOM = $("#pageEditPosition"); var positionDOM = $("#pageEditPosition");
var positionInitial = <?php echo $this->getData(['page',$this->getUrl(2),"position"]); ?>; var positionInitial = <?php echo $this->getData(['page',$this->getUrl(2),"position"]); ?>;
console.log(positionInitial); buildPagesList(true);
// La position précédente était dans le menu standard
if (positionInitial >= 2)
{
positionInitial = 0;
}
positionDOM.empty().append(
$("<option>").val(0).text("Ne pas afficher"),
$("<option>").val(1).text("Au début")
);
$("#pageEditPosition").val(positionInitial); $("#pageEditPosition").val(positionInitial);
} }
@ -531,18 +522,9 @@ pageTypeMenuDOM.on("change", function() {
$("#pageEditExtraPosition").on("change", function() { $("#pageEditExtraPosition").on("change", function() {
if ($("#pageEditExtraPosition").val() == 1 ) { if ($("#pageEditExtraPosition").val() == 1 ) {
buildPagesList(true);
var positionDOM = $("#pageEditPosition");
/*
positionDOM.empty().append(
$("<option>").val(0).text("Ne pas afficher"),
$("<option>").val(1).text("Au début")
);
$("#pageEditPosition").val(1);
*/
getPages(true);
} else { } else {
getPages(false); buildPagesList(false);
//$("#pageEditParentPageId").trigger("change"); //$("#pageEditParentPageId").trigger("change");
} }
}); });
@ -558,14 +540,14 @@ $("#pageEditModuleConfig").on("click", function() {
* Affiche les pages en fonction de la page parent dans le choix de la position * Affiche les pages en fonction de la page parent dans le choix de la position
*/ */
$("#pageEditParentPageId").on("change", function() { $("#pageEditParentPageId").on("change", function() {
getPages(false); buildPagesList(false);
}).trigger("change"); }).trigger("change");
/** /**
* Construit un select contenant la liste des pages du site. * Construit un select contenant la liste des pages du site.
*/ */
function getPages(extra) { function buildPagesList(extraPosition) {
var hierarchy = <?php echo json_encode($this->getHierarchy()); ?>; var hierarchy = <?php echo json_encode($this->getHierarchy()); ?>;
var pages = <?php echo json_encode($this->getData(['page'])); ?>; var pages = <?php echo json_encode($this->getData(['page'])); ?>;
var positionInitial = <?php echo $this->getData(['page',$this->getUrl(2),"position"]); ?>; var positionInitial = <?php echo $this->getData(['page',$this->getUrl(2),"position"]); ?>;
@ -583,8 +565,7 @@ function getPages(extra) {
if(parentSelected === "") { if(parentSelected === "") {
// Liste des pages sans parents // Liste des pages sans parents
for(var key in hierarchy) { for(var key in hierarchy) {
if(hierarchy.hasOwnProperty(key) && if(hierarchy.hasOwnProperty(key) ) {
extra === false ) {
// Sélectionne la page avant s'il s'agit de la page courante // Sélectionne la page avant s'il s'agit de la page courante
if(key === "<?php echo $this->getUrl(2); ?>") { if(key === "<?php echo $this->getUrl(2); ?>") {
positionSelected = positionPrevious; positionSelected = positionPrevious;
@ -592,11 +573,14 @@ function getPages(extra) {
// Sinon ajoute la page à la liste // Sinon ajoute la page à la liste
else { else {
// Enregistre la position de cette page afin de la sélectionner si la prochaine page de la liste est la page courante // Enregistre la position de cette page afin de la sélectionner si la prochaine page de la liste est la page courante
positionPrevious++; if (extraPosition == pages[key].extraPosition ) {
// Ajout à la liste positionPrevious++;
positionDOM.append( // Ajout à la liste
$("<option>").val(positionPrevious).html("Après \"" + (pages[key].title) + "\"") positionDOM.append(
); $("<option>").val(positionPrevious).html("Après \"" + (pages[key].title) + "\"")
);
}
} }
} }
} }