Htmleditor.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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.setStyles({
  16. "height": "auto",
  17. "max-width" : "100%"
  18. });
  19. }.bind(this))
  20. }
  21. }else{
  22. var config = Object.clone(this.json.editorProperties);
  23. if (this.json.config){
  24. if (this.json.config.code){
  25. var obj = MWF.CMSMacro.exec(this.json.config.code, this);
  26. Object.each(obj, function(v, k){
  27. config[k] = v;
  28. });
  29. }
  30. }
  31. this.loadCkeditor(config);
  32. }
  33. // this._loadValue();
  34. },
  35. loadCkeditor: function(config){
  36. _self = this;
  37. COMMON.AjaxModule.loadDom("ckeditor", function(){
  38. CKEDITOR.disableAutoInline = true;
  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. getImages : function(){
  83. var result = [];
  84. var imgaes = this.editor.document.find("img");
  85. if( imgaes ){
  86. for( var i=0; i< imgaes.$.length; i++ ){
  87. result.push( imgaes.getItem(i).$ );
  88. }
  89. }
  90. return result;
  91. },
  92. getImageIds : function(){
  93. var result = [];
  94. var images = this.getImages();
  95. for( var i=0; i<images.length; i++ ){
  96. var img = images[i];
  97. if( img.getAttribute("data-id") ){
  98. result.push( img.getAttribute("data-id") )
  99. }
  100. }
  101. return result;
  102. },
  103. _loadStyles: function(){
  104. if (this.json.styles) this.node.setStyles(this.json.styles);
  105. this.node.setStyle("overflow","hidden");
  106. },
  107. //selectCurrentDocumentImage : function( e, callback ){
  108. // var _self = this;
  109. // MWF.xDesktop.requireApp("cms.Xform", "Attachment", function(){
  110. // //_self.form.app.content
  111. // _self.selector_doc = new MWF.xApplication.cms.Xform.Attachment( document.body , {}, _self.form, {})
  112. // _self.selector_doc.loadAttachmentSelecter({
  113. // "style" : "cms",
  114. // "title": "选择本文档图片",
  115. // "listStyle": "preview",
  116. // "toBase64" : true,
  117. // "selectType" : "images"
  118. // }, function(url, data, base64Code){
  119. // if(callback)callback(url, base64Code, data);
  120. // });
  121. //
  122. // }, true);
  123. //
  124. //},
  125. //selectCloudFilesImage : function( e, callback ){
  126. // var _self = this;
  127. // MWF.xDesktop.requireApp("File", "FileSelector", function(){
  128. // //_self.form.app.content
  129. // _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
  130. // "style" : "default",
  131. // "title": "选择云文件图片",
  132. // "toBase64" : true,
  133. // "listStyle": "preview",
  134. // "selectType" : "images",
  135. // "onPostSelectAttachment" : function(url, base64Code){
  136. // if(callback)callback(url, base64Code);
  137. // }
  138. // });
  139. // _self.selector_cloud.load();
  140. // }, true);
  141. //
  142. //},
  143. validationConfigItem: function(routeName, data){
  144. var flag = (data.status=="all") ? true: (routeName == "publish");
  145. if (flag){
  146. var n = this.getData();
  147. var v = (data.valueType=="value") ? n : n.length;
  148. switch (data.operateor){
  149. case "isnull":
  150. if (!v){
  151. this.notValidationMode(data.prompt);
  152. return false;
  153. }
  154. break;
  155. case "notnull":
  156. if (v){
  157. this.notValidationMode(data.prompt);
  158. return false;
  159. }
  160. break;
  161. case "gt":
  162. if (v>data.value){
  163. this.notValidationMode(data.prompt);
  164. return false;
  165. }
  166. break;
  167. case "lt":
  168. if (v<data.value){
  169. this.notValidationMode(data.prompt);
  170. return false;
  171. }
  172. break;
  173. case "equal":
  174. if (v==data.value){
  175. this.notValidationMode(data.prompt);
  176. return false;
  177. }
  178. break;
  179. case "neq":
  180. if (v!=data.value){
  181. this.notValidationMode(data.prompt);
  182. return false;
  183. }
  184. break;
  185. case "contain":
  186. if (v.indexOf(data.value)!=-1){
  187. this.notValidationMode(data.prompt);
  188. return false;
  189. }
  190. break;
  191. case "notcontain":
  192. if (v.indexOf(data.value)==-1){
  193. this.notValidationMode(data.prompt);
  194. return false;
  195. }
  196. break;
  197. }
  198. }
  199. return true;
  200. }
  201. });