meraproject/lib/js/bws/react/form/class/form.min.js

3 lines
4.3 KiB
JavaScript
Raw Normal View History

var Form,indexOf=[].indexOf;import Input from"./input.js";import autoBind from"react-autobind";export default Form=function(){class Form extends React.Component{constructor(t){var e,n,o;super(t),e=!0===t.ajaxFast,this.state={inputs:null!=t.inputs?t.inputs:t.inputs=[],values:null!=t.values?t.values:t.values=[],ajaxFast:e,ajaxInitData:null!=(n=t.ajaxInitData)?n:{},loading:e,controller:null!=(o=t.controller)?o:"",hideSubmitAndClose:!0===t.hideSubmitAndClose},autoBind(this),this.inputs={},this.form=null}componentDidMount(){var t,e,n,o;return o=this,({ajaxFast:t,controller:n,ajaxInitData:e}=this.state),t?API(n+"/getCardInfo/",{id:0,dataType:"JSON",init_data:e},function(t){return o.setState({loading:!1,inputs:t.form},o.checkRules)}):this.checkRules()}onCancel(){var t;return"function"==typeof(t=this.props).onCancel?t.onCancel():void 0}getValues(){var t,e;for(t in e={},this.inputs)e[t]=this.inputs[t].getValue();return e}onSubmitAndClose(t){var e,n;return null!=t&&t.preventDefault(),n=this.getValues(),"function"==typeof(e=this.props).onSubmitAndClose&&e.onSubmitAndClose({form:this.form,values:n}),!1}onSubmit(t){var e,n;return null!=t&&t.preventDefault(),n=this.getValues(),"function"==typeof(e=this.props).onSubmit&&e.onSubmit({form:this.form,values:n}),!1}onChange(){return this.checkRules(name)}onKeyUp(t){return this.checkRules(t,"onkeyup")}checkRule(){}doRuleActions(actions,reverse=!1){var action,input,name,results,x;for(name in results=[],actions)if(action=actions[name],input=this.inputs[name],null!=input&&void 0!==input){switch(console.log("action",action),action.action){case"show":reverse?input.hide():input.show();break;case"hide":reverse?input.show():input.hide()}console.log("typeof",typeof action.js_function),"string"==typeof action.js_function?(x=eval(action.js_function),console.log("XXXX",x),results.push(x({values:this.getValues(),inputs:this.inputs,form:this}))):results.push(void 0)}else results.push(void 0);return results}checkRules(t=null,e=null){var n,o,r,i,s,u,a;if(a=this.getValues(),void 0===this.rules)return null;for(o in n=this.rules,null!=t&&void 0!==t&&(n={},void 0!==this.rules[t]&&(n[t]=this.rules[t])),r=[],n)s=n[o],u=a[o],r.push(function(){var t,n,o;for(o=[],t=0,n=s.length;t<n;t++)if(i=s[t],null===e||i.operator===e)switch(i.operator){case"in":o.push(this.doRuleActions(i.actions,indexOf.call(i.value,u)<0));break;case"onkeyup":o.push(this.doRuleActions(i.actions));break;default:o.push(void 0)}return o}.call(this));return r}addInput(t,e,n,o){var r,i=this;return({hideSubmitAndClose:r}=this.state),React.createElement(Input,{key:t,data:e,value:o,name:n,ref:function(t){return i.inputs[n]=t},onSubmit:this.onSubmit,onSubmitAndClose:this.onSubmitAndClose,hideSubmitAndClose:r,onChange:this.onChange,onKeyUp:this.onKeyUp})}renderInput(t,e){var n,o,r,i,s,u,a,l,m;if(null===t)return null;if(l="",o=[],!1,t[Form.VIEW]===Form.TITLE)return null;if(t[Form.VIEW]===Form.RULES)return this.rules=t[Form.RULES],null;if(t[Form.VIEW]===Form.ROW){if(l=null!=(s=t[Form.ROW_CLASSES])?s:"",null!=t[Form.COLS])for(r in t[Form.COLS])null!==(n=t[Form.COLS][r])&&(n[Form.VIEW]===Form.TITLE?o.push(React.createElement("div",{class:"c"},React.createElement("div",{class:"h1"},n[Form.TITLE_TEXT]))):(void 0===(i=n[Form.KEY_VALUE])&&(i=n[Form.INPUT_OPT][Input.NAME]),m=this.state.values[i],o.push(this.addInput(r,n,i,m))))}else i=null!=(u=null!=(a=t.name)?a:t[Form.KEY_VALUE])?u:void 0,m=t.value,void 0===i&&(console.warn("В форме поле ввода без аттрибута name",t),i="input"+(new Date).getTime()),void 0===m&&(m=this.state.values[i]),1===t[Form.TYPE],o.push(this.addInput(e,t,i,m));return React.createElement("div",{className:"row2 "+l},o)}render(){var t,e,n=this;return({loading:e}=this.state),e?React.createElement("div",null,"Загрузка..."):(t=this.state.inputs.map(this.renderInput.bind(this)),React.createElement("form",{onSubmit:this.onSubmit,ref:function(t){return n.form=t}},t,React.createElement("div",{className:"res"})))}}return Form.VALUES=1,Form.INPUTS=2,Form.INPUT=3,Form.KEY_VALUE=4,Form.TYPE=5,Form.LABEL=6,Form.VIEW=7,For
//# sourceMappingURL=form.min.js.map