This commit is contained in:
fredtempez 2022-03-08 10:47:15 +01:00
parent e7bbd18e4c
commit 6deda024c8
1 changed files with 22 additions and 18 deletions

View File

@ -239,9 +239,10 @@ $( 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"]); ?>; positionDOM.empty().append(
buildPagesList(true); $("<option>").val(0).text("Ne pas afficher"),
$("#pageEditPosition").val(positionInitial); $("<option>").val(1).text("Au début")
);
} }
}); });
@ -522,9 +523,14 @@ 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")
);
} else { } else {
buildPagesList(false); getPages();
//$("#pageEditParentPageId").trigger("change"); //$("#pageEditParentPageId").trigger("change");
} }
}); });
@ -540,14 +546,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() {
buildPagesList(false); getPages();
}).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 buildPagesList(extraPosition) { function getPages() {
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"]); ?>;
@ -561,11 +567,12 @@ function buildPagesList(extraPosition) {
var positionSelected = 0; var positionSelected = 0;
var positionPrevious = 1; var positionPrevious = 1;
// Aucune page parent sélectionnée // Aucune page parent selectionnée
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) &&
extraPosition == pages[key].extraPosition ) {
// 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;
@ -573,14 +580,11 @@ function buildPagesList(extraPosition) {
// 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
if (extraPosition == pages[key].extraPosition ) { positionPrevious++;
positionPrevious++; // Ajout à la liste
// Ajout à la liste positionDOM.append(
positionDOM.append( $("<option>").val(positionPrevious).html("Après \"" + (pages[key].title) + "\"")
$("<option>").val(positionPrevious).html("Après \"" + (pages[key].title) + "\"") );
);
}
} }
} }
} }
@ -588,7 +592,7 @@ function buildPagesList(extraPosition) {
positionSelected = 0; positionSelected = 0;
} }
} }
// Une page parent est sélectionnée // Un page parent est sélectionnée
else { else {
// Liste des pages enfants de la page parent // Liste des pages enfants de la page parent
for(var i = 0; i < hierarchy[parentSelected].length; i++) { for(var i = 0; i < hierarchy[parentSelected].length; i++) {