text: MWF.CMSVD=MWF.xApplication.cms.ViewDesigner,MWF.CMSVD.options={multitask:!0,executable:!1},MWF.xDesktop.requireApp("cms.ViewDesigner","View",null,!1),MWF.xApplication.cms.ViewDesigner.Main=new Class({Extends:MWF.xApplication.Common.Main,Implements:[Options,Events],options:{style:"default",name:"cms.ViewDesigner",icon:"icon.png",title:MWF.CMSVD.LP.title,appTitle:MWF.CMSVD.LP.title,id:"",actions:null,category:null,processData:null},onQueryLoad:function(){this.shortcut=!0,!this.options.id&&this.status?this.options.id=this.status.id:this.options.id&&this.options.id.toLowerCase().indexOf("viewdesigner")>-1&&(this.status&&this.status.id?this.options.id=this.status.id:this.options.id=""),!this.options.formId&&this.status&&this.status.formId&&(this.options.formId=this.status.formId),!this.application&&this.status&&this.status.applicationId&&(this.application={id:this.status.applicationId,appName:this.status.applicationName}),this.options.id||(this.options.desktopReload=!1,this.options.title=this.options.title+"-"+MWF.CMSVD.LP.newView),this.actions=MWF.Actions.get("x_cms_assemble_control"),this.path="../x_component_cms_ViewDesigner/$Main/",this.lp=MWF.xApplication.cms.ViewDesigner.LP},loadApplication:function(t){this.createNode(),this.options.isRefresh?this.openForm():this.maxSize(function(){this.openForm()}.bind(this)),t&&t()},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.loadNodes(),this.loadViewListNodes(),this.loadContentNode(),this.resizeNode(),this.addEvent("resize",this.resizeNode.bind(this)),this.loadView(),this.toolbarContentNode&&this.setScrollBar(this.toolbarContentNode,null,{V:{x:0,y:0},H:{x:0,y:0}})},initOptions:function(){},loadNodes:function(){this.viewListNode=new Element("div",{styles:this.css.viewListNode}).inject(this.node),this.contentNode=new Element("div",{styles:this.css.contentNode}).inject(this.node)},loadViewListNodes:function(){this.viewListTitleNode=new Element("div",{styles:this.css.viewListTitleNode,text:MWF.CMSVD.LP.view}).inject(this.viewListNode),this.viewListResizeNode=new Element("div",{styles:this.css.viewListResizeNode}).inject(this.viewListNode),this.viewListAreaSccrollNode=new Element("div",{styles:this.css.viewListAreaSccrollNode}).inject(this.viewListNode),this.viewListAreaNode=new Element("div",{styles:this.css.viewListAreaNode}).inject(this.viewListAreaSccrollNode),this.loadViewListResize(),this.loadViewList()},loadViewListResize:function(){this.viewListResize=new Drag(this.viewListResizeNode,{snap:1,onStart:function(t,i){var e="firefox"==Browser.name?i.event.clientX:i.event.x,s="firefox"==Browser.name?i.event.clientY:i.event.y;t.store("position",{x:e,y:s});var o=this.viewListAreaSccrollNode.getSize();t.store("initialWidth",o.x)}.bind(this),onDrag:function(t,i){var e="firefox"==Browser.name?i.event.clientX:i.event.x,s=this.content.getSize(),o=t.retrieve("position"),n=t.retrieve("initialWidth").toFloat()+(e.toFloat()-o.x.toFloat());n>s.x/2&&(n=s.x/2),n<40&&(n=40),this.contentNode.setStyle("margin-left",n+1),this.viewListNode.setStyle("width",n)}.bind(this)})},loadViewList:function(){this.actions.listView(this.application.id,function(t){(t.data||[]).each(function(t){this.createListViewItem(t)}.bind(this))}.bind(this),null,!1)},createListViewItem:function(t,i){var e=this,s=new Element("div",{styles:this.css.listViewItem}).inject(this.viewListAreaNode,i?"top":"bottom");new Element("div",{styles:this.css.listViewItemIcon}).inject(s),new Element("div",{styles:this.css.listViewItemText,text:t.name?t.name+" ("+t.alias+")":this.lp.newView}).inject(s);s.store("view",t),s.addEvents({dblclick:function(t){e.loadViewByData(this,t)},mouseover:function(){e.currentListViewItem!=this&&this.setStyles(e.css.listViewItem_over)},mouseout:function(){e.currentListViewItem!=this&&this.setStyles(e.css.listViewItem)}})},loadViewByData:function(t,i){for(var e=t.retrieve("view"),s=!0,o=0;o<this.tab.pages.length;o++)if(e.id==this.tab.pages[o].view.data.id){this.tab.pages[o].showTabIm(),s=!1;break}s&&this.loadViewData(e.id,function(t){new MWF.xApplication.cms.ViewDesigner.View(this,t).load()}.bind(this),!0)},loadRelativeForm:function(t,i){this.actions.getForm(t,function(t){this.relativeFormData=t.data.data?JSON.decode(MWF.decodeJsonString(t.data.data)):null,this.relativeForm||(this.relativeForm={id:this.relativeFormData.json.id,name:this.relativeFormData.json.name}),this.getFields(i)}.bind(this))},getFields:function(t){var i=this.path+"fieldConfig.json";MWF.getJSON(i,function(i){this.documentFields=i.documentFields;var e=[];i.formFileldType.each((function(t){e.push(t.name)})),this.formFields=[],Object.each(this.relativeFormData.json.moduleList,function(t,s){var o=e.indexOf(t.type.toLowerCase());o>-1&&this.formFields.push({name:s,type:i.formFileldType[o].type})}.bind(this)),t&&t()}.bind(this))},loadContentNode:function(){this.contentToolbarNode=new Element("div#contentToolbarNode",{styles:this.css.contentToolbarNode}).inject(this.contentNode),this.options.readMode||this.loadContentToolbar(),this.editContentNode=new Element("div.editContentNode",{styles:this.css.editContentNode}).inject(this.contentNode),this.loadEditContent(function(){this.designNode&&this.designNode.setStyles(this.css.designNode)}.bind(this))},loadContentToolbar:function(t){this.getFormToolbarHTML(function(i){i.getElements("span").each(function(t,i){var e=t.get("MWFButtonImage");e&&t.set("MWFButtonImage",this.path+""+this.options.style+"/toolbar/"+e)}.bind(this)),$(i).inject(this.contentToolbarNode),MWF.require("MWF.widget.Toolbar",function(){this.toolbar=new MWF.widget.Toolbar(i,{style:"ProcessCategory"},this),this.toolbar.load(),t&&t()}.bind(this))}.bind(this))},getFormToolbarHTML:function(t){var i=this.path+this.options.style+"/toolbars.html";new Request.HTML({url:i,method:"get",onSuccess:function(i,e,s,o){var n=i[0];t&&t(n)}.bind(this),onFailure:function(t){this.notice("request cmsToolbars error: "+t.responseText,"error")}.bind(this)}).send()},maxOrReturnEditor:function(){this.isMax?(this.isMax=!1,this.designNode.inject(this.editContentNode),this.designNode.setStyles(this.css.designNode),this.designNode.setStyles({position:"static"}),this.resizeNode(),this.tab.pages.each((function(t){t.view.setAreaNodeSize()}))):(this.designNode.inject(this.node),this.designNode.setStyles({position:"absolute",width:"100%",height:"100%",top:"0px",margin:"0px",left:"0px"}),this.tab.pages.each((function(t){t.view.setAreaNodeSize()})),this.isMax=!0)},loadEditContent:function(t){this.designNode=new Element("div.designNode",{styles:this.css.designNode}).inject(this.editContentNode),MWF.require("MWF.widget.Tab",function(){this.tab=new MWF.widget.Tab(this.designNode,{style:"dictionary"}),this.tab.load()}.bind(this),!1)},resizeNode:function(){var t=this.node.getSize();this.contentNode.setStyle("height",t.y+"px");var i=this.contentToolbarNode.getStyle("margin-top").toFloat(),e=this.contentToolbarNode.getStyle("margin-bottom").toFloat(),s=this.contentToolbarNode.getComputedSize(),o=t.y-s.totalHeight-i-e;if(this.editContentNode.setStyle("height",o+"px"),this.designNode){var n=this.designNode.getStyle("margin-top").toFloat(),a=this.designNode.getStyle("margin-bottom").toFloat();o=t.y-s.totalHeight-i-e-n-a,this.designNode.setStyle("height",o+"px")}titleSize=this.viewListTitleNode.getSize(),titleMarginTop=this.viewListTitleNode.getStyle("margin-top").toFloat(),titleMarginBottom=this.viewListTitleNode.getStyle("margin-bottom").toFloat(),titlePaddingTop=this.viewListTitleNode.getStyle("padding-top").toFloat(),titlePaddingBottom=this.viewListTitleNode.getStyle("padding-bottom").toFloat(),nodeMarginTop=this.viewListAreaSccrollNode.getStyle("margin-top").toFloat(),nodeMarginBottom=this.viewListAreaSccrollNode.getStyle("margin-bottom").toFloat(),o=titleSize.y+titleMarginTop+titleMarginBottom+titlePaddingTop+titlePaddingBottom+nodeMarginTop+nodeMarginBottom,o=t.y-o,this.viewListAreaSccrollNode.setStyle("height",o+"px"),this.viewListResizeNode.setStyle("height",o+"px")},loadView:function(){this.getViewData(this.options.id,function(t){var i=t.name||"";this.setTitle(this.options.appTitle+"-"+i),this.taskitem.setText(this.options.appTitle+"-"+i),this.options.appTitle=this.options.appTitle+"-"+i,this.view=new MWF.xApplication.cms.ViewDesigner.View(this,t),this.view.load(),this.status&&this.status.openViews&&this.status.openViews.each(function(t){this.loadViewData(t,function(t){var i=!0;this.status.currentId&&this.status.currentId!=t.id&&(i=!1),new MWF.xApplication.cms.ViewDesigner.View(this,t,{showTab:i}).load()}.bind(this),!0)}.bind(this))}.bind(this))},getViewData:function(t,i){t?this.loadViewData(t,i):this.loadNewViewData(i)},loadNewViewData:function(t){this.loadRelativeForm(this.options.formId||this.relativeForm.id,function(){var i={content:{isNew:!0,name:"",id:this.actions.getUUID(),application:this.application.id,applicationName:this.application.appName,alias:"",description:"",relativeForm:this.relativeForm,events:null,columns:[],jsheader:null,sortType:"DESC"}};this.createListViewItem(i,!0),t&&t(i)}.bind(this))},loadViewData:function(t,i){this.actions.getView(t,function(e){e&&(e.data.content=JSON.parse(e.data.content),e.data.content.id!=t&&(e.data.content.id=t),this.application?this.loadRelativeForm(e.data.content.relativeForm.id,(function(){i&&i(e.data)})):this.actions.getColumn(e.appId,function(t){this.application={name:t.data.name,id:t.data.id},this.loadRelativeForm(e.data.content.relativeForm.id,(function(){i&&i(e.data)}))}.bind(this)))}.bind(this))},saveView:function(){if(this.tab.showPage){var t=this.tab.showPage.view;t.save(function(){if(t==this.view){var i=t.data.name||"";this.setTitle(MWF.CMSVD.LP.title+"-"+i),this.options.desktopReload=!0,this.options.id=t.data.id}this.fireAppEvent("postSave")}.bind(this))}},saveViewAs:function(){this.view.saveAs()},viewExplode:function(){this.view.explode()},viewImplode:function(){this.view.implode()},recordStatus:function(){if(this.tab){var t=[];this.tab.pages.each(function(i){i.view.data.id!=this.options.id&&t.push(i.view.data.id)}.bind(this));var i=this.tab.showPage.view.data.id;return{id:this.options.id,applicationId:this.application.id,applicationName:this.application.appName,formId:this.options.formId||this.relativeForm.id,openViews:t,currentId:i}}return{id:this.options.id,applicationId:this.application.id,applicationName:this.application.appName,formId:this.options.formId||this.relativeForm.id}}});