NxTIC/view/js/input-min.js

16 lines
6.8 KiB
JavaScript
Raw Normal View History

var subjectManager,contactManager,miniManager,ficheManager,matriceManager;
function dynamicUpdate(b){var a=b instanceof Element,e=a&&"SPAN"==b.tagName&&"switch-left"==b.className,f=a&&"SPAN"==b.tagName&&"switch-both"==b.className,g=a&&"INPUT"==b.tagName&&"submit"==b.type,c=a&&"SPAN"==b.tagName&&("nav-mini"==b.parentNode.id||"nav-fiche"==b.parentNode.id),a=a&&"SPAN"==b.tagName&&"nav-contact"==b.parentNode.id;if(!(f||e||g||c||a)&&!0!==b)return!1;if(f)console.log("> switch firstname <-> lastname"),e=b.parentNode,b=e.children[8],e=e.children[10],f=b.value,b.value=e.value,e.value=
f;else if(e){console.log("> switch firstname+lastname -> username");e=b.parentNode;f=e.children[6];b=e.children[8];e=e.children[10];if(0<f.value.length||0==b.value.length&&0==e.value.length)return!1;f.value=b.value+" "+e.value;b.value="";e.value=""}else console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),matriceManager.fieldsToStorage(),ficheManager.sync(),miniManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),
matriceManager.storageToFields(),(g||a)&&contactManager.storageToFields()}function readableName(b,a,e){var f=a.length,g=e.length;return 0<b.length?0<f+g?b+" ("+(a+" "+e).trim()+")":b:0<f+g?(a+" "+e).trim():"Inconnu"}
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);
$('input#call_log-import[type="file"]').addEventListener("click",function(b){b.target.value=null},!1);$('input#call_log-import[type="file"]').addEventListener("change",function(b){b={path:"upload/call_log",phone_number:$("#subject_phone_number").value,file:b.target.files[0]};api.send(b,function(a){console.log(a);var b=null;if(0!=a.ModuleError)9==a.ModuleError?Notification.error("Erreur","Il est n\u00e9cessaire de saisir les informations du <b>sujet</b> avant d'exporter son journal d'appel"):Notification.error("Erreur",
a.ModuleError);else{for(var b=Notification.info("Info","Chargement du journal d'appel"),f=0,g=[],c=0;c<a.calls.length&&10>c;c++)g.push(a.calls[c].number);for(c=0;c<g.length;c++){var d=a.directory[g[c]].name.split(" ");lsi.set("contacts",f,{uid:f,number:g[c],username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:a.directory[g[c]].sms,countcall:a.directory[g[c]].calls,call:c,sms:-1});f++}console.warn(1);for(var h=[],c=0;c<a.sms.length&&10>c;c++)h.push(a.sms[c].number);
for(c=0;c<h.length;c++)if(d=g.indexOf(h[c]),-1<d){var l=lsi.get("contacts",d);l.sms=c;lsi.set("contacts",d,l)}else d=[""],null!=a.directory[h[c]].name&&(d=a.directory[h[c]].name.split(" ")),lsi.set("contacts",f,{uid:f,number:h[c],username:0<d.length?d[0]:"",firstname:0<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:a.directory[h[c]].sms,countcall:a.directory[h[c]].calls,call:-1,sms:c}),f++;for(var k in a.directory)-1<g.indexOf(k)||-1<h.indexOf(k)||(d=(null===a.directory[k].name?
"":a.directory[k].name).split(" "),lsi.set("contacts",f,{uid:f,number:k,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:a.directory[k].sms,countcall:a.directory[k].calls,call:-1,sms:-1}),f++);console.warn(3);contactManager.storageToFields();dynamicUpdate(!0);null!=b&&b.click();Notification.success("OK","Chargement termin\u00e9")}})},!1);$("#clear-all").addEventListener("click",function(b){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();Notification.success("OK","Les donn\u00e9es ont \u00e9t\u00e9 supprim\u00e9es")},!1);$("#export-all").addEventListener("click",function(b){Notification.info("INFORMATION","Lancement du t\u00e9l\u00e9chargement de la sauvegarde");b={subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),
mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches"),matrice:lsi["export"]("matrice")[0]};var a=$("#download-target");a.download="local-data.json";a.href="data:application/octet-stream,"+encodeURIComponent(JSON.stringify(b));a.click()},!1);$("#import-all").addEventListener("click",function(b){$("#local-upload").click()},!1);$("#local-upload").addEventListener("click",function(b){b.target.value=null},!1);$("#local-upload").addEventListener("change",function(b){b={path:"upload/local_data",
file:$("#local-upload").files[0]};api.send(b,function(a){console.log(a);if(0!=a.ModuleError)return Notification.error("Erreur",a.ModuleError),!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);lsi.set("matrice",0,a.local_data.matrice);subjectManager.storageToFields();contactManager.storageToFields();matriceManager.storageToFields();dynamicUpdate(!0)})},!1);$("#submit-all").addEventListener("click",
function(b){console.log("> GATHERING ALL DATA");subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();if(!subjectManager.check())return Notification.warning("Attention","Vous devez saisir les informations du <i>sujet</i>"),!1;b=lsi["export"]("mini-fiches");for(var a in b)if(!b[a].valid)return Notification.warning("Attention","La <i>fiche rapide</i> <b>"+(parseInt(a)+1)+"</b> est incompl\u00e8te et/ou incorrecte"),!1;b=lsi["export"]("fiches");
for(a in b)if(!b[a].valid)return Notification.warning("Attention","La <i>fiche compl\u00e8te</i> <b>"+(parseInt(a)+1)+"</b> est incompl\u00e8te et/ou incorrecte"),!1;a={path:"input/phone",subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches"),matrice:lsi["export"]("matrice")[0]};api.send(a,function(a){if(0!=a.ModuleError)return Notification.error("ERREUR",a.ModuleError),!1;console.log(a)},!1)},!1)})})})})});