ScriptText.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. "option": {"value": this.code},
  50. "onSave": function(){
  51. var value = this.editor.getValue();
  52. this.fireEvent("change", [value]);
  53. this.app.saveProcess();
  54. }.bind(this)
  55. });
  56. this.editor.load(function(){
  57. this.editor.addEditorEvent("blur", function(){
  58. var value = this.editor.getValue();
  59. this.fireEvent("change", [value]);
  60. }.bind(this));
  61. // this.editor.editor.on("blur", function(){
  62. // var value = this.editor.editor.getValue();
  63. // this.fireEvent("change", [value]);
  64. // }.bind(this));
  65. this.createScriptReferenceMenu();
  66. this.editor.addEvent("reference", function(editor, e, e1){
  67. if (!this.scriptReferenceMenu){
  68. this.createScriptReferenceMenu(this.showReferenceMenu.bind(this));
  69. }else{
  70. this.showReferenceMenu();
  71. }
  72. }.bind(this));
  73. if (callback) callback();
  74. }.bind(this));
  75. }.bind(this));
  76. this.maxNode.addEvent("click", function(){this.maxSize();}.bind(this));
  77. this.returnNode.addEvent("click", function(){this.returnSize();}.bind(this))
  78. },
  79. createScriptReferenceMenu: function(callback){
  80. MWF.require("MWF.widget.ScriptHelp", function(){
  81. this.scriptReferenceMenu = new MWF.widget.ScriptHelp(this.referenceNode, this.editor.editor, {
  82. "code": "code_background.json",
  83. "event": "click",
  84. "onPostLoad": function(){
  85. if (callback) callback();
  86. }.bind(this)
  87. });
  88. this.scriptReferenceMenu.getEditor = function(){return this.editor.editor;}.bind(this)
  89. }.bind(this));
  90. },
  91. showReferenceMenu: function(){
  92. var pos = this.editor.getCursorPixelPosition();
  93. var e = {"page": {}};
  94. e.page.x = pos.left;
  95. e.page.y = pos.top;
  96. this.scriptReferenceMenu.menu.showIm(e);
  97. },
  98. maxSize: function() {
  99. if (!this.options.maxObj){
  100. this.areaNode.setStyles({
  101. "width": "100%",
  102. "height": "100%",
  103. "position": "absolute",
  104. "z-index": "50001",
  105. "top": "0px",
  106. "left": "0px"
  107. });
  108. this.areaNode.inject(this.app.content);
  109. }else{
  110. var size = this.options.maxObj.getSize();
  111. this.areaNode.inject(this.options.maxObj);
  112. this.areaNode.setStyles({
  113. "width": ""+size.x+"px",
  114. "height": ""+size.y+"px",
  115. "position": "absolute",
  116. "z-index": "50001"
  117. });
  118. this.areaNode.position({
  119. "relativeTo": this.options.maxObj,
  120. "position": "upperLeft",
  121. "edge": "upperLeft"
  122. });
  123. }
  124. this.resizeEditor();
  125. this.resizeEditorFun = this.resizeEditor.bind(this);
  126. this.app.addEvent("resize", this.resizeEditorFun);
  127. this.maxNode.setStyle("display", "none");
  128. this.returnNode.setStyle("display", "block");
  129. },
  130. resizeEditor: function(){
  131. var size = this.areaNode.getSize();
  132. var y = size.y-20;
  133. this.editorNode.setStyle("height", ""+y+"px");
  134. if (this.editor.editor) this.editor.editor.resize();
  135. },
  136. returnSize: function(){
  137. this.areaNode.setStyles(this.css.areaNode);
  138. this.areaNode.inject(this.node);
  139. if (this.options.height) this.areaNode.setStyle("height", ""+this.options.height+"px");
  140. this.resizeEditor();
  141. this.app.removeEvent("resize", this.resizeEditorFun);
  142. this.maxNode.setStyle("display", "block");
  143. this.returnNode.setStyle("display", "none");
  144. }
  145. //getValue()
  146. });