|
|
@@ -1,549 +1,297 @@
|
|
|
-//$(function () {
|
|
|
+
|
|
|
+// JS s'execute: Retire l'avertissement 'Javascript est requis'
|
|
|
+document.body.classList.remove("nojs");
|
|
|
|
|
|
- // 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');
|
|
|
- }
|
|
|
+if ('serviceWorker' in navigator) {
|
|
|
+ console.log("[ServiceWorker] Installe");
|
|
|
+ navigator.serviceWorker.register('../sw.js');
|
|
|
+}
|
|
|
|
|
|
- Handlebars.registerHelper('lower', function (options) {
|
|
|
- return options.fn(this).toLowerCase();
|
|
|
- });
|
|
|
+Handlebars.registerHelper('lower', function (options) {
|
|
|
+ return options.fn(this).toLowerCase();
|
|
|
+});
|
|
|
|
|
|
- Handlebars.registerHelper('repuri', function (find, replace, options) {
|
|
|
- return encodeURI(options.fn(this).replace(find, replace).toString());
|
|
|
- });
|
|
|
+Handlebars.registerHelper('repuri', function (find, replace, options) {
|
|
|
+ return encodeURI(options.fn(this).replace(find, replace).toString());
|
|
|
+});
|
|
|
|
|
|
- Handlebars.registerHelper('todate', function (options) {
|
|
|
- var d = options.fn(this);
|
|
|
- var dt = new Date(Number.parseInt(d)*1);
|
|
|
- return dt.toLocaleString();
|
|
|
- });
|
|
|
+Handlebars.registerHelper('todate', function (options) {
|
|
|
+ var d = options.fn(this);
|
|
|
+ var dt = new Date(Number.parseInt(d)*1);
|
|
|
+ return dt.toLocaleString();
|
|
|
+});
|
|
|
|
|
|
- Handlebars.registerHelper('timestamp', function (options) {
|
|
|
- return Number.parseInt(options.fn(this));
|
|
|
- });
|
|
|
+Handlebars.registerHelper('timestamp', function (options) {
|
|
|
+ return Number.parseInt(options.fn(this));
|
|
|
+});
|
|
|
|
|
|
- Handlebars.registerHelper('if_eq', function (a, opts) {
|
|
|
- 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);
|
|
|
- });
|
|
|
+Handlebars.registerHelper('if_eq', function (a, opts) {
|
|
|
+ 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>
|
|
|
- var main = document.getElementsByClassName('main')[0];
|
|
|
+// Main <div>
|
|
|
+var main = document.getElementsByClassName('main')[0];
|
|
|
|
|
|
- // ???
|
|
|
- var template = Handlebars.compile(document.getElementById(getUrldest()).innerHTML);
|
|
|
+// ???
|
|
|
+var template = Handlebars.compile(document.getElementById(getUrldest()).innerHTML);
|
|
|
|
|
|
|
|
|
- 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);
|
|
|
- });
|
|
|
- }
|
|
|
- function uuidv4() {
|
|
|
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
|
- (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
|
|
- )
|
|
|
- }
|
|
|
+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);
|
|
|
+ });
|
|
|
+}
|
|
|
+function uuidv4() {
|
|
|
+ return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
|
|
+ (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
|
|
+ )
|
|
|
+}
|
|
|
|
|
|
- var contacts;
|
|
|
- function callback(response) {
|
|
|
- contacts = response;
|
|
|
- // localStorage.setItem("contacts", JSON.stringify(response))
|
|
|
- }
|
|
|
+var contacts;
|
|
|
+function callback(response) {
|
|
|
+ contacts = response;
|
|
|
+ // localStorage.setItem("contacts", JSON.stringify(response))
|
|
|
+}
|
|
|
|
|
|
- $.ajax({
|
|
|
- url: "data/contacts.json", success: function (result) {
|
|
|
- callback(result);
|
|
|
- }
|
|
|
- });
|
|
|
+//$.ajax({
|
|
|
+// url: "data/contacts.json", success: function (result) {
|
|
|
+// callback(result);
|
|
|
+// }
|
|
|
+//});
|
|
|
|
|
|
- try {
|
|
|
- getLocation();
|
|
|
- }
|
|
|
- catch (e) {
|
|
|
- console.log("error loc");
|
|
|
- }
|
|
|
+//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)
|
|
|
- };
|
|
|
+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)
|
|
|
+};
|
|
|
|
|
|
- $('.bt-menu').on('click', 'svg', function () {
|
|
|
- $(this).closest('nav').find('div:not(:first)').toggleClass('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');
|
|
|
- });
|
|
|
+$(document).on('click', '.sidebar', function () {
|
|
|
+ $(this).closest('nav').find('div:not(:first)').toggleClass('sidebar');
|
|
|
+});
|
|
|
|
|
|
- //param first
|
|
|
+//param first
|
|
|
|
|
|
- //suppression
|
|
|
+//suppression
|
|
|
|
|
|
- //gestion offline
|
|
|
- if (navigator.onLine) {
|
|
|
- $(".data-sync").removeAttr("disabled");
|
|
|
- }
|
|
|
- else {
|
|
|
- if (!$(".data-sync").is(":disabled"))
|
|
|
- {
|
|
|
- $(".data-sync").attr("disabled")
|
|
|
- }
|
|
|
+//gestion offline
|
|
|
+if (navigator.onLine) {
|
|
|
+ $(".data-sync").removeAttr("disabled");
|
|
|
+}
|
|
|
+else {
|
|
|
+ if (!$(".data-sync").is(":disabled"))
|
|
|
+ {
|
|
|
+ $(".data-sync").attr("disabled")
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- //syncro
|
|
|
- $(".data-sync").on("click", function () {
|
|
|
-
|
|
|
- var db = open.result;
|
|
|
- var txs = db.transaction("anomalies", "readonly");
|
|
|
- var stores = txs.objectStore("anomalies");
|
|
|
- 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";
|
|
|
-
|
|
|
- cursor.value.model = "anomaly";
|
|
|
- var id = cursor.value.tstamp;
|
|
|
- var posting = $.post("/api/canalbis", { data: JSON.stringify(cursor.value) });
|
|
|
-
|
|
|
- // Put the results in a div
|
|
|
- posting.done(function (data) {
|
|
|
- if (data == 'ole') {
|
|
|
-
|
|
|
- var tx = db.transaction("anomalies", "readwrite");
|
|
|
- var store = tx.objectStore("anomalies");
|
|
|
- store.delete(id).onsuccess = function (evt) {
|
|
|
- $('.sync-result').append("Sync ok anomalie : " + id + "<br>");
|
|
|
- };
|
|
|
- }
|
|
|
- });
|
|
|
- cursor.continue();
|
|
|
- }
|
|
|
- else {
|
|
|
- console.log("end anomalies");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //$.post("/api/canalbis", { data: JSON.stringify({anomaly: event.target.result}) });
|
|
|
- // main.innerHTML = template(data);
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- txs = db.transaction("vannes", "readonly");
|
|
|
- stores = txs.objectStore("vannes");
|
|
|
- console.log("post all : ");
|
|
|
- stores.openCursor().onsuccess = function (event) {
|
|
|
- var cursor = event.target.result;
|
|
|
- if (cursor) {
|
|
|
- //cursor.model = "anomaly";
|
|
|
-
|
|
|
- cursor.value.model = "valve";
|
|
|
- var id = cursor.value.tstamp;
|
|
|
- var posting = $.post("/api/canalbis", { data: JSON.stringify(cursor.value) });
|
|
|
-
|
|
|
- // Put the results in a div
|
|
|
- posting.done(function (data) {
|
|
|
- if (data == 'ole') {
|
|
|
-
|
|
|
- var tx = db.transaction("vannes", "readwrite");
|
|
|
- var store = tx.objectStore("vannes");
|
|
|
- store.delete(id).onsuccess = function (evt) {
|
|
|
- $('.sync-result').append("Sync ok vanne : " + id +"<br>");
|
|
|
- };
|
|
|
- }
|
|
|
- });
|
|
|
- cursor.continue();
|
|
|
- }
|
|
|
- else {
|
|
|
- console.log("end valve");
|
|
|
- }
|
|
|
-
|
|
|
- //var data = { data: event.target.result };
|
|
|
-
|
|
|
- //$.post("/api/canalbis", { data: JSON.stringify({ valve: event.target.result }) });
|
|
|
- // main.innerHTML = template(data);
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- txs = db.transaction("interventions", "readonly");
|
|
|
- stores = txs.objectStore("interventions");
|
|
|
- console.log("post all : ");
|
|
|
- //stores.getAll().onsuccess = function (event) {
|
|
|
- stores.openCursor().onsuccess = function (event) {
|
|
|
- var cursor = event.target.result;
|
|
|
- if (cursor) {
|
|
|
- //cursor.model = "anomaly";
|
|
|
-
|
|
|
- cursor.value.model = "interventions";
|
|
|
- var id = cursor.value.tstamp;
|
|
|
- var posting = $.post("/api/canalbis", { data: JSON.stringify(cursor.value) });
|
|
|
-
|
|
|
- // Put the results in a div
|
|
|
- posting.done(function (data) {
|
|
|
- if (data == 'ole') {
|
|
|
-
|
|
|
- var tx = db.transaction("interventions", "readwrite");
|
|
|
- var store = tx.objectStore("interventions");
|
|
|
- store.delete(id).onsuccess = function (evt) {
|
|
|
- $('.sync-result').append("Sync ok intervention : " + id + "<br>");
|
|
|
- };
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- cursor.continue();
|
|
|
- }
|
|
|
- else {
|
|
|
- console.log("end interventions");
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
-
|
|
|
- txs = db.transaction("niveaux", "readonly");
|
|
|
- stores = txs.objectStore("niveaux");
|
|
|
- console.log("post all : ");
|
|
|
- //stores.getAll().onsuccess = function (event) {
|
|
|
- stores.openCursor().onsuccess = function (event) {
|
|
|
- var cursor = event.target.result;
|
|
|
- if (cursor) {
|
|
|
- //cursor.model = "anomaly";
|
|
|
-
|
|
|
- cursor.value.model = "level";
|
|
|
- var id = cursor.value.tstamp;
|
|
|
- var posting = $.post("/api/canalbis", { data: JSON.stringify(cursor.value) });
|
|
|
-
|
|
|
- // Put the results in a div
|
|
|
- posting.done(function (data) {
|
|
|
- if (data == 'ole') {
|
|
|
-
|
|
|
- var tx = db.transaction("niveaux", "readwrite");
|
|
|
- var store = tx.objectStore("niveaux");
|
|
|
- store.delete(id).onsuccess = function (evt) {
|
|
|
- $('.sync-result').append("Sync ok niveau : " + id + "<br>");
|
|
|
- };}
|
|
|
- });
|
|
|
-
|
|
|
- cursor.continue();
|
|
|
- }
|
|
|
- else {
|
|
|
- console.log("end level");
|
|
|
- }
|
|
|
-
|
|
|
- //var data = { data: event.target.result };
|
|
|
-
|
|
|
- //$.post("/api/canalbis", { data: JSON.stringify({level: event.target.result}) });
|
|
|
- // main.innerHTML = template(data);
|
|
|
- };
|
|
|
-
|
|
|
- //location.reload();
|
|
|
- })
|
|
|
-
|
|
|
- $(window).on('hashchange', function () {
|
|
|
-
|
|
|
- var href = $(this).attr('href');
|
|
|
-
|
|
|
- $('html, body').animate({ scrollTop: 0 }, 200);
|
|
|
-
|
|
|
- var urldest = getUrldest();
|
|
|
-
|
|
|
- template = Handlebars.compile(document.getElementById(urldest).innerHTML);
|
|
|
-
|
|
|
- try {
|
|
|
- getLocation();
|
|
|
- }
|
|
|
- catch (e) {
|
|
|
- console.log("error loc");
|
|
|
- }
|
|
|
-
|
|
|
- if (urldest != 'interventions' && urldest != 'contacts') {
|
|
|
-
|
|
|
- $(".main").empty();
|
|
|
- try {
|
|
|
- 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);
|
|
|
- };
|
|
|
- //console.log(data);
|
|
|
- // $(".main").html(template({}));
|
|
|
- }
|
|
|
- catch (e) {
|
|
|
-
|
|
|
- main.innerHTML = template({});
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if (urldest == 'interventions') {
|
|
|
-
|
|
|
- //$.ajax({
|
|
|
- // url: "", success: function (result) {
|
|
|
- var contactInter = contacts;
|
|
|
- console.log(contactInter);
|
|
|
- if (localStorage.hasOwnProperty("contact")) contactInter.intervention = localStorage.getItem("contact");
|
|
|
- $(".main").html(template(contactInter));
|
|
|
-
|
|
|
-
|
|
|
- // }
|
|
|
- //});
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (urldest == 'contacts') {
|
|
|
-
|
|
|
- //$.ajax({
|
|
|
- // url: "", success: function (result) {
|
|
|
-
|
|
|
- $(".main").html(template(contacts));
|
|
|
+//syncro
|
|
|
+$(".data-sync").on("click", function () {
|
|
|
|
|
|
- // }
|
|
|
- //});
|
|
|
+ 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";
|
|
|
+
|
|
|
+ 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') {
|
|
|
+
|
|
|
+ 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();
|
|
|
}
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
- var imgdata;
|
|
|
-//a finir
|
|
|
-
|
|
|
-
|
|
|
- $("body").on("click", ".btn-duplicate", function (event) {
|
|
|
- event.preventDefault();
|
|
|
-
|
|
|
- // var copie = $('#img-group-1').clone();
|
|
|
-
|
|
|
- var copie = $('.input-group-img').find('div:first-child').clone();
|
|
|
-
|
|
|
-
|
|
|
- var inputlenght = createGuid(); //$('.input-file-img').length + 1;
|
|
|
-
|
|
|
- var grpId = $(copie).attr('id') + "-" + inputlenght;
|
|
|
-
|
|
|
- $(copie).attr('id', grpId);
|
|
|
-
|
|
|
- console.log(inputlenght);
|
|
|
-
|
|
|
- var inputName = $(copie).find('.input-file-img').attr('name') + "-" + inputlenght;
|
|
|
-
|
|
|
- $(copie).find('.input-file-img').val('');
|
|
|
-
|
|
|
- $(copie).find('.input-file-img').attr('name', inputName);
|
|
|
-
|
|
|
- var hiddenName = $(copie).find('.hidden-file-img').attr('name') + "-" + inputlenght;
|
|
|
-
|
|
|
- $(copie).find('.hidden-file-img').attr('name', hiddenName);
|
|
|
-
|
|
|
- $(copie).find('.hidden-file-img').val('');
|
|
|
-
|
|
|
- $(copie).find('img').attr('src', '');
|
|
|
-
|
|
|
- copie.appendTo('.input-group-img');
|
|
|
-
|
|
|
- var imginputs = document.querySelectorAll('.input-file-img');
|
|
|
-
|
|
|
- Array.from(imginputs).forEach(img => {
|
|
|
- img.addEventListener('change', handleFileSelect, false);
|
|
|
- });
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- $("body").on("click", ".file-del", function (event) {
|
|
|
- event.preventDefault();
|
|
|
- if ($(this).closest('div').attr('id') == 'img-group') {
|
|
|
- $(this).closest('div').find('img').attr('src', '');
|
|
|
- $(this).closest('div').find('.input-file-img').val('');
|
|
|
- $(this).closest('div').find('.hidden-file-img').val('');
|
|
|
+ else {
|
|
|
+ console.log("end activite");
|
|
|
}
|
|
|
- else $(this).closest('div').remove();
|
|
|
-
|
|
|
- });
|
|
|
|
|
|
- $("body").on("click", ".intervention-start, .intervention-end", function (event) {
|
|
|
+ };
|
|
|
+})
|
|
|
+
|
|
|
+// Recharge dynamiquement le contenu HTML à chaque changement d'url
|
|
|
+$(window).on('hashchange', function () {
|
|
|
|
|
|
+ var href = $(this).attr('href');
|
|
|
|
|
|
- console.log("intervention");
|
|
|
+ $('html, body').animate({ scrollTop: 0 }, 200);
|
|
|
|
|
|
- var data = new Object();
|
|
|
- data.tstamp = Date.now();
|
|
|
- data.user = JSON.parse(localStorage.getItem("params")).user;
|
|
|
- data.event = $(this).data("type");
|
|
|
- var db = open.result;
|
|
|
- var txs = db.transaction("interventions", "readwrite");
|
|
|
- var stores = txs.objectStore("interventions");
|
|
|
- stores.put(data);
|
|
|
-
|
|
|
- })
|
|
|
+ var urldest = getUrldest();
|
|
|
|
|
|
- $("body").on("click", ".data-del", function (event) {
|
|
|
+ template = Handlebars.compile(document.getElementById(urldest).innerHTML);
|
|
|
|
|
|
- // console.log($(this).data("id") + " " + $(this).data("type"));
|
|
|
- var id = $(this).data("id");
|
|
|
- var datatype = $(this).data("type");
|
|
|
- //console.log(id + " " + datatype);
|
|
|
+ //try {
|
|
|
+ // getLocation();
|
|
|
+ //}
|
|
|
+ //catch (e) {
|
|
|
+ // console.log("error loc");
|
|
|
+ //}
|
|
|
|
|
|
- var r = confirm("Supprimer cet élément!");
|
|
|
- if (r == true) {
|
|
|
+ if (urldest != 'activite') {
|
|
|
|
|
|
+ $(".main").empty();
|
|
|
+ try {
|
|
|
var db = open.result;
|
|
|
- var tx = db.transaction(datatype, "readwrite");
|
|
|
- var store = tx.objectStore(datatype);
|
|
|
+ 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 };
|
|
|
|
|
|
- store.delete(id).onsuccess = function (evt) {
|
|
|
- // console.log(id + " " + datatype);
|
|
|
- location.reload();
|
|
|
+ main.innerHTML = template(data);
|
|
|
};
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- $("body").on("click", ".send-message", function (event) {
|
|
|
- event.preventDefault();
|
|
|
- var form = $(this).closest("form");
|
|
|
-
|
|
|
- function getLocation() {
|
|
|
- if (navigator.geolocation) {
|
|
|
- navigator.geolocation.getCurrentPosition(showPosition);
|
|
|
- } else {
|
|
|
- return "Geolocation is not supported by this browser.";
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
- function showPosition(position) {
|
|
|
- //{ lat: position.coords.latitude, lng : position.coords.longitude };
|
|
|
-
|
|
|
- $("input[name='lat']:hidden").val(position.coords.latitude);
|
|
|
- $("input[name='lng']:hidden").val(position.coords.longitude);
|
|
|
-
|
|
|
+ catch (e) {
|
|
|
+ main.innerHTML = template({});
|
|
|
}
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
- var pp = getLocation();
|
|
|
+var imgdata;
|
|
|
|
|
|
- //var data = form.serializeArray().reduce(function (a, x) { a[x.name] = x.value; return a; }, { tstamp: Date.now(), file: imgdata });
|
|
|
+$("body").on("click", ".data-del", function (event) {
|
|
|
|
|
|
- var data = form.serializeArray().reduce(function (a, x) { a[x.name] = x.value; return a; }, { tstamp: Date.now()});
|
|
|
+ // 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 request = indexedDB.open("Contenu", 3);
|
|
|
+ var db = open.result;
|
|
|
+ var tx = db.transaction(datatype, "readwrite");
|
|
|
+ var store = tx.objectStore(datatype);
|
|
|
|
|
|
- request.onerror = function () {
|
|
|
- form.find(".send-result").html("Une erreur c'est produite.");
|
|
|
+ store.delete(id).onsuccess = function (evt) {
|
|
|
+ // console.log(id + " " + datatype);
|
|
|
+ location.reload();
|
|
|
};
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
- 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.");
|
|
|
+$("body").on("click", ".send-message", function (event) {
|
|
|
+ event.preventDefault();
|
|
|
+ var form = $(this).closest("form");
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
|
|
|
+ var pp = getLocation();
|
|
|
|
|
|
- //$(function () {
|
|
|
- $(".modal-open, .modal-background, .modal-close").click(function () {
|
|
|
- console.log("modal");
|
|
|
- $(".modal-content,.modal-background").toggleClass("active");
|
|
|
- if ($(this).hasClass("modal-close")) location.reload();// $(this).closest("form").find(".send-result").html("");
|
|
|
- });
|
|
|
+ var data = form.serializeArray().reduce(function (a, x) { a[x.name] = x.value; return a; }, { tstamp: Date.now()});
|
|
|
|
|
|
+ var request = indexedDB.open("Contenu", 3);
|
|
|
|
|
|
-
|
|
|
- /* retour haut de page*/
|
|
|
- //document.addEventListener('DOMContentLoaded', function () {
|
|
|
- window.onscroll = function (ev) {
|
|
|
- document.getElementById("cRetour").className = (window.pageYOffset > 100) ? "cVisible" : "cInvisible";
|
|
|
+ request.onerror = function () {
|
|
|
+ form.find(".send-result").html("Une erreur c'est produite.");
|
|
|
};
|
|
|
- //});
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $('#cRetour').on('click', function () {
|
|
|
-
|
|
|
- $('html, body').animate({ scrollTop: 0 }, 200);
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
- $(".main").empty();
|
|
|
- var urldest = getUrldest();
|
|
|
- try{
|
|
|
- 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({});
|
|
|
-
|
|
|
-
|
|
|
+ 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.");
|
|
|
}
|
|
|
+});
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+$(".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";
|
|
|
+};
|
|
|
|
|
|
+$('#cRetour').on('click', function () {
|
|
|
+ $('html, body').animate({ scrollTop: 0 }, 200);
|
|
|
+});
|
|
|
|
|
|
- $("body").on("click", ".del", function (event) {
|
|
|
+$(".main").empty();
|
|
|
+var urldest = getUrldest();
|
|
|
+try{
|
|
|
+ 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 del = $(this);
|
|
|
- var r = confirm("Supprimer la selection!");
|
|
|
- if (r == true) {
|
|
|
+$("body").on("click", ".del", function (event) {
|
|
|
|
|
|
- $(del).prop("disabled",true);
|
|
|
+ var del = $(this);
|
|
|
+ var r = confirm("Supprimer la selection!");
|
|
|
+ if (r == 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();
|
|
|
+ $(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();
|
|
|
|
|
|
- });
|
|
|
+ };
|
|
|
|
|
|
- }
|
|
|
});
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-///////////////////////});
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -662,34 +410,18 @@ var formToJSON = function formToJSON(elements) {
|
|
|
}, {});
|
|
|
};
|
|
|
|
|
|
-
|
|
|
-
|
|
|
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
|
|
|
|
|
|
// Open (or create) the database
|
|
|
-var open = indexedDB.open("CanalBis", 3);
|
|
|
+var open = indexedDB.open("MobiParc", 3);
|
|
|
|
|
|
// Create the schema
|
|
|
open.onupgradeneeded = function () {
|
|
|
var db = open.result;
|
|
|
//creation anomalies
|
|
|
- var store = db.createObjectStore("anomalies", { keyPath: "tstamp" });
|
|
|
-
|
|
|
- //creation niveaux
|
|
|
- var store = db.createObjectStore("niveaux", { keyPath: "tstamp" });
|
|
|
-
|
|
|
- //creation vannes
|
|
|
- var store = db.createObjectStore("vannes", { keyPath: "tstamp" });
|
|
|
-
|
|
|
-
|
|
|
- //creation interventions
|
|
|
- var store = db.createObjectStore("interventions", { keyPath: "tstamp" });
|
|
|
-
|
|
|
-
|
|
|
+ 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
|
|
|
@@ -712,84 +444,33 @@ var handleFormSubmit = function handleFormSubmit(event) {
|
|
|
// 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));
|
|
|
- //console.log("localstorage");
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- if ($(form).hasClass("anomalie")) {
|
|
|
+ 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("anomalies", "readwrite");
|
|
|
- var stores = txs.objectStore("anomalies");
|
|
|
+ var txs = db.transaction("activite", "readwrite");
|
|
|
+ var stores = txs.objectStore("activite");
|
|
|
stores.put(data);
|
|
|
|
|
|
-
|
|
|
$(".main").empty();
|
|
|
|
|
|
- console.log("Got all anomalies: ");
|
|
|
+ console.log("Got all activite: ");
|
|
|
stores.getAll().onsuccess = function (event) {
|
|
|
var data = { data: event.target.result };
|
|
|
- var template = Handlebars.compile(document.getElementById("anomalies").innerHTML);
|
|
|
+ var template = Handlebars.compile(document.getElementById("activite").innerHTML);
|
|
|
$(".main").html(template(data));
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- if ($(form).hasClass("vanne")) {
|
|
|
- data.tstamp = Date.now();
|
|
|
- data.user = JSON.parse(localStorage.getItem("params")).user;
|
|
|
- data.campaign = JSON.parse(localStorage.getItem("params")).year_week;
|
|
|
- var db = open.result;
|
|
|
- var txs = db.transaction("vannes", "readwrite");
|
|
|
- var stores = txs.objectStore("vannes");
|
|
|
- stores.put(data);
|
|
|
-
|
|
|
-
|
|
|
- $(".main").empty();
|
|
|
-
|
|
|
- console.log("Got all vannes: ");
|
|
|
- stores.getAll().onsuccess = function (event) {
|
|
|
- var data = { data: event.target.result };
|
|
|
- var template = Handlebars.compile(document.getElementById("vannes").innerHTML);
|
|
|
- $(".main").html(template(data));
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if ($(form).hasClass("niveau")) {
|
|
|
- data.tstamp = Date.now();
|
|
|
- data.user = JSON.parse(localStorage.getItem("params")).user;
|
|
|
- data.campaign = JSON.parse(localStorage.getItem("params")).year_week;
|
|
|
- var db = open.result;
|
|
|
- var txs = db.transaction("niveaux", "readwrite");
|
|
|
- var stores = txs.objectStore("niveaux");
|
|
|
- stores.put(data);
|
|
|
-
|
|
|
-
|
|
|
- $(".main").empty();
|
|
|
-
|
|
|
- console.log("Got all niveaux: ");
|
|
|
- stores.getAll().onsuccess = function (event) {
|
|
|
- var data = { data: event.target.result };
|
|
|
- var template = Handlebars.compile(document.getElementById("niveaux").innerHTML);
|
|
|
- $(".main").html(template(data));
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
console.log(data);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
};
|
|
|
|
|
|
/*
|
|
|
@@ -812,8 +493,6 @@ function handleFileSelect(evt) {
|
|
|
console.log(evt.target.files);
|
|
|
|
|
|
var files = evt.target.files; // FileList object
|
|
|
-
|
|
|
-
|
|
|
|
|
|
// use the 1st file from the list
|
|
|
var f = files[0];
|
|
|
@@ -835,8 +514,6 @@ function handleFileSelect(evt) {
|
|
|
//console.log(reader.readAsDataURL(f))
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
function getLocation() {
|
|
|
if (navigator.geolocation) {
|
|
|
navigator.geolocation.getCurrentPosition(showPosition);
|
|
|
@@ -846,16 +523,12 @@ function getLocation() {
|
|
|
}
|
|
|
|
|
|
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:56343/" ? "index" : window.location.hash.slice(1));
|
|
|
-
|
|
|
+ return (window.location.href.replace("index.html", "") == "http://localhost:62188/" ? "index" : window.location.hash.slice(1));
|
|
|
}
|
|
|
|
|
|
new MutationObserver(function (mutations, observer) {
|
|
|
@@ -868,7 +541,6 @@ new MutationObserver(function (mutations, observer) {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-
|
|
|
$(".select-contact").change(function () {
|
|
|
console.log("contact");
|
|
|
var contact = $(this).find("option:selected").val();
|
|
|
@@ -885,10 +557,8 @@ new MutationObserver(function (mutations, observer) {
|
|
|
$(".main").html(template(result));
|
|
|
});
|
|
|
|
|
|
-
|
|
|
document.getElementsByClassName('results-display')[0].innerHTML = null;
|
|
|
|
|
|
-
|
|
|
if ($(".main").find(".data-form").length){
|
|
|
|
|
|
form = $(".main").find(".data-form")[0];
|
|
|
@@ -899,28 +569,11 @@ new MutationObserver(function (mutations, observer) {
|
|
|
|
|
|
if ($(".main").find("#year_week").length) document.getElementById('year_week').value = today.getFullYear() + "_" + today.getWeekNumber();
|
|
|
|
|
|
- //if ($(".main").find("#imgfile").length) document.getElementById('imgfile').addEventListener('change', handleFileSelect, false);
|
|
|
-
|
|
|
- //if ($(".input-file-img").length)
|
|
|
-
|
|
|
- // document.querySelector('.input-file-img').addEventListener('change', handleFileSelect, false);
|
|
|
-
|
|
|
- //{
|
|
|
-
|
|
|
- //$(".input-file-img").each(function (index) {
|
|
|
- // document.querySelector('.input-file-img').addEventListener('change', handleFileSelect, false);
|
|
|
-
|
|
|
- // });
|
|
|
-
|
|
|
-
|
|
|
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");
|
|
|
@@ -930,15 +583,6 @@ new MutationObserver(function (mutations, observer) {
|
|
|
//console.log("pas param");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- //observer.disconnect();
|
|
|
-
|
|
|
}).observe(document.querySelector('section.main'), { childList: true });
|
|
|
-
|
|
|
-//});
|
|
|
-
|
|
|
-
|