ScriptText.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. MWF.xApplication.process.ProcessDesigner.widget = MWF.xApplication.process.ProcessDesigner.widget || {};
  2. MWF.xApplication.process.ProcessDesigner.widget.ScriptText = new Class({
  3. Implements: [Options, Events],
  4. Extends: MWF.widget.Common,
  5. options: {
  6. "style": "default",
  7. "maskNode": $(document.body),
  8. "height": null,
  9. "maxObj": null,
  10. "forceType": null,
  11. "type": "service" //web or service
  12. },
  13. initialize: function(node, code, app, options){
  14. this.setOptions(options);
  15. this.node = $(node);
  16. this.app = app;
  17. this.code = code;
  18. this.path = "../x_component_process_ProcessDesigner/widget/$ScriptText/";
  19. this.cssPath = "../x_component_process_ProcessDesigner/widget/$ScriptText/"+this.options.style+"/css.wcss";
  20. this._loadCss();
  21. this.createEditor();
  22. },
  23. createEditor: function(){
  24. var codeIcon = (this.options.type!=="web") ? "code.png" : "web_code.png";
  25. var codeEmptyIcon = (this.options.type!=="web") ? "code_empty.png" : "web_code_empty.png";
  26. this.areaNode = new Element("div", {"styles": this.css.areaNode}).inject(this.node);
  27. if (this.options.height) this.areaNode.setStyle("height", ""+this.options.height+"px");
  28. this.titleNode = new Element("div", {"styles": this.css.titleNode}).inject(this.areaNode);
  29. this.referenceNode = new Element("div", {"styles": this.css.actionReferenceNode}).inject(this.titleNode);
  30. if (!this.code){
  31. this.referenceNode.setStyle("background", "url("+"../x_component_process_ProcessDesigner/widget/$ScriptText/"+this.options.style+"/icon/"+codeEmptyIcon+") no-repeat center center");
  32. }else{
  33. this.referenceNode.setStyle("background", "url("+"../x_component_process_ProcessDesigner/widget/$ScriptText/"+this.options.style+"/icon/"+codeIcon+") no-repeat center center")
  34. }
  35. this.referenceNode.addEvent("click", this.openApi.bind(this));
  36. this.maxNode = new Element("div", {"styles": this.css.actionMaxNode}).inject(this.titleNode);
  37. this.returnNode = new Element("div", {"styles": this.css.actionReturnNode}).inject(this.titleNode);
  38. this.editorNode = new Element("div", {"styles": this.css.editorNode}).inject(this.areaNode);
  39. if (this.options.height){
  40. var height = this.options.height.toInt()-20;
  41. this.editorNode.setStyle("height", ""+height+"px");
  42. }
  43. this.inforNode = new Element("div", {"styles": this.css.inforNode, "text": this.app.lp.intoScript}).inject(this.editorNode);
  44. var _self = this;
  45. this.inforNode.addEvent("click", function(){
  46. //this.destroy();
  47. //_self.inforNode = null;
  48. _self.loadEditor();
  49. });
  50. },
  51. openApi: function(){
  52. o2.openWindow(this.options.api || "../api")
  53. },
  54. loadEditor: function(callback){
  55. if (this.inforNode){
  56. this.inforNode.destroy();
  57. this.inforNode = null;
  58. }
  59. MWF.require("MWF.widget.JavascriptEditor", function(){
  60. this.editor = new MWF.widget.JavascriptEditor(this.editorNode, {
  61. "runtime": "server",
  62. "forceType": this.options.forceType,
  63. "option": {"value": this.code, "lineNumbers": false},
  64. "onSave": function(){
  65. var value = this.editor.getValue();
  66. this.fireEvent("change", [value]);
  67. this.app.saveProcess();
  68. }.bind(this)
  69. });
  70. debugger;
  71. this.editor.load(function(){
  72. this.editor.addEditorEvent("blur", function(){
  73. var value = this.editor.getValue();
  74. this.fireEvent("change", [value]);
  75. }.bind(this));
  76. // this.editor.editor.on("blur", function(){
  77. // var value = this.editor.editor.getValue();
  78. // this.fireEvent("change", [value]);
  79. // }.bind(this));
  80. // this.createScriptReferenceMenu();
  81. //
  82. // this.editor.addEvent("reference", function(editor, e, e1){
  83. // if (!this.scriptReferenceMenu){
  84. // this.createScriptReferenceMenu(this.showReferenceMenu.bind(this));
  85. // }else{
  86. // this.showReferenceMenu();
  87. // }
  88. // }.bind(this));
  89. if (callback) callback();
  90. }.bind(this));
  91. }.bind(this));
  92. this.maxNode.addEvent("click", function(){this.maxSize();}.bind(this));
  93. this.returnNode.addEvent("click", function(){this.returnSize();}.bind(this))
  94. },
  95. createScriptReferenceMenu: function(callback){
  96. MWF.require("MWF.widget.ScriptHelp", function(){
  97. this.scriptReferenceMenu = new MWF.widget.ScriptHelp(this.referenceNode, this.editor.editor, {
  98. "code": "code_background.json",
  99. "event": "click",
  100. "onPostLoad": function(){
  101. if (callback) callback();
  102. }.bind(this)
  103. });
  104. this.scriptReferenceMenu.getEditor = function(){return this.editor.editor;}.bind(this)
  105. }.bind(this));
  106. },
  107. showReferenceMenu: function(){
  108. var pos = this.editor.getCursorPixelPosition();
  109. var e = {"page": {}};
  110. e.page.x = pos.left;
  111. e.page.y = pos.top;
  112. this.scriptReferenceMenu.menu.showIm(e);
  113. },
  114. maxSize: function() {
  115. var areaSize = this.areaNode.getSize();
  116. this.originAreaWidth = areaSize.x;
  117. this.originAreaHeight = areaSize.y;
  118. if (!this.options.maxObj){
  119. this.areaNode.setStyles({
  120. "width": "100%",
  121. "height": "100%",
  122. "position": "absolute",
  123. "z-index": "50001",
  124. "top": "0px",
  125. "left": "0px"
  126. });
  127. this.areaNode.inject(this.app.content);
  128. }else{
  129. var size = this.options.maxObj.getSize();
  130. this.areaNode.inject(this.options.maxObj);
  131. this.areaNode.setStyles({
  132. "width": ""+size.x+"px",
  133. "height": ""+size.y+"px",
  134. "position": "absolute",
  135. "z-index": "50001"
  136. });
  137. this.areaNode.position({
  138. "relativeTo": this.options.maxObj,
  139. "position": "upperLeft",
  140. "edge": "upperLeft"
  141. });
  142. }
  143. this.resizeEditor();
  144. this.resizeEditorFun = this.resizeEditor.bind(this);
  145. this.app.addEvent("resize", this.resizeEditorFun);
  146. this.maxNode.setStyle("display", "none");
  147. this.returnNode.setStyle("display", "block");
  148. if (this.editor) this.editor.showLineNumbers();
  149. },
  150. resizeEditor: function(){
  151. var size = this.areaNode.getSize();
  152. var y = size.y-20;
  153. this.editorNode.setStyle("height", ""+y+"px");
  154. if (this.editor) this.editor.resize();
  155. if (this.editor) this.editor.hideLineNumbers();
  156. },
  157. returnSize: function(){
  158. this.areaNode.setStyles(this.css.areaNode);
  159. this.areaNode.inject(this.node);
  160. this.areaNode.setStyle("width", ""+this.originAreaWidth+"px");
  161. if (this.options.height) {
  162. this.areaNode.setStyle("height", ""+this.options.height+"px");
  163. }else{
  164. this.areaNode.setStyle("height", ""+this.originAreaHeight+"px");
  165. }
  166. this.resizeEditor();
  167. this.app.removeEvent("resize", this.resizeEditorFun);
  168. this.maxNode.setStyle("display", "block");
  169. this.returnNode.setStyle("display", "none");
  170. }
  171. //getValue()
  172. });