Htmleditor.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. if( editorConfig.skin )editorConfig.skin = "moono-lisa";
  68. this.editor = CKEDITOR.replace(editorDiv, editorConfig);
  69. this._loadEvents();
  70. //this.editor.on("loaded", function(){
  71. // this._loadEvents();
  72. //}.bind(this));
  73. //this.setData(data)
  74. this.editor.on("change", function(){
  75. this._setBusinessData(this.getData());
  76. }.bind(this));
  77. // this._loadEvents();
  78. }.bind(this));
  79. },
  80. getText : function(){
  81. return this.editor.document.getBody().getText();
  82. },
  83. getImages : function(){
  84. var result = [];
  85. var imgaes = this.editor.document.find("img");
  86. if( imgaes ){
  87. for( var i=0; i< imgaes.$.length; i++ ){
  88. result.push( imgaes.getItem(i).$ );
  89. }
  90. }
  91. return result;
  92. },
  93. getImageIds : function(){
  94. var result = [];
  95. var images = this.getImages();
  96. for( var i=0; i<images.length; i++ ){
  97. var img = images[i];
  98. if( img.getAttribute("data-id") ){
  99. result.push( img.getAttribute("data-id") )
  100. }
  101. }
  102. return result;
  103. },
  104. _loadStyles: function(){
  105. if (this.json.styles) this.node.setStyles(this.json.styles);
  106. this.node.setStyle("overflow","hidden");
  107. },
  108. //selectCurrentDocumentImage : function( e, callback ){
  109. // var _self = this;
  110. // MWF.xDesktop.requireApp("cms.Xform", "Attachment", function(){
  111. // //_self.form.app.content
  112. // _self.selector_doc = new MWF.xApplication.cms.Xform.Attachment( document.body , {}, _self.form, {})
  113. // _self.selector_doc.loadAttachmentSelecter({
  114. // "style" : "cms",
  115. // "title": "选择本文档图片",
  116. // "listStyle": "preview",
  117. // "toBase64" : true,
  118. // "selectType" : "images"
  119. // }, function(url, data, base64Code){
  120. // if(callback)callback(url, base64Code, data);
  121. // });
  122. //
  123. // }, true);
  124. //
  125. //},
  126. //selectCloudFilesImage : function( e, callback ){
  127. // var _self = this;
  128. // MWF.xDesktop.requireApp("File", "FileSelector", function(){
  129. // //_self.form.app.content
  130. // _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
  131. // "style" : "default",
  132. // "title": "选择云文件图片",
  133. // "toBase64" : true,
  134. // "listStyle": "preview",
  135. // "selectType" : "images",
  136. // "onPostSelectAttachment" : function(url, base64Code){
  137. // if(callback)callback(url, base64Code);
  138. // }
  139. // });
  140. // _self.selector_cloud.load();
  141. // }, true);
  142. //
  143. //},
  144. validationConfigItem: function(routeName, data){
  145. var flag = (data.status=="all") ? true: (routeName == "publish");
  146. if (flag){
  147. var n = this.getData();
  148. var v = (data.valueType=="value") ? n : n.length;
  149. switch (data.operateor){
  150. case "isnull":
  151. if (!v){
  152. this.notValidationMode(data.prompt);
  153. return false;
  154. }
  155. break;
  156. case "notnull":
  157. if (v){
  158. this.notValidationMode(data.prompt);
  159. return false;
  160. }
  161. break;
  162. case "gt":
  163. if (v>data.value){
  164. this.notValidationMode(data.prompt);
  165. return false;
  166. }
  167. break;
  168. case "lt":
  169. if (v<data.value){
  170. this.notValidationMode(data.prompt);
  171. return false;
  172. }
  173. break;
  174. case "equal":
  175. if (v==data.value){
  176. this.notValidationMode(data.prompt);
  177. return false;
  178. }
  179. break;
  180. case "neq":
  181. if (v!=data.value){
  182. this.notValidationMode(data.prompt);
  183. return false;
  184. }
  185. break;
  186. case "contain":
  187. if (v.indexOf(data.value)!=-1){
  188. this.notValidationMode(data.prompt);
  189. return false;
  190. }
  191. break;
  192. case "notcontain":
  193. if (v.indexOf(data.value)==-1){
  194. this.notValidationMode(data.prompt);
  195. return false;
  196. }
  197. break;
  198. }
  199. }
  200. return true;
  201. }
  202. });