2016-04-26 14:16:43 +00:00
|
|
|
/* [0] Constructeur -> définit le conteneur et le bouton d'ajout
|
|
|
|
=========================================================*/
|
2016-05-12 19:47:52 +00:00
|
|
|
function inputPhoneSubject(iTmpId, iNumber, iUsername, iFirstname, iLastname, store_button){
|
|
|
|
this.tmp_id = iTmpId;
|
2016-04-26 14:16:43 +00:00
|
|
|
this.number = iNumber;
|
|
|
|
this.username = iUsername;
|
|
|
|
this.firstname = iFirstname;
|
|
|
|
this.lastname = iLastname;
|
|
|
|
|
|
|
|
this.store_button = store_button;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* [1] Attributs
|
|
|
|
=========================================================*/
|
|
|
|
inputPhoneSubject.prototype = {
|
|
|
|
store_button: this.store_button, // Bouton d'ajout d'un formulaire
|
2016-05-12 19:47:52 +00:00
|
|
|
tmp_id: this.tmp_id,
|
2016-04-26 14:16:43 +00:00
|
|
|
number: this.number,
|
|
|
|
username: this.username,
|
|
|
|
firstname: this.firstname,
|
|
|
|
lastname: this.lastname
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-05-10 14:51:09 +00:00
|
|
|
/* [2] Vérification d'un formulaire
|
2016-04-26 14:16:43 +00:00
|
|
|
=========================================================*/
|
2016-05-10 14:51:09 +00:00
|
|
|
inputPhoneSubject.prototype.check = function(){
|
|
|
|
/* (1) Le numéro n'est pas vide */
|
2016-04-26 14:16:43 +00:00
|
|
|
var validForm = this.number.value.length > 0;
|
2016-05-10 14:51:09 +00:00
|
|
|
|
|
|
|
/* (2) ET le pseudo et/ou le prénom et/ou le nom n'est pas vide */
|
2016-04-26 14:16:43 +00:00
|
|
|
validForm = validForm && this.username.value.length+this.firstname.value.length+this.lastname.value.length > 0;
|
|
|
|
|
2016-05-10 14:51:09 +00:00
|
|
|
// On renvoie la validité du formulaire
|
|
|
|
return validForm;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* [3] Gestion de l'enregistrement des formulaires de contact
|
|
|
|
=========================================================*/
|
|
|
|
inputPhoneSubject.prototype.fieldsToStorage = function(){
|
|
|
|
console.log('SUBJECT: FIELDS TO STORAGE');
|
|
|
|
|
|
|
|
// {1} Si le formulaire n'est pas valide, on ne l'enregistre pas //
|
|
|
|
if( !this.check() ) return false;
|
2016-04-26 14:16:43 +00:00
|
|
|
|
|
|
|
// {2} On récupère et met en forme les valeurs du deflater //
|
|
|
|
var obj = {
|
2016-05-12 19:47:52 +00:00
|
|
|
tmp_id: this.tmp_id.value,
|
2016-04-26 14:16:43 +00:00
|
|
|
number: this.number.value,
|
|
|
|
username: this.username.value,
|
|
|
|
firstname: this.firstname.value,
|
|
|
|
lastname: this.lastname.value
|
|
|
|
};
|
|
|
|
|
|
|
|
// {3} On enregistre les données dans le 'localStorage' //
|
2016-04-30 10:19:51 +00:00
|
|
|
lsi.set('subject', 0, obj);
|
2016-04-26 14:16:43 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-10 14:51:09 +00:00
|
|
|
/* [4] Gestion de l'affichage depuis le 'localStorage'
|
2016-04-26 14:16:43 +00:00
|
|
|
=========================================================*/
|
|
|
|
inputPhoneSubject.prototype.storageToFields = function(){
|
|
|
|
console.log('SUBJECT: STORAGE TO FIELDS');
|
|
|
|
|
|
|
|
// {1} On récupère les informations du sujet //
|
2016-04-30 10:19:51 +00:00
|
|
|
var subjectData = lsi.get('subject', 0);
|
2016-04-26 14:16:43 +00:00
|
|
|
|
2016-05-03 20:28:47 +00:00
|
|
|
if( subjectData == null )
|
2016-05-12 19:47:52 +00:00
|
|
|
subjectData = { tmp_id: '', number: '', username: '', firstname: '', lastname: '' };
|
2016-04-26 14:16:43 +00:00
|
|
|
|
|
|
|
// {2} On restore les valeurs //
|
2016-05-12 19:47:52 +00:00
|
|
|
this.tmp_id.value = subjectData.tmp_id;
|
2016-04-26 14:16:43 +00:00
|
|
|
this.number.value = subjectData.number;
|
|
|
|
this.username.value = subjectData.username;
|
|
|
|
this.firstname.value = subjectData.firstname;
|
|
|
|
this.lastname.value = subjectData.lastname;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-10 14:51:09 +00:00
|
|
|
/* [5] Point d'amorçage de la gestion des contacts
|
2016-04-26 14:16:43 +00:00
|
|
|
=========================================================*/
|
|
|
|
inputPhoneSubject.prototype.attach = function(){
|
|
|
|
console.log('SUBJECT: ATTACH');
|
|
|
|
|
|
|
|
/* (1) On initialise le jeu de données */
|
|
|
|
lsi.createDataset('subject');
|
|
|
|
|
2016-05-10 14:51:09 +00:00
|
|
|
// Pointeur pour les scopes des addEventListener()
|
2016-04-26 14:16:43 +00:00
|
|
|
var ptr = this;
|
2016-05-10 14:51:09 +00:00
|
|
|
// Handler de mise à jour quand les champs sont bons
|
|
|
|
function fts(e){ if( ptr.fieldsToStorage() ) ptr.storageToFields(); }
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On attache l'évènement sur le bouton d'enregistrement */
|
|
|
|
this.store_button.addEventListener('click', fts, false);
|
|
|
|
|
|
|
|
/* (3) On attache un évènement de 'blur' sur chaque '<input type="text">' */
|
|
|
|
this.number.addEventListener( 'blur', fts, false);
|
|
|
|
this.username.addEventListener( 'blur', fts, false);
|
|
|
|
this.firstname.addEventListener( 'blur', fts, false);
|
|
|
|
this.lastname.addEventListener( 'blur', fts, false);
|
2016-04-26 14:16:43 +00:00
|
|
|
|
2016-05-10 14:51:09 +00:00
|
|
|
/* (4) On charge le sujet depuis la mémoire ('localStorage') */
|
2016-04-26 14:16:43 +00:00
|
|
|
this.storageToFields();
|
|
|
|
};
|