Browse Source

remplace tstamp par guid

olivier.massot 8 years ago
parent
commit
d7288c951f
2 changed files with 22 additions and 23 deletions
  1. 0 1
      MobiParc/index.html
  2. 22 22
      MobiParc/js/mobiparc.js

+ 0 - 1
MobiParc/index.html

@@ -98,7 +98,6 @@
                     </picture><h3>
                         Saisie d'activité
                     </h3>
-
                 </div>
             </a>
         </div>

+ 22 - 22
MobiParc/js/mobiparc.js

@@ -71,7 +71,7 @@ var load = function () {
         // Cree les stockages necessaires si ceux ci sont manquants
         request.onupgradeneeded = function () {
             var db = request.result;
-            db.createObjectStore(model, { keyPath: "tstamp" });
+            db.createObjectStore(model, { keyPath: "guid" });
             console.log("[DB] Cree '" + model + "'");
         };
 
@@ -103,27 +103,25 @@ var load = function () {
             // Call our function to get the form data.
             var data = formToJSON(form.elements);
 
-            // Demo only: print the form data onscreen as a formatted JSON object.
-            var dataContainer = document.getElementsByClassName('results-display')[0];
+            //// DEMO ONLY: print the form data onscreen as a formatted JSON object.
+            //var dataContainer = document.getElementsByClassName('results-display')[0];
+            //// Use `JSON.stringify()` to make the output valid, human-readable JSON.
+            //dataContainer.textContent = JSON.stringify(data, null, "  ");
 
-            // Use `JSON.stringify()` to make the output valid, human-readable JSON.
-            dataContainer.textContent = JSON.stringify(data, null, "  ");
-
-            if ($(form).hasClass("activite")) {
-                data.tstamp = Date.now();
-                data.user = localStorage.hasOwnProperty("params") ? JSON.parse(localStorage.getItem("params")).user : "(unknown)";
-
-                txs = db.transaction(model, "readwrite");
-                store = txs.objectStore(model);
-                store.put(data);
+            data.guid = createGuid();
+            //data.tstamp = Date.now();
+            data.user = localStorage.hasOwnProperty("params") ? JSON.parse(localStorage.getItem("params")).user : "(unknown)";
+            
+            txs = db.transaction(model, "readwrite");
+            store = txs.objectStore(model);
+            store.put(data);
                 
-                store.getAll().onsuccess = function (event) {
-                    $("#main").empty();
-                    var data = { data: event.target.result };
-                    var template = Handlebars.compile(section.html());
-                    $("#main").html(template(data));
-                };
-            }
+            store.getAll().onsuccess = function (event) {
+                $("#main").empty();
+                var data = { data: event.target.result };
+                var template = Handlebars.compile(section.html());
+                $("#main").html(template(data));
+            };
         });
 
         // Gere le clic sur un bouton supprimer
@@ -149,7 +147,9 @@ var load = function () {
 
     }
     else {
-        $("#main").html($(section).html());
+        //template = Handlebars.compile(section.html());
+        //$("#main").html(template({}));
+        $("#main").html(section.html());
     }
 
 }
@@ -230,7 +230,7 @@ $(".data-sync").on("click", function () {
         var cursor = event.target.result;
         if (cursor) {
             cursor.value.model = "activites";
-            var id = cursor.value.tstamp;
+            var id = cursor.value.guid;
             var posting = $.post("/api/mobiparc", { data: JSON.stringify(cursor.value) });
 
             // Put the results in a div