summaryrefslogtreecommitdiff
path: root/public/js/modif_page.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js/modif_page.js')
-rw-r--r--public/js/modif_page.js188
1 files changed, 188 insertions, 0 deletions
diff --git a/public/js/modif_page.js b/public/js/modif_page.js
new file mode 100644
index 0000000..8ff26c1
--- /dev/null
+++ b/public/js/modif_page.js
@@ -0,0 +1,188 @@
1/* -- mode modification d'une page -- */
2
3// même fonction que dans new_page.js
4function makePageNamePath(){
5 const page_name = document.getElementById("page_name");
6 const page_name_path = document.getElementById("page_name_path");
7 page_name_path.value = page_name.value.replace(/\W+/g, " ").trim().toLowerCase().split(' ').join('_');
8
9 /* explication de l'expression régulière
10 / = début et fin, \W+ = lettres et chiffres, g = global */
11}
12
13
14// partie "page"
15function changePageTitle(page_id){
16 const page_name = document.getElementById("page_name");
17
18 fetch('index.php?page_edit=page_title', {
19 method: 'POST',
20 headers: {
21 'Content-Type': 'application/json'
22 },
23 body: JSON.stringify({title: page_name.value, page_id: page_id})
24 })
25 .then(response => response.json())
26 .then(data => {
27 if(data.success){
28 document.querySelector("title").innerHTML = data.title; // metadonnées
29 document.getElementById("m_" + page_id).innerHTML = data.title; // menu
30 const thesee = document.getElementById("thesee"); // fil d'Ariane
31 if(thesee != null){
32 thesee.innerHTML = data.title;
33 }
34 console.log("la page a été renommée: " + data.title);
35 toastNotify("la page a été renommée: " + data.title);
36 }
37 else{
38 console.error('Erreur au renommage de la page.');
39 }
40 })
41 .catch(error => {
42 console.error('Erreur:', error);
43 });
44}
45/*function changePageMenuPath(page_id){
46 const page_name_path = document.getElementById("page_name_path");
47
48 fetch('index.php?page_edit=page_menu_path', {
49 method: 'POST',
50 headers: {
51 'Content-Type': 'application/json'
52 },
53 body: JSON.stringify({page_menu_path: page_name_path.value, page_id: page_id})
54 })
55 .then(response => response.json())
56 .then(data => {
57 if(data.success){
58 // oh putaing...
59 let url = new URL(document.getElementById("m_" + page_id).parentElement.href); // url attrapée dans une balise <a>
60 let params = new URLSearchParams(url.search); // params à droite du ?
61 let path_array = params.get('page').split('/'); // chemin 'page' découpé dans un tableau
62 console.log(data.page_name_path);
63 path_array[path_array.length - 1] = data.page_name_path; // modif de la dernière case
64 params.set('page', path_array.join('/')); // réassemblage du chemin et MAJ de params
65 url.search = params.toString(); // MAJ de url
66 document.getElementById("m_" + page_id).parentElement.href = url.toString(); // MAJ de la balise <a>
67
68 // modifier l'URL sans rafraichir en touchant à l'historique
69 params.set('action', 'modif_page'); // on veut rester en mode "modif"
70 url.search = params.toString();
71 history.pushState({}, '', url.toString())
72
73 console.log("la nouveau chemin est: " + data.page_name_path);
74 toastNotify("la nouveau chemin est: " + data.page_name_path);
75 }
76 else{
77 console.error("Erreur à la modification du chemin de la page dans l'URL.");
78 }
79 })
80 .catch(error => {
81 console.error('Erreur:', error);
82 });
83}*/
84function changeDescription(node_data_id){
85 const textarea = document.getElementById("description_textarea");
86
87 fetch('index.php?page_edit=page_description', {
88 method: 'POST',
89 headers: {
90 'Content-Type': 'application/json'
91 },
92 body: JSON.stringify({description: textarea.value, node_data_id: node_data_id})
93 })
94 .then(response => response.json())
95 .then(data => {
96 if(data.success){
97 document.querySelector('meta[name="description"]').setAttribute('content', data.description); // c'était vraiment nécéssaire?
98 console.log("la nouvelle description de la page est: " + data.description);
99 toastNotify("la nouvelle description de la page est: " + data.description);
100 }
101 else{
102 console.error('Erreur à la modification de la description de la page.');
103 }
104 })
105 .catch(error => {
106 console.error('Erreur:', error);
107 });
108}
109
110
111// partie "blocs"
112function renamePageBloc(bloc_id){
113 const input = document.getElementById("bloc_rename_" + bloc_id);
114 const title = document.getElementById(bloc_id).querySelector("h3");
115
116 fetch('index.php?bloc_edit=rename_page_bloc', {
117 method: 'POST',
118 headers: {
119 'Content-Type': 'application/json'
120 },
121 body: JSON.stringify({bloc_title: input.value, bloc_id: bloc_id})
122 })
123 .then(response => response.json())
124 .then(data => {
125 if(data.success){
126 title.innerHTML = data.title;
127 console.log(data.title);
128 toastNotify('Le bloc a été renommé: ' + data.title);
129 }
130 else{
131 console.error('Erreur au renommage du titre.');
132 }
133 })
134 .catch(error => {
135 console.error('Erreur:', error);
136 });
137}
138
139function switchBlocsPositions(bloc_id, direction, current_page) {
140 const current_bloc = document.getElementById(bloc_id);
141 const current_bloc_edit_zone = document.getElementById("bloc_edit_" + bloc_id);
142 var other_bloc;
143
144 if(direction == 'down'){
145 other_bloc = current_bloc.nextElementSibling;
146 }
147 else if(direction == 'up'){
148 other_bloc = current_bloc.previousElementSibling;
149 }
150
151 if(other_bloc == null || other_bloc.tagName !== 'SECTION')
152 {
153 console.log('Inversion impossible');
154 return;
155 }
156 const other_bloc_edit_zone = document.getElementById("bloc_edit_" + other_bloc.id);
157
158 fetch('index.php?page=' + current_page + '&bloc_edit=switch_blocs_positions', {
159 method: 'POST',
160 headers: {
161 'Content-Type': 'application/json'
162 },
163 body: JSON.stringify({ id1: bloc_id, id2: parseInt(other_bloc.id) })
164 })
165 .then(response => response.json())
166 .then(data => {
167 if(data.success)
168 {
169 if(direction == 'down'){
170 current_bloc.parentElement.insertBefore(other_bloc, current_bloc);
171 current_bloc_edit_zone.parentElement.insertBefore(other_bloc_edit_zone, current_bloc_edit_zone);
172 console.log('Inversion réussie');
173 }
174 else if(direction == 'up'){
175 other_bloc.parentElement.insertBefore(current_bloc, other_bloc);
176 other_bloc_edit_zone.parentElement.insertBefore(current_bloc_edit_zone, other_bloc_edit_zone);
177 console.log('Inversion réussie');
178 }
179 }
180 else {
181
182 console.error('Échec de l\'inversion');
183 }
184 })
185 .catch(error => {
186 console.error('Erreur:', error);
187 });
188} \ No newline at end of file