2016-05-18 12:46:13 +00:00
|
|
|
/*=========================================================*/
|
|
|
|
/*********** Gestion du formulaire téléphonique ************/
|
|
|
|
/*=========================================================*/
|
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-05-18 12:46:13 +00:00
|
|
|
var cSubjectManager;
|
|
|
|
var cContactManager;
|
|
|
|
var cMiniManager;
|
|
|
|
var cFicheManager;
|
|
|
|
var cMatriceManager;
|
2016-04-22 17:35:05 +00:00
|
|
|
|
2016-04-28 16:58:18 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) Fonctions utiles */
|
|
|
|
function cDynamicUpdate(target){
|
|
|
|
|
|
|
|
|
|
|
|
/* (0) Vérification de la cohérence de la @target
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
var isElement = target instanceof Element;
|
|
|
|
var isSaveButton = isElement && target.tagName == 'INPUT' && target.type == 'submit';
|
|
|
|
var isNavButton = isElement && target.tagName == 'SPAN' && (target.parentNode.id == 'p_nav-mini' || target.parentNode.id == 'p_nav-fiche');
|
|
|
|
var isNavContact = isElement && target.tagName == 'SPAN' && target.parentNode.id == 'p_nav-contact';
|
|
|
|
|
|
|
|
// Si erreur, on retourne une erreur
|
2016-05-19 13:14:10 +00:00
|
|
|
if( !isSaveButton && !isNavButton && !isNavContact && target !== true )
|
2016-05-18 15:00:00 +00:00
|
|
|
return false;
|
|
|
|
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
console.log('> dynamic update');
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (1) On enregistre les MINI fiches relation */
|
2016-05-23 12:06:17 +00:00
|
|
|
pMiniManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (2) On enregister les FICHES relation */
|
2016-05-23 12:06:17 +00:00
|
|
|
pFicheManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (3) On enregistre les CONTACTS */
|
2016-05-23 12:06:17 +00:00
|
|
|
pContactManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (4) On enregistre la MATRICE */
|
2016-05-23 12:06:17 +00:00
|
|
|
pMatriceManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (5) On synchronise les FICHE avec les CONTACTS */
|
|
|
|
// 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-05-23 12:06:17 +00:00
|
|
|
pFicheManager.sync();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (6) On synchronise les MINI avec les CONTACTS */
|
|
|
|
// Supprime les contacts déja dans les FICHES
|
2016-05-23 12:06:17 +00:00
|
|
|
pMiniManager.sync();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (7) On affiche le tout */
|
2016-05-23 12:06:17 +00:00
|
|
|
pMiniManager.storageToFields();
|
|
|
|
pFicheManager.storageToFields();
|
|
|
|
pMatriceManager.storageToFields();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (8) On met à jour les contacts si on les a modifié on si on navigue dans les contacts */
|
|
|
|
if( isSaveButton || isNavContact )
|
2016-05-23 12:06:17 +00:00
|
|
|
pContactManager.storageToFields();
|
2016-05-18 15:00:00 +00:00
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* [2] Inclusion des scripts externes et lancement
|
|
|
|
=========================================================*/
|
2016-05-22 12:49:20 +00:00
|
|
|
include('/js/includes/input-phone-subject-min.js', function(){
|
|
|
|
include('/js/includes/input-phone-contact-min.js', function(){
|
|
|
|
include('/js/includes/input-phone-mini-min.js', function(){
|
|
|
|
include('/js/includes/input-phone-fiche-min.js', function(){
|
|
|
|
include('/js/includes/input-phone-matrice-min.js', function(){
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (1) Gestion du formulaire du sujet
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du manager du sujet */
|
2016-05-23 12:06:17 +00:00
|
|
|
pSubjectManager = new inputPhoneSubject(
|
2016-05-18 15:00:00 +00:00
|
|
|
$('[data-sublink="phone"] article.subject-panel [data-name="tmp_id"]'),
|
|
|
|
$('[data-sublink="phone"] article.subject-panel [data-name="number"]'),
|
|
|
|
$('[data-sublink="phone"] article.subject-panel [data-name="username"]'),
|
|
|
|
$('[data-sublink="phone"] article.subject-panel [data-name="submit"]')
|
|
|
|
);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On le démarre */
|
2016-05-23 12:06:17 +00:00
|
|
|
pSubjectManager.attach();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) Gestion des formulaires de contact
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire des CONTACTS */
|
2016-05-23 12:06:17 +00:00
|
|
|
pContactManager = new inputPhoneContact(
|
2016-05-18 15:00:00 +00:00
|
|
|
$('[data-sublink="phone"] article.contact-panel'),
|
|
|
|
$('[data-sublink="phone"] #p_nav-contact')
|
|
|
|
);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On le démarre */
|
2016-05-23 12:06:17 +00:00
|
|
|
pContactManager.attach(cDynamicUpdate);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (3) Gestion des mini fiches relation
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire des mini fiches relation */
|
2016-05-23 12:06:17 +00:00
|
|
|
pMiniManager = new inputPhoneMini(
|
2016-05-18 15:00:00 +00:00
|
|
|
$('[data-sublink="phone"] article.mini-relation-panel'),
|
|
|
|
$('[data-sublink="phone"] #p_nav-mini')
|
|
|
|
);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On le démarre */
|
2016-05-23 12:06:17 +00:00
|
|
|
pMiniManager.attach(cDynamicUpdate);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (4) Gestion des fiches relation
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire des fiches relation */
|
2016-05-23 12:06:17 +00:00
|
|
|
pFicheManager = new inputPhoneFiche(
|
2016-05-18 15:00:00 +00:00
|
|
|
$('[data-sublink="phone"] article.relation-panel'),
|
|
|
|
$('[data-sublink="phone"] #p_nav-fiche')
|
|
|
|
);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On le démarre */
|
2016-05-23 12:06:17 +00:00
|
|
|
pFicheManager.attach(cDynamicUpdate);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (5) Gestion de la matrice de relations
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire de la matrice */
|
2016-05-23 12:06:17 +00:00
|
|
|
pMatriceManager = new inputPhoneMatrice(
|
2016-05-18 15:00:00 +00:00
|
|
|
$('[data-sublink="phone"] article.matrice-panel')
|
|
|
|
);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On le démarre */
|
2016-05-23 12:06:17 +00:00
|
|
|
pMatriceManager.attach(cDynamicUpdate);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (6) Gestion de l'import du fichier
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
// On vide l'input de type 'file' quand on clique
|
|
|
|
$('[data-sublink="phone"] input#p_call_log-import[type="file"]').addEventListener('click', function(e){
|
|
|
|
e.target.value = null;
|
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Gestion de l'upload
|
|
|
|
$('[data-sublink="phone"] input#p_call_log-import[type="file"]').addEventListener('change', function(e){
|
|
|
|
/* (1) On rédige la requête */
|
|
|
|
var request = {
|
|
|
|
path: 'upload/call_log',
|
|
|
|
phone_number: $('[data-sublink="phone"] #p_subject_phone_number').value,
|
|
|
|
file: e.target.files[0]
|
|
|
|
};
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On effectue l'upload (import) */
|
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
var loadingNotif = null;
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Si erreur, on quitte
|
|
|
|
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);
|
|
|
|
return;
|
|
|
|
}else
|
|
|
|
loadingNotif = Notification.info('Info', 'Chargement du journal d\'appel');
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (3) On enregistre l'identifiant temporaire du sujet */
|
2016-05-23 12:06:17 +00:00
|
|
|
pSubjectManager.tmp_id.value = response.tmp_id;
|
|
|
|
pSubjectManager.fieldsToStorage();
|
|
|
|
pSubjectManager.storageToFields();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (3) On crée les 10 contacts les plus APPELÉS */
|
|
|
|
for( var i = 0 ; i < response.call.length ; i++ ){
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Données du cnotact
|
|
|
|
var conData = response.directory[ response.call[i] ];
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
lsi.set('p_contacts', conData.id, {
|
|
|
|
uid: conData.id,
|
|
|
|
number: conData.number,
|
2016-05-19 13:14:10 +00:00
|
|
|
username: conData.name, // nom
|
2016-05-18 15:00:00 +00:00
|
|
|
countsms: conData.sms, // Nombre de sms
|
|
|
|
countcall: conData.call, // Nombre d'appels
|
|
|
|
call: i, // classement dans le top 10 des APPELS
|
|
|
|
sms: -1 // classement dans le top 10 des SMS
|
|
|
|
});
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (5) On crée les 10 contacts les plus SMSÉS */
|
|
|
|
for( var i = 0 ; i < response.sms.length ; i++ ){
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Données du cnotact
|
|
|
|
var conData = response.directory[response.sms[i]];
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Si le contact existe déja, on lui ajoute juste 'sms'
|
|
|
|
// Si le contact est déja dans le top 10 des appels, on lui ajoute juste le classement dans le top 10 des SMS
|
|
|
|
var callIndex = response.call.indexOf(response.sms[i]);
|
|
|
|
if( callIndex > -1 ){
|
|
|
|
var created = lsi.get('p_contacts', conData.id);
|
|
|
|
created.sms = i;
|
|
|
|
lsi.set('p_contacts', conData.id, created);
|
|
|
|
continue;
|
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
lsi.set('p_contacts', conData.id, {
|
|
|
|
uid: conData.id,
|
|
|
|
number: conData.number,
|
2016-05-19 13:14:10 +00:00
|
|
|
username: conData.name, // nom
|
2016-05-18 15:00:00 +00:00
|
|
|
countsms: conData.sms, // Nombre de sms
|
|
|
|
countcall: conData.call, // Nombre d'appels
|
|
|
|
call: -1, // classement dans le top 10 des APPELS
|
|
|
|
sms: i // classement dans le top 10 des SMS
|
|
|
|
});
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (7) Pour chaque contact qui n'est pas dans un top 10, on l'ajoute */
|
|
|
|
for( var id in response.directory ){
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
id = parseInt(id);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Si dans top 10 des APPELS, on ne l'ajoute pas
|
|
|
|
if( response.call.indexOf(id) > -1 )
|
|
|
|
continue;
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Si dans top 10 des SMS, on ne l'ajoute pas
|
|
|
|
if( response.sms.indexOf(id) > -1 )
|
|
|
|
continue;
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// On récupère les données du contact
|
|
|
|
var conData = response.directory[id];
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
lsi.set('p_contacts', conData.id, {
|
|
|
|
uid: conData.id,
|
|
|
|
number: conData.number,
|
2016-05-19 13:14:10 +00:00
|
|
|
username: conData.name, // nom
|
2016-05-18 15:00:00 +00:00
|
|
|
countsms: conData.sms, // Nombre de sms
|
|
|
|
countcall: conData.call, // Nombre d'appels
|
|
|
|
call: -1,
|
|
|
|
sms: -1
|
|
|
|
});
|
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (8) On met à jour l'affichage */
|
2016-05-23 12:06:17 +00:00
|
|
|
pContactManager.storageToFields();
|
2016-05-18 15:00:00 +00:00
|
|
|
cDynamicUpdate(true);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (9) On notifie la fin du chargement */
|
|
|
|
// On retire la notification de chargement
|
|
|
|
if( loadingNotif != null )
|
|
|
|
loadingNotif.click();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// On notifie que tout s'est bien passé
|
|
|
|
Notification.success('OK', 'Chargement terminé');
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
});
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (7) Gestion de l'effacement des données locales
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$('[data-sublink="phone"] #p_clear-all').addEventListener('click', function(e){
|
|
|
|
/* (1) On vide tous les dataset de données */
|
|
|
|
lsi.clear('p_subject');
|
|
|
|
lsi.clear('p_contacts');
|
|
|
|
lsi.clear('p_mini-fiches');
|
|
|
|
lsi.clear('p_fiches');
|
|
|
|
lsi.clear('p_matrice');
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On met à jour l'affichage */
|
2016-05-23 12:06:17 +00:00
|
|
|
pSubjectManager.storageToFields();
|
|
|
|
pContactManager.storageToFields();
|
|
|
|
pMiniManager.storageToFields();
|
|
|
|
pFicheManager.storageToFields();
|
|
|
|
pMatriceManager.storageToFields();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
Notification.success('OK', 'Les données ont été supprimées');
|
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-04-28 16:58:18 +00:00
|
|
|
|
2016-05-11 20:02:20 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (8) Gestion de l'export des données locales
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$('[data-sublink="phone"] #p_export-all').addEventListener('click', function(e){
|
2016-05-11 20:02:20 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
Notification.info('INFORMATION', 'Lancement du téléchargement de la sauvegarde');
|
2016-05-11 20:02:20 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (1) On construit les données */
|
|
|
|
var data = {
|
|
|
|
subject: lsi.export('p_subject')[0],
|
|
|
|
contacts: lsi.export('p_contacts'),
|
|
|
|
mini: lsi.export('p_mini-fiches'),
|
|
|
|
fiches: lsi.export('p_fiches'),
|
|
|
|
matrice: lsi.export('p_matrice')[0]
|
|
|
|
};
|
2016-05-11 20:02:20 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On lance le téléchargement */
|
|
|
|
var downloadTarget = $('[data-sublink="phone"] #p_download-target'); // On récupère le lien (<a>) caché qui fera le téléchargement
|
|
|
|
downloadTarget.download = 'local-phone-data.json'; // Nom du fichier qui sera téléchargé
|
|
|
|
downloadTarget.href = 'data:application/octet-stream,' + encodeURIComponent(JSON.stringify(data)); // Contenu
|
|
|
|
downloadTarget.click(); // On lance le téléchargement
|
2016-05-11 20:02:20 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}, false);
|
2016-05-11 20:02:20 +00:00
|
|
|
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (9) Gestion de l'import des données locales
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
// Le bouton lance l'<input> file
|
|
|
|
$('[data-sublink="phone"] #p_import-all').addEventListener('click', function(e){
|
|
|
|
$('[data-sublink="phone"] #p_local-upload').click();
|
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// On vide l'input de type 'file' quand on clique
|
|
|
|
$('[data-sublink="phone"] #p_local-upload').addEventListener('click', function(e){
|
|
|
|
e.target.value = null;
|
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Gestion de l'upload d'une sauvegarde de formulaire local
|
|
|
|
$('[data-sublink="phone"] #p_local-upload').addEventListener('change', function(e){
|
|
|
|
/* (1) Rédaction de la requête d'upload */
|
|
|
|
var request = {
|
|
|
|
path: 'upload/local_data',
|
|
|
|
file: $('[data-sublink="phone"] #p_local-upload').files[0]
|
|
|
|
};
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) Upload et réponse */
|
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Si erreur, on quitte
|
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
Notification.error('Erreur', response.ModuleError);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (3) On enregistre les données dans le 'localStorage' */
|
|
|
|
lsi.set('p_subject', 0, response.local_data.subject);
|
|
|
|
lsi.import('p_contacts', response.local_data.contacts);
|
|
|
|
lsi.import('p_mini-fiches', response.local_data.mini);
|
|
|
|
lsi.import('p_fiches', response.local_data.fiches);
|
|
|
|
lsi.set('p_matrice', 0, response.local_data.matrice);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (3) On met à jour l'affichage */
|
2016-05-23 12:06:17 +00:00
|
|
|
pSubjectManager.storageToFields();
|
|
|
|
pContactManager.storageToFields();
|
|
|
|
pMatriceManager.storageToFields();
|
2016-05-18 15:00:00 +00:00
|
|
|
cDynamicUpdate(true);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
});
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (10) Gestion de la validation et de l'envoi des données
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$('[data-sublink="phone"] #p_submit-all').addEventListener('click', function(e){
|
|
|
|
console.log('> GATHERING ALL DATA');
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (1) On met dans la mémoire tout les champs non enregistrés */
|
2016-05-23 12:06:17 +00:00
|
|
|
pSubjectManager.fieldsToStorage();
|
|
|
|
pContactManager.fieldsToStorage();
|
|
|
|
pMiniManager.fieldsToStorage();
|
2016-05-18 15:00:00 +00:00
|
|
|
cFicheManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) Vérification de la validité de toutes les données */
|
|
|
|
// {1} Vérification du sujet //
|
|
|
|
if( !cSubjectManager.check() ){
|
|
|
|
Notification.warning('Attention', 'Vous devez saisir les informations du <i>sujet</i>');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// {2} Vérification des mini-fiches //
|
|
|
|
var mini = lsi.export('p_mini-fiches');
|
|
|
|
var i = 0;
|
|
|
|
for( var id in mini ){ if( !isNaN(id) ){
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
i++
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
if( !mini[id].valid ){
|
|
|
|
Notification.warning('Attention', 'La <i>fiche rapide</i> <b>'+i+'</b> est incomplète et/ou incorrecte');
|
2016-05-18 12:46:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}}
|
|
|
|
// {3} Vérification des fiches //
|
2016-05-22 12:49:20 +00:00
|
|
|
var fiches = lsi.export('p_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-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (3) On prépare la requête avec toutes les données */
|
|
|
|
var request = {
|
|
|
|
path: 'input/phone',
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
subject: lsi.export('p_subject')[0],
|
|
|
|
contacts: lsi.export('p_contacts'),
|
|
|
|
mini: lsi.export('p_mini-fiches'),
|
|
|
|
fiches: lsi.export('p_fiches'),
|
|
|
|
matrice: lsi.export('p_matrice')[0]
|
|
|
|
};
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (4) On envoie la requête et traite la réponse */
|
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Si erreur, on la notifie
|
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
Notification.error('ERREUR', response.ModuleError);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-23 12:06:17 +00:00
|
|
|
Notification.success('OK', "L'identifiant du sujet est <strong>"+response.subject_id+"</strong> ! Tout s'est bien déroulé.", 10000);
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
console.log(response);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +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
|
|
|
|
|
|
|
|
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-21 14:41:11 +00:00
|
|
|
|
|
|
|
|
2016-04-22 14:40:06 +00:00
|
|
|
|
2016-04-27 12:32:54 +00:00
|
|
|
|
2016-04-22 14:40:06 +00:00
|
|
|
|
|
|
|
|
2016-05-08 17:11:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
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-09 07:34:17 +00:00
|
|
|
|
2016-04-27 16:32:44 +00:00
|
|
|
|
2016-05-03 09:47:05 +00:00
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-05-03 09:47:05 +00:00
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 19:47:52 +00:00
|
|
|
|
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
|
|
|
|
2016-05-12 12:30:42 +00:00
|
|
|
|
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-03 14:29:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-12 15:01:31 +00:00
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-03 14:46:38 +00:00
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 15:01:31 +00:00
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-03 09:47:05 +00:00
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-03 14:46:38 +00:00
|
|
|
|
2016-05-03 09:47:05 +00:00
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-05-12 17:30:53 +00:00
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-04-27 16:32:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
|
2016-05-18 12:46:13 +00:00
|
|
|
/*=========================================================*/
|
|
|
|
/************ Gestion du formulaire facebook ***************/
|
|
|
|
/*=========================================================*/
|
|
|
|
|
|
|
|
/* [1] Initialisation des utilitaires et variables
|
|
|
|
=========================================================*
|
|
|
|
/* (1) Initialisation des managers */
|
|
|
|
var fSubjectManager;
|
|
|
|
var fContactManager;
|
|
|
|
var fMiniManager;
|
|
|
|
var fFicheManager;
|
|
|
|
var fMatriceManager;
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) Fonctions utiles */
|
|
|
|
function fDynamicUpdate(target){
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (0) Vérification de la cohérence de la @target
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
var isElement = target instanceof Element;
|
|
|
|
var isSaveButton = isElement && target.tagName == 'INPUT' && target.type == 'submit';
|
|
|
|
var isNavButton = isElement && target.tagName == 'SPAN' && (target.parentNode.id == 'f_nav-mini' || target.parentNode.id == 'f_nav-fiche');
|
|
|
|
var isNavContact = isElement && target.tagName == 'SPAN' && target.parentNode.id == 'f_nav-contact';
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Si erreur, on retourne une erreur
|
2016-05-19 13:14:10 +00:00
|
|
|
if( !isSaveButton && !isNavButton && !isNavContact && target !== true )
|
2016-05-18 15:00:00 +00:00
|
|
|
return false;
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
console.log('> dynamic update');
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (1) On enregistre les MINI fiches relation */
|
|
|
|
fMiniManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (2) On enregister les FICHES relation */
|
|
|
|
fFicheManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (3) On enregistre les CONTACTS */
|
|
|
|
fContactManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (4) On enregistre la MATRICE */
|
|
|
|
fMatriceManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (5) On synchronise les FICHE avec les CONTACTS */
|
|
|
|
// 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
|
|
|
|
fFicheManager.sync();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (6) On synchronise les MINI avec les CONTACTS */
|
|
|
|
// Supprime les contacts déja dans les FICHES
|
|
|
|
fMiniManager.sync();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (7) On affiche le tout */
|
|
|
|
fMiniManager.storageToFields();
|
|
|
|
fFicheManager.storageToFields();
|
|
|
|
fMatriceManager.storageToFields();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-19 13:14:10 +00:00
|
|
|
/* (8) On met à jour les contacts si on les a modifié on si on navigue dans les contacts */
|
|
|
|
if( isSaveButton || isNavContact )
|
|
|
|
fContactManager.storageToFields();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-03 20:28:47 +00:00
|
|
|
|
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-04-28 14:00:49 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* [2] Inclusion des scripts externes et lancement
|
|
|
|
=========================================================*/
|
2016-05-22 12:49:20 +00:00
|
|
|
include('/js/includes/input-facebook-subject-min.js', function(){
|
|
|
|
include('/js/includes/input-facebook-contact-min.js', function(){
|
|
|
|
include('/js/includes/input-facebook-mini-min.js', function(){
|
|
|
|
include('/js/includes/input-facebook-fiche-min.js', function(){
|
|
|
|
include('/js/includes/input-facebook-matrice-min.js', function(){
|
2016-04-28 14:00:49 +00:00
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (1) Gestion du formulaire du sujet
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du manager du sujet */
|
|
|
|
fSubjectManager = new inputFacebookSubject(
|
|
|
|
$('[data-sublink="facebook"] article.subject-panel [data-name="username"]'),
|
|
|
|
$('[data-sublink="facebook"] article.subject-panel [data-name="submit"]')
|
|
|
|
);
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
fSubjectManager.attach();
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-05-02 19:21:09 +00:00
|
|
|
|
2016-05-09 07:34:17 +00:00
|
|
|
|
2016-05-02 19:21:09 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) Gestion des formulaires de contact
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire des CONTACTS */
|
|
|
|
fContactManager = new inputFacebookContact(
|
|
|
|
$('[data-sublink="facebook"] article.contact-panel'),
|
|
|
|
$('[data-sublink="facebook"] #f_nav-contact')
|
|
|
|
);
|
2016-05-02 19:21:09 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
fContactManager.attach(fDynamicUpdate);
|
2016-05-03 10:08:24 +00:00
|
|
|
|
|
|
|
|
2016-05-03 09:11:41 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (3) Gestion des mini fiches relation
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire des mini fiches relation */
|
|
|
|
fMiniManager = new inputFacebookMini(
|
|
|
|
$('[data-sublink="facebook"] article.mini-relation-panel'),
|
|
|
|
$('[data-sublink="facebook"] #f_nav-mini')
|
|
|
|
);
|
2016-05-03 09:11:41 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
fMiniManager.attach(fDynamicUpdate);
|
2016-05-09 07:34:17 +00:00
|
|
|
|
2016-05-03 09:11:41 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (4) Gestion des fiches relation
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire des fiches relation */
|
|
|
|
fFicheManager = new inputFacebookFiche(
|
|
|
|
$('[data-sublink="facebook"] article.relation-panel'),
|
|
|
|
$('[data-sublink="facebook"] #f_nav-fiche')
|
|
|
|
);
|
2016-05-03 09:11:41 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
fFicheManager.attach(fDynamicUpdate);
|
2016-05-09 07:34:17 +00:00
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (5) Gestion de la matrice de relations
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire de la matrice */
|
|
|
|
fMatriceManager = new inputFacebookMatrice(
|
|
|
|
$('[data-sublink="facebook"] article.matrice-panel')
|
|
|
|
);
|
2016-05-03 09:11:41 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
fMatriceManager.attach(fDynamicUpdate);
|
2016-05-03 09:11:41 +00:00
|
|
|
|
2016-05-02 19:21:09 +00:00
|
|
|
|
|
|
|
|
2016-05-03 10:08:24 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (7) Gestion de l'effacement des données locales
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$('[data-sublink="facebook"] #f_clear-all').addEventListener('click', function(e){
|
|
|
|
/* (1) On vide tous les dataset de données */
|
|
|
|
lsi.clear('f_subject');
|
|
|
|
lsi.clear('f_contacts');
|
|
|
|
lsi.clear('f_mini-fiches');
|
|
|
|
lsi.clear('f_fiches');
|
|
|
|
lsi.clear('f_matrice');
|
2016-04-30 09:33:01 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On met à jour l'affichage */
|
|
|
|
fSubjectManager.storageToFields();
|
|
|
|
fContactManager.storageToFields();
|
|
|
|
fMiniManager.storageToFields();
|
|
|
|
fFicheManager.storageToFields();
|
|
|
|
fMatriceManager.storageToFields();
|
2016-05-13 09:14:41 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
Notification.success('OK', 'Les données ont été supprimées');
|
|
|
|
}, false);
|
2016-05-13 09:14:41 +00:00
|
|
|
|
|
|
|
|
2016-05-10 14:51:09 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (8) Gestion de l'export des données locales
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$('[data-sublink="facebook"] #f_export-all').addEventListener('click', function(e){
|
2016-05-10 14:51:09 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
Notification.info('INFORMATION', 'Lancement du téléchargement de la sauvegarde');
|
2016-05-10 14:51:09 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (1) On construit les données */
|
|
|
|
var data = {
|
|
|
|
subject: lsi.export('f_subject')[0],
|
|
|
|
contacts: lsi.export('f_contacts'),
|
|
|
|
mini: lsi.export('f_mini-fiches'),
|
|
|
|
fiches: lsi.export('f_fiches'),
|
|
|
|
matrice: lsi.export('f_matrice')[0]
|
|
|
|
};
|
2016-04-30 10:19:51 +00:00
|
|
|
|
2016-04-30 09:33:01 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) On lance le téléchargement */
|
|
|
|
var downloadTarget = $('[data-sublink="facebook"] #f_download-target'); // On récupère le lien (<a>) caché qui fera le téléchargement
|
|
|
|
downloadTarget.download = 'local-facebook-data.json'; // Nom du fichier qui sera téléchargé
|
|
|
|
downloadTarget.href = 'data:application/octet-stream,' + encodeURIComponent(JSON.stringify(data)); // Contenu
|
|
|
|
downloadTarget.click(); // On lance le téléchargement
|
2016-05-13 09:47:45 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}, false);
|
2016-05-10 16:43:31 +00:00
|
|
|
|
|
|
|
|
2016-04-30 09:33:01 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (9) Gestion de l'import des données locales
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
// Le bouton lance l'<input> file
|
|
|
|
$('[data-sublink="facebook"] #f_import-all').addEventListener('click', function(e){
|
|
|
|
$('[data-sublink="facebook"] #f_local-upload').click();
|
|
|
|
}, false);
|
2016-04-30 09:33:01 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// On vide l'input de type 'file' quand on clique
|
|
|
|
$('[data-sublink="facebook"] #f_local-upload').addEventListener('click', function(e){
|
|
|
|
e.target.value = null;
|
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Gestion de l'upload d'une sauvegarde de formulaire local
|
|
|
|
$('[data-sublink="facebook"] #f_local-upload').addEventListener('change', function(e){
|
|
|
|
/* (1) Rédaction de la requête d'upload */
|
|
|
|
var request = {
|
|
|
|
path: 'upload/local_data',
|
|
|
|
file: $('[data-sublink="facebook"] #f_local-upload').files[0]
|
|
|
|
};
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) Upload et réponse */
|
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Si erreur, on quitte
|
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
Notification.error('Erreur', response.ModuleError);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (3) On enregistre les données dans le 'localStorage' */
|
|
|
|
lsi.set('f_subject', 0, response.local_data.subject);
|
|
|
|
lsi.import('f_contacts', response.local_data.contacts);
|
|
|
|
lsi.import('f_mini-fiches', response.local_data.mini);
|
|
|
|
lsi.import('f_fiches', response.local_data.fiches);
|
|
|
|
lsi.set('f_matrice', 0, response.local_data.matrice);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (3) On met à jour l'affichage */
|
|
|
|
fSubjectManager.storageToFields();
|
|
|
|
fContactManager.storageToFields();
|
|
|
|
fMatriceManager.storageToFields();
|
|
|
|
fDynamicUpdate(true);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
});
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (10) Gestion de la validation et de l'envoi des données
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$('[data-sublink="facebook"] #f_submit-all').addEventListener('click', function(e){
|
|
|
|
console.log('> GATHERING ALL DATA');
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (1) On met dans la mémoire tout les champs non enregistrés */
|
|
|
|
fSubjectManager.fieldsToStorage();
|
|
|
|
fContactManager.fieldsToStorage();
|
|
|
|
fMiniManager.fieldsToStorage();
|
|
|
|
fFicheManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (2) Vérification de la validité de toutes les données */
|
|
|
|
// {1} Vérification du sujet //
|
|
|
|
if( !fSubjectManager.check() ){
|
|
|
|
Notification.warning('Attention', 'Vous devez saisir les informations du <i>sujet</i>');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// {2} Vérification des mini-fiches //
|
|
|
|
var mini = lsi.export('f_mini-fiches');
|
|
|
|
var i = 0;
|
|
|
|
for( var id in mini ){ if( !isNaN(id) ){
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
i++
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
if( !mini[id].valid ){
|
|
|
|
Notification.warning('Attention', 'La <i>fiche rapide</i> <b>'+i+'</b> est incomplète et/ou incorrecte');
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}}
|
|
|
|
// {3} Vérification des fiches //
|
2016-05-22 12:49:20 +00:00
|
|
|
var fiches = lsi.export('f_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-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (3) On prépare la requête avec toutes les données */
|
|
|
|
var request = {
|
|
|
|
path: 'input/facebook',
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
subject: lsi.export('f_subject')[0],
|
|
|
|
contacts: lsi.export('f_contacts'),
|
|
|
|
mini: lsi.export('f_mini-fiches'),
|
|
|
|
fiches: lsi.export('f_fiches'),
|
|
|
|
matrice: lsi.export('f_matrice')[0]
|
|
|
|
};
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
/* (4) On envoie la requête et traite la réponse */
|
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
// Si erreur, on la notifie
|
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
Notification.error('ERREUR', response.ModuleError);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
console.log(response);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
}); }); }); }); });
|