Htmleditor.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. MWF.xDesktop.requireApp("process.Xform", "Htmleditor", null, false);
  2. MWF.xApplication.cms.Xform.Htmleditor = MWF.CMSHtmleditor = new Class({
  3. Extends: MWF.APPHtmleditor,
  4. _loadUserInterface: function(){
  5. this.node.empty();
  6. if (this.readonly){
  7. this.node.set("html", this._getBusinessData());
  8. debugger;
  9. this.node.setStyles({
  10. "-webkit-user-select": "text",
  11. "-moz-user-select": "text"
  12. });
  13. if( layout.mobile ){
  14. this.node.getElements("img").each( function( img ){
  15. //if( img.height )img.erase("height");
  16. img.setStyles({
  17. "height": "auto",
  18. "max-width" : "100%"
  19. });
  20. }.bind(this))
  21. }
  22. }else{
  23. var config = Object.clone(this.json.editorProperties);
  24. if (this.json.config){
  25. if (this.json.config.code){
  26. var obj = MWF.CMSMacro.exec(this.json.config.code, this);
  27. Object.each(obj, function(v, k){
  28. config[k] = v;
  29. });
  30. }
  31. }
  32. this.loadCkeditor(config);
  33. }
  34. // this._loadValue();
  35. },
  36. loadCkeditor: function(config){
  37. _self = this;
  38. COMMON.AjaxModule.loadDom("ckeditor", function(){
  39. var editorDiv = new Element("div").inject(this.node);
  40. var htmlData = this._getBusinessData();
  41. if (htmlData){
  42. editorDiv.set("html", htmlData);
  43. }else if (this.json.templateCode){
  44. editorDiv.set("html", this.json.templateCode);
  45. }
  46. var height = this.node.getSize().y;
  47. var editorConfig = config || {};
  48. if (this.form.json.mode=="Mobile"){
  49. if (!editorConfig.toolbar && !editorConfig.toolbarGroups){
  50. editorConfig.toolbar = [
  51. { name: 'paragraph', items: [ 'Bold', 'Italic', "-" , 'TextColor', "BGColor", 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', "-", 'Undo', 'Redo' ] },
  52. { name: 'basicstyles', items: [ 'Styles', 'FontSize']}
  53. ];
  54. }
  55. }
  56. // CKEDITOR.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/";
  57. // CKEDITOR.plugins.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/plugins/";
  58. //editorConfig.filebrowserCurrentDocumentImage = function( e, callback ){
  59. // _self.selectCurrentDocumentImage( e, callback );
  60. //};
  61. //editorConfig.filebrowserFilesImage = function( e, callback ){
  62. // _self.selectCloudFilesImage( e, callback );
  63. //};
  64. editorConfig.localImageMaxWidth = 800;
  65. editorConfig.reference = this.form.businessData.document.id;
  66. editorConfig.referenceType = "cmsDocument";
  67. this.editor = CKEDITOR.replace(editorDiv, editorConfig);
  68. this._loadEvents();
  69. //this.editor.on("loaded", function(){
  70. // this._loadEvents();
  71. //}.bind(this));
  72. //this.setData(data)
  73. this.editor.on("change", function(){
  74. this._setBusinessData(this.getData());
  75. }.bind(this));
  76. // this._loadEvents();
  77. }.bind(this));
  78. },
  79. getText : function(){
  80. return this.editor.document.getBody().getText();
  81. },
  82. _loadStyles: function(){
  83. if (this.json.styles) this.node.setStyles(this.json.styles);
  84. this.node.setStyle("overflow","hidden");
  85. },
  86. //selectCurrentDocumentImage : function( e, callback ){
  87. // var _self = this;
  88. // MWF.xDesktop.requireApp("cms.Xform", "Attachment", function(){
  89. // //_self.form.app.content
  90. // _self.selector_doc = new MWF.xApplication.cms.Xform.Attachment( document.body , {}, _self.form, {})
  91. // _self.selector_doc.loadAttachmentSelecter({
  92. // "style" : "cms",
  93. // "title": "选择本文档图片",
  94. // "listStyle": "preview",
  95. // "toBase64" : true,
  96. // "selectType" : "images"
  97. // }, function(url, data, base64Code){
  98. // if(callback)callback(url, base64Code, data);
  99. // });
  100. //
  101. // }, true);
  102. //
  103. //},
  104. //selectCloudFilesImage : function( e, callback ){
  105. // var _self = this;
  106. // MWF.xDesktop.requireApp("File", "FileSelector", function(){
  107. // //_self.form.app.content
  108. // _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
  109. // "style" : "default",
  110. // "title": "选择云文件图片",
  111. // "toBase64" : true,
  112. // "listStyle": "preview",
  113. // "selectType" : "images",
  114. // "onPostSelectAttachment" : function(url, base64Code){
  115. // if(callback)callback(url, base64Code);
  116. // }
  117. // });
  118. // _self.selector_cloud.load();
  119. // }, true);
  120. //
  121. //},
  122. validationConfigItem: function(routeName, data){
  123. var flag = (data.status=="all") ? true: (routeName == "publish");
  124. if (flag){
  125. var n = this.getData();
  126. var v = (data.valueType=="value") ? n : n.length;
  127. switch (data.operateor){
  128. case "isnull":
  129. if (!v){
  130. this.notValidationMode(data.prompt);
  131. return false;
  132. }
  133. break;
  134. case "notnull":
  135. if (v){
  136. this.notValidationMode(data.prompt);
  137. return false;
  138. }
  139. break;
  140. case "gt":
  141. if (v>data.value){
  142. this.notValidationMode(data.prompt);
  143. return false;
  144. }
  145. break;
  146. case "lt":
  147. if (v<data.value){
  148. this.notValidationMode(data.prompt);
  149. return false;
  150. }
  151. break;
  152. case "equal":
  153. if (v==data.value){
  154. this.notValidationMode(data.prompt);
  155. return false;
  156. }
  157. break;
  158. case "neq":
  159. if (v!=data.value){
  160. this.notValidationMode(data.prompt);
  161. return false;
  162. }
  163. break;
  164. case "contain":
  165. if (v.indexOf(data.value)!=-1){
  166. this.notValidationMode(data.prompt);
  167. return false;
  168. }
  169. break;
  170. case "notcontain":
  171. if (v.indexOf(data.value)==-1){
  172. this.notValidationMode(data.prompt);
  173. return false;
  174. }
  175. break;
  176. }
  177. }
  178. return true;
  179. }
  180. });