2016-09-17 08:02:22 +00:00
|
|
|
var FormBuilder=function(a,c){this.parent_element=a;this.form_object=c;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-]+)\}\}$/,array_output_value:/\{([a-z-]+)\.([a-z-]+)\}/g,array_input_key:/^\$\$([a-z-]+)$/}};
|
|
|
|
FormBuilder.formatFormObject=function(a){if(a.hasOwnProperty("children"))for(var c in a.children)a.children[c].parent=a,FormBuilder.formatFormObject(a.children[c]);return a};FormBuilder.prototype.add_definition=function(a){for(var c in a)this.defs_object[c]=a[c]};
|
|
|
|
FormBuilder.replaceStatements=function(a,c){var b,e,d;for(b in a)if("parent"!=b&&"string"==typeof a[b]){e=FormBuilder.prototype.regex.array_output_set;var f=[];d=e.exec(a[b]);null!==d&&f.push(d[1]);for(d in f)c.hasOwnProperty(f[d])||(c[f[d]]=[]),a[b]=c[f[d]];if(!(0<f.length)){e=FormBuilder.prototype.regex.primitive_ouput_value;for(var g=[];null!==(d=e.exec(a[b]));)g.push(d[1]);for(d in g)c.hasOwnProperty(g[d])||(c[g[d]]=""),e=new RegExp("{"+g[d]+"}","g"),a[b]=a[b].replace(e,c[g[d]]);if(!(0<g.length)){e=
|
|
|
|
FormBuilder.prototype.regex.array_output_value;for(g=[];null!==(d=e.exec(a[b]));)g.push(d[1]);for(d in g)c.hasOwnProperty(f[d])||(c[f[d]]=""),e=new RegExp("/{"+f[d]+"}/","g"),a[b].replace(e,c[f[d]])}}}for(b in a)FormBuilder.prototype.regex.primitive_input_key.test(b)?c[b.substring(1)]=a[b]:FormBuilder.prototype.regex.array_input_key.test(b)&&(c[b.substring(2)]=a[b]);console.log("scope",c);for(b in a)"parent"!=b&&(a[b]instanceof Object||a[b]instanceof Array)&&(a[b]=FormBuilder.replaceStatements(a[b],
|
|
|
|
c));return a};
|