diff options
author | polo <ordipolo@gmx.fr> | 2025-05-09 01:02:23 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-05-09 01:02:23 +0200 |
commit | d2bdfa7d0f746f060090a9e8c8ad6e376b5a1480 (patch) | |
tree | 985e8aca070a0f4ad56bea31ceb19b759828027c /public/js/main.js | |
parent | 0f497d215de8e16739263e2718bd39640a6cc4d8 (diff) | |
download | cms-d2bdfa7d0f746f060090a9e8c8ad6e376b5a1480.zip |
mode modif page terminé!
Diffstat (limited to 'public/js/main.js')
-rw-r--r-- | public/js/main.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/public/js/main.js b/public/js/main.js index 802bbbe..7dacb7a 100644 --- a/public/js/main.js +++ b/public/js/main.js | |||
@@ -231,4 +231,55 @@ function renamePageBloc(bloc_id){ | |||
231 | .catch(error => { | 231 | .catch(error => { |
232 | console.error('Erreur:', error); | 232 | console.error('Erreur:', error); |
233 | }); | 233 | }); |
234 | } | ||
235 | |||
236 | function switchBlocsPositions(bloc_id, direction, current_page) { | ||
237 | const current_bloc = document.getElementById(bloc_id); | ||
238 | const current_bloc_edit_zone = document.getElementById("bloc_edit_" + bloc_id); | ||
239 | var other_bloc; | ||
240 | |||
241 | if(direction == 'down'){ | ||
242 | other_bloc = current_bloc.nextElementSibling; | ||
243 | } | ||
244 | else if(direction == 'up'){ | ||
245 | other_bloc = current_bloc.previousElementSibling; | ||
246 | } | ||
247 | |||
248 | if(other_bloc == null || other_bloc.tagName !== 'SECTION') | ||
249 | { | ||
250 | console.log('Inversion impossible'); | ||
251 | return; | ||
252 | } | ||
253 | const other_bloc_edit_zone = document.getElementById("bloc_edit_" + other_bloc.id); | ||
254 | |||
255 | fetch('index.php?page=' + current_page + '&bloc_edit=switch_blocs_positions', { | ||
256 | method: 'POST', | ||
257 | headers: { | ||
258 | 'Content-Type': 'application/json' | ||
259 | }, | ||
260 | body: JSON.stringify({ id1: bloc_id, id2: parseInt(other_bloc.id) }) | ||
261 | }) | ||
262 | .then(response => response.json()) | ||
263 | .then(data => { | ||
264 | if(data.success) | ||
265 | { | ||
266 | if(direction == 'down'){ | ||
267 | current_bloc.parentElement.insertBefore(other_bloc, current_bloc); | ||
268 | current_bloc_edit_zone.parentElement.insertBefore(other_bloc_edit_zone, current_bloc_edit_zone); | ||
269 | console.log('Inversion réussie'); | ||
270 | } | ||
271 | else if(direction == 'up'){ | ||
272 | other_bloc.parentElement.insertBefore(current_bloc, other_bloc); | ||
273 | other_bloc_edit_zone.parentElement.insertBefore(current_bloc_edit_zone, other_bloc_edit_zone); | ||
274 | console.log('Inversion réussie'); | ||
275 | } | ||
276 | } | ||
277 | else { | ||
278 | |||
279 | console.error('Échec de l\'inversion'); | ||
280 | } | ||
281 | }) | ||
282 | .catch(error => { | ||
283 | console.error('Erreur:', error); | ||
284 | }); | ||
234 | } \ No newline at end of file | 285 | } \ No newline at end of file |