TinyMCEEditor.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.TinyMCEEditor = MWF.FCTinyMCEEditor = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "../x_component_process_FormDesigner/Module/TinyMCEEditor/TinyMCEEditor.html"
  9. },
  10. initialize: function(form, options){
  11. this.setOptions(options);
  12. this.path = "../x_component_process_FormDesigner/Module/TinyMCEEditor/";
  13. this.cssPath = "../x_component_process_FormDesigner/Module/TinyMCEEditor/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. this.moduleType = "element";
  16. this.moduleName = "tinymceeditor";
  17. this.form = form;
  18. this.container = null;
  19. this.containerNode = null;
  20. },
  21. _createMoveNode: function(){
  22. this.moveNode = new Element("div", {
  23. "MWFType": "tinymceeditor",
  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. },
  41. _setEditStyle_custom: function(name){
  42. if (name=="editorProperties"){
  43. if (this.editor){
  44. Object.each(this.json.editorProperties, function(value, key){
  45. if (value=="true") this.json.editorProperties[key] = true;
  46. if (value=="false") this.json.editorProperties[key] = false;
  47. }.bind(this));
  48. this.distroyEditor();
  49. var config = Object.clone(this.json.editorProperties);
  50. if (this.json.config){
  51. if (this.json.config.code){
  52. var obj = MWF.Macro.exec(this.json.config.code, this);
  53. Object.each(obj, function(v, k){
  54. config[k] = v;
  55. });
  56. }
  57. }
  58. this.loadTinyMCEEditor(config);
  59. }
  60. }
  61. if (name=="templateCode"){
  62. if (this.editor) {
  63. this.editor.setContent(this.json.templateCode || "");
  64. }
  65. }
  66. },
  67. _initModule: function(){
  68. this.node.empty();
  69. var config = Object.clone(this.json.editorProperties);
  70. if (this.json.config){
  71. if (this.json.config.code){
  72. var obj = MWF.Macro.exec(this.json.config.code, this);
  73. Object.each(obj, function(v, k){
  74. config[k] = v;
  75. });
  76. }
  77. }
  78. this.loadTinyMCEEditor(config);
  79. this._setNodeProperty();
  80. if (!this.form.isSubform) this._createIconAction() ;
  81. this._setNodeEvent();
  82. },
  83. loadResource: function ( callback ) {
  84. o2.load([
  85. "../o2_lib/tinymce/tinymce_5.9.2/tinymce.min.js",
  86. "../o2_lib/tinymce/tinymce_5.9.2/o2config.js"
  87. ], function () {
  88. var config = o2.TinyMCEConfig( this.form.json.mode === "Mobile" );
  89. callback( config );
  90. }.bind(this))
  91. },
  92. //ckeditor
  93. loadTinyMCEEditor: function(config){
  94. this.loadResource( function( defaultConfig ){
  95. var editorConfig = Object.merge(defaultConfig, config || {});
  96. var id = this.form.json.id +"_"+this.json.id + "_" + this.form.options.mode;
  97. editorConfig.selector = '#'+id;
  98. var editorDiv = new Element("div", {"id": id}).inject(this.node);
  99. editorConfig.readonly = true;
  100. editorConfig.init_instance_callback = function(editor) {
  101. this.form.designer.addEvent("queryClose", function () {
  102. editor.destroy();
  103. });
  104. this.editor = editor;
  105. if( this.json.templateCode ){
  106. this.editor.setContent(this.json.templateCode);
  107. }
  108. }.bind(this);
  109. tinymce.init(editorConfig);
  110. }.bind(this));
  111. },
  112. destroy: function(){
  113. this.distroyEditor();
  114. this.form.moduleList.erase(this);
  115. this.form.moduleNodeList.erase(this.node);
  116. this.form.moduleElementNodeList.erase(this.node);
  117. if (this.form.scriptDesigner){
  118. this.form.scriptDesigner.removeModule(this.json);
  119. }
  120. if (this.property) this.property.destroy();
  121. this.node.destroy();
  122. this.actionArea.destroy();
  123. delete this.form.json.moduleList[this.json.id];
  124. this.json = null;
  125. delete this.json;
  126. this.treeNode.destroy();
  127. o2.release(this);
  128. },
  129. distroyEditor: function(){
  130. if (this.editor) this.editor.destroy();
  131. this.editor = null;
  132. }
  133. });