diff options
author | polo <ordipolo@gmx.fr> | 2025-04-27 23:58:46 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-04-27 23:58:46 +0200 |
commit | 962d315ec0c99974df3dc2261bf94c54ca8cdbdd (patch) | |
tree | 7463f74a722e759067daf8c3ef43202a60352759 /public/js/main.js | |
parent | a3ba7dde60dc1c94b7170ec28266a966e5004d33 (diff) | |
download | cms-962d315ec0c99974df3dc2261bf94c54ca8cdbdd.zip |
page menu et chemins, partie3
Diffstat (limited to 'public/js/main.js')
-rw-r--r-- | public/js/main.js | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/public/js/main.js b/public/js/main.js index f74c670..e278325 100644 --- a/public/js/main.js +++ b/public/js/main.js | |||
@@ -202,97 +202,4 @@ function findParent(element, tag_name){ | |||
202 | element = element.parentElement; | 202 | element = element.parentElement; |
203 | } | 203 | } |
204 | return null; | 204 | return null; |
205 | } | ||
206 | |||
207 | |||
208 | /* page Menu et chemins */ | ||
209 | function moveOneLevelUp(){} | ||
210 | function moveOneLevelDown(){} | ||
211 | |||
212 | function switchMenuPositions(page_id, direction) | ||
213 | { | ||
214 | const nav_zone = document.getElementById("nav_zone"); // parent de <nav> | ||
215 | const clicked_menu_entry = document.getElementById(page_id); // div parente du bouton | ||
216 | var other_entry = null; | ||
217 | |||
218 | // pas bon | ||
219 | if(direction == 'down'){ | ||
220 | other_entry = clicked_menu_entry.nextElementSibling; | ||
221 | } | ||
222 | else if(direction == 'up'){ | ||
223 | other_entry = clicked_menu_entry.previousElementSibling; | ||
224 | } | ||
225 | |||
226 | if(other_entry == null){ | ||
227 | console.log('Inversion impossible'); | ||
228 | return; | ||
229 | } | ||
230 | |||
231 | fetch('index.php?menu_edit=switch_positions', { | ||
232 | method: 'POST', | ||
233 | headers: { | ||
234 | 'Content-Type': 'application/json' | ||
235 | }, | ||
236 | body: JSON.stringify({ id1: clicked_menu_entry.id, id2: other_entry.id }) | ||
237 | }) | ||
238 | .then(response => response.json()) | ||
239 | .then(data => { | ||
240 | if(data.success) | ||
241 | { | ||
242 | if(direction == 'down'){ | ||
243 | clicked_menu_entry.parentElement.insertBefore(other_entry, clicked_menu_entry); | ||
244 | console.log('Inversion réussie'); | ||
245 | } | ||
246 | else if(direction == 'up'){ | ||
247 | other_entry.parentElement.insertBefore(clicked_menu_entry, other_entry); | ||
248 | console.log('Inversion réussie'); | ||
249 | } | ||
250 | else{ | ||
251 | console.error('Échec de l\'inversion'); | ||
252 | } | ||
253 | |||
254 | nav_zone.innerHTML = ''; | ||
255 | nav_zone.insertAdjacentHTML('afterbegin', data.nav); | ||
256 | } | ||
257 | else { | ||
258 | |||
259 | console.error('Échec de l\'inversion'); | ||
260 | } | ||
261 | }) | ||
262 | .catch(error => { | ||
263 | console.error('Erreur:', error); | ||
264 | }); | ||
265 | } | ||
266 | |||
267 | function checkMenuEntry(page_id){ | ||
268 | const nav_zone = document.getElementById("nav_zone"); // parent de <nav> | ||
269 | const clicked_menu_entry = document.getElementById(page_id); // div parente du bouton | ||
270 | const checkbox = clicked_menu_entry.querySelector("input"); | ||
271 | let color; | ||
272 | |||
273 | fetch('index.php?menu_edit=displayInMenu', { | ||
274 | method: 'POST', | ||
275 | headers: { | ||
276 | 'Content-Type': 'application/json' | ||
277 | }, | ||
278 | body: JSON.stringify({ id: clicked_menu_entry.id, checked: checkbox.checked }) | ||
279 | }) | ||
280 | .then(response => response.json()) | ||
281 | .then(data => { | ||
282 | if(data.success) | ||
283 | { | ||
284 | color = checkbox.checked ? "#ff1d04" : "grey"; | ||
285 | clicked_menu_entry.querySelector("button").style.color = color; | ||
286 | |||
287 | nav_zone.innerHTML = ''; | ||
288 | nav_zone.insertAdjacentHTML('afterbegin', data.nav); | ||
289 | } | ||
290 | else { | ||
291 | |||
292 | console.error('Échec de l\'inversion'); | ||
293 | } | ||
294 | }) | ||
295 | .catch(error => { | ||
296 | console.error('Erreur:', error); | ||
297 | }); | ||
298 | } \ No newline at end of file | 205 | } \ No newline at end of file |