summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/js/main.js51
-rw-r--r--src/controller/ajax.php36
-rw-r--r--src/view/MainBuilder.php10
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){
231 .catch(error => { 231 .catch(error => {
232 console.error('Erreur:', error); 232 console.error('Erreur:', error);
233 }); 233 });
234}
235
236function switchBlocsPositions(bloc_id, direction, current_page) {
237 const current_bloc = document.getElementById(bloc_id);
238 const current_bloc_edit_zone = document.getElementById("bloc_edit_" + bloc_id);
239 var other_bloc;
240
241 if(direction == 'down'){
242 other_bloc = current_bloc.nextElementSibling;
243 }
244 else if(direction == 'up'){
245 other_bloc = current_bloc.previousElementSibling;
246 }
247
248 if(other_bloc == null || other_bloc.tagName !== 'SECTION')
249 {
250 console.log('Inversion impossible');
251 return;
252 }
253 const other_bloc_edit_zone = document.getElementById("bloc_edit_" + other_bloc.id);
254
255 fetch('index.php?page=' + current_page + '&bloc_edit=switch_blocs_positions', {
256 method: 'POST',
257 headers: {
258 'Content-Type': 'application/json'
259 },
260 body: JSON.stringify({ id1: bloc_id, id2: parseInt(other_bloc.id) })
261 })
262 .then(response => response.json())
263 .then(data => {
264 if(data.success)
265 {
266 if(direction == 'down'){
267 current_bloc.parentElement.insertBefore(other_bloc, current_bloc);
268 current_bloc_edit_zone.parentElement.insertBefore(other_bloc_edit_zone, current_bloc_edit_zone);
269 console.log('Inversion réussie');
270 }
271 else if(direction == 'up'){
272 other_bloc.parentElement.insertBefore(current_bloc, other_bloc);
273 other_bloc_edit_zone.parentElement.insertBefore(current_bloc_edit_zone, other_bloc_edit_zone);
274 console.log('Inversion réussie');
275 }
276 }
277 else {
278
279 console.error('Échec de l\'inversion');
280 }
281 })
282 .catch(error => {
283 console.error('Erreur:', error);
284 });
234} \ No newline at end of file 285} \ 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']))
378 } 378 }
379 die; 379 die;
380 } 380 }
381 // inversion des positions de deux blocs
382 elseif($_GET['bloc_edit'] === 'switch_blocs_positions')
383 {
384 if(isset($json['id1']) && is_int($json['id1']) && isset($json['id2']) && is_int($json['id2']) && isset($_GET['page'])){
385 $director = new Director($entityManager, true);
386 $director->findUniqueNodeByName('main');
387 $director->findItsChildren();
388 $main = $director->getNode();
389 $main->sortChildren(true); // régénère les positions avant inversion
390
391 $bloc1; $bloc2;
392 foreach($main->getChildren() as $child){
393 if($child->getId() === $json['id1']){
394 $bloc1 = $child;
395 break;
396 }
397 }
398 foreach($main->getChildren() as $child){
399 if($child->getId() === $json['id2']){
400 $bloc2 = $child;
401 break;
402 }
403 }
381 404
405 // inversion
406 $tmp = $bloc1->getPosition();
407 $bloc1->setPosition($bloc2->getPosition());
408 $bloc2->setPosition($tmp);
409
410 $entityManager->flush();
411 echo json_encode(['success' => true]);
412 }
413 else{
414 echo json_encode(['success' => false]);
415 }
416 die;
417 }
382} 418}
383 419
384 420
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
68 </div> 68 </div>
69 </aside>' . "\n";*/ 69 </aside>' . "\n";*/
70 70
71 // ajout d'un nouveau bloc 71 // création d'un bloc
72 $this->html .= '<div class="edit_bloc_zone"> 72 $this->html .= '<div class="edit_bloc_zone">
73 <div class="new_bloc"> 73 <div class="new_bloc">
74 <p>Ajouter un bloc de page</p> 74 <p>Ajouter un bloc de page</p>
@@ -87,13 +87,13 @@ class MainBuilder extends AbstractBuilder
87 <p>Modifier un bloc</p>'; 87 <p>Modifier un bloc</p>';
88 foreach($node->getChildren() as $child_node){ 88 foreach($node->getChildren() as $child_node){
89 // renommage d'un bloc 89 // renommage d'un bloc
90 $this->html .= '<div> 90 $this->html .= '<div id="bloc_edit_' . $child_node->getId() . '">
91 <p><label for="bloc_rename_title">Titre</label> 91 <p><label for="bloc_rename_' . $child_node->getId() . '">Titre</label>
92 <input type="text" id="bloc_rename_' . $child_node->getId() . '" name="bloc_rename_title" value="' . $child_node->getNodeData()->getdata()['title'] . '" required> 92 <input type="text" id="bloc_rename_' . $child_node->getId() . '" name="bloc_rename_title" value="' . $child_node->getNodeData()->getdata()['title'] . '" required>
93 <button onclick="renamePageBloc(' . $child_node->getId() . ')">Renommer</button>'. "\n"; 93 <button onclick="renamePageBloc(' . $child_node->getId() . ')">Renommer</button>'. "\n";
94 // déplacement d'un bloc 94 // déplacement d'un bloc
95 $this->html .= '<img class="action_icon" onclick="switchBlocPositions(' . $child_node->getId() . ', \'up\')" src="assets/arrow-up.svg"> 95 $this->html .= '<img class="action_icon" onclick="switchBlocsPositions(' . $child_node->getId() . ', \'up\', \'' . CURRENT_PAGE . '\')" src="assets/arrow-up.svg">
96 <img class="action_icon" onclick="switchBlocPositions(' . $child_node->getId() . ', \'down\')" src="assets/arrow-down.svg">' . "\n"; 96 <img class="action_icon" onclick="switchBlocsPositions(' . $child_node->getId() . ', \'down\', \'' . CURRENT_PAGE . '\')" src="assets/arrow-down.svg">' . "\n";
97 // suppression d'un bloc 97 // suppression d'un bloc
98 $this->html .= '<form method="post" action="' . new URL(['page' => CURRENT_PAGE]) . '"> 98 $this->html .= '<form method="post" action="' . new URL(['page' => CURRENT_PAGE]) . '">
99 <input type="hidden" name="delete_bloc_id" value="' . $child_node->getId() . '"> 99 <input type="hidden" name="delete_bloc_id" value="' . $child_node->getId() . '">