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