Inclusion de la `matrice` dans l'export/import de données de formulaire local

This commit is contained in:
xdrm-brackets 2016-05-09 09:34:17 +02:00
parent 0ed57c8b50
commit 56ed406653
4 changed files with 58 additions and 11 deletions

View File

@ -125,6 +125,13 @@
/* IMPORT D'UN JOURNAL D'APPEL /* IMPORT D'UN JOURNAL D'APPEL
* *
* @file<FILE> Pointeur vers $_FILES[''] * @file<FILE> Pointeur vers $_FILES['']
@ -202,6 +209,10 @@
/* IMPORT D'UNE SAUVEGARDE DE FORMULAIRE LOCAL /* IMPORT D'UNE SAUVEGARDE DE FORMULAIRE LOCAL
* *
* @file<FILE> Pointeur vers $_FILES[''] * @file<FILE> Pointeur vers $_FILES['']
@ -228,6 +239,7 @@
$checkLevel0 = $checkLevel0 && isset($json['contacts']) && is_array($json['contacts']); $checkLevel0 = $checkLevel0 && isset($json['contacts']) && is_array($json['contacts']);
$checkLevel0 = $checkLevel0 && isset($json['mini']) && is_array($json['mini']); $checkLevel0 = $checkLevel0 && isset($json['mini']) && is_array($json['mini']);
$checkLevel0 = $checkLevel0 && isset($json['fiches']) && is_array($json['fiches']); $checkLevel0 = $checkLevel0 && isset($json['fiches']) && is_array($json['fiches']);
$checkLevel0 = $checkLevel0 && isset($json['matrice']) && is_array($json['matrice']);
// Erreur si level 0 incorrect // Erreur si level 0 incorrect
if( !$checkLevel0 ) if( !$checkLevel0 )
@ -305,6 +317,21 @@
} }
/* (7) Vérification de la matrice */
foreach($json['matrice'] as $idA=>$Bs){
$checkMatrice = is_numeric($idA);
if( !is_array($Bs) )
return false;
// Pour chaque relation entre le sujet d'id @idA et le sujet d'id $B
foreach($Bs as $B)
$checkMatrice = $checkMatrice && is_numeric($B);
if( !$checkMatrice )
return false;
}
return true; return true;
} }

File diff suppressed because one or more lines are too long

19
view/js/input-min.js vendored
View File

