ScriptText.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. },
  11. initialize: function(node, code, app, options){
  12. this.setOptions(options);
  13. this.node = $(node);
  14. this.app = app;
  15. this.code = code;
  16. this.path = "../x_component_process_ProcessDesigner/widget/$ScriptText/";
  17. this.cssPath = "../x_component_process_ProcessDesigner/widget/$ScriptText/"+this.options.style+"/css.wcss";
  18. this._loadCss();
  19. this.createEditor();
  20. },
  21. createEditor: function(){
  22. this.areaNode = new Element("div", {"styles": this.css.areaNode}).inject(this.node);
  23. if (this.options.height) this.areaNode.setStyle("height", ""+this.options.height+"px");
  24. this.titleNode = new Element("div", {"styles": this.css.titleNode}).inject(this.areaNode);
  25. this.referenceNode = new Element("div", {"styles": this.css.actionReferenceNode}).inject(this.titleNode);
  26. if (!this.code) this.referenceNode.setStyle("background", "url("+"../x_component_process_ProcessDesigner/widget/$ScriptText/"+this.options.style+"/icon/reference_empty.png) no-repeat center center")
  27. this.maxNode = new Element("div", {"styles": this.css.actionMaxNode}).inject(this.titleNode);
  28. this.returnNode = new Element("div", {"styles": this.css.actionReturnNode}).inject(this.titleNode);
  29. this.editorNode = new Element("div", {"styles": this.css.editorNode}).inject(this.areaNode);
  30. if (this.options.height){
  31. var height = this.options.height.toInt()-20;
  32. this.editorNode.setStyle("height", ""+height+"px");
  33. }
  34. this.inforNode = new Element("div", {"styles": this.css.inforNode, "text": this.app.lp.intoScript}).inject(this.editorNode);
  35. var _self = this;
  36. this.inforNode.addEvent("click", function(){
  37. //this.destroy();
  38. //_self.inforNode = null;
  39. _self.loadEditor();
  40. });
  41. },
  42. loadEditor: function(callback){
  43. if (this.inforNode){
  44. this.inforNode.destroy();
  45. this.inforNode = null;
  46. }
  47. MWF.require("MWF.widget.JavascriptEditor", function(){
  48. this.editor = new MWF.widget.JavascriptEditor(this.editorNode, {
  49. "runtime": "server",
  50. "option": {"value": this.code},
  51. "onSave": function(){
  52. var value = this.editor.getValue();
  53. this.fireEvent("change", [value]);
  54. this.app.saveProcess();
  55. }.bind(this)
  56. });
  57. this.editor.load(function(){
  58. this.editor.addEditorEvent("blur", function(){
  59. var value = this.editor.getValue();
  60. this.fireEvent("change", [value]);
  61. }.bind(this));
  62. // this.editor.editor.on("blur", function(){
  63. // var value = this.editor.editor.getValue();
  64. // this.fireEvent("change", [value]);
  65. // }.bind(this));
  66. // this.createScriptReferenceMenu();
  67. //
  68. // this.editor.addEvent("reference", function(editor, e, e1){
  69. // if (!this.scriptReferenceMenu){
  70. // this.createScriptReferenceMenu(this.showReferenceMenu.bind(this));
  71. // }else{
  72. // this.showReferenceMenu();
  73. // }
  74. // }.bind(this));
  75. if (callback) callback();
  76. }.bind(this));
  77. }.bind(this));
  78. this.maxNode.addEvent("click", function(){this.maxSize();}.bind(this));
  79. this.returnNode.addEvent("click", function(){this.returnSize();}.bind(this))
  80. },
  81. createScriptReferenceMenu: function(callback){
  82. MWF.require("MWF.widget.ScriptHelp", function(){
  83. this.scriptReferenceMenu = new MWF.widget.ScriptHelp(this.referenceNode, this.editor.editor, {
  84. "code": "code_background.json",
  85. "event": "click",
  86. "onPostLoad": function(){
  87. if (callback) callback();
  88. }.bind(this)
  89. });
  90. this.scriptReferenceMenu.getEditor = function(){return this.editor.editor;}.bind(this)
  91. }.bind(this));
  92. },
  93. showReferenceMenu: function(){
  94. var pos = this.editor.getCursorPixelPosition();
  95. var e = {"page": {}};
  96. e.page.x = pos.left;
  97. e.page.y = pos.top;
  98. this.scriptReferenceMenu.menu.showIm(e);
  99. },
  100. maxSize: function() {
  101. if (!this.options.maxObj){
  102. this.areaNode.setStyles({
  103. "width": "100%",
  104. "height": "100%",
  105. "position": "absolute",
  106. "z-index": "50001",
  107. "top": "0px",
  108. "left": "0px"
  109. });
  110. this.areaNode.inject(this.app.content);
  111. }else{
  112. var size = this.options.maxObj.getSize();
  113. this.areaNode.inject(this.options.maxObj);
  114. this.areaNode.setStyles({
  115. "width": ""+size.x+"px",
  116. "height": ""+size.y+"px",
  117. "position": "absolute",
  118. "z-index": "50001"
  119. });
  120. this.areaNode.position({
  121. "relativeTo": this.options.maxObj,
  122. "position": "upperLeft",
  123. "edge": "upperLeft"
  124. });
  125. }
  126. this.resizeEditor();
  127. this.resizeEditorFun = this.resizeEditor.bind(this);
  128. this.app.addEvent("resize", this.resizeEditorFun);
  129. this.maxNode.setStyle("display", "none");
  130. this.returnNode.setStyle("display", "block");
  131. },
  132. resizeEditor: function(){
  133. var size = this.areaNode.getSize();
  134. var y = size.y-20;
  135. this.editorNode.setStyle("height", ""+y+"px");
  136. if (this.editor) this.editor.resize();
  137. },
  138. returnSize: function(){
  139. this.areaNode.setStyles(this.css.areaNode);
  140. this.areaNode.inject(this.node);
  141. if (this.options.height) this.areaNode.setStyle("height", ""+this.options.height+"px");
  142. this.resizeEditor();
  143. this.app.removeEvent("resize", this.resizeEditorFun);
  144. this.maxNode.setStyle("display", "block");
  145. this.returnNode.setStyle("display", "none");
  146. }
  147. //getValue()
  148. });