Preview.min.js 3.5 KB

1
  1. MWF.require("MWF.widget.Common",null,false);MWF.require("MWF.widget.Panel",null,false);MWF.xApplication.process.FormDesigner.Preview=MWF.FCPreview=new Class({Extends:MWF.widget.Common,Implements:[Options,Events],options:{style:"default",previewPath:COMMON.contentPath+"/preview.html",size:null,mode:"pc"},initialize:function(t,e){this.setOptions(e);var s=window.location.href;if(s.indexOf("debugger")!=-1)this.options.previewPath=COMMON.contentPath+"/preview.html?debugger";this.path="/x_component_process_FormDesigner/$Preview/";this.cssPath="/x_component_process_FormDesigner/$Preview/"+this.options.style+"/css.wcss";this._loadCss();this.form=t;this.data=t._getFormData?t._getFormData():t._getPageData()},load:function(){var t=this.getPanelPostion();this.createPreviewNodes();this.createPanel(t);this.setEvent();this.loadForm();this.addActions()},getPanelPostion:function(){var t=this.form.designer.node.getSize();var e=t.x*.7;var s=t.y*.8;if(this.options.size){e=this.options.size.x;s=this.options.size.y}var o=(t.y-s)/2*.8;var i=(t.x-e)/2;return{x:e,y:s,top:o,left:i}},createPreviewNodes:function(){this.node=new Element("div",{styles:this.css.contentNode});this.topActionAreaNode=new Element("div",{styles:this.css.topActionAreaNode}).inject(this.node);this.formFrameNode=new Element("iframe",{styles:this.css.formFrameNode}).inject(this.node);this.formJsonNode=new Element("div",{styles:this.css.formJsonNode}).inject(this.node)},addActions:function(){this.showJsonAction=new Element("div",{styles:this.css.actionButton,text:"show json"}).inject(this.topActionAreaNode);this.showJsonAction.addEvent("click",function(){this.showJson()}.bind(this));this.showFormAction=new Element("div",{styles:this.css.actionButton,text:"show form"}).inject(this.topActionAreaNode);this.showFormAction.setStyle("display","none");this.showFormAction.addEvent("click",function(){this.showForm()}.bind(this))},showForm:function(){this.formJsonNode.empty();this.formFrameNode.setStyle("display","block");this.formJsonNode.setStyle("display","none");this.showJsonAction.setStyle("display","block");this.showFormAction.setStyle("display","none")},showJson:function(){this.showJsonAction.setStyle("display","none");this.showFormAction.setStyle("display","block");this.formFrameNode.setStyle("display","none");this.formJsonNode.setStyle("display","block");var t=this.formFrameNode.contentWindow.layout;MWF.require("MWF.widget.JsonParse",function(){this.json=new MWF.widget.JsonParse(t.appForm.getData(),this.formJsonNode,null);this.json.load()}.bind(this))},createPanel:function(t){this.panel=new MWF.widget.Panel(this.node,{style:"form",title:this.data.json.name,width:t.x,height:t.y,top:t.top,left:t.left,isExpand:false,target:this.form.designer.node});this.panel.load()},setEvent:function(){this.setFormFrameSize();this.panel.addEvent("resize",this.setFormFrameSize.bind(this))},setFormFrameSize:function(){var t=this.panel.content.getSize();var e=this.topActionAreaNode.getSize();var s=t.y-e.y-8;var o=t.x-8;this.formFrameNode.setStyle("height",""+s+"px");this.formFrameNode.setStyle("width",""+o+"px");this.formJsonNode.setStyle("height",""+s+"px");this.formJsonNode.setStyle("width",""+o+"px")},loadForm:function(){this.formFrameNode.store("preview",this);this.formFrameNode.set("src",this.options.previewPath+"?mode="+this.options.mode)},loadFormData:function(t){MWF.getJSON("/x_desktop/res/preview/work.json",function(e){MWF.xDesktop.requireApp("process.Xform","Form",function(){this.appForm=new MWF.APPForm(t,this.data);this.appForm.app=this.form.designer;this.appForm.load()}.bind(this))}.bind(this))}});