Script.min.js 6.8 KB

1
  1. MWF.xApplication=MWF.xApplication||{};MWF.xApplication.process=MWF.xApplication.process||{};MWF.xApplication.process.ScriptDesigner=MWF.xApplication.process.ScriptDesigner||{};MWF.APPSD=MWF.xApplication.process.ScriptDesigner;MWF.require("MWF.widget.Common",null,false);MWF.xDesktop.requireApp("process.ScriptDesigner","lp."+MWF.language,null,false);MWF.require("MWF.widget.JavascriptEditor",null,false);MWF.xApplication.process.ScriptDesigner.Script=new Class({Extends:MWF.widget.Common,Implements:[Options,Events],options:{style:"default",showTab:true},initialize:function(e,t,i){this.setOptions(i);this.path="/x_component_process_ScriptDesigner/$Script/";this.cssPath="/x_component_process_ScriptDesigner/$Script/"+this.options.style+"/css.wcss";this._loadCss();this.isChanged=false;this.designer=e;this.data=t;if(!this.data.text)this.data.text="";this.node=this.designer.designNode;this.tab=this.designer.scriptTab;this.areaNode=new Element("div",{styles:{overflow:"hidden",height:"700px"}});this.propertyIncludeNode=this.designer.propertyDomArea;this.propertyNode=this.designer.propertyContentArea;if(this.designer.application)this.data.applicationName=this.designer.application.name;if(this.designer.application)this.data.application=this.designer.application.id;this.isNewScript=this.data.id?false:true;this.autoSave();this.designer.addEvent("queryClose",function(){if(this.autoSaveTimerID)window.clearInterval(this.autoSaveTimerID)}.bind(this))},autoSave:function(){this.autoSaveTimerID=window.setInterval(function(){if(!this.autoSaveCheckNode)this.autoSaveCheckNode=this.designer.contentToolbarNode.getElement("#MWFScriptAutoSaveCheck");if(this.autoSaveCheckNode){if(this.autoSaveCheckNode.get("checked")){if(this.isChanged)this.saveSilence()}}}.bind(this),6e4)},load:function(){this.setAreaNodeSize();this.designer.addEvent("resize",this.setAreaNodeSize.bind(this));this.page=this.tab.addTab(this.areaNode,this.data.name||this.designer.lp.newScript,!this.data.isNewScript&&this.data.id!=this.designer.options.id);this.page.script=this;this.page.addEvent("show",function(){this.designer.scriptListAreaNode.getChildren().each(function(e){var t=e.retrieve("script");if(t.id==this.data.id){if(this.designer.currentListScriptItem){this.designer.currentListScriptItem.setStyles(this.designer.css.listScriptItem)}e.setStyles(this.designer.css.listScriptItem_current);this.designer.currentListScriptItem=e;this.lisNode=e}}.bind(this));this.setPropertyContent();this.setIncludeNode();if(this.editor.editor){this.editor.editor.focus();this.editor.editor.navigateFileStart()}}.bind(this));this.page.addEvent("queryClose",function(){if(this.autoSaveTimerID)window.clearInterval(this.autoSaveTimerID);this.saveSilence();if(this.lisNode)this.lisNode.setStyles(this.designer.css.listScriptItem)}.bind(this));this.page.tabNode.addEvent("dblclick",this.designer.maxOrReturnEditor.bind(this.designer));this.editor=new MWF.widget.JavascriptEditor(this.areaNode);this.editor.load(function(){if(this.data.text){this.editor.editor.setValue(this.data.text)}this.editor.editor.on("change",function(e){if(!this.isChanged){this.isChanged=true;this.page.textNode.set("text"," * "+this.page.textNode.get("text"))}}.bind(this));this.editor.addEvent("save",function(){this.save()}.bind(this));this.editor.addEvent("reference",function(e,t,i){if(!this.scriptReferenceMenu){MWF.require("MWF.widget.ScriptHelp",function(){this.scriptReferenceMenu=new MWF.widget.ScriptHelp(null,this.editor.editor,{onPostLoad:function(){this.showReferenceMenu()}.bind(this)});this.scriptReferenceMenu.getEditor=function(){return this.editor.editor}.bind(this)}.bind(this))}else{this.showReferenceMenu()}}.bind(this));var e=this.designer.styleSelectNode.options;for(var t=0;t<e.length;t++){var i=e[t];if(i.value==this.editor.theme){i.set("selected",true);break}}}.bind(this));if(this.options.showTab)this.page.showTabIm()},showReferenceMenu:function(){var e=this.editor.getCursorPixelPosition();var t={page:{}};t.page.x=e.left;t.page.y=e.top;this.scriptReferenceMenu.menu.showIm(t)},setIncludeNode:function(){this.designer.propertyIncludeListArea.empty();this.data.dependScriptList.each(function(e){this.designer.addIncludeToList(e)}.bind(this))},setPropertyContent:function(){this.designer.propertyIdNode.set("text",this.data.id||"");this.designer.propertyNameNode.set("value",this.data.name||"");this.designer.propertyAliasNode.set("value",this.data.alias||"");this.designer.propertyDescriptionNode.set("value",this.data.description||"")},setAreaNodeSize:function(){var e=this.node.getSize();var t=this.tab.tabNodeContainer.getSize();var i=e.y-t.y;this.areaNode.setStyle("height",""+i+"px");if(this.editor)if(this.editor.editor)this.editor.editor.resize()},addInclude:function(){},save:function(e){if(!this.isSave){var t=this.editor.editor.getSession();var i=t.getAnnotations();var s=true;for(var a=0;a<i.length;a++){if(i[a].type=="error"){s=false;break}}var r=this.designer.propertyNameNode.get("value");var n=this.designer.propertyAliasNode.get("value");var o=this.designer.propertyDescriptionNode.get("value");if(!r){this.designer.notice(this.designer.lp.notice.inputName,"error");return false}this.data.name=r;this.data.alias=n;this.data.description=o;this.data.validated=s;this.data.text=this.editor.editor.getValue();this.isSave=true;this.designer.actions.saveScript(this.data,function(t){this.isSave=false;this.data.isNewScript=false;this.isChanged=false;this.page.textNode.set("text",this.data.name);if(this.lisNode){this.lisNode.getLast().set("text",this.data.name)}this.designer.notice(this.designer.lp.notice.save_success,"success",this.node,{x:"left",y:"bottom"});this.data.id=t.data.id;if(e)e()}.bind(this),function(e,t,i){this.isSave=false;var s=i+":"+t;if(e)s=e.responseText;MWF.xDesktop.notice("error",{x:"right",y:"top"},"request json error: "+s)}.bind(this))}else{MWF.xDesktop.notice("info",{x:"right",y:"top"},this.designer.lp.isSave)}},saveSilence:function(e){if(!this.isSave){var t=this.editor.editor.getSession();var i=t.getAnnotations();var s=true;for(var a=0;a<i.length;a++){if(i[a].type=="error"){s=false;break}}var r=this.designer.propertyNameNode.get("value");var n=this.designer.propertyAliasNode.get("value");var o=this.designer.propertyDescriptionNode.get("value");if(!r){this.designer.notice(this.designer.lp.notice.inputName,"error");return false}this.data.name=r;this.data.alias=n;this.data.description=o;this.data.validated=s;this.data.text=this.editor.editor.getValue();this.isSave=true;this.designer.actions.saveScript(this.data,function(t){this.isSave=false;this.data.isNewScript=false;this.isChanged=false;this.page.textNode.set("text",this.data.name);if(this.lisNode){this.lisNode.getLast().set("text",this.data.name)}this.data.id=t.data.id;if(e)e()}.bind(this),function(e,t,i){this.isSave=false}.bind(this))}else{MWF.xDesktop.notice("info",{x:"right",y:"top"},this.designer.lp.isSave)}},saveAs:function(){},explode:function(){},implode:function(){}});