123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- MWF.xApplication = MWF.xApplication || {};
- MWF.xApplication.service = MWF.xApplication.service || {};
- MWF.xApplication.service.AgentDesigner = MWF.xApplication.service.AgentDesigner || {};
- MWF.SRVAD = MWF.xApplication.service.AgentDesigner;
- MWF.require("MWF.widget.Common", null, false);
- MWF.xDesktop.requireApp("service.AgentDesigner", "lp."+MWF.language, null, false);
- MWF.require("MWF.widget.JavascriptEditor", null, false);
- MWF.xApplication.service.AgentDesigner.Agent = new Class({
- Extends: MWF.widget.Common,
- Implements: [Options, Events],
- options: {
- "style": "default",
- "showTab": true
- },
- initialize: function(designer, data, options){
- this.setOptions(options);
- this.path = "../x_component_service_AgentDesigner/$Agent/";
- this.cssPath = "../x_component_service_AgentDesigner/$Agent/"+this.options.style+"/css.wcss";
- this._loadCss();
- this.isChanged = false;
- this.designer = designer;
- this.data = data;
- if (!this.data.text) this.data.text = "";
- this.node = this.designer.designNode;
- this.tab = this.designer.agentTab;
- this.areaNode = new Element("div", {"styles": {"overflow": "hidden", "height": "700px"}});
- //this.propertyIncludeNode = this.designer.propertyDomArea;
- this.propertyNode = this.designer.propertyContentArea;
- this.isNewAgent = (this.data.id) ? false : true;
- // this.createProperty();
- 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("#MWFAgentAutoSaveCheck");
- if (this.autoSaveCheckNode){
- if (this.autoSaveCheckNode.get("checked")){
- if (this.isChanged) this.saveSilence();
- }
- }
- }.bind(this), 60000);
- },
- //createProperty: function(){
- // this.agentPropertyNode = new Element("div", {"styles": this.css.agentPropertyNode}).inject(this.propertyNode);
- //},
- 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.newAgent, (!this.data.isNewAgent && this.data.id!=this.designer.options.id));
- this.page.agent = this;
- this.page.addEvent("show", function(){
- this.designer.agentListAreaNode.getChildren().each(function(node){
- var scrtip = node.retrieve("agent");
- if (scrtip.id==this.data.id){
- if (this.designer.currentListAgentItem){
- this.designer.currentListAgentItem.setStyles(this.designer.css.listAgentItem);
- }
- node.setStyles(this.designer.css.listAgentItem_current);
- this.designer.currentListAgentItem = node;
- this.lisNode = node;
- }
- }.bind(this));
- this.designer.currentScript = this;
- this.setPropertyContent();
- //this.setIncludeNode();
- if (this.editor){
- this.editor.focus();
- }else{
- this.loadEditor();
- }
- this.setAreaNodeSize();
- //if (this.editor.editor){
- // this.editor.editor.focus();
- //this.editor.editor.navigateFileStart();
- //}
- }.bind(this));
- var _self = this;
- this.page.addEvent("queryClose", function(){
- if (_self.autoSaveTimerID) window.clearInterval(_self.autoSaveTimerID);
- this.showIm();
- //this.saveSilence();
- if (_self.lisNode) _self.lisNode.setStyles(_self.designer.css.listAgentItem);
- });
- this.page.tabNode.addEvent("dblclick", this.designer.maxOrReturnEditor.bind(this.designer));
- if (this.options.showTab) this.page.showTabIm();
- },
- loadEditor:function(){
- this.editor = new MWF.widget.JavascriptEditor(this.areaNode, {"runtime": "service", "option": {"value": this.data.text}});
- this.editor.load(function(){
- if (this.data.text){
- this.editor.editor.setValue(this.data.text);
- }else{
- // var defaultText = "/********************\n";
- // defaultText += "resources.getEntityManagerContainer(); //实体管理器\n";
- // defaultText += "resources.getContext(); //上下文根\n";
- // defaultText += "resources.getOrganization(); //组织访问\n";
- // defaultText += "resources.getWebservicesClient();//webSerivces客户端\n";
- // defaultText += "********************/\n";
- var lp = this.designer.lp.comment;
- var url = new URI("../api");
- var p =url.get("port");
- p = (!p || p===80) ? "" : ":"+p;
- var h = url.get("host");
- url.get("scheme")+"://"+h+p+"/api"
- var defaultText = "/********************\n";
- // defaultText += "this.entityManager; //"+lp.entityManager+"\n";
- // defaultText += "this.applications; //"+lp.applications+"\n";
- // defaultText += "this.organization; //"+lp.organization+"\n";
- // defaultText += "this.org; //"+lp.org+"\n";
- // defaultText += "this.service; ///"+lp.service+"\n";
- defaultText += "API Document: "+url.get("scheme")+"://"+h+p+"/api"+"\n";
- defaultText += "********************/\n";
- this.editor.editor.setValue(defaultText);
- }
- this.editor.addEditorEvent("change", function(e){
- if (!this.isChanged){
- this.isChanged = true;
- this.page.textNode.set("text", " * "+this.page.textNode.get("text"));
- }
- }.bind(this));
- // 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(editor, e, e1){
- // if (!this.agentReferenceMenu){
- // MWF.require("MWF.widget.ScriptHelp", function(){
- // this.agentReferenceMenu = new MWF.widget.ScriptHelp(null, this.editor.editor, {
- // "onPostLoad": function(){
- // this.showReferenceMenu();
- // }.bind(this)
- // });
- // this.agentReferenceMenu.getEditor = function(){return this.editor.editor;}.bind(this)
- // }.bind(this));
- // }else{
- // this.showReferenceMenu();
- // }
- // }.bind(this));
- var options = this.designer.styleSelectNode.options;
- for (var i=0; i<options.length; i++){
- var option = options[i];
- if (option.value==this.editor.theme){
- option.set("selected", true);
- break;
- }
- }
- var options = this.designer.fontsizeSelectNode.options;
- for (var i=0; i<options.length; i++){
- var option = options[i];
- if (option.value==this.editor.fontSize){
- option.set("selected", true);
- break;
- }
- }
- options = this.designer.editorSelectNode.options;
- for (var i=0; i<options.length; i++){
- var option = options[i];
- if (option.value==this.editor.options.type){
- option.set("selected", true);
- break;
- }
- }
- options = this.designer.monacoStyleSelectNode.options;
- for (var i=0; i<options.length; i++){
- var option = options[i];
- if (option.value==this.editor.theme){
- option.set("selected", true);
- break;
- }
- }
- if (this.editor.options.type=="ace"){
- this.designer.monacoStyleSelectNode.hide();
- this.designer.styleSelectNode.show();
- }else{
- this.designer.monacoStyleSelectNode.show();
- this.designer.styleSelectNode.hide();
- }
- }.bind(this));
- },
- showReferenceMenu: function(){
- var pos = this.editor.getCursorPixelPosition();
- var e = {"page": {}};
- e.page.x = pos.left;
- e.page.y = pos.top;
- this.agentReferenceMenu.menu.showIm(e);
- },
- setIncludeNode: function(){
- this.designer.propertyIncludeListArea.empty();
- this.data.dependAgentList.each(function(name){
- this.designer.addIncludeToList(name);
- }.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.propertyEnableNode.set("text", this.data.enable ? this.designer.lp.true : this.designer.lp.false );
- this.designer.propertyCronNode.set("value", this.data.cron || "");
- this.designer.cronValue = this.data.cron || "";
- //this.designer.cronPicker.setCronValue( this.data.cron || "" );
- this.designer.propertyLastStartTimeNode.set("text", this.data.lastStartTime || "");
- this.designer.propertyLastEndTimeNode.set("text", this.data.lastEndTime || "");
- //this.designer.propertyAppointmentTimeNode.set("text", this.data.appointmentTime || "");
- this.designer.propertyDescriptionNode.set("value", this.data.description || "");
- this.setButton()
- },
- setButton : function(){
- this.designer.propertyEnableButton.store("id", this.data.id);
- this.designer.propertyDisableButton.store("id", this.data.id);
- this.designer.propertyExecuteButton.store("id", this.data.id);
- if( this.data.enable ){
- this.designer.propertyEnableButton.setStyle("display","none");
- this.designer.propertyDisableButton.setStyle("display", this.data.isNewAgent ? "none" : "" );
- }else{
- this.designer.propertyEnableButton.setStyle("display",this.data.isNewAgent ? "none" : "");
- this.designer.propertyDisableButton.setStyle("display", "none" );
- }
- },
- setAreaNodeSize: function(){
- if( !this.areaNode.offsetParent )return;
- //var size = this.node.getSize();
- var size = this.node.getComputedSize();
- size.y = size.height;
- var tabSize = this.tab.tabNodeContainer.getSize();
- var y = size.y - tabSize.y;
- this.areaNode.setStyle("height", ""+y+"px");
- //if (this.editor) if (this.editor.editor) this.editor.editor.resize();
- if (this.editor) this.editor.resize(y);
- },
- addInclude: function(){
- },
- saveAgent: function (data, success, failure) {
- if (data.isNewAgent) {
- this.designer.actions.createAgent(data, success, failure);
- } else {
- this.designer.actions.updateAgent(data.id, data, success, failure);
- }
- },
- save: function(callback){
- if (!this.isSave){
- /*var session = this.editor.editor.getSession();
- var annotations = session.getAnnotations();
- var validated = true;
- for (var i=0; i<annotations.length; i++){
- if (annotations[i].type=="error"){
- validated = false;
- break;
- }
- }*/
- var validated = this.editor.validated();
- var name = this.designer.propertyNameNode.get("value");
- var alias = this.designer.propertyAliasNode.get("value");
- var description = this.designer.propertyDescriptionNode.get("value");
- var cron = this.designer.propertyCronNode.get("value");
- if (!name){
- this.designer.notice(this.designer.lp.notice.inputName, "error");
- return false;
- }
- if(!cron){
- this.designer.notice(this.designer.lp.notice.inputCron, "error");
- return false;
- }
- this.data.name = name;
- this.data.alias = alias;
- this.data.description = description;
- this.data.cron = cron;
- this.data.validated = validated;
- this.data.text = this.editor.editor.getValue();
- this.isSave = true;
- this.saveAgent(this.data, function(json){
- this.isSave = false;
- if( this.data.isNewAgent ){
- this.data.isNewAgent = false;
- this.setButton();
- }
- 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 = json.data.id;
- this.designer.propertyIdNode.set("text", this.data.id );
- if (callback) callback();
- }.bind(this), function(xhr, text, error){
- this.isSave = false;
- var errorText = error+":"+text;
- if (xhr) errorText = xhr.responseText;
- MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
- }.bind(this));
- }else{
- MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
- }
- },
- saveSilence: function(callback){
- if (!this.isSave){
- var session = this.editor.editor.getSession();
- var annotations = session.getAnnotations();
- var validated = true;
- for (var i=0; i<annotations.length; i++){
- if (annotations[i].type=="error"){
- validated = false;
- break;
- }
- }
- if( this.designer.currentScript == this ){
- var name = this.designer.propertyNameNode.get("value");
- var alias = this.designer.propertyAliasNode.get("value");
- var description = this.designer.propertyDescriptionNode.get("value");
- var cron = this.designer.propertyCronNode.get("value");
- if (!name){
- this.designer.notice(this.designer.lp.notice.inputName, "error");
- return false;
- }
- if(!cron){
- this.designer.notice(this.designer.lp.notice.inputCron, "error");
- return false;
- }
- this.data.name = name;
- this.data.alias = alias;
- this.data.description = description;
- this.data.cron = cron;
- this.data.validated = validated;
- }
- this.data.text = this.editor.editor.getValue();
- this.isSave = true;
- this.saveAgent(this.data, function(json){
- this.isSave = false;
- if( this.data.isNewAgent ){
- this.data.isNewAgent = false;
- if( this.designer.currentScript == this ) {
- this.setButton();
- }
- }
- this.data.isNewAgent = 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 = json.data.id;
- if( this.designer.currentScript == this ) {
- this.designer.propertyIdNode.set("text", this.data.id);
- }
- if (callback) callback();
- }.bind(this), function(xhr, text, error){
- this.isSave = false;
- //
- //var errorText = error+":"+text;
- //if (xhr) errorText = xhr.responseText;
- //MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
- }.bind(this));
- }else{
- MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
- }
- },
- saveAs: function(){},
- explode: function(){},
- implode: function(){}
- });
|