1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
// flèche gauche <=: position = position du parent + 1, parent = grand-parent, recalculer les positions
function moveOneLevelUp(page_id)
{
const nav_zone = document.getElementById("nav_zone"); // parent de <nav>
const menu_edit_buttons = document.getElementById("menu_edit_buttons"); // div englobant le html généré par MenuBuilder
fetch('index.php?menu_edit=move_one_level_up', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ id: page_id })
})
.then(response => response.json())
.then(data => {
if(data.success)
{
// affichage
nav_zone.innerHTML = '';
nav_zone.insertAdjacentHTML('afterbegin', data.nav);
menu_edit_buttons.innerHTML = '';
menu_edit_buttons.insertAdjacentHTML('afterbegin', data.menu_buttons);
}
else {
console.error('Échec du déplacement');
}
})
.catch(error => {
console.error('Erreur:', error);
});
}
// flèche droite =>: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent
function moveOneLevelDown(page_id)
{
const nav_zone = document.getElementById("nav_zone"); // parent de <nav>
const menu_edit_buttons = document.getElementById("menu_edit_buttons"); // div englobant le html généré par MenuBuilder
fetch('index.php?menu_edit=move_one_level_down', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ id: page_id })
})
.then(response => response.json())
.then(data => {
if(data.success)
{
// affichage
nav_zone.innerHTML = '';
nav_zone.insertAdjacentHTML('afterbegin', data.nav);
menu_edit_buttons.innerHTML = '';
menu_edit_buttons.insertAdjacentHTML('afterbegin', data.menu_buttons);
}
else {
console.error('Échec du déplacement');
}
})
.catch(error => {
console.error('Erreur:', error);
});
}
function switchMenuPositions(page_id, direction)
{
const nav_zone = document.getElementById("nav_zone"); // parent de <nav>
const clicked_menu_entry = document.getElementById(page_id); // div parente du bouton
let other_entry = null;
// pas bon
if(direction == 'down'){
other_entry = clicked_menu_entry.nextElementSibling;
}
else if(direction == 'up'){
other_entry = clicked_menu_entry.previousElementSibling;
}
if(other_entry == null){
console.log('Inversion impossible');
return;
}
fetch('index.php?menu_edit=switch_positions', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ id1: clicked_menu_entry.id, id2: other_entry.id })
})
.then(response => response.json())
.then(data => {
if(data.success)
{
if(direction == 'down'){
clicked_menu_entry.parentElement.insertBefore(other_entry, clicked_menu_entry);
}
else if(direction == 'up'){
other_entry.parentElement.insertBefore(clicked_menu_entry, other_entry);
}
else{
console.error('Échec de l\'inversion');
}
// menu régénéré
nav_zone.innerHTML = '';
nav_zone.insertAdjacentHTML('afterbegin', data.nav);
}
else {
console.error('Échec de l\'inversion');
}
})
.catch(error => {
console.error('Erreur:', error);
});
}
function checkMenuEntry(page_id){
const nav_zone = document.getElementById("nav_zone"); // parent de <nav>
const clicked_menu_entry = document.getElementById(page_id); // div parente du bouton
const checkbox = clicked_menu_entry.querySelector("input");
let color;
fetch('index.php?menu_edit=displayInMenu', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ id: clicked_menu_entry.id, checked: checkbox.checked })
})
.then(response => response.json())
.then(data => {
if(data.success)
{
color = checkbox.checked ? "#ff1d04" : "grey";
clicked_menu_entry.querySelector("button").style.color = color;
nav_zone.innerHTML = '';
nav_zone.insertAdjacentHTML('afterbegin', data.nav);
}
else {
console.error('Échec de l\'inversion');
}
})
.catch(error => {
console.error('Erreur:', error);
});
}
function editUrlEntry(page_id){
const selected_div = document.getElementById(page_id);
console.log(selected_div.id);
}
function deleteUrlEntry(page_id){
const selected_div = document.getElementById(page_id);
console.log(selected_div.id);
}
|