$Module.js 15 KB

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