123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- MWF.xApplication = MWF.xApplication || {};
- MWF.xApplication.service = MWF.xApplication.service || {};
- MWF.xApplication.service.InvokeDesigner = MWF.xApplication.service.InvokeDesigner || {};
- MWF.SRVID = MWF.xApplication.service.InvokeDesigner;
- MWF.require("MWF.widget.Common", null, false);
- MWF.xDesktop.requireApp("service.InvokeDesigner", "lp."+MWF.language, null, false);
- MWF.require("MWF.widget.JavascriptEditor", null, false);
- MWF.xApplication.service.InvokeDesigner.Invoke = 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_InvokeDesigner/$Invoke/";
- this.cssPath = "../x_component_service_InvokeDesigner/$Invoke/"+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.invokeTab;
- this.areaNode = new Element("div", {"styles": {"overflow": "hidden", "height": "700px"}});
- //this.propertyIncludeNode = this.designer.propertyDomArea;
- this.propertyNode = this.designer.propertyContentArea;
- this.isNewInvoke = (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("#MWFInvokeAutoSaveCheck");
- if (this.autoSaveCheckNode){
- if (this.autoSaveCheckNode.get("checked")){
- if (this.isChanged) this.saveSilence();
- }
- }
- }.bind(this), 60000);
- },
- //createProperty: function(){
- // this.invokePropertyNode = new Element("div", {"styles": this.css.invokePropertyNode}).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.newInvoke, (!this.data.isNewInvoke && this.data.id!=this.designer.options.id));
- this.page.invoke = this;
- this.page.addEvent("show", function(){
- this.designer.currentPage = this.page;
- this.designer.invokeListAreaNode.getChildren().each(function(node){
- var scrtip = node.retrieve("invoke");
- if (scrtip.id==this.data.id){
- if (this.designer.currentListInvokeItem){
- this.designer.currentListInvokeItem.setStyles(this.designer.css.listInvokeItem);
- }
- node.setStyles(this.designer.css.listInvokeItem_current);
- this.designer.currentListInvokeItem = 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();
- //}
- }.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.listInvokeItem);
- });
- 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 += "requestText//请求正文\n";
- // defaultText += "request//请求\n";
- // defaultText += "effectivePerson//当前用户\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.requestText//"+lp.requestText+"\n";
- // defaultText += "this.request//"+lp.request+"\n";
- defaultText += "this.currentPerson//"+lp.currentPerson+"\n";
- defaultText += "this.response//"+lp.response+"\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.invokeReferenceMenu){
- // MWF.require("MWF.widget.ScriptHelp", function(){
- // this.invokeReferenceMenu = new MWF.widget.ScriptHelp(null, this.editor.editor, {
- // "onPostLoad": function(){
- // this.showReferenceMenu();
- // }.bind(this)
- // });
- // this.invokeReferenceMenu.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.invokeReferenceMenu.menu.showIm(e);
- },
- setIncludeNode: function(){
- this.designer.propertyIncludeListArea.empty();
- this.data.dependInvokeList.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.propertyEnableTokenNode.getElement("option[value='"+ this.data.enableToken +"']").set("selected", true );
- this.designer.propertyEnableNode.getElement("option[value='"+ this.data.enable +"']").set("selected", true );
- this.designer.propertyRemoteAddrRegexNode.set("value", this.data.remoteAddrRegex || "");
- this.designer.propertyLastStartTimeNode.set("text", this.data.lastStartTime || "");
- this.designer.propertyLastEndTimeNode.set("text", this.data.lastEndTime || "");
- this.designer.propertyDescriptionNode.set("value", this.data.description || "");
- if( this.designer.propertyEnableTokenChangeEvent ){
- this.designer.propertyEnableTokenNode.removeEvent("change", this.designer.propertyEnableTokenChangeEvent);
- }
- this.designer.propertyEnableTokenChangeEvent = function(){
- this.setInvokeUrlText();
- this.checkPropertyTokenNode();
- }.bind(this);
- this.designer.propertyEnableTokenNode.addEvent("change", this.designer.propertyEnableTokenChangeEvent);
- this.designer.propertyEnableTokenChangeEvent();
- var data = {};
- if( this.data.data ){
- try{ data = JSON.parse( this.data.data ) }catch (e) {}
- }
- if(this.page){
- //this.designer.propertyRequireBodyNode.set("value", this.page.requireBody || "");
- if( this.designer.propertyRequireBodyScriptArea.jsEditor ){
- this.designer.propertyRequireBodyScriptArea.jsEditor.setValue(this.page.requireBody || data.requireBodyScript || "");
- }
- this.designer.propertyRunResultNode.set("text", this.page.executeResult || "");
- if(this.designer.propertyTokenNode){
- this.designer.propertyTokenNode.getElements("option").each(function ( opt ) {
- if( data.simulaToken === opt.value )opt.selected = true;
- });
- }
- }
- this.setButton();
- },
- setButton : function(){
- this.designer.propertyExecuteButton.store("id", this.data.id);
- this.designer.propertyExecuteButton.store("alias", this.data.alias);
- this.designer.propertyExecuteButton.store("name", this.data.name);
- },
- checkPropertyTokenNode: function(){
- var enableToken = true;
- this.designer.propertyEnableTokenNode.getElements("option").each( function(option){
- if( option.selected ){
- enableToken = (option.value == "true");
- }
- });
- this.designer.propertyTokenNode.getPrevious().setStyle("display", enableToken ? "" : "none" );
- this.designer.propertyTokenNode.setStyle("display", enableToken ? "" : "none" );
- },
- setInvokeUrlText: function(){
- debugger
- var action = this.designer.actions.action;
- var uri;
- var enableToken = true;
- this.designer.propertyEnableTokenNode.getElements("option").each( function(option){
- if( option.selected ){
- enableToken = (option.value == "true");
- }
- });
- if (enableToken===true){
- uri = action.address + action.actions.executeToken.uri ;
- uri = uri.replace("{flag}", this.data.alias || this.data.name || this.data.id );
- }else{
- uri = action.address + action.actions.executeInvoke.uri ;
- uri = uri.replace("{flag}", this.data.alias || this.data.name || this.data.id );
- }
- var url = o2.filterUrl(uri);
- this.designer.propertyInvokeUriNode.set("text", url);
- },
- 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(){
- },
- saveInvoke: function (data, success, failure) {
- if (data.isNewInvoke) {
- this.designer.actions.createInvoke(data, success, failure);
- } else {
- this.designer.actions.updateInvoke(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 remoteAddrRegex = this.designer.propertyRemoteAddrRegexNode.get("value");
- var enable = true;
- this.designer.propertyEnableNode.getElements("option").each( function(option){
- if( option.selected ){
- enable = (option.value == "true");
- }
- });
- var enableToken = true;
- this.designer.propertyEnableTokenNode.getElements("option").each( function(option){
- if( option.selected ){
- enableToken = (option.value == "true");
- }
- });
- var requireBodyScript = "";
- if(this.designer.propertyRequireBodyScriptArea){
- requireBodyScript = this.designer.propertyRequireBodyScriptArea.toJson().code;
- }
- var simulaToken = "";
- if(this.designer.propertyTokenNode){
- this.designer.propertyTokenNode.getElements("option").each( function(option){
- if( option.selected ){
- simulaToken = option.value;
- }
- });
- }
- if (!name){
- this.designer.notice(this.designer.lp.notice.inputName, "error");
- return false;
- }
- //if(!remoteAddrRegex){
- // this.designer.notice(this.designer.lp.notice.inputRemoteAddrRegex, "error");
- // return false;
- //}
- this.data.name = name;
- this.data.alias = alias;
- this.data.description = description;
- this.data.remoteAddrRegex = remoteAddrRegex;
- this.data.validated = validated;
- this.data.text = this.editor.editor.getValue();
- this.data.enable = enable;
- this.data.enableToken = enableToken;
- this.data.data = JSON.stringify({
- requireBodyScript: requireBodyScript,
- simulaToken: simulaToken
- });
- this.isSave = true;
- this.saveInvoke(this.data, function(json){
- this.isSave = false;
- if( this.data.isNewInvoke ){
- this.data.isNewInvoke = 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 );
- this.setInvokeUrlText()
- // var action = this.designer.actions.action;
- // var uri = action.address + action.actions.executeInvoke.uri ;
- // uri = uri.replace("{flag}", this.data.alias || this.data.name || this.data.id );
- // this.designer.propertyInvokeUriNode.set("text", uri);
- 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 remoteAddrRegex = this.designer.propertyRemoteAddrRegexNode.get("value");
- var enable = true;
- this.designer.propertyEnableNode.getElements("option").each( function(option){
- if( option.selected ){
- enable = (option.value == "true");
- }
- });
- var requireBodyScript = "";
- if(this.designer.propertyRequireBodyScriptArea){
- requireBodyScript = this.designer.propertyRequireBodyScriptArea.toJson().code;
- }
- var simulaToken = "";
- if(this.designer.propertyTokenNode){
- this.designer.propertyTokenNode.getElements("option").each( function(option){
- if( option.selected ){
- simulaToken = option.value;
- }
- });
- }
- if (!name){
- this.designer.notice(this.designer.lp.notice.inputName, "error");
- return false;
- }
- //if(!remoteAddrRegex){
- // this.designer.notice(this.designer.lp.notice.inputRemoteAddrRegex, "error");
- // return false;
- //}
- this.data.name = name;
- this.data.alias = alias;
- this.data.description = description;
- this.data.remoteAddrRegex = remoteAddrRegex;
- this.data.validated = validated;
- this.data.enable = enable;
- this.data.data = JSON.stringify({
- requireBodyScript: requireBodyScript,
- simulaToken: simulaToken
- });
- }
- this.data.text = this.editor.editor.getValue();
- this.isSave = true;
- this.saveInvoke(this.data, function(json){
- this.isSave = false;
- if( this.data.isNewInvoke ){
- this.data.isNewInvoke = false;
- this.setButton();
- }
- this.data.isNewInvoke = 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 );
- this.setInvokeUrlText();
- // var action = this.designer.actions.action;
- // var uri = action.address + action.actions.executeInvoke.uri ;
- // uri = uri.replace("{flag}", this.data.alias || this.data.name || this.data.id );
- // this.designer.propertyInvokeUriNode.set("text", uri);
- }
- 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(){}
- });
|