2016-04-26 14:16:43 +00:00
|
|
|
/* [0] Constructeur -> définit le conteneur et le bouton d'ajout
|
|
|
|
=========================================================*/
|
2016-05-27 14:32:26 +00:00
|
|
|
function inputPhoneSubject(iTmpId, iSubjectId, store_button){
|
2016-05-26 14:47:15 +00:00
|
|
|
this.tmp_id = iTmpId;
|
|
|
|
this.subject_id = iSubjectId;
|
2016-05-18 13:28:02 +00:00
|
|
|
this.store_button = store_button;
|
2016-04-26 14:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* [1] Attributs
|
|
|
|
=========================================================*/
|
|
|
|
inputPhoneSubject.prototype = {
|
2016-05-18 13:28:02 +00:00
|
|
|
store_button: this.store_button, // Bouton d'ajout d'un formulaire
|
|
|
|
tmp_id: this.tmp_id,
|
2016-05-27 14:32:26 +00:00
|
|
|
subject_id: this.subject_id,
|
|
|
|
handler: null
|
2016-04-26 14:16:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
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(){
|
2016-09-27 14:13:51 +00:00
|
|
|
/* (1) Le numéro n'est pas vide (et c'est un numéro) */
|
2016-05-27 14:32:26 +00:00
|
|
|
return this.subject_id.value.length > 0 && !isNaN(this.subject_id.value);
|
2016-05-10 14:51:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* [3] Gestion de l'enregistrement des formulaires de contact
|
|
|
|
=========================================================*/
|
|
|
|
inputPhoneSubject.prototype.fieldsToStorage = function(){
|
2016-05-18 13:28:02 +00:00
|
|
|
console.log('SUBJECT: FIELDS TO STORAGE');
|
2016-05-10 14:51:09 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
// {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
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
// {2} On récupère et met en forme les valeurs du deflater //
|
|
|
|
var obj = {
|
2016-05-26 14:47:15 +00:00
|
|
|
tmp_id: this.tmp_id.value,
|
|
|
|
subject_id: this.subject_id.value
|
2016-05-18 13:28:02 +00:00
|
|
|
};
|
2016-09-30 07:59:42 +00:00
|
|
|
|
2016-04-26 14:16:43 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
// {3} On enregistre les données dans le 'localStorage' //
|
|
|
|
lsi.set('p_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(){
|
2016-05-18 13:28:02 +00:00
|
|
|
console.log('SUBJECT: STORAGE TO FIELDS');
|
2016-04-26 14:16:43 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
// {1} On récupère les informations du sujet //
|
|
|
|
var subjectData = lsi.get('p_subject', 0);
|
2016-04-26 14:16:43 +00:00
|
|
|
|
2016-09-27 14:13:51 +00:00
|
|
|
subjectData = subjectData || { tmp_id: '', subject_id: '' };
|
2016-04-26 14:16:43 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
// {2} On restore les valeurs //
|
2016-05-27 14:32:26 +00:00
|
|
|
this.tmp_id.value = subjectData.tmp_id;
|
|
|
|
this.subject_id.value = subjectData.subject_id;
|
2016-04-26 14:16:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
=========================================================*/
|
2016-05-27 14:32:26 +00:00
|
|
|
inputPhoneSubject.prototype.attach = function(handler){
|
2016-05-18 13:28:02 +00:00
|
|
|
console.log('SUBJECT: ATTACH');
|
2016-04-26 14:16:43 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
/* (1) On initialise le jeu de données */
|
|
|
|
lsi.createDataset('p_subject');
|
2016-05-27 14:32:26 +00:00
|
|
|
lsi.createDataset('p_friends');
|
2016-04-26 14:16:43 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
// Pointeur pour les scopes des addEventListener()
|
2016-05-27 14:32:26 +00:00
|
|
|
this.handler = handler;
|
2016-05-18 13:28:02 +00:00
|
|
|
var ptr = this;
|
|
|
|
// Handler de mise à jour quand les champs sont bons
|
2016-09-27 14:13:51 +00:00
|
|
|
function fts(e){
|
|
|
|
ptr.fieldsToStorage();
|
|
|
|
ptr.handler(true);
|
|
|
|
ptr.storageToFields();
|
|
|
|
}
|
2016-05-10 14:51:09 +00:00
|
|
|
|
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
/* (2) On attache l'évènement sur le bouton d'enregistrement */
|
|
|
|
this.store_button.addEventListener('click', fts, false);
|
2016-05-10 14:51:09 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
/* (3) On attache un évènement de 'blur' sur chaque '<input type="text">' */
|
2016-09-27 14:13:51 +00:00
|
|
|
// this.subject_id.addEventListener('blur', fts, false);
|
2016-04-26 14:16:43 +00:00
|
|
|
|
2016-05-18 13:28:02 +00:00
|
|
|
/* (4) On charge le sujet depuis la mémoire ('localStorage') */
|
|
|
|
this.storageToFields();
|
2016-04-26 14:16:43 +00:00
|
|
|
};
|