NxTIC/subDir/public_html/js/lib/form-builder/main-min.js

6 lines
2.5 KiB
JavaScript

for(var default_definition={input:{node_type:"input",_value:"{value}"},"/^h([1-6])$/":{node_type:"h{$1}"},br:{node_type:"br"},option:{node_type:"option"},select:{node_type:"select"},span:{node_type:"span"},"/^br([0-9]+)$/":{node:"br",repeat:{n:"{$1}",id:"brs"}}},custom_definition={"/^input.([a-z]+)$/":{node:"input",attributes:{type:"{$1}","data-name":"{name}",value:"{value}",placeholder:"{placeholder}"},listeners:{click:"{click_listener()}"}},"custom-select":{node:"span",attributes:{"class":"select-container nobold"},
children:[{node:"select",attributes:{"data-name":"{name}"},children:[{node:"option",attributes:{value:"{options.index}"},text:"{options.value}",browse:{array:"{options[]}",funcs:{"options.value":"{getoptval()}","options.index":"{getoptid()}"}}}],_selected:"{selected}",listeners:{change:"{listener()}"}}],next_nodes:[{node_type:"text",text:"    ou    "}]}},forms={contact:{node:"h4",attributes:{"data-icon":"o","class":"new-contact color2"},children:[{node:"input.hidden",
$name:"uid",$value:"{contacts.uid}"},{node:"input.hidden",$name:"call",$value:"{contacts.call}"},{node:"input.hidden",$name:"sms",$value:"{contacts.sms}"},{node:"input.hidden",$name:"countcall",$value:"{contacts.count_call}"},{node:"input.hidden",$name:"countsms",$value:"{contacts.count_sms}"},{node:"input.text",$name:"number",$value:"{contacts.number}"},{node:"custom-select",$name:"existing",$options:"{contacts.existing}",$selected:"{contacts.friend}"},{node:"input.text",$name:"username",$placeholder:"{username_ph}",
$value:"{contacts.username}"},{node:"input.submit",$value:"Enregistrer",attributes:{"class":"primary sub-number"}}],browse:{array:"{contacts[]}",funcs:{"contacts.existing":"{cexisting()}"}}}},myForm={node:"contact"},contactData=[],c=0;10>c;c++)contactData[c]={uid:c,call:Math.floor(10*Math.random()),sms:10+Math.floor(10*Math.random()),number:"05 06 07 08 0"+Math.floor(10*Math.random()),username:(1048576+Math.floor(15728639*Math.random())).toString(16),existing:{".":"Choisir un contact existant",1:String.fromCharCode(65+
(c+0)%26),2:String.fromCharCode(65+(c+1)%26),3:String.fromCharCode(65+(c+2)%26)},friend:1+Math.floor(4*Math.random()),count_call:100+Math.floor(10*Math.random()),count_sms:1E3+Math.floor(10*Math.random())};var fb=new FormBuilder(myForm);fb.add_definition(default_definition);fb.add_definition(custom_definition);fb.add_definition(forms);fb.build({contacts:contactData,username_ph:"Pseudo",cexisting:function(b,a){return a.existing},getoptid:function(b,a){return b},getoptval:function(b,a){return a}});