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