Codeeditor.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. MWF.xApplication.process.FormDesigner.Module = MWF.xApplication.process.FormDesigner.Module || {};
  2. MWF.xDesktop.requireApp("process.FormDesigner", "Module.$Element", null, false);
  3. MWF.xApplication.process.FormDesigner.Module.Codeeditor = MWF.FCCodeeditor = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "../x_component_process_FormDesigner/Module/Codeeditor/codeeditor.html"
  9. },
  10. initialize: function(form, options){
  11. this.setOptions(options);
  12. this.path = "../x_component_process_FormDesigner/Module/Codeeditor/";
  13. this.cssPath = "../x_component_process_FormDesigner/Module/Codeeditor/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.moduleType = "element";
  16. this.moduleName = "codeeditor";
  17. this.form = form;
  18. this.container = null;
  19. this.containerNode = null;
  20. },
  21. _createMoveNode: function(){
  22. this.moveNode = new Element("div", {
  23. "MWFType": "codeeditor",
  24. "id": this.json.id,
  25. "styles": this.css.moduleNodeMove,
  26. "events": {
  27. "selectstart": function(){
  28. return false;
  29. }
  30. }
  31. }).inject(this.form.container);
  32. },
  33. _createNode: function(){
  34. this.node = this.moveNode.clone(true, true);
  35. this.node.setStyles(this.css.moduleNode);
  36. this.node.set("id", this.json.id);
  37. this.node.addEvent("selectstart", function(e){
  38. e.preventDefault();
  39. });
  40. // this.loadCkeditor();
  41. },
  42. _setEditStyle_custom: function(name){
  43. if (name==="mode"){
  44. if (this.editor && this.editor.jsEditor){
  45. this.editor.jsEditor.setMode(this.json.mode);
  46. }
  47. }
  48. if (name==="lineNumber"){
  49. if (this.editor && this.editor.jsEditor){
  50. if (this.json.lineNumber){
  51. this.editor.jsEditor.showLineNumbers();
  52. }else{
  53. this.editor.jsEditor.hideLineNumbers();
  54. }
  55. }
  56. }
  57. if (name==="scriptEditor"){
  58. const forceType = (this.json.scriptEditor !== "monaco" && this.json.scriptEditor !== "ace") ? null : this.json.scriptEditor;
  59. if (this.editor){
  60. this.editor.options.forceType = forceType;
  61. }
  62. if (this.editor && this.editor.jsEditor){
  63. this.editor.jsEditor.options.forceType = forceType;
  64. this.editor.jsEditor.reload();
  65. }
  66. }
  67. if (name==="isReadonly"){
  68. if (this.editor){
  69. this.setReadonly(this.json.isReadonly);
  70. }
  71. }
  72. if (name==="title"){
  73. if (this.editor){
  74. this.editor.setTitle(this.json.title);
  75. }
  76. }
  77. },
  78. setReadonly: function(readonly){
  79. if (readonly){
  80. if (this.editor){
  81. if (this.editor.jsEditor){
  82. this.editor.jsEditor.destroy();
  83. this.editor.jsEditor = null;
  84. }
  85. this.editor.titleNode.hide();
  86. this.editor.inforNode.hide();
  87. }
  88. }else{
  89. if (this.editor){
  90. this.editor.titleNode.show();
  91. this.editor.inforNode.show();
  92. this.editor.inforNode.inject(this.editor.contentNode);
  93. }
  94. }
  95. },
  96. _initModule: function(){
  97. this.node.empty();
  98. this.loadCodeeditor();
  99. this._setNodeProperty();
  100. if (!this.form.isSubform) this._createIconAction() ;
  101. this._setNodeEvent();
  102. },
  103. loadCodeeditor: function(){
  104. if (this.editor || this.editorLoading) return;
  105. this.editorLoading = true;
  106. MWF.require("MWF.widget.ScriptArea", function(){
  107. this.editor = new MWF.widget.ScriptArea(this.node, {
  108. "title": this.json.title || MWF.xApplication.process.FormDesigner.LP.modules.codeedit,
  109. "isbind": false,
  110. "forceType": (this.json.scriptEditor !== "monaco" && this.json.scriptEditor !== "ace") ? null : this.json.scriptEditor,
  111. "maxPosition": "absolute",
  112. "mode": this.json.mode || "javascript",
  113. "onChange": function(){
  114. }.bind(this),
  115. "onSave": function(){
  116. }.bind(this),
  117. "style": this.json.style || "v10"
  118. });
  119. this.editor.load();
  120. this.form.designer.addEvent("queryClose", function(){
  121. if (this.editor) this.editor?.destroy?.()
  122. }.bind(this));
  123. this.editorLoading = false;
  124. this.setReadonly(this.json.isReadonly);
  125. }.bind(this));
  126. },
  127. destroy: function(){
  128. this.distroyCkeditor();
  129. this.form.moduleList.erase(this);
  130. this.form.moduleNodeList.erase(this.node);
  131. this.form.moduleElementNodeList.erase(this.node);
  132. if (this.form.scriptDesigner){
  133. this.form.scriptDesigner.removeModule(this.json);
  134. }
  135. if (this.property) this.property.destroy();
  136. this.node.destroy();
  137. this.actionArea.destroy();
  138. delete this.form.json.moduleList[this.json.id];
  139. this.json = null;
  140. delete this.json;
  141. this.treeNode.destroy();
  142. o2.release(this);
  143. },
  144. distroyCkeditor: function(){
  145. if (this.editor) this.editor.destroy();
  146. this.editor = null;
  147. },
  148. _preprocessingModuleData: function(){
  149. this.node.clearStyles();
  150. //if (this.initialStyles) this.node.setStyles(this.initialStyles);
  151. this.json.recoveryStyles = Object.clone(this.json.styles);
  152. if (this.json.recoveryStyles) Object.each(this.json.recoveryStyles, function(value, key){
  153. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  154. //需要运行时处理
  155. }else{
  156. this.node.setStyle(key, value);
  157. delete this.json.styles[key];
  158. }
  159. }.bind(this));
  160. if (this.editor){
  161. this.editor.destroy();
  162. this.editor = null;
  163. this.node.empty();
  164. }
  165. this.json.preprocessing = "y";
  166. },
  167. _recoveryModuleData: function(){
  168. if (this.json.recoveryStyles) this.json.styles = this.json.recoveryStyles;
  169. this.json.recoveryStyles = null;
  170. this.loadCodeeditor();
  171. }
  172. });