Correction de l'api (/js/lib/api.js) pour upload des File sans les mettre en JSON
This commit is contained in:
parent
73b09eb59b
commit
827a8dd827
File diff suppressed because one or more lines are too long
|
@ -43,7 +43,7 @@ miniFicheBuilder.setLayout(
|
|||
"\t<input type='hidden' data-name='username' value='@username'>\n"+
|
||||
|
||||
"\t<span data-space></span>\n"+
|
||||
"\t<h4 data-icon='o' class='color2'>@firstname @lastname (@username)</h4>\n"+
|
||||
"\t<h4 data-icon='o' class='color2'>@firstname @lastname @username</h4>\n"+
|
||||
|
||||
"\t<h5 class='nobold color0'>\n"+
|
||||
"\t\t<input type='radio' name='sexe_min_@uid' data-name='sexe' id='sexeH_min_@uid'><label for='sexeH_min_@uid'>Homme</label>\n"+
|
||||
|
@ -162,7 +162,7 @@ ficheBuilder.setLayout(
|
|||
"\t<input type='hidden' data-name='lastname' value='@lastname'>\n"+
|
||||
"\t<input type='hidden' data-name='username' value='@username'>\n"+
|
||||
|
||||
"\t<h4 data-icon='o' class='color2'>@firstname @lastname (@username)</h4>\n"+
|
||||
"\t<h4 data-icon='o' class='color2'>@firstname @lastname @username</h4>\n"+
|
||||
|
||||
"\t<h5 class='nobold color0'>\n"+
|
||||
"\t\t<input type='radio' name='sexe_@uid' data-name='sexe' id='sexeH_@uid'><label for='sexeH_@uid'>Homme</label>\n"+
|
||||
|
|
|
@ -8,12 +8,12 @@ c.connectSpecial[1].value],hash:d};c.valid=this.check(c);c.timestamp=Date.now();
|
|||
inputPhoneFiche.prototype.add=function(a){console.log("FICHE: ADD");if(null==a.uid)return!1;a.firstname=null!=a.firstname?a.firstname:this.defaultData.firstname;a.lastname=null!=a.lastname?a.lastname:this.defaultData.lastname;a.username=null!=a.username?a.username:this.defaultData.username;a.age=null!=a.age?a.age:this.defaultData.age;a.city=null!=a.city?a.city:this.defaultData.city;a.duration[0]=null!=a.duration[0]?a.duration[0]:this.defaultData.duration[0];a.duration[1]=null!=a.duration[1]?a.duration[1]:
|
||||
this.defaultData.duration[1];a.reltypeSpecial=null!=a.reltypeSpecial?a.reltypeSpecial:this.defaultData.reltypeSpecial;a.contextSpecial[0]=null!=a.contextSpecial[0]?a.contextSpecial[0]:this.defaultData.contextSpecial[0];a.contextSpecial[1]=null!=a.contextSpecial[1]?a.contextSpecial[1]:this.defaultData.contextSpecial[1];a.contextSpecial[2]=null!=a.contextSpecial[2]?a.contextSpecial[2]:this.defaultData.contextSpecial[2];a.connectSpecial[0]=null!=a.connectSpecial[0]?a.connectSpecial[0]:this.defaultData.connectSpecial[0];
|
||||
a.connectSpecial[1]=null!=a.connectSpecial[1]?a.connectSpecial[1]:this.defaultData.connectSpecial[1];a.job=null!=a.job?a.job:this.defaultData.job;a.studies=null!=a.studies?a.studies:this.defaultData.studies;a.sexe=null!=a.sexe?a.sexe:this.defaultData.sexe;a.famsit=null!=a.famsit?a.famsit:this.defaultData.famsit;a.reltype=null!=a.reltype?a.reltype:this.defaultData.reltype;a.loc=null!=a.loc?a.loc:this.defaultData.loc;a.loc2=null!=a.loc2?a.loc2:this.defaultData.loc2;a.context=null!=a.context?a.context:
|
||||
this.defaultData.context;a.freq=null!=a.freq?a.freq:this.defaultData.freq;a.connect=null!=a.connect?a.connect:this.defaultData.connect;this.container.innerHTML+=ficheBuilder.build({firstname:a.firstname,lastname:a.lastname,username:a.username,uid:a.uid,age:a.age,city:a.city,duration0:a.duration[0],duration1:a.duration[1],reltypespecial:a.reltypeSpecial,contextspecial0:a.contextSpecial[0],contextspecial1:a.contextSpecial[1],contextspecial2:a.contextSpecial[2],connectspecial0:a.connectSpecial[0],connectspecial1:a.connectSpecial[1]});
|
||||
var b=$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="job"]>option[value="'+a.job+'"]');null!=b&&b.setAttribute("selected","selected");b=$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="studies"]>option[value="'+a.studies+'"]');null!=b&&b.setAttribute("selected","selected");for(var c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),b=0;b<c.length&&
|
||||
b<a.sexe.length;b++)a.sexe[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="famsit"]');for(b=0;b<c.length&&b<a.famsit.length;b++)a.famsit[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="reltype"]');for(b=0;b<c.length&&b<a.reltype.length;b++)a.reltype[b].status?
|
||||
c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(b=0;b<c.length&&b<a.loc.length;b++)a.loc[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc2"]');for(b=0;b<c.length&&b<a.loc2.length;b++)a.loc2[b].status?c[b].setAttribute("checked",
|
||||
"checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="context"]');for(b=0;b<c.length&&b<a.context.length;b++)a.context[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");for(c=0;c<a.freq.length;c++)for(var d=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="freq'+c+'"]'),b=0;b<d.length&&b<a.freq[c].length;b++)a.freq[c][b].status?
|
||||
d[b].setAttribute("checked","checked"):d[b].removeAttribute("checked");for(c=0;c<a.connect.length;c++)for(d=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="connect'+c+'"]'),b=0;b<d.length&&b<a.connect[c].length;b++)a.connect[c][b].status?d[b].setAttribute("checked","checked"):d[b].removeAttribute("checked")};
|
||||
this.defaultData.context;a.freq=null!=a.freq?a.freq:this.defaultData.freq;a.connect=null!=a.connect?a.connect:this.defaultData.connect;this.container.innerHTML+=ficheBuilder.build({firstname:a.firstname,lastname:a.lastname,username:0==a.username.length?"":"("+a.username+")",uid:a.uid,age:a.age,city:a.city,duration0:a.duration[0],duration1:a.duration[1],reltypespecial:a.reltypeSpecial,contextspecial0:a.contextSpecial[0],contextspecial1:a.contextSpecial[1],contextspecial2:a.contextSpecial[2],connectspecial0:a.connectSpecial[0],
|
||||
connectspecial1:a.connectSpecial[1]});var b=$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="job"]>option[value="'+a.job+'"]');null!=b&&b.setAttribute("selected","selected");b=$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="studies"]>option[value="'+a.studies+'"]');null!=b&&b.setAttribute("selected","selected");for(var c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),
|
||||
b=0;b<c.length&&b<a.sexe.length;b++)a.sexe[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="famsit"]');for(b=0;b<c.length&&b<a.famsit.length;b++)a.famsit[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="reltype"]');for(b=0;b<
|
||||
c.length&&b<a.reltype.length;b++)a.reltype[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(b=0;b<c.length&&b<a.loc.length;b++)a.loc[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc2"]');for(b=0;b<c.length&&
|
||||
b<a.loc2.length;b++)a.loc2[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="context"]');for(b=0;b<c.length&&b<a.context.length;b++)a.context[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");for(c=0;c<a.freq.length;c++)for(var d=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="freq'+
|
||||
c+'"]'),b=0;b<d.length&&b<a.freq[c].length;b++)a.freq[c][b].status?d[b].setAttribute("checked","checked"):d[b].removeAttribute("checked");for(c=0;c<a.connect.length;c++)for(d=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="connect'+c+'"]'),b=0;b<d.length&&b<a.connect[c].length;b++)a.connect[c][b].status?d[b].setAttribute("checked","checked"):d[b].removeAttribute("checked")};
|
||||
inputPhoneFiche.prototype.storageToFields=function(){console.log("FICHE: STORAGE TO FIELDS");var a=lsi["export"]("fiches");this.container.innerHTML="";var b=[],c;for(c in a){var d=a[c].uid;d==this.selected&&this.add(a[c]);b.push(d)}this.updateNavBar(b)};
|
||||
inputPhoneFiche.prototype.sync=function(){console.log("FICHE: SYNC");for(var a=lsi.keys("contacts"),b=0;b<a.length&&10>b;b++){var c=lsi.get("contacts",a[b]),d=lsi.get("fiches",a[b]);null==d&&(d=this.defaultData);d.uid=c.uid;d.firstname=c.firstname;d.lastname=c.lastname;d.username=c.username;lsi.set("fiches",a[b],d)}var a=lsi["export"]("mini-fiches"),d=lsi["export"]("fiches"),e;for(e in d)d[e].timestamp>a[e].timestamp?(a[e].sexe=d[e].sexe,a[e].age=d[e].age,a[e].job=d[e].job,a[e].loc=d[e].loc):(d[e].sexe=
|
||||
a[e].sexe,d[e].age=a[e].age,d[e].job=a[e].job,d[e].loc=a[e].loc),lsi.set("mini-fiches",e,a[e]),lsi.set("fiches",e,d[e])};inputPhoneFiche.prototype.nav=function(a){if("undefined"==typeof a||isNaN(a.innerHTML)||"nav-fiche"!=a.parentNode.id)return!1;for(var b=$$("#nav-fiche > span.active"),c=0;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.innerHTML)-1};
|
||||
|
|
|
@ -206,7 +206,7 @@ inputPhoneFiche.prototype.add = function(objectData){
|
|||
this.container.innerHTML += ficheBuilder.build({
|
||||
firstname: objectData.firstname,
|
||||
lastname: objectData.lastname,
|
||||
username: objectData.username,
|
||||
username: (objectData.username.length==0) ? '' : '('+objectData.username+')',
|
||||
uid: objectData.uid,
|
||||
age: objectData.age,
|
||||
city: objectData.city,
|
||||
|
|
|
@ -2,8 +2,9 @@ function inputPhoneMini(a,b){this.container=a;this.nav_container=b}inputPhoneMin
|
|||
inputPhoneMini.prototype.fieldsToStorage=function(){console.log("MINI FICHE: FIELDS TO STORAGE");for(var a=$$("article.mini-relation-panel .mini-fiche-relation"),b=0;b<a.length;b++){var c=(new FormDeflater(a[b],["input","select"],["data-name"])).deflate(),e=crc32(JSON.stringify(c)),d=lsi.get("mini-fiches",c.uid.value);!1===d&&(d.username="inconnu",d.firstname="inconnu",d.lastname="inconnu");if(null!=d.hash&&d.hash==e)break;console.warn("> MINI UPDATE");c={uid:c.uid.value,firstname:d.firstname,lastname:d.lastname,
|
||||
username:d.username,sexe:c.sexe,age:c.age.value,job:c.job.value,loc:c.loc,hash:e};c.valid=this.check(c);c.timestamp=Date.now();lsi.set("mini-fiches",c.uid,c)}};
|
||||
inputPhoneMini.prototype.add=function(a){console.log("MINI FICHE: ADD");if(null==a||null==a.uid)return!1;a.firstname=null!=a.firstname?a.firstname:this.defaultData.firstname;a.lastname=null!=a.lastname?a.lastname:this.defaultData.lastname;a.username=null!=a.username?a.username:this.defaultData.username;a.age=null!=a.age?a.age:this.defaultData.age;a.sexe=null!=a.sexe?a.sexe:this.defaultData.sexe;a.job=null!=a.job?a.job:this.defaultData.job;a.loc=null!=a.loc?a.loc:this.defaultData.loc;this.container.innerHTML+=
|
||||
miniFicheBuilder.build({firstname:a.firstname,lastname:a.lastname,username:a.username,uid:a.uid,age:a.age,job:a.job});var b=$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="job"]>option[value="'+a.job+'"]');null!=b&&b.setAttribute("selected","selected");for(var c=$$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),b=0;b<c.length&&b<a.sexe.length;b++)a.sexe[b].status?c[b].setAttribute("checked",
|
||||
"checked"):c[b].removeAttribute("checked");c=$$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(b=0;b<c.length&&b<a.loc.length;b++)a.loc[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked")};inputPhoneMini.prototype.storageToFields=function(){console.log("MINI FICHE: STORAGE TO FIELDS");var a=lsi["export"]("mini-fiches");this.container.innerHTML="";this.add(a[this.selected]);this.updateNavBar()};
|
||||
miniFicheBuilder.build({firstname:a.firstname,lastname:a.lastname,username:0==a.username.length?"":"("+a.username+")",uid:a.uid,age:a.age,job:a.job});var b=$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>span>select[data-name="job"]>option[value="'+a.job+'"]');null!=b&&b.setAttribute("selected","selected");for(var c=$$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),b=0;b<c.length&&b<a.sexe.length;b++)a.sexe[b].status?
|
||||
c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.mini-fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(b=0;b<c.length&&b<a.loc.length;b++)a.loc[b].status?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked")};
|
||||
inputPhoneMini.prototype.storageToFields=function(){console.log("MINI FICHE: STORAGE TO FIELDS");var a=lsi["export"]("mini-fiches");this.container.innerHTML="";this.add(a[this.selected]);this.updateNavBar()};
|
||||
inputPhoneMini.prototype.sync=function(){console.log("MINI FICHE: SYNC");var a=lsi["export"]("contacts"),b;for(b in a){var c=lsi.get("mini-fiches",b);null==c&&(c=this.defaultData,c.valid=!1);c.uid=a[b].uid;c.firstname=a[b].firstname;c.lastname=a[b].lastname;c.username=a[b].username;lsi.set("mini-fiches",b,c)}};
|
||||
inputPhoneMini.prototype.nav=function(a){if("undefined"==typeof a||isNaN(a.innerHTML)||"nav-mini"!=a.parentNode.id)return!1;for(var b=$$("#nav-mini > span.active"),c=0;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.innerHTML)-1};
|
||||
inputPhoneMini.prototype.updateNavBar=function(){var a=lsi["export"]("mini-fiches"),b=Object.keys(a).length;if(this.nav_container.children.length!=b){this.nav_container.innerHTML="";for(var c=0;c<b;c++)this.nav_container.innerHTML+="<span></span>"}for(var e in a)b=this.nav_container.children[a[e].uid],b.innerHTML=a[e].uid+1,!0===a[e].valid?b.addClass("done"):b.remClass("done");this.nav(this.nav_container.children[this.selected])};
|
||||
|
|
|
@ -124,7 +124,7 @@ inputPhoneMini.prototype.add = function(objectData){
|
|||
this.container.innerHTML += miniFicheBuilder.build({
|
||||
firstname: objectData.firstname,
|
||||
lastname: objectData.lastname,
|
||||
username: objectData.username,
|
||||
username: (objectData.username.length==0) ? '' : '('+objectData.username+')',
|
||||
uid: objectData.uid,
|
||||
age: objectData.age,
|
||||
job: objectData.job
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
function APIClass(b){this.target=b}
|
||||
APIClass.prototype={xhr:[],send:function(b,d,g){b.hasOwnProperty("path")||d({ModuleError:4});for(var a=0;a<this.xhr.length;a++)4==this.xhr[a].readyState&&(this.xhr=this.xhr.slice(0,a-1).concat(this.xhr.slice(a,this.xhr.length-1)));this.xhr.push(null);a=this.xhr.length-1;this.xhr[a]=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHttpRequest");console.log(b);var e=this;this.xhr[a].onreadystatechange=function(){if(4==e.xhr[a].readyState)if(-1<[0,200].indexOf(e.xhr[a].status))try{d(JSON.parse(e.xhr[a].responseText))}catch(b){d({ModuleError:1})}else d({ModuleError:3})};
|
||||
var f=new FormData,c;for(c in b)"path"==c?f.append(c,b[c]):f.append(c,JSON.stringify(b[c]));this.xhr[a].open("POST",this.target,!0);null!=g&&this.xhr[a].setRequestHeader("Authorization","Digest "+g);this.xhr[a].send(f)}};
|
||||
APIClass.prototype={xhr:[],send:function(b,d,g){b.hasOwnProperty("path")||d({ModuleError:4});for(var a=0;a<this.xhr.length;a++)4==this.xhr[a].readyState&&(this.xhr=this.xhr.slice(0,a-1).concat(this.xhr.slice(a,this.xhr.length-1)));this.xhr.push(null);a=this.xhr.length-1;this.xhr[a]=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHttpRequest");console.log(b);var f=this;this.xhr[a].onreadystatechange=function(){if(4==f.xhr[a].readyState)if(-1<[0,200].indexOf(f.xhr[a].status))try{d(JSON.parse(f.xhr[a].responseText))}catch(b){d({ModuleError:1})}else d({ModuleError:3})};
|
||||
var e=new FormData,c;for(c in b)"path"==c?e.append(c,b[c]):b[c]instanceof File?e.append(c,b[c]):e.append(c,JSON.stringify(b[c]));this.xhr[a].open("POST",this.target,!0);null!=g&&this.xhr[a].setRequestHeader("Authorization","Digest "+g);this.xhr[a].send(e)}};
|
||||
|
|
|
@ -75,8 +75,12 @@ APIClass.prototype = {
|
|||
|
||||
// On ajoute tous les attributs en POST
|
||||
for( var key in pRequest )
|
||||
if( key == 'path' ) form.append(key, pRequest[key]);
|
||||
else form.append(key, JSON.stringify(pRequest[key]));
|
||||
// On envoie le 'path' tel quel <String>
|
||||
if( key == 'path' ) form.append(key, pRequest[key]);
|
||||
// On envoie un fichier tel quel <File>
|
||||
else if( pRequest[key] instanceof File ) form.append(key, pRequest[key]);
|
||||
// On envoie le reste en JSON
|
||||
else form.append(key, JSON.stringify(pRequest[key]));
|
||||
|
||||
|
||||
this.xhr[i].open('POST', this.target, true);
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -214,6 +214,7 @@ include('/js/includes/input-phone-fiche.js', function(){
|
|||
/* (5) Gestion de l'import du fichier
|
||||
---------------------------------------------------------*/
|
||||
importCallLog.addEventListener('change', function(e){
|
||||
console.log( importCallLog.files[0] );
|
||||
/* (1) On rédige la requête */
|
||||
var uploadRequest = {
|
||||
path: 'upload/call_log',
|
||||
|
@ -291,13 +292,10 @@ include('/js/includes/input-phone-fiche.js', function(){
|
|||
};
|
||||
|
||||
/* (2) On lance le téléchargement */
|
||||
var downloadTarget = $('#download-target');
|
||||
downloadTarget.download = 'local-data.json';
|
||||
downloadTarget.href = 'data:application/octet-stream,charset:utf-8,'+encodeURIComponent(JSON.stringify(data));
|
||||
downloadTarget.click();
|
||||
|
||||
|
||||
|
||||
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.href = 'data:application/octet-stream,'+encodeURIComponent(JSON.stringify(data)); // Contenu
|
||||
downloadTarget.click(); // On lance le téléchargement
|
||||
|
||||
}, false);
|
||||
|
||||
|
|
Loading…
Reference in New Issue