NxTIC/view/js/input-min.js

12 lines
9.5 KiB
JavaScript

var clearAllButton=$("#clear-all"),submitAllButton=$("#submit-all"),importCallLog=$('input#call_log-import[type="file"]'),subjectManager,contactManager,miniManager,ficheManager;
function dynamicUpdate(a){var b=a instanceof Element,c=b&&"SPAN"==a.tagName&&"switch-left"==a.className,e=b&&"SPAN"==a.tagName&&"switch-both"==a.className,d=b&&"INPUT"==a.tagName&&"submit"==a.type,f=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(!(e||c||d||f||b)&&!0!==a)return!1;if(e)console.log("> switch firstname <-> lastname"),c=a.parentNode,a=c.children[3],c=c.children[5],e=a.value,a.value=c.value,c.value=
e;else if(c){console.log("> switch firstname+lastname -> username");c=a.parentNode;e=c.children[1];a=c.children[3];c=c.children[5];if(0<e.value.length||0==a.value.length&&0==c.value.length)return!1;e.value=a.value+" "+c.value;a.value="";c.value=""}else console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),miniManager.sync(),ficheManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),(d||b)&&contactManager.storageToFields()}
function checkRadioValue(a){for(var b=0,c=0;c<a.length;c++)!0===a[c].status&&b++;return 1!=b?!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){api.send({path:"upload/call_log",file:importCallLog.files[0]},function(a){console.log(a);
0==a.ModuleError&&(importCallLog.addClass("active"),a={path:"call_log/unserialize",phone_number:$("#subject_phone_number").value},api.send(a,function(a){console.log(a);if(0==a.ModuleError){for(var b=0;b<a.directory.length;b++){var d=(null===a.directory[b].name?"":a.directory[b].name).split(" ");lsi.set("contacts",b,{uid:b,number:a.directory[b].number,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):""})}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 b=$("#download-target");b.download="local-data.json";b.href="data:application/octet-stream,charset:utf-8,"+encodeURIComponent(JSON.stringify(a));b.click()},!1);$("#import-all").addEventListener("click",function(a){a=
JSON.parse('{"subject":{"number":"06 69 05 19 10","username":"","firstname":"Adrien","lastname":""},"contacts":{"0":{"uid":0,"number":"1","username":"1","firstname":"","lastname":"","hash":241770401},"1":{"uid":1,"number":"2","username":"2","firstname":"","lastname":"","hash":363925312}},"mini":{"0":{"uid":0,"firstname":"","lastname":"","username":"1","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"25","job":"0","loc":[{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":true},{"value":"on","status":false}],"hash":1923019850,"valid":true,"timestamp":1462196014908},"1":{"uid":1,"firstname":"","lastname":"","username":"2","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"23","job":"32","loc":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"hash":3042965309,"valid":true,"timestamp":1462196032703}},"fiches":{"0":{"uid":0,"firstname":"","lastname":"","username":"1","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"25","job":"0","famsit":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false}],"studies":".","reltype":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"reltypeSpecial":"","city":"","loc":[{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":true},{"value":"on","status":false}],"loc2":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"duration":["",""],"context":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"contextSpecial":["","",""],"freq":[[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}]],"connect":[[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}]],"connectSpecial":["",""],"hash":1570439147,"valid":false,"timestamp":1462196015606},"1":{"uid":1,"firstname":"","lastname":"","username":"2","sexe":[{"value":"on","status":true},{"value":"on","status":false}],"age":"23","job":"32","famsit":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false}],"studies":".","reltype":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"reltypeSpecial":"","city":"","loc":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"loc2":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"duration":["",""],"context":[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],"contextSpecial":["","",""],"freq":[[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}],[{"value":"on","status":true},{"value":"on","status":false},{"value":"on","status":false},{"value":"on","status":false}]],"connect":[[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}],[{"value":"on","status":false},{"value":"on","status":true}]],"connectSpecial":["",""],"hash":3347750419,"valid":false,"timestamp":1462195434069}}}');
console.log(a);lsi["import"]("subject",a.subject);lsi["import"]("contacts",a.contacts);lsi["import"]("mini-fiches",a.mini);lsi["import"]("fiches",a.fiches)},!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)})})})});