From 7f13ca69bb71a0eb477cbf4f4bfcd08b2843bf9b Mon Sep 17 00:00:00 2001 From: polo Date: Mon, 31 Mar 2025 22:50:11 +0200 Subject: inversion de deux articles --- public/js/main.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'public/js') 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){ element.parentNode.removeChild(element); alert('Cette adresse a été copiée dans le presse-papier:\n\n' + link); +} + +// complète les fonctions dans tinymce.js +function switchPositions(articleId, direction) +{ + const current_article = document.getElementById(articleId).parentElement.parentElement; + var other_article = current_article; + + if(direction == 'down'){ + other_article = current_article.nextElementSibling; + } + else if(direction == 'up'){ + other_article = current_article.previousElementSibling; + } + const other_article_id = other_article.querySelector('div[id]').id; + + fetch('index.php?action=switch_positions', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ id1: articleId, id2: other_article_id }) + }) + .then(response => response.json()) + .then(data => { + if(data.success) + { + if(direction == 'down'){ + current_article.parentElement.insertBefore(other_article, current_article); + console.log('Inversion réussie'); + } + else if(direction == 'up'){ + other_article.parentElement.insertBefore(current_article, other_article); + console.log('Inversion réussie'); + } + else{ + console.log('Échec de l\'inversion'); + } + } + else { + + console.log('Échec de l\'inversion'); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); } \ No newline at end of file -- cgit v1.2.3