From a2bfa172e9184f220469a40611d70177e9c02bca Mon Sep 17 00:00:00 2001 From: polo Date: Sun, 23 Mar 2025 15:21:46 +0100 Subject: affichage toolbar, bouton suppression --- public/index.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 9 deletions(-) diff --git a/public/index.php b/public/index.php index 81a0408..233d85d 100644 --- a/public/index.php +++ b/public/index.php @@ -4,9 +4,8 @@ if(isset($_GET['action']) && $_GET['action'] == 'editor_submit'){ $data = file_get_contents('php://input'); $json = json_decode($data, true); - // Vérifier du décodage du JSON if(json_last_error() === JSON_ERROR_NONE) { - // Traitement les données... + // Traitement côté serveur $articleId = $json['id']; $content = $json['content']; @@ -18,6 +17,26 @@ if(isset($_GET['action']) && $_GET['action'] == 'editor_submit'){ } die; } +elseif(isset($_GET['action']) && $_GET['action'] == 'delete_article'){ + // récupération des données + $post = json_decode(file_get_contents('php://input'), true); + //echo $post['id']; + + if(json_last_error() === JSON_ERROR_NONE){ + // Traitement côté serveur + $success = true; + + // retour au client + if($success) { + echo json_encode(['success' => true]); + } + else { + http_response_code(500); + echo json_encode(['success' => false, 'message' => 'Erreur lors de la suppression de l\'article.']); + } + } + die; +} elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ if (isset($_FILES['file'])) { $file = $_FILES['file']; @@ -30,8 +49,8 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ $filePath = $dest . basename($file['name']); if(move_uploaded_file($file['tmp_name'], $filePath)) { - // Répondre avec l'URL de l'image téléchargée - echo json_encode(['location' => '/' . $filePath]); + $image_url = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); + echo json_encode(['location' => $image_url . $filePath]); // renvoyer l'URL de l'image téléchargée } else{ http_response_code(500); @@ -44,6 +63,7 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ } die; } + ?> @@ -58,6 +78,12 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ .hidden{ display: none; } + figure .align-center{ + + } + figcaption { + + } @@ -74,8 +100,11 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ language: 'fr_FR', // télécharger le paquet correspondant ici: https://www.tiny.cloud/get-tiny/language-packages/ license_key: 'gpl', branding: false, - plugins: 'lists advlist link autolink table image media autoresize help', - toolbar: 'undo redo print | styles | bold italic underline strikethrough | align outdent indent | numlist bullist | link table image media | help', + plugins: 'lists link autolink table image media autoresize help', + toolbar: 'undo redo newdocument print selectall styles bold italic underline strikethrough fontsize forecolor backcolor fontfamily align numlist bullist outdent indent table link image media help', + menubar: false, + toolbar_mode: 'wrap', + statusbar: false, setup: function (editor) { editor.on('init', function () { editors[articleId] = editor; @@ -108,7 +137,8 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ .catch(error => { reject("Erreur lors de l'upload"); }); - }) + }), + image_caption: true }); // Remplacer le contenu de l'article par l'éditeur @@ -116,8 +146,30 @@ elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image'){ } function deleteArticle(articleId) { - console.log("suppression"); - // code similaire à submitArticle() + if (confirm('Voulez-vous vraiment supprimer cet article ?')) { + // Envoyer une requête au serveur pour supprimer l'article + fetch('index.php?action=delete_article', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ id: articleId }) + }) + .then(response => response.json()) + .then(data => { + if (data.success) { + // Supprimer l'article du DOM + const articleElement = document.getElementById(articleId); + articleElement.parentElement.remove(); + } + else { + alert('Erreur lors de la suppression de l\'article.'); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); + } } function closeEditor(articleId) { -- cgit v1.2.3