summaryrefslogtreecommitdiff
path: root/public/js/main.js
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-04-06 12:18:49 +0200
committerpolo <ordipolo@gmx.fr>2025-04-06 12:18:49 +0200
commit68b6058e2a27fc251c117c4efeb141392a0c9736 (patch)
tree5c029b2c147bd14f777765d41bc623582c81daa2 /public/js/main.js
parente4a325c9d5c07f09bc18b7e366ffb82b82c43502 (diff)
downloadcms-68b6058e2a27fc251c117c4efeb141392a0c9736.zip
nouvel article, boutons dans les builders, makeArticleNode, JS MAJ page, tri quand déplacement ou suppression
Diffstat (limited to 'public/js/main.js')
-rw-r--r--public/js/main.js30
1 files changed, 25 insertions, 5 deletions
diff --git a/public/js/main.js b/public/js/main.js
index 1351fea..c05eb2f 100644
--- a/public/js/main.js
+++ b/public/js/main.js
@@ -30,10 +30,10 @@ function copyInClipBoard(link){
30} 30}
31 31
32// complète les fonctions dans tinymce.js 32// complète les fonctions dans tinymce.js
33function switchPositions(articleId, direction) 33function switchPositions(article_id, direction)
34{ 34{
35 const current_article = document.getElementById(articleId).parentElement.parentElement; 35 const current_article = findParent(document.getElementById(article_id), 'article');
36 var other_article = current_article; 36 var other_article;
37 37
38 if(direction == 'down'){ 38 if(direction == 'down'){
39 other_article = current_article.nextElementSibling; 39 other_article = current_article.nextElementSibling;
@@ -41,14 +41,23 @@ function switchPositions(articleId, direction)
41 else if(direction == 'up'){ 41 else if(direction == 'up'){
42 other_article = current_article.previousElementSibling; 42 other_article = current_article.previousElementSibling;
43 } 43 }
44 const other_article_id = other_article.querySelector('div[id]').id; 44
45 var other_article_id;
46 try{
47 other_article_id = other_article.querySelector('div[id]').id;
48 other_article_id = 'i' + other_article_id.slice(1); // peut mieux faire
49 }
50 catch(error){
51 console.log('Inversion impossible');
52 return;
53 }
45 54
46 fetch('index.php?action=switch_positions', { 55 fetch('index.php?action=switch_positions', {
47 method: 'POST', 56 method: 'POST',
48 headers: { 57 headers: {
49 'Content-Type': 'application/json' 58 'Content-Type': 'application/json'
50 }, 59 },
51 body: JSON.stringify({ id1: articleId, id2: other_article_id }) 60 body: JSON.stringify({ id1: article_id, id2: other_article_id })
52 }) 61 })
53 .then(response => response.json()) 62 .then(response => response.json())
54 .then(data => { 63 .then(data => {
@@ -155,4 +164,15 @@ function submitDate(id_date)
155 .catch(error => { 164 .catch(error => {
156 console.error('Erreur:', error); 165 console.error('Erreur:', error);
157 }); 166 });
167}
168
169function findParent(element, tag_name) {
170 while (element !== null) {
171 if (element.tagName === tag_name.toUpperCase()) // tagName est en majuscules
172 {
173 return element;
174 }
175 element = element.parentElement;
176 }
177 return null;
158} \ No newline at end of file 178} \ No newline at end of file