| 1 |
- MWF.xApplication.process=MWF.xApplication.process||{};MWF.APPFD=MWF.xApplication.process.FormDesigner=MWF.xApplication.process.FormDesigner||{};MWF.xApplication.cms.FormDesigner=MWF.xApplication.cms.FormDesigner||{};MWF.CMSFD=MWF.xApplication.cms.FormDesigner;MWF.CMSFD.options={multitask:true,executable:false};MWF.xDesktop.requireApp("cms.FormDesigner","Module.Package",null,false);MWF.xApplication.cms.FormDesigner.Main=new Class({Extends:MWF.xApplication.Common.Main,Implements:[Options,Events],options:{style:"default",template:"template.json",templateId:"",name:"cms.FormDesigner",icon:"icon.png",title:MWF.CMSFD.LP.title,appTitle:MWF.CMSFD.LP.title,id:"",actions:null,category:null,processData:null},onQueryLoad:function(){this.shortcut=true;if(this.status){this.options.id=this.status.id}if(!this.options.id){this.options.desktopReload=false;this.options.title=this.options.title+"-"+MWF.CMSFD.LP.newForm}this.actions=MWF.Actions.get("x_cms_assemble_control");this.lp=MWF.xApplication.cms.FormDesigner.LP},loadApplication:function(t){this.createNode();if(!this.options.isRefresh){this.maxSize(function(){this.openForm()}.bind(this))}else{this.openForm()}this.addKeyboardEvents();if(t)t()},addKeyboardEvents:function(){this.addEvent("copy",function(){this.copyModule()}.bind(this));this.addEvent("paste",function(){this.pasteModule()}.bind(this));this.addEvent("cut",function(){this.cutModule()}.bind(this));this.addEvent("keySave",function(t){this.keySave(t)}.bind(this));this.addEvent("keyDelete",function(t){this.keyDelete(t)}.bind(this))},keySave:function(t){if(this.shortcut){if(this.form)this.saveForm();t.preventDefault()}},keyDelete:function(t){if(this.form){if(this.shortcut){if(this.form.currentSelectedModule){var e=this.form.currentSelectedModule;if(e.moduleType!="form"&&e.moduleName.indexOf("$")==-1){e["delete"](e.node)}}}}},copyModule:function(){if(this.shortcut){if(this.form){if(this.form.currentSelectedModule){var t=this.form.currentSelectedModule;if(t.moduleType!="form"&&t.moduleName.indexOf("$")==-1){var e=t.getHtml();var o=t.getJson();MWF.clipboard.data={type:"form",data:{html:e,json:o}}}else{MWF.clipboard.data=null}}}}},cutModule:function(){if(this.shortcut){if(this.form){if(this.form.currentSelectedModule){var t=this.form.currentSelectedModule;if(t.moduleType!="form"&&t.moduleName.indexOf("$")==-1){this.copyModule();t.destroy();t.form.selected()}}}}},pasteModule:function(){if(this.shortcut){if(this.form){if(MWF.clipboard.data){if(MWF.clipboard.data.type=="form"){var t=MWF.clipboard.data.data.html;var e=Object.clone(MWF.clipboard.data.data.json);var r=Element("div",{styles:{display:"none"},html:t}).inject(this.content);Object.each(e,function(t){var e=t.id;var o=t.id;var i=1;while(this.form.json.moduleList[o]){o=e+"_"+i;i++}if(e!=o){t.id=o;var s=r.getElementById(e);if(s)s.set("id",o)}this.form.json.moduleList[t.id]=t}.bind(this));delete e;var o=this.form.node;var i="bottom";var s=this.form;if(this.form.currentSelectedModule){var n=this.form.currentSelectedModule;o=n.node;s=n;if(n.moduleType!="container"&&n.moduleType!="form"){i="after";s=n.parentContainer}}var l=r.getFirst();while(l){l.inject(o,i);var a=this.form.getDomjson(l);module=this.form.loadModule(a,l,s);module._setEditStyle_custom("id");module.selected();l=r.getFirst()}r.destroy();delete r}}}}},createNode:function(){this.content.setStyle("overflow","hidden");this.node=new Element("div",{styles:{width:"100%",height:"100%",overflow:"hidden"}}).inject(this.content)},openForm:function(){this.initOptions();this.loadNodes();this.loadToolbar();this.loadFormNode();this.loadProperty();this.loadTools();this.resizeNode();this.addEvent("resize",this.resizeNode.bind(this));this.loadForm();if(this.toolbarContentNode){this.setScrollBar(this.toolbarContentNode,null,{V:{x:0,y:0},H:{x:0,y:0}});MWF.require("MWF.widget.ScrollBar",function(){new MWF.widget.ScrollBar(this.propertyDomScrollArea,{style:"default",where:"before",distance:30,friction:4,indent:false,axis:{x:false,y:true}})}.bind(this))}},initOptions:function(){this.toolsData=null;this.toolbarMode="all";this.tools=[];this.toolbarDecrease=0;this.designNode=null;this.form=null},loadNodes:function(){this.toolbarNode=new Element("div",{styles:this.css.toolbarNode,events:{selectstart:function(t){t.preventDefault()}}}).inject(this.node);this.propertyNode=new Element("div",{styles:this.css.propertyNode}).inject(this.node);this.formNode=new Element("div",{styles:this.css.formNode}).inject(this.node);if(this.options.style=="bottom")this.propertyNode.inject(this.formNode,"after")},loadToolbar:function(){this.toolbarTitleNode=new Element("div",{styles:this.css.toolbarTitleNode,text:MWF.APPFD.LP.tools}).inject(this.toolbarNode);this.toolbarTitleActionNode=new Element("div",{styles:this.css.toolbarTitleActionNode,events:{click:function(t){this.switchToolbarMode()}.bind(this)}}).inject(this.toolbarNode);this.toolbarContentNode=new Element("div",{styles:this.css.toolbarContentNode,events:{selectstart:function(t){t.preventDefault();t.stopPropagation()}}}).inject(this.toolbarNode)},switchToolbarMode:function(){if(this.toolbarMode=="all"){var t=this.toolbarNode.getSize();this.toolbarDecrease=t.x.toFloat()-60;this.tools.each(function(t){t.getLast().setStyle("display","none")});this.toolbarTitleNode.set("text","");this.toolbarNode.setStyle("width","60px");var e=this.formNode.getStyle("margin-left").toFloat();e=e-this.toolbarDecrease;this.formNode.setStyle("margin-left",""+e+"px");this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNodeRight);this.toolbarMode="simple"}else{sizeX=60+this.toolbarDecrease;var e=this.formNode.getStyle("margin-left").toFloat();e=e+this.toolbarDecrease;this.toolbarNode.setStyle("width",""+sizeX+"px");this.formNode.setStyle("margin-left",""+e+"px");this.tools.each(function(t){t.getLast().setStyle("display","block")});this.toolbarTitleNode.set("text",MWF.APPFD.LP.tools);this.toolbarTitleActionNode.setStyles(this.css.toolbarTitleActionNode);this.toolbarMode="all"}},loadFormNode:function(){this.formToolbarNode=new Element("div",{styles:this.css.formToolbarNode}).inject(this.formNode);this.loadFormToolbar();this.formContentNode=new Element("div",{styles:this.css.formContentNode}).inject(this.formNode);this.loadFormContent(function(){if(this.designDcoument)this.designDcoument.body.setStyles(this.css.designBody);if(this.designNode)this.designNode.setStyles(this.css.designNode)}.bind(this))},loaddesignerActionNode:function(){this.pcDesignerActionNode=this.formToolbarNode.getElement("#MWFFormPCDesignerAction");this.mobileDesignerActionNode=this.formToolbarNode.getElement("#MWFFormMobileDesignerAction");this.currentDesignerMode="PC";this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);var t=new Element("div",{styles:this.css.designerActionPcIconNode}).inject(this.pcDesignerActionNode);t=new Element("div",{styles:this.css.designerActionMobileIconNode}).inject(this.mobileDesignerActionNode);var e=new Element("div",{styles:this.css.designerActiontextNode,text:"PC"}).inject(this.pcDesignerActionNode);e=new Element("div",{styles:this.css.designerActiontextNode,text:"Mobile"}).inject(this.mobileDesignerActionNode);this.pcDesignerActionNode.addEvent("click",function(){if(this.currentDesignerMode!="PC"){this.changeDesignerModeToPC()}}.bind(this));this.mobileDesignerActionNode.addEvent("click",function(){if(this.currentDesignerMode=="PC"){this.changeDesignerModeToMobile()}}.bind(this))},changeDesignerModeToPC:function(){this.pcDesignerActionNode.setStyles(this.css.designerActionNode_current);this.mobileDesignerActionNode.setStyles(this.css.designerActionNode);this.designMobileNode.setStyle("display","none");this.designNode.setStyle("display","block");if(this.form.currentSelectedModule){if(this.form.currentSelectedModule==this){return true}else{this.form.currentSelectedModule.unSelected()}}if(this.form.propertyMultiTd){this.form.propertyMultiTd.hide();this.form.propertyMultiTd=null}this.form.unSelectedMulti();this.form=this.pcForm;this.currentDesignerMode="PC"},changeDesignerModeToMobile:function(){this.pcDesignerActionNode.setStyles(this.css.designerActionNode);this.mobileDesignerActionNode.setStyles(this.css.designerActionNode_current);this.designMobileNode.setStyle("display","block");this.designNode.setStyle("display","none");if(this.form.currentSelectedModule){if(this.form.currentSelectedModule==this){return true}else{this.form.currentSelectedModule.unSelected()}}if(this.form.propertyMultiTd){this.form.propertyMultiTd.hide();this.form.propertyMultiTd=null}this.form.unSelectedMulti();if(!this.mobileForm){this.mobileForm=new MWF.CMSFCForm(this,this.designMobileNode,{mode:"Mobile"});this.mobileForm.load(this.formMobileData)}this.form=this.mobileForm;this.currentDesignerMode="Mobile"},loadFormToolbar:function(o){this.getFormToolbarHTML(function(t){var e=t.getElements("span");e.each(function(t,e){var o=t.get("MWFButtonImage");if(o){t.set("MWFButtonImage",this.path+""+this.options.style+"/formtoolbar/"+o)}}.bind(this));$(t).inject(this.formToolbarNode);MWF.require("MWF.widget.Toolbar",function(){this.formToolbar=new MWF.widget.Toolbar(t,{style:"ProcessCategory"},this);this.formToolbar.load();this.loaddesignerActionNode();if(o)o()}.bind(this))}.bind(this))},getFormToolbarHTML:function(r){var t=this.path+this.options.style+"/formToolbars.html";var e=new Request.HTML({url:t,method:"get",onSuccess:function(t,e,o,i){var s=t[0];if(r)r(s)}.bind(this),onFailure:function(t){this.notice("request processToolbars error: "+t.responseText,"error")}.bind(this)});e.send()},loadFormContent:function(t){this.designNode=new Element("div",{styles:this.css.designNode}).inject(this.formContentNode);this.designMobileNode=new Element("div",{styles:this.css.designMobileNode}).inject(this.formContentNode)},reloadPropertyStyles:function(){this.css=null;this.cssPath="/x_component_"+this.options.name.replace(/\./g,"_")+"/$Main/"+this.options.style+"/css.wcss";this._loadCss();if(this.options.style=="bottom"){this.propertyNode.inject(this.formNode,"after");this.propertyTitleNode.setStyle("cursor","row-resize");this.loadPropertyResizeBottom()}else{this.propertyNode.inject(this.formNode,"before");this.propertyTitleNode.setStyle("cursor","default");if(this.propertyResizeBottom)this.propertyResizeBottom.detach()}this.formNode.clearStyles(false);this.formNode.setStyles(this.css.formNode);this.propertyNode.clearStyles(false);this.propertyNode.setStyles(this.css.propertyNode);this.propertyTitleNode.clearStyles(false);this.propertyTitleNode.setStyles(this.css.propertyTitleNode);this.propertyResizeBar.clearStyles(false);this.propertyResizeBar.setStyles(this.css.propertyResizeBar);this.propertyContentNode.clearStyles(false);this.propertyContentNode.setStyles(this.css.propertyContentNode);this.propertyDomContentArea.clearStyles(false);this.propertyDomContentArea.setStyles(this.css.propertyDomContentArea);this.propertyDomScrollArea.clearStyles(false);this.propertyDomScrollArea.setStyles(this.css.propertyDomScrollArea);this.propertyDomArea.clearStyles(false);this.propertyDomArea.setStyles(this.css.propertyDomArea);this.propertyContentArea.clearStyles(false);this.propertyContentArea.setStyles(this.css.propertyContentArea);this.propertyContentResizeNode.clearStyles(false);this.propertyContentResizeNode.setStyles(this.css.propertyContentResizeNode);this.propertyTitleActionNode.clearStyles(false);this.propertyTitleActionNode.setStyles(this.css.propertyTitleActionNode);this.resizeNode()},loadProperty:function(){this.propertyTitleActionNode=new Element("div",{styles:this.css.propertyTitleActionNode}).inject(this.propertyNode);this.propertyTitleActionNode.addEvent("click",function(){this.options.style=this.options.style=="default"?"bottom":"default";MWF.UD.putData("formDesignerStyle",{style:this.options.style});this.reloadPropertyStyles()}.bind(this));this.propertyTitleNode=new Element("div",{styles:this.css.propertyTitleNode,text:MWF.APPFD.LP.property}).inject(this.propertyNode);if(this.options.style=="bottom"){this.propertyTitleNode.setStyle("cursor","row-resize");this.loadPropertyResizeBottom()}this.propertyResizeBar=new Element("div",{styles:this.css.propertyResizeBar}).inject(this.propertyNode);this.loadPropertyResize();this.propertyContentNode=new Element("div",{styles:this.css.propertyContentNode}).inject(this.propertyNode);this.propertyDomContentArea=new Element("div",{styles:this.css.propertyDomContentArea}).inject(this.propertyContentNode);this.propertyDomScrollArea=new Element("div",{styles:this.css.propertyDomScrollArea}).inject(this.propertyDomContentArea);this.propertyDomArea=new Element("div",{styles:this.css.propertyDomArea}).inject(this.propertyDomScrollArea);this.propertyDomPercent=.3;this.propertyContentResizeNode=new Element("div",{styles:this.css.propertyContentResizeNode}).inject(this.propertyContentNode);this.propertyContentArea=new Element("div",{styles:this.css.propertyContentArea}).inject(this.propertyContentNode);this.loadPropertyContentResize()},loadPropertyResizeBottom:function(){if(!this.propertyResizeBottom){this.propertyResizeBottom=new Drag(this.propertyTitleNode,{snap:1,onStart:function(t,e){var o=Browser.name=="firefox"?e.event.clientX:e.event.x;var i=Browser.name=="firefox"?e.event.clientY:e.event.y;t.store("position",{x:o,y:i});var s=this.propertyNode.getSize();t.store("initialWidth",s.x);t.store("initialHeight",s.y)}.bind(this),onDrag:function(t,e){var o=Browser.name=="firefox"?e.event.clientY:e.event.y;var i=this.content.getSize();var s=t.retrieve("position");var r=t.retrieve("initialHeight").toFloat();var n=s.y.toFloat()-o.toFloat();var l=r+n;if(l>i.y/1.5)l=i.y/1.5;if(l<40)l=40;var a=1-l/i.y;this.resizeNode(a)}.bind(this)})}else{this.propertyResizeBottom.attach()}},loadPropertyResize:function(){this.propertyResize=new Drag(this.propertyResizeBar,{snap:1,onStart:function(t,e){var o=Browser.name=="firefox"?e.event.clientX:e.event.x;var i=Browser.name=="firefox"?e.event.clientY:e.event.y;t.store("position",{x:o,y:i});var s=this.propertyNode.getSize();t.store("initialWidth",s.x)}.bind(this),onDrag:function(t,e){var o=Browser.name=="firefox"?e.event.clientX:e.event.x;var i=this.content.getSize();var s=t.retrieve("position");var r=t.retrieve("initialWidth").toFloat();var n=s.x.toFloat()-o.toFloat();var l=r+n;if(l>i.x/2)l=i.x/2;if(l<40)l=40;this.formNode.setStyle("margin-right",l+1);this.propertyNode.setStyle("width",l)}.bind(this)})},propertyResizeDragTopBottom:function(t,e){var o=this.propertyContentNode.getSize();var i=e.event.y;var s=t.retrieve("position");var r=i.toFloat()-s.y.toFloat();var n=t.retrieve("initialHeight").toFloat();var l=n+r;if(l<40)l=40;if(l>o.y-40)l=o.y-40;this.propertyDomPercent=l/o.y;this.setPropertyContentResize()},propertyResizeDragLeftRight:function(t,e){var o=this.propertyContentNode.getSize();var i=Browser.name=="firefox"?e.event.clientX:e.event.x;var s=t.retrieve("position");var r=i.toFloat()-s.x.toFloat();var n=t.retrieve("initialWidth").toFloat();var l=n+r;if(l<40)l=40;if(l>o.x-40)l=o.x-40;this.propertyDomPercent=l/o.x;this.setPropertyContentResizeBottom()},loadPropertyContentResize:function(){this.propertyContentResize=new Drag(this.propertyContentResizeNode,{snap:1,onStart:function(t,e){var o=Browser.name=="firefox"?e.event.clientX:e.event.x;var i=Browser.name=="firefox"?e.event.clientY:e.event.y;t.store("position",{x:o,y:i});var s=this.propertyDomContentArea.getSize();t.store("initialHeight",s.y);t.store("initialWidth",s.x)}.bind(this),onDrag:function(t,e){if(this.options.style=="bottom"){this.propertyResizeDragLeftRight(t,e)}else{this.propertyResizeDragTopBottom(t,e)}}.bind(this)})},setPropertyContentResizeBottom:function(){var t=this.propertyContentNode.getSize();var e=this.propertyContentResizeNode.getSize();var o=t.x-e.x-6;var i=this.propertyDomPercent*o;var s=i+e.x+6;this.propertyDomContentArea.setStyle("width",""+i+"px");this.propertyContentArea.setStyle("margin-left",""+s+"px")},setPropertyContentResize:function(){var t=this.propertyContentNode.getSize();var e=this.propertyContentResizeNode.getSize();var o=t.y-e.y;var i=this.propertyDomPercent*o;var s=o-i;this.propertyDomContentArea.setStyle("height",""+i+"px");this.propertyDomScrollArea.setStyle("height",""+i+"px");this.propertyContentArea.setStyle("height",""+s+"px");if(this.form){if(this.form.currentSelectedModule){if(this.form.currentSelectedModule.property){var r=this.form.currentSelectedModule.property.propertyTab;if(r){var n=r.tabNodeContainer.getSize();r.pages.each(function(t){var e=t.contentNodeArea.getStyle("margin-top").toFloat();var o=t.contentNodeArea.getStyle("margin-bottom").toFloat();var i=s-e-o-n.y.toFloat()-15;t.contentNodeArea.setStyle("height",i)}.bind(this))}}}}},loadTools:function(){var r=this;this.getTools(function(){Object.each(this.toolsData,function(t,e){var o=new Element("div",{styles:this.css.toolbarToolNode,title:t.text,events:{mouseover:function(t){try{this.setStyles(r.css.toolbarToolNodeOver)}catch(t){this.setStyles(r.css.toolbarToolNodeOverCSS2)}},mouseout:function(t){try{this.setStyles(r.css.toolbarToolNode)}catch(t){}},mousedown:function(t){try{this.setStyles(r.css.toolbarToolNodeDown)}catch(t){this.setStyles(r.css.toolbarToolNodeDownCSS2)}},mouseup:function(t){try{this.setStyles(r.css.toolbarToolNodeUp)}catch(t){this.setStyles(r.css.toolbarToolNodeUpCSS2)}}}}).inject(this.toolbarContentNode);o.store("toolClass",t.className);var i=new Element("div",{styles:this.css.toolbarToolIconNode}).inject(o);i.setStyle("background-image","url("+this.path+this.options.style+"/icon/"+t.icon+")");var s=new Element("div",{styles:this.css.toolbarToolTextNode,text:t.text});s.inject(o);o.addEvent("mousedown",function(t){var e=this.retrieve("toolClass");r.form.createModule(e,t)});this.tools.push(o)}.bind(this))}.bind(this))},getTools:function(o){if(this.toolsData){if(o)o()}else{var t=this.path+this.options.style+"/tools.json";var e=new Request.JSON({url:t,secure:false,async:false,method:"get",noCache:true,onSuccess:function(t,e){this.toolsData=t;if(o)o()}.bind(this),onError:function(t,e){this.notice("request tools data error: "+e,"error")}.bind(this)});e.send()}},resizeNodeLeftRight:function(){var t=this.node.getSize();this.toolbarNode.setStyle("height",""+t.y+"px");this.formNode.setStyle("height",""+t.y+"px");this.propertyNode.setStyle("height",""+t.y+"px");var e=this.formToolbarNode.getStyle("margin-top").toFloat();var o=this.formToolbarNode.getStyle("margin-bottom").toFloat();var i=this.formToolbarNode.getComputedSize();var s=t.y-i.totalHeight-e-o;this.formContentNode.setStyle("height",""+s+"px");if(this.designNode){var r=this.designNode.getStyle("margin-top").toFloat();var n=this.designNode.getStyle("margin-bottom").toFloat();s=t.y-i.totalHeight-e-o-r-n;this.designNode.setStyle("height",""+s+"px")}var l=this.toolbarTitleNode.getSize();var a=this.toolbarTitleNode.getStyle("margin-top").toFloat();var h=this.toolbarTitleNode.getStyle("margin-bottom").toFloat();var d=this.toolbarTitleNode.getStyle("padding-top").toFloat();var p=this.toolbarTitleNode.getStyle("padding-bottom").toFloat();s=l.y+a+h+d+p;s=t.y-s;this.toolbarContentNode.setStyle("height",""+s+"px");l=this.propertyTitleNode.getSize();a=this.propertyTitleNode.getStyle("margin-top").toFloat();h=this.propertyTitleNode.getStyle("margin-bottom").toFloat();d=this.propertyTitleNode.getStyle("padding-top").toFloat();p=this.propertyTitleNode.getStyle("padding-bottom").toFloat();s=l.y+a+h+d+p;s=t.y-s;this.propertyContentNode.setStyle("height",""+s+"px");this.propertyResizeBar.setStyle("height",""+s+"px")},resizeNodeTopBottom:function(t){var e=this.node.getSize();this.toolbarNode.setStyle("height",""+e.y+"px");var o=t||.6;var i=e.y*o;var s=e.y-i;this.formNode.setStyle("height",""+i+"px");this.propertyNode.setStyle("height",""+s+"px");var r=this.formToolbarNode.getStyle("margin-top").toFloat();var n=this.formToolbarNode.getStyle("margin-bottom").toFloat();var l=this.formToolbarNode.getComputedSize();var a=i-l.totalHeight-r-n;if(this.designNode){var h=this.designNode.getStyle("margin-top").toFloat();var d=this.designNode.getStyle("margin-bottom").toFloat();a=i-l.totalHeight-r-n-h-d;this.designNode.setStyle("height",""+a+"px")}var p=this.toolbarTitleNode.getSize();var c=this.toolbarTitleNode.getStyle("margin-top").toFloat();var m=this.toolbarTitleNode.getStyle("margin-bottom").toFloat();var y=this.toolbarTitleNode.getStyle("padding-top").toFloat();var f=this.toolbarTitleNode.getStyle("padding-bottom").toFloat();a=p.y+c+m+y+f;a=e.y-a;this.toolbarContentNode.setStyle("height",""+a+"px");p=this.propertyTitleNode.getSize();c=this.propertyTitleNode.getStyle("margin-top").toFloat();m=this.propertyTitleNode.getStyle("margin-bottom").toFloat();y=this.propertyTitleNode.getStyle("padding-top").toFloat();f=this.propertyTitleNode.getStyle("padding-bottom").toFloat();a=p.y+c+m+y+f;a=s-a;this.propertyContentNode.setStyle("height",""+a+"px");this.propertyResizeBar.setStyle("height",""+a+"px");this.propertyDomContentArea.setStyle("height",""+a+"px");this.propertyDomScrollArea.setStyle("height",""+a+"px");this.propertyContentResizeNode.setStyle("height",""+a+"px");this.propertyContentArea.setStyle("height",""+a+"px");if(this.form){if(this.form.currentSelectedModule){if(this.form.currentSelectedModule.property){var u=this.form.currentSelectedModule.property.propertyTab;if(u){var g=u.tabNodeContainer.getSize();u.pages.each(function(t){var e=t.contentNodeArea.getStyle("margin-top").toFloat();var o=t.contentNodeArea.getStyle("margin-bottom").toFloat();var i=a-e-o-g.y.toFloat()-15;t.contentNodeArea.setStyle("height",i)}.bind(this))}}}}},resizeNode:function(t){if(this.options.style=="bottom"){this.resizeNodeTopBottom(t);this.setPropertyContentResizeBottom()}else{this.resizeNodeLeftRight(t);this.setPropertyContentResize()}},loadForm:function(){this.getFormData(function(){this.pcForm=new MWF.CMSFCForm(this,this.designNode);this.pcForm.load(this.formData);this.form=this.pcForm}.bind(this))},getFormData:function(t){if(!this.options.id){if(this.options.templateId){this.loadNewFormDataFormTemplate(t)}else{this.loadNewFormData(t)}}else{this.loadFormData(t)}},loadNewFormData:function(e){var t="/x_component_cms_FormDesigner/Module/Form/template/"+this.options.template;MWF.getJSON(t,{onSuccess:function(t){this.formData=t.pcData;this.formData.id="";this.formData.isNewForm=true;this.formMobileData=t.mobileData;this.formMobileData.id="";this.formMobileData.isNewForm=true;if(e)e()}.bind(this),onerror:function(t){this.notice(t,"error")}.bind(this),onRequestFailure:function(t){this.notice(t.responseText,"error")}.bind(this)})},loadNewFormDataFormTemplate:function(e){this.actions.getFormTemplate(this.options.templateId,function(t){if(t){this.formData=JSON.decode(MWF.decodeJsonString(t.data.data));this.formData.isNewForm=true;this.formData.json.id="";if(t.data.mobileData){this.formMobileData=JSON.decode(MWF.decodeJsonString(t.data.mobileData));this.formMobileData.isNewForm=true;this.formMobileData.json.id=""}else{this.formMobileData=Object.clone(this.formData)}if(e)e()}}.bind(this))},loadFormData:function(e){this.actions.getForm(this.options.id,function(t){if(t){this.formData=JSON.decode(MWF.decodeJsonString(t.data.data));this.formData.isNewForm=false;this.formData.json.id=t.data.id;if(t.data.mobileData){this.formMobileData=JSON.decode(MWF.decodeJsonString(t.data.mobileData));this.formMobileData.isNewForm=false;this.formMobileData.json.id=t.data.id}else{this.formMobileData=Object.clone(this.formData)}this.setTitle(this.options.appTitle+"-"+this.formData.json.name);this.taskitem.setText(this.options.appTitle+"-"+this.formData.json.name);this.options.appTitle=this.options.appTitle+"-"+this.formData.json.name;if(!this.application){this.actions.getColumn(t.data.appId,function(t){this.application={name:t.data.appName,id:t.data.id};if(e)e()}.bind(this))}else{if(e)e()}}}.bind(this))},getFieldList:function(){dataTypes={string:["htmledit","radio","select","textarea","textfield"],person:["personfield","readerfield","authorfield"],date:["calender"],number:["number"],array:["checkbox"]};fieldList=[];this.pcForm.moduleList.each(function(t){var e="";for(k in dataTypes){if(dataTypes[k].indexOf(t.moduleName.toLowerCase())!=-1){e=k;break}}if(e){fieldList.push({name:t.json.id,dataType:e})}}.bind(this));return fieldList},saveForm:function(){if(!this.isSave){var t,e;if(this.pcForm){this.pcForm._getFormData();t=this.pcForm.data}if(this.mobileForm){this.mobileForm._getFormData();e=this.mobileForm.data}else{if(this.formMobileData)e=this.formMobileData}this.isSave=true;var o=this.getFieldList();this.actions.saveForm(t,e,o,function(t){this.notice(MWF.APPFD.LP.notice["save_success"],"ok",null,{x:"left",y:"bottom"});if(!this.pcForm.json.name)this.pcForm.treeNode.setText("<"+this.json.type+"> "+this.json.id);this.pcForm.treeNode.setTitle(this.pcForm.json.id);this.pcForm.node.set("id",this.pcForm.json.id);if(this.mobileForm){if(!this.mobileForm.json.name)this.mobileForm.treeNode.setText("<"+this.mobileForm.json.type+"> "+this.mobileForm.json.id);this.mobileForm.treeNode.setTitle(this.mobileForm.json.id);this.mobileForm.node.set("id",this.mobileForm.json.id+"_"+this.options.mode)}var e=this.pcForm.json.name;if(this.pcForm.data.isNewForm)this.setTitle(this.options.appTitle+"-"+e);this.pcForm.data.isNewForm=false;if(this.mobileForm)this.mobileForm.data.isNewForm=false;this.options.desktopReload=true;this.options.id=this.pcForm.json.id;this.isSave=false;this.fireAppEvent("postSave")}.bind(this),function(t,e,o){this.isSave=false;var i=o+":"+e;if(t)i=t.responseText;MWF.xDesktop.notice("error",{x:"right",y:"top"},"request json error: "+i)}.bind(this))}else{MWF.xDesktop.notice("info",{x:"right",y:"top"},this.lp.isSave)}},previewForm:function(){this.form.preview()},formExplode:function(){this.form.explode()},recordStatus:function(){return{id:this.options.id}},onPostClose:function(){if(this.pcForm){MWF.release(this.pcForm.moduleList);MWF.release(this.pcForm.moduleNodeList);MWF.release(this.pcForm.moduleContainerNodeList);MWF.release(this.pcForm.moduleElementNodeList);MWF.release(this.pcForm.moduleComponentNodeList);MWF.release(this.pcForm)}if(this.mobileForm){MWF.release(this.mobileForm.moduleList);MWF.release(this.mobileForm.moduleNodeList);MWF.release(this.mobileForm.moduleContainerNodeList);MWF.release(this.mobileForm.moduleElementNodeList);MWF.release(this.mobileForm.moduleComponentNodeList);MWF.release(this.mobileForm)}},setTemplateFormNode:function(t){var e='<table align="center" width="100%" height="90%" border="0" cellPadding="0" cellSpacing="0">'+'<tr><td colSpan="2" style="height: 50px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold">'+this.lp.saveTemplate+"</td></tr>"+'<tr><td style="height: 40px;" width="80px">'+this.lp.templateName+"</td><td>"+'<input value="'+this.pcForm.json.name+'" type="text" style="width: 98%; height: 22px; border: 1px solid #cccccc"/>'+"</td></tr>"+'<tr><td style="height: 40px;">'+this.lp.templateCategory+"</td><td>"+'<select style="width: 30%; height: 24px; border: 1px solid #cccccc"></select>'+'<input type="text" style="width: 68%; height: 22px; border: 1px solid #cccccc"/>'+"</td></tr>"+'<tr><td style="height: 40px;">'+this.lp.templateDescription+"</td><td>"+'<textarea type="text" style="width: 98%; height: 44px; border: 1px solid #cccccc">'+this.pcForm.json.description+"</textarea>"+"</td></tr>"+'<tr><td colSpan="2" id="form_templatePreview">'+'<div style="position: relative; width: 180px; height: 180px; margin: 20px auto 0px auto; overflow: hidden"></div>'+"</td></tr>"+"</table>";t.set("html",e);var o=t.getElements("td");var i=o[o.length-1].getFirst();var s=this.pcForm.node.clone();s.setStyles({"transform-origin":"0px 0px",transform:"scale(0.15,0.15)",position:"absolute",top:"0px",left:"0px"}).inject(i);return i},setCategorySelect:function(e){if(e){new Element("option",{value:"$newCategory",text:this.lp.newCategory}).inject(e);this.actions.listFormTemplateCategory(function(t){t.data.each(function(t){new Element("option",{value:t.name,text:t.name}).inject(e)}.bind(this))}.bind(this))}},setTemplateActions:function(t,e,o,i,s,r,n,l){var a=new Element("div",{styles:this.css.templateActionNode}).inject(o);var h=new Element("div",{styles:this.css.templateCancelActionNode,text:this.lp.cancel,events:{click:function(){t.destroy();e.destroy()}}}).inject(a);var d=new Element("div",{styles:this.css.templateSaveActionNode,text:this.lp.save,events:{click:function(){this.saveTemplate(t,e,i,s,r,n,l)}.bind(this)}}).inject(a)},saveTemplate:function(t,e,o,i,s,r,n){var l,a;if(this.pcForm){this.pcForm._getFormData();l=this.pcForm.data}if(this.mobileForm){this.mobileForm._getFormData();a=this.mobileForm.data}var h=i.get("value");var d=s.options[s.selectedIndex].value=="$newCategory"?r.get("value"):s.options[s.selectedIndex].value;var p=n.get("value");if(!h){this.notice(MWF.APPFD.LP.notice["saveTemplate_inputName"],"error",i,{x:"left",y:"top"});return false}if(s.options[s.selectedIndex].value=="$newCategory"&&!r.get("value")){this.notice(MWF.APPFD.LP.notice["saveTemplate_inputCategory"],"error",s,{x:"left",y:"top"});return false}var c={name:h,category:d,description:p,outline:o.get("html")};this.actions.addFormTemplate(l,a,c,function(){this.notice(MWF.APPFD.LP.notice["saveTemplate_success"],"ok",null,{x:"left",y:"bottom"});t.destroy();e.destroy()}.bind(this),function(t,e,o){var i=o+":"+e;if(t)i=t.responseText;MWF.xDesktop.notice("error",{x:"right",y:"top"},"request json error: "+i)})},createTemplateSaveNode:function(){var t=new Element("div",{styles:this.css.templateMarkNode,events:{mouseover:function(t){t.stopPropagation()},mouseout:function(t){t.stopPropagation()}}}).inject(this.content);var e=new Element("div",{styles:this.css.templateAreaNode}).inject(this.content);var o=new Element("div",{styles:this.css.templateInfoNode}).inject(e);var i=new Element("div",{styles:this.css.templateFormNode}).inject(o);var s=this.setTemplateFormNode(i);var r=i.getElements("input");var n=r[0];var l=r[1];var a=i.getElement("textarea");var h=i.getElement("select");this.setCategorySelect(h);this.setTemplateActions(t,e,i,s,n,h,l,a)},saveFormAsTemplate:function(){if(!this.isSave){this.createTemplateSaveNode()}else{MWF.xDesktop.notice("info",{x:"right",y:"top"},this.lp.isSave)}}});
|