la gestion de la création du 'repeat' fonctionne

This commit is contained in:
xdrm-brackets 2016-09-20 10:59:46 +02:00
parent 2f8d0fc9ea
commit 66ad11700d
4 changed files with 42 additions and 52 deletions

View File

@ -1,18 +1,17 @@
var ref=function(a,b){for(var g=null;null==g||a.hasOwnProperty(g);)g="$"+(268435456+Math.floor(4026531839*Math.random())).toString(16)+"$";a[g]=b;return g},FormBuilder=function(a){this.form_object=a};FormBuilder.prototype={form_object:this.form_object,defs_object:{},parent_element:null,built_form:null,root_element:null,ref_table:{$00000000$:null},ref_assoc:{NULL:"$00000000$"}}; var ref=function(a,b){for(var f=null;null==f||a.hasOwnProperty(f);)f="$"+(268435456+Math.floor(4026531839*Math.random())).toString(16)+"$";a[f]=b;return f},FormBuilder=function(a){this.form_object=a};FormBuilder.prototype={form_object:this.form_object,defs_object:{},parent_element:null,built_form:null,root_element:null,ref_table:{$00000000$:null},ref_assoc:{NULL:"$00000000$"}};
FormBuilder.regex={reg_in_key:/^\/\^(.+)\$\/$/,reg_out_val:/\{(\$[1-9])\}/,pri_out_val:/\{([a-z-]+)\}/g,pri_in_key:/^\$([a-z-]+)$/,arr_out_set:/^\{([a-z-]+)\[\]\}$/,arr_out_val:/\{([a-z-]+)\.([a-z-]+)\}/g,arr_in_key:/^\$([a-z-]+)$/,fun_out_val:/^\{([a-z-]+)\(\)\}$/,ref_pri:/^\$[a-f0-9]{8}\$$/};FormBuilder.spread_attr="children next_nodes prev_nodes attributes node_link listeners repeat browse".split(" ");FormBuilder.prototype.add_definition=function(a){for(var b in a)this.defs_object[b]=a[b]}; FormBuilder.regex={reg_in_key:/^\/\^(.+)\$\/$/,reg_out_val:/\{(\$[1-9])\}/,pri_out_val:/\{([a-z-]+)\}/g,pri_in_key:/^\$([a-z-]+)$/,arr_out_set:/^\{([a-z-]+)\[\]\}$/,arr_out_val:/\{([a-z-]+)\.([a-z-]+)\}/g,arr_in_key:/^\$([a-z-]+)$/,fun_out_val:/^\{([a-z-]+)\(\)\}$/,ref_pri:/^\$[a-f0-9]{8}\$$/,ref_arv:/^(.+)\.(.+)$/};FormBuilder.spread_attr="children next_nodes prev_nodes attributes node_link listeners repeat browse".split(" ");
FormBuilder.prototype.build=function(a){a=null==a?{}:a;for(var b in a)a[b]=ref(this.ref_table,a[b]),this.ref_assoc[b]=a[b];this.built_form=JSON.parse(JSON.stringify(this.form_object));this.built_form=FormBuilder.formatFormObject(this.built_form,this.defs_object);this.built_form=FormBuilder.replaceStatements(this.built_form,a,this.defs_object,this.ref_table,this.ref_assoc)}; FormBuilder.prototype.add_definition=function(a){for(var b in a)this.defs_object[b]=a[b]};FormBuilder.prototype.build=function(a){a=null==a?{}:a;for(var b in a)a[b]=ref(this.ref_table,a[b]),this.ref_assoc[b]=a[b];this.built_form=JSON.parse(JSON.stringify(this.form_object));this.built_form=FormBuilder.formatFormObject(this.built_form,this.defs_object);this.built_form=FormBuilder.replaceStatements(this.built_form,a,this.defs_object,this.ref_table,this.ref_assoc)};
FormBuilder.prototype.update=function(a){a=null==a?{}:a;for(var b in a)this.ref_assoc.hasOwnProperty(b)&&(this.ref_table[this.ref_assoc[b]]=a[b])}; FormBuilder.prototype.update=function(a){a=null==a?{}:a;for(var b in a)this.ref_assoc.hasOwnProperty(b)&&(this.ref_table[this.ref_assoc[b]]=a[b])};
FormBuilder.prototype.attach=function(a){if(!(a instanceof Element)&&null===this.parent_element)return!1;this.parent_element=a instanceof Element?a:this.parent_element;var b,g;a=FormBuilder.buildElements(this.built_form,this.ref_table,this.ref_assoc);for(b in a){for(g in a[b].prev)this.parent_element.appendChild(a[b].prev[g]);this.parent_element.appendChild(a[b].node);for(g in a[b].next)this.parent_element.appendChild(a[b].next[g])}};FormBuilder.formatFormObject=function(a,b){return a}; FormBuilder.prototype.attach=function(a){if(!(a instanceof Element)&&null===this.parent_element)return!1;this.parent_element=a instanceof Element?a:this.parent_element;var b,f;a=FormBuilder.buildElements(this.built_form,this.ref_table,this.ref_assoc);for(b in a){for(f in a[b].prev)this.parent_element.appendChild(a[b].prev[f]);this.parent_element.appendChild(a[b].node);for(f in a[b].next)this.parent_element.appendChild(a[b].next[f])}};FormBuilder.formatFormObject=function(a,b){return a};
FormBuilder.fetchNodeDefinition=function(a,b){var g,c;r=FormBuilder.regex.reg_in_key;if("undefined"!=typeof b&&b.hasOwnProperty(a))return{def:b[a]};for(g in b)if(r.test(g)&&(c=new RegExp(g.slice(1,-1)),c.test(a))){matches={};for(c=1;c<RegExp.length&&10>c;c++)matches["$"+c]=RegExp["$"+c];return{def:b[g],scope:matches}}return{}}; FormBuilder.fetchNodeDefinition=function(a,b){var f,c;r=FormBuilder.regex.reg_in_key;if("undefined"!=typeof b&&b.hasOwnProperty(a))return{def:b[a]};for(f in b)if(r.test(f)&&(c=new RegExp(f.slice(1,-1)),c.test(a))){matches={};for(c=1;c<RegExp.length&&10>c;c++)matches["$"+c]=RegExp["$"+c];return{def:b[f],scope:matches}}return{}};
FormBuilder.replaceStatements=function(a,b,g,c,e){a=a instanceof Object?a:{};b=b instanceof Object?JSON.parse(JSON.stringify(b)):{};var d,k;if(a.hasOwnProperty("scope")&&a.scope instanceof Object)for(d in a.scope)b[d]=a.scope[d];if(a.hasOwnProperty("node")&&"string"==typeof a.node&&(k=FormBuilder.fetchNodeDefinition(a.node,g),k.hasOwnProperty("def")&&(a.node_link=JSON.parse(JSON.stringify(k.def)),k.hasOwnProperty("scope"))))for(d in k.scope)b[d]=k.scope[d];a.hasOwnProperty("browse")&&(a.browse.hasOwnProperty("array")&& FormBuilder.replaceStatements=function(a,b,f,c,e){a=a instanceof Object?a:{};b=b instanceof Object?JSON.parse(JSON.stringify(b)):{};var d,k;if(a.hasOwnProperty("scope")&&a.scope instanceof Object)for(d in a.scope)b[d]=a.scope[d];if(a.hasOwnProperty("node")&&"string"==typeof a.node&&(k=FormBuilder.fetchNodeDefinition(a.node,f),k.hasOwnProperty("def")&&(a.node_link=JSON.parse(JSON.stringify(k.def)),k.hasOwnProperty("scope"))))for(d in k.scope)b[d]=k.scope[d];a.hasOwnProperty("browse")&&(a.browse.hasOwnProperty("array")&&
FormBuilder.regex.arr_out_set.test(a.browse.array)?a.browse.id=RegExp.$1:delete a.browse);for(d in a)"string"==typeof a[d]?(a[d]=[a[d]],k=FormBuilder.replaceStatementsFunction(c,a[d][0],b),!1!==k?a[d]=k:(k=FormBuilder.replaceStatementsArray(a[d][0],b,c),!1!==k?a[d]=k:(a[d]=FormBuilder.replaceStatementsRegex(a[d],b),a[d]=FormBuilder.replaceStatementsPrimary(a[d],b),a[d]=FormBuilder.replaceStatementsArrayValue(a[d],b,c,e)))):"number"===typeof a[d]&&(a[d]=[ref(c,a[d])]);for(d in a)FormBuilder.regex.pri_in_key.test(d)? FormBuilder.regex.arr_out_set.test(a.browse.array)?a.browse.id=RegExp.$1:delete a.browse);for(d in a)"string"==typeof a[d]?(a[d]=[a[d]],k=FormBuilder.replaceStatementsFunction(c,a[d][0],b),!1!==k?a[d]=k:(k=FormBuilder.replaceStatementsArray(a[d][0],b,c),!1!==k?a[d]=k:(a[d]=FormBuilder.replaceStatementsRegex(a[d],b),a[d]=FormBuilder.replaceStatementsPrimary(a[d],b),a[d]=FormBuilder.replaceStatementsArrayValue(a[d],b,c,e)))):"number"===typeof a[d]&&(a[d]=[ref(c,a[d])]);for(d in a)FormBuilder.regex.pri_in_key.test(d)?
b[d.substring(1)]=ref(c,a[d]):FormBuilder.regex.arr_in_key.test(d)&&(b[d.substring(2)]=ref(c,a[d]));b=JSON.parse(JSON.stringify(b));for(d in a)if(-1<FormBuilder.spread_attr.indexOf(d))if(a[d]instanceof Array)for(var f in a[d])FormBuilder.replaceStatements(a[d][f],b,g,c,e);else a[d]instanceof Object&&FormBuilder.replaceStatements(a[d],b,g,c,e);return a}; b[d.substring(1)]=ref(c,a[d]):FormBuilder.regex.arr_in_key.test(d)&&(b[d.substring(2)]=ref(c,a[d]));b=JSON.parse(JSON.stringify(b));for(d in a)if(-1<FormBuilder.spread_attr.indexOf(d))if(a[d]instanceof Array)for(var g in a[d])FormBuilder.replaceStatements(a[d][g],b,f,c,e);else a[d]instanceof Object&&FormBuilder.replaceStatements(a[d],b,f,c,e);return a};
FormBuilder.replaceStatementsFunction=function(a,b,g){var c=null,c=FormBuilder.regex.fun_out_val.exec(b);if(null===c)return!1;g.hasOwnProperty(c[1])||(g[c[1]]=ref(a,function(){}));return g[c[1]]};FormBuilder.replaceStatementsArray=function(a,b,g){var c=null,c=FormBuilder.regex.arr_out_set.exec(a);if(null===c)return!1;b.hasOwnProperty(c[1])||(b[c[1]]=ref(g,[]));return b[c[1]]}; FormBuilder.replaceStatementsFunction=function(a,b,f){var c=null,c=FormBuilder.regex.fun_out_val.exec(b);if(null===c)return!1;f.hasOwnProperty(c[1])||(f[c[1]]=ref(a,function(){}));return f[c[1]]};FormBuilder.replaceStatementsArray=function(a,b,f){var c=null,c=FormBuilder.regex.arr_out_set.exec(a);if(null===c)return!1;b.hasOwnProperty(c[1])||(b[c[1]]=ref(f,[]));return b[c[1]]};
FormBuilder.replaceStatementsRegex=function(a,b){var g=FormBuilder.regex.reg_out_val,c=null,e=[],d,k,f,h;for(f=0;f<a.length;f++){m=null;e=[];d=-1;for(k=[];null!==(c=g.exec(a[f]))&&!(d>=g.lastIndex);)d=g.lastIndex,e.push(c);for(c=d=0;c<e.length;c++)h=e[c][1],(0<d||0<e[c].index)&&k.push(a[f].substr(d,e[c].index-d)),b.hasOwnProperty(h)||(b[h]=""),k.push(b[h]),d=e[c].index+e[c][0].length;d<a[f].length&&k.push(a[f].substr(d,a[f].length));a=a.slice(0,f).concat(k).concat(a.slice(f+1))}return a}; FormBuilder.replaceStatementsRegex=function(a,b){var f=FormBuilder.regex.reg_out_val,c=null,e=[],d,k,g,h;for(g=0;g<a.length;g++){m=null;e=[];d=-1;for(k=[];null!==(c=f.exec(a[g]))&&!(d>=f.lastIndex);)d=f.lastIndex,e.push(c);for(c=d=0;c<e.length;c++)h=e[c][1],(0<d||0<e[c].index)&&k.push(a[g].substr(d,e[c].index-d)),b.hasOwnProperty(h)||(b[h]=""),k.push(b[h]),d=e[c].index+e[c][0].length;d<a[g].length&&k.push(a[g].substr(d,a[g].length));a=a.slice(0,g).concat(k).concat(a.slice(g+1))}return a};
FormBuilder.replaceStatementsPrimary=function(a,b){var g=FormBuilder.regex.pri_out_val,c=null,e=[],d,k,f,h;for(f=0;f<a.length;f++){m=null;e=[];d=0;for(k=[];null!==(c=g.exec(a[f]));)e.push(c);for(c=0;c<e.length;c++)h=e[c][1],(0<d||0<e[c].index)&&k.push(a[f].substr(d,e[c].index-d)),b.hasOwnProperty(h)||(b[h]=""),k.push(b[h]),d=e[c].index+e[c][0].length;d<a[f].length&&k.push(a[f].substr(d,a[f].length));a=a.slice(0,f).concat(k).concat(a.slice(f+1))}return a}; FormBuilder.replaceStatementsPrimary=function(a,b){var f=FormBuilder.regex.pri_out_val,c=null,e=[],d,k,g,h;for(g=0;g<a.length;g++){m=null;e=[];d=0;for(k=[];null!==(c=f.exec(a[g]));)e.push(c);for(c=0;c<e.length;c++)h=e[c][1],(0<d||0<e[c].index)&&k.push(a[g].substr(d,e[c].index-d)),b.hasOwnProperty(h)||(b[h]=""),k.push(b[h]),d=e[c].index+e[c][0].length;d<a[g].length&&k.push(a[g].substr(d,a[g].length));a=a.slice(0,g).concat(k).concat(a.slice(g+1))}return a};
FormBuilder.replaceStatementsArrayValue=function(a,b,g,c){b=FormBuilder.regex.arr_out_val;var e=null,d=[],k,f,h,l;for(h=0;h<a.length;h++){m=null;d=[];k=0;for(f=[];null!==(e=b.exec(a[h]));)d.push(e);for(e=0;e<d.length;e++)l=d[e][1]+"."+d[e][2],(0<k||0<d[e].index)&&f.push(a[h].substr(k,d[e].index-k)),c.hasOwnProperty(l)||(c[l]=ref(g)),f.push(c[l]),k=d[e].index+d[e][0].length;k<a[h].length&&f.push(a[h].substr(k,a[h].length));a=a.slice(0,h).concat(f).concat(a.slice(h+1))}return a}; FormBuilder.replaceStatementsArrayValue=function(a,b,f,c){b=FormBuilder.regex.arr_out_val;var e=null,d=[],k,g,h,l;for(h=0;h<a.length;h++){m=null;d=[];k=0;for(g=[];null!==(e=b.exec(a[h]));)d.push(e);for(e=0;e<d.length;e++)l=d[e][1]+"."+d[e][2],(0<k||0<d[e].index)&&g.push(a[h].substr(k,d[e].index-k)),c.hasOwnProperty(l)||(c[l]=ref(f)),g.push(c[l]),k=d[e].index+d[e][0].length;k<a[h].length&&g.push(a[h].substr(k,a[h].length));a=a.slice(0,h).concat(g).concat(a.slice(h+1))}return a};
FormBuilder.readRef=function(a,b){var g,c="";if("string"==typeof b&&FormBuilder.regex.ref_pri.test(b)){for(;"string"==typeof b&&FormBuilder.regex.ref_pri.test(b);)b=a[b],b instanceof Array&&1==b.length&&(b=b[0]);return b}for(g in b)c=FormBuilder.regex.ref_pri.test(b[g])&&a.hasOwnProperty(b[g])?a[b[g]]instanceof Array?c+FormBuilder.readRef(a,a[b[g]]):c+a[b[g]]:c+b[g].toString();return c}; FormBuilder.readRef=function(a,b){var f,c="";if("string"==typeof b&&FormBuilder.regex.ref_pri.test(b)){for(;"string"==typeof b&&FormBuilder.regex.ref_pri.test(b);)b=a[b],b instanceof Array&&1==b.length&&(b=b[0]);return b}for(f in b)c=FormBuilder.regex.ref_pri.test(b[f])&&a.hasOwnProperty(b[f])?a[b[f]]instanceof Array?c+FormBuilder.readRef(a,a[b[f]]):c+a[b[f]]:c+b[f].toString();return c};
FormBuilder.buildElements=function(a,b,g){var c=[],e,d,k,f,h;h=null;var l=["NULL"];if(a.hasOwnProperty("repeat")){f=FormBuilder.readRef(b,a.repeat);if(isNaN(f))f instanceof Array&&(h=f);else for(h=[],e=0;e<f;e++)h[e]=e;if(h instanceof Array){console.log("repeat",h);console.log(a);delete a.repeat;l=[];f=g["options.value"];for(e=0;e<h.length;e++){b[f]=h[e];l[e]=FormBuilder.buildElements(a,b,g);for(d in l[e].prev)parent.dom.appendChild(l[e].prev[d]);parent.dom.appendChild(l[e].node);for(d in l[e].next)parent.dom.appendChild(l[e].next[d])}console.log(l)}}a.hasOwnProperty("browse"); FormBuilder.buildElements=function(a,b,f){var c=[],e,d,k,g,h,l=["NULL"];if(a.hasOwnProperty("repeat")&&(g=FormBuilder.readRef(b,a.repeat.n),!isNaN(g)))for(l=[],f.hasOwnProperty(a.repeat.id+".i")||(f[a.repeat.id+".i"]=ref(0)),f.hasOwnProperty(a.repeat.id+".n")||(f[a.repeat.id+".n"]=ref(g)),e=0;e<g;e++)l[e]={},l[e][a.repeat.id+".i"]=e,l[e][a.repeat.id+".n"]=n;a.hasOwnProperty("browse");for(h=0;h<l.length;h++){c[h]={prev:[],node:null,next:[]};for(e in l[h])b[f[e]]=l[h][e];if(a.hasOwnProperty("prev_nodes"))for(e in a.prev_nodes)c[h].prev=
for(h=0;h<l.length;h++){c[h]={prev:[],node:null,next:[]};if(a.hasOwnProperty("prev_nodes"))for(e in a.prev_nodes)c[h].prev=FormBuilder.buildElements(a.prev_nodes[e],b,g);if(a.hasOwnProperty("next_nodes"))for(e in a.next_nodes)c[h].next=FormBuilder.buildElements(a.next_nodes[e],b,g);if(a.hasOwnProperty("node_type"))c[h].node=document.createElement(FormBuilder.readRef(b,a.node_type));else if(a.hasOwnProperty("node_link"))for(e in f=FormBuilder.buildElements(a.node_link,b,g),f)c[h].prev=c[h].prev.concat(f[e].prev), FormBuilder.buildElements(a.prev_nodes[e],b,f);if(a.hasOwnProperty("next_nodes"))for(e in a.next_nodes)c[h].next=FormBuilder.buildElements(a.next_nodes[e],b,f);if(a.hasOwnProperty("node_type"))c[h].node=document.createElement(FormBuilder.readRef(b,a.node_type));else if(a.hasOwnProperty("node_link"))for(e in g=FormBuilder.buildElements(a.node_link,b,f),g)c[h].prev=c[h].prev.concat(g[e].prev),c[h].node=g[e].node,c[h].next=g[e].next.concat(c[h].next);if(a.hasOwnProperty("attributes"))for(e in a.attributes)c[h].node.setAttribute(e,
c[h].node=f[e].node,c[h].next=f[e].next.concat(c[h].next);if(a.hasOwnProperty("attributes"))for(e in a.attributes)c[h].node.setAttribute(e,FormBuilder.readRef(b,a.attributes[e]));a.hasOwnProperty("text")&&(c[h].node.innerHTML=a.text);if(a.hasOwnProperty("listeners"))for(e in a.listeners)c[h].node.addEventListener(e,FormBuilder.readRef(b,a.listeners[e]),!1);if(a.hasOwnProperty("children"))for(e in a.children)for(k in f=FormBuilder.buildElements(a.children[e],b,g),f){for(d in f[k].prev)c[h].node.appendChild(f[k].prev[d]); FormBuilder.readRef(b,a.attributes[e]));a.hasOwnProperty("text")&&(c[h].node.innerHTML=a.text);if(a.hasOwnProperty("listeners"))for(e in a.listeners)c[h].node.addEventListener(e,FormBuilder.readRef(b,a.listeners[e]),!1);if(a.hasOwnProperty("children"))for(e in a.children)for(k in g=FormBuilder.buildElements(a.children[e],b,f),g){for(d in g[k].prev)c[h].node.appendChild(g[k].prev[d]);c[h].node.appendChild(g[k].node);for(d in g[k].prev)c[h].node.appendChild(g[k].next[d])}}return a.dom=c};
c[h].node.appendChild(f[k].node);for(d in f[k].prev)c[h].node.appendChild(f[k].next[d])}}return a.dom=c};

