$Module.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. MWF.require("MWF.widget.Common", null, false);
  2. /** @classdesc $Module 组件类,此类为所有组件的父类。
  3. * @class
  4. * @hideconstructor
  5. * */
  6. MWF.xApplication.process.Xform.$Module = MWF.APP$Module = new Class(
  7. /** @lends MWF.xApplication.process.Xform.$Module# */
  8. {
  9. Implements: [Events],
  10. options: {
  11. /**
  12. * 组件加载前事件。<br/>
  13. * 平台执行queryLoad事件的时候,组件还没有开始加载,这个时候可以根据条件修改组件的配置信息以改变加载细节。
  14. * @event MWF.xApplication.process.Xform.$Module#queryLoad
  15. * @example
  16. * var field = this.form.get("fieldName");
  17. * field.addEvent("queryLoad", function(){
  18. *
  19. * };
  20. */
  21. /**
  22. * 组件加载事件.
  23. * @event MWF.xApplication.process.Xform.$Module#load
  24. */
  25. /**
  26. * 组件加载后事件.
  27. * @event MWF.xApplication.process.Xform.$Module#postLoad
  28. */
  29. "moduleEvents": ["load", "queryLoad", "postLoad"]
  30. },
  31. initialize: function(node, json, form, options){
  32. /**
  33. * @summary 组件的节点
  34. * @see https://mootools.net/core/docs/1.6.0/Element/Element
  35. * @member {Element}
  36. * @example
  37. * //可以在脚本中获取该组件
  38. * var field = this.form.get("fieldName"); //获取组件对象
  39. * field.node.setStyle("font-size","12px"); //给节点设置样式
  40. */
  41. this.node = $(node);
  42. this.node.store("module", this);
  43. /**
  44. * @summary 组件的配置信息,比如id,类型等.
  45. * @member {JsonObject}
  46. * @example
  47. * //可以在脚本中获取该组件
  48. * var json = this.form.get("fieldName").json; //获取组件对象
  49. * var id = json.id; //获取组件的id
  50. * var type = json.type; //获取组件的类型,如Textfield 为文本输入组件,Select为下拉组件
  51. */
  52. this.json = json;
  53. /**
  54. * @summary 组件的所在表单对象.
  55. * @member {MWF.xApplication.process.Xform.Form}
  56. * @example
  57. * var form = this.form.get("fieldName").form; //获取组件所在表单对象
  58. * form.saveFormData(); //保存表单数据
  59. */
  60. this.form = form;
  61. },
  62. _getSource: function(){
  63. var parent = this.node.getParent();
  64. while(parent && (
  65. parent.get("MWFtype")!="source" &&
  66. parent.get("MWFtype")!="subSource" &&
  67. parent.get("MWFtype")!="subSourceItem"
  68. )) parent = parent.getParent();
  69. return (parent) ? parent.retrieve("module") : null;
  70. },
  71. /**
  72. * @summary 隐藏组件.
  73. * @example
  74. * this.form.get("fieldName").hide(); //隐藏组件
  75. */
  76. hide: function(){
  77. var dsp = this.node.getStyle("display");
  78. if (dsp!=="none") this.node.store("mwf_display", dsp);
  79. this.node.setStyle("display", "none");
  80. if (this.iconNode) this.iconNode.setStyle("display", "none");
  81. },
  82. /**
  83. * @summary 显示组件.
  84. * @example
  85. * this.form.get("fieldName").show(); //显示组件
  86. */
  87. show: function(){
  88. var dsp = this.node.retrieve("mwf_display", dsp);
  89. this.node.setStyle("display", dsp);
  90. if (this.iconNode) this.iconNode.setStyle("display", "block");
  91. },
  92. load: function(){
  93. this._loadModuleEvents();
  94. if (this.fireEvent("queryLoad")){
  95. this._queryLoaded();
  96. this._loadUserInterface();
  97. this._loadStyles();
  98. this._loadDomEvents();
  99. //this._loadEvents();
  100. this._afterLoaded();
  101. this.fireEvent("postLoad");
  102. this.fireEvent("load");
  103. }
  104. },
  105. _loadUserInterface: function(){
  106. // this.node = this.node;
  107. },
  108. _loadStyles: function(){
  109. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  110. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1 || value.indexOf("x_cms_assemble_control")!=-1)){
  111. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  112. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  113. var host3 = MWF.Actions.getHost("x_cms_assemble_control");
  114. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  115. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  116. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  117. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  118. }
  119. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  120. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  121. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  122. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  123. }
  124. if (value.indexOf("/x_cms_assemble_control")!==-1){
  125. value = value.replace("/x_cms_assemble_control", host3+"/x_cms_assemble_control");
  126. }else if (value.indexOf("x_cms_assemble_control")!==-1){
  127. value = value.replace("x_cms_assemble_control", host3+"/x_cms_assemble_control");
  128. }
  129. value = o2.filterUrl(value);
  130. }
  131. this.node.setStyle(key, value);
  132. }.bind(this));
  133. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  134. // var host = MWF.Actions.getHost(root);
  135. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  136. // }
  137. //if (this.json.styles) this.node.setStyles(this.json.styles);
  138. },
  139. _loadModuleEvents : function(){
  140. Object.each(this.json.events, function(e, key){
  141. if (e.code){
  142. if (this.options.moduleEvents.indexOf(key)!==-1){
  143. this.addEvent(key, function(event){
  144. return this.form.Macro.fire(e.code, this, event);
  145. }.bind(this));
  146. }
  147. }
  148. }.bind(this));
  149. },
  150. _loadDomEvents: function(){
  151. Object.each(this.json.events, function(e, key){
  152. if (e.code){
  153. if (this.options.moduleEvents.indexOf(key)===-1){
  154. this.node.addEvent(key, function(event){
  155. return this.form.Macro.fire(e.code, this, event);
  156. }.bind(this));
  157. }
  158. }
  159. }.bind(this));
  160. },
  161. _loadEvents: function(){
  162. Object.each(this.json.events, function(e, key){
  163. if (e.code){
  164. if (this.options.moduleEvents.indexOf(key)!==-1){
  165. this.addEvent(key, function(event){
  166. return this.form.Macro.fire(e.code, this, event);
  167. }.bind(this));
  168. }else{
  169. this.node.addEvent(key, function(event){
  170. return this.form.Macro.fire(e.code, this, event);
  171. }.bind(this));
  172. }
  173. }
  174. }.bind(this));
  175. },
  176. addModuleEvent: function(key, fun){
  177. if (this.options.moduleEvents.indexOf(key)!==-1){
  178. this.addEvent(key, function(event){
  179. return (fun) ? fun(this, event) : null;
  180. }.bind(this));
  181. }else{
  182. this.node.addEvent(key, function(event){
  183. return (fun) ? fun(this, event) : null;
  184. }.bind(this));
  185. }
  186. },
  187. _getBusinessData: function(){
  188. if (this.json.section=="yes"){
  189. return this._getBusinessSectionData();
  190. }else {
  191. if (this.json.type==="Opinion"){
  192. return this._getBusinessSectionDataByPerson();
  193. }else{
  194. return this.form.businessData.data[this.json.id] || "";
  195. }
  196. }
  197. },
  198. _getBusinessSectionData: function(){
  199. switch (this.json.sectionBy){
  200. case "person":
  201. return this._getBusinessSectionDataByPerson();
  202. case "unit":
  203. return this._getBusinessSectionDataByUnit();
  204. case "activity":
  205. return this._getBusinessSectionDataByActivity();
  206. case "splitValue":
  207. return this._getBusinessSectionDataBySplitValue();
  208. case "script":
  209. return this._getBusinessSectionDataByScript(((this.json.sectionByScript) ? this.json.sectionByScript.code : ""));
  210. default:
  211. return this.form.businessData.data[this.json.id] || "";
  212. }
  213. },
  214. _getBusinessSectionDataByPerson: function(){
  215. this.form.sectionListObj[this.json.id] = layout.desktop.session.user.id;
  216. var dataObj = this.form.businessData.data[this.json.id];
  217. return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
  218. },
  219. _getBusinessSectionDataByUnit: function(){
  220. this.form.sectionListObj[this.json.id] = "";
  221. var dataObj = this.form.businessData.data[this.json.id];
  222. if (!dataObj) return "";
  223. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  224. if (key) this.form.sectionListObj[this.json.id] = key;
  225. return (key) ? (dataObj[key] || "") : "";
  226. },
  227. _getBusinessSectionDataByActivity: function(){
  228. this.form.sectionListObj[this.json.id] = "";
  229. var dataObj = this.form.businessData.data[this.json.id];
  230. if (!dataObj) return "";
  231. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  232. if (key) this.form.sectionListObj[this.json.id] = key;
  233. return (key) ? (dataObj[key] || "") : "";
  234. },
  235. _getBusinessSectionDataBySplitValue: function(){
  236. this.form.sectionListObj[this.json.id] = "";
  237. var dataObj = this.form.businessData.data[this.json.id];
  238. if (!dataObj) return "";
  239. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  240. if (key) this.form.sectionListObj[this.json.id] = key;
  241. return (key) ? (dataObj[key] || "") : "";
  242. },
  243. _getBusinessSectionDataByScript: function(code){
  244. this.form.sectionListObj[this.json.id] = "";
  245. var dataObj = this.form.businessData.data[this.json.id];
  246. if (!dataObj) return "";
  247. var key = this.form.Macro.exec(code, this);
  248. if (key) this.form.sectionListObj[this.json.id] = key;
  249. return (key) ? (dataObj[key] || "") : "";
  250. },
  251. _setBusinessData: function(v){
  252. if (this.json.section=="yes"){
  253. this._setBusinessSectionData(v);
  254. }else {
  255. if (this.json.type==="Opinion"){
  256. this._setBusinessSectionDataByPerson(v);
  257. }else{
  258. if (this.form.businessData.data[this.json.id]){
  259. this.form.businessData.data[this.json.id] = v;
  260. }else{
  261. this.form.businessData.data[this.json.id] = v;
  262. this.form.Macro.environment.setData(this.form.businessData.data);
  263. }
  264. if (this.json.isTitle) this.form.businessData.work.title = v;
  265. }
  266. }
  267. },
  268. _setBusinessSectionData: function(v){
  269. switch (this.json.sectionBy){
  270. case "person":
  271. this._setBusinessSectionDataByPerson(v);
  272. break;
  273. case "unit":
  274. this._setBusinessSectionDataByUnit(v);
  275. break;
  276. case "activity":
  277. this._setBusinessSectionDataByActivity(v);
  278. break;
  279. case "splitValue":
  280. this._setBusinessSectionDataBySplitValue(v);
  281. break;
  282. case "script":
  283. this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v);
  284. break;
  285. default:
  286. if (this.form.businessData.data[this.json.id]){
  287. this.form.businessData.data[this.json.id] = v;
  288. }else{
  289. this.form.businessData.data[this.json.id] = v;
  290. this.form.Macro.environment.setData(this.form.businessData.data);
  291. }
  292. }
  293. },
  294. _setBusinessSectionDataByPerson: function(v){
  295. var resetData = false;
  296. var key = layout.desktop.session.user.id;
  297. var dataObj = this.form.businessData.data[this.json.id];
  298. if (!dataObj){
  299. dataObj = {};
  300. this.form.businessData.data[this.json.id] = dataObj;
  301. resetData = true;
  302. }
  303. if (!dataObj[key]) resetData = true;
  304. dataObj[key] = v;
  305. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  306. },
  307. _setBusinessSectionDataByUnit: function(v){
  308. var resetData = false;
  309. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  310. if (key){
  311. var dataObj = this.form.businessData.data[this.json.id];
  312. if (!dataObj){
  313. dataObj = {};
  314. this.form.businessData.data[this.json.id] = dataObj;
  315. resetData = true;
  316. }
  317. if (!dataObj[key]) resetData = true;
  318. dataObj[key] = v;
  319. }
  320. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  321. },
  322. _setBusinessSectionDataByActivity: function(v){
  323. var resetData = false;
  324. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  325. if (key){
  326. var dataObj = this.form.businessData.data[this.json.id];
  327. if (!dataObj){
  328. dataObj = {};
  329. this.form.businessData.data[this.json.id] = dataObj;
  330. resetData = true;
  331. }
  332. if (!dataObj[key]) resetData = true;
  333. dataObj[key] = v;
  334. }
  335. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  336. },
  337. _setBusinessSectionDataBySplitValue: function(v){
  338. var resetData = false;
  339. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  340. if (key){
  341. var dataObj = this.form.businessData.data[this.json.id];
  342. if (!dataObj){
  343. dataObj = {};
  344. this.form.businessData.data[this.json.id] = dataObj;
  345. resetData = true;
  346. }
  347. if (!dataObj[key]) resetData = true;
  348. dataObj[key] = v;
  349. }
  350. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  351. },
  352. _setBusinessSectionDataByScript: function(code, v){
  353. var resetData = false;
  354. var key = this.form.Macro.exec(code, this);
  355. if (key){
  356. var dataObj = this.form.businessData.data[this.json.id];
  357. if (!dataObj){
  358. dataObj = {};
  359. this.form.businessData.data[this.json.id] = dataObj;
  360. resetData = true;
  361. }
  362. if (!dataObj[key]) resetData = true;
  363. dataObj[key] = v;
  364. }
  365. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  366. },
  367. _queryLoaded: function(){},
  368. _afterLoaded: function(){},
  369. setValue: function(){
  370. },
  371. focus: function(){
  372. this.node.focus();
  373. }
  374. });