Bläddra i källkod

Reset en ajax

Loquicom 6 år sedan
förälder
incheckning
c5e84dd77e
1 ändrade filer med 28 tillägg och 6 borttagningar
  1. 28 6
      js/script.js

+ 28 - 6
js/script.js

@@ -1,3 +1,5 @@
+var first = true;
+
 $(document).ready(function(){
 
 	//Ini Materialize
@@ -30,17 +32,21 @@ $(document).ready(function(){
 
     //Rechargement
     $("#reload").on('click', function(){
-    	//location.href = './';
-        reload_score();
+        if(first){
+            reload(false);
+            first = false;
+        } else {
+            reload(true);
+        }   
     }).click();
     //Recharge toutes les minutes
     setTimeout(function(){
-    	$("#reload").click();
-    }, 60 * 1000);
+    	reload(false);
+    }, 30 * 1000);
 
     //Reset
     $('#reset').on('click', function(){
-    	location.href = './?reset';
+    	reset_score();
     });
 
     //Quit
@@ -56,10 +62,26 @@ $(document).ready(function(){
 
 });
 
-function reload_score(){
+function reload(msg){
     $.post("ajx/score.php", null, function(data){
         if(data.etat == 'ok'){
             $("#tbody").html(data.html);
+            $("#save-name").html(data.savename);
+            if(msg){
+                float_message(message_conf("Page rechargée"));
+            }
+            M.AutoInit();
+        }
+    }, 'json');
+}
+
+function reset_score(){
+    $.post("ajx/reset.php", null, function(data){
+        if(data.etat == 'ok'){
+            $("#tbody").html('');
+            $("#save-name").html('<option value="" disabled selected>Selectionnez un lanceur</option>');
+            float_message(message_conf("Session reset"));
+            M.AutoInit();
         }
     }, 'json');
 }