View File

@ -87,7 +87,9 @@ FormBuilder.regex = {
fun_out_val: /^\{([a-z-]+)\(\)\}$/, // Regex associée à une function incluse dans une clé fun_out_val: /^\{([a-z-]+)\(\)\}$/, // Regex associée à une function incluse dans une clé
ref_pri: /^\$[a-f0-9]{8}\$$/ // Clé de référence ref_pri: /^\$[a-f0-9]{8}\$$/, // Clé de référence
ref_arv: /^(.+)\.(.+)$/ // Clé de référence
}; };
FormBuilder.spread_attr = [ // Liste des attributs diffusant le scope FormBuilder.spread_attr = [ // Liste des attributs diffusant le scope
@ -860,54 +862,39 @@ FormBuilder.buildElements = function(definition, ref_table, ref_assoc){
var built = []; var built = [];
var i, j, k, tmp, b, var i, j, k, tmp, b,
repeater = null, repeated = ['NULL'],
repeated = ['NULL']; scope;
/* [1] Gestion de l'attribut 'repeat' /* [1] Gestion de l'attribut 'repeat'
=========================================================*/ =========================================================*/
if( definition.hasOwnProperty('repeat') ){ if( definition.hasOwnProperty('repeat') ){
tmp = FormBuilder.readRef(ref_table, definition.repeat); tmp = FormBuilder.readRef( ref_table, definition.repeat.n );
/* (1) Si on a un nombre */ // Si c'est bien un nombre
if( !isNaN(tmp) ){ if( !isNaN(tmp) ){
repeater = [];
for( i = 0 ; i < tmp ; i++ )
repeater[i] = i;
/* (2) Si c'est un tableau */
}else if( tmp instanceof Array)
repeater = tmp; // repeater = tmp;
/* (1) Si on a un répéteur correct
---------------------------------------------------------*/
if( repeater instanceof Array ){
console.log('repeat', repeater);
console.log(definition);
delete definition.repeat;
/* (1) On initialise le tableau */
repeated = []; repeated = [];
var refx = ref_assoc['options.value'];
/* (1) Pour chaque répétition */
for( i = 0 ; i < repeater.length ; i++ ){
// {1} On met à jour la valeur // /* (2) Vérification des variables */
ref_table[refx] = repeater[i]; if( !ref_assoc.hasOwnProperty(definition.repeat.id+'.i') )
ref_assoc[definition.repeat.id+'.i'] = ref(0);
// {2} On crée l'élément // if( !ref_assoc.hasOwnProperty(definition.repeat.id+'.n') )
repeated[i] = FormBuilder.buildElements(definition, ref_table, ref_assoc); ref_assoc[definition.repeat.id+'.n'] = ref(tmp);
for( j in repeated[i].prev ) parent.dom.appendChild( repeated[i].prev[j] );
parent.dom.appendChild( repeated[i].node ); /* (2) On construit le scope pour chaque valeur */
for( j in repeated[i].next ) parent.dom.appendChild( repeated[i].next[j] ); for( i = 0 ; i < tmp ; i++ ){
repeated[i] = {};
repeated[i][definition.repeat.id+'.i'] = i;
repeated[i][definition.repeat.id+'.n'] = tmp;
} }
console.log( repeated );
} }
@ -927,9 +914,13 @@ FormBuilder.buildElements = function(definition, ref_table, ref_assoc){
for( b = 0 ; b < repeated.length ; b++ ){ for( b = 0 ; b < repeated.length ; b++ ){
/* (1) On initialise l'élément courant */
built[b] = { prev: [], node: null, next: [] }; built[b] = { prev: [], node: null, next: [] };
/* (2) Gestion des variables de 'repeat' et 'browse' */
for( i in repeated[b] )
ref_table[ ref_assoc[i] ] = repeated[b][i];
/* [3] On construit les éléments @prev_nodes, s'ils existent /* [3] On construit les éléments @prev_nodes, s'ils existent

View File

@ -1,5 +1,5 @@
document.body.innerHTML="";"use strict"; document.body.innerHTML="";"use strict";
var default_definition={input:{node_type:"input"},"/^h([1-6])$/":{node_type:"h{$1}"},br:{node_type:"br"},option:{node_type:"option"},select:{node_type:"select"},span:{node_type:"span"}},custom_definition={"/^input.([a-z]+)$/":{node:"input",attributes:{type:"{$1}","data-name":"{name}",value:"{value}",placeholder:"{placeholder}"},next_nodes:[{node:"br"}],listeners:{focus:"{xx()}"}},"custom-select":{node:"span",attributes:{"class":"select-container nobold"},children:[{node:"select",attributes:{"data-name":"{name}"}, var default_definition={input:{node_type:"input"},"/^h([1-6])$/":{node_type:"h{$1}"},br:{node_type:"br"},option:{node_type:"option"},select:{node_type:"select"},span:{node_type:"span"}},custom_definition={"/^input.([a-z]+)$/":{node:"input",attributes:{type:"{$1}","data-name":"{name}",value:"{value}",placeholder:"{placeholder}"},next_nodes:[{node:"br"}],listeners:{focus:"{xx()}"}},"custom-select":{node:"span",attributes:{"class":"select-container nobold"},children:[{node:"select",attributes:{"data-name":"{name}"},
children:[{node:"option",attributes:{value:"{options.id}"},text:"{options.value}",browse:{array:"{options[]}",funcs:{"option.value":"{getval()}","option.id":"{getnam()}"}}}]}],next_nodes:[{node:"br"}]}},form={node:"h4",attributes:{"data-icon":"o","class":"new-contact color2"},children:[{node:"input.hidden",$name:"uid",$value:"{uid}"},{node:"input.hidden",$name:"call",$value:"{call}"},{node:"input.hidden",$name:"sms",$value:"{sms}"},{node:"input.hidden",$name:"countcall",$value:"{countcall}"},{node:"input.hidden", children:[{node:"option",attributes:{value:"{options.id}"},text:"{options.value}",browse:{array:"{options[]}",funcs:{"option.value":"{getval()}","option.id":"{getnam()}"}}}]}],next_nodes:[{node:"br"}]}},form={node:"h4",attributes:{"data-icon":"o","class":"new-contact color2"},children:[{node:"input.hidden",$name:"uid",$value:"{uid}"},{node:"input.hidden",$name:"call",$value:"{call}"},{node:"input.hidden",$name:"sms",$value:"{sms}"},{node:"input.hidden",$name:"countcall",$value:"{countcall}"},{node:"input.hidden",
$name:"countsms",$value:"{countsms}"},{node:"input.text",$name:"total",$value:"xx{countcall} calls + {countsms} sms to {number}xx"},{node:"input.text",$name:"count",$value:"{rep.i} sur {rep.n}",repeat:{n:10,id:"rep"}},{node:"input.text",$name:"number",$value:"{number}",$xx:"{clicklistener}"},{node:"custom-select",$name:"existing",$options:"{options[]}"}]},fb=new FormBuilder(form);fb.add_definition(default_definition);fb.add_definition(custom_definition); $name:"countsms",$value:"{countsms}"},{node:"input.text",$name:"total",$value:"xx{countcall} calls + {countsms} sms to {number}xx"},{node:"input.text",$name:"count{rep.i}",$value:"{rep.i} sur {rep.n}",repeat:{n:100,id:"rep"}},{node:"input.text",$name:"number",$value:"{number}",$xx:"{clicklistener}"},{node:"custom-select",$name:"existing",$options:"{options[]}"}]},fb=new FormBuilder(form);fb.add_definition(default_definition);fb.add_definition(custom_definition);
fb.build({uid:1,call:2,sms:3,countcall:4,countsms:5,number:"01 02 03 04 05",options:["a","b","c","d"],clicklistener:function(a){console.log("clicked",a)},getval:function(a){return a},getnam:function(a){return"["+a+"]"}});console.log(fb.built_form);var str=function(a){return FormBuilder.readRef(fb.ref_table,a)};fb.attach(document.body); fb.build({uid:1,call:2,sms:3,countcall:4,countsms:5,number:"01 02 03 04 05",options:["a","b","c","d"],clicklistener:function(a){console.log("clicked",a)},getval:function(a){return a},getnam:function(a){return"["+a+"]"}});console.log(fb.built_form);var str=function(a){return FormBuilder.readRef(fb.ref_table,a)};fb.attach(document.body);

View File

@ -68,7 +68,7 @@ var form = {
{ node: 'input.hidden', $name: 'countcall', $value: '{countcall}' }, { node: 'input.hidden', $name: 'countcall', $value: '{countcall}' },
{ node: 'input.hidden', $name: 'countsms', $value: '{countsms}' }, { node: 'input.hidden', $name: 'countsms', $value: '{countsms}' },
{ node: 'input.text', $name: 'total', $value: 'xx{countcall} calls + {countsms} sms to {number}xx' }, { node: 'input.text', $name: 'total', $value: 'xx{countcall} calls + {countsms} sms to {number}xx' },
{ node: 'input.text', $name: 'count', $value: '{rep.i} sur {rep.n}', repeat: {n: 10, id: "rep"} }, { node: 'input.text', $name: 'count{rep.i}', $value: '{rep.i} sur {rep.n}', repeat: {n: 10, id: "rep"} },
{ node: 'input.text', $name: 'number', $value: '{number}', $xx: '{clicklistener}' }, { node: 'input.text', $name: 'number', $value: '{number}', $xx: '{clicklistener}' },
{ node: 'custom-select', $name: 'existing', $options: '{options[]}' } { node: 'custom-select', $name: 'existing', $options: '{options[]}' }