$Module.js 14 KB

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