Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
META-INF.web.lib.js.bee.form.js Maven / Gradle / Ivy
var Form=function(i){var j=this;var f=this.$form=$(i);var h=(f.attr("method")||"get").toLowerCase();this.action=f.attr("action");this.enctype=f.attr("enctype");this.autocomplete=(f.attr("autocomplete")||"on").toLowerCase();this.auto=f.attr("auto");this.method=h=="delete"?$.del:h=="post"?$.post:h=="put"?$.put:$.get;this.params={};if(this.id=f.attr("id")){var g=Form[this.id];if(g){$.each(g,function(b,a){j[b]=a})}Form[this.id]=Form.items[this.id]=this;this.storekey=this.id+location.href.hashCode()}i.onsubmit=function(a){if(a.result===false){return false}j.submit();return false};if(Form.dialog&&!Form.dialog.call){Form.dialog.call=function(){f.trigger("submit")}}this.res=f.attr("res");this.resdatatype=f.attr("resdatatype")||"json"};Form.multipart="multipart/form-data";Form.items={};Form.dialog=function(){try{return top.dialog?top.dialog.get(window):null}catch(b){return null}}();Form.prototype={auto:true,params:null,data:null,storekey:null,autocomplete:null,recovery:function(){var c=this;if(!c.storekey){return}var d=localStorage.getItem(c.storekey);if(d){d=JSON.parse(d)}c.bind({data:d})},store:function(){var b=this;if(!b.storekey){return}b.$form.find("input,textarea,select").change(function(){var a=b.$form.serialize();$.each(a||{},function(f,e){if(!e||!e.trim()){delete a[f]}});b.$form.find(":input[autocomplete=off]").each(function(){delete a[this.name]});localStorage.setItem(b.storekey,JSON.stringify(a))})},clear:function(){var b=this;if(!b.storekey){return}localStorage.removeItem(b.storekey)},getUrl:function(d){var c=this;return(d||this.action).replace(/\${(.)*?}/g,function(a){return self[a.replace(/[\${}]+/g,"")]||""}).replace(/{(.)*?}/g,function(b){var a=b.replace(/[{}]+/g,"");return c.params[a]||$.getParam(a)||(top.data||{})[a]||b}).replace(/\[.*?{.*?}\]/g,"").replace(/[\[\]]/g,"").replace(/{.*?}/g,"")},init:function(){if(this.autocomplete=="on"){this.recovery()}this.initValues();if(this.res&&this.auto!="false"){this.get()}if(this.autocomplete=="on"){this.store()}},initValues:function(){var b=this;b.params=$.getParams();$.each(b.params||{},function(a,d){b._setValue(a,d)})},after:function(){if(Form.dialog){Form.dialog.options.win.location.reload();Form.dialog.remove()}},going:function(){var b=this;b.method(b.getUrl(),b.data,function(a){if(a.message){alert(a.message);return}b.clear();b.after(a)})},before:function(){},changeResData:function(b){},binded:function(b){},get:function(){var b=this;b.$form[0].reset();$.get(b.getUrl(b.res),function(a){b.bind(a)},b.resdatatype)},bind:function(c){var d=this;d.changeResData(c);$.each(c.data||c.result||{},function(b,a){d._depthbind(b,a)});d.binded(c)},_depthbind:function(e,f){var d=this;if(typeof(f)=="object"){$.each(f,function(a,b){d._depthbind(e+"."+a,b)})}else{d._setValue(e,f)}},submit:function(){var d=this;if(d.enctype==Form.multipart){d.data=new FormData(d.$form[0])}else{d.data=d.$form.serialize();$.extend(d.data,d.params)}d._merge0bParams();var c=d.before(d.data);if(c===false){return}if(typeof(c)=="object"){d.data=c}d.going()},_merge0bParams:function(){var c=this;var d={};$(":checkbox[dtype='0b']",c.$form).each(function(){d[this.name]=this.name});$.each(d,function(b,f){var a=c.data[f];if(!a){return}a=a.split(",");c.data[f]=0;$.each(a,function(e,h){c.data[f]+=parseInt(h)||0})})},_split0bData:function(h){if(!typeof(h)=="number"){return h}var f=[];for(var e=0;;e++){var g=Math.pow(2,e);if(g>h){break}if((h&g)>0){f.push(g)}}return f},_setValue:function(o,l){var m=this;var k=m.$form.find(":input[name='"+o+"']");var n=m.$form.find(":input[name='"+o+"']").attr("type");if(n=="checkbox"){if(k.size()==1){k.attr("defval",l)}if(k.attr("dtype")=="0b"){l=m._split0bData(l)}k.val(typeof(l)=="string"?l.split(","):typeof(l)=="number"?[l]:l)}else{if(n=="radio"){if(k.size()==1){k.attr("defval",l)}k.val([l])}else{var j=k.attr("datatype"),p=k.attr("formatter");if(j=="date"){l=Util.formatDate(l,p)}else{if(j=="number"){l=Util.formatNumber(l,p)}else{if(j=="json"){var i=l;if(typeof(l)=="string"){i=JSON.parse(l)}l=JSON.stringify(i,null,"\t")}}}k.val(l)}}m.$form.find("img[name='"+o+"']").attr("src",l);m.$form.find("[name\\:='"+o+"']").html(l)}};Form.method=function(b){$.each(b,function(a,d){Form[a]=d})};$(document).ready(function(){$("form.submit").each(function(){var b=new Form(this);b.init()})});