2016-09-30 09:03:18 +00:00
|
|
|
var sField, sSubmit, sList,
|
2016-10-02 16:01:35 +00:00
|
|
|
pSubjectManager = null,
|
|
|
|
pContactManager = null,
|
|
|
|
pMiniManager = null,
|
|
|
|
pFicheManager = null,
|
|
|
|
pMatriceManager = null,
|
|
|
|
|
|
|
|
fSubjectManager = null,
|
|
|
|
fContactManager = null,
|
|
|
|
fMiniManager = null,
|
|
|
|
fFicheManager = null,
|
|
|
|
fMatriceManager = null;
|
2016-05-26 14:33:00 +00:00
|
|
|
|
2016-10-20 11:16:31 +00:00
|
|
|
var input_ts = Date.now();
|
2016-05-26 14:33:00 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/*=========================================================*/
|
|
|
|
/*=========== Gestion de la recherche de sujet ============*/
|
|
|
|
/*=========================================================*/
|
|
|
|
/* (1) On récupère les éléments utiles
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
sField = $('#search-field');
|
|
|
|
sSubmit = $('#search-subject');
|
|
|
|
sList = $('section[data-sublink="survey"] ul[data-list]');
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Routine de recherche
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
var tmpSubjectSearchListener = function(e){
|
|
|
|
|
|
|
|
/* (1) On construit la requête */
|
|
|
|
var request = {
|
|
|
|
path: 'subject/search',
|
|
|
|
name: sField.value
|
|
|
|
};
|
2016-05-26 14:33:00 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On effectue la requête */
|
|
|
|
api.send(request, function(response){
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-11-22 14:05:28 +00:00
|
|
|
console.warn(response);
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si erreur
|
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
Notification.error('Erreur', 'La recherche a échoué.')
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-26 14:33:00 +00:00
|
|
|
|
|
|
|
|
2016-05-27 08:39:39 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
console.log(response);
|
2016-05-26 14:33:00 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) On remplit la liste des résultats */
|
|
|
|
var htmlContent = [];
|
|
|
|
for( var id in response.results ){
|
|
|
|
htmlContent.push("<li data-element data-id='"+id+"'>");
|
|
|
|
htmlContent.push("<div data-user><span>SUJET</span></div>");
|
|
|
|
htmlContent.push("<div> <span><input type='text' readonly style='text-align: center' onclick='this.select()' class='flag' value='"+id+"'></span> </div>");
|
|
|
|
htmlContent.push("<div> <span data-prefix='Nom'>"+response.results[id].name+"</span> </div>");
|
|
|
|
htmlContent.push("<div> <span data-prefix='Création'>"+response.results[id].creation+"</span> </div>");
|
|
|
|
htmlContent.push("<div> <span><input type='checkbox' id='s_"+id+"' "+((response.results[id].phone!=null)?'checked':'')+" disabled><label for='s_"+id+"'>Cellulaire</label>");
|
|
|
|
htmlContent.push("</span> </div>");
|
|
|
|
htmlContent.push("<div> <span><input type='checkbox' id='s_"+id+"' "+((response.results[id].facebook!=null)?'checked':'')+" disabled><label for='s_"+id+"'>Facebook</label>");
|
|
|
|
htmlContent.push("</span> </div>");
|
2016-05-26 14:33:00 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
htmlContent.push( "</li>");
|
|
|
|
}
|
2016-05-26 14:33:00 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
sList.innerHTML = htmlContent.join('');
|
2016-05-26 14:33:00 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
});
|
2016-05-26 14:33:00 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
};
|
2016-05-26 14:33:00 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) Attachement des évènements
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
sSubmit.addEventListener('click', tmpSubjectSearchListener, false);
|
2016-05-26 14:33:00 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
sField.addEventListener('keypress', function(e){
|
|
|
|
if( e.keyCode === 13 )
|
|
|
|
tmpSubjectSearchListener(e);
|
|
|
|
}, false);
|
2016-05-26 14:33:00 +00:00
|
|
|
|
2016-11-05 10:59:42 +00:00
|
|
|
/* (4) On lance une recherche par défaut
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
tmpSubjectSearchListener();
|
2016-04-22 17:35:05 +00:00
|
|
|
|
2016-04-28 16:58:18 +00:00
|
|
|
|
2016-05-18 15:00:00 +00:00
|
|
|
|
|
|
|
|
2016-10-10 10:24:03 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/*=========================================================*/
|
|
|
|
/*========== Gestion du formulaire téléphonique ===========*/
|
|
|
|
/*=========================================================*/
|
2016-10-12 16:43:51 +00:00
|
|
|
var pAlready = 0;
|
|
|
|
var pLoaded = [ 0, 0, 0, 0, 0 ];
|
2016-05-18 15:00:00 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
var phoneRoutine = function(){
|
2016-10-12 16:43:51 +00:00
|
|
|
if( !Math.min.apply(Math, pLoaded) | pAlready )
|
2016-10-10 10:24:03 +00:00
|
|
|
return;
|
|
|
|
|
2016-10-12 16:43:51 +00:00
|
|
|
pAlready = 1;
|
2016-05-18 15:00:00 +00:00
|
|
|
|
2016-10-11 12:05:59 +00:00
|
|
|
console.groupEnd();
|
2016-10-10 08:58:44 +00:00
|
|
|
console.group('[phone] Initialization');
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (1) Gestion du formulaire du sujet
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du manager du sujet */
|
|
|
|
pSubjectManager = new inputPhoneSubject(
|
|
|
|
$('[data-sublink="phone"] article.subject-panel [data-name="subject_id"]'),
|
2016-12-13 18:37:44 +00:00
|
|
|
$('[data-sublink="phone"] #coord_p'),
|
2016-10-10 08:58:44 +00:00
|
|
|
$('[data-sublink="phone"] article.subject-panel [data-name="submit"]')
|
|
|
|
);
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
pSubjectManager.attach(pDynamicUpdate);
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-02 11:36:14 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) Gestion des formulaires de contact
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire des CONTACTS */
|
|
|
|
pContactManager = new inputPhoneContact(
|
|
|
|
$('[data-sublink="phone"] article.contact-panel'),
|
|
|
|
$('[data-sublink="phone"] #p_nav-contact')
|
|
|
|
);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
pContactManager.attach(pDynamicUpdate);
|
2016-05-03 13:18:09 +00:00
|
|
|
|
2016-05-09 07:34:17 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) Gestion des mini fiches relation
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire des mini fiches relation */
|
|
|
|
pMiniManager = new inputPhoneMini(
|
|
|
|
$('[data-sublink="phone"] article.mini-relation-panel'),
|
|
|
|
$('[data-sublink="phone"] #p_nav-mini')
|
|
|
|
);
|
2016-05-03 09:47:05 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
pMiniManager.attach(pDynamicUpdate);
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 19:47:52 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (4) Gestion des fiches relation
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire des fiches relation */
|
|
|
|
pFicheManager = new inputPhoneFiche(
|
|
|
|
$('[data-sublink="phone"] article.relation-panel'),
|
|
|
|
$('[data-sublink="phone"] #p_nav-fiche')
|
|
|
|
);
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On le démarre */
|
2016-10-12 16:43:51 +00:00
|
|
|
pFicheManager.top_size = 20;
|
2016-10-10 08:58:44 +00:00
|
|
|
pFicheManager.attach(pDynamicUpdate);
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (5) Gestion de la matrice de relations
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) On crée une instance du gestionnaire de la matrice */
|
|
|
|
pMatriceManager = new inputPhoneMatrice(
|
|
|
|
$('[data-sublink="phone"] article.matrice-panel')
|
|
|
|
);
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
pMatriceManager.attach(pDynamicUpdate);
|
2016-09-27 14:13:51 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +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');
|
|
|
|
lsi.clear('p_friends');
|
|
|
|
|
|
|
|
/* (2) On met à jour l'affichage */
|
|
|
|
pSubjectManager.storageToFields();
|
|
|
|
pContactManager.storageToFields();
|
|
|
|
pMiniManager.storageToFields();
|
|
|
|
pFicheManager.storageToFields();
|
|
|
|
pMatriceManager.storageToFields();
|
|
|
|
|
|
|
|
Notification.success('OK', 'Les données ont été supprimées');
|
|
|
|
}, false);
|
2016-09-27 14:13:51 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (8) Gestion de l'export des données locales
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$('[data-sublink="phone"] #p_export-all').addEventListener('click', function(e){
|
2016-09-27 14:13:51 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
Notification.info('INFORMATION', 'Lancement du téléchargement de la sauvegarde');
|
2016-09-27 14:13:51 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-09-27 14:13:51 +00:00
|
|
|
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +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
|
2016-11-27 16:34:53 +00:00
|
|
|
downloadTarget.download = 'local-phone-data.json'; // Nom du fichier qui sera téléchargé
|
2016-10-10 08:58:44 +00:00
|
|
|
downloadTarget.href = 'data:application/octet-stream,' + encodeURIComponent(JSON.stringify(data)); // Contenu
|
|
|
|
downloadTarget.click(); // On lance le téléchargement
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}, false);
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-03 14:29:12 +00:00
|
|
|
|
2016-05-03 14:46:38 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-12 15:01:31 +00:00
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-03 14:29:12 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) Upload et réponse */
|
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si erreur, on quitte
|
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
Notification.error('Erreur', response.ModuleError);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-12 15:01:31 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) On met à jour l'affichage */
|
|
|
|
pSubjectManager.storageToFields();
|
|
|
|
pContactManager.storageToFields();
|
2016-12-14 11:18:15 +00:00
|
|
|
pMiniManager.storageToFields();
|
|
|
|
pFicheManager.storageToFields();
|
2016-10-10 08:58:44 +00:00
|
|
|
pMatriceManager.storageToFields();
|
|
|
|
pDynamicUpdate(true);
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}, false);
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-09-27 14:13:51 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-09-27 14:13:51 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (1) On met dans la mémoire tout les champs non enregistrés */
|
|
|
|
pContactManager.fieldsToStorage();
|
|
|
|
pMiniManager.fieldsToStorage();
|
|
|
|
pFicheManager.fieldsToStorage();
|
|
|
|
|
|
|
|
/* (2) Vérification de la validité de toutes les données */
|
|
|
|
// {1} Vérification du sujet //
|
|
|
|
if( !pSubjectManager.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) ){
|
|
|
|
|
|
|
|
i++
|
|
|
|
|
|
|
|
if( !mini[id].valid ){
|
|
|
|
Notification.warning('Attention', 'La <i>fiche rapide</i> <b>'+i+'</b> est incomplète et/ou incorrecte');
|
2016-05-27 10:13:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}}
|
|
|
|
// {3} Vérification des fiches //
|
|
|
|
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-03 14:46:38 +00:00
|
|
|
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-05-12 15:01:31 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) On prépare la requête avec toutes les données */
|
|
|
|
var request = {
|
2016-11-06 13:22:15 +00:00
|
|
|
path: 'input/phone',
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-12-13 18:37:44 +00:00
|
|
|
subject: lsi.export('p_subject')[0],
|
2016-10-10 08:58:44 +00:00
|
|
|
contacts: lsi.export('p_contacts'),
|
|
|
|
mini: lsi.export('p_mini-fiches'),
|
|
|
|
fiches: lsi.export('p_fiches'),
|
|
|
|
matrice: lsi.export('p_matrice')[0]
|
|
|
|
};
|
2016-05-03 09:47:05 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (4) On envoie la requête et traite la réponse */
|
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
2016-05-03 14:29:12 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si erreur, on la notifie
|
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
Notification.error('ERREUR', response.ModuleError);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-03 14:46:38 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
Notification.success('OK', "L'identifiant du sujet est <strong>"+response.subject_id+"</strong> ! Tout s'est bien déroulé.", 10000);
|
2016-05-03 09:47:05 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
console.log(response);
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}, false);
|
2016-05-12 17:30:53 +00:00
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}, false);
|
2016-04-27 16:32:44 +00:00
|
|
|
|
|
|
|
|
2016-10-11 12:05:59 +00:00
|
|
|
console.groupEnd();
|
2016-04-27 16:32:44 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
};
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-10-12 16:43:51 +00:00
|
|
|
include('/js/includes/input-phone-subject.js', function(){ pLoaded[0] = 1; phoneRoutine(); });
|
|
|
|
include('/js/includes/input-phone-contact.js', function(){ pLoaded[1] = 1; phoneRoutine(); });
|
|
|
|
include('/js/includes/input-phone-mini.js', function(){ pLoaded[2] = 1; phoneRoutine(); });
|
|
|
|
include('/js/includes/input-phone-fiche.js', function(){ pLoaded[3] = 1; phoneRoutine(); });
|
|
|
|
include('/js/includes/input-phone-matrice.js', function(){ pLoaded[4] = 1; phoneRoutine(); });
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/*=========================================================*/
|
|
|
|
/*=========== Gestion du formulaire facebook ==============*/
|
|
|
|
/*=========================================================*/
|
2016-10-12 16:43:51 +00:00
|
|
|
var fAlready = 0;
|
|
|
|
var fLoaded = [ 0, 0, 0, 0, 0 ];
|
2016-10-11 10:44:53 +00:00
|
|
|
|
|
|
|
var facebookRoutine = function(){
|
2016-10-12 16:43:51 +00:00
|
|
|
if( !Math.min.apply(Math, fLoaded) | fAlready )
|
2016-10-11 10:44:53 +00:00
|
|
|
return;
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-10-12 16:43:51 +00:00
|
|
|
fAlready = 1;
|
2016-10-11 10:44:53 +00:00
|
|
|
|
2016-10-11 12:05:59 +00:00
|
|
|
console.groupEnd();
|
2016-10-11 10:44:53 +00:00
|
|
|
console.group('[facebook] Initialization');
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-10-10 08:58:44 +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="subject_id"]'),
|
2016-12-13 18:37:44 +00:00
|
|
|
$('[data-sublink="facebook"] #coord_f'),
|
2016-10-10 08:58:44 +00:00
|
|
|
$('[data-sublink="facebook"] article.subject-panel [data-name="submit"]')
|
|
|
|
);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
fSubjectManager.attach(fDynamicUpdate);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-05-02 19:21:09 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-03 10:08:24 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-10-10 08:58:44 +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-09 07:34:17 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
fMiniManager.attach(fDynamicUpdate);
|
2016-05-03 09:11:41 +00:00
|
|
|
|
2016-05-09 07:34:17 +00:00
|
|
|
|
2016-10-10 08:58:44 +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 10:08:24 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On le démarre */
|
2016-10-12 16:43:51 +00:00
|
|
|
fFicheManager.top_size = 20;
|
2016-10-10 08:58:44 +00:00
|
|
|
fFicheManager.attach(fDynamicUpdate);
|
2016-05-03 09:11:41 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +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-02 19:21:09 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On le démarre */
|
|
|
|
fMatriceManager.attach(fDynamicUpdate);
|
2016-05-02 19:21:09 +00:00
|
|
|
|
2016-04-30 09:33:01 +00:00
|
|
|
|
2016-10-10 08:58:44 +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');
|
|
|
|
lsi.clear('f_friends');
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) On met à jour l'affichage */
|
|
|
|
fSubjectManager.storageToFields();
|
|
|
|
fContactManager.storageToFields();
|
|
|
|
fMiniManager.storageToFields();
|
|
|
|
fFicheManager.storageToFields();
|
|
|
|
fMatriceManager.storageToFields();
|
|
|
|
|
|
|
|
Notification.success('OK', 'Les données ont été supprimées');
|
|
|
|
}, false);
|
2016-05-13 09:14:41 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +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-10-10 08:58:44 +00:00
|
|
|
Notification.info('INFORMATION', 'Lancement du téléchargement de la sauvegarde');
|
2016-05-10 14:51:09 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (1) On construit les données */
|
|
|
|
var data = {
|
2016-12-13 18:37:44 +00:00
|
|
|
subject: lsi.export('f_subject')[0],
|
2016-10-10 08:58:44 +00:00
|
|
|
contacts: lsi.export('f_contacts'),
|
|
|
|
mini: lsi.export('f_mini-fiches'),
|
|
|
|
fiches: lsi.export('f_fiches'),
|
|
|
|
matrice: lsi.export('f_matrice')[0]
|
|
|
|
};
|
2016-05-10 14:51:09 +00:00
|
|
|
|
2016-04-30 10:19:51 +00:00
|
|
|
|
2016-10-10 08:58:44 +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
|
2016-10-17 09:45:25 +00:00
|
|
|
downloadTarget.download = 'local-facebook-data.json'; // Nom du fichier qui sera téléchargé
|
2016-10-10 08:58:44 +00:00
|
|
|
downloadTarget.href = 'data:application/octet-stream,' + encodeURIComponent(JSON.stringify(data)); // Contenu
|
|
|
|
downloadTarget.click(); // On lance le téléchargement
|
2016-04-30 09:33:01 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}, false);
|
2016-05-13 09:47:45 +00:00
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-05-27 14:32:26 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +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-27 14:32:26 +00:00
|
|
|
|
2016-05-10 16:43:31 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-04-30 09:33:01 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) Upload et réponse */
|
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si erreur, on quitte
|
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
Notification.error('Erreur', response.ModuleError);
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-27 14:13:51 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-09-27 14:13:51 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) On met à jour l'affichage */
|
2016-12-14 11:18:15 +00:00
|
|
|
fSubjectManager.storageToFields();
|
|
|
|
fContactManager.storageToFields();
|
|
|
|
fMiniManager.storageToFields();
|
|
|
|
fFicheManager.storageToFields();
|
|
|
|
fMatriceManager.storageToFields();
|
|
|
|
fDynamicUpdate(true);
|
2016-04-30 09:33:01 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
});
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}, false);
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +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-10-10 08:58:44 +00:00
|
|
|
/* (1) On met dans la mémoire tout les champs non enregistrés */
|
2016-11-06 13:22:15 +00:00
|
|
|
// pSubjectManager.fieldsToStorage();
|
2016-10-11 10:44:53 +00:00
|
|
|
pContactManager.fieldsToStorage();
|
|
|
|
pMiniManager.fieldsToStorage();
|
|
|
|
pFicheManager.fieldsToStorage();
|
2016-05-18 12:46:13 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) Vérification de la validité de toutes les données */
|
|
|
|
// {1} Vérification du sujet //
|
2016-10-11 10:44:53 +00:00
|
|
|
if( !pSubjectManager.check() ){
|
2016-10-10 08:58:44 +00:00
|
|
|
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-10-10 08:58:44 +00:00
|
|
|
i++
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +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 15:00:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-10-10 08:58:44 +00:00
|
|
|
|
|
|
|
}}
|
|
|
|
// {3} Vérification des fiches //
|
|
|
|
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');
|
2016-05-22 12:49:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-05-18 12:46:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) On prépare la requête avec toutes les données */
|
|
|
|
var request = {
|
2016-11-06 13:22:15 +00:00
|
|
|
path: 'input/facebook',
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-10-10 08:58:44 +00:00
|
|
|
/* (4) On envoie la requête et traite la réponse */
|
|
|
|
api.send(request, function(response){
|
|
|
|
console.log(response);
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si erreur, on la notifie
|
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
Notification.error('ERREUR', response.ModuleError);
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-11 10:44:53 +00:00
|
|
|
Notification.success('OK', "L'identifiant du sujet est <strong>"+response.subject_id+"</strong> ! Tout s'est bien déroulé.", 10000);
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
console.log(response);
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}, false);
|
2016-05-26 17:43:50 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}, false);
|
2016-05-26 17:43:50 +00:00
|
|
|
|
|
|
|
|
2016-10-11 12:05:59 +00:00
|
|
|
console.groupEnd();
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-11 10:44:53 +00:00
|
|
|
};
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-12 16:43:51 +00:00
|
|
|
include('/js/includes/input-facebook-subject.js', function(){ fLoaded[0] = 1; facebookRoutine(); });
|
|
|
|
include('/js/includes/input-facebook-contact.js', function(){ fLoaded[1] = 1; facebookRoutine(); });
|
|
|
|
include('/js/includes/input-facebook-mini.js', function(){ fLoaded[2] = 1; facebookRoutine(); });
|
|
|
|
include('/js/includes/input-facebook-fiche.js', function(){ fLoaded[3] = 1; facebookRoutine(); });
|
|
|
|
include('/js/includes/input-facebook-matrice.js', function(){ fLoaded[4] = 1; facebookRoutine(); });
|
2016-05-26 17:43:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-02 11:04:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-09 15:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* [1] Initialisation des utilitaires et variables PHONE
|
|
|
|
=========================================================*/
|
|
|
|
/* (2) Fonctions utiles */
|
|
|
|
var pDynamicUpdate = function(target){
|
2016-10-09 15:44:06 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +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 == 'p_nav-mini' || target.parentNode.id == 'p_nav-fiche');
|
|
|
|
var isNavContact = isElement && target.tagName == 'SPAN' && target.parentNode.id == 'p_nav-contact';
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si erreur, on retourne une erreur
|
|
|
|
if( !isSaveButton && !isNavButton && !isNavContact && target !== true )
|
|
|
|
return false;
|
2016-10-09 15:44:06 +00:00
|
|
|
|
|
|
|
|
2016-10-12 14:20:46 +00:00
|
|
|
console.groupEnd(); console.groupEnd();
|
2016-10-10 08:58:44 +00:00
|
|
|
console.group('[phone] Dynamic Update');
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (1) On enregistre les MINI fiches relation */
|
|
|
|
pMiniManager.fieldsToStorage();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On enregister les FICHES relation */
|
|
|
|
pFicheManager.fieldsToStorage();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) On enregistre les CONTACTS */
|
|
|
|
pContactManager.fieldsToStorage();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (4) On enregistre la MATRICE */
|
|
|
|
pMatriceManager.fieldsToStorage();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +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
|
|
|
|
pFicheManager.sync();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (6) On synchronise les MINI avec les CONTACTS */
|
|
|
|
// Supprime les contacts déja dans les FICHES
|
|
|
|
pMiniManager.sync();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-11-23 15:36:25 +00:00
|
|
|
/* (7) On récupère tous les "amis" du sujet */
|
2016-10-10 08:58:44 +00:00
|
|
|
if( target === true ){
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
api.send({ path: 'subject/getFriends', subject_id: pSubjectManager.subject_id.value }, function(response){
|
2016-11-23 15:36:25 +00:00
|
|
|
console.warn('xx', response);
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si erreur, on quitte
|
2016-10-12 14:20:46 +00:00
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
console.groupEnd();
|
2016-10-10 08:58:44 +00:00
|
|
|
return false;
|
2016-10-12 14:20:46 +00:00
|
|
|
}
|
2016-10-10 08:58:44 +00:00
|
|
|
|
|
|
|
// On enregistre les contacts existants
|
|
|
|
lsi.import('p_friends', response.subjects);
|
2016-10-09 15:44:06 +00:00
|
|
|
|
|
|
|
/* (8) On affiche le tout */
|
|
|
|
pMiniManager.storageToFields();
|
|
|
|
pFicheManager.storageToFields();
|
|
|
|
pMatriceManager.storageToFields();
|
|
|
|
|
|
|
|
/* (8) On met à jour les contacts si on les a modifié on si on navigue dans les contacts */
|
2016-10-10 08:58:44 +00:00
|
|
|
pContactManager.storageToFields();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-20 11:16:31 +00:00
|
|
|
/* (9) On met à jour les barres de navigation */
|
|
|
|
pMiniManager.updateNavBar();
|
|
|
|
pFicheManager.updateNavBar();
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
});
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-02 11:04:32 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}else{
|
2016-10-02 11:04:32 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (8) On affiche le tout */
|
|
|
|
pMiniManager.storageToFields();
|
|
|
|
pFicheManager.storageToFields();
|
|
|
|
pMatriceManager.storageToFields();
|
2016-10-02 11:36:14 +00:00
|
|
|
|
2016-10-20 11:16:31 +00:00
|
|
|
/* (9) On met à jour les barres de navigation */
|
|
|
|
pMiniManager.updateNavBar();
|
|
|
|
pFicheManager.updateNavBar();
|
|
|
|
|
|
|
|
/* (10) On met à jour les contacts si on les a modifié on si on navigue dans les contacts */
|
2016-10-10 08:58:44 +00:00
|
|
|
( isSaveButton || isNavContact ) && pContactManager.storageToFields();
|
2016-10-02 11:36:14 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-11 12:05:59 +00:00
|
|
|
console.groupEnd();
|
2016-10-10 08:58:44 +00:00
|
|
|
};
|
2016-10-09 15:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* [2] Initialisation des utilitaires et variables FACEBEOOK
|
|
|
|
=========================================================*
|
|
|
|
/* (2) Fonctions utiles */
|
|
|
|
var fDynamicUpdate = function(target){
|
2016-10-09 15:44:06 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +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-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si erreur, on retourne une erreur
|
|
|
|
if( !isSaveButton && !isNavButton && !isNavContact && target !== true )
|
|
|
|
return false;
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-12 14:20:46 +00:00
|
|
|
console.groupEnd(); console.groupEnd();
|
2016-10-10 08:58:44 +00:00
|
|
|
console.group('[facebook] Dynamic Update');
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (1) On enregistre les MINI fiches relation */
|
|
|
|
fMiniManager.fieldsToStorage();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On enregister les FICHES relation */
|
|
|
|
fFicheManager.fieldsToStorage();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) On enregistre les CONTACTS */
|
|
|
|
fContactManager.fieldsToStorage();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (4) On enregistre la MATRICE */
|
|
|
|
fMatriceManager.fieldsToStorage();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (6) On synchronise les MINI avec les CONTACTS */
|
|
|
|
// Supprime les contacts déja dans les FICHES
|
|
|
|
fMiniManager.sync();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (7) On récupère tous les amis du sujet */
|
|
|
|
if( target === true ){
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
api.send({ path: 'subject/getFriends', subject_id: fSubjectManager.subject_id.value }, function(response){
|
|
|
|
// Si erreur, on quitte
|
2016-10-12 14:20:46 +00:00
|
|
|
if( response.ModuleError != 0 ){
|
|
|
|
console.groupEnd();
|
2016-10-10 08:58:44 +00:00
|
|
|
return false;
|
2016-10-12 14:20:46 +00:00
|
|
|
}
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// On enregistre les contacts existants
|
|
|
|
lsi.import('f_friends', response.subjects);
|
2016-10-09 15:44:06 +00:00
|
|
|
|
|
|
|
/* (8) On affiche le tout */
|
|
|
|
fMiniManager.storageToFields();
|
|
|
|
fFicheManager.storageToFields();
|
|
|
|
fMatriceManager.storageToFields();
|
|
|
|
|
|
|
|
/* (8) On met à jour les contacts si on les a modifié on si on navigue dans les contacts */
|
2016-10-10 08:58:44 +00:00
|
|
|
fContactManager.storageToFields();
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
});
|
2016-10-02 11:36:14 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}else{
|
2016-10-02 11:04:32 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (8) On affiche le tout */
|
|
|
|
fMiniManager.storageToFields();
|
|
|
|
fFicheManager.storageToFields();
|
|
|
|
fMatriceManager.storageToFields();
|
2016-10-02 11:04:32 +00:00
|
|
|
|
2016-10-10 08:58:44 +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-10-02 11:04:32 +00:00
|
|
|
|
2016-10-11 12:05:59 +00:00
|
|
|
console.groupEnd();
|
2016-10-10 08:58:44 +00:00
|
|
|
|
|
|
|
};
|
2016-10-02 11:04:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-09 15:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-26 17:43:50 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/*=========================================================*/
|
|
|
|
/*============= Routine de test CELLULAIRE ================*/
|
|
|
|
/*=========================================================*/
|
|
|
|
function testContactsPhone(){
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
for( var i = 0 ; i < 45 ; i++ ){
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
if( i%20 == 0 )
|
2016-11-28 10:50:26 +00:00
|
|
|
lsi.set('p_contacts', i, { uid: i, username: 'contact-x', existing: '.' });
|
2016-10-10 08:58:44 +00:00
|
|
|
else
|
2016-11-28 10:50:26 +00:00
|
|
|
lsi.set('p_contacts', i, { uid: i, username: 'contact-'+i, existing: '.' });
|
2016-10-10 08:58:44 +00:00
|
|
|
}
|
|
|
|
};
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
function testRoutinePhone(doMini){
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* [0] Récupération des données
|
|
|
|
=========================================================*/
|
|
|
|
var contacts = lsi.export('p_contacts');
|
|
|
|
var mini = lsi.export('p_mini-fiches');
|
|
|
|
var fiches = lsi.export('p_fiches');
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
var count = 0;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* [1] Remplissage des mini-fiches
|
|
|
|
=========================================================*/
|
|
|
|
if( doMini != null && doMini ){
|
|
|
|
for( var m in mini ){
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (0) Si la fiche n'est pas affichée, on passe à la suivante */
|
|
|
|
if( isNaN(m) )
|
|
|
|
continue;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (1) On récupére le nom du contact associé */
|
|
|
|
var name = '';
|
|
|
|
if( contacts[m] != null )
|
|
|
|
name = contacts[m].username;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On remplit la mini fiche */
|
|
|
|
// {1} On se positionne sur la fiche en question //
|
|
|
|
var navBut = $('#p_nav-mini [data-n="'+m+'"]');
|
|
|
|
navBut.click();
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {2} Si la personne n'a pas de nom, on met que ce contact est inconnu, puis les valeurs par défaut //
|
|
|
|
$('#unknown_min_p_'+m).checked = name.length == 0;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
|
|
|
|
2016-12-15 12:18:37 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) Si personne inconnue -> valeurs indéterminées */
|
|
|
|
if( name.length == 0 ){
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {1} Sexe indéterminé //
|
|
|
|
$('#sexeI_mini_p_'+m).checked = true;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {2} Age indéterminé //
|
|
|
|
$('input[data-name="uid"][value="'+m+'"] ~ h5 select[data-name="age"]').value = count % 19;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {3} Etudes indéterminées //
|
|
|
|
$('input[data-name="uid"][value="'+m+'"] ~ h5 select[data-name="studies"]').value = 0;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {4} Type de relation inconnue //
|
|
|
|
$('#reltype9_mini_p_'+m).checked = true;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
continue;
|
|
|
|
/* (4) Si la personne est connue on incrémente les valeurs */
|
|
|
|
}else{
|
|
|
|
|
|
|
|
// {1} On remplit le sexe //
|
|
|
|
var sexeVal = ['H', 'F'][ Math.floor(count % 2) ];
|
|
|
|
$('#sexe'+sexeVal+'_mini_p_'+m).checked = true;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {2} On remplit l'age //
|
|
|
|
$('input[data-name="uid"][value="'+m+'"] ~ h5 select[data-name="age"]').value = count % 19;
|
|
|
|
|
|
|
|
// {3} On remplit les études //
|
|
|
|
$('input[data-name="uid"][value="'+m+'"] ~ h5 select[data-name="studies"]').value = 1 + (count % 6);
|
|
|
|
|
|
|
|
// {4} Type de relation //
|
2016-12-15 11:23:14 +00:00
|
|
|
var relVal = count % 9;
|
|
|
|
if( relVal == 7 ) relVal = 9; // value 7,8 removed so 9 directly
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si AUTRE
|
2016-12-15 11:23:14 +00:00
|
|
|
if( relVal == 8 ){
|
2016-10-10 08:58:44 +00:00
|
|
|
$('#reltype10_mini_p_'+m).checked = true;
|
|
|
|
$('input[data-name="uid"][value="'+m+'"] ~ h5 input[data-name="reltypeSpecial"]').value = 'autre';
|
|
|
|
// Sinon
|
|
|
|
}else
|
|
|
|
$('#reltype'+relVal+'_mini_p_'+m).checked = true;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-12-15 12:18:37 +00:00
|
|
|
// {7} Temps entre les domiciles //
|
|
|
|
var locVal = ['X', 'A', 'B', 'C', 'D'][ Math.floor(count % 5) ];
|
|
|
|
$('#loc'+locVal+'_mini_p_'+m).checked = true;
|
2016-05-26 17:43:50 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
count++;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-26 17:43:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* [2] Remplissage des fiches complètes
|
2016-12-15 12:18:37 +00:00
|
|
|
*
|
|
|
|
*
|
2016-10-10 08:58:44 +00:00
|
|
|
=========================================================*/
|
|
|
|
for( var f in fiches ){
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (0) Si la fiche n'est pas affichée, on passe à la suivante */
|
|
|
|
if( isNaN(f) )
|
|
|
|
continue;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (1) On récupére le nom du contact associé */
|
|
|
|
var name = '';
|
|
|
|
if( contacts[fiches[f].contact] != null )
|
|
|
|
name = contacts[fiches[f].contact].username;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On remplit la fiche */
|
2016-12-15 11:23:14 +00:00
|
|
|
// {1} On se positionne sur la fiche en question //
|
|
|
|
var navBut = $('#p_nav-fiche [data-n="'+f+'"]');
|
|
|
|
navBut.click();
|
2016-05-26 17:43:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {1} On remplit le sexe //
|
|
|
|
var sexeVal = ['H', 'F', 'I'][ Math.floor(count % 3) ];
|
|
|
|
$('#sexe'+sexeVal+'_p_'+f).checked = true;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {2} On remplit l'age //
|
|
|
|
$('article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 select[data-name="age"]').value = count % 19;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {3} On remplit la profession //
|
2016-12-13 18:37:44 +00:00
|
|
|
var jobVal = (count % 13).toString();
|
2016-10-10 08:58:44 +00:00
|
|
|
$('article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 select[data-name="job"]').value = jobVal;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {4} On remplit les études //
|
2016-12-13 18:37:44 +00:00
|
|
|
var stuVal = (count % 8).toString();
|
2016-10-10 08:58:44 +00:00
|
|
|
$('article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 select[data-name="studies"]').value = stuVal;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {5} Type de relation //
|
2016-11-27 16:08:10 +00:00
|
|
|
var relVal = count % 8;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si AUTRE
|
2016-11-27 16:08:10 +00:00
|
|
|
if( relVal == 7 ){
|
2016-10-10 08:58:44 +00:00
|
|
|
$('#reltype10_p_'+f).checked = true;
|
|
|
|
$('article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="reltypeSpecial"]').value = 'autre';
|
|
|
|
// Sinon
|
|
|
|
}else
|
|
|
|
$('#reltype'+relVal+'_p_'+f).checked = true;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {6} La ville, le CP et le quartier //
|
|
|
|
$('article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="city"]').value = (10 + count).toString();
|
|
|
|
$('article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="cp"]').value = (10000 + count).toString();
|
|
|
|
$('article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="quartier"]').value = count;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {7} Temps entre les domiciles //
|
|
|
|
var locVal = ['A', 'B', 'C', 'D'][ Math.floor(count % 4) ];
|
|
|
|
$('#loc'+locVal+'_p_'+f).checked = true;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-11-27 16:08:10 +00:00
|
|
|
// {7} Situation familiale //
|
|
|
|
var famsitVal = ['A', 'B', 'C', 'D'][ Math.floor(count % 4) ];
|
|
|
|
$('#famsit'+famsitVal+'_p_'+f).checked = true;
|
|
|
|
|
|
|
|
// {7} Situation familiale //
|
|
|
|
var famsitVal = ['A', 'B', 'C', 'D'][ Math.floor(count % 4) ];
|
|
|
|
$('#famsit'+famsitVal+'_p_'+f).checked = true;
|
|
|
|
|
|
|
|
// {7} Utilisation des Medias Sociaux //
|
|
|
|
var medsocVal = ['A', 'B', 'C', 'D'][ Math.floor(count % 4) ];
|
|
|
|
$('#medsoc'+medsocVal+'_p_'+f).checked = true;
|
|
|
|
|
|
|
|
// {7} Relation via médias sociaux //
|
|
|
|
var medrelVal = ['A', 'B', 'C'][ Math.floor(count % 3) ];
|
|
|
|
$('#medrel'+medrelVal+'_p_'+f).checked = true;
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {8} Temps de connaissance //
|
2016-12-14 11:18:15 +00:00
|
|
|
var duration = $$('section[data-sublink="phone"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="duration"]');
|
2016-10-10 08:58:44 +00:00
|
|
|
duration[0].value = count.toString();
|
|
|
|
duration[1].value = 1+count.toString();
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {9} Contexte de rencontre //
|
|
|
|
var ctxVal = count % 14;
|
|
|
|
$('article.fiche-relation #contexte'+ctxVal+'_p_'+f).checked = true;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-12-14 11:18:15 +00:00
|
|
|
var ctxSpe = $$('section[data-sublink="phone"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="contextSpecial"]');
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si special1
|
|
|
|
if( ctxVal == 11 )
|
|
|
|
ctxSpe[0].value = 'internet';
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si special2
|
|
|
|
if( ctxVal == 12 )
|
|
|
|
ctxSpe[1].value = 'association';
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si special3
|
|
|
|
if( ctxVal == 13 )
|
|
|
|
ctxSpe[2].value = 'autre';
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-11-27 16:08:10 +00:00
|
|
|
// {3} On remplit les interets //
|
|
|
|
var interestVal = ['0','1','2','3','4'];
|
|
|
|
interestVal = interestVal[ count % interestVal.length ];
|
|
|
|
$('article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 select[data-name="interest"]').value = interestVal;
|
|
|
|
|
|
|
|
// {3} On remplit la relation avec la personne //
|
|
|
|
var relmarkVal = ['0','1','2','3','4'];
|
|
|
|
relmarkVal = relmarkVal[ count % relmarkVal.length ];
|
|
|
|
$('article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 select[data-name="relmark"]').value = relmarkVal;
|
|
|
|
|
|
|
|
|
|
|
|
// FREQ
|
|
|
|
var freqVal;
|
|
|
|
for( var i = 0 ; i < 5 ; i++ ){
|
|
|
|
freqVal = 1+ i*5+ Math.floor( count % 4 );
|
|
|
|
if( freqVal < 10 ) freqVal = '0'+freqVal;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-11-27 16:08:10 +00:00
|
|
|
$('#freq'+freqVal+'_p_'+f).checked = true;
|
|
|
|
}
|
|
|
|
// IRLFREQ
|
|
|
|
var irlfreqVal;
|
|
|
|
for( var i = 0 ; i < 5 ; i++ ){
|
|
|
|
irlfreqVal = 1+ i*5+ Math.floor( count % 4 );
|
|
|
|
if( irlfreqVal < 10 ) irlfreqVal = '0'+irlfreqVal;
|
|
|
|
|
|
|
|
$('#irlfreq'+irlfreqVal+'_p_'+f).checked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CONNECT
|
|
|
|
var connectVal;
|
|
|
|
for( var i = 1 ; i < 7 ; i++ ){
|
|
|
|
connectVal = 1+ Math.floor( count % 2 );
|
|
|
|
|
|
|
|
$('#connect'+i+''+connectVal+'_p_'+f).checked = true;
|
|
|
|
}
|
2016-10-10 08:58:44 +00:00
|
|
|
|
|
|
|
count++;
|
2016-05-26 17:43:50 +00:00
|
|
|
|
2016-09-27 14:13:51 +00:00
|
|
|
}
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}
|
2016-05-27 14:32:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/*=========================================================*/
|
|
|
|
/*============== Routine de test FACEBOOK =================*/
|
|
|
|
/*=========================================================*/
|
|
|
|
function testContactsFacebook(){
|
2016-10-09 15:44:06 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
for( var i = 0 ; i < 45 ; i++ ){
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
if( i%20 == 0 )
|
2016-11-28 10:50:26 +00:00
|
|
|
lsi.set('f_contacts', i, { uid: i, username: 'contact-x', existing: '.' });
|
2016-10-10 08:58:44 +00:00
|
|
|
else
|
2016-11-28 10:50:26 +00:00
|
|
|
lsi.set('f_contacts', i, { uid: i, username: 'contact-'+i, existing: '.' });
|
2016-10-10 08:58:44 +00:00
|
|
|
}
|
|
|
|
};
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
function testRoutineFacebook(doMini){
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* [0] Récupération des données
|
|
|
|
=========================================================*/
|
|
|
|
var contacts = lsi.export('f_contacts');
|
|
|
|
var mini = lsi.export('f_mini-fiches');
|
|
|
|
var fiches = lsi.export('f_fiches');
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
var count = 0;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* [1] Remplissage des mini-fiches
|
|
|
|
=========================================================*/
|
|
|
|
if( doMini != null && doMini ){
|
|
|
|
for( var m in mini ){
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (0) Si la fiche n'est pas affichée, on passe à la suivante */
|
|
|
|
if( isNaN(m) )
|
|
|
|
continue;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (1) On récupére le nom du contact associé */
|
|
|
|
var name = '';
|
|
|
|
if( contacts[m] != null )
|
|
|
|
name = contacts[m].username;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On remplit la mini fiche */
|
|
|
|
// {1} On se positionne sur la fiche en question //
|
|
|
|
var navBut = $('#f_nav-mini [data-n="'+m+'"]');
|
|
|
|
navBut.click();
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {2} Si la personne n'a pas de nom, on met que ce contact est inconnu, puis les valeurs par défaut //
|
|
|
|
$('#unknown_min_f_'+m).checked = name.length == 0;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (3) Si personne inconnue -> valeurs indéterminées */
|
|
|
|
if( name.length == 0 ){
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {1} Sexe indéterminé //
|
|
|
|
$('#sexeI_mini_f_'+m).checked = true;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {2} Age indéterminé //
|
|
|
|
$('input[data-name="uid"][value="'+m+'"] ~ h5 select[data-name="age"]').value = count % 19;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {3} Etudes indéterminées //
|
|
|
|
$('input[data-name="uid"][value="'+m+'"] ~ h5 select[data-name="studies"]').value = 0;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {4} Type de relation inconnue //
|
|
|
|
$('#reltype9_mini_f_'+m).checked = true;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
continue;
|
|
|
|
/* (4) Si la personne est connue on incrémente les valeurs */
|
|
|
|
}else{
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {1} On remplit le sexe //
|
|
|
|
var sexeVal = ['H', 'F'][ Math.floor(count % 2) ];
|
|
|
|
$('#sexe'+sexeVal+'_mini_f_'+m).checked = true;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {2} On remplit l'age //
|
|
|
|
$('input[data-name="uid"][value="'+m+'"] ~ h5 select[data-name="age"]').value = count % 19;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {3} On remplit les études //
|
|
|
|
$('input[data-name="uid"][value="'+m+'"] ~ h5 select[data-name="studies"]').value = 1 + (count % 6);
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {4} Type de relation //
|
2016-12-15 11:23:14 +00:00
|
|
|
var relVal = count % 9;
|
|
|
|
if( relVal == 7 ) relVal = 9; // value 7,8 removed so 9 directly
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si AUTRE
|
2016-12-15 11:23:14 +00:00
|
|
|
if( relVal == 8 ){
|
2016-10-10 08:58:44 +00:00
|
|
|
$('#reltype10_mini_f_'+m).checked = true;
|
|
|
|
$('input[data-name="uid"][value="'+m+'"] ~ h5 input[data-name="reltypeSpecial"]').value = 'autre';
|
|
|
|
// Sinon
|
|
|
|
}else
|
|
|
|
$('#reltype'+relVal+'_mini_f_'+m).checked = true;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-12-15 12:18:37 +00:00
|
|
|
// {7} Temps entre les domiciles //
|
|
|
|
var locVal = ['X', 'A', 'B', 'C', 'D'][ Math.floor(count % 5) ];
|
|
|
|
$('#loc'+locVal+'_mini_f_'+m).checked = true;
|
2016-09-27 14:13:51 +00:00
|
|
|
}
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
count++;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-09-27 14:13:51 +00:00
|
|
|
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* [2] Remplissage des fiches complètes
|
|
|
|
=========================================================*/
|
|
|
|
for( var f in fiches ){
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (0) Si la fiche n'est pas affichée, on passe à la suivante */
|
|
|
|
if( isNaN(f) )
|
|
|
|
continue;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (1) On récupére le nom du contact associé */
|
|
|
|
var name = '';
|
|
|
|
if( contacts[fiches[f].contact] != null )
|
|
|
|
name = contacts[fiches[f].contact].username;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
/* (2) On remplit la fiche */
|
|
|
|
// {1} On se positionne sur la fiche en question //
|
|
|
|
var navBut = $('#f_nav-fiche [data-n="'+f+'"]');
|
|
|
|
navBut.click();
|
2016-05-27 14:32:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {1} On remplit le sexe //
|
|
|
|
var sexeVal = ['H', 'F', 'I'][ Math.floor(count % 3) ];
|
|
|
|
$('#sexe'+sexeVal+'_f_'+f).checked = true;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {2} On remplit l'age //
|
|
|
|
$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 select[data-name="age"]').value = count % 19;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {3} On remplit la profession //
|
2016-12-13 18:37:44 +00:00
|
|
|
var jobVal = (count % 13).toString();
|
2016-10-10 08:58:44 +00:00
|
|
|
jobVal = jobVal[ count % jobVal.length ];
|
|
|
|
$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 select[data-name="job"]').value = jobVal;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {4} On remplit les études //
|
2016-12-13 18:37:44 +00:00
|
|
|
var stuVal = (count % 8).toString();
|
2016-10-10 08:58:44 +00:00
|
|
|
if( stuVal.length == 1 ) stuVal = '0'+stuVal;
|
|
|
|
$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 select[data-name="studies"]').value = stuVal;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {5} Type de relation //
|
2016-12-14 11:18:15 +00:00
|
|
|
var relVal = count % 8;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si AUTRE
|
2016-12-14 11:18:15 +00:00
|
|
|
if( relVal == 7 ){
|
2016-10-10 08:58:44 +00:00
|
|
|
$('#reltype10_f_'+f).checked = true;
|
|
|
|
$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="reltypeSpecial"]').value = 'autre';
|
|
|
|
// Sinon
|
|
|
|
}else
|
|
|
|
$('#reltype'+relVal+'_f_'+f).checked = true;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {6} La ville, le CP et le quartier //
|
|
|
|
$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="city"]').value = (10 + count).toString();
|
|
|
|
$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="cp"]').value = (10000 + count).toString();
|
|
|
|
$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="quartier"]').value = count;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {7} Temps entre les domiciles //
|
|
|
|
var locVal = ['A', 'B', 'C', 'D'][ Math.floor(count % 4) ];
|
|
|
|
$('#loc'+locVal+'_f_'+f).checked = true;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-12-14 11:18:15 +00:00
|
|
|
// {7} Situation familiale //
|
|
|
|
var famsitVal = ['A', 'B', 'C', 'D'][ Math.floor(count % 4) ];
|
|
|
|
$('#famsit'+famsitVal+'_f_'+f).checked = true;
|
|
|
|
|
|
|
|
// {7} Situation familiale //
|
|
|
|
var famsitVal = ['A', 'B', 'C', 'D'][ Math.floor(count % 4) ];
|
|
|
|
$('#famsit'+famsitVal+'_f_'+f).checked = true;
|
|
|
|
|
|
|
|
// {7} Utilisation des Medias Sociaux //
|
|
|
|
var medsocVal = ['A', 'B', 'C', 'D'][ Math.floor(count % 4) ];
|
|
|
|
$('#medsoc'+medsocVal+'_f_'+f).checked = true;
|
|
|
|
|
|
|
|
// {7} Relation via médias sociaux //
|
|
|
|
var medrelVal = ['A', 'B', 'C'][ Math.floor(count % 3) ];
|
|
|
|
$('#medrel'+medrelVal+'_f_'+f).checked = true;
|
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {8} Temps de connaissance //
|
|
|
|
var duration = $$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="duration"]');
|
|
|
|
duration[0].value = count.toString();
|
|
|
|
duration[1].value = 1+count.toString();
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// {9} Contexte de rencontre //
|
|
|
|
var ctxVal = count % 14;
|
|
|
|
$('section[data-sublink="facebook"] article.fiche-relation #contexte'+ctxVal+'_f_'+f).checked = true;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
var ctxSpe = $$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 input[data-name="contextSpecial"]');
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si special1
|
|
|
|
if( ctxVal == 11 )
|
|
|
|
ctxSpe[0].value = 'internet';
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si special2
|
|
|
|
if( ctxVal == 12 )
|
|
|
|
ctxSpe[1].value = 'association';
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
// Si special3
|
|
|
|
if( ctxVal == 13 )
|
|
|
|
ctxSpe[2].value = 'autre';
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-12-14 11:18:15 +00:00
|
|
|
// {3} On remplit les interets //
|
|
|
|
var interestVal = ['0','1','2','3','4'];
|
|
|
|
interestVal = interestVal[ count % interestVal.length ];
|
|
|
|
$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 select[data-name="interest"]').value = interestVal;
|
|
|
|
|
|
|
|
// {3} On remplit la relation avec la personne //
|
|
|
|
var relmarkVal = ['0','1','2','3','4'];
|
|
|
|
relmarkVal = relmarkVal[ count % relmarkVal.length ];
|
|
|
|
$('section[data-sublink="facebook"] article.fiche-relation > input[data-name="uid"][value="'+f+'"] ~ h5 select[data-name="relmark"]').value = relmarkVal;
|
|
|
|
|
|
|
|
|
|
|
|
// FREQ
|
|
|
|
var freqVal;
|
|
|
|
for( var i = 0 ; i < 5 ; i++ ){
|
|
|
|
freqVal = 1+ i*5+ Math.floor( count % 4 );
|
|
|
|
if( freqVal < 10 ) freqVal = '0'+freqVal;
|
|
|
|
|
|
|
|
$('#freq'+freqVal+'_f_'+f).checked = true;
|
|
|
|
}
|
|
|
|
// IRLFREQ
|
|
|
|
var irlfreqVal;
|
|
|
|
for( var i = 0 ; i < 5 ; i++ ){
|
|
|
|
irlfreqVal = 1+ i*5+ Math.floor( count % 4 );
|
|
|
|
if( irlfreqVal < 10 ) irlfreqVal = '0'+irlfreqVal;
|
|
|
|
|
|
|
|
$('#irlfreq'+irlfreqVal+'_f_'+f).checked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CONNECT
|
|
|
|
var connectVal;
|
|
|
|
for( var i = 1 ; i < 7 ; i++ ){
|
|
|
|
connectVal = 1+ Math.floor( count % 2 );
|
|
|
|
|
|
|
|
$('#connect'+i+''+connectVal+'_f_'+f).checked = true;
|
|
|
|
}
|
2016-05-27 14:32:26 +00:00
|
|
|
|
2016-10-10 08:58:44 +00:00
|
|
|
|
|
|
|
count++;
|
2016-05-27 14:32:26 +00:00
|
|
|
|
|
|
|
}
|
2016-10-10 08:58:44 +00:00
|
|
|
|
|
|
|
}
|