From d2bdfa7d0f746f060090a9e8c8ad6e376b5a1480 Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 9 May 2025 01:02:23 +0200 Subject: =?UTF-8?q?mode=20modif=20page=20termin=C3=A9!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/main.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ src/controller/ajax.php | 36 ++++++++++++++++++++++++++++++++++ src/view/MainBuilder.php | 10 +++++----- 3 files changed, 92 insertions(+), 5 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index 802bbbe..7dacb7a 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -231,4 +231,55 @@ function renamePageBloc(bloc_id){ .catch(error => { console.error('Erreur:', error); }); +} + +function switchBlocsPositions(bloc_id, direction, current_page) { + const current_bloc = document.getElementById(bloc_id); + const current_bloc_edit_zone = document.getElementById("bloc_edit_" + bloc_id); + var other_bloc; + + if(direction == 'down'){ + other_bloc = current_bloc.nextElementSibling; + } + else if(direction == 'up'){ + other_bloc = current_bloc.previousElementSibling; + } + + if(other_bloc == null || other_bloc.tagName !== 'SECTION') + { + console.log('Inversion impossible'); + return; + } + const other_bloc_edit_zone = document.getElementById("bloc_edit_" + other_bloc.id); + + fetch('index.php?page=' + current_page + '&bloc_edit=switch_blocs_positions', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ id1: bloc_id, id2: parseInt(other_bloc.id) }) + }) + .then(response => response.json()) + .then(data => { + if(data.success) + { + if(direction == 'down'){ + current_bloc.parentElement.insertBefore(other_bloc, current_bloc); + current_bloc_edit_zone.parentElement.insertBefore(other_bloc_edit_zone, current_bloc_edit_zone); + console.log('Inversion réussie'); + } + else if(direction == 'up'){ + other_bloc.parentElement.insertBefore(current_bloc, other_bloc); + other_bloc_edit_zone.parentElement.insertBefore(current_bloc_edit_zone, other_bloc_edit_zone); + console.log('Inversion réussie'); + } + } + else { + + console.error('Échec de l\'inversion'); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); } \ No newline at end of file diff --git a/src/controller/ajax.php b/src/controller/ajax.php index a6786d9..a64c39b 100644 --- a/src/controller/ajax.php +++ b/src/controller/ajax.php @@ -378,7 +378,43 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['bloc_edit'])) } die; } + // inversion des positions de deux blocs + elseif($_GET['bloc_edit'] === 'switch_blocs_positions') + { + if(isset($json['id1']) && is_int($json['id1']) && isset($json['id2']) && is_int($json['id2']) && isset($_GET['page'])){ + $director = new Director($entityManager, true); + $director->findUniqueNodeByName('main'); + $director->findItsChildren(); + $main = $director->getNode(); + $main->sortChildren(true); // régénère les positions avant inversion + + $bloc1; $bloc2; + foreach($main->getChildren() as $child){ + if($child->getId() === $json['id1']){ + $bloc1 = $child; + break; + } + } + foreach($main->getChildren() as $child){ + if($child->getId() === $json['id2']){ + $bloc2 = $child; + break; + } + } + // inversion + $tmp = $bloc1->getPosition(); + $bloc1->setPosition($bloc2->getPosition()); + $bloc2->setPosition($tmp); + + $entityManager->flush(); + echo json_encode(['success' => true]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } } diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index 4664c17..5096134 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php @@ -68,7 +68,7 @@ class MainBuilder extends AbstractBuilder ' . "\n";*/ - // ajout d'un nouveau bloc + // création d'un bloc $this->html .= '

Ajouter un bloc de page

@@ -87,13 +87,13 @@ class MainBuilder extends AbstractBuilder

Modifier un bloc

'; foreach($node->getChildren() as $child_node){ // renommage d'un bloc - $this->html .= '
-

+ $this->html .= '

+

'. "\n"; // déplacement d'un bloc - $this->html .= ' - ' . "\n"; + $this->html .= ' + ' . "\n"; // suppression d'un bloc $this->html .= '

-- cgit v1.2.3