diff options
Diffstat (limited to 'public/js/InputText.js')
| -rw-r--r-- | public/js/InputText.js | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/public/js/InputText.js b/public/js/InputText.js deleted file mode 100644 index 79f0398..0000000 --- a/public/js/InputText.js +++ /dev/null | |||
| @@ -1,48 +0,0 @@ | |||
| 1 | // s'en servir dans menu et chemin | ||
| 2 | // étendre un classe parente avec InputText? | ||
| 3 | class InputText{ | ||
| 4 | constructor(name){ | ||
| 5 | this.name = name; | ||
| 6 | this.parent = document.getElementById(name); | ||
| 7 | } | ||
| 8 | open(){ | ||
| 9 | this.parent.querySelector('#' + this.name + '_span').classList.add('hidden'); | ||
| 10 | this.parent.querySelector('#' + this.name + '_input').classList.remove('hidden'); | ||
| 11 | this.parent.querySelector('#' + this.name + '_open').classList.add('hidden'); | ||
| 12 | this.parent.querySelector('#' + this.name + '_submit').classList.remove('hidden'); | ||
| 13 | this.parent.querySelector('#' + this.name + '_cancel').classList.remove('hidden'); | ||
| 14 | } | ||
| 15 | close(){ | ||
| 16 | this.parent.querySelector('#' + this.name + '_span').classList.remove('hidden'); | ||
| 17 | this.parent.querySelector('#' + this.name + '_input').classList.add('hidden'); | ||
| 18 | this.parent.querySelector('#' + this.name + '_open').classList.remove('hidden'); | ||
| 19 | this.parent.querySelector('#' + this.name + '_submit').classList.add('hidden'); | ||
| 20 | this.parent.querySelector('#' + this.name + '_cancel').classList.add('hidden'); | ||
| 21 | } | ||
| 22 | submit(){ | ||
| 23 | const new_text = this.parent.querySelector('#' + this.name + '_input').value; | ||
| 24 | |||
| 25 | fetch('index.php?head_foot_text=' + this.name, { | ||
| 26 | method: 'POST', | ||
| 27 | headers: { 'Content-Type': 'application/json' }, | ||
| 28 | body: JSON.stringify({new_text: new_text}) | ||
| 29 | }) | ||
| 30 | .then(response => response.json()) | ||
| 31 | .then(data => { | ||
| 32 | if(data.success){ | ||
| 33 | this.parent.querySelector('#' + this.name + '_span').innerHTML = new_text; | ||
| 34 | this.close(); | ||
| 35 | } | ||
| 36 | else{ | ||
| 37 | console.error("Erreur: le serveur n'a pas enregistré le nouveau texte."); | ||
| 38 | } | ||
| 39 | }) | ||
| 40 | .catch(error => { | ||
| 41 | console.error('Erreur:', error); | ||
| 42 | }); | ||
| 43 | } | ||
| 44 | cancel(){ | ||
| 45 | this.parent.querySelector('#' + this.name + '_input').value = this.parent.querySelector('#' + this.name + '_span').innerHTML; | ||
| 46 | this.close(); | ||
| 47 | } | ||
| 48 | } \ No newline at end of file | ||
