NxTIC/view/js/input-min.js

12 lines
4.7 KiB
JavaScript
Raw Normal View History

var clearAllButton=$("#clear-all"),submitAllButton=$("#submit-all"),importCallLog=$('input#call_log-import[type="file"]'),subjectManager,contactManager,miniManager,ficheManager;
function dynamicUpdate(a){var e=a instanceof Element,b=e&&"SPAN"==a.tagName&&"switch-left"==a.className,f=e&&"SPAN"==a.tagName&&"switch-both"==a.className,c=e&&"INPUT"==a.tagName&&"submit"==a.type,d=e&&"SPAN"==a.tagName&&("nav-mini"==a.parentNode.id||"nav-fiche"==a.parentNode.id),e=e&&"SPAN"==a.tagName&&"nav-contact"==a.parentNode.id;if(!(f||b||c||d||e)&&!0!==a)return!1;if(f)console.log("> switch firstname <-> lastname"),b=a.parentNode,a=b.children[3],b=b.children[5],f=a.value,a.value=b.value,b.value=
f;else if(b){console.log("> switch firstname+lastname -> username");b=a.parentNode;f=b.children[1];a=b.children[3];b=b.children[5];if(0<f.value.length||0==a.value.length&&0==b.value.length)return!1;f.value=a.value+" "+b.value;a.value="";b.value=""}else console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),(c||e)&&contactManager.storageToFields()}
function checkRadioValue(a){for(var e=0,b=0;b<a.length;b++)!0===a[b].status&&e++;return 1!=e?!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(){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);importCallLog.addEventListener("change",function(a){a={path:"upload/call_log",phone_number:$("#subject_phone_number").value,file:importCallLog.files[0]};
api.send(a,function(a){console.log(a);if(0==a.ModuleError){for(var b=0,f=[],c=0;c<a.calls.length&&10>c;c++)f.push(a.calls[c].number);for(c=0;c<f.length;c++){var d=a.directory[f[c]].name.split(" ");lsi.set("contacts",b,{uid:b,number:f[c],username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",call:c});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=f.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?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",sms:c}),b++;for(var h in a.directory)-1<f.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(" "):"",call:-1,sms:-1}),
b++);contactManager.storageToFields();dynamicUpdate(!0)}})},!1);clearAllButton.addEventListener("click",function(a){localStorage.clear();reload()},!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 e=$("#download-target");e.download="local-data.json";e.href="data:application/octet-stream,"+encodeURIComponent(JSON.stringify(a));e.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();contactManager.storageToFields();dynamicUpdate(!0)})},!1);
submitAllButton.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)})})})});