Form-Builder début implémentation

This commit is contained in:
xdrm-brackets 2016-09-17 08:29:59 +02:00
parent 6ab5dec529
commit 3326f44b15
2 changed files with 24 additions and 11 deletions

View File

@ -1,3 +1,3 @@
var FormBuilder=function(a,b){this.parent_element=a;this.form_object=b;FormBuilder.formatFormObject(this.form_object)}; var FormBuilder=function(a,d){this.parent_element=a;this.form_object=d;FormBuilder.formatFormObject(this.form_object)};
FormBuilder.prototype={form_object:this.form_object,defs_object:{},parent_element:this.parent_element,allowed_attr:"node node_type node_attr node_children next_nodes prev_nodes attributes children text repeat".split(" "),built_form:null,regex:{primitive_ouput_value:/\{([a-z-]+)\}/g,primitive_input_key:/^\$([a-z-]+)$/,array_output_set:/\{\{([a-z-]+)\}\}/g,array_output_value:/\{([a-z-]+)\.([a-z-]+)\}/g,array_input_key:/^\$\$([a-z-]+)$/}}; FormBuilder.prototype={form_object:this.form_object,defs_object:{},parent_element:this.parent_element,allowed_attr:"node node_type node_attr node_children next_nodes prev_nodes attributes children text repeat".split(" "),built_form:null,regex:{primitive_ouput_value:/\{([a-z-]+)\}/g,primitive_input_key:/^\$([a-z-]+)$/,array_output_set:/\{\{([a-z-]+)\}\}/g,array_output_value:/\{([a-z-]+)\.([a-z-]+)\}/g,array_input_key:/^\$\$([a-z-]+)$/}};
FormBuilder.formatFormObject=function(a){if(a.hasOwnProperty("children"))for(var b in a.children)a.children[b].parent=a,FormBuilder.formatFormObject(a.children[b]);return a};FormBuilder.replaceStatements=function(a,b){for(var c in a)"string"==typeof a[c]&&(/a/.exec(a[c]),console.log(RegExp.$0));return a}; FormBuilder.formatFormObject=function(a){if(a.hasOwnProperty("children"))for(var d in a.children)a.children[d].parent=a,FormBuilder.formatFormObject(a.children[d]);return a};FormBuilder.replaceStatements=function(a,d){for(var e in a)if("string"==typeof a[e]){for(var b=FormBuilder.prototype.regex.primitive_ouput_value,c=[];null!==c[c.push(b.exec(a[e]))-1];);for(b=0;b<c.length-1;b++)c[b]=c[b][1];console.log(c)}return a};

View File

@ -37,11 +37,11 @@ FormBuilder.prototype = {
], ],
built_form: null, // Element correspondant au formulaire construit built_form: null, // Element correspondant au formulaire construit
regex: { regex: {
'primitive_ouput_value': /\{([a-z-]+)\}/g, primitive_ouput_value: /\{([a-z-]+)\}/g,
'primitive_input_key': /^\$([a-z-]+)$/, primitive_input_key: /^\$([a-z-]+)$/,
'array_output_set': /\{\{([a-z-]+)\}\}/g, array_output_set: /\{\{([a-z-]+)\}\}/g,
'array_output_value': /\{([a-z-]+)\.([a-z-]+)\}/g, array_output_value: /\{([a-z-]+)\.([a-z-]+)\}/g,
'array_input_key': /^\$\$([a-z-]+)$/ array_input_key: /^\$\$([a-z-]+)$/
} }
}; };
@ -84,11 +84,24 @@ FormBuilder.replaceStatements = function(object, scope){
/* (1) Si la valeur est une string */ /* (1) Si la valeur est une string */
if( typeof object[key] == 'string' ){ if( typeof object[key] == 'string' ){
/* (2) On cherche toutes les variables à remplacer */ /* [1] On cherche toutes les variables PRIMITIVES à remplacer
var matches = []; =========================================================*/
/a/.exec(object[key]); /* (1) On récupère la regex */
console.log(RegExp.$0); var r = FormBuilder.prototype.regex.primitive_ouput_value,
m,
matches = [];
/* (2) Tant que ça match */
// while( m = r.exec(object[key]) !== null ){
// matches.push( m[1] );
// }
while( matches[ matches.push(r.exec(object[key])) -1 ] !== null );
for( var i = 0 ; i < matches.length-1 ; i++ )
matches[i] = matches[i][1];
console.log(matches);
} }