Merged feature/formDeflater.js into dev
This commit is contained in:
commit
7349f937f6
|
@ -1,3 +1,3 @@
|
|||
function FormDeflater(b,c,a){for(var d=0;d<c.length;d++)c[d]=c[d].toLowerCase();for(d=0;d<a.length;d++)a[d]=a[d].toLowerCase();this.container=b;this.tags=c;this.attr=a}
|
||||
FormDeflater.prototype={container:this.container,tags:this.tags,attr:this.attr,deflate:function(){for(var b=this.getChildren(this.container),b=this.filterElements(b),c={},a=0;a<b.length;a++)for(var d=0;d<this.attr.length;d++){var e=b[a].getAttribute(this.attr[d]);if(null!==e&&0<e.length){c.hasOwnProperty(e)?c[e]instanceof Array?c[e].push(b[a].value):c[e]=[c[e],b[a].value]:c[e]=b[a].value;break}}return c},getChildren:function(b){if(!(b instanceof Element))return[];for(var c=b=[].slice.call(b.children),
|
||||
a=0;a<b.length;a++)c=c.concat([].slice.call(this.getChildren(b[a])));return c},filterElements:function(b){for(var c=[],a=0;a<b.length;a++)-1<this.tags.indexOf(b[a].tagName.toLowerCase())&&c.push(b[a]);return c}};
|
||||
FormDeflater.prototype={container:this.container,tags:this.tags,attr:this.attr,deflate:function(){for(var b=this.getChildren(this.container),b=this.filterElements(b),c={},a=0;a<b.length;a++)for(var d=0;d<this.attr.length;d++){var e=b[a].getAttribute(this.attr[d]);if(null!==e&&0<e.length){c.hasOwnProperty(e)?c[e]instanceof Array?c[e].push({value:b[a].value,status:b[a].checked}):c[e]=[c[e],{value:b[a].value,status:b[a].checked}]:c[e]={value:b[a].value,status:b[a].checked};break}}return c},getChildren:function(b){if(!(b instanceof
|
||||
Element))return[];for(var c=b=[].slice.call(b.children),a=0;a<b.length;a++)c=c.concat([].slice.call(this.getChildren(b[a])));return c},filterElements:function(b){for(var c=[],a=0;a<b.length;a++)-1<this.tags.indexOf(b[a].tagName.toLowerCase())&&c.push(b[a]);return c}};
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// TODO: Form deflater qui renvoie un objet à partir d'un formulaire
|
||||
|
||||
|
||||
/* CONSTRUCTEUR D'UN DEFLATER DE formulaire
|
||||
*
|
||||
|
@ -79,16 +77,15 @@ FormDeflater.prototype = {
|
|||
|
||||
// {1} Si l'existant est un tableau, on ajoute notre valeur //
|
||||
if( existing instanceof Array )
|
||||
object[attr].push(children[c].value);
|
||||
object[attr].push( { value: children[c].value, status: children[c].checked } );
|
||||
|
||||
// {2} Sinon, si c'est une valeur seule, on crée un tableau //
|
||||
else
|
||||
object[attr] = [ object[attr], children[c].value ];
|
||||
object[attr] = [ object[attr], { value: children[c].value, status: children[c].checked } ];
|
||||
|
||||
/* (5) Si c'est le premier champ avec ce nom, on le crée */
|
||||
}else{
|
||||
object[attr] = children[c].value;
|
||||
}
|
||||
}else
|
||||
object[attr] = { value: children[c].value, status: children[c].checked };
|
||||
|
||||
// On en a fini pour cet élément
|
||||
break;
|
||||
|
|
|
@ -27,6 +27,10 @@ $pers = $request->answer();
|
|||
<input type='password' name='pass1' value='value_pass1'>
|
||||
<input type='number' name='number1' value='value_number1'>
|
||||
|
||||
<input type='radio' data-name='rad1' id='A' value='A'><label for='A'>A</label><br>
|
||||
<input type='radio' data-name='rad1' id='B' value='B'><label for='B'>B</label><br>
|
||||
<input type='radio' data-name='rad1' id='C' value='C'><label for='C'>C</label><br>
|
||||
|
||||
<div>
|
||||
<span>
|
||||
<input type='test' values='valuetestHier'>
|
||||
|
|
|
@ -45,10 +45,10 @@
|
|||
<span data-space></span>
|
||||
<h5 data-text="Renseigner au moins un des nominatifs pour chaque contact. (pseudo, prénom et/ou nom)"></h5>
|
||||
<h4 data-icon='p' class='new-contact'>
|
||||
<input type='text' class='no-line number' placeholder='Numéro de téléphone'>
|
||||
<input type='text' class='no-line username' placeholder='Pseudo'>
|
||||
<input type='text' class='no-line firstname' placeholder='Prénom'>
|
||||
<input type='text' class='no-line lastname' placeholder='Nom'>
|
||||
<input type='text' class='no-line' data-name='number' placeholder='Numéro de téléphone'>
|
||||
<input type='text' class='no-line' data-name='username' placeholder='Pseudo'>
|
||||
<input type='text' class='no-line' data-name='firstname' placeholder='Prénom'>
|
||||
<input type='text' class='no-line' data-name='lastname' placeholder='Nom'>
|
||||
<input type='submit' class='primary no-line sub-number' value='Valider'>
|
||||
</h4>
|
||||
<h4 data-icon='+' class='add-contact'>Ajouter un contact</h4>
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
var newContact="<h4 data-icon='p' class='new-contact'>",newContact=newContact+"<input type='text' class='no-line number' placeholder='Num\u00e9ro de t\u00e9l\u00e9phone'>",newContact=newContact+"<input type='text' class='no-line username' placeholder='Pseudo'>",newContact=newContact+"<input type='text' class='no-line firstname' placeholder='Pr\u00e9nom'>",newContact=newContact+"<input type='text' class='no-line lastname' placeholder='Nom'>",newContact=newContact+"<input type='submit' class='primary no-line sub-number' value='Valider'>",
|
||||
newContact=newContact+"</h4>",ficheRelation="",ic=new inputChecker,importCallLog=document.querySelector('input#call_log-import[type="file"]');function contactForms(){return document.querySelectorAll("h4.new-contact")}var addContact=document.querySelector("h4.add-contact");function relationForms(){return document.querySelectorAll()}importCallLog.addEventListener("change",function(a){api.send({path:"upload/call_log",file:importCallLog.files[0]},function(a){console.log(a)})},!1);var number=document.querySelector('input.number[type="text"]');
|
||||
ic.append(number,format_number,"06 06 06 06 06");number.addEventListener("keyup",function(a){ic.correct(number,!1)},!1);
|
||||
var newContact="<h4 data-icon='p' class='new-contact'>",newContact=newContact+"<input type='text' class='no-line' data-name='number' placeholder='Num\u00e9ro de t\u00e9l\u00e9phone'>",newContact=newContact+"<input type='text' class='no-line' data-name='username' placeholder='Pseudo'>",newContact=newContact+"<input type='text' class='no-line' data-name='firstname' placeholder='Pr\u00e9nom'>",newContact=newContact+"<input type='text' class='no-line' data-name='lastname' placeholder='Nom'>",newContact=
|
||||
newContact+"<input type='submit' class='primary no-line' data-name='sub-number' value='Valider'>",newContact=newContact+"</h4>",ficheRelation="",ic=new inputChecker,FormDeflaterP={tags:["input"],attr:["data-name"]},importCallLog=document.querySelector('input#call_log-import[type="file"]');function contactForms(){return document.querySelectorAll("h4.new-contact")}var addContact=document.querySelector("h4.add-contact");function relationForms(){return document.querySelectorAll()}
|
||||
importCallLog.addEventListener("change",function(b){api.send({path:"upload/call_log",file:importCallLog.files[0]},function(a){console.log(a)})},!1);
|
||||
|
|
|
@ -2,22 +2,25 @@
|
|||
=========================================================*/
|
||||
/* (1) Contiendra le formulaire d'ajout de contact (numéro, pseudo, prénom, nom, submit) */
|
||||
var newContact = "<h4 data-icon='p' class='new-contact'>";
|
||||
newContact += "<input type='text' class='no-line number' placeholder='Numéro de téléphone'>";
|
||||
newContact += "<input type='text' class='no-line username' placeholder='Pseudo'>";
|
||||
newContact += "<input type='text' class='no-line firstname' placeholder='Prénom'>";
|
||||
newContact += "<input type='text' class='no-line lastname' placeholder='Nom'>";
|
||||
newContact += "<input type='submit' class='primary no-line sub-number' value='Valider'>";
|
||||
newContact += "<input type='text' class='no-line' data-name='number' placeholder='Numéro de téléphone'>";
|
||||
newContact += "<input type='text' class='no-line' data-name='username' placeholder='Pseudo'>";
|
||||
newContact += "<input type='text' class='no-line' data-name='firstname' placeholder='Prénom'>";
|
||||
newContact += "<input type='text' class='no-line' data-name='lastname' placeholder='Nom'>";
|
||||
newContact += "<input type='submit' class='primary no-line' data-name='sub-number' value='Valider'>";
|
||||
newContact += "</h4>";
|
||||
|
||||
/* (2) TODO: Contiendra la fiche relation complète */
|
||||
var ficheRelation = "";
|
||||
|
||||
|
||||
/* [1] Initialisation de l'inputChecker
|
||||
/* [1] Initialisation des utilitaires
|
||||
=========================================================*/
|
||||
// Instanciation
|
||||
/* (1) Instanciation de inputChecker */
|
||||
var ic = new inputChecker();
|
||||
|
||||
/* (2) Paramètres de FormDeflater */
|
||||
var FormDeflaterP = { tags: ['input'], attr: ['data-name'] };
|
||||
|
||||
|
||||
|
||||
/* [2] Indexation des inputs
|
||||
|
@ -58,10 +61,10 @@ importCallLog.addEventListener('change', function(e){
|
|||
|
||||
|
||||
|
||||
var number = document.querySelector('input.number[type="text"]');
|
||||
ic.append(number, format_number, '06 06 06 06 06');
|
||||
// format_number -> format pour les numéros de téléphones
|
||||
|
||||
number.addEventListener('keyup', function(e){
|
||||
ic.correct(number, false);
|
||||
}, false);
|
||||
// var number = document.querySelector('input.number[type="text"]');
|
||||
// ic.append(number, format_number, '06 06 06 06 06');
|
||||
// // format_number -> format pour les numéros de téléphones
|
||||
//
|
||||
// number.addEventListener('keyup', function(e){
|
||||
// ic.correct(number, false);
|
||||
// }, false);
|
||||
|
|
Loading…
Reference in New Issue