Htmleditor.js 6.8 KB

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