Htmleditor.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.Htmleditor = MWF.FCHtmleditor = new Class({
  4. Extends: MWF.FC$Element,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "propertyPath": "../x_component_process_FormDesigner/Module/Htmleditor/htmleditor.html"
  9. },
  10. initialize: function(form, options){
  11. debugger;
  12. this.setOptions(options);
  13. this.path = "../x_component_process_FormDesigner/Module/Htmleditor/";
  14. this.cssPath = "../x_component_process_FormDesigner/Module/Htmleditor/"+this.options.style+"/css.wcss";
  15. this._loadCss();
  16. this.moduleType = "element";
  17. this.moduleName = "htmleditor";
  18. this.form = form;
  19. this.container = null;
  20. this.containerNode = null;
  21. },
  22. _createMoveNode: function(){
  23. this.moveNode = new Element("div", {
  24. "MWFType": "htmleditor",
  25. "id": this.json.id,
  26. "styles": this.css.moduleNodeMove,
  27. "events": {
  28. "selectstart": function(){
  29. return false;
  30. }
  31. }
  32. }).inject(this.form.container);
  33. },
  34. _createNode: function(){
  35. this.node = this.moveNode.clone(true, true);
  36. this.node.setStyles(this.css.moduleNode);
  37. this.node.set("id", this.json.id);
  38. this.node.addEvent("selectstart", function(e){
  39. e.preventDefault();
  40. });
  41. // this.loadCkeditor();
  42. },
  43. _setEditStyle_custom: function(name){
  44. if (name=="editorProperties"){
  45. if (this.editor){
  46. Object.each(this.json.editorProperties, function(value, key){
  47. if (value=="true") this.json.editorProperties[key] = true;
  48. if (value=="false") this.json.editorProperties[key] = false;
  49. }.bind(this));
  50. this.distroyCkeditor();
  51. var config = Object.clone(this.json.editorProperties);
  52. if (this.json.config){
  53. if (this.json.config.code){
  54. var obj = MWF.Macro.exec(this.json.config.code, this);
  55. Object.each(obj, function(v, k){
  56. config[k] = v;
  57. });
  58. }
  59. }
  60. this.loadCkeditor(config);
  61. }
  62. }
  63. if (name=="templateCode"){
  64. if (this.editor) this.editor.setData(this.json.templateCode);
  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.loadCkeditor(config);
  79. this._setNodeProperty();
  80. if (!this.form.isSubform) this._createIconAction() ;
  81. this._setNodeEvent();
  82. },
  83. //ckeditor
  84. loadCkeditor: function(config){
  85. COMMON.AjaxModule.load("ckeditor", function(){
  86. CKEDITOR.disableAutoInline = true;
  87. var editorDiv = new Element("div").inject(this.node);
  88. if (this.json.templateCode) editorDiv.set("html", this.json.templateCode);
  89. var height = this.node.getSize().y;
  90. var editorConfig = config || {};
  91. if (this.form.options.mode=="Mobile"){
  92. // if (!editorConfig.toolbar && !editorConfig.toolbarGroups){
  93. editorConfig.toolbar = [
  94. //{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
  95. //{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ] },
  96. //{ name: 'links' },
  97. //{ name: 'insert' },
  98. //{ name: 'forms' },
  99. //{ name: 'tools' },
  100. //{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
  101. //{ name: 'others' },
  102. //'/',
  103. { name: 'paragraph', items: [ 'Bold', 'Italic', "-" , 'TextColor', "BGColor", 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', "-", 'Undo', 'Redo' ] },
  104. { name: 'basicstyles', items: [ 'Styles', 'FontSize']}
  105. //{ name: 'colors' },
  106. //{ name: 'about' }
  107. ];
  108. // }
  109. }
  110. if (!editorConfig.removeButtons){
  111. editorConfig.removeButtons = "EasyImageUpload,ExportPdf";
  112. }else{
  113. editorConfig.removeButtons += ",EasyImageUpload,ExportPdf";
  114. }
  115. if (!editorConfig.removePlugins || !editorConfig.removePlugins.length) editorConfig.removePlugins = [];
  116. editorConfig.removePlugins = editorConfig.removePlugins.concat(['cloudservices','easyimage', 'exportpdf']);
  117. // CKEDITOR.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/";
  118. this.editor = CKEDITOR.replace(editorDiv, editorConfig);
  119. this.editor.on("dataReady", function(){
  120. this.editor.setReadOnly(true);
  121. }, this);
  122. }.bind(this));
  123. },
  124. destroy: function(){
  125. this.distroyCkeditor();
  126. this.form.moduleList.erase(this);
  127. this.form.moduleNodeList.erase(this.node);
  128. this.form.moduleElementNodeList.erase(this.node);
  129. if (this.form.scriptDesigner){
  130. this.form.scriptDesigner.removeModule(this.json);
  131. }
  132. if (this.property) this.property.destroy();
  133. this.node.destroy();
  134. this.actionArea.destroy();
  135. delete this.form.json.moduleList[this.json.id];
  136. this.json = null;
  137. delete this.json;
  138. this.treeNode.destroy();
  139. o2.release(this);
  140. },
  141. distroyCkeditor: function(){
  142. if (this.editor) this.editor.destroy();
  143. this.editor = null;
  144. }
  145. });