Invoke.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.service = MWF.xApplication.service || {};
  3. MWF.xApplication.service.InvokeDesigner = MWF.xApplication.service.InvokeDesigner || {};
  4. MWF.SRVID = MWF.xApplication.service.InvokeDesigner;
  5. MWF.require("MWF.widget.Common", null, false);
  6. MWF.xDesktop.requireApp("service.InvokeDesigner", "lp."+MWF.language, null, false);
  7. MWF.require("MWF.widget.JavascriptEditor", null, false);
  8. MWF.xApplication.service.InvokeDesigner.Invoke = new Class({
  9. Extends: MWF.widget.Common,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "showTab": true
  14. },
  15. initialize: function(designer, data, options){
  16. this.setOptions(options);
  17. this.path = "/x_component_service_InvokeDesigner/$Invoke/";
  18. this.cssPath = "/x_component_service_InvokeDesigner/$Invoke/"+this.options.style+"/css.wcss";
  19. this._loadCss();
  20. this.isChanged = false;
  21. this.designer = designer;
  22. this.data = data;
  23. if (!this.data.text) this.data.text = "";
  24. this.node = this.designer.designNode;
  25. this.tab = this.designer.invokeTab;
  26. this.areaNode = new Element("div", {"styles": {"overflow": "hidden", "height": "700px"}});
  27. //this.propertyIncludeNode = this.designer.propertyDomArea;
  28. this.propertyNode = this.designer.propertyContentArea;
  29. this.isNewInvoke = (this.data.id) ? false : true;
  30. // this.createProperty();
  31. this.autoSave();
  32. this.designer.addEvent("queryClose", function(){
  33. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  34. }.bind(this));
  35. },
  36. autoSave: function(){
  37. this.autoSaveTimerID = window.setInterval(function(){
  38. if (!this.autoSaveCheckNode) this.autoSaveCheckNode = this.designer.contentToolbarNode.getElement("#MWFInvokeAutoSaveCheck");
  39. if (this.autoSaveCheckNode){
  40. if (this.autoSaveCheckNode.get("checked")){
  41. if (this.isChanged) this.saveSilence();
  42. }
  43. }
  44. }.bind(this), 60000);
  45. },
  46. //createProperty: function(){
  47. // this.invokePropertyNode = new Element("div", {"styles": this.css.invokePropertyNode}).inject(this.propertyNode);
  48. //},
  49. load : function(){
  50. this.setAreaNodeSize();
  51. this.designer.addEvent("resize", this.setAreaNodeSize.bind(this));
  52. this.page = this.tab.addTab(this.areaNode, this.data.name || this.designer.lp.newInvoke, (!this.data.isNewInvoke && this.data.id!=this.designer.options.id));
  53. this.page.invoke = this;
  54. this.page.addEvent("show", function(){
  55. this.designer.invokeListAreaNode.getChildren().each(function(node){
  56. var scrtip = node.retrieve("invoke");
  57. if (scrtip.id==this.data.id){
  58. if (this.designer.currentListInvokeItem){
  59. this.designer.currentListInvokeItem.setStyles(this.designer.css.listInvokeItem);
  60. }
  61. node.setStyles(this.designer.css.listInvokeItem_current);
  62. this.designer.currentListInvokeItem = node;
  63. this.lisNode = node;
  64. }
  65. }.bind(this));
  66. this.setPropertyContent();
  67. //this.setIncludeNode();
  68. if (this.editor.editor){
  69. this.editor.editor.focus();
  70. this.editor.editor.navigateFileStart();
  71. }
  72. }.bind(this));
  73. this.page.addEvent("queryClose", function(){
  74. if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID);
  75. this.saveSilence();
  76. if (this.lisNode) this.lisNode.setStyles(this.designer.css.listInvokeItem);
  77. }.bind(this));
  78. this.page.tabNode.addEvent("dblclick", this.designer.maxOrReturnEditor.bind(this.designer));
  79. this.editor = new MWF.widget.JavascriptEditor(this.areaNode);
  80. this.editor.load(function(){
  81. if (this.data.text){
  82. this.editor.editor.setValue(this.data.text);
  83. }else{
  84. var defaultText = "/********************\n";
  85. defaultText += "resources.getEntityManagerContainer(); //实体管理器\n";
  86. defaultText += "resources.getContext(); //上下文根\n";
  87. defaultText += "resources.getOrganization(); //组织访问\n";
  88. defaultText += "resources.getWebservicesClient();//webSerivces客户端\n";
  89. defaultText += "requestText//请求正文\n";
  90. defaultText += "request//请求\n";
  91. defaultText += "effectivePerson//当前用户\n";
  92. defaultText += "********************/\n";
  93. this.editor.editor.setValue(defaultText);
  94. }
  95. this.editor.editor.on("change", function(e){
  96. if (!this.isChanged){
  97. this.isChanged = true;
  98. this.page.textNode.set("text", " * "+this.page.textNode.get("text"));
  99. }
  100. }.bind(this));
  101. this.editor.addEvent("save", function(){
  102. this.save();
  103. }.bind(this));
  104. this.editor.addEvent("reference", function(editor, e, e1){
  105. if (!this.invokeReferenceMenu){
  106. MWF.require("MWF.widget.ScriptHelp", function(){
  107. this.invokeReferenceMenu = new MWF.widget.ScriptHelp(null, this.editor.editor, {
  108. "onPostLoad": function(){
  109. this.showReferenceMenu();
  110. }.bind(this)
  111. });
  112. this.invokeReferenceMenu.getEditor = function(){return this.editor.editor;}.bind(this)
  113. }.bind(this));
  114. }else{
  115. this.showReferenceMenu();
  116. }
  117. }.bind(this));
  118. var options = this.designer.styleSelectNode.options;
  119. for (var i=0; i<options.length; i++){
  120. var option = options[i];
  121. if (option.value==this.editor.theme){
  122. option.set("selected", true);
  123. break;
  124. }
  125. }
  126. }.bind(this));
  127. if (this.options.showTab) this.page.showTabIm();
  128. },
  129. showReferenceMenu: function(){
  130. var pos = this.editor.getCursorPixelPosition();
  131. var e = {"page": {}};
  132. e.page.x = pos.left;
  133. e.page.y = pos.top;
  134. this.invokeReferenceMenu.menu.showIm(e);
  135. },
  136. setIncludeNode: function(){
  137. this.designer.propertyIncludeListArea.empty();
  138. this.data.dependInvokeList.each(function(name){
  139. this.designer.addIncludeToList(name);
  140. }.bind(this));
  141. },
  142. setPropertyContent: function(){
  143. this.designer.propertyIdNode.set("text", this.data.id || "");
  144. this.designer.propertyNameNode.set("value", this.data.name || "");
  145. this.designer.propertyAliasNode.set("value", this.data.alias || "");
  146. this.designer.propertyEnableNode.getElement("option[value='"+ this.data.enable +"']").set("selected", true );
  147. this.designer.propertyRemoteAddrRegexNode.set("value", this.data.remoteAddrRegex || "");
  148. this.designer.propertyLastStartTimeNode.set("text", this.data.lastStartTime || "");
  149. this.designer.propertyLastEndTimeNode.set("text", this.data.lastEndTime || "");
  150. this.designer.propertyDescriptionNode.set("value", this.data.description || "");
  151. var action = this.designer.actions.action;
  152. var uri = action.address + action.actions.executeInvoke.uri ;
  153. uri = uri.replace("{flag}", this.data.alias || this.data.name || this.data.id );
  154. this.designer.propertyInvokeUriNode.set("text", uri);
  155. },
  156. setAreaNodeSize: function(){
  157. var size = this.node.getSize();
  158. var tabSize = this.tab.tabNodeContainer.getSize();
  159. var y = size.y - tabSize.y;
  160. this.areaNode.setStyle("height", ""+y+"px");
  161. if (this.editor) if (this.editor.editor) this.editor.editor.resize();
  162. },
  163. addInclude: function(){
  164. },
  165. saveInvoke: function (data, success, failure) {
  166. if (data.isNewInvoke) {
  167. this.designer.actions.createInvoke(data, success, failure);
  168. } else {
  169. this.designer.actions.updateInvoke(data.id, data, success, failure);
  170. }
  171. },
  172. save: function(callback){
  173. debugger;
  174. if (!this.isSave){
  175. var session = this.editor.editor.getSession();
  176. var annotations = session.getAnnotations();
  177. var validated = true;
  178. for (var i=0; i<annotations.length; i++){
  179. if (annotations[i].type=="error"){
  180. validated = false;
  181. break;
  182. }
  183. }
  184. var name = this.designer.propertyNameNode.get("value");
  185. var alias = this.designer.propertyAliasNode.get("value");
  186. var description = this.designer.propertyDescriptionNode.get("value");
  187. var remoteAddrRegex = this.designer.propertyRemoteAddrRegexNode.get("value");
  188. var enable = true;
  189. this.designer.propertyEnableNode.getElements("option").each( function(option){
  190. if( option.selected ){
  191. enable = (option.value == "true");
  192. }
  193. });
  194. if (!name){
  195. this.designer.notice(this.designer.lp.notice.inputName, "error");
  196. return false;
  197. }
  198. //if(!remoteAddrRegex){
  199. // this.designer.notice(this.designer.lp.notice.inputRemoteAddrRegex, "error");
  200. // return false;
  201. //}
  202. this.data.name = name;
  203. this.data.alias = alias;
  204. this.data.description = description;
  205. this.data.remoteAddrRegex = remoteAddrRegex;
  206. this.data.validated = validated;
  207. this.data.text = this.editor.editor.getValue();
  208. this.data.enable = enable;
  209. this.isSave = true;
  210. this.saveInvoke(this.data, function(json){
  211. this.isSave = false;
  212. if( this.data.isNewInvoke ){
  213. this.data.isNewInvoke = false;
  214. //this.setButton();
  215. }
  216. this.isChanged = false;
  217. this.page.textNode.set("text", this.data.name);
  218. if (this.lisNode) {
  219. this.lisNode.getLast().set("text", this.data.name);
  220. }
  221. this.designer.notice(this.designer.lp.notice.save_success, "success", this.node, {"x": "left", "y": "bottom"});
  222. this.data.id = json.data.id;
  223. this.designer.propertyIdNode.set("text", this.data.id );
  224. var action = this.designer.actions.action;
  225. var uri = action.address + action.actions.executeInvoke.uri ;
  226. uri = uri.replace("{flag}", this.data.alias || this.data.name || this.data.id );
  227. this.designer.propertyInvokeUriNode.set("text", uri);
  228. if (callback) callback();
  229. }.bind(this), function(xhr, text, error){
  230. this.isSave = false;
  231. var errorText = error+":"+text;
  232. if (xhr) errorText = xhr.responseText;
  233. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  234. }.bind(this));
  235. }else{
  236. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
  237. }
  238. },
  239. saveSilence: function(callback){
  240. if (!this.isSave){
  241. var session = this.editor.editor.getSession();
  242. var annotations = session.getAnnotations();
  243. var validated = true;
  244. for (var i=0; i<annotations.length; i++){
  245. if (annotations[i].type=="error"){
  246. validated = false;
  247. break;
  248. }
  249. }
  250. var name = this.designer.propertyNameNode.get("value");
  251. var alias = this.designer.propertyAliasNode.get("value");
  252. var description = this.designer.propertyDescriptionNode.get("value");
  253. var remoteAddrRegex = this.designer.propertyRemoteAddrRegexNode.get("value");
  254. var enable = true;
  255. this.designer.propertyEnableNode.getElements("option").each( function(option){
  256. if( option.selected ){
  257. enable = (option.value == "true");
  258. }
  259. });
  260. if (!name){
  261. this.designer.notice(this.designer.lp.notice.inputName, "error");
  262. return false;
  263. }
  264. //if(!remoteAddrRegex){
  265. // this.designer.notice(this.designer.lp.notice.inputRemoteAddrRegex, "error");
  266. // return false;
  267. //}
  268. this.data.name = name;
  269. this.data.alias = alias;
  270. this.data.description = description;
  271. this.data.remoteAddrRegex = remoteAddrRegex;
  272. this.data.validated = validated;
  273. this.data.text = this.editor.editor.getValue();
  274. this.data.enable = enable;
  275. this.isSave = true;
  276. this.saveInvoke(this.data, function(json){
  277. this.isSave = false;
  278. if( this.data.isNewInvoke ){
  279. this.data.isNewInvoke = false;
  280. //this.setButton();
  281. }
  282. this.data.isNewInvoke = false;
  283. this.isChanged = false;
  284. this.page.textNode.set("text", this.data.name);
  285. if (this.lisNode) {
  286. this.lisNode.getLast().set("text", this.data.name);
  287. }
  288. this.data.id = json.data.id;
  289. this.designer.propertyIdNode.set("text", this.data.id );
  290. var action = this.designer.actions.action;
  291. var uri = action.address + action.actions.executeInvoke.uri ;
  292. uri = uri.replace("{flag}", this.data.alias || this.data.name || this.data.id );
  293. this.designer.propertyInvokeUriNode.set("text", uri);
  294. if (callback) callback();
  295. }.bind(this), function(xhr, text, error){
  296. this.isSave = false;
  297. //
  298. //var errorText = error+":"+text;
  299. //if (xhr) errorText = xhr.responseText;
  300. //MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  301. }.bind(this));
  302. }else{
  303. MWF.xDesktop.notice("info", {x: "right", y:"top"}, this.designer.lp.isSave);
  304. }
  305. },
  306. saveAs: function(){},
  307. explode: function(){},
  308. implode: function(){}
  309. });