From 959527bb712fcd05351d8b4b52ff17786baad454 Mon Sep 17 00:00:00 2001 From: polo Date: Sun, 26 Oct 2025 22:48:49 +0100 Subject: =?UTF-8?q?modification=20du=20nom=20et=20plus=20seulement=20de=20?= =?UTF-8?q?l'URL=20des=20entr=C3=A9es=20"URL"=20du=20menu,=20header/footer?= =?UTF-8?q?:=20renommage=20de=20classes=20et=20input=20absents=20du=20HTML?= =?UTF-8?q?=20sans=20=C3=AAtre=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/Input.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 public/js/Input.js (limited to 'public/js/Input.js') diff --git a/public/js/Input.js b/public/js/Input.js new file mode 100644 index 0000000..0b6912b --- /dev/null +++ b/public/js/Input.js @@ -0,0 +1,96 @@ +class Input{ + constructor(name){ + this.name = name; + /*const name_array = name.split('_'); + this.node = name_array[0]; + this.what = name_array[1];*/ + this.parent = document.getElementById(name); + } + open(){ + this.parent.querySelector('#' + this.name + '_content').classList.add('hidden'); + this.parent.querySelector('#' + this.name + '_input').classList.remove('hidden'); + this.parent.querySelector('#' + this.name + '_open').classList.add('hidden'); + this.parent.querySelector('#' + this.name + '_submit').classList.remove('hidden'); + this.parent.querySelector('#' + this.name + '_cancel').classList.remove('hidden'); + } + close(){ + this.parent.querySelector('#' + this.name + '_content').classList.remove('hidden'); + this.parent.querySelector('#' + this.name + '_input').classList.add('hidden'); + this.parent.querySelector('#' + this.name + '_open').classList.remove('hidden'); + this.parent.querySelector('#' + this.name + '_submit').classList.add('hidden'); + this.parent.querySelector('#' + this.name + '_cancel').classList.add('hidden'); + } + cancel(){ + this.close(); + } +} + +class InputFile extends Input{ + submit(){ + const file = this.parent.querySelector('#' + this.name + '_input').files[0]; + if(!file){ + console.error("Erreur: aucun fichier sélectionné."); + toastNotify("Erreur: aucun fichier sélectionné."); + return; + } + const form_data = new FormData(); + form_data.append('file', file); + + fetch('index.php?head_foot_image=' + this.name, { + method: 'POST', // apparemment il faudrait utiliser PUT + body: form_data + }) + .then(response => response.json()) + .then(data => { + if(data.success){ + // cas particuliers + if(this.name === 'head_favicon'){ + const link = document.querySelector('link[rel="icon"]'); + link.type = data.mime_type; + link.href = data.location; + } + else if(this.name === 'header_background'){ + document.querySelector('header').style.backgroundImage = "url('" + data.location + "')"; + } + + this.parent.querySelector('#' + this.name + '_content').src = data.location; + this.close(); + } + else{ + console.error("Erreur: le serveur n'a pas enregistré l'image'."); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); + } +} + +class InputText extends Input{ + submit(){ + const new_text = this.parent.querySelector('#' + this.name + '_input').value; + + fetch('index.php?head_foot_text=' + this.name, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({new_text: new_text}) + }) + .then(response => response.json()) + .then(data => { + if(data.success){ + this.parent.querySelector('#' + this.name + '_content').innerHTML = new_text; + this.close(); + } + else{ + console.error("Erreur: le serveur n'a pas enregistré le nouveau texte."); + } + }) + .catch(error => { + console.error('Erreur:', error); + }); + } + cancel(){ // surcharge + this.parent.querySelector('#' + this.name + '_input').value = this.parent.querySelector('#' + this.name + '_content').innerHTML; + this.close(); + } +} \ No newline at end of file -- cgit v1.2.3