diff options
| author | polo <ordipolo@gmx.fr> | 2025-10-09 01:35:52 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2025-10-09 01:35:52 +0200 |
| commit | 15cbf5d56b4644151d59fee512f5f8fbe496caa3 (patch) | |
| tree | 0da411f4aff53a0249cf3d59ea13f3786897b740 /public/js/modif_page.js | |
| parent | 9f88389d78755d7c69c29e9db8f114fd1dbef034 (diff) | |
| download | cms-15cbf5d56b4644151d59fee512f5f8fbe496caa3.tar.gz cms-15cbf5d56b4644151d59fee512f5f8fbe496caa3.tar.bz2 cms-15cbf5d56b4644151d59fee512f5f8fbe496caa3.zip | |
pagination partie 2, nouvelles fonctions + renommage dans Director, ArticleController::fetch, et en JS: fetchArticles, insertLocalDates, modifs dans changePaginationLimit, dans les vues
Diffstat (limited to 'public/js/modif_page.js')
| -rw-r--r-- | public/js/modif_page.js | 78 |
1 files changed, 67 insertions, 11 deletions
diff --git a/public/js/modif_page.js b/public/js/modif_page.js index bf269ee..15f3598 100644 --- a/public/js/modif_page.js +++ b/public/js/modif_page.js | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | /* -- mode modification d'une page -- */ | 1 | /* -- mode modification d'une page -- */ |
| 2 | 2 | ||
| 3 | // beaucoup de fonctions similaires | ||
| 4 | // à factoriser avec le pattern stratégie? | ||
| 5 | |||
| 3 | // même fonction que dans new_page.js | 6 | // même fonction que dans new_page.js |
| 4 | function makePageNamePath(){ | 7 | function makePageNamePath(){ |
| 5 | document.getElementById("page_name_path").value = document.getElementById("page_name").value | 8 | document.getElementById("page_name_path").value = document.getElementById("page_name").value |
| @@ -92,7 +95,7 @@ function changeDescription(node_data_id){ | |||
| 92 | toastNotify("la nouvelle description de la page est: " + data.description); | 95 | toastNotify("la nouvelle description de la page est: " + data.description); |
| 93 | } | 96 | } |
| 94 | else{ | 97 | else{ |
| 95 | console.error('Erreur à la modification de la description de la page.'); | 98 | console.error('Erreur côté serveur à la modification de la description de la page.'); |
| 96 | } | 99 | } |
| 97 | }) | 100 | }) |
| 98 | .catch(error => { | 101 | .catch(error => { |
| @@ -119,7 +122,7 @@ function renamePageBloc(bloc_id){ | |||
| 119 | toastNotify('Le bloc a été renommé: ' + data.title); | 122 | toastNotify('Le bloc a été renommé: ' + data.title); |
| 120 | } | 123 | } |
| 121 | else{ | 124 | else{ |
| 122 | console.error('Erreur au renommage du titre.'); | 125 | console.error('Erreur côté serveur au renommage du titre.'); |
| 123 | } | 126 | } |
| 124 | }) | 127 | }) |
| 125 | .catch(error => { | 128 | .catch(error => { |
| @@ -168,7 +171,7 @@ function switchBlocsPositions(bloc_id, direction) { | |||
| 168 | } | 171 | } |
| 169 | else { | 172 | else { |
| 170 | 173 | ||
| 171 | console.error('Échec de l\'inversion'); | 174 | console.error("Échec de l'inversion côté serveur"); |
| 172 | } | 175 | } |
| 173 | }) | 176 | }) |
| 174 | .catch(error => { | 177 | .catch(error => { |
| @@ -187,17 +190,21 @@ function articlesOrderSelect(bloc_id){ | |||
| 187 | .then(response => response.json()) | 190 | .then(response => response.json()) |
| 188 | .then(data => { | 191 | .then(data => { |
| 189 | if(data.success){ | 192 | if(data.success){ |
| 190 | // inverser l'ordre des articles!! | 193 | // inversion des articles |
| 191 | const parent = document.getElementById(bloc_id).querySelector(".section_child"); | 194 | /*const parent = document.getElementById(bloc_id).querySelector(".section_child"); |
| 192 | const articles = Array.from(parent.querySelectorAll("article")); | 195 | const articles = Array.from(parent.querySelectorAll("article")); |
| 193 | articles.reverse().forEach(article => { | 196 | articles.reverse().forEach(article => { |
| 194 | parent.appendChild(article); // déplace dans le DOM, ne copie pas | 197 | parent.appendChild(article); // déplace dans le DOM, ne copie pas |
| 195 | }); | 198 | });*/ |
| 199 | |||
| 200 | // Ã cause de la pagination, au lieu d'inverser, on remplace les articles par les 1er dans le nouveau sens | ||
| 201 | document.getElementById(bloc_id).querySelector('.section_child').innerHTML = ''; | ||
| 202 | fetchArticles(bloc_id); | ||
| 196 | 203 | ||
| 197 | console.log('ordre ' + articles_order_select); | 204 | console.log('ordre ' + articles_order_select); |
| 198 | } | 205 | } |
| 199 | else{ | 206 | else{ |
| 200 | console.log("Erreur au changement de l'ordre d'affichage côté serveur"); | 207 | console.log("Erreur côté serveur au changement de l'ordre d'affichage"); |
| 201 | } | 208 | } |
| 202 | }) | 209 | }) |
| 203 | .catch(error => { | 210 | .catch(error => { |
| @@ -219,10 +226,10 @@ function changePresentation(bloc_id){ | |||
| 219 | document.getElementById(bloc_id).className = presentation; | 226 | document.getElementById(bloc_id).className = presentation; |
| 220 | document.getElementById(bloc_id).querySelector(".section_child").style.gridTemplateColumns = presentation === 'grid' ? 'repeat(auto-fit, minmax(' + data.cols_min_width + 'px, 1fr))' : ''; | 227 | document.getElementById(bloc_id).querySelector(".section_child").style.gridTemplateColumns = presentation === 'grid' ? 'repeat(auto-fit, minmax(' + data.cols_min_width + 'px, 1fr))' : ''; |
| 221 | document.getElementById('cols_min_width_edit_' + bloc_id).className = presentation === 'grid' ? '' : 'hidden'; | 228 | document.getElementById('cols_min_width_edit_' + bloc_id).className = presentation === 'grid' ? '' : 'hidden'; |
| 222 | console.log('changement de présentation'); | 229 | console.log('Changement de présentation'); |
| 223 | } | 230 | } |
| 224 | else{ | 231 | else{ |
| 225 | console.log('Erreur au changement de présentation côté serveur'); | 232 | console.log('Erreur côté serveur au changement de présentation'); |
| 226 | } | 233 | } |
| 227 | }) | 234 | }) |
| 228 | .catch(error => { | 235 | .catch(error => { |
| @@ -230,6 +237,7 @@ function changePresentation(bloc_id){ | |||
| 230 | }); | 237 | }); |
| 231 | } | 238 | } |
| 232 | 239 | ||
| 240 | // ressemble à changePaginationLimit | ||
| 233 | function changeColsMinWidth(bloc_id){ | 241 | function changeColsMinWidth(bloc_id){ |
| 234 | const cols_min_width_input = document.getElementById('cols_min_width_select_' + bloc_id); | 242 | const cols_min_width_input = document.getElementById('cols_min_width_select_' + bloc_id); |
| 235 | 243 | ||
| @@ -250,10 +258,58 @@ function changeColsMinWidth(bloc_id){ | |||
| 250 | if(data.success){ | 258 | if(data.success){ |
| 251 | document.getElementById(bloc_id).className = 'grid'; | 259 | document.getElementById(bloc_id).className = 'grid'; |
| 252 | document.getElementById(bloc_id).querySelector(".section_child").style.gridTemplateColumns = 'repeat(auto-fit, minmax(' + data.cols_min_width + 'px, 1fr))'; | 260 | document.getElementById(bloc_id).querySelector(".section_child").style.gridTemplateColumns = 'repeat(auto-fit, minmax(' + data.cols_min_width + 'px, 1fr))'; |
| 253 | console.log('changement de la largeur minimum en mode grille'); | 261 | console.log('Changement de la largeur minimum en mode grille'); |
| 262 | } | ||
| 263 | else{ | ||
| 264 | console.log('Erreur côté serveur au changement du nb de colonnes en mode grille'); | ||
| 265 | } | ||
| 266 | }) | ||
| 267 | .catch(error => { | ||
| 268 | console.error('Erreur:', error); | ||
| 269 | }); | ||
| 270 | } | ||
| 271 | |||
| 272 | // ressemble à changeColsMinWidth | ||
| 273 | function changePaginationLimit(bloc_id){ | ||
| 274 | const pagination_limit_input = document.getElementById('pagination_limit_' + bloc_id); | ||
| 275 | |||
| 276 | if(pagination_limit_input.value > 30){ | ||
| 277 | pagination_limit_input.value = 30; | ||
| 278 | } | ||
| 279 | else if(pagination_limit_input.value < 0){ | ||
| 280 | pagination_limit_input.value = 0; // fait joli dans la BDD, les valeurs négatives ont le même effet que 0 | ||
| 281 | } | ||
| 282 | |||
| 283 | fetch('index.php?bloc_edit=change_pagination_limit', { | ||
| 284 | method: 'POST', | ||
| 285 | headers: { 'Content-Type': 'application/json' }, | ||
| 286 | body: JSON.stringify({ id: bloc_id, pagination_limit: pagination_limit_input.value }) | ||
| 287 | }) | ||
| 288 | .then(response => response.json()) | ||
| 289 | .then(data => { | ||
| 290 | if(data.success){ | ||
| 291 | const parent = document.getElementById(bloc_id).querySelector('.section_child'); | ||
| 292 | const articles_list = parent.querySelectorAll('article'); | ||
| 293 | |||
| 294 | if(data.new_limit > data.old_limit || data.new_limit <= 0){ // si 0, fetchArticles va TOUT chercher! | ||
| 295 | parent.innerHTML = ''; // pas opti, mais améliorer ça serait très compliqué | ||
| 296 | fetchArticles(bloc_id); | ||
| 297 | } | ||
| 298 | else if(data.new_limit < articles_list.length){ | ||
| 299 | // retirer les articles | ||
| 300 | const articles_array = Array.from(articles_list).slice(0, data.new_limit); | ||
| 301 | parent.innerHTML = ''; | ||
| 302 | for(let i = 0; i < articles_array.length; i++){ | ||
| 303 | parent.appendChild(articles_array[i]); | ||
| 304 | } | ||
| 305 | // remettre le bouton "Articles suivants" | ||
| 306 | document.getElementById(bloc_id).querySelector('.fetch_articles').querySelector('button').className = ''; | ||
| 307 | } | ||
| 308 | |||
| 309 | console.log("Changement du nombre d'articles affichés simultanément dans ce bloc"); | ||
| 254 | } | 310 | } |
| 255 | else{ | 311 | else{ |
| 256 | console.log('Erreur au changement du nb de colonnes en mode grille côté serveur'); | 312 | console.log("Erreur côté serveur au changement du nb d'éléments affichés par la pagination"); |
| 257 | } | 313 | } |
| 258 | }) | 314 | }) |
| 259 | .catch(error => { | 315 | .catch(error => { |
