Htmleditor.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.Htmleditor = MWF.APPHtmleditor = new Class({
  3. Extends: MWF.APP$Module,
  4. options: {
  5. "moduleEvents": ["load", "postLoad", "afterLoad"]
  6. },
  7. initialize: function(node, json, form, options){
  8. this.node = $(node);
  9. this.node.store("module", this);
  10. this.json = json;
  11. this.form = form;
  12. this.field = true;
  13. },
  14. load: function(){
  15. if (this.fireEvent("queryLoad")){
  16. this._queryLoaded();
  17. this._loadUserInterface();
  18. this._loadStyles();
  19. //this._loadEvents();
  20. this._afterLoaded();
  21. this.fireEvent("postLoad");
  22. this.fireEvent("load");
  23. }
  24. },
  25. _loadUserInterface: function(){
  26. this.node.empty();
  27. if (this.readonly){
  28. this.node.set("html", this._getBusinessData());
  29. this.node.setStyles({
  30. "-webkit-user-select": "text",
  31. "-moz-user-select": "text"
  32. });
  33. }else{
  34. var config = Object.clone(this.json.editorProperties);
  35. if (this.json.config){
  36. if (this.json.config.code){
  37. var obj = MWF.Macro.exec(this.json.config.code, this);
  38. Object.each(obj, function(v, k){
  39. config[k] = v;
  40. });
  41. }
  42. }
  43. this.loadCkeditor(config);
  44. }
  45. // this._loadValue();
  46. },
  47. loadCkeditor: function(config){
  48. COMMON.AjaxModule.loadDom("ckeditor", function(){
  49. var editorDiv = new Element("div").inject(this.node);
  50. var htmlData = this._getBusinessData();
  51. if (htmlData){
  52. editorDiv.set("html", htmlData);
  53. }else if (this.json.templateCode){
  54. editorDiv.set("html", this.json.templateCode);
  55. }
  56. var height = this.node.getSize().y;
  57. var editorConfig = config || {};
  58. if (this.form.json.mode==="Mobile"){
  59. if (!editorConfig.toolbar && !editorConfig.toolbarGroups){
  60. editorConfig.toolbar = [
  61. { name: 'paragraph', items: [ 'Bold', 'Italic', "-" , 'TextColor', "BGColor", 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', "-", 'Undo', 'Redo' ] },
  62. { name: 'basicstyles', items: [ 'Styles', 'FontSize']}
  63. ];
  64. }
  65. }
  66. // CKEDITOR.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/";
  67. // CKEDITOR.plugins.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/plugins/";
  68. editorConfig.localImageMaxWidth = 800;
  69. editorConfig.reference = this.form.businessData.work.job;
  70. editorConfig.referenceType = "processPlatformJob";
  71. this.editor = CKEDITOR.replace(editorDiv, editorConfig);
  72. this._loadEvents();
  73. //this.editor.on("loaded", function(){
  74. // this._loadEvents();
  75. //}.bind(this));
  76. //this.setData(data)
  77. this.editor.on("change", function(){
  78. this._setBusinessData(this.getData());
  79. }.bind(this));
  80. // this._loadEvents();
  81. }.bind(this));
  82. },
  83. _loadEvents: function(editorConfig){
  84. Object.each(this.json.events, function(e, key){
  85. if (e.code){
  86. this.editor.on(key, function(event){
  87. return this.form.Macro.fire(e.code, this, event);
  88. }.bind(this), this);
  89. }
  90. }.bind(this));
  91. },
  92. _loadValue: function(){
  93. var data = this._getBusinessData();
  94. },
  95. resetData: function(){
  96. this.setData(this._getBusinessData());
  97. },
  98. getData: function(){
  99. return this.editor.getData();
  100. },
  101. setData: function(data){
  102. this._setBusinessData(data);
  103. if (this.editor) this.editor.setData(data);
  104. },
  105. createErrorNode: function(text){
  106. var node = new Element("div");
  107. var iconNode = new Element("div", {
  108. "styles": {
  109. "width": "20px",
  110. "height": "20px",
  111. "float": "left",
  112. "background": "url("+"/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
  113. }
  114. }).inject(node);
  115. var textNode = new Element("div", {
  116. "styles": {
  117. "line-height": "20px",
  118. "margin-left": "20px",
  119. "color": "red"
  120. },
  121. "text": text
  122. }).inject(node);
  123. return node;
  124. },
  125. notValidationMode: function(text){
  126. if (!this.isNotValidationMode){
  127. this.isNotValidationMode = true;
  128. this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
  129. this.node.setStyle("border", "1px solid red");
  130. this.errNode = this.createErrorNode(text).inject(this.node, "after");
  131. this.showNotValidationMode(this.node);
  132. }
  133. },
  134. showNotValidationMode: function(node){
  135. var p = node.getParent("div");
  136. if (p){
  137. if (p.get("MWFtype") == "tab$Content"){
  138. if (p.getParent("div").getStyle("display")=="none"){
  139. var contentAreaNode = p.getParent("div").getParent("div");
  140. var tabAreaNode = contentAreaNode.getPrevious("div");
  141. var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
  142. var tabNode = tabAreaNode.getChildren()[idx];
  143. tabNode.click();
  144. p = tabAreaNode.getParent("div");
  145. }
  146. }
  147. this.showNotValidationMode(p);
  148. }
  149. },
  150. validationMode: function(){
  151. if (this.isNotValidationMode){
  152. this.isNotValidationMode = false;
  153. this.node.setStyles(this.node.retrieve("borderStyle"));
  154. if (this.errNode){
  155. this.errNode.destroy();
  156. this.errNode = null;
  157. }
  158. }
  159. },
  160. validationConfigItem: function(routeName, data){
  161. var flag = (data.status=="all") ? true: (routeName == data.decision);
  162. if (flag){
  163. var n = this.getData();
  164. var v = (data.valueType=="value") ? n : n.length;
  165. switch (data.operateor){
  166. case "isnull":
  167. if (!v){
  168. this.notValidationMode(data.prompt);
  169. return false;
  170. }
  171. break;
  172. case "notnull":
  173. if (v){
  174. this.notValidationMode(data.prompt);
  175. return false;
  176. }
  177. break;
  178. case "gt":
  179. if (v>data.value){
  180. this.notValidationMode(data.prompt);
  181. return false;
  182. }
  183. break;
  184. case "lt":
  185. if (v<data.value){
  186. this.notValidationMode(data.prompt);
  187. return false;
  188. }
  189. break;
  190. case "equal":
  191. if (v==data.value){
  192. this.notValidationMode(data.prompt);
  193. return false;
  194. }
  195. break;
  196. case "neq":
  197. if (v!=data.value){
  198. this.notValidationMode(data.prompt);
  199. return false;
  200. }
  201. break;
  202. case "contain":
  203. if (v.indexOf(data.value)!=-1){
  204. this.notValidationMode(data.prompt);
  205. return false;
  206. }
  207. break;
  208. case "notcontain":
  209. if (v.indexOf(data.value)==-1){
  210. this.notValidationMode(data.prompt);
  211. return false;
  212. }
  213. break;
  214. }
  215. }
  216. return true;
  217. },
  218. validationConfig: function(routeName, opinion){
  219. if (this.json.validationConfig){
  220. if (this.json.validationConfig.length){
  221. for (var i=0; i<this.json.validationConfig.length; i++) {
  222. var data = this.json.validationConfig[i];
  223. if (!this.validationConfigItem(routeName, data)) return false;
  224. }
  225. }
  226. return true;
  227. }
  228. return true;
  229. },
  230. validation: function(routeName, opinion){
  231. if (!this.validationConfig(routeName, opinion)) return false;
  232. if (!this.json.validation) return true;
  233. if (!this.json.validation.code) return true;
  234. var flag = this.form.Macro.exec(this.json.validation.code, this);
  235. if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
  236. if (flag.toString()!="true"){
  237. this.notValidationMode(flag);
  238. return false;
  239. }
  240. return true;
  241. }
  242. });