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-05-08 16:31:58 +00:00
|
|
|
// matrice -> contient les relations de la matrice
|
2016-04-22 17:35:05 +00:00
|
|
|
|
|
|
|
|
2016-04-26 14:16:43 +00:00
|
|
|
/* [1] Initialisation des utilitaires et variables
|
2016-05-08 16:31:58 +00:00
|
|
|
=========================================================*
|
|
|
|
/* (1) Initialisation des managers */
|
2016-04-26 14:16:43 +00:00
|
|
|
var subjectManager;
|
|
|
|
var contactManager;
|
|
|
|
var miniManager;
|
|
|
|
var ficheManager;
|
2016-05-08 17:11:03 +00:00
|
|
|
var matriceManager;
|
2016-04-21 14:41:11 +00:00
|
|
|
|
2016-05-08 13:25:20 +00:00
|
|
|
|
2016-05-08 16:31:58 +00:00
|
|
|
/* (2) Fonctions utiles */
|
2016-04-28 14:00:49 +00:00
|
|
|
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-05-04 17:28:20 +00:00
|
|
|
var firstname = currentForm.children[8];
|
|
|
|
var lastname = currentForm.children[10];
|
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 */
|
2016-05-04 17:28:20 +00:00
|
|
|
var username = currentForm.children[6];
|
|
|
|
var firstname = currentForm.children[8];
|
|
|
|
var lastname = currentForm.children[10];
|
2016-04-28 14:32:09 +00:00
|
|
|
|
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-05-08 21:32:07 +00:00
|
|
|
/* (4) On enregistre la MATRICE */
|
|
|
|
matriceManager.fieldsToStorage();
|
|
|
|
|
2016-05-11 17:34:52 +00:00
|
|
|
/* (5) On synchronise les FICHE avec les CONTACTS */
|
2016-05-04 17:02:44 +00:00
|
|
|
// 1. On synchronise les `mini` et `fiches` associées en fonction de la dernière date de modification
|
|
|
|
// 2. On synchronise les `fiches` dupliquées en fonction de la dernière date de modification
|
2016-04-28 14:00:49 +00:00
|
|
|
ficheManager.sync();
|
|
|
|
|
2016-05-11 17:34:52 +00:00
|
|
|
/* (6) On synchronise les MINI avec les CONTACTS */
|
|
|
|
// Supprime les contacts déja dans les FICHES
|
|
|
|
miniManager.sync();
|
2016-05-02 10:22:54 +00:00
|
|
|
|
2016-05-08 21:32:07 +00:00
|
|
|
/* (7) On affiche le tout */
|
2016-04-28 14:00:49 +00:00
|
|
|
miniManager.storageToFields();
|
|
|
|
ficheManager.storageToFields();
|
2016-05-08 21:32:07 +00:00
|
|
|
matriceManager.storageToFields();
|
2016-04-28 16:58:18 +00:00
|
|
|
|
2016-05-08 21:32:07 +00:00
|
|
|
/* (8) On met à jour les contacts si on les a modifié on si on navigue dans les contacts */
|
2016-04-29 13:24:03 +00:00
|
|
|
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-28 16:58:18 +00:00
|
|
|
|
|
|
|
|
2016-05-11 20:02:20 +00:00
|
|
|
/* AFFICHE UN NOM EXPLICITE A PARTIR DE @u username, @f firstname, et @l lastname
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function readableName(u, f, l){
|
|
|
|
/* (1) On calcule les tailles des chaines */
|
|
|
|
var ul = u.length,
|
|
|
|
fl = f.length,
|
|
|
|
ll = l.length;
|
|
|
|
|
|
|
|
/* (2) Si @username n'est pas vide */
|
|
|
|
if( ul > 0 ){
|
|
|
|
|
|
|
|
/* (3) Si @username+(@firstname et/ou @lastname) -> username (firstname lastname) */
|
|
|
|
if( fl+ll > 0 )
|
|
|
|
return u+' ('+(f+' '+l).trim()+')';
|
|
|
|
|
|
|
|
/* (4) Si @username uniquement -> username */
|
|
|
|
else
|
|
|
|
return u;
|
|
|
|
|
|
|
|
/* (5) Si pas @username */
|
|
|
|
}else{
|
|
|
|
|
|
|
|
/* (6) Si @firstname et/ou @lastname -> firstname lastname*/
|
|
|
|
if( fl+ll > 0 )
|
|
|
|
return (f+' '+l).trim();
|
|
|
|
|
|
|
|
/* (7) Si rien -> Inconnu */
|
|
|
|
else
|
|
|
|
return 'Inconnu';
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
=========================================================*/
|
2016-05-11 20:02:20 +00:00
|
|
|
// TODO: Mettre les versions minifiées
|
2016-04-26 14:16:43 +00:00
|
|
|
include('/js/includes/input-phone-subject.js', function(){
|
|
|
|
include('/js/includes/input-phone-contact.js', function(){
|
2016-05-08 16:31:58 +00:00
|
|
|
include('/js/includes/input-phone-mini.js', function(){
|
|
|
|
include('/js/includes/input-phone-fiche.js', function(){
|
|
|
|
include('/js/includes/input-phone-matrice.js', function(){
|
2016-04-26 14:16:43 +00:00
|
|
|
|
|
|
|
|
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(
|
2016-05-12 19:47:52 +00:00
|
|
|
$('article.subject-panel [data-name="tmp_id"]'),
|
2016-04-26 14:16:43 +00:00
|
|
|
$('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-05-08 17:11:03 +00:00
|
|
|
/* (5) Gestion de la matrice de relations
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire de la matrice */
|
|
|
|
matriceManager = new inputPhoneMatrice(
|
|
|
|
$('article.matrice-panel')
|
|
|
|
);
|
|
|
|
|
|
|
|
/* (2) On le démarre */
|
|
|
|
matriceManager.attach(dynamicUpdate);
|
|
|
|
|
|
|
|
|
2016-04-22 17:35:05 +00:00
|
|
|
|
2016-04-27 16:32:44 +00:00
|
|
|
|
2016-05-03 13:18:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-08 17:11:03 +00:00
|
|
|
/* (6) Gestion de l'import du fichier
|
2016-04-28 14:00:49 +00:00
|
|
|
---------------------------------------------------------*/
|
2016-05-09 07:34:17 +00:00
|
|
|
// On vide l'input de type 'file' quand on clique
|
|
|
|
$('input#call_log-import[type="file"]').addEventListener('click', function(e){
|
|
|
|
e.target.value = null;
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
// Gestion de l'upload
|
2016-05-08 16:31:58 +00:00
|
|
|
$('input#call_log-import[type="file"]').addEventListener('change', function(e){
|
2016-04-27 16:32:44 +00:00
|
|
|
/* (1) On rédige la requête */
|
2016-05-03 09:47:05 +00:00
|
|
|
var request = {
|
|
|
|
path: 'upload/call_log',
|
|
|
|
phone_number: $('#subject_phone_number').value,
|
2016-05-08 16:31:58 +00:00
|
|
|
file: e.target.files[0]
|
2016-04-27 16:32:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* (2) On effectue l'upload (import) */
|
2016-05-03 09:47:05 +00:00
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
var loadingNotif = null;
|
|
|
|
|
2016-05-03 09:47:05 +00:00
|
|
|
// Si erreur, on quitte
|
2016-05-10 16:43:31 +00:00
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
if( response.ModuleError == 9 )
|
|
|
|
Notification.error('Erreur', 'Il est nécessaire de saisir les informations du <b>sujet</b> avant d\'exporter son journal d\'appel');
|
|
|
|
else
|
|
|
|
Notification.error('Erreur', response.ModuleError);
|
2016-05-03 09:47:05 +00:00
|
|
|
return;
|
2016-05-10 16:43:31 +00:00
|
|
|
}else
|
|
|
|
loadingNotif = Notification.info('Info', 'Chargement du journal d\'appel');
|
2016-05-03 09:47:05 +00:00
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 19:47:52 +00:00
|
|
|
/* (3) On enregistre l'identifiant temporaire du sujet */
|
|
|
|
subjectManager.tmp_id.value = response.tmp_id;
|
2016-05-13 09:47:45 +00:00
|
|
|
subjectManager.fieldsToStorage();
|
|
|
|
subjectManager.storageToFields();
|
2016-05-12 19:47:52 +00:00
|
|
|
|
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
/* (3) On crée les 10 contacts les plus APPELÉS */
|
|
|
|
for( var i = 0 ; i < response.call.length ; i++ ){
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
// Données du cnotact
|
|
|
|
var conData = response.directory[ response.call[i] ];
|
2016-05-12 12:30:42 +00:00
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
var splittedName = conData.name.split(' ');
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
lsi.set('contacts', conData.id, {
|
|
|
|
uid: conData.id,
|
|
|
|
number: conData.number,
|
|
|
|
username: splittedName.length == 1 ? splittedName[0] : '', // Si un seul mot -> pseudo
|
|
|
|
firstname: splittedName.length > 1 ? splittedName[0] : '', // Si plusieurs mots -> le 1er est le prénom
|
|
|
|
lastname: splittedName.length > 1 ? splittedName.splice(1).join(' ') : '', // et les autres sont le nom
|
|
|
|
countsms: conData.sms, // Nombre de sms
|
2016-05-12 15:01:31 +00:00
|
|
|
countcall: conData.call, // Nombre d'appels
|
2016-05-03 15:34:27 +00:00
|
|
|
call: i, // classement dans le top 10 des APPELS
|
|
|
|
sms: -1 // classement dans le top 10 des SMS
|
2016-05-03 14:29:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2016-05-03 14:46:38 +00:00
|
|
|
|
2016-05-12 15:01:31 +00:00
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
/* (5) On crée les 10 contacts les plus SMSÉS */
|
|
|
|
for( var i = 0 ; i < response.sms.length ; i++ ){
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
// Données du cnotact
|
|
|
|
var conData = response.directory[response.sms[i]];
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 15:01:31 +00:00
|
|
|
// Si le contact existe déja, on lui ajoute juste 'sms'
|
2016-05-03 14:29:12 +00:00
|
|
|
// Si le contact est déja dans le top 10 des appels, on lui ajoute juste le classement dans le top 10 des SMS
|
2016-05-12 14:11:07 +00:00
|
|
|
var callIndex = response.call.indexOf(response.sms[i]);
|
2016-05-03 14:29:12 +00:00
|
|
|
if( callIndex > -1 ){
|
2016-05-12 14:11:07 +00:00
|
|
|
var created = lsi.get('contacts', conData.id);
|
2016-05-03 14:29:12 +00:00
|
|
|
created.sms = i;
|
2016-05-12 14:11:07 +00:00
|
|
|
lsi.set('contacts', conData.id, created);
|
2016-05-03 14:29:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
var splittedName = conData.name.split(' ');
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 15:01:31 +00:00
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
lsi.set('contacts', conData.id, {
|
|
|
|
uid: conData.id,
|
|
|
|
number: conData.number,
|
|
|
|
username: splittedName.length == 1 ? splittedName[0] : '', // Si un seul mot -> pseudo
|
|
|
|
firstname: splittedName.length > 1 ? splittedName[0] : '', // Si plusieurs mots -> le 1er est le prénom
|
|
|
|
lastname: splittedName.length > 1 ? splittedName.splice(1).join(' ') : '', // et les autres sont le nom
|
|
|
|
countsms: conData.sms, // Nombre de sms
|
2016-05-12 15:01:31 +00:00
|
|
|
countcall: conData.call, // Nombre d'appels
|
2016-05-03 15:34:27 +00:00
|
|
|
call: -1, // classement dans le top 10 des APPELS
|
|
|
|
sms: i // classement dans le top 10 des SMS
|
2016-05-03 14:29:12 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2016-05-03 14:46:38 +00:00
|
|
|
|
2016-05-12 15:01:31 +00:00
|
|
|
/* (7) Pour chaque contact qui n'est pas dans un top 10, on l'ajoute */
|
2016-05-12 14:11:07 +00:00
|
|
|
for( var id in response.directory ){
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 15:01:31 +00:00
|
|
|
id = parseInt(id);
|
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
// Si dans top 10 des APPELS, on ne l'ajoute pas
|
2016-05-12 14:11:07 +00:00
|
|
|
if( response.call.indexOf(id) > -1 )
|
2016-05-03 14:29:12 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Si dans top 10 des SMS, on ne l'ajoute pas
|
2016-05-12 14:11:07 +00:00
|
|
|
if( response.sms.indexOf(id) > -1 )
|
2016-05-03 14:29:12 +00:00
|
|
|
continue;
|
2016-05-03 09:47:05 +00:00
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
// On récupère les données du contact
|
|
|
|
var conData = response.directory[id];
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
// On découpe le nom par espaces
|
|
|
|
var splittedName = conData.name.split(' ');
|
2016-05-03 14:29:12 +00:00
|
|
|
|
|
|
|
|
2016-05-12 14:11:07 +00:00
|
|
|
lsi.set('contacts', conData.id, {
|
|
|
|
uid: conData.id,
|
|
|
|
number: conData.number,
|
2016-05-03 14:29:12 +00:00
|
|
|
username: splittedName.length == 1 ? splittedName[0] : '', // Si un seul mot -> pseudo
|
2016-05-12 14:11:07 +00:00
|
|
|
firstname: splittedName.length > 1 ? splittedName[0] : '', // Si plusieurs mots -> le 1er est le prénom
|
|
|
|
lastname: splittedName.length > 1 ? splittedName.splice(1).join(' ') : '', // et les autres sont le nom
|
|
|
|
countsms: conData.sms, // Nombre de sms
|
2016-05-12 15:01:31 +00:00
|
|
|
countcall: conData.call, // Nombre d'appels
|
2016-05-03 15:34:27 +00:00
|
|
|
call: -1,
|
|
|
|
sms: -1
|
2016-04-27 17:54:11 +00:00
|
|
|
});
|
2016-04-27 16:32:44 +00:00
|
|
|
}
|
2016-05-03 14:46:38 +00:00
|
|
|
|
2016-05-03 15:19:54 +00:00
|
|
|
/* (8) On met à jour l'affichage */
|
2016-05-03 09:47:05 +00:00
|
|
|
contactManager.storageToFields();
|
|
|
|
dynamicUpdate(true);
|
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
|
|
|
|
/* (9) On notifie la fin du chargement */
|
|
|
|
// On retire la notification de chargement
|
|
|
|
if( loadingNotif != null )
|
|
|
|
loadingNotif.click();
|
2016-05-12 17:30:53 +00:00
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
// On notifie que tout s'est bien passé
|
|
|
|
Notification.success('OK', 'Chargement terminé');
|
|
|
|
|
2016-04-27 16:32:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
|
2016-05-08 17:11:03 +00:00
|
|
|
/* (7) Gestion de l'effacement des données locales
|
2016-04-28 14:00:49 +00:00
|
|
|
---------------------------------------------------------*/
|
2016-05-08 16:31:58 +00:00
|
|
|
$('#clear-all').addEventListener('click', function(e){
|
2016-05-03 20:28:47 +00:00
|
|
|
/* (1) On vide tous les dataset de données */
|
|
|
|
lsi.clear('subject');
|
|
|
|
lsi.clear('contacts');
|
|
|
|
lsi.clear('mini-fiches');
|
|
|
|
lsi.clear('fiches');
|
2016-05-09 07:34:17 +00:00
|
|
|
lsi.clear('matrice');
|
2016-05-03 20:28:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* (2) On met à jour l'affichage */
|
|
|
|
subjectManager.storageToFields();
|
|
|
|
contactManager.storageToFields();
|
|
|
|
miniManager.storageToFields();
|
|
|
|
ficheManager.storageToFields();
|
2016-05-09 07:34:17 +00:00
|
|
|
matriceManager.storageToFields();
|
2016-05-10 16:43:31 +00:00
|
|
|
|
|
|
|
Notification.success('OK', 'Les données ont été supprimées');
|
2016-04-28 14:00:49 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
|
2016-05-08 17:11:03 +00:00
|
|
|
/* (8) Gestion de l'export des données locales
|
2016-05-02 19:21:09 +00:00
|
|
|
---------------------------------------------------------*/
|
|
|
|
$('#export-all').addEventListener('click', function(e){
|
2016-05-10 16:43:31 +00:00
|
|
|
|
|
|
|
Notification.info('INFORMATION', 'Lancement du téléchargement de la sauvegarde');
|
|
|
|
|
2016-05-02 19:21:09 +00:00
|
|
|
/* (1) On construit les données */
|
|
|
|
var data = {
|
|
|
|
subject: lsi.export('subject')[0],
|
|
|
|
contacts: lsi.export('contacts'),
|
|
|
|
mini: lsi.export('mini-fiches'),
|
2016-05-09 07:34:17 +00:00
|
|
|
fiches: lsi.export('fiches'),
|
2016-05-12 17:30:53 +00:00
|
|
|
matrice: lsi.export('matrice')[0]
|
2016-05-02 19:21:09 +00:00
|
|
|
};
|
|
|
|
|
2016-05-09 07:34:17 +00:00
|
|
|
|
2016-05-02 19:21:09 +00:00
|
|
|
/* (2) On lance le téléchargement */
|
2016-05-03 07:44:25 +00:00
|
|
|
var downloadTarget = $('#download-target'); // On récupère le lien (<a>) caché qui fera le téléchargement
|
|
|
|
downloadTarget.download = 'local-data.json'; // Nom du fichier qui sera téléchargé
|
2016-05-03 13:10:56 +00:00
|
|
|
downloadTarget.href = 'data:application/octet-stream,' + encodeURIComponent(JSON.stringify(data)); // Contenu
|
2016-05-03 07:44:25 +00:00
|
|
|
downloadTarget.click(); // On lance le téléchargement
|
2016-05-02 19:21:09 +00:00
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
|
|
|
|
|
2016-05-08 17:11:03 +00:00
|
|
|
/* (9) Gestion de l'import des données locales
|
2016-05-02 19:21:09 +00:00
|
|
|
---------------------------------------------------------*/
|
2016-05-03 09:11:41 +00:00
|
|
|
// Le bouton lance l'<input> file
|
2016-05-02 19:21:09 +00:00
|
|
|
$('#import-all').addEventListener('click', function(e){
|
2016-05-03 09:11:41 +00:00
|
|
|
$('#local-upload').click();
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-05-09 07:34:17 +00:00
|
|
|
// On vide l'input de type 'file' quand on clique
|
|
|
|
$('#local-upload').addEventListener('click', function(e){
|
|
|
|
e.target.value = null;
|
|
|
|
}, false);
|
|
|
|
|
2016-05-03 09:11:41 +00:00
|
|
|
// Gestion de l'upload d'une sauvegarde de formulaire local
|
|
|
|
$('#local-upload').addEventListener('change', function(e){
|
|
|
|
/* (1) Rédaction de la requête d'upload */
|
2016-05-03 10:08:24 +00:00
|
|
|
var request = {
|
2016-05-03 09:11:41 +00:00
|
|
|
path: 'upload/local_data',
|
|
|
|
file: $('#local-upload').files[0]
|
|
|
|
};
|
|
|
|
|
|
|
|
/* (2) Upload et réponse */
|
2016-05-03 10:08:24 +00:00
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
2016-05-03 09:11:41 +00:00
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
// Si erreur, on quitte
|
2016-05-10 16:43:31 +00:00
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
Notification.error('Erreur', response.ModuleError);
|
2016-05-03 10:08:24 +00:00
|
|
|
return false;
|
2016-05-10 16:43:31 +00:00
|
|
|
}
|
2016-05-09 07:34:17 +00:00
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
/* (3) On enregistre les données dans le 'localStorage' */
|
2016-05-03 13:10:56 +00:00
|
|
|
lsi.set('subject', 0, response.local_data.subject);
|
2016-05-03 10:08:24 +00:00
|
|
|
lsi.import('contacts', response.local_data.contacts);
|
|
|
|
lsi.import('mini-fiches', response.local_data.mini);
|
|
|
|
lsi.import('fiches', response.local_data.fiches);
|
2016-05-09 07:34:17 +00:00
|
|
|
lsi.set('matrice', 0, response.local_data.matrice);
|
2016-05-03 10:08:24 +00:00
|
|
|
|
|
|
|
/* (3) On met à jour l'affichage */
|
2016-05-03 13:10:56 +00:00
|
|
|
subjectManager.storageToFields();
|
2016-05-03 10:08:24 +00:00
|
|
|
contactManager.storageToFields();
|
2016-05-09 07:34:17 +00:00
|
|
|
matriceManager.storageToFields();
|
2016-05-03 10:08:24 +00:00
|
|
|
dynamicUpdate(true);
|
2016-05-03 09:11:41 +00:00
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
});
|
2016-05-03 09:11:41 +00:00
|
|
|
|
2016-05-02 19:21:09 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
|
|
|
|
|
2016-05-08 17:11:03 +00:00
|
|
|
/* (10) Gestion de la validation et de l'envoi des données
|
2016-04-30 09:33:01 +00:00
|
|
|
---------------------------------------------------------*/
|
2016-05-08 16:31:58 +00:00
|
|
|
$('#submit-all').addEventListener('click', function(e){
|
2016-05-03 09:11:41 +00:00
|
|
|
console.log('> GATHERING ALL DATA');
|
2016-04-30 09:33:01 +00:00
|
|
|
|
|
|
|
/* (1) On met dans la mémoire tout les champs non enregistrés */
|
|
|
|
subjectManager.fieldsToStorage();
|
|
|
|
contactManager.fieldsToStorage();
|
|
|
|
miniManager.fieldsToStorage();
|
|
|
|
ficheManager.fieldsToStorage();
|
|
|
|
|
2016-05-10 14:51:09 +00:00
|
|
|
/* (2) Vérification de la validité de toutes les données */
|
|
|
|
// {1} Vérification du sujet //
|
2016-05-10 16:43:31 +00:00
|
|
|
if( !subjectManager.check() ){
|
|
|
|
Notification.warning('Attention', 'Vous devez saisir les informations du <i>sujet</i>');
|
2016-05-10 14:51:09 +00:00
|
|
|
return false;
|
2016-05-10 16:43:31 +00:00
|
|
|
}
|
2016-05-10 14:51:09 +00:00
|
|
|
// {2} Vérification des mini-fiches //
|
|
|
|
var mini = lsi.export('mini-fiches');
|
2016-05-13 09:14:41 +00:00
|
|
|
var i = 0;
|
|
|
|
for( var id in mini ){ if( !isNaN(id) ){
|
|
|
|
|
|
|
|
i++
|
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
if( !mini[id].valid ){
|
2016-05-13 09:14:41 +00:00
|
|
|
Notification.warning('Attention', 'La <i>fiche rapide</i> <b>'+i+'</b> est incomplète et/ou incorrecte');
|
2016-05-10 14:51:09 +00:00
|
|
|
return false;
|
2016-05-10 16:43:31 +00:00
|
|
|
}
|
2016-05-13 09:14:41 +00:00
|
|
|
|
|
|
|
}}
|
2016-05-10 14:51:09 +00:00
|
|
|
// {3} Vérification des fiches //
|
2016-05-13 09:14:41 +00:00
|
|
|
//TODO: Remettre la vérification des fiches
|
|
|
|
// var fiches = lsi.export('fiches');
|
|
|
|
// for( var id in fiches )
|
|
|
|
// if( !fiches[id].valid ){
|
|
|
|
// Notification.warning('Attention', 'La <i>fiche complète</i> <b>'+(parseInt(id)+1)+'</b> est incomplète et/ou incorrecte');
|
|
|
|
// return false;
|
|
|
|
// }
|
2016-05-10 14:51:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) 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-05-09 09:01:43 +00:00
|
|
|
fiches: lsi.export('fiches'),
|
|
|
|
matrice: lsi.export('matrice')[0]
|
2016-04-30 09:33:01 +00:00
|
|
|
};
|
|
|
|
|
2016-05-10 14:51:09 +00:00
|
|
|
/* (4) On envoie la requête et traite la réponse */
|
2016-04-30 09:33:01 +00:00
|
|
|
api.send(request, function(response){
|
2016-05-13 09:14:41 +00:00
|
|
|
console.log(response);
|
2016-05-13 09:47:45 +00:00
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
// Si erreur, on la notifie
|
|
|
|
if( response.ModuleError != 0 ){
|
2016-05-10 17:12:38 +00:00
|
|
|
Notification.error('ERREUR', response.ModuleError);
|
2016-05-10 16:43:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-30 09:33:01 +00:00
|
|
|
console.log(response);
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-04-30 09:33:01 +00:00
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-05-08 16:31:58 +00:00
|
|
|
}); }); }); }); });
|