ScriptText.js 6.2 KB

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