diff options
author | polo-pc-greta <ordipolo@gmx.fr> | 2025-04-07 21:38:12 +0200 |
---|---|---|
committer | polo-pc-greta <ordipolo@gmx.fr> | 2025-04-07 21:38:12 +0200 |
commit | 1937a2f49ebe920b79604cb5df3649f9f1dff738 (patch) | |
tree | fac9a39aae9690b0e5a860bdb2cc88565e83daac /public | |
parent | 09bea09c8157ff45279f0d06aa9d313448c0bec5 (diff) | |
download | cms-1937a2f49ebe920b79604cb5df3649f9f1dff738.zip |
bouton suppression après création d'une "news"
Diffstat (limited to 'public')
-rw-r--r-- | public/index.php | 2 | ||||
-rw-r--r-- | public/js/tinymce.js | 63 |
2 files changed, 29 insertions, 36 deletions
diff --git a/public/index.php b/public/index.php index 2512d6d..8cb2b9a 100644 --- a/public/index.php +++ b/public/index.php | |||
@@ -26,7 +26,7 @@ require '../src/model/doctrine-bootstrap.php'; // isDevMode est sur "true", DSN | |||
26 | 26 | ||
27 | URL::setProtocol(Config::$protocol); // utile si port autre que 80 ou 443 | 27 | URL::setProtocol(Config::$protocol); // utile si port autre que 80 ou 443 |
28 | URL::setPort(Config::$port); | 28 | URL::setPort(Config::$port); |
29 | URL::setHost($_SERVER['HTTP_HOST']); | 29 | URL::setHost($_SERVER['HTTP_HOST'] . Config::$index_path); |
30 | 30 | ||
31 | //require('controller/Session.php'); | 31 | //require('controller/Session.php'); |
32 | ini_set('session.cookie_samesite', 'Strict'); | 32 | ini_set('session.cookie_samesite', 'Strict'); |
diff --git a/public/js/tinymce.js b/public/js/tinymce.js index 00868ee..092698e 100644 --- a/public/js/tinymce.js +++ b/public/js/tinymce.js | |||
@@ -95,7 +95,7 @@ function deleteArticle(id, page = '') { | |||
95 | .then(data => { | 95 | .then(data => { |
96 | if(data.success) | 96 | if(data.success) |
97 | { | 97 | { |
98 | if(page == 'article'){ | 98 | if(page === 'article'){ |
99 | // redirection vers la page d'accueil | 99 | // redirection vers la page d'accueil |
100 | window.setTimeout(function(){ | 100 | window.setTimeout(function(){ |
101 | location.href = "index.php?page=accueil"; | 101 | location.href = "index.php?page=accueil"; |
@@ -177,49 +177,27 @@ function closeEditor(id, page = '', restore_old = true) | |||
177 | 177 | ||
178 | function submitArticle(id, page = '', clone = null) | 178 | function submitArticle(id, page = '', clone = null) |
179 | { | 179 | { |
180 | /*if(id[0] === 'n' && clone == null){ | ||
181 | return; // sécurité | ||
182 | }*/ | ||
183 | var editor; | 180 | var editor; |
181 | var content; | ||
184 | const params = new URL(document.location).searchParams; // "search" = ? et paramètres, searchParams = objet avec des getters | 182 | const params = new URL(document.location).searchParams; // "search" = ? et paramètres, searchParams = objet avec des getters |
185 | 183 | ||
186 | // clic sur "tout enregistrer" | 184 | // clic sur "tout enregistrer" |
187 | if(id[0] === 'n' && page === 'article'){ | 185 | if(id[0] === 'n' && page === 'article'){ |
188 | const prefixes = ['t', 'p', 'i', 'd']; | 186 | const prefixes = ['t', 'p', 'i', 'd']; |
189 | const allElemsWithId = document.querySelectorAll('[id]'); | 187 | const allElemsWithId = document.querySelectorAll('[class="data"]'); |
190 | var content = {}; | 188 | content = {}; |
189 | var id_from_builder; | ||
191 | 190 | ||
192 | allElemsWithId.forEach(element => { | 191 | allElemsWithId.forEach(element => { |
193 | const first_letter = element.id.charAt(0).toLowerCase(); | 192 | const first_letter = element.id.charAt(0).toLowerCase(); |
194 | if(prefixes.includes(first_letter)){ | 193 | if(prefixes.includes(first_letter)){ |
195 | content[first_letter] = element.innerHTML; | 194 | content[first_letter] = element.innerHTML; |
195 | if(first_letter === 'i'){ | ||
196 | id_from_builder = element.id; | ||
197 | } | ||
196 | } | 198 | } |
197 | }) | 199 | }) |
198 | content['d'] = dateToISO(content['d']); | 200 | content['d'] = dateToISO(content['d']); |
199 | |||
200 | // Envoi AJAX au serveur | ||
201 | fetch('index.php?action=editor_submit', { | ||
202 | method: 'POST', | ||
203 | headers: { | ||
204 | 'Content-Type': 'application/json' | ||
205 | }, | ||
206 | body: JSON.stringify({id: id, content: content}) | ||
207 | }) | ||
208 | .then(response => response.json()) | ||
209 | .then(data => { | ||
210 | if (data.success) { | ||
211 | console.log('données envoyées au serveur avec succès.'); | ||
212 | |||
213 | // remplacer les boutons (Enregistrer => Supprimer) | ||
214 | } | ||
215 | else { | ||
216 | alert('Erreur lors de la sauvegarde de l\'article.'); | ||
217 | } | ||
218 | }) | ||
219 | .catch(error => { | ||
220 | console.error('Erreur:', error); | ||
221 | }); | ||
222 | return; | ||
223 | } | 201 | } |
224 | // champs à remplir des nouvelles "news" | 202 | // champs à remplir des nouvelles "news" |
225 | else if(page === 'article' && params != null && params.get("id")[0] === 'n'){ | 203 | else if(page === 'article' && params != null && params.get("id")[0] === 'n'){ |
@@ -235,6 +213,7 @@ function submitArticle(id, page = '', clone = null) | |||
235 | console.error('Éditeur non trouvé pour l\'article:', id); | 213 | console.error('Éditeur non trouvé pour l\'article:', id); |
236 | return; | 214 | return; |
237 | } | 215 | } |
216 | content = editor.getContent(); | ||
238 | } | 217 | } |
239 | 218 | ||
240 | // Envoi AJAX au serveur | 219 | // Envoi AJAX au serveur |
@@ -243,15 +222,29 @@ function submitArticle(id, page = '', clone = null) | |||
243 | headers: { | 222 | headers: { |
244 | 'Content-Type': 'application/json' | 223 | 'Content-Type': 'application/json' |
245 | }, | 224 | }, |
246 | body: JSON.stringify({id: id, content: editor.getContent()}) | 225 | body: JSON.stringify({id: id, content: content}) |
247 | }) | 226 | }) |
248 | .then(response => response.json()) | 227 | .then(response => response.json()) |
249 | .then(data => { | 228 | .then(data => { |
250 | if (data.success) { | 229 | if (data.success) { |
251 | // Fermer l'éditeur et mettre à jour le contenu de l'article | 230 | console.log(data.article_id); |
252 | closeEditor(id, page, false); | 231 | if(id[0] === 'n' && page === 'article'){ |
253 | if(id[0] === 'n'){ | 232 | console.log('données envoyées au serveur avec succès.'); |
254 | makeNewArticleButtons(id, data.article_id, clone); | 233 | |
234 | // remplacer bouton Enregistrer par Supprimer | ||
235 | submit_btn = document.getElementById('save-' + id_from_builder); // id précédent par NewBuilder | ||
236 | submit_btn.classList.add('hidden'); | ||
237 | delete_btn = document.getElementById('delete-' + id_from_builder); | ||
238 | delete_btn.id = data.article_id; | ||
239 | delete_btn.querySelector('button').setAttribute('onclick', "deleteArticle('" + data.article_id + "', 'article')"); | ||
240 | delete_btn.classList.remove('hidden'); | ||
241 | } | ||
242 | else{ | ||
243 | // Fermer l'éditeur et mettre à jour le contenu de l'article | ||
244 | closeEditor(id, page, false); | ||
245 | if(id[0] === 'n'){ | ||
246 | makeNewArticleButtons(id, data.article_id, clone); | ||
247 | } | ||
255 | } | 248 | } |
256 | } | 249 | } |
257 | else { | 250 | else { |