|
|
@@ -1,12 +1,5 @@
|
|
|
|
|
|
-// JS s'execute: Retire l'avertissement 'Javascript est requis'
|
|
|
-document.body.classList.remove("nojs");
|
|
|
-
|
|
|
-if ('serviceWorker' in navigator) {
|
|
|
- console.log("[ServiceWorker] Installe");
|
|
|
- navigator.serviceWorker.register('../sw.js');
|
|
|
-}
|
|
|
-
|
|
|
+//### Helpers handlebars personnalisés
|
|
|
Handlebars.registerHelper('lower', function (options) {
|
|
|
return options.fn(this).toLowerCase();
|
|
|
});
|
|
|
@@ -17,7 +10,7 @@ Handlebars.registerHelper('repuri', function (find, replace, options) {
|
|
|
|
|
|
Handlebars.registerHelper('todate', function (options) {
|
|
|
var d = options.fn(this);
|
|
|
- var dt = new Date(Number.parseInt(d)*1);
|
|
|
+ var dt = new Date(Number.parseInt(d) * 1);
|
|
|
return dt.toLocaleString();
|
|
|
});
|
|
|
|
|
|
@@ -26,72 +19,83 @@ Handlebars.registerHelper('timestamp', function (options) {
|
|
|
});
|
|
|
|
|
|
Handlebars.registerHelper('if_eq', function (a, opts) {
|
|
|
- var b = localStorage.hasOwnProperty("contact") ? localStorage.getItem("contact"): "";
|
|
|
+ var b = localStorage.hasOwnProperty("contact") ? localStorage.getItem("contact") : "";
|
|
|
if (a === b) // Or === depending on your needs
|
|
|
return opts.fn(this);
|
|
|
else
|
|
|
return opts.inverse(this);
|
|
|
});
|
|
|
|
|
|
-// Main <div>
|
|
|
+// ### References
|
|
|
+
|
|
|
+// ref a la section main
|
|
|
var main = document.getElementsByClassName('main')[0];
|
|
|
|
|
|
-// ???
|
|
|
-var template = Handlebars.compile(document.getElementById(getUrldest()).innerHTML);
|
|
|
|
|
|
+//### Initialisation
|
|
|
|
|
|
-function createGuid() {
|
|
|
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
|
- var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
|
- return v.toString(16);
|
|
|
- });
|
|
|
+// JS s'execute: Retire l'avertissement 'Javascript est requis'
|
|
|
+document.body.classList.remove("nojs");
|
|
|
+
|
|
|
+// Installe le service worker
|
|
|
+if ('serviceWorker' in navigator) {
|
|
|
+ console.log("[ServiceWorker] Installe");
|
|
|
+ navigator.serviceWorker.register('../sw.js');
|
|
|
}
|
|
|
-function uuidv4() {
|
|
|
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
|
- (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
|
|
- )
|
|
|
+
|
|
|
+// Nettoie la section main
|
|
|
+$(".main").empty();
|
|
|
+
|
|
|
+// Open (or create) the database
|
|
|
+var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
|
|
|
+var open = indexedDB.open("MobiParc", 3);
|
|
|
+
|
|
|
+// Create the schema
|
|
|
+open.onupgradeneeded = function () {
|
|
|
+ var db = open.result;
|
|
|
+ var store = db.createObjectStore("activites", { keyPath: "tstamp" });
|
|
|
+};
|
|
|
+
|
|
|
+console.log(">"+window.location.hash.slice(1));
|
|
|
+
|
|
|
+// Obtient l'id de la section a afficher en fonction de l'url
|
|
|
+function getSectionId() {
|
|
|
+ return (window.location.hash.slice(1).length > 0 ? window.location.hash.slice(1) : "index");
|
|
|
+};
|
|
|
+// Memorise la section en cours
|
|
|
+var sectionId = getSectionId();
|
|
|
+
|
|
|
+// compile la page entiere avec handlebars
|
|
|
+var template = Handlebars.compile(document.getElementById(sectionId).innerHTML);
|
|
|
+
|
|
|
+// Essaie de peupler la page en cours avec les données de la base (s'il y en a a afficher)
|
|
|
+try {
|
|
|
+ var db = open.result;
|
|
|
+ var txs = db.transaction(sectionId, "readonly");
|
|
|
+ var stores = txs.objectStore(sectionId);
|
|
|
+ console.log("Got all " + sectionId + ": ");
|
|
|
+ stores.getAll().onsuccess = function (event) {
|
|
|
+ var data = { data: event.target.result };
|
|
|
+ main.innerHTML = template(data);
|
|
|
+ };
|
|
|
}
|
|
|
-
|
|
|
-var contacts;
|
|
|
-function callback(response) {
|
|
|
- contacts = response;
|
|
|
- // localStorage.setItem("contacts", JSON.stringify(response))
|
|
|
+catch (e) {
|
|
|
+ main.innerHTML = template({});
|
|
|
}
|
|
|
|
|
|
-//$.ajax({
|
|
|
-// url: "data/contacts.json", success: function (result) {
|
|
|
-// callback(result);
|
|
|
-// }
|
|
|
-//});
|
|
|
-
|
|
|
-//try {
|
|
|
-// getLocation();
|
|
|
-//}
|
|
|
-//catch (e) {
|
|
|
-// console.log("error loc");
|
|
|
-//}
|
|
|
-
|
|
|
-Date.prototype.getWeekNumber = function () {
|
|
|
- var d = new Date(Date.UTC(this.getFullYear(), this.getMonth(), this.getDate()));
|
|
|
- var dayNum = d.getUTCDay() || 7;
|
|
|
- d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
|
|
- var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
|
|
- return Math.ceil((((d - yearStart) / 86400000) + 1) / 7)
|
|
|
-};
|
|
|
+//######### MAIN ###############
|
|
|
|
|
|
+// ### Interactions
|
|
|
+
|
|
|
+// Affiche ou masque la sidebar
|
|
|
$('.bt-menu').on('click', 'svg', function () {
|
|
|
$(this).closest('nav').find('div:not(:first)').toggleClass('sidebar');
|
|
|
});
|
|
|
-
|
|
|
$(document).on('click', '.sidebar', function () {
|
|
|
$(this).closest('nav').find('div:not(:first)').toggleClass('sidebar');
|
|
|
});
|
|
|
|
|
|
-//param first
|
|
|
-
|
|
|
-//suppression
|
|
|
-
|
|
|
-//gestion offline
|
|
|
+// Affiche ou masque le bouton de sync
|
|
|
if (navigator.onLine) {
|
|
|
$(".data-sync").removeAttr("disabled");
|
|
|
}
|
|
|
@@ -102,43 +106,67 @@ else {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-//syncro
|
|
|
-$(".data-sync").on("click", function () {
|
|
|
+/* retour haut de page*/
|
|
|
+window.onscroll = function (ev) {
|
|
|
+ document.getElementById("cRetour").className = (window.pageYOffset > 100) ? "cVisible" : "cInvisible";
|
|
|
+};
|
|
|
|
|
|
- var db = open.result;
|
|
|
- var txs = db.transaction("activite", "readonly");
|
|
|
- var stores = txs.objectStore("activite");
|
|
|
- console.log("post all : ");
|
|
|
- stores.openCursor().onsuccess = function (event) {
|
|
|
- //var data = { data: event.target.result };
|
|
|
- var cursor = event.target.result;
|
|
|
- if (cursor) {
|
|
|
- //cursor.model = "anomaly";
|
|
|
+$('#cRetour').on('click', function () {
|
|
|
+ $('html, body').animate({ scrollTop: 0 }, 200);
|
|
|
+});
|
|
|
|
|
|
- cursor.value.model = "activite";
|
|
|
- var id = cursor.value.tstamp;
|
|
|
- var posting = $.post("/api/mobiparc", { data: JSON.stringify(cursor.value) });
|
|
|
|
|
|
- // Put the results in a div
|
|
|
- posting.done(function (data) {
|
|
|
- if (data == 'ole') {
|
|
|
+// Gere l'affichage des classes modales
|
|
|
+$(".modal-open, .modal-background, .modal-close").click(function () {
|
|
|
+ $(".modal-content,.modal-background").toggleClass("active");
|
|
|
+ if ($(this).hasClass("modal-close")) location.reload();
|
|
|
+});
|
|
|
+
|
|
|
+// Gere le clic sur un bouton supprimer
|
|
|
+$("body").on("click", ".data-del", function (event) {
|
|
|
+
|
|
|
+ // console.log($(this).data("id") + " " + $(this).data("type"));
|
|
|
+ var id = $(this).data("id");
|
|
|
+ var datatype = $(this).data("type");
|
|
|
+ //console.log(id + " " + datatype);
|
|
|
+
|
|
|
+ var r = confirm("Supprimer cet élément!");
|
|
|
+ if (r == true) {
|
|
|
+
|
|
|
+ var db = open.result;
|
|
|
+ var tx = db.transaction(datatype, "readwrite");
|
|
|
+ var store = tx.objectStore(datatype);
|
|
|
+
|
|
|
+ store.delete(id).onsuccess = function (evt) {
|
|
|
+ // console.log(id + " " + datatype);
|
|
|
+ location.reload();
|
|
|
+ };
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+// Gere le clic sur un bouton supprimer (bis?)
|
|
|
+$("body").on("click", ".del", function (event) {
|
|
|
+
|
|
|
+ var del = $(this);
|
|
|
+ if (confirm("Supprimer la selection!") == true) {
|
|
|
+
|
|
|
+ $(del).prop("disabled", true);
|
|
|
+
|
|
|
+ $(".ui-selected").each(function () {
|
|
|
+ var elt = $(this);
|
|
|
+ var id = $(elt).data("id");
|
|
|
+ var datatype = $(elt).data("type");
|
|
|
+ var db = open.result;
|
|
|
+ var tx = db.transaction(datatype, "readwrite");
|
|
|
+ var store = tx.objectStore(datatype);
|
|
|
+ store.delete(id).onsuccess = function (evt) {
|
|
|
+ $(elt).remove();
|
|
|
+ };
|
|
|
+ });
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
- var tx = db.transaction("activite", "readwrite");
|
|
|
- var store = tx.objectStore("activite");
|
|
|
- store.delete(id).onsuccess = function (evt) {
|
|
|
- $('.sync-result').append("Sync ok activite : " + id + "<br>");
|
|
|
- };
|
|
|
- }
|
|
|
- });
|
|
|
- cursor.continue();
|
|
|
- }
|
|
|
- else {
|
|
|
- console.log("end activite");
|
|
|
- }
|
|
|
|
|
|
- };
|
|
|
-})
|
|
|
-
|
|
|
// Recharge dynamiquement le contenu HTML à chaque changement d'url
|
|
|
$(window).on('hashchange', function () {
|
|
|
|
|
|
@@ -146,25 +174,16 @@ $(window).on('hashchange', function () {
|
|
|
|
|
|
$('html, body').animate({ scrollTop: 0 }, 200);
|
|
|
|
|
|
- var urldest = getUrldest();
|
|
|
-
|
|
|
- template = Handlebars.compile(document.getElementById(urldest).innerHTML);
|
|
|
+ template = Handlebars.compile(document.getElementById(sectionId).innerHTML);
|
|
|
|
|
|
- //try {
|
|
|
- // getLocation();
|
|
|
- //}
|
|
|
- //catch (e) {
|
|
|
- // console.log("error loc");
|
|
|
- //}
|
|
|
-
|
|
|
- if (urldest != 'activite') {
|
|
|
+ if (sectionId != 'activites') {
|
|
|
|
|
|
$(".main").empty();
|
|
|
try {
|
|
|
var db = open.result;
|
|
|
- var txs = db.transaction(urldest, "readonly");
|
|
|
- var stores = txs.objectStore(urldest);
|
|
|
- console.log("Got all " + urldest + ": ");
|
|
|
+ var txs = db.transaction(sectionId, "readonly");
|
|
|
+ var stores = txs.objectStore(sectionId);
|
|
|
+ console.log("Got all " + sectionId + ": ");
|
|
|
stores.getAll().onsuccess = function (event) {
|
|
|
var data = { data: event.target.result };
|
|
|
|
|
|
@@ -177,122 +196,141 @@ $(window).on('hashchange', function () {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-var imgdata;
|
|
|
|
|
|
-$("body").on("click", ".data-del", function (event) {
|
|
|
|
|
|
- // console.log($(this).data("id") + " " + $(this).data("type"));
|
|
|
- var id = $(this).data("id");
|
|
|
- var datatype = $(this).data("type");
|
|
|
- //console.log(id + " " + datatype);
|
|
|
+// Observeur: suit les modifications apportees a la section main
|
|
|
+var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
|
|
|
+var mainsection = document.querySelector("section.main");
|
|
|
+var observer = new MutationObserver(function (mutations) {
|
|
|
+ //gestion des mise element selectable
|
|
|
+ $(".selectable > tbody").selectable({
|
|
|
+ filter: "tr",
|
|
|
+ stop: function () {
|
|
|
+ $(".del").removeAttr("disabled");
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- var r = confirm("Supprimer cet élément!");
|
|
|
- if (r == true) {
|
|
|
+ //document.getElementsByClassName('results-display')[0].innerHTML = null;
|
|
|
|
|
|
- var db = open.result;
|
|
|
- var tx = db.transaction(datatype, "readwrite");
|
|
|
- var store = tx.objectStore(datatype);
|
|
|
+ // intercepte la soumision de formulaires
|
|
|
+ if ($(".main").find(".data-form").length) {
|
|
|
+ form = $(".main").find(".data-form")[0];
|
|
|
+ form.addEventListener('submit', handleFormSubmit);
|
|
|
+ console.log("submit handled");
|
|
|
+ }
|
|
|
|
|
|
- store.delete(id).onsuccess = function (evt) {
|
|
|
- // console.log(id + " " + datatype);
|
|
|
- location.reload();
|
|
|
- };
|
|
|
- }
|
|
|
});
|
|
|
|
|
|
-$("body").on("click", ".send-message", function (event) {
|
|
|
- event.preventDefault();
|
|
|
- var form = $(this).closest("form");
|
|
|
+observer.observe(mainsection, { attributes: true, childList: true, subtree: true });
|
|
|
|
|
|
- function getLocation() {
|
|
|
- if (navigator.geolocation) {
|
|
|
- navigator.geolocation.getCurrentPosition(showPosition);
|
|
|
- } else {
|
|
|
- return "Geolocation is not supported by this browser.";
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- function showPosition(position) {
|
|
|
- $("input[name='lat']:hidden").val(position.coords.latitude);
|
|
|
- $("input[name='lng']:hidden").val(position.coords.longitude);
|
|
|
- }
|
|
|
+// Intercepte le submit de données
|
|
|
+var form;
|
|
|
+var handleFormSubmit = function handleFormSubmit(event) {
|
|
|
+ console.log("handle submit");
|
|
|
|
|
|
- var pp = getLocation();
|
|
|
+ // Stop the form from submitting since we’re handling that with AJAX.
|
|
|
+ event.preventDefault();
|
|
|
|
|
|
- var data = form.serializeArray().reduce(function (a, x) { a[x.name] = x.value; return a; }, { tstamp: Date.now()});
|
|
|
+ // Call our function to get the form data.
|
|
|
+ var data = formToJSON(form.elements);
|
|
|
|
|
|
- var request = indexedDB.open("Contenu", 3);
|
|
|
+ // Demo only: print the form data onscreen as a formatted JSON object.
|
|
|
+ var dataContainer = document.getElementsByClassName('results-display')[0];
|
|
|
|
|
|
- request.onerror = function () {
|
|
|
- form.find(".send-result").html("Une erreur c'est produite.");
|
|
|
- };
|
|
|
+ // Use `JSON.stringify()` to make the output valid, human-readable JSON.
|
|
|
+ dataContainer.textContent = JSON.stringify(data, null, " ");
|
|
|
|
|
|
- request.onsuccess = function () {
|
|
|
- var db = request.result;
|
|
|
- var tx = db.transaction("emails", "readwrite");
|
|
|
- var store = tx.objectStore("emails");
|
|
|
- store.put(data);
|
|
|
- form.find(".send-result").html("Votre message est pris en compte.");
|
|
|
- }
|
|
|
-});
|
|
|
+ if ($(form).hasClass("activite")) {
|
|
|
+ data.tstamp = Date.now();
|
|
|
+ data.user = localStorage.hasOwnProperty("params") ? JSON.parse(localStorage.getItem("params")).user : "(unknown)";
|
|
|
+
|
|
|
+ var db = open.result;
|
|
|
+ var txs = db.transaction("activite", "readwrite");
|
|
|
+ var stores = txs.objectStore("activite");
|
|
|
+ stores.put(data);
|
|
|
|
|
|
-$(".modal-open, .modal-background, .modal-close").click(function () {
|
|
|
- console.log("modal");
|
|
|
- $(".modal-content,.modal-background").toggleClass("active");
|
|
|
- if ($(this).hasClass("modal-close")) location.reload();
|
|
|
-});
|
|
|
-
|
|
|
-/* retour haut de page*/
|
|
|
-window.onscroll = function (ev) {
|
|
|
- document.getElementById("cRetour").className = (window.pageYOffset > 100) ? "cVisible" : "cInvisible";
|
|
|
+ $(".main").empty();
|
|
|
+
|
|
|
+ stores.getAll().onsuccess = function (event) {
|
|
|
+ var data = { data: event.target.result };
|
|
|
+ var template = Handlebars.compile(document.getElementById("activites").innerHTML);
|
|
|
+ $(".main").html(template(data));
|
|
|
+ };
|
|
|
+ }
|
|
|
+ console.log(data);
|
|
|
};
|
|
|
|
|
|
-$('#cRetour').on('click', function () {
|
|
|
- $('html, body').animate({ scrollTop: 0 }, 200);
|
|
|
-});
|
|
|
|
|
|
-$(".main").empty();
|
|
|
-var urldest = getUrldest();
|
|
|
-try{
|
|
|
+// ### Synchronisation des données
|
|
|
+
|
|
|
+$(".data-sync").on("click", function () {
|
|
|
+
|
|
|
var db = open.result;
|
|
|
- var txs = db.transaction(urldest, "readonly");
|
|
|
- var stores = txs.objectStore(urldest);
|
|
|
- console.log("Got all " + urldest + ": ");
|
|
|
- stores.getAll().onsuccess = function (event) {
|
|
|
- var data = { data: event.target.result };
|
|
|
- main.innerHTML = template(data);
|
|
|
- };}
|
|
|
-catch (e) {
|
|
|
- main.innerHTML = template({});
|
|
|
-}
|
|
|
+ var txs = db.transaction("activite", "readonly");
|
|
|
+ var stores = txs.objectStore("activite");
|
|
|
+ console.log("post all : ");
|
|
|
+ stores.openCursor().onsuccess = function (event) {
|
|
|
+ //var data = { data: event.target.result };
|
|
|
+ var cursor = event.target.result;
|
|
|
+ if (cursor) {
|
|
|
+ //cursor.model = "anomaly";
|
|
|
|
|
|
-$("body").on("click", ".del", function (event) {
|
|
|
+ cursor.value.model = "activite";
|
|
|
+ var id = cursor.value.tstamp;
|
|
|
+ var posting = $.post("/api/mobiparc", { data: JSON.stringify(cursor.value) });
|
|
|
|
|
|
- var del = $(this);
|
|
|
- var r = confirm("Supprimer la selection!");
|
|
|
- if (r == true) {
|
|
|
+ // Put the results in a div
|
|
|
+ posting.done(function (data) {
|
|
|
+ if (data == 'ole') {
|
|
|
+
|
|
|
+ var tx = db.transaction("activite", "readwrite");
|
|
|
+ var store = tx.objectStore("activite");
|
|
|
+ store.delete(id).onsuccess = function (evt) {
|
|
|
+ $('.sync-result').append("Sync ok activite : " + id + "<br>");
|
|
|
+ };
|
|
|
+ }
|
|
|
+ });
|
|
|
+ cursor.continue();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log("end activite");
|
|
|
+ }
|
|
|
|
|
|
- $(del).prop("disabled",true);
|
|
|
+ };
|
|
|
+})
|
|
|
|
|
|
- $(".ui-selected").each(function () {
|
|
|
- var elt = $(this);
|
|
|
- var id = $(elt).data("id");
|
|
|
- var datatype = $(elt).data("type");
|
|
|
- //console.log(id + " " + datatype);
|
|
|
- var db = open.result;
|
|
|
- var tx = db.transaction(datatype, "readwrite");
|
|
|
- var store = tx.objectStore(datatype);
|
|
|
- store.delete(id).onsuccess = function (evt) {
|
|
|
- // console.log(id + " " + datatype);
|
|
|
- $(elt).remove();
|
|
|
|
|
|
- };
|
|
|
|
|
|
- });
|
|
|
+//###### TOOLBOX ######
|
|
|
+
|
|
|
+function createGuid() {
|
|
|
+ return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
|
+ (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
|
|
+ )
|
|
|
+}
|
|
|
|
|
|
+function getLocation() {
|
|
|
+ try {
|
|
|
+ if (navigator.geolocation) {
|
|
|
+ navigator.geolocation.getCurrentPosition(showPosition);
|
|
|
+ } else {
|
|
|
+ console.log("Geolocation is not supported by this browser.");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
}
|
|
|
-});
|
|
|
+ catch (e) {
|
|
|
+ console.log("Geolocation: error");
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+function showPosition(position) {
|
|
|
+ $("input[name='coordinates']").val(position.coords.latitude + "," + position.coords.longitude);
|
|
|
+ console.log(position.coords);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// ### Serialization
|
|
|
|
|
|
/**
|
|
|
* Checks that an element has a non-empty `name` and `value` property.
|
|
|
@@ -408,181 +446,4 @@ var formToJSON = function formToJSON(elements) {
|
|
|
|
|
|
return data;
|
|
|
}, {});
|
|
|
-};
|
|
|
-
|
|
|
-var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
|
|
|
-
|
|
|
-// Open (or create) the database
|
|
|
-var open = indexedDB.open("MobiParc", 3);
|
|
|
-
|
|
|
-// Create the schema
|
|
|
-open.onupgradeneeded = function () {
|
|
|
- var db = open.result;
|
|
|
- //creation anomalies
|
|
|
- var store = db.createObjectStore("activite", { keyPath: "tstamp" });
|
|
|
-};
|
|
|
-
|
|
|
-/**
|
|
|
- * A handler function to prevent default submission and run our custom script.
|
|
|
- * @param {Event} event the submit event triggered by the user
|
|
|
- * @return {void}
|
|
|
- */
|
|
|
-
|
|
|
-var form;
|
|
|
-
|
|
|
-var handleFormSubmit = function handleFormSubmit(event) {
|
|
|
-
|
|
|
- // Stop the form from submitting since we’re handling that with AJAX.
|
|
|
- event.preventDefault();
|
|
|
-
|
|
|
- // 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];
|
|
|
-
|
|
|
- // Use `JSON.stringify()` to make the output valid, human-readable JSON.
|
|
|
- dataContainer.textContent = JSON.stringify(data, null, " ");
|
|
|
-
|
|
|
- // ...this is where we’d actually do something with the form data...
|
|
|
- if ($(form).hasClass("param")) {
|
|
|
- localStorage.setItem("params", JSON.stringify(data));
|
|
|
- }
|
|
|
-
|
|
|
- if ($(form).hasClass("activite")) {
|
|
|
- data.tstamp = Date.now();
|
|
|
- data.user = localStorage.hasOwnProperty("params") ? JSON.parse(localStorage.getItem("params")).user : "";
|
|
|
-
|
|
|
- var db = open.result;
|
|
|
- var txs = db.transaction("activite", "readwrite");
|
|
|
- var stores = txs.objectStore("activite");
|
|
|
- stores.put(data);
|
|
|
-
|
|
|
- $(".main").empty();
|
|
|
-
|
|
|
- console.log("Got all activite: ");
|
|
|
- stores.getAll().onsuccess = function (event) {
|
|
|
- var data = { data: event.target.result };
|
|
|
- var template = Handlebars.compile(document.getElementById("activite").innerHTML);
|
|
|
- $(".main").html(template(data));
|
|
|
- };
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- console.log(data);
|
|
|
-
|
|
|
-};
|
|
|
-
|
|
|
-/*
|
|
|
- * This is where things actually get started. We find the form element using
|
|
|
- * its class name, then attach the `handleFormSubmit()` function to the
|
|
|
- * `submit` event.
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
-function handleFileSelect(evt) {
|
|
|
-
|
|
|
- console.log(evt.target.name);
|
|
|
-
|
|
|
- console.log(evt.target.id);
|
|
|
-
|
|
|
- var preview = $(this).closest('div').find('.img-preview');
|
|
|
-
|
|
|
- var hidden = $(this).closest('div').find('.hidden-file-img');
|
|
|
-
|
|
|
- console.log(evt.target.files);
|
|
|
-
|
|
|
- var files = evt.target.files; // FileList object
|
|
|
-
|
|
|
- // use the 1st file from the list
|
|
|
- var f = files[0];
|
|
|
-
|
|
|
- var reader = new FileReader();
|
|
|
-
|
|
|
- // Closure to capture the file information.
|
|
|
- reader.onload = (function (theFile) {
|
|
|
- return function (e) {
|
|
|
-
|
|
|
- $(hidden).val( e.target.result); //{ data: e.target.result, name: f.name };
|
|
|
-
|
|
|
- $(preview).attr('src', e.target.result);
|
|
|
- };
|
|
|
- })(f);
|
|
|
-
|
|
|
- // Read in the image file as a data URL.
|
|
|
- reader.readAsDataURL(f);
|
|
|
- //console.log(reader.readAsDataURL(f))
|
|
|
-}
|
|
|
-
|
|
|
-function getLocation() {
|
|
|
- if (navigator.geolocation) {
|
|
|
- navigator.geolocation.getCurrentPosition(showPosition);
|
|
|
- } else {
|
|
|
- return "Geolocation is not supported by this browser.";
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function showPosition(position) {
|
|
|
- $("input[name='coordinates']").val(position.coords.latitude + "," + position.coords.longitude);
|
|
|
- console.log(position.coords);
|
|
|
-}
|
|
|
-
|
|
|
-function getUrldest() {
|
|
|
- return (window.location.href.replace("index.html", "") == "http://localhost:62188/" ? "index" : window.location.hash.slice(1));
|
|
|
-}
|
|
|
-
|
|
|
-new MutationObserver(function (mutations, observer) {
|
|
|
-
|
|
|
- //gestion des mise element selectable
|
|
|
- $(".selectable > tbody").selectable({
|
|
|
- filter: "tr",
|
|
|
- stop: function () {
|
|
|
- $(".del").removeAttr("disabled");
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- $(".select-contact").change(function () {
|
|
|
- console.log("contact");
|
|
|
- var contact = $(this).find("option:selected").val();
|
|
|
- localStorage.setItem("contact", contact);
|
|
|
-
|
|
|
- var result = contacts;
|
|
|
-
|
|
|
- result.intervention = contact;
|
|
|
-
|
|
|
- console.log(result);
|
|
|
-
|
|
|
- var template = Handlebars.compile(document.getElementById("interventions").innerHTML);
|
|
|
-
|
|
|
- $(".main").html(template(result));
|
|
|
- });
|
|
|
-
|
|
|
- document.getElementsByClassName('results-display')[0].innerHTML = null;
|
|
|
-
|
|
|
- if ($(".main").find(".data-form").length){
|
|
|
-
|
|
|
- form = $(".main").find(".data-form")[0];
|
|
|
-
|
|
|
- form.addEventListener('submit', handleFormSubmit);
|
|
|
-
|
|
|
- var today = new Date();
|
|
|
-
|
|
|
- if ($(".main").find("#year_week").length) document.getElementById('year_week').value = today.getFullYear() + "_" + today.getWeekNumber();
|
|
|
-
|
|
|
- var imginputs = document.querySelectorAll('.input-file-img');
|
|
|
-
|
|
|
- Array.from(imginputs).forEach(img => {
|
|
|
- img.addEventListener('change', handleFileSelect, false); });
|
|
|
-
|
|
|
- if (localStorage.hasOwnProperty('params')) { }
|
|
|
- else {
|
|
|
- // console.log("no local");
|
|
|
- if (!$(form).hasClass("param") && !$(form).hasClass("anomalie")) {
|
|
|
- $(".main .data-form").toggle();
|
|
|
- alert("Vous devez d'abord définir les paramètres de la campagne");
|
|
|
- //console.log("pas param");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}).observe(document.querySelector('section.main'), { childList: true });
|
|
|
+};
|