From 2763a32e9199cd0134aa83fa6afd4f06b99820ee Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 19 Sep 2016 08:37:35 +0200 Subject: [PATCH] =?UTF-8?q?Remplacement=20avec=20r=C3=A9f=C3=A9rence=20fon?= =?UTF-8?q?ctionne=20pour=20les=20PRIMARY=20variables,=20=C3=A0=20tester?= =?UTF-8?q?=20pour=20le=20reste,=20m=C3=A9thodes=20=C3=A0=20part=20pour=20?= =?UTF-8?q?'replaceArray'=20et=20'replacePrimary',=20=C3=A0=20faire=20pour?= =?UTF-8?q?=20'replaceRegex'=20et=20'replaceArrayVal'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/form-builder/behaviour-min.js | 6 +- doc/form-builder/behaviour.js | 3 + js/lib/form-builder-min.js | 20 +- js/lib/form-builder.js | 311 ++++++++++++++++++++---------- js/lib/form-builder/main-min.js | 4 +- js/lib/form-builder/main.js | 4 +- 6 files changed, 231 insertions(+), 117 deletions(-) diff --git a/doc/form-builder/behaviour-min.js b/doc/form-builder/behaviour-min.js index 31fdecc..a45f47c 100644 --- a/doc/form-builder/behaviour-min.js +++ b/doc/form-builder/behaviour-min.js @@ -1,3 +1,3 @@ -var ElementObject={node:"node name defined earlier",attributes:{attr_name_1:"attr_value_1",attr_name_2:"attr_value_2"},children:[ElementObject],next_nodes:[ElementObject],prev_nodes:[ElementObject],text:"some text to be the innerHTML",repeat:"number to repeat ElementObject || {{array}} to repeat ElementObject",node_type:"html tag name",listeners:[EventListener]},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"}]},"custom-select":{node:"span",attributes:{"class":"select-container nobold"},children:[{node:"select",attributes:{"data-name":"{name}"},children:[{node:"option",attribute:{value:"{options.value}"},text:"{options.value}",repeat:"{{options}}"}]}],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:"number",$value:"{number}",$placeholder:"{Num\u00e9ro de t\u00e9l\u00e9phone}"},{node:"custom-select",$name:"existing",$$options:"{{options}}"}]}; +var reference_table={"2fd8":!0},ElementObject={node:"node name defined earlier",attributes:{attr_name_1:"attr_value_1",attr_name_2:"attr_value_2"},children:[ElementObject],next_nodes:[ElementObject],prev_nodes:[ElementObject],text:"some text to be the innerHTML",repeat:"number to repeat ElementObject || {{array}} to repeat ElementObject",node_type:"html tag name",listeners:[EventListener]},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"}]},"custom-select":{node:"span",attributes:{"class":"select-container nobold"},children:[{node:"select",attributes:{"data-name":"{name}"},children:[{node:"option",attribute:{value:"{options.value}"},text:"{options.value}",repeat:"{{options}}"}]}],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:"number",$value:"{number}",$placeholder:"{Num\u00e9ro de t\u00e9l\u00e9phone}"},{node:"custom-select",$name:"existing",$$options:"{{options}}"}]}; diff --git a/doc/form-builder/behaviour.js b/doc/form-builder/behaviour.js index 72d5797..bfc3249 100644 --- a/doc/form-builder/behaviour.js +++ b/doc/form-builder/behaviour.js @@ -77,6 +77,9 @@ // variables are transformed to references, so they can be updated easily without rebuilding the whole model // when the model is built the first time, all the passed variables are transformed to references // and they are spread by references +var reference_table = { + '2fd8': true +}; //////////////////////// // LANGAGE DEFINITION // diff --git a/js/lib/form-builder-min.js b/js/lib/form-builder-min.js index 5e9d333..e60933f 100644 --- a/js/lib/form-builder-min.js +++ b/js/lib/form-builder-min.js @@ -1,9 +1,11 @@ -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(" "); -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;cc;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=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"),console.log(f),a[c]=a[c].replace(f,b[d[e]]);if(!(0e;e++)matches["$"+e]=RegExp["$"+e];return{def:b[d],scope:matches}}return{}}; +FormBuilder.replaceStatements=function(a,b,d,e){a=a instanceof Object?a:{};b=b instanceof Object?JSON.parse(JSON.stringify(b)):{};var c,h,f,g,n,k,l;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,d),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];for(c in a)if("string"==typeof a[c])if(a[c]= +[a[c]],f=FormBuilder.replaceStatementsArray(a[c][0],b),!1!==f)a[c][0]=f;else{h=FormBuilder.regex.reg_out_val;g=-1;for(k=[];null!==(f=h.exec(a[c][0]))&&!(g>=h.lastIndex);)g=h.lastIndex,k.push(f[1]);for(f in k)b.hasOwnProperty(k[f])||(b[k[f]]=""),h=new RegExp("{\\$"+k[f][1]+"}","g"),a[c][0]=a[c][0].replace(h,b[k[f]]);if(!(0 Objet dans lequel remplacer les valeurs * @scope Ensemble des variables permettant le remplacement * @definitions Définitions des éléments +* @ref_table Table des références * * @return replaced Objet avec les remplacements effectués * */ -FormBuilder.replaceStatements = function(object, scope, definitions){ +FormBuilder.replaceStatements = function(object, scope, definitions, ref_table){ /* [0] Initialisation ==================================================================*/ /* (1) Paramètres */ @@ -304,7 +309,8 @@ FormBuilder.replaceStatements = function(object, scope, definitions){ scope = (scope instanceof Object) ? JSON.parse(JSON.stringify(scope)) : {}; /* (2) Variables */ - var key, r, tmp, m, found, lasti; + var key, r, tmp, m, found, lasti, s, parts; + var m_arr, m_reg, m_pri, m_aval; /* (3) On récupère le scope s'il est dans l'attribut 'scope' */ if( object.hasOwnProperty('scope') && object.scope instanceof Object ) @@ -335,7 +341,6 @@ FormBuilder.replaceStatements = function(object, scope, definitions){ } - object.received = scope; /* [2] On remplace les valeurs ==================================================================*/ @@ -345,34 +350,21 @@ FormBuilder.replaceStatements = function(object, scope, definitions){ ==================================================================*/ if( typeof object[key] == 'string' ){ + // On transforme en tableau + object[key] = [object[key]]; + /* (2.1) On cherche tous les TABLEAUX à remplacer ---------------------------------------------------------*/ - /* (1.1) On récupère les remplacements de TABLEAUX */ - m = null, r = FormBuilder.regex.arr_out_set; - var m_arr = []; - - /* (1.2) Si ça match */ - if( m = r.exec(object[key]) ) - m_arr.push( m[1] ); - - /* (1.3) Pour chaque match */ - for( m in m_arr ){ - - // {1} Si la var n'est pas dans le scope // - if( !scope.hasOwnProperty(m_arr[m]) ) - scope[m_arr[m]] = []; // on met un tableau vide - - // {2} on attribue le tableau // - object[key] = scope[m_arr[m]]; - - // console.log('arr', m_arr[m], scope[m_arr[m]]); + /* (1) On récupère le remplacement */ + m_arr = FormBuilder.replaceStatementsArray(object[key][0], scope); + /* (2) Si on a remplacé, on remplace, et on passe à la clé suivante */ + if( m_arr !== false ){ + object[key][0] = m_arr; + continue; } - /* (1.4) Si on a trouvé qqch, on passe à la clé suivante */ - if( m_arr.length > 0 ) - continue; /* (2.2) On cherche toutes les variables REGEX à remplacer @@ -380,11 +372,11 @@ FormBuilder.replaceStatements = function(object, scope, definitions){ /* (1.1) On récupère les remplacements REGEX */ m = null, r = FormBuilder.regex.reg_out_val, lasti = -1; - var m_reg = []; + m_reg = []; /* (1.2) Tant que ça match */ var max = 10; - while( (m=r.exec(object[key])) !== null && max > 0 ){ + while( (m=r.exec(object[key][0])) !== null && max > 0 ){ // si on boucle, on sort if( lasti >= r.lastIndex ) break; lasti = r.lastIndex; @@ -400,7 +392,7 @@ FormBuilder.replaceStatements = function(object, scope, definitions){ // {2} on remplace toutes les occurences par la valeur // tmp = new RegExp( "{\\$"+m_reg[m][1]+"}", 'g' ); - object[key] = object[key].replace(tmp, scope[m_reg[m]]); + object[key][0] = object[key][0].replace(tmp, scope[m_reg[m]]); } @@ -411,61 +403,67 @@ FormBuilder.replaceStatements = function(object, scope, definitions){ /* (2.3) On cherche toutes les variables PRIMITIVES à remplacer ---------------------------------------------------------*/ - /* (1.1) On récupère les remplacements PRIMITIFS */ - m = null, r = FormBuilder.regex.pri_out_val; - var m_pri = []; - - /* (1.2) Tant que ça match */ - while( (m=r.exec(object[key])) !== null ) - m_pri.push( m[1] ); - - /* (1.3) Pour chaque match */ - for( m in m_pri ){ - - // {1} Si la var n'est pas dans le scope // - if( !scope.hasOwnProperty(m_pri[m]) ) - scope[m_pri[m]] = ''; // on met une chaine vide - - // {2} on remplace toutes les occurences par la valeur // - tmp = new RegExp( "{"+m_pri[m]+"}", 'g' ); - console.log('replacing', object[key], tmp, scope[m_pri[m]]); - object[key] = object[key].replace(tmp, scope[m_pri[m]]); - - } - - /* (1.4) Si on a trouvé qqch, on passe à la clé suivante */ - // if( m_pri.length > 0 ) - // continue; + /* (1) On récupère les remplacements */ + object[key] = FormBuilder.replaceStatementsPrimary(object[key], scope); /* (2.4) On cherche toutes les valeurs de TABLEAUX à remplacer ---------------------------------------------------------*/ /* (1.1) On récupère les remplacements de valeurs de TABLEAUX */ - m = null, r = FormBuilder.regex.arr_out_val; - var m_aval = []; + r = FormBuilder.regex.arr_out_val; - /* (1.2) Tant que ça match */ - while( (m=r.exec(object[key])) !== null ) - m_aval.push( m[1] ); + /* (1.2) Pour chaque partie de la chaine */ + for( s in object[key] ){ + // bugfix + if( object[key][s] == null ) + continue; - /* (1.3) Pour chaque match */ - for( m in m_aval ){ //TODO: implémenter l'ajout des items d'un tableau au scope lors d'un "repeat" - // {1} Si la var n'est pas dans le scope // - if( !scope.hasOwnProperty(m_aval[m]) ) - scope[m_aval[m]] = ''; // on met une chaine vide + m = null, + m_aval = []; - // {2} on remplace toutes les occurences par la valeur // - tmp = new RegExp( "{"+m_aval[m]+"}", 'g' ); - object[key] = object[key].replace(tmp, scope[m_aval[m]]); + /* (1.3) Tant que ça match */ + while( (m=r.exec(object[key][s])) !== null ) + m_aval.push( m ); + + /* (1.4) Pour chaque match */ + lasti = 0; + parts = []; + + for( m in m_aval ){ + + // {1} On met la chaine d'avant le match // + if( lasti > 0 || m_aval[m].index > 0 ) + parts.push( object[key][s].substr(lasti, m_aval[m].index) ); + + // {2} Si la var n'est pas dans le scope // + if( !scope.hasOwnProperty(m_aval[m][1]) ) + scope[m_aval[m][1]] = ''; // on met une chaine vide + + // {3} On met le match // + parts.push( scope[m_aval[m][1]] ); + + // {4} On met à jour l'index de fin pour la suite // + lasti = m_aval[m].index + m_aval[m][0].length; + + + // // {2} [OLD]on remplace toutes les occurences par la valeur // + // tmp = new RegExp( "{"+m_pri[m]+"}", 'g' ); + // object[key][s] = object[key][s].replace(tmp, scope[m_pri[m]]); + } + + // {5} On ajoute la partie après le match // + if( lasti < object[key][s].length ) + parts.push( object[key][s].substr(lasti, object[key][s].length) ); + + + /* (1.5) Si on l'attribue */ + if( m_aval.length > 0 ) + object[key] = object[key].slice(0, s).concat(parts).concat(object[key].slice(s+1)); } - /* (1.4) Si on a trouvé qqch, on passe à la clé suivante */ - // if( m_aval.length > 0 ) - // continue; - } @@ -479,12 +477,12 @@ FormBuilder.replaceStatements = function(object, scope, definitions){ /* (1) Ajout des variables de type '$nomVar' ---------------------------------------------------------*/ if( FormBuilder.regex.pri_in_key.test(key) ) - scope[ key.substring(1) ] = object[key]; + scope[ key.substring(1) ] = ref( ref_table, object[key] ); /* (2) Ajout des tableaux de type '$$nomArr' ---------------------------------------------------------*/ else if( FormBuilder.regex.arr_in_key.test(key) ) - scope[ key.substring(2) ] = object[key]; + scope[ key.substring(2) ] = ref( ref_table, object[key] ); } @@ -503,13 +501,13 @@ FormBuilder.replaceStatements = function(object, scope, definitions){ /* (1) Si c'est un tableau, on lance récursivement pour chaque item */ if( object[key] instanceof Array ) for( var i in object[key] ) - FormBuilder.replaceStatements(object[key][i], scope, definitions); + FormBuilder.replaceStatements(object[key][i], scope, definitions, ref_table); // console.log(object.node, key+'['+i+']'); /* (2) Si c'est un objet, on lance récursivement */ else if( object[key] instanceof Object ) - FormBuilder.replaceStatements(object[key], scope, definitions); + FormBuilder.replaceStatements(object[key], scope, definitions, ref_table); // console.log(object.node, key); @@ -523,38 +521,147 @@ FormBuilder.replaceStatements = function(object, scope, definitions){ }; +/* REMPLACE UN TABLEAU SOUS LA FORME "{{arrayName}}" par sa référence +* +* @statement String contenant la chaine +* @scope Objet contenant le scope +* +* @return newVal Retourne la nouvelle (ref) valeur ou FALSE si rien n'a été fais +* +*/ +FormBuilder.replaceStatementsArray = function(statement, scope){ + /* (1) On initialise les variables */ + var match = null; + var regex = FormBuilder.regex.arr_out_set; + + /* (2) On exécute la regex */ + match = regex.exec(statement); + + /* (3) Si ça match pas, on retourne FALSE */ + if( match === null ) + return false; + + /* (4) Sinon, si le tableau n'est pas dans le scope, on l'initialise */ + if( !scope.hasOwnProperty(match[1]) ) + scope[match[1]] = []; // on met un tableau vide + + /* (5) On remplace le 'statement' par le tableau */ + return scope[match[1]]; + +}; + + +/* REMPLACE LES VARIABLE SOUS LA FORME "{varName}" par leur référence +* +* @statements Tableau contenant les parties de la chaine +* @scope Objet contenant le scope +* +* @return splitVal Tableau contenant les parties de la chaine (références + chaine) +* +*/ +FormBuilder.replaceStatementsPrimary = function(statements, scope){ + /* [1] Initialisation + =========================================================*/ + var regex = FormBuilder.regex.pri_out_val; + var match = null; + var matches = []; + var lasti, parts, p, i; + + + /* [2] Pour chaque partie de la chaine + =========================================================*/ + for( p = 0 ; p < statements.length ; p++ ){ + + /* (1) Initialisation */ + m = null, matches = [], + lasti = 0, parts = []; + + /* (2) Tant que ça match, on récupère les infos du match */ + while( (match=regex.exec(statements[p])) !== null ) + matches.push( match ); + + + /* [3] Pour chaque match + =========================================================*/ + for( i = 0 ; i < matches.length ; i++ ){ + + /* (1) On met la chaine d'avant le match (si existe) */ + if( lasti > 0 || matches[i].index > 0 ) + parts.push( statements[p].substr(lasti, matches[i].index) ); + + /* (2) Si la var n'est pas dans le scope, on l'initialise vide */ + if( !scope.hasOwnProperty(matches[i][1]) ) + scope[matches[i][1]] = ''; // on met une chaine vide + + /* (3) On insère la valeur du scope */ + parts.push( scope[matches[i][1]] ); + + /* (4) On met à jour l'index de fin pour la suite */ + lasti = matches[i].index + matches[i][0].length; + + } + + /* (5) On ajoute la partie après le match */ + if( lasti < statements[p].length ) + parts.push( statements[p].substr(lasti, statements[p].length) ); + + + /* [4] Si on a remplacé qqch, on remplace statements[p] par sa décomposition + =========================================================*/ + if( matches.length > 0 ) + statements = statements.slice(0, p).concat(parts).concat(statements.slice(p+1)); + + } + + + /* [5] On retourne la chaine modifiée (ou non) + =========================================================*/ + return statements; +}; + /* CONSTRUIT UNE CHAINE A PARTIR DE SES PARTIES (VARIABLES OU TEXTE BRUT) * +* @ref_table Objet contenant les références * @parts Tableau contenant les parties * * @return built Chaine recomposée * */ -FormBuilder.buildString = function(parts){ +FormBuilder.buildString = function(ref_table, parts){ /* [0] Initialisation =========================================================*/ var i, built = ""; - /* [1] On remplace par les valeurs + + /* [1] Si c'est un tableau, on le retourne + =========================================================*/ + if( typeof parts == 'string' && FormBuilder.regex.ref_pri.test(parts) ) + return ref_table[parts]; + + + /* [2] Sinon, on remplace par les valeurs =========================================================*/ for( i in parts ){ - /* (1) Si , on ajoute la valeur */ - if( parts[i] instanceof refObject ) - built += '' + parts[i].get(); + /* (1) Si , on ajoute la valeur (si elle existe) */ + if( FormBuilder.regex.ref_pri.test(parts[i]) && ref_table.hasOwnProperty(parts[i]) ){ + + // si le résultat est un tableau, on lance récursivement + if( ref_table[parts[i]] instanceof Array ) + built += ''+ FormBuilder.buildString(ref_table, ref_table[parts[i]]); + + // sinon + else + built += '' + ref_table[parts[i]]; /* (2) Sinon, on ajoute simplement */ - else if( typeof parts[i] != 'undefined' ) + }else built += '' + parts[i].toString(); - /* (3) Erreur */ - else - console.log(parts[i], 'cant be displayed'); - } - /* [2] On retourne le résultat + /* [3] On retourne le résultat =========================================================*/ return built; diff --git a/js/lib/form-builder/main-min.js b/js/lib/form-builder/main-min.js index a7ebcc9..100c5e3 100644 --- a/js/lib/form-builder/main-min.js +++ b/js/lib/form-builder/main-min.js @@ -1,4 +1,4 @@ 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"}]},"custom-select":{node:"span",attributes:{"class":"select-container nobold"},children:[{node:"select",attributes:{"data-name":"{name}"},children:[{node:"option", -attribute:{value:"{options.value}"},text:"{options.value}",repeat:"{{options}}"}]}],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.hidden",$name:"total",$value:"{countcall} calls + {countsms} sms to {number}"}, -{node:"input.text",$name:"number",$value:"{number}"},{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"]});console.log(fb.built_form); +attribute:{value:"{options.value}"},text:"{options.value}",repeat:"{{options}}"}]}],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.hidden",$name:"total",$value:"xx{countcall} calls + {countsms} sms to {number}xx"}, +{node:"input.text",$name:"number",$value:"{number}"},{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"]});console.log(fb.built_form);var str=function(a){return FormBuilder.buildString(fb.ref_table,a)}; diff --git a/js/lib/form-builder/main.js b/js/lib/form-builder/main.js index 9ba359f..55f4215 100644 --- a/js/lib/form-builder/main.js +++ b/js/lib/form-builder/main.js @@ -58,7 +58,7 @@ var form = { { node: 'input.hidden', $name: 'sms', $value: '{sms}' }, { node: 'input.hidden', $name: 'countcall', $value: '{countcall}' }, { node: 'input.hidden', $name: 'countsms', $value: '{countsms}' }, - { node: 'input.hidden', $name: 'total', $value: '{countcall} calls + {countsms} sms to {number}' }, + { node: 'input.hidden', $name: 'total', $value: 'xx{countcall} calls + {countsms} sms to {number}xx' }, { node: 'input.text', $name: 'number', $value: '{number}' }, @@ -85,3 +85,5 @@ fb.build({ options: ['a', 'b', 'c', 'd'] }); console.log(fb.built_form); + +var str = function(attr){ return FormBuilder.buildString(fb.ref_table, attr); };