Gestion de l'enregistrement d'objets en local (localStorage) /js/lib/local-storage-interface.js
This commit is contained in:
parent
e5382c7a7a
commit
a2de78f80e
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -264,7 +264,7 @@
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
color: #333;
|
color: #333;
|
||||||
|
|
||||||
@include transition( border .2s ease-in-out );
|
@include transition( border .2s ease-in-out, background .2s ease-in-out );
|
||||||
|
|
||||||
/* Animation de @focus*/
|
/* Animation de @focus*/
|
||||||
&:focus{
|
&:focus{
|
||||||
|
@ -272,6 +272,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Before pour les submit
|
||||||
|
& input[type='submit'][data-store]{
|
||||||
|
|
||||||
|
&:before{
|
||||||
|
/* Icone de sauvegarde */
|
||||||
|
content: 'y ';
|
||||||
|
|
||||||
|
font-size: 1em;
|
||||||
|
font-family: 'icomoon';
|
||||||
|
color: #fff;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
& label{
|
& label{
|
||||||
color: #555;
|
color: #555;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,3 @@
|
||||||
|
function localStorageInterface(){}
|
||||||
|
localStorageInterface.prototype={dataset:[],dataset_keys:[],set:function(a,b,d){var c=this.dataset.indexOf(a);if(-1==c)return!1;this.dataset_keys[c].push(b);localStorage.setItem(a,this.dataset_keys[c].join(","));localStorage.setItem(a+"_"+b,d);return!0},get:function(a,b){return-1==this.dataset.indexOf(a)?!1:localStorage.getItem(a+"_"+b)},setObject:function(a,b){if(-1==this.dataset.indexOf(a))return!1;for(var d in b)this.set(a,d,b[d]);return!0},getObject:function(a){var b=this.dataset.indexOf(a);if(-1==
|
||||||
|
b)return!1;for(var d={},c=0;c<this.dataset_keys[b].length;c++)d[this.dataset_keys[b][c]]=this.get(a,this.dataset_keys[b][c]);return d},createDataset:function(a){if(null==a||"string"!=typeof a)return!1;if(-1<this.dataset.indexOf(a))return!0;var b=localStorage.getItem(a);null!=b?(this.dataset.push(a),this.dataset_keys.push(b.split(","))):(this.dataset.push(a),this.dataset_keys.push([]),localStorage.setItem(a,""));return!0}};var lsi=new localStorageInterface;
|
|
@ -0,0 +1,121 @@
|
||||||
|
function localStorageInterface(){}
|
||||||
|
|
||||||
|
localStorageInterface.prototype = {
|
||||||
|
|
||||||
|
dataset: [], // Contiendra les différents 'dataset'
|
||||||
|
dataset_keys: [], // Contiendra les clés de chaque 'dataset'
|
||||||
|
|
||||||
|
|
||||||
|
/* AJOUTE UN ELEMENT AU DATASET DONNE
|
||||||
|
*
|
||||||
|
* @dataset_name<String> Nom du dataset en question
|
||||||
|
* @key<String> Clé à donner à l'élément
|
||||||
|
* @value<String> Valeur de l'élément
|
||||||
|
*
|
||||||
|
* @return error<Bool> Retourne FALSE si erreur, sinon TRUE
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
set: function(dataset_name, key, value){
|
||||||
|
var index = this.dataset.indexOf(dataset_name);
|
||||||
|
|
||||||
|
/* (1) Si le 'dataset' n'existe pas */
|
||||||
|
if( index == -1 ) return false; // erreur
|
||||||
|
|
||||||
|
/* (2) On enregistre la nouvelle clé */
|
||||||
|
this.dataset_keys[index].push(key);
|
||||||
|
localStorage.setItem(dataset_name, this.dataset_keys[index].join(','));
|
||||||
|
|
||||||
|
/* (3) On propage au 'localStorage' */
|
||||||
|
localStorage.setItem(dataset_name+'_'+key, value);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
/* RETOURNE UN ELEMENT AU DATASET DONNE
|
||||||
|
*
|
||||||
|
* @dataset_name<String> Nom du dataset en question
|
||||||
|
* @key<String> Clé de l'élément
|
||||||
|
*
|
||||||
|
* @return value<String> Retourne la valeur de l'élément, sinon FALSE si erreur
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
get: function(dataset_name, key){
|
||||||
|
/* (1) Si le 'dataset' n'existe pas */
|
||||||
|
if( this.dataset.indexOf(dataset_name) == -1 ) return false; // erreur
|
||||||
|
|
||||||
|
/* (2) On propage au 'localStorage' */
|
||||||
|
return localStorage.getItem(dataset_name+'_'+key);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
setObject: function(dataset_name, object){
|
||||||
|
/* (1) Si le 'dataset' n'existe pas */
|
||||||
|
var index = this.dataset.indexOf(dataset_name);
|
||||||
|
if( index == -1 ) return false; // erreur
|
||||||
|
|
||||||
|
/* (2) On met toutes les valeurs de l'objet dans le 'localStorage' */
|
||||||
|
for( var key in object )
|
||||||
|
this.set(dataset_name, key, object[key]);
|
||||||
|
|
||||||
|
/* (3) On retourne que tout s'est bien passé */
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
getObject: function(dataset_name){
|
||||||
|
/* (1) Si le 'dataset' n'existe pas */
|
||||||
|
var index = this.dataset.indexOf(dataset_name);
|
||||||
|
if( index == -1 ) return false; // erreur
|
||||||
|
|
||||||
|
/* (2) On récupère toutes les valeurs dans un objet */
|
||||||
|
var obj = {};
|
||||||
|
for( var i = 0 ; i < this.dataset_keys[index].length ; i++ )
|
||||||
|
obj[this.dataset_keys[index][i]] = this.get(dataset_name, this.dataset_keys[index][i]);
|
||||||
|
|
||||||
|
/* (3) On retourne l'objet */
|
||||||
|
return obj;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/* CREATION D'UN DATASET OU RECUPERATION DES DONNEES S'IL EXISTE DEJA
|
||||||
|
*
|
||||||
|
* @name<String> Nom du dataset à créer ou récupérer
|
||||||
|
*
|
||||||
|
* @return error<Bool> Retourne true si tout s'est bien passé, sinon false
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
createDataset: function(name){
|
||||||
|
/* (1) On vérifie que le @name est correct */
|
||||||
|
if( name == null || 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;
|
||||||
|
|
||||||
|
/* (3) On charge le dataset s'il existe */
|
||||||
|
var storedDataset = localStorage.getItem(name);
|
||||||
|
if( storedDataset != null ){ // Si le dataset existe, on charge les données
|
||||||
|
|
||||||
|
this.dataset.push(name);
|
||||||
|
this.dataset_keys.push( storedDataset.split(',') );
|
||||||
|
|
||||||
|
/* (4) Sinon, on le crée 'dataset' */
|
||||||
|
}else{
|
||||||
|
|
||||||
|
this.dataset.push(name);
|
||||||
|
this.dataset_keys.push([]);
|
||||||
|
localStorage.setItem(name, '');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var lsi = new localStorageInterface();
|
1
view.php
1
view.php
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
|
|
||||||
<!-- Dépendences Javascript -->
|
<!-- Dépendences Javascript -->
|
||||||
|
<script type='text/javascript' src='/f/js/local-storage-interface-min/js/lib' ></script> <!-- Interface de gestion du 'localStorage' -->
|
||||||
<script type='text/javascript' src='/f/js/input-checker-min/js/lib' ></script> <!-- Gestion dynamique des saisies -->
|
<script type='text/javascript' src='/f/js/input-checker-min/js/lib' ></script> <!-- Gestion dynamique des saisies -->
|
||||||
<script type='text/javascript' src='/f/js/form-deflater-min/js/lib' ></script> <!-- Gestion des formulaires js-friendly -->
|
<script type='text/javascript' src='/f/js/form-deflater-min/js/lib' ></script> <!-- Gestion des formulaires js-friendly -->
|
||||||
<script type='text/javascript' src='/f/js/reset-min/js/lib' ></script> <!-- Corrections Javascript natif (ajouts) -->
|
<script type='text/javascript' src='/f/js/reset-min/js/lib' ></script> <!-- Corrections Javascript natif (ajouts) -->
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<input type='text' data-name='username' placeholder='Pseudo'>
|
<input type='text' data-name='username' placeholder='Pseudo'>
|
||||||
<input type='text' data-name='firstname' placeholder='Prénom'>
|
<input type='text' data-name='firstname' placeholder='Prénom'>
|
||||||
<input type='text' data-name='lastname' placeholder='Nom'>
|
<input type='text' data-name='lastname' placeholder='Nom'>
|
||||||
<input type='submit' class='primary sub-number' value='Enregistrer'>
|
<input type='submit' class='primary' data-name='submit' data-store value='Enregistrer'>
|
||||||
</h4>
|
</h4>
|
||||||
<span data-space></span>
|
<span data-space></span>
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
<input type='text' data-name='username' placeholder='Pseudo'>
|
<input type='text' data-name='username' placeholder='Pseudo'>
|
||||||
<input type='text' data-name='firstname' placeholder='Prénom'>
|
<input type='text' data-name='firstname' placeholder='Prénom'>
|
||||||
<input type='text' data-name='lastname' placeholder='Nom'>
|
<input type='text' data-name='lastname' placeholder='Nom'>
|
||||||
<input type='submit' class='primary sub-number' value='Enregistrer'>
|
<input type='submit' class='primary sub-number' data-store value='Enregistrer'>
|
||||||
</h4>
|
</h4>
|
||||||
<h4 data-icon='+' class='add-contact line' style='cursor: pointer;'>Ajouter un contact</h4>
|
<h4 data-icon='+' class='add-contact line' style='cursor: pointer;'>Ajouter un contact</h4>
|
||||||
<!-- <span data-tag='ET'></span> -->
|
<!-- <span data-tag='ET'></span> -->
|
||||||
|
|
|
@ -1,3 +1,24 @@
|
||||||
|
// STRUCTURE DU localStorage
|
||||||
|
// subject-data -> contient
|
||||||
|
// contacts-data
|
||||||
|
// fiches-relation
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [0] Gestion des constantes et fonctions
|
/* [0] Gestion des constantes et fonctions
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* (1) Contiendra le formulaire d'ajout de contact (numéro, pseudo, prénom, nom, submit) */
|
/* (1) Contiendra le formulaire d'ajout de contact (numéro, pseudo, prénom, nom, submit) */
|
||||||
|
|
Loading…
Reference in New Issue