Remplacement de 'repeater.i' et 'repeater.n' en 'repeater:i' et 'repeater:n'
This commit is contained in:
parent
66ad11700d
commit
7e26e80604
|
@ -1,17 +1,19 @@
|
||||||
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$"}};
|
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}\$$/,ref_arv:/^(.+)\.(.+)$/};FormBuilder.spread_attr="children next_nodes prev_nodes attributes node_link listeners repeat browse".split(" ");
|
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 funcs".split(" ");
|
||||||
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.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,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.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 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.fetchNodeDefinition=function(a,b){var f,d;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)&&(d=new RegExp(f.slice(1,-1)),d.test(a))){matches={};for(d=1;d<RegExp.length&&10>d;d++)matches["$"+d]=RegExp["$"+d];return{def:b[f],scope:matches}}return{}};
|
||||||
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.replaceStatements=function(a,b,f,d,e){a=a instanceof Object?a:{};b=b instanceof Object?JSON.parse(JSON.stringify(b)):{};var c,k;if(a.hasOwnProperty("scope")&&a.scope instanceof Object)for(c in a.scope)b[c]=a.scope[c];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(c in k.scope)b[c]=k.scope[c];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(c in a)"string"==typeof a[c]?(a[c]=[a[c]],k=FormBuilder.replaceStatementsFunction(d,a[c][0],b),!1!==k?a[c]=k:(k=FormBuilder.replaceStatementsArray(a[c][0],b,d),!1!==k?a[c]=k:(a[c]=FormBuilder.replaceStatementsRegex(a[c],b),a[c]=FormBuilder.replaceStatementsPrimary(a[c],b),a[c]=FormBuilder.replaceStatementsArrayValue(a[c],b,d,e)))):"number"===typeof a[c]&&(a[c]=[ref(d,a[c])]);for(c in a)FormBuilder.regex.pri_in_key.test(c)?
|
||||||
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};
|
b[c.substring(1)]=ref(d,a[c]):FormBuilder.regex.arr_in_key.test(c)&&(b[c.substring(2)]=ref(d,a[c]));b=JSON.parse(JSON.stringify(b));for(c in a)if(-1<FormBuilder.spread_attr.indexOf(c))if(a[c]instanceof Array)for(var g in a[c])FormBuilder.replaceStatements(a[c][g],b,f,d,e);else a[c]instanceof Object&&FormBuilder.replaceStatements(a[c],b,f,d,e);return a};
|
||||||
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.replaceStatementsFunction=function(a,b,f){var d=null,d=FormBuilder.regex.fun_out_val.exec(b);if(null===d)return!1;f.hasOwnProperty(d[1])||(f[d[1]]=ref(a,function(){}));return f[d[1]]};FormBuilder.replaceStatementsArray=function(a,b,f){var d=null,d=FormBuilder.regex.arr_out_set.exec(a);if(null===d)return!1;b.hasOwnProperty(d[1])||(b[d[1]]=ref(f,[]));return b[d[1]]};
|
||||||
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.replaceStatementsRegex=function(a,b){var f=FormBuilder.regex.reg_out_val,d=null,e=[],c,k,g,h;for(g=0;g<a.length;g++){m=null;e=[];c=-1;for(k=[];null!==(d=f.exec(a[g]))&&!(c>=f.lastIndex);)c=f.lastIndex,e.push(d);for(d=c=0;d<e.length;d++)h=e[d][1],(0<c||0<e[d].index)&&k.push(a[g].substr(c,e[d].index-c)),b.hasOwnProperty(h)||(b[h]=""),k.push(b[h]),c=e[d].index+e[d][0].length;c<a[g].length&&k.push(a[g].substr(c,a[g].length));a=a.slice(0,g).concat(k).concat(a.slice(g+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.replaceStatementsPrimary=function(a,b){var f=FormBuilder.regex.pri_out_val,d=null,e=[],c,k,g,h;for(g=0;g<a.length;g++){m=null;e=[];c=0;for(k=[];null!==(d=f.exec(a[g]));)e.push(d);for(d=0;d<e.length;d++)h=e[d][1],(0<c||0<e[d].index)&&k.push(a[g].substr(c,e[d].index-c)),b.hasOwnProperty(h)||(b[h]=""),k.push(b[h]),c=e[d].index+e[d][0].length;c<a[g].length&&k.push(a[g].substr(c,a[g].length));a=a.slice(0,g).concat(k).concat(a.slice(g+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.replaceStatementsArrayValue=function(a,b,f,d){b=FormBuilder.regex.arr_out_val;var e=null,c=[],k,g,h,l;for(h=0;h<a.length;h++){m=null;c=[];k=0;for(g=[];null!==(e=b.exec(a[h]));)c.push(e);for(e=0;e<c.length;e++)l=c[e][1]+c[e][2]+c[e][3],(0<k||0<c[e].index)&&g.push(a[h].substr(k,c[e].index-k)),d.hasOwnProperty(l)||(d[l]=ref(f)),g.push(d[l]),k=c[e].index+c[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 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.readRef=function(a,b){var f,d="";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)d=FormBuilder.regex.ref_pri.test(b[f])&&a.hasOwnProperty(b[f])?a[b[f]]instanceof Array?d+FormBuilder.readRef(a,a[b[f]]):d+a[b[f]]:d+b[f].toString();return d};
|
||||||
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=
|
FormBuilder.buildElements=function(a,b,f){var d=[],e,c,k,g,h,l=["NULL"],n;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"]=g;if(a.hasOwnProperty("browse")&&(g=FormBuilder.readRef(b,a.browse.array),g instanceof Array)){l=[];h=[];n={};k=new RegExp(a.browse.id+".(.+)");
|
||||||
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,
|
for(e in f)k.test(e)&&h.push(RegExp.$1);if(a.browse.hasOwnProperty("funcs"))for(e in a.browse.funcs)k.test(e)&&(n[RegExp.$1]=FormBuilder.readRef(b,a.browse.funcs[e]));f.hasOwnProperty(a.browse.id+":i")||(f[a.browse.id+":i"]=ref(0));f.hasOwnProperty(a.browse.id+":n")||(f[a.browse.id+":n"]=ref(g));for(e=0;e<g.length;e++){l[e]={};for(c in h)g[e].hasOwnProperty(h[c])?l[e][a.browse.id+"."+h[c]]=g[e][h[c]]:n.hasOwnProperty(h[c])&&(l[e][a.browse.id+"."+h[c]]=n[h[c]](g[e]));l[e][a.browse.id+":i"]=e;l[e][a.browse.id+
|
||||||
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};
|
":n"]=g.length}}for(h=0;h<l.length;h++){d[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)d[h].prev=FormBuilder.buildElements(a.prev_nodes[e],b,f);if(a.hasOwnProperty("next_nodes"))for(e in a.next_nodes)d[h].next=FormBuilder.buildElements(a.next_nodes[e],b,f);if(a.hasOwnProperty("node_type"))d[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)d[h].prev=d[h].prev.concat(g[e].prev),d[h].node=g[e].node,d[h].next=g[e].next.concat(d[h].next);if(a.hasOwnProperty("attributes"))for(e in a.attributes)d[h].node.setAttribute(e,FormBuilder.readRef(b,a.attributes[e]));a.hasOwnProperty("text")&&(d[h].node.innerHTML=a.text);if(a.hasOwnProperty("listeners"))for(e in a.listeners)d[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(c in g[k].prev)d[h].node.appendChild(g[k].prev[c]);d[h].node.appendChild(g[k].node);for(c in g[k].prev)d[h].node.appendChild(g[k].next[c])}}return a.dom=d};
|
||||||
|
|
|
@ -82,14 +82,12 @@ FormBuilder.regex = {
|
||||||
pri_in_key: /^\$([a-z-]+)$/, // Regex associée à la clé d'une variable primitive
|
pri_in_key: /^\$([a-z-]+)$/, // Regex associée à la clé d'une variable primitive
|
||||||
|
|
||||||
arr_out_set: /^\{([a-z-]+)\[\]\}$/, // Regex associée à un tableau à remplacer
|
arr_out_set: /^\{([a-z-]+)\[\]\}$/, // Regex associée à un tableau à remplacer
|
||||||
arr_out_val: /\{([a-z-]+)\.([a-z-]+)\}/g, // Regex associée à une valeur de tableau à remplacer (primitif)
|
arr_out_val: /\{([a-z-]+)([\.:])([a-z-]+)\}/g, // Regex associée à une valeur de tableau à remplacer (primitif)
|
||||||
arr_in_key: /^\$([a-z-]+)$/, // Regex associée à la clé d'un tableau
|
arr_in_key: /^\$([a-z-]+)$/, // Regex associée à la clé d'un tableau
|
||||||
|
|
||||||
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
|
||||||
|
@ -101,7 +99,8 @@ FormBuilder.spread_attr = [ // Liste des attributs diffusant le scope
|
||||||
'listeners',
|
'listeners',
|
||||||
|
|
||||||
'repeat',
|
'repeat',
|
||||||
'browse'
|
'browse',
|
||||||
|
'funcs'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
@ -751,7 +750,7 @@ FormBuilder.replaceStatementsArrayValue = function(statements, scope, ref_table,
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
for( i = 0 ; i < matches.length ; i++ ){
|
for( i = 0 ; i < matches.length ; i++ ){
|
||||||
|
|
||||||
key = matches[i][1] + '.' + matches[i][2];
|
key = matches[i][1] + matches[i][2] + matches[i][3];
|
||||||
|
|
||||||
/* (1) On met la chaine d'avant le match (si existe) */
|
/* (1) On met la chaine d'avant le match (si existe) */
|
||||||
if( lasti > 0 || matches[i].index > 0 )
|
if( lasti > 0 || matches[i].index > 0 )
|
||||||
|
@ -863,12 +862,11 @@ FormBuilder.buildElements = function(definition, ref_table, ref_assoc){
|
||||||
|
|
||||||
var i, j, k, tmp, b,
|
var i, j, k, tmp, b,
|
||||||
repeated = ['NULL'],
|
repeated = ['NULL'],
|
||||||
scope;
|
scope, funcs;
|
||||||
|
|
||||||
/* [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.n );
|
tmp = FormBuilder.readRef( ref_table, definition.repeat.n );
|
||||||
|
|
||||||
// Si c'est bien un nombre
|
// Si c'est bien un nombre
|
||||||
|
@ -879,19 +877,19 @@ FormBuilder.buildElements = function(definition, ref_table, ref_assoc){
|
||||||
|
|
||||||
|
|
||||||
/* (2) Vérification des variables */
|
/* (2) Vérification des variables */
|
||||||
if( !ref_assoc.hasOwnProperty(definition.repeat.id+'.i') )
|
if( !ref_assoc.hasOwnProperty(definition.repeat.id+':i') )
|
||||||
ref_assoc[definition.repeat.id+'.i'] = ref(0);
|
ref_assoc[definition.repeat.id+':i'] = ref(0);
|
||||||
|
|
||||||
if( !ref_assoc.hasOwnProperty(definition.repeat.id+'.n') )
|
if( !ref_assoc.hasOwnProperty(definition.repeat.id+':n') )
|
||||||
ref_assoc[definition.repeat.id+'.n'] = ref(tmp);
|
ref_assoc[definition.repeat.id+':n'] = ref(tmp);
|
||||||
|
|
||||||
|
|
||||||
/* (2) On construit le scope pour chaque valeur */
|
/* (2) On construit le scope pour chaque valeur */
|
||||||
for( i = 0 ; i < tmp ; i++ ){
|
for( i = 0 ; i < tmp ; i++ ){
|
||||||
|
|
||||||
repeated[i] = {};
|
repeated[i] = {};
|
||||||
repeated[i][definition.repeat.id+'.i'] = i;
|
repeated[i][definition.repeat.id+':i'] = i;
|
||||||
repeated[i][definition.repeat.id+'.n'] = tmp;
|
repeated[i][definition.repeat.id+':n'] = tmp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -904,7 +902,75 @@ FormBuilder.buildElements = function(definition, ref_table, ref_assoc){
|
||||||
/* [2] Gestion de l'attribut 'browse'
|
/* [2] Gestion de l'attribut 'browse'
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
if( definition.hasOwnProperty('browse') ){
|
if( definition.hasOwnProperty('browse') ){
|
||||||
|
tmp = FormBuilder.readRef( ref_table, definition.browse.array );
|
||||||
|
|
||||||
|
// Si c'est bien un tableau
|
||||||
|
if( tmp instanceof Array ){
|
||||||
|
|
||||||
|
/* (1) On initialise le tableau et le scope */
|
||||||
|
repeated = [];
|
||||||
|
scope = [];
|
||||||
|
funcs = {};
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) On cherche les variables */
|
||||||
|
k = new RegExp( definition.browse.id+'.(.+)' );
|
||||||
|
|
||||||
|
// Si on trouve une valeur du type 'monTableauId.xxxxx'
|
||||||
|
for( i in ref_assoc )
|
||||||
|
if( k.test(i) )
|
||||||
|
scope.push( RegExp.$1 );
|
||||||
|
|
||||||
|
/* (2) On récupère les fonctions custom */
|
||||||
|
if( definition.browse.hasOwnProperty('funcs') ){
|
||||||
|
|
||||||
|
// Pour chaque fonction
|
||||||
|
for( i in definition.browse.funcs ){
|
||||||
|
|
||||||
|
// Si elle a le bon nom
|
||||||
|
if( k.test(i) ){
|
||||||
|
|
||||||
|
// on ajoute la fonction à la liste de fonctions
|
||||||
|
funcs[RegExp.$1] = FormBuilder.readRef( ref_table, definition.browse.funcs[i] );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* (3) Vérification des variables */
|
||||||
|
if( !ref_assoc.hasOwnProperty(definition.browse.id+':i') )
|
||||||
|
ref_assoc[definition.browse.id+':i'] = ref(0);
|
||||||
|
|
||||||
|
if( !ref_assoc.hasOwnProperty(definition.browse.id+':n') )
|
||||||
|
ref_assoc[definition.browse.id+':n'] = ref(tmp);
|
||||||
|
|
||||||
|
|
||||||
|
/* (4) On construit le scope pour chaque valeur */
|
||||||
|
for( i = 0 ; i < tmp.length ; i++ ){
|
||||||
|
|
||||||
|
repeated[i] = {};
|
||||||
|
|
||||||
|
for( j in scope ){
|
||||||
|
|
||||||
|
// {1} Si la valeur est un attribut //
|
||||||
|
if( tmp[i].hasOwnProperty(scope[j]) )
|
||||||
|
repeated[i][definition.browse.id+'.'+scope[j]] = tmp[i][scope[j]];
|
||||||
|
|
||||||
|
// {2} Si c'est une fonction custom //
|
||||||
|
else if( funcs.hasOwnProperty(scope[j]) )
|
||||||
|
repeated[i][definition.browse.id+'.'+scope[j]] = funcs[scope[j]](tmp[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
repeated[i][definition.browse.id+':i'] = i;
|
||||||
|
repeated[i][definition.browse.id+':n'] = tmp.length;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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:{"options.value":"{getval()}","options.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{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);
|
$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: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);
|
||||||
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);
|
||||||
|
|
|
@ -45,8 +45,8 @@ var custom_definition = {
|
||||||
browse: {
|
browse: {
|
||||||
array: '{options[]}',
|
array: '{options[]}',
|
||||||
funcs: {
|
funcs: {
|
||||||
'option.value': '{getval()}',
|
'options.value': '{getval()}',
|
||||||
'option.id': '{getnam()}'
|
'options.id': '{getnam()}'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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{rep.i}', $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[]}' }
|
||||||
|
|
Loading…
Reference in New Issue