diff --git a/js/lib/local-storage-interface-min.js b/js/lib/local-storage-interface-min.js index 02dc934..1b2ed66 100644 --- a/js/lib/local-storage-interface-min.js +++ b/js/lib/local-storage-interface-min.js @@ -1,3 +1,4 @@ function localStorageInterface(){} -localStorageInterface.prototype={dataset:[],dataset_keys:[],set:function(a,b,d){var c=this.dataset.indexOf(a);if(-1==c)return!1;-1==this.dataset_keys[c].indexOf(b)&&(this.dataset_keys[c].push(b),localStorage.setItem(a,JSON.stringify(this.dataset_keys[c])));localStorage.setItem(a+"_"+b,JSON.stringify(d));return!0},get:function(a,b){return-1==this.dataset.indexOf(a)?!1:JSON.parse(localStorage.getItem(a+"_"+b))},createDataset:function(a){if(null==a||"string"!=typeof a)return!1;if(-1 Nom du dataset en question + * @key Clé de l'élément + * + * @return status Retourne FALSE si erreur + * + */ + del: function(dataset, key){ + /* (1) Si le 'dataset' n'existe pas */ + var index = this.dataset.indexOf(dataset); + if( index == -1 ) return false; // erreur + + /* (2) On récupère la clé dans la liste des clés */ + var keyIndex = this.dataset_keys[index].indexOf(key); + if( keyIndex == -1 ) return false; // erreur si la clé n'est pas référencée + + /* (3) On supprime dans le 'localStorage' */ + localStorage.removeItem(dataset+'_'+key); + + /* (4) On supprime la clé dans la liste des clés */ + this.dataset_keys[index].splice(keyIndex, 1); + + /* (5) On met à jour dans le 'localStorage' */ + localStorage.setItem(dataset, JSON.stringify(this.dataset_keys[index])); + + + return true; + }, + /* CREATION D'UN DATASET OU RECUPERATION DES DONNEES S'IL EXISTE DEJA * @@ -59,11 +89,12 @@ localStorageInterface.prototype = { */ createDataset: function(name){ /* (1) On vérifie que le @name est correct */ - if( name == null || typeof name != 'string' ) return false; // erreur + if( typeof name != 'string' ) return false; // erreur /* (2) Si le dataset est déjà enregistré, on ne fais rien */ - if( this.dataset.indexOf(name) > -1 ) return true; + var datasetIndex = this.dataset.indexOf(name); + if( datasetIndex > -1 ) return true; /* (3) On charge le dataset s'il existe */ var storedDataset = localStorage.getItem(name); @@ -72,7 +103,7 @@ localStorageInterface.prototype = { this.dataset.push(name); this.dataset_keys.push( JSON.parse(storedDataset) ); - /* (4) Sinon, on le crée 'dataset' */ + /* (4) Sinon, on crée le 'dataset' */ }else{ this.dataset.push(name); @@ -107,6 +138,32 @@ localStorageInterface.prototype = { /* (3) On retourne le résultat */ return obj; + }, + + + import: function(dataset, data){ + /* (1) On récupère l'indice du dataset s'il existe déjà */ + var index = this.dataset.indexOf(dataset); + + /* (2) Cas 1 : Le dataset n'existe pas -> on le crée */ + if( index == -1 ) + this.createDataset(dataset); + + /* (3) Cas 2 : Le dataset existe -> on supprime tout */ + else{ + var content = this.export(dataset); + // On supprime toutes les valeurs + for( var key in content ) + this.del(dataset, key); + + } + + /* (2) On remplit le dataset avec toutes les données de l'objet */ + for( var key in data ) + this.set(dataset, key, data[key]); + + /* (3) On retourne le résultat */ + return true; } diff --git a/view/input.php b/view/input.php index ae27fff..8f6d076 100755 --- a/view/input.php +++ b/view/input.php @@ -39,6 +39,8 @@

Effacer les données de la dernière enquête

+
+

diff --git a/view/js/input-min.js b/view/js/input-min.js index f1a167a..524c5f4 100644 --- a/view/js/input-min.js +++ b/view/js/input-min.js @@ -5,5 +5,6 @@ function checkRadioValue(a){for(var c=0,b=0;b GATHERING ALL DATA");subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();a={path:"input/phone",subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches")};api.send(a,function(a){console.log(a)}, -!1)},!1)})})})}); +!1);clearAllButton.addEventListener("click",function(a){localStorage.clear();reload()},!1);$("#export-all").addEventListener("click",function(a){a={subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches")};console.log(JSON.stringify(a))},!1);$("#import-all").addEventListener("click",function(a){a=JSON.parse('{"subject":{"number":"06 69 05 19 10","username":"","firstname":"Adrien","lastname":""},"contacts":{"0":{"uid":0,"number":"1","username":"1","firstname":"","lastname":"","hash":241770401},"1":{"uid":1,"number":"2","username":"2","firstname":"","lastname":"","hash":363925312}},"mini":{"0":{"uid":0,"firstname":"","lastname":"","username":"1","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"25","job":"0","loc":[{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":true},{"value":"on","status":false}],"hash":1923019850,"valid":true,"timestamp":1462196014908},"1":{"uid":1,"firstname":"","lastname":"","username":"2","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"23","job":"32","loc":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"hash":3042965309,"valid":true,"timestamp":1462196032703}},"fiches":{"0":{"uid":0,"firstname":"","lastname":"","username":"1","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"25","job":"0","famsit":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false}],"studies":".","reltype":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"reltypeSpecial":"","city":"","loc":[{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":true},{"value":"on","status":false}],"loc2":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"duration":["",""],"context":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"contextSpecial":["","",""],"freq":[[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}]],"connect":[[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}]],"connectSpecial":["",""],"hash":1570439147,"valid":false,"timestamp":1462196015606},"1":{"uid":1,"firstname":"","lastname":"","username":"2","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"23","job":"32","famsit":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false}],"studies":".","reltype":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"reltypeSpecial":"","city":"","loc":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"loc2":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"duration":["",""],"context":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"contextSpecial":["","",""],"freq":[[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}]],"connect":[[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}]],"connectSpecial":["",""],"hash":3347750419,"valid":false,"timestamp":1462195434069}}}'); +console.log(a);lsi["import"]("subject",a.subject);lsi["import"]("contacts",a.contacts);lsi["import"]("mini-fiches",a.mini);lsi["import"]("fiches",a.fiches)},!1);submitAllButton.addEventListener("click",function(a){console.log("> GATHERING ALL DATA");subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();a={path:"input/phone",subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"), +fiches:lsi["export"]("fiches")};api.send(a,function(a){console.log(a)},!1)},!1)})})})}); diff --git a/view/js/input.js b/view/js/input.js index 78e77f4..b5cd3f2 100644 --- a/view/js/input.js +++ b/view/js/input.js @@ -211,9 +211,6 @@ include('/js/includes/input-phone-fiche.js', function(){ - - - /* (5) Gestion de l'import du fichier ---------------------------------------------------------*/ importCallLog.addEventListener('change', function(e){ @@ -282,7 +279,45 @@ include('/js/includes/input-phone-fiche.js', function(){ }, false); - /* (7) Gestion de la validation et de l'envoi des données + /* (7) Gestion de l'export des données locales + ---------------------------------------------------------*/ + $('#export-all').addEventListener('click', function(e){ + /* (1) On construit les données */ + var data = { + subject: lsi.export('subject')[0], + contacts: lsi.export('contacts'), + mini: lsi.export('mini-fiches'), + fiches: lsi.export('fiches') + }; + + /* (2) On lance le téléchargement */ + console.log(JSON.stringify(data)); + + // TODO: Gestion du download du fichier avec les données souhaitées + + }, false); + + + /* (8) Gestion de l'import des données locales + ---------------------------------------------------------*/ + $('#import-all').addEventListener('click', function(e){ + /* (1) On récupère les données uploadées */ + // TODO: Gestion de la récupération de données uploadées + var json = '{"subject":{"number":"06 69 05 19 10","username":"","firstname":"Adrien","lastname":""},"contacts":{"0":{"uid":0,"number":"1","username":"1","firstname":"","lastname":"","hash":241770401},"1":{"uid":1,"number":"2","username":"2","firstname":"","lastname":"","hash":363925312}},"mini":{"0":{"uid":0,"firstname":"","lastname":"","username":"1","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"25","job":"0","loc":[{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":true},{"value":"on","status":false}],"hash":1923019850,"valid":true,"timestamp":1462196014908},"1":{"uid":1,"firstname":"","lastname":"","username":"2","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"23","job":"32","loc":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"hash":3042965309,"valid":true,"timestamp":1462196032703}},"fiches":{"0":{"uid":0,"firstname":"","lastname":"","username":"1","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"25","job":"0","famsit":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false}],"studies":".","reltype":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"reltypeSpecial":"","city":"","loc":[{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":true},{"value":"on","status":false}],"loc2":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"duration":["",""],"context":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"contextSpecial":["","",""],"freq":[[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}]],"connect":[[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}]],"connectSpecial":["",""],"hash":1570439147,"valid":false,"timestamp":1462196015606},"1":{"uid":1,"firstname":"","lastname":"","username":"2","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"23","job":"32","famsit":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false}],"studies":".","reltype":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"reltypeSpecial":"","city":"","loc":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"loc2":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"duration":["",""],"context":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"contextSpecial":["","",""],"freq":[[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}]],"connect":[[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}]],"connectSpecial":["",""],"hash":3347750419,"valid":false,"timestamp":1462195434069}}}'; + + /* (2) On les met en forme */ + var data = JSON.parse(json); + + /* (3) On met les données dans le 'localStorage' et on recharge la page */ + console.log(data); + lsi.import('subject', data.subject); + lsi.import('contacts', data.contacts); + lsi.import('mini-fiches', data.mini); + lsi.import('fiches', data.fiches); + }, false); + + + /* (9) Gestion de la validation et de l'envoi des données ---------------------------------------------------------*/ submitAllButton.addEventListener('click', function(e){ console.log('> GATHERING ALL DATA')