Browse code

Externalisation du systeme de menu

schardon authored on 27/04/2020 23:19:23
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,195 +0,0 @@
1
-(function($) {
2
-$(document).ready(function() {
3
-
4
-  var menuList = [];
5
-  var scPartieId = scInput_PartieId;
6
-  var scJoueurId = scInput_JoueurId;
7
-  var menuMode = '';
8
-
9
-  function refreshScreen(data) {
10
-    if(data['mode'] == 'g') {
11
-      if(scJoueurId > 0)
12
-        window.location.href = 'index.php?j=' + scJoueurId;
13
-      else
14
-        window.location.href = 'index.php';
15
-      return;
16
-    }
17
-
18
-    if(data['mode'] != menuMode) {
19
-      menuMode = data['mode'];
20
-      if(menuMode == 'p') {
21
-        $('#creerTitre').html(scInput_JeuNom.toUpperCase() + ' - Choisir une partie');
22
-        $('#creerTitre').removeClass('creer-titre-attente');
23
-        $('#creerTitre').removeClass('creer-titre-joueur');
24
-        $('#creerTitre').addClass('creer-titre-partie');
25
-        $('#creerForm').show();
26
-        $('#creerGo').hide();
27
-        scPartieId = 0;
28
-        scJoueurId = 0;
29
-      }
30
-      if(menuMode == 'j') {
31
-        $('#creerTitre').html('<div class="creer-titre-retour creer-btn">&lt;&lt;</div>' + scInput_JeuNom.toUpperCase() + ' [ Partie : ' + data['partie'] + ' ] Choisir un joueur');
32
-        $('#creerTitre').removeClass('creer-titre-attente');
33
-        $('#creerTitre').removeClass('creer-titre-partie');
34
-        $('#creerTitre').addClass('creer-titre-joueur');
35
-        $('#creerForm').show();
36
-        $('#creerGo').hide();
37
-        scJoueurId = 0;
38
-      }
39
-      if(menuMode == 's') {
40
-        $('#creerTitre').html('<div class="creer-titre-retour creer-btn">&lt;&lt;</div>' + scInput_JeuNom.toUpperCase() + ' [ Partie : ' + data['partie'] + ' ] [ Joueur : ' + data['joueur'] + " ] Salle d'attente");
41
-        $('#creerTitre').removeClass('creer-titre-partie');
42
-        $('#creerTitre').removeClass('creer-titre-joueur');
43
-        $('#creerTitre').addClass('creer-titre-attente');
44
-        $('#creerForm').hide();
45
-      }
46
-      $('#creerListeTab').empty();
47
-      menuList = [];
48
-    }
49
-
50
-    // Parties/Joueurs ajoutes ou modifies ?
51
-    var dataListeTaille = 0;
52
-    for(var key in data['liste']) {
53
-      dataListeTaille++;
54
-      var val = data['liste'][key];
55
-      if( menuList[key] ) {
56
-        if( menuList[key] != val )
57
-          $('#creerListeItem' + key + ' .creer-liste-nom').html( val );
58
-      }
59
-      else {
60
-        var tr = $('<tr id="creerListeItem' + key + '"><td class="creer-liste-nom">' + val + '</td>' + (scJoueurId > 0 ? '' : '<td class="creer-liste-btn"><div class="creer-liste-btn-entrer creer-btn">Entrer</div><div class="creer-liste-btn-suppr creer-btn">Supprimer</div></td>') + '</tr>');
61
-        $('#creerListeTab').prepend(tr);
62
-        tr.hide().fadeIn();
63
-        menuList[key] = val;
64
-      }
65
-    }
66
-
67
-    // Parties/Joueurs supprimes ?
68
-    for(var key in menuList) {
69
-      if( !data['liste'][key] ) {
70
-        $('#creerListeItem' + key).fadeOut();
71
-        menuList[key] = false;
72
-      }
73
-    }
74
-
75
-    if(data['mode'] == 's') {
76
-      if( dataListeTaille > 1 )
77
-        $('#creerGo').show();
78
-      else
79
-        $('#creerGo').hide();
80
-    }
81
-  }
82
-
83
-  function refresh() {
84
-    $.get('backend/creer.php?p=' + scPartieId + '&j=' + scJoueurId)
85
-      .done(function(data, text, jqxhr) {
86
-        refreshScreen(  JSON.parse(jqxhr.responseText) );
87
-      })
88
-      .fail(function(jqxhr){
89
-//        alert(jqxhr.responseText);
90
-      })
91
-      .always(function(){
92
-        refreshTimer = setTimeout(refresh, 1000);
93
-      });
94
-  }
95
-
96
-  refresh();
97
-  var refreshTimer;
98
-
99
-
100
-  function creerSwitchTo(id) {
101
-    if(scPartieId > 0)
102
-      scJoueurId = id;
103
-    else
104
-      scPartieId = id;
105
-
106
-    clearTimeout(refreshTimer);
107
-    refresh();
108
-  }
109
-
110
-  $('#creerTitre').on('click', '.creer-titre-retour', function(e) {
111
-    if(scJoueurId > 0) {
112
-      var tempJ = scJoueurId;
113
-      scJoueurId = 0;
114
-      $.get('backend/creer.php?p=' + scPartieId + '&j=' + tempJ + '&out=1')
115
-        .done(function(data, text, jqxhr) {
116
-
117
-        })
118
-        .fail(function(jqxhr){
119
-  //        alert(jqxhr.responseText);
120
-        })
121
-        .always(function(){
122
-          clearTimeout(refreshTimer);
123
-          refresh();
124
-        });
125
-    }
126
-    else {
127
-      scPartieId = 0;
128
-      creerSwitchTo(0);
129
-    }
130
-  });
131
-
132
-  $('#creerListeTab').on('click', '.creer-liste-btn-entrer', function(e) {
133
-    e.preventDefault();
134
-    var id = $(this).parents('tr').attr('id').substring('creerListeItem'.length);
135
-    creerSwitchTo(id);
136
-  });
137
-
138
-  $('#creerListeTab').on('click', '.creer-liste-btn-suppr', function(e) {
139
-    e.preventDefault();
140
-    var id = $(this).parents('tr').attr('id').substring('creerListeItem'.length);
141
-    $(this).parents('td').empty();
142
-    $(this).parents('tr').fadeOut();
143
-    menuList[id] = false;
144
-    $.get('backend/creer.php?p=' + scPartieId + '&suppr=' + id)
145
-      .done(function(data, text, jqxhr) {
146
-
147
-      })
148
-      .fail(function(jqxhr){
149
-//        alert(jqxhr.responseText);
150
-      })
151
-      .always(function(){
152
-
153
-      });
154
-  });
155
-
156
-  $('#creerGo .creer-go-btn').on('click', function(e) {
157
-    e.preventDefault();
158
-    $('#creerGo').fadeOut();
159
-
160
-    $.get('backend/creer.php?p=' + scPartieId + '&j=' + scJoueurId + '&go=1')
161
-      .done(function(data, text, jqxhr) {
162
-
163
-      })
164
-      .fail(function(jqxhr){
165
-//        alert(jqxhr.responseText);
166
-      })
167
-      .always(function(){
168
-        clearTimeout(refreshTimer);
169
-        refresh();
170
-      });
171
-  });
172
-
173
-  $('#creerForm').on('submit', function(e) {
174
-    e.preventDefault();
175
-    if($('#creerForm .creer-form-input').val().length < 2) return;
176
-    var $form = $(this);
177
-
178
-    $form.hide();
179
-
180
-    $.post('backend/creer.php?p=' + scPartieId, $form.serializeArray())
181
-      .done(function(data, text, jqxhr) {
182
-        creerSwitchTo( jqxhr.responseText );
183
-        $('#creerForm .creer-form-input').val('');
184
-      })
185
-      .fail(function(jqxhr){
186
-//        alert(jqxhr.responseText);
187
-      })
188
-      .always(function(){
189
-        $form.show();
190
-      });
191
-  });
192
-
193
-
194
-});
195
-})(jQuery);
Browse code

Ajout de la salle d'attente

schardon authored on 23/04/2020 14:33:40
Showing 1 changed files
... ...
@@ -2,36 +2,62 @@
2 2
 $(document).ready(function() {
3 3
 
4 4
   var menuList = [];
5
-  var scPartieId = 0;
5
+  var scPartieId = scInput_PartieId;
6
+  var scJoueurId = scInput_JoueurId;
6 7
   var menuMode = '';
7 8
 
8 9
   function refreshScreen(data) {
10
+    if(data['mode'] == 'g') {
11
+      if(scJoueurId > 0)
12
+        window.location.href = 'index.php?j=' + scJoueurId;
13
+      else
14
+        window.location.href = 'index.php';
15
+      return;
16
+    }
17
+
9 18
     if(data['mode'] != menuMode) {
10 19
       menuMode = data['mode'];
11 20
       if(menuMode == 'p') {
12
-        $('#creerTitre').html('Karuba - Choisir une partie');
21
+        $('#creerTitre').html(scInput_JeuNom.toUpperCase() + ' - Choisir une partie');
22
+        $('#creerTitre').removeClass('creer-titre-attente');
13 23
         $('#creerTitre').removeClass('creer-titre-joueur');
14 24
         $('#creerTitre').addClass('creer-titre-partie');
25
+        $('#creerForm').show();
26
+        $('#creerGo').hide();
15 27
         scPartieId = 0;
28
+        scJoueurId = 0;
16 29
       }
17 30
       if(menuMode == 'j') {
18
-        $('#creerTitre').html('<div class="creer-titre-retour creer-btn">&lt;&lt;</div>Karuba - Partie : ' + data['nom'] + ' - Choisir un joueur');
31
+        $('#creerTitre').html('<div class="creer-titre-retour creer-btn">&lt;&lt;</div>' + scInput_JeuNom.toUpperCase() + ' [ Partie : ' + data['partie'] + ' ] Choisir un joueur');
32
+        $('#creerTitre').removeClass('creer-titre-attente');
19 33
         $('#creerTitre').removeClass('creer-titre-partie');
20 34
         $('#creerTitre').addClass('creer-titre-joueur');
35
+        $('#creerForm').show();
36
+        $('#creerGo').hide();
37
+        scJoueurId = 0;
38
+      }
39
+      if(menuMode == 's') {
40
+        $('#creerTitre').html('<div class="creer-titre-retour creer-btn">&lt;&lt;</div>' + scInput_JeuNom.toUpperCase() + ' [ Partie : ' + data['partie'] + ' ] [ Joueur : ' + data['joueur'] + " ] Salle d'attente");
41
+        $('#creerTitre').removeClass('creer-titre-partie');
42
+        $('#creerTitre').removeClass('creer-titre-joueur');
43
+        $('#creerTitre').addClass('creer-titre-attente');
44
+        $('#creerForm').hide();
21 45
       }
22 46
       $('#creerListeTab').empty();
23 47
       menuList = [];
24 48
     }
25 49
 
26 50
     // Parties/Joueurs ajoutes ou modifies ?
51
+    var dataListeTaille = 0;
27 52
     for(var key in data['liste']) {
53
+      dataListeTaille++;
28 54
       var val = data['liste'][key];
29 55
       if( menuList[key] ) {
30 56
         if( menuList[key] != val )
31 57
           $('#creerListeItem' + key + ' .creer-liste-nom').html( val );
32 58
       }
33 59
       else {
34
-        var tr = $('<tr id="creerListeItem' + key + '"><td class="creer-liste-nom">' + val + '</td><td class="creer-liste-btn"><div class="creer-liste-btn-entrer creer-btn">Entrer</div><div class="creer-liste-btn-suppr creer-btn">Supprimer</div></td></tr>');
60
+        var tr = $('<tr id="creerListeItem' + key + '"><td class="creer-liste-nom">' + val + '</td>' + (scJoueurId > 0 ? '' : '<td class="creer-liste-btn"><div class="creer-liste-btn-entrer creer-btn">Entrer</div><div class="creer-liste-btn-suppr creer-btn">Supprimer</div></td>') + '</tr>');
35 61
         $('#creerListeTab').prepend(tr);
36 62
         tr.hide().fadeIn();
37 63
         menuList[key] = val;
... ...
@@ -45,10 +71,17 @@ $(document).ready(function() {
45 71
         menuList[key] = false;
46 72
       }
47 73
     }
74
+
75
+    if(data['mode'] == 's') {
76
+      if( dataListeTaille > 1 )
77
+        $('#creerGo').show();
78
+      else
79
+        $('#creerGo').hide();
80
+    }
48 81
   }
49 82
 
50 83
   function refresh() {
51
-    $.get('backend/creer.php?p=' + scPartieId)
84
+    $.get('backend/creer.php?p=' + scPartieId + '&j=' + scJoueurId)
52 85
       .done(function(data, text, jqxhr) {
53 86
         refreshScreen(  JSON.parse(jqxhr.responseText) );
54 87
       })
... ...
@@ -66,17 +99,34 @@ $(document).ready(function() {
66 99
 
67 100
   function creerSwitchTo(id) {
68 101
     if(scPartieId > 0)
69
-      window.location.href = 'index.php?j=' + id;
70
-    else {
102
+      scJoueurId = id;
103
+    else
71 104
       scPartieId = id;
72
-      clearTimeout(refreshTimer);
73
-      refresh();
74
-    }
105
+
106
+    clearTimeout(refreshTimer);
107
+    refresh();
75 108
   }
76 109
 
77 110
   $('#creerTitre').on('click', '.creer-titre-retour', function(e) {
78
-    scPartieId = 0;
79
-    creerSwitchTo(0);
111
+    if(scJoueurId > 0) {
112
+      var tempJ = scJoueurId;
113
+      scJoueurId = 0;
114
+      $.get('backend/creer.php?p=' + scPartieId + '&j=' + tempJ + '&out=1')
115
+        .done(function(data, text, jqxhr) {
116
+
117
+        })
118
+        .fail(function(jqxhr){
119
+  //        alert(jqxhr.responseText);
120
+        })
121
+        .always(function(){
122
+          clearTimeout(refreshTimer);
123
+          refresh();
124
+        });
125
+    }
126
+    else {
127
+      scPartieId = 0;
128
+      creerSwitchTo(0);
129
+    }
80 130
   });
81 131
 
82 132
   $('#creerListeTab').on('click', '.creer-liste-btn-entrer', function(e) {
... ...
@@ -88,7 +138,7 @@ $(document).ready(function() {
88 138
   $('#creerListeTab').on('click', '.creer-liste-btn-suppr', function(e) {
89 139
     e.preventDefault();
90 140
     var id = $(this).parents('tr').attr('id').substring('creerListeItem'.length);
91
-//    $(this).parents('td').empty();
141
+    $(this).parents('td').empty();
92 142
     $(this).parents('tr').fadeOut();
93 143
     menuList[id] = false;
94 144
     $.get('backend/creer.php?p=' + scPartieId + '&suppr=' + id)
... ...
@@ -103,6 +153,22 @@ $(document).ready(function() {
103 153
       });
104 154
   });
105 155
 
156
+  $('#creerGo .creer-go-btn').on('click', function(e) {
157
+    e.preventDefault();
158
+    $('#creerGo').fadeOut();
159
+
160
+    $.get('backend/creer.php?p=' + scPartieId + '&j=' + scJoueurId + '&go=1')
161
+      .done(function(data, text, jqxhr) {
162
+
163
+      })
164
+      .fail(function(jqxhr){
165
+//        alert(jqxhr.responseText);
166
+      })
167
+      .always(function(){
168
+        clearTimeout(refreshTimer);
169
+        refresh();
170
+      });
171
+  });
106 172
 
107 173
   $('#creerForm').on('submit', function(e) {
108 174
     e.preventDefault();
Browse code

Gestion du choix de la partie et du joueur

schardon authored on 22/04/2020 21:35:22
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,129 @@
1
+(function($) {
2
+$(document).ready(function() {
3
+
4
+  var menuList = [];
5
+  var scPartieId = 0;
6
+  var menuMode = '';
7
+
8
+  function refreshScreen(data) {
9
+    if(data['mode'] != menuMode) {
10
+      menuMode = data['mode'];
11
+      if(menuMode == 'p') {
12
+        $('#creerTitre').html('Karuba - Choisir une partie');
13
+        $('#creerTitre').removeClass('creer-titre-joueur');
14
+        $('#creerTitre').addClass('creer-titre-partie');
15
+        scPartieId = 0;
16
+      }
17
+      if(menuMode == 'j') {
18
+        $('#creerTitre').html('<div class="creer-titre-retour creer-btn">&lt;&lt;</div>Karuba - Partie : ' + data['nom'] + ' - Choisir un joueur');
19
+        $('#creerTitre').removeClass('creer-titre-partie');
20
+        $('#creerTitre').addClass('creer-titre-joueur');
21
+      }
22
+      $('#creerListeTab').empty();
23
+      menuList = [];
24
+    }
25
+
26
+    // Parties/Joueurs ajoutes ou modifies ?
27
+    for(var key in data['liste']) {
28
+      var val = data['liste'][key];
29
+      if( menuList[key] ) {
30
+        if( menuList[key] != val )
31
+          $('#creerListeItem' + key + ' .creer-liste-nom').html( val );
32
+      }
33
+      else {
34
+        var tr = $('<tr id="creerListeItem' + key + '"><td class="creer-liste-nom">' + val + '</td><td class="creer-liste-btn"><div class="creer-liste-btn-entrer creer-btn">Entrer</div><div class="creer-liste-btn-suppr creer-btn">Supprimer</div></td></tr>');
35
+        $('#creerListeTab').prepend(tr);
36
+        tr.hide().fadeIn();
37
+        menuList[key] = val;
38
+      }
39
+    }
40
+
41
+    // Parties/Joueurs supprimes ?
42
+    for(var key in menuList) {
43
+      if( !data['liste'][key] ) {
44
+        $('#creerListeItem' + key).fadeOut();
45
+        menuList[key] = false;
46
+      }
47
+    }
48
+  }
49
+
50
+  function refresh() {
51
+    $.get('backend/creer.php?p=' + scPartieId)
52
+      .done(function(data, text, jqxhr) {
53
+        refreshScreen(  JSON.parse(jqxhr.responseText) );
54
+      })
55
+      .fail(function(jqxhr){
56
+//        alert(jqxhr.responseText);
57
+      })
58
+      .always(function(){
59
+        refreshTimer = setTimeout(refresh, 1000);
60
+      });
61
+  }
62
+
63
+  refresh();
64
+  var refreshTimer;
65
+
66
+
67
+  function creerSwitchTo(id) {
68
+    if(scPartieId > 0)
69
+      window.location.href = 'index.php?j=' + id;
70
+    else {
71
+      scPartieId = id;
72
+      clearTimeout(refreshTimer);
73
+      refresh();
74
+    }
75
+  }
76
+
77
+  $('#creerTitre').on('click', '.creer-titre-retour', function(e) {
78
+    scPartieId = 0;
79
+    creerSwitchTo(0);
80
+  });
81
+
82
+  $('#creerListeTab').on('click', '.creer-liste-btn-entrer', function(e) {
83
+    e.preventDefault();
84
+    var id = $(this).parents('tr').attr('id').substring('creerListeItem'.length);
85
+    creerSwitchTo(id);
86
+  });
87
+
88
+  $('#creerListeTab').on('click', '.creer-liste-btn-suppr', function(e) {
89
+    e.preventDefault();
90
+    var id = $(this).parents('tr').attr('id').substring('creerListeItem'.length);
91
+//    $(this).parents('td').empty();
92
+    $(this).parents('tr').fadeOut();
93
+    menuList[id] = false;
94
+    $.get('backend/creer.php?p=' + scPartieId + '&suppr=' + id)
95
+      .done(function(data, text, jqxhr) {
96
+
97
+      })
98
+      .fail(function(jqxhr){
99
+//        alert(jqxhr.responseText);
100
+      })
101
+      .always(function(){
102
+
103
+      });
104
+  });
105
+
106
+
107
+  $('#creerForm').on('submit', function(e) {
108
+    e.preventDefault();
109
+    if($('#creerForm .creer-form-input').val().length < 2) return;
110
+    var $form = $(this);
111
+
112
+    $form.hide();
113
+
114
+    $.post('backend/creer.php?p=' + scPartieId, $form.serializeArray())
115
+      .done(function(data, text, jqxhr) {
116
+        creerSwitchTo( jqxhr.responseText );
117
+        $('#creerForm .creer-form-input').val('');
118
+      })
119
+      .fail(function(jqxhr){
120
+//        alert(jqxhr.responseText);
121
+      })
122
+      .always(function(){
123
+        $form.show();
124
+      });
125
+  });
126
+
127
+
128
+});
129
+})(jQuery);