2016-09-18 10:37:21 +00:00
var refObject = function ( a ) { this . value = a } ; refObject . prototype = { value : this . value , get : function ( ) { return this . value } , set : function ( a ) { this . value = a } , valueOf : function ( ) { return this . get ( ) } } ; var ref = function ( a ) { return new refObject ( a ) } , 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 } ;
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-]+)$/ } ; FormBuilder . spread _attr = [ "children" , "next_nodes" , "prev_nodes" , "attributes" , "node_link" ] ; FormBuilder . allowed _attr = "node node_type next_nodes prev_nodes attributes children text repeat" . split ( " " ) ;
2016-09-18 13:11:19 +00:00
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 ; 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 ) } ;
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 } ; FormBuilder . formatFormObject = function ( a , b ) { if ( a . hasOwnProperty ( "children" ) ) for ( var g in a . children ) a . children [ g ] . parent = a , FormBuilder . formatFormObject ( a . children [ g ] , 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 . replaceStatements = function ( a , b , g ) { a = a instanceof Object ? a : { } ; b = b instanceof Object ? JSON . parse ( JSON . stringify ( b ) ) : { } ; var c , f , e , h ; 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 && ( f = FormBuilder . fetchNodeDefinition ( a . node , g ) , f . hasOwnProperty ( "def" ) && ( a . node _link = JSON . parse ( JSON . stringify ( f . def ) ) , f . hasOwnProperty ( "scope" ) ) ) ) for ( c in f . scope ) b [ c ] = f . scope [ c ] ; a . received = b ; for ( c in a ) if ( "string" == typeof a [ c ] ) { f =
FormBuilder . regex . arr _out _set ; var d = [ ] ; ( e = f . exec ( a [ c ] ) ) && d . push ( e [ 1 ] ) ; for ( e in d ) b . hasOwnProperty ( d [ e ] ) || ( b [ d [ e ] ] = [ ] ) , a [ c ] = b [ d [ e ] ] ; if ( ! ( 0 < d . length ) ) { f = FormBuilder . regex . reg _out _val ; h = - 1 ; for ( d = [ ] ; null !== ( e = f . exec ( a [ c ] ) ) && ! ( h >= f . lastIndex ) ; ) h = f . lastIndex , d . push ( e [ 1 ] ) ; for ( e in d ) b . hasOwnProperty ( d [ e ] ) || ( b [ d [ e ] ] = "" ) , f = new RegExp ( "{$" + d [ e ] [ 1 ] + "}" , "g" ) , a [ c ] = a [ c ] . replace ( f , b [ d [ e ] ] ) ; if ( ! ( 0 < d . length ) ) { f = FormBuilder . regex . pri _out _val ; for ( d = [ ] ; null !== ( e = f . exec ( a [ c ] ) ) ; ) d . push ( e [ 1 ] ) ; for ( e in d ) b . hasOwnProperty ( d [ e ] ) ||
( b [ d [ e ] ] = "" ) , f = new RegExp ( "{" + d [ e ] + "}" , "g" ) , console . log ( "replacing" , a [ c ] , f , b [ d [ e ] ] ) , a [ c ] = a [ c ] . replace ( f , b [ d [ e ] ] ) ; f = FormBuilder . regex . arr _out _val ; for ( d = [ ] ; null !== ( e = f . exec ( a [ c ] ) ) ; ) d . push ( e [ 1 ] ) ; for ( e in d ) b . hasOwnProperty ( d [ e ] ) || ( b [ d [ e ] ] = "" ) , f = new RegExp ( "{" + d [ e ] + "}" , "g" ) , a [ c ] = a [ c ] . replace ( f , b [ d [ e ] ] ) } } } for ( c in a ) FormBuilder . regex . pri _in _key . test ( c ) ? b [ c . substring ( 1 ) ] = a [ c ] : FormBuilder . regex . arr _in _key . test ( c ) && ( b [ c . substring ( 2 ) ] = 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 k in a [ c ] ) FormBuilder . replaceStatements ( a [ c ] [ k ] , b , g ) ; else a [ c ] instanceof Object && FormBuilder . replaceStatements ( a [ c ] , b , g ) ; return a } ; FormBuilder . buildString = function ( a ) { var b , g = "" ; for ( b in a ) a [ b ] instanceof refObject ? g += "" + a [ b ] . get ( ) : "undefined" != typeof a [ b ] ? g += "" + a [ b ] . toString ( ) : console . log ( a [ b ] , "cant be displayed" ) ; return g } ;