diff options
author | polo <ordipolo@gmx.fr> | 2025-03-31 22:50:11 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-03-31 22:50:11 +0200 |
commit | 7f13ca69bb71a0eb477cbf4f4bfcd08b2843bf9b (patch) | |
tree | 93cdc918764a09c1ebde1cea0c25f24324834850 | |
parent | 43c962f442165327d73756c62501ff823d43f9f3 (diff) | |
download | cms-7f13ca69bb71a0eb477cbf4f4bfcd08b2843bf9b.zip |
inversion de deux articles
-rw-r--r-- | public/js/main.js | 47 | ||||
-rw-r--r-- | src/controller/ajax.php | 17 | ||||
-rw-r--r-- | src/model/entities/Node.php | 4 | ||||
-rw-r--r-- | src/view/ArticleBuilder.php | 8 | ||||
-rw-r--r-- | src/view/NewBuilder.php | 12 |
5 files changed, 76 insertions, 12 deletions
diff --git a/public/js/main.js b/public/js/main.js index c86ec51..d985b71 100644 --- a/public/js/main.js +++ b/public/js/main.js | |||
@@ -27,4 +27,51 @@ function copyInClipBoard(link){ | |||
27 | element.parentNode.removeChild(element); | 27 | element.parentNode.removeChild(element); |
28 | 28 | ||
29 | alert('Cette adresse a été copiée dans le presse-papier:\n\n' + link); | 29 | alert('Cette adresse a été copiée dans le presse-papier:\n\n' + link); |
30 | } | ||
31 | |||
32 | // complète les fonctions dans tinymce.js | ||
33 | function switchPositions(articleId, direction) | ||
34 | { | ||
35 | const current_article = document.getElementById(articleId).parentElement.parentElement; | ||
36 | var other_article = current_article; | ||
37 | |||
38 | if(direction == 'down'){ | ||
39 | other_article = current_article.nextElementSibling; | ||
40 | } | ||
41 | else if(direction == 'up'){ | ||
42 | other_article = current_article.previousElementSibling; | ||
43 | } | ||
44 | const other_article_id = other_article.querySelector('div[id]').id; | ||
45 | |||
46 | fetch('index.php?action=switch_positions', { | ||
47 | method: 'POST', | ||
48 | headers: { | ||
49 | 'Content-Type': 'application/json' | ||
50 | }, | ||
51 | body: JSON.stringify({ id1: articleId, id2: other_article_id }) | ||
52 | }) | ||
53 | .then(response => response.json()) | ||
54 | .then(data => { | ||
55 | if(data.success) | ||
56 | { | ||
57 | if(direction == 'down'){ | ||
58 | current_article.parentElement.insertBefore(other_article, current_article); | ||
59 | console.log('Inversion réussie'); | ||
60 | } | ||
61 | else if(direction == 'up'){ | ||
62 | other_article.parentElement.insertBefore(current_article, other_article); | ||
63 | console.log('Inversion réussie'); | ||
64 | } | ||
65 | else{ | ||
66 | console.log('Échec de l\'inversion'); | ||
67 | } | ||
68 | } | ||
69 | else { | ||
70 | |||
71 | console.log('Échec de l\'inversion'); | ||
72 | } | ||
73 | }) | ||
74 | .catch(error => { | ||
75 | console.error('Erreur:', error); | ||
76 | }); | ||
30 | } \ No newline at end of file | 77 | } \ No newline at end of file |
diff --git a/src/controller/ajax.php b/src/controller/ajax.php index 130c4c6..bcba3f2 100644 --- a/src/controller/ajax.php +++ b/src/controller/ajax.php | |||
@@ -58,6 +58,23 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json' && isset($_GET['action'])) | |||
58 | } | 58 | } |
59 | die; | 59 | die; |
60 | } | 60 | } |
61 | // inversion de la position de deux noeuds | ||
62 | elseif($_GET['action'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) | ||
63 | { | ||
64 | $director = new Director($entityManager); | ||
65 | $director->makeArticleNode($json['id1']); | ||
66 | $node1 = $director->getRootNode(); | ||
67 | $director->makeArticleNode($json['id2']); | ||
68 | $node2 = $director->getRootNode(); | ||
69 | |||
70 | $tmp = $node1->getPosition(); | ||
71 | $node1->setPosition($node2->getPosition()); | ||
72 | $node2->setPosition($tmp); | ||
73 | $entityManager->flush(); | ||
74 | |||
75 | echo json_encode(['success' => true]); | ||
76 | die; | ||
77 | } | ||
61 | } | 78 | } |
62 | 79 | ||
63 | // détection des requêtes d'upload d'image de tinymce | 80 | // détection des requêtes d'upload d'image de tinymce |
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php index 49e16ba..9240413 100644 --- a/src/model/entities/Node.php +++ b/src/model/entities/Node.php | |||
@@ -128,10 +128,10 @@ class Node | |||
128 | { | 128 | { |
129 | return $this->position; | 129 | return $this->position; |
130 | } | 130 | } |
131 | /*public function setPosition(int $position): void | 131 | public function setPosition(int $position): void |
132 | { | 132 | { |
133 | $this->position = $position; | 133 | $this->position = $position; |
134 | }*/ | 134 | } |
135 | public function getPage(): Page | 135 | public function getPage(): Page |
136 | { | 136 | { |
137 | return $this->page; | 137 | return $this->page; |
diff --git a/src/view/ArticleBuilder.php b/src/view/ArticleBuilder.php index 989da0d..6c2f63c 100644 --- a/src/view/ArticleBuilder.php +++ b/src/view/ArticleBuilder.php | |||
@@ -34,11 +34,11 @@ class ArticleBuilder extends AbstractBuilder | |||
34 | $modify_js = 'onclick="openEditor(\'' . $id . '\')"'; | 34 | $modify_js = 'onclick="openEditor(\'' . $id . '\')"'; |
35 | $modify_article = '<p id="edit-' . $id . '"><a href="#"><img class="action_icon" src="assets/edit.svg" ' . $modify_js . '></a></p>' . "\n"; | 35 | $modify_article = '<p id="edit-' . $id . '"><a href="#"><img class="action_icon" src="assets/edit.svg" ' . $modify_js . '></a></p>' . "\n"; |
36 | 36 | ||
37 | $up_link = new URL(['page' => CURRENT_PAGE, 'id' => $id, 'action' => 'position_up']); | 37 | $up_js = 'onclick="switchPositions(\'' . $id . '\', \'up\')"'; |
38 | $up_button = '<p id="position_up-' . $id . '"><a href="' . $up_link . '"><img class="action_icon" src="assets/arrow-up.svg"></a></p>' . "\n"; | 38 | $up_button = '<p id="position_up-' . $id . '"><a href="#"><img class="action_icon" src="assets/arrow-up.svg" ' . $up_js . '></a></p>' . "\n"; |
39 | 39 | ||
40 | $down_link = new URL(['page' => CURRENT_PAGE, 'id' => $id, 'action' => 'position_down']); | 40 | $down_js = 'onclick="switchPositions(\'' . $id . '\', \'down\')"'; |
41 | $down_button = '<p id="position_down-' . $id . '"><a href="' . $down_link . '"><img class="action_icon" src="assets/arrow-down.svg"></a></p>' . "\n"; | 41 | $down_button = '<p id="position_down-' . $id . '"><a href="#"><img class="action_icon" src="assets/arrow-down.svg" ' . $down_js . '></a></p>' . "\n"; |
42 | 42 | ||
43 | $delete_js = 'onclick="deleteArticle(\'' . $id . '\')"'; | 43 | $delete_js = 'onclick="deleteArticle(\'' . $id . '\')"'; |
44 | $delete_article = '<p id="delete-' . $id . '"><a href="#"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></a></p>' . "\n"; | 44 | $delete_article = '<p id="delete-' . $id . '"><a href="#"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></a></p>' . "\n"; |
diff --git a/src/view/NewBuilder.php b/src/view/NewBuilder.php index 605c174..56d1f4d 100644 --- a/src/view/NewBuilder.php +++ b/src/view/NewBuilder.php | |||
@@ -53,8 +53,8 @@ class NewBuilder extends AbstractBuilder | |||
53 | $modify_js = 'onclick="openEditor(\'' . $id . '\')"'; | 53 | $modify_js = 'onclick="openEditor(\'' . $id . '\')"'; |
54 | $modify_article = '<p id="edit-' . $id . '"><a href="#"><img class="action_icon" src="assets/edit.svg" ' . $modify_js . '></a></p>' . "\n"; | 54 | $modify_article = '<p id="edit-' . $id . '"><a href="#"><img class="action_icon" src="assets/edit.svg" ' . $modify_js . '></a></p>' . "\n"; |
55 | 55 | ||
56 | $up_button = '<p id="position_up-' . $id . '"></p>' . "\n"; | 56 | $up_button = ''; |
57 | $down_button = '<p id="position_down-' . $id . '"></p>' . "\n"; | 57 | $down_button = ''; |
58 | 58 | ||
59 | $delete_js = 'onclick="deleteArticle(\'' . $id . '\', \'' . CURRENT_PAGE . '\')"'; | 59 | $delete_js = 'onclick="deleteArticle(\'' . $id . '\', \'' . CURRENT_PAGE . '\')"'; |
60 | $delete_article = '<p id="delete-' . $id . '"><a href="#"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></a></p>' . "\n"; | 60 | $delete_article = '<p id="delete-' . $id . '"><a href="#"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></a></p>' . "\n"; |
@@ -68,11 +68,11 @@ class NewBuilder extends AbstractBuilder | |||
68 | else{ | 68 | else{ |
69 | $modify_article = '<p id="edit-' . $id . '"></p>' . "\n"; | 69 | $modify_article = '<p id="edit-' . $id . '"></p>' . "\n"; |
70 | 70 | ||
71 | $up_link = new URL(['page' => CURRENT_PAGE, 'id' => $id, 'action' => 'position_up']); | 71 | $up_js = 'onclick="switchPositions(\'' . $id . '\', \'up\')"'; |
72 | $up_button = '<p id="position_up-' . $id . '"><a href="' . $up_link . '"><img class="action_icon" src="assets/arrow-up.svg"></a></p>' . "\n"; | 72 | $up_button = '<p id="position_up-' . $id . '"><a href="#"><img class="action_icon" src="assets/arrow-up.svg" ' . $up_js . '></a></p>' . "\n"; |
73 | 73 | ||
74 | $down_link = new URL(['page' => CURRENT_PAGE, 'id' => $id, 'action' => 'position_down']); | 74 | $down_js = 'onclick="switchPositions(\'' . $id . '\', \'down\')"'; |
75 | $down_button = '<p id="position_down-' . $id . '"><a href="' . $down_link . '"><img class="action_icon" src="assets/arrow-down.svg"></a></p>' . "\n"; | 75 | $down_button = '<p id="position_down-' . $id . '"><a href="#"><img class="action_icon" src="assets/arrow-down.svg" ' . $down_js . '></a></p>' . "\n"; |
76 | 76 | ||
77 | $delete_js = 'onclick="deleteArticle(\'' . $id . '\')"'; | 77 | $delete_js = 'onclick="deleteArticle(\'' . $id . '\')"'; |
78 | $delete_article = '<p id="delete-' . $id . '"><a href="#"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></a></p>' . "\n"; | 78 | $delete_article = '<p id="delete-' . $id . '"><a href="#"><img class="action_icon" src="assets/delete-bin.svg" ' . $delete_js . '></a></p>' . "\n"; |