2016-04-22 12:44:23 +00:00
|
|
|
// STRUCTURE DU localStorage
|
2016-04-27 16:32:44 +00:00
|
|
|
// subject -> contient les données du sujet
|
|
|
|
// contacts -> contient les données de tous les contacts
|
|
|
|
// mini-fiches -> contient les données de toutes les mini fiches
|
|
|
|
// fiches -> contient les données de toutes les fiches
|
2016-04-22 17:35:05 +00:00
|
|
|
|
|
|
|
|
2016-04-26 14:16:43 +00:00
|
|
|
/* [1] Initialisation des utilitaires et variables
|
2016-04-21 09:46:24 +00:00
|
|
|
=========================================================*/
|
2016-04-30 09:33:01 +00:00
|
|
|
/* (1) Boutons primaires */
|
|
|
|
// {1} pour effacer toutes les données //
|
|
|
|
var clearAllButton = $('#clear-all');
|
|
|
|
// {2} pour envoyer toutes les données //
|
|
|
|
var submitAllButton = $('#submit-all');
|
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
|
|
|
|
/* (2) Input de type fichier pour l'import */
|
2016-04-26 14:16:43 +00:00
|
|
|
var importCallLog = $('input#call_log-import[type="file"]');
|
2016-04-21 13:22:43 +00:00
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (3) Initialisation des managers */
|
2016-04-26 14:16:43 +00:00
|
|
|
var subjectManager;
|
|
|
|
var contactManager;
|
|
|
|
var miniManager;
|
|
|
|
var ficheManager;
|
2016-04-21 14:41:11 +00:00
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (4) Fonctions utiles */
|
|
|
|
function dynamicUpdate(target){
|
2016-04-28 15:49:13 +00:00
|
|
|
|
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (0) Vérification de la cohérence de la @target
|
|
|
|
---------------------------------------------------------*/
|
2016-04-28 15:49:13 +00:00
|
|
|
var isElement = target instanceof Element;
|
2016-04-30 09:33:01 +00:00
|
|
|
var isSwitchLeft = isElement && target.tagName == 'SPAN' && target.className == 'switch-left';
|
|
|
|
var isSwitchBoth = isElement && target.tagName == 'SPAN' && target.className == 'switch-both';
|
|
|
|
var isSaveButton = isElement && target.tagName == 'INPUT' && target.type == 'submit';
|
2016-04-28 15:49:13 +00:00
|
|
|
var isNavButton = isElement && target.tagName == 'SPAN' && (target.parentNode.id == 'nav-mini' || target.parentNode.id == 'nav-fiche');
|
2016-04-30 09:33:01 +00:00
|
|
|
var isNavContact = isElement && target.tagName == 'SPAN' && target.parentNode.id == 'nav-contact';
|
2016-04-28 14:00:49 +00:00
|
|
|
|
|
|
|
// Si erreur, on retourne une erreur
|
2016-04-29 13:24:03 +00:00
|
|
|
if( !isSwitchBoth && !isSwitchLeft && !isSaveButton && !isNavButton && !isNavContact && target !== true )
|
2016-04-28 14:00:49 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (1) Gestion de l'échange de nom/prénom
|
|
|
|
---------------------------------------------------------*/
|
2016-04-28 14:32:09 +00:00
|
|
|
if( isSwitchBoth ){
|
2016-04-28 14:00:49 +00:00
|
|
|
console.log('> switch firstname <-> lastname');
|
|
|
|
|
|
|
|
/* (1) On récupère le formulaire parent */
|
|
|
|
var currentForm = target.parentNode;
|
|
|
|
|
|
|
|
/* (2) On récupère Nom et Prénom */
|
2016-04-28 14:32:09 +00:00
|
|
|
var firstname = currentForm.children[3];
|
|
|
|
var lastname = currentForm.children[5];
|
2016-04-28 14:00:49 +00:00
|
|
|
|
|
|
|
/* (3) On échange leurs valeurs */
|
|
|
|
var tmp = firstname.value;
|
|
|
|
firstname.value = lastname.value;
|
|
|
|
lastname.value = tmp;
|
2016-04-26 16:44:39 +00:00
|
|
|
|
2016-04-28 14:32:09 +00:00
|
|
|
}else if( isSwitchLeft ){
|
|
|
|
/* (2) Gestion de l'échange Prénom+Nom = Pseudo
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
console.log('> switch firstname+lastname -> username');
|
|
|
|
|
|
|
|
/* (1) On récupère le formulaire parent */
|
|
|
|
var currentForm = target.parentNode;
|
2016-04-26 16:44:39 +00:00
|
|
|
|
2016-04-28 14:32:09 +00:00
|
|
|
/* (2) On récupère Pseudo, Nom et Prénom */
|
|
|
|
var username = currentForm.children[1];
|
|
|
|
var firstname = currentForm.children[3];
|
|
|
|
var lastname = currentForm.children[5];
|
|
|
|
|
2016-04-29 17:24:56 +00:00
|
|
|
/* (3) Vérification de la validité */
|
|
|
|
// Si pseudo pas vide, ou nom et prenom vide -> on ne fais rien
|
|
|
|
if( username.value.length > 0 || firstname.value.length == 0 && lastname.value.length == 0 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* (4) On attribue à Pseudo, la valeur de Prénom+Nom */
|
2016-04-28 14:32:09 +00:00
|
|
|
username.value = firstname.value +' '+ lastname.value;
|
|
|
|
firstname.value = '';
|
|
|
|
lastname.value = '';
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Gestion de la mise à jour dynamique
|
2016-04-28 14:00:49 +00:00
|
|
|
---------------------------------------------------------*/
|
|
|
|
}else{
|
|
|
|
console.log('> dynamic update');
|
2016-04-21 14:41:11 +00:00
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (1) On enregistre les MINI fiches relation */
|
|
|
|
miniManager.fieldsToStorage();
|
2016-04-21 14:41:11 +00:00
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (2) On enregister les FICHES relation */
|
|
|
|
ficheManager.fieldsToStorage();
|
2016-04-21 14:41:11 +00:00
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (3) On enregistre les CONTACTS */
|
|
|
|
contactManager.fieldsToStorage();
|
2016-04-22 13:51:17 +00:00
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (4) On synchronise les MINI avec les CONTACTS */
|
|
|
|
miniManager.sync();
|
2016-04-22 17:35:05 +00:00
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (5) On synchronise les FICHE avec les CONTACTS */
|
|
|
|
ficheManager.sync();
|
|
|
|
|
|
|
|
/* (6) On affiche le tout */
|
|
|
|
miniManager.storageToFields();
|
|
|
|
ficheManager.storageToFields();
|
2016-04-28 16:58:18 +00:00
|
|
|
|
2016-04-29 13:24:03 +00:00
|
|
|
/* (7) On met à jour les contacts si on les a modifié on si on navigue dans les contacts */
|
|
|
|
if( isSaveButton || isNavContact )
|
2016-04-28 16:58:18 +00:00
|
|
|
contactManager.storageToFields();
|
2016-04-28 14:00:49 +00:00
|
|
|
}
|
2016-04-26 14:16:43 +00:00
|
|
|
}
|
2016-04-22 17:35:05 +00:00
|
|
|
|
2016-04-27 16:04:54 +00:00
|
|
|
// Vérifie qu'une seule valeur vaut TRUE et les autres false
|
|
|
|
function checkRadioValue(selectData){
|
|
|
|
var nbTrue = 0;
|
|
|
|
for( var i = 0 ; i < selectData.length ; i++ )
|
|
|
|
if( selectData[i].status === true )
|
|
|
|
nbTrue++;
|
|
|
|
|
|
|
|
if( nbTrue != 1 ) return false;
|
|
|
|
else return true;
|
|
|
|
}
|
2016-04-22 17:35:05 +00:00
|
|
|
|
|
|
|
|
2016-04-28 16:58:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-22 17:35:05 +00:00
|
|
|
|
2016-04-26 14:16:43 +00:00
|
|
|
/* [2] Inclusion des scripts externes et lancement
|
|
|
|
=========================================================*/
|
|
|
|
include('/js/includes/input-phone-subject.js', function(){
|
|
|
|
include('/js/includes/input-phone-contact.js', function(){
|
|
|
|
include('/js/includes/input-phone-mini.js', function(){
|
|
|
|
include('/js/includes/input-phone-fiche.js', function(){
|
|
|
|
|
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (1) Gestion du formulaire du sujet
|
|
|
|
---------------------------------------------------------*/
|
2016-04-26 14:16:43 +00:00
|
|
|
/* (1) On crée une instance du manager du sujet */
|
|
|
|
subjectManager = new inputPhoneSubject(
|
|
|
|
$('article.subject-panel [data-name="number"]'),
|
|
|
|
$('article.subject-panel [data-name="username"]'),
|
|
|
|
$('article.subject-panel [data-name="firstname"]'),
|
|
|
|
$('article.subject-panel [data-name="lastname"]'),
|
|
|
|
$('article.subject-panel [data-name="submit"]')
|
|
|
|
);
|
2016-04-22 17:35:05 +00:00
|
|
|
|
2016-04-26 14:16:43 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
subjectManager.attach();
|
2016-04-22 17:35:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (2) Gestion des formulaires de contact
|
|
|
|
---------------------------------------------------------*/
|
2016-04-26 14:16:43 +00:00
|
|
|
/* (1) On crée une instance du gestionnaire des CONTACTS */
|
|
|
|
contactManager = new inputPhoneContact(
|
|
|
|
$('article.contact-panel'),
|
2016-04-29 13:24:03 +00:00
|
|
|
$('#nav-contact')
|
2016-04-26 14:16:43 +00:00
|
|
|
);
|
2016-04-22 17:35:05 +00:00
|
|
|
|
2016-04-26 14:16:43 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
contactManager.attach(dynamicUpdate);
|
2016-04-22 17:35:05 +00:00
|
|
|
|
2016-04-21 09:46:24 +00:00
|
|
|
|
2016-04-22 13:51:17 +00:00
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (3) Gestion des mini fiches relation
|
|
|
|
---------------------------------------------------------*/
|
2016-04-26 14:16:43 +00:00
|
|
|
/* (1) On crée une instance du gestionnaire des mini fiches relation */
|
|
|
|
miniManager = new inputPhoneMini(
|
2016-04-26 16:44:39 +00:00
|
|
|
$('article.mini-relation-panel'),
|
|
|
|
$('#nav-mini')
|
2016-04-26 14:16:43 +00:00
|
|
|
);
|
2016-04-21 14:41:11 +00:00
|
|
|
|
2016-04-27 09:36:07 +00:00
|
|
|
/* (2) On le démarre */
|
2016-04-27 09:22:03 +00:00
|
|
|
miniManager.attach(dynamicUpdate);
|
2016-04-21 14:41:11 +00:00
|
|
|
|
2016-04-22 14:40:06 +00:00
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (4) Gestion des fiches relation
|
|
|
|
---------------------------------------------------------*/
|
2016-04-26 14:16:43 +00:00
|
|
|
/* (1) On crée une instance du gestionnaire des fiches relation */
|
2016-04-27 12:32:54 +00:00
|
|
|
ficheManager = new inputPhoneFiche(
|
|
|
|
$('article.relation-panel'),
|
|
|
|
$('#nav-fiche')
|
|
|
|
);
|
|
|
|
|
|
|
|
/* (2) On le démarre */
|
|
|
|
ficheManager.attach(dynamicUpdate);
|
2016-04-22 14:40:06 +00:00
|
|
|
|
|
|
|
|
2016-04-22 17:35:05 +00:00
|
|
|
|
2016-04-27 16:32:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (5) Gestion de l'import du fichier
|
|
|
|
---------------------------------------------------------*/
|
2016-04-27 16:32:44 +00:00
|
|
|
importCallLog.addEventListener('change', function(e){
|
|
|
|
/* (1) On rédige la requête */
|
|
|
|
var uploadRequest = {
|
|
|
|
path: 'upload/call_log',
|
|
|
|
file: importCallLog.files[0]
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (2) On effectue l'upload (import) */
|
2016-04-27 17:54:11 +00:00
|
|
|
api.send(uploadRequest, function(uploadResponse){
|
2016-04-28 09:42:08 +00:00
|
|
|
console.log(uploadResponse);
|
|
|
|
|
2016-04-27 16:32:44 +00:00
|
|
|
// Si tout est bon, on met l'input en bleu
|
2016-04-27 17:54:11 +00:00
|
|
|
if( uploadResponse.ModuleError == 0 ){
|
2016-04-27 16:32:44 +00:00
|
|
|
importCallLog.addClass('active');
|
2016-04-27 17:54:11 +00:00
|
|
|
|
|
|
|
/* (3) On rédige la requête pour récupérer les données du fichier */
|
2016-04-28 16:00:09 +00:00
|
|
|
var callLogRequest = {
|
2016-04-27 17:54:11 +00:00
|
|
|
path: 'call_log/unserialize',
|
|
|
|
phone_number: $('#subject_phone_number').value
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (4) On effectue la récupération d'informations */
|
2016-04-28 16:00:09 +00:00
|
|
|
api.send(callLogRequest, function(dataResponse){
|
2016-04-27 17:54:11 +00:00
|
|
|
console.log(dataResponse);
|
2016-04-28 09:42:08 +00:00
|
|
|
|
2016-04-28 15:49:13 +00:00
|
|
|
// Si erreur, on quitte
|
|
|
|
if( dataResponse.ModuleError != 0 )
|
|
|
|
return;
|
|
|
|
|
2016-04-28 16:00:09 +00:00
|
|
|
|
|
|
|
|
2016-04-28 15:49:13 +00:00
|
|
|
/* (5) Pour chaque contact de l'annuaire, on ajoute un contact */
|
2016-04-28 16:00:09 +00:00
|
|
|
for( var i = 0 ; i < dataResponse.directory.length ; i++ ){
|
|
|
|
|
2016-04-28 15:49:13 +00:00
|
|
|
// On découpe le nom par espaces
|
2016-04-28 16:00:09 +00:00
|
|
|
var name = dataResponse.directory[i].name===null ? '' : dataResponse.directory[i].name;
|
|
|
|
var splitted = name.split(' ');
|
2016-04-28 15:49:13 +00:00
|
|
|
|
2016-04-30 14:13:37 +00:00
|
|
|
lsi.set('contacts', i, {
|
2016-04-28 16:00:09 +00:00
|
|
|
uid: i,
|
2016-04-28 15:49:13 +00:00
|
|
|
number: dataResponse.directory[i].number,
|
|
|
|
username: splitted.length == 1 ? splitted[0] : '', // Si un seul mot -> pseudo
|
|
|
|
firstname: splitted.length > 1 ? splitted[0] : '', // Si plusieurs mots -> le 1er est le prénom
|
|
|
|
lastname: splitted.length > 1 ? splitted.splice(1).join(' ') : '' // et les autres sont le nom
|
|
|
|
});
|
2016-04-28 09:42:08 +00:00
|
|
|
}
|
2016-04-28 15:49:13 +00:00
|
|
|
|
|
|
|
/* (6) On met à jour l'affichage */
|
2016-04-28 16:49:49 +00:00
|
|
|
contactManager.storageToFields();
|
2016-04-28 15:49:13 +00:00
|
|
|
dynamicUpdate(true);
|
2016-04-27 17:54:11 +00:00
|
|
|
});
|
2016-04-27 16:32:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
/* (6) Gestion de l'effacement des données locales
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
clearAllButton.addEventListener('click', function(e){
|
|
|
|
localStorage.clear();
|
|
|
|
reload();
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-04-30 09:33:01 +00:00
|
|
|
/* (7) Gestion de la validation et de l'envoi des données
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
submitAllButton.addEventListener('click', function(e){
|
|
|
|
console.log('> GATHERING ALL DATA')
|
|
|
|
|
|
|
|
/* (1) On met dans la mémoire tout les champs non enregistrés */
|
|
|
|
subjectManager.fieldsToStorage();
|
|
|
|
contactManager.fieldsToStorage();
|
|
|
|
miniManager.fieldsToStorage();
|
|
|
|
ficheManager.fieldsToStorage();
|
|
|
|
|
2016-04-30 14:13:37 +00:00
|
|
|
/* (2) On prépare la requête avec toutes les données */
|
2016-04-30 09:33:01 +00:00
|
|
|
var request = {
|
|
|
|
path: 'input/phone',
|
2016-04-30 10:19:51 +00:00
|
|
|
|
|
|
|
subject: lsi.export('subject')[0],
|
|
|
|
contacts: lsi.export('contacts'),
|
|
|
|
mini: lsi.export('mini-fiches'),
|
2016-04-30 14:13:37 +00:00
|
|
|
fiches: lsi.export('fiches')
|
2016-04-30 09:33:01 +00:00
|
|
|
};
|
|
|
|
|
2016-04-30 14:13:37 +00:00
|
|
|
/* (3) On envoie la requête et traite la réponse */
|
2016-04-30 09:33:01 +00:00
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-04-27 16:32:44 +00:00
|
|
|
|
2016-04-30 14:50:46 +00:00
|
|
|
}); }); }); });
|
2016-04-26 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-26 14:16:43 +00:00
|
|
|
// ETAPE 1 : INITIALISATION (ON RESTAURE LES DONNEES)
|
|
|
|
// 1. contact.storageToFields();
|
|
|
|
// 2. contact.add();
|
|
|
|
// 3. mini.storageToFields();
|
|
|
|
// 4. fiche.storageToFields();
|
2016-04-26 09:30:02 +00:00
|
|
|
|
2016-04-26 14:16:43 +00:00
|
|
|
// ETAPE 2 : ENREGISTREMENT + MISE À JOUR
|
|
|
|
// 1. mini.fieldsToStorage();
|
|
|
|
// 2. fiche.fieldsToStorage();
|
|
|
|
// 3. contact.fieldsToStorage();
|
|
|
|
// 4. mini.sync();
|
|
|
|
// 5. fiche.sync();
|
2016-04-26 09:30:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-21 14:41:11 +00:00
|
|
|
|
2016-04-26 09:30:02 +00:00
|
|
|
|
2016-04-22 17:35:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-27 16:32:44 +00:00
|
|
|
|
2016-04-21 09:26:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-22 08:27:58 +00:00
|
|
|
// var number = $('input.number[type="text"]');
|
2016-04-21 13:22:43 +00:00
|
|
|
// ic.append(number, format_number, '06 06 06 06 06');
|
|
|
|
// // format_number -> format pour les numéros de téléphones
|
|
|
|
//
|
|
|
|
// number.addEventListener('keyup', function(e){
|
|
|
|
// ic.correct(number, false);
|
|
|
|
// }, false);
|