@ -1,12 +1,13 @@
var subjectManager,contactManager,miniManager,ficheManager,matriceManager,defTrue={status:!0,value:"on"},defFalse={status:!1,value:"on"}; var subjectManager,contactManager,miniManager,ficheManager,matriceManager,defTrue={status:!0,value:"on"},defFalse={status:!1,value:"on"};
function dynamicUpdate(a){var b=a instanceof Element,e=b&&"SPAN"==a.tagName&&"switch-left"==a.className,f=b&&"SPAN"==a.tagName&&"switch-both"==a.className,c=b&&"INPUT"==a.tagName&&"submit"==a.type,d=b&&"SPAN"==a.tagName&&("nav-mini"==a.parentNode.id||"nav-fiche"==a.parentNode.id),b=b&&"SPAN"==a.tagName&&"nav-contact"==a.parentNode.id;if(!(f||e||c||d||b)&&!0!==a)return!1;if(f)console.log("> switch firstname <-> lastname"),e=a.parentNode,a=e.children[8],e=e.children[10],f=a.value,a.value=e.value,e.value= function dynamicUpdate(a){var f=a instanceof Element,b=f&&"SPAN"==a.tagName&&"switch-left"==a.className,e=f&&"SPAN"==a.tagName&&"switch-both"==a.className,c=f&&"INPUT"==a.tagName&&"submit"==a.type,d=f&&"SPAN"==a.tagName&&("nav-mini"==a.parentNode.id||"nav-fiche"==a.parentNode.id),f=f&&"SPAN"==a.tagName&&"nav-contact"==a.parentNode.id;if(!(e||b||c||d||f)&&!0!==a)return!1;if(e)console.log("> switch firstname <-> lastname"),b=a.parentNode,a=b.children[8],b=b.children[10],e=a.value,a.value=b.value,b.value=
f;else if(e){console.log("> switch firstname+lastname -> username");e=a.parentNode;f=e.children[6];a=e.children[8];e=e.children[10];if(0<f.value.length||0==a.value.length&&0==e.value.length)return!1;f.value=a.value+" "+e.value;a.value="";e.value=""}else console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),matriceManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(), e;else if(b){console.log("> switch firstname+lastname -> username");b=a.parentNode;e=b.children[6];a=b.children[8];b=b.children[10];if(0<e.value.length||0==a.value.length&&0==b.value.length)return!1;e.value=a.value+" "+b.value;a.value="";b.value=""}else console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),matriceManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),
matriceManager.storageToFields(),(c||b)&&contactManager.storageToFields()}function checkRadioValue(a){for(var b=0,e=0;e<a.length;e++)!0===a[e].status&&b++;return 1!=b?!1:!0} matriceManager.storageToFields(),(c||f)&&contactManager.storageToFields()}function checkRadioValue(a){for(var f=0,b=0;b<a.length;b++)!0===a[b].status&&f++;return 1!=f?!1:!0}
include("/js/includes/input-phone-subject.js",function(){include("/js/includes/input-phone-contact.js",function(){include("/js/includes/input-phone-mini.js",function(){include("/js/includes/input-phone-fiche.js",function(){include("/js/includes/input-phone-matrice.js",function(){subjectManager=new inputPhoneSubject($('article.subject-panel [data-name="number"]'),$('article.subject-panel [data-name="username"]'),$('article.subject-panel [data-name="firstname"]'),$('article.subject-panel [data-name="lastname"]'), include("/js/includes/input-phone-subject.js",function(){include("/js/includes/input-phone-contact.js",function(){include("/js/includes/input-phone-mini.js",function(){include("/js/includes/input-phone-fiche.js",function(){include("/js/includes/input-phone-matrice.js",function(){subjectManager=new inputPhoneSubject($('article.subject-panel [data-name="number"]'),$('article.subject-panel [data-name="username"]'),$('article.subject-panel [data-name="firstname"]'),$('article.subject-panel [data-name="lastname"]'),
$('article.subject-panel [data-name="submit"]'));subjectManager.attach();contactManager=new inputPhoneContact($("article.contact-panel"),$("#nav-contact"));contactManager.attach(dynamicUpdate);miniManager=new inputPhoneMini($("article.mini-relation-panel"),$("#nav-mini"));miniManager.attach(dynamicUpdate);ficheManager=new inputPhoneFiche($("article.relation-panel"),$("#nav-fiche"));ficheManager.attach(dynamicUpdate);matriceManager=new inputPhoneMatrice($("article.matrice-panel"));matriceManager.attach(dynamicUpdate); $('article.subject-panel [data-name="submit"]'));subjectManager.attach();contactManager=new inputPhoneContact($("article.contact-panel"),$("#nav-contact"));contactManager.attach(dynamicUpdate);miniManager=new inputPhoneMini($("article.mini-relation-panel"),$("#nav-mini"));miniManager.attach(dynamicUpdate);ficheManager=new inputPhoneFiche($("article.relation-panel"),$("#nav-fiche"));ficheManager.attach(dynamicUpdate);matriceManager=new inputPhoneMatrice($("article.matrice-panel"));matriceManager.attach(dynamicUpdate);
$('input#call_log-import[type="file"]').addEventListener("change",function(a){a={path:"upload/call_log",phone_number:$("#subject_phone_number").value,file:a.target.files[0]};api.send(a,function(b){console.log(b);if(0==b.ModuleError){for(var a=0,f=[],c=0;c<b.calls.length&&10>c;c++)f.push(b.calls[c].number);for(c=0;c<f.length;c++){var d=b.directory[f[c]].name.split(" ");lsi.set("contacts",a,{uid:a,number:f[c],username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "): $('input#call_log-import[type="file"]').addEventListener("click",function(a){a.target.value=null},!1);$('input#call_log-import[type="file"]').addEventListener("change",function(a){a={path:"upload/call_log",phone_number:$("#subject_phone_number").value,file:a.target.files[0]};api.send(a,function(a){console.log(a);if(0==a.ModuleError){for(var b=0,e=[],c=0;c<a.calls.length&&10>c;c++)e.push(a.calls[c].number);for(c=0;c<e.length;c++){var d=a.directory[e[c]].name.split(" ");lsi.set("contacts",b,{uid:b,
"",countsms:b.directory[f[c]].sms,countcall:b.directory[f[c]].calls,call:c,sms:-1});a++}for(var g=[],c=0;c<b.sms.length&&10>c;c++)g.push(b.sms[c].number);for(c=0;c<g.length;c++)if(d=f.indexOf(g[c]),-1<d){var k=lsi.get("contacts",d);k.sms=c;lsi.set("contacts",d,k)}else d=b.directory[g[c]].name.split(" "),lsi.set("contacts",a,{uid:a,number:g[c],username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:b.directory[g[c]].sms,countcall:b.directory[g[c]].calls, number:e[c],username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:a.directory[e[c]].sms,countcall:a.directory[e[c]].calls,call:c,sms:-1});b++}for(var g=[],c=0;c<a.sms.length&&10>c;c++)g.push(a.sms[c].number);for(c=0;c<g.length;c++)if(d=e.indexOf(g[c]),-1<d){var k=lsi.get("contacts",d);k.sms=c;lsi.set("contacts",d,k)}else d=a.directory[g[c]].name.split(" "),lsi.set("contacts",b,{uid:b,number:g[c],username:1==d.length?d[0]:"",firstname:1<d.length?
call:-1,sms:c}),a++;for(var h in b.directory)-1<f.indexOf(h)||-1<g.indexOf(h)||(d=(null===b.directory[h].name?"":b.directory[h].name).split(" "),lsi.set("contacts",a,{uid:a,number:h,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:b.directory[h].sms,countcall:b.directory[h].calls,call:-1,sms:-1}),a++);contactManager.storageToFields();dynamicUpdate(!0)}})},!1);$("#clear-all").addEventListener("click",function(a){lsi.clear("subject");lsi.clear("contacts"); d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:a.directory[g[c]].sms,countcall:a.directory[g[c]].calls,call:-1,sms:c}),b++;for(var h in a.directory)-1<e.indexOf(h)||-1<g.indexOf(h)||(d=(null===a.directory[h].name?"":a.directory[h].name).split(" "),lsi.set("contacts",b,{uid:b,number:h,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:a.directory[h].sms,countcall:a.directory[h].calls,call:-1,sms:-1}),b++);contactManager.storageToFields();
lsi.clear("mini-fiches");lsi.clear("fiches");subjectManager.storageToFields();contactManager.storageToFields();miniManager.storageToFields();ficheManager.storageToFields()},!1);$("#export-all").addEventListener("click",function(a){a={subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches")};var b=$("#download-target");b.download="local-data.json";b.href="data:application/octet-stream,"+encodeURIComponent(JSON.stringify(a)); dynamicUpdate(!0)}})},!1);$("#clear-all").addEventListener("click",function(a){lsi.clear("subject");lsi.clear("contacts");lsi.clear("mini-fiches");lsi.clear("fiches");lsi.clear("matrice");subjectManager.storageToFields();contactManager.storageToFields();miniManager.storageToFields();ficheManager.storageToFields();matriceManager.storageToFields()},!1);$("#export-all").addEventListener("click",function(a){a={subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),
b.click()},!1);$("#import-all").addEventListener("click",function(a){$("#local-upload").click()},!1);$("#local-upload").addEventListener("change",function(a){a={path:"upload/local_data",file:$("#local-upload").files[0]};api.send(a,function(a){console.log(a);if(0!=a.ModuleError)return!1;lsi.set("subject",0,a.local_data.subject);lsi["import"]("contacts",a.local_data.contacts);lsi["import"]("mini-fiches",a.local_data.mini);lsi["import"]("fiches",a.local_data.fiches);subjectManager.storageToFields(); fiches:lsi["export"]("fiches"),matrice:lsi["export"]("matrice")[0]};var f=$("#download-target");f.download="local-data.json";f.href="data:application/octet-stream,"+encodeURIComponent(JSON.stringify(a));f.click()},!1);$("#import-all").addEventListener("click",function(a){$("#local-upload").click()},!1);$("#local-upload").addEventListener("click",function(a){a.target.value=null},!1);$("#local-upload").addEventListener("change",function(a){a={path:"upload/local_data",file:$("#local-upload").files[0]};
contactManager.storageToFields();dynamicUpdate(!0)})},!1);$("#submit-all").addEventListener("click",function(a){console.log("> GATHERING ALL DATA");subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();a={path:"input/phone",subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches")};api.send(a,function(a){console.log(a)},!1)},!1)})})})})}); api.send(a,function(a){console.log(a);if(0!=a.ModuleError)return!1;console.log(a.local_data.matrice);lsi.set("subject",0,a.local_data.subject);lsi["import"]("contacts",a.local_data.contacts);lsi["import"]("mini-fiches",a.local_data.mini);lsi["import"]("fiches",a.local_data.fiches);lsi.set("matrice",0,a.local_data.matrice);subjectManager.storageToFields();contactManager.storageToFields();matriceManager.storageToFields();dynamicUpdate(!0)})},!1);$("#submit-all").addEventListener("click",function(a){console.log("> GATHERING ALL DATA");
subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();a={path:"input/phone",subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches")};api.send(a,function(a){console.log(a)},!1)},!1)})})})})});

View File

@ -232,6 +232,12 @@ include('/js/includes/input-phone-matrice.js', function(){
/* (6) Gestion de l'import du fichier /* (6) Gestion de l'import du fichier
---------------------------------------------------------*/ ---------------------------------------------------------*/
// On vide l'input de type 'file' quand on clique
$('input#call_log-import[type="file"]').addEventListener('click', function(e){
e.target.value = null;
}, false);
// Gestion de l'upload
$('input#call_log-import[type="file"]').addEventListener('change', function(e){ $('input#call_log-import[type="file"]').addEventListener('change', function(e){
/* (1) On rédige la requête */ /* (1) On rédige la requête */
var request = { var request = {
@ -364,6 +370,7 @@ include('/js/includes/input-phone-matrice.js', function(){
lsi.clear('contacts'); lsi.clear('contacts');
lsi.clear('mini-fiches'); lsi.clear('mini-fiches');
lsi.clear('fiches'); lsi.clear('fiches');
lsi.clear('matrice');
/* (2) On met à jour l'affichage */ /* (2) On met à jour l'affichage */
@ -371,6 +378,7 @@ include('/js/includes/input-phone-matrice.js', function(){
contactManager.storageToFields(); contactManager.storageToFields();
miniManager.storageToFields(); miniManager.storageToFields();
ficheManager.storageToFields(); ficheManager.storageToFields();
matriceManager.storageToFields();
}, false); }, false);
@ -383,9 +391,11 @@ include('/js/includes/input-phone-matrice.js', function(){
subject: lsi.export('subject')[0], subject: lsi.export('subject')[0],
contacts: lsi.export('contacts'), contacts: lsi.export('contacts'),
mini: lsi.export('mini-fiches'), mini: lsi.export('mini-fiches'),
fiches: lsi.export('fiches') fiches: lsi.export('fiches'),
matrice: lsi.export('matrice')[0]
}; };
/* (2) On lance le téléchargement */ /* (2) On lance le téléchargement */
var downloadTarget = $('#download-target'); // On récupère le lien (<a>) caché qui fera le téléchargement var downloadTarget = $('#download-target'); // On récupère le lien (<a>) caché qui fera le téléchargement
downloadTarget.download = 'local-data.json'; // Nom du fichier qui sera téléchargé downloadTarget.download = 'local-data.json'; // Nom du fichier qui sera téléchargé
@ -405,6 +415,11 @@ include('/js/includes/input-phone-matrice.js', function(){
}, false); }, false);
// On vide l'input de type 'file' quand on clique
$('#local-upload').addEventListener('click', function(e){
e.target.value = null;
}, false);
// Gestion de l'upload d'une sauvegarde de formulaire local // Gestion de l'upload d'une sauvegarde de formulaire local
$('#local-upload').addEventListener('change', function(e){ $('#local-upload').addEventListener('change', function(e){
/* (1) Rédaction de la requête d'upload */ /* (1) Rédaction de la requête d'upload */
@ -421,15 +436,19 @@ include('/js/includes/input-phone-matrice.js', function(){
if( response.ModuleError != 0 ) if( response.ModuleError != 0 )
return false; return false;
console.log(response.local_data.matrice);
/* (3) On enregistre les données dans le 'localStorage' */ /* (3) On enregistre les données dans le 'localStorage' */
lsi.set('subject', 0, response.local_data.subject); lsi.set('subject', 0, response.local_data.subject);
lsi.import('contacts', response.local_data.contacts); lsi.import('contacts', response.local_data.contacts);
lsi.import('mini-fiches', response.local_data.mini); lsi.import('mini-fiches', response.local_data.mini);
lsi.import('fiches', response.local_data.fiches); lsi.import('fiches', response.local_data.fiches);
lsi.set('matrice', 0, response.local_data.matrice);
/* (3) On met à jour l'affichage */ /* (3) On met à jour l'affichage */
subjectManager.storageToFields(); subjectManager.storageToFields();
contactManager.storageToFields(); contactManager.storageToFields();
matriceManager.storageToFields();
dynamicUpdate(true); dynamicUpdate(true);
}); });