$Module.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. value = o2.filterUrl(value);
  83. }
  84. this.node.setStyle(key, value);
  85. }.bind(this));
  86. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  87. // var host = MWF.Actions.getHost(root);
  88. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  89. // }
  90. //if (this.json.styles) this.node.setStyles(this.json.styles);
  91. },
  92. _loadModuleEvents : function(){
  93. Object.each(this.json.events, function(e, key){
  94. if (e.code){
  95. if (this.options.moduleEvents.indexOf(key)!==-1){
  96. this.addEvent(key, function(event){
  97. return this.form.Macro.fire(e.code, this, event);
  98. }.bind(this));
  99. }
  100. }
  101. }.bind(this));
  102. },
  103. _loadDomEvents: function(){
  104. Object.each(this.json.events, function(e, key){
  105. if (e.code){
  106. if (this.options.moduleEvents.indexOf(key)===-1){
  107. this.node.addEvent(key, function(event){
  108. return this.form.Macro.fire(e.code, this, event);
  109. }.bind(this));
  110. }
  111. }
  112. }.bind(this));
  113. },
  114. _loadEvents: function(){
  115. Object.each(this.json.events, function(e, key){
  116. if (e.code){
  117. if (this.options.moduleEvents.indexOf(key)!==-1){
  118. this.addEvent(key, function(event){
  119. return this.form.Macro.fire(e.code, this, event);
  120. }.bind(this));
  121. }else{
  122. this.node.addEvent(key, function(event){
  123. return this.form.Macro.fire(e.code, this, event);
  124. }.bind(this));
  125. }
  126. }
  127. }.bind(this));
  128. },
  129. addModuleEvent: function(key, fun){
  130. if (this.options.moduleEvents.indexOf(key)!==-1){
  131. this.addEvent(key, function(event){
  132. return (fun) ? fun(this, event) : null;
  133. }.bind(this));
  134. }else{
  135. this.node.addEvent(key, function(event){
  136. return (fun) ? fun(this, event) : null;
  137. }.bind(this));
  138. }
  139. },
  140. _getBusinessData: function(){
  141. if (this.json.section=="yes"){
  142. return this._getBusinessSectionData();
  143. }else {
  144. if (this.json.type==="Opinion"){
  145. return this._getBusinessSectionDataByPerson();
  146. }else{
  147. return this.form.businessData.data[this.json.id] || "";
  148. }
  149. }
  150. },
  151. _getBusinessSectionData: function(){
  152. switch (this.json.sectionBy){
  153. case "person":
  154. return this._getBusinessSectionDataByPerson();
  155. case "unit":
  156. return this._getBusinessSectionDataByUnit();
  157. case "activity":
  158. return this._getBusinessSectionDataByActivity();
  159. case "splitValue":
  160. return this._getBusinessSectionDataBySplitValue();
  161. case "script":
  162. return this._getBusinessSectionDataByScript(((this.json.sectionByScript) ? this.json.sectionByScript.code : ""));
  163. default:
  164. return this.form.businessData.data[this.json.id] || "";
  165. }
  166. },
  167. _getBusinessSectionDataByPerson: function(){
  168. this.form.sectionListObj[this.json.id] = layout.desktop.session.user.id;
  169. var dataObj = this.form.businessData.data[this.json.id];
  170. return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
  171. },
  172. _getBusinessSectionDataByUnit: function(){
  173. this.form.sectionListObj[this.json.id] = "";
  174. var dataObj = this.form.businessData.data[this.json.id];
  175. if (!dataObj) return "";
  176. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  177. if (key) this.form.sectionListObj[this.json.id] = key;
  178. return (key) ? (dataObj[key] || "") : "";
  179. },
  180. _getBusinessSectionDataByActivity: function(){
  181. this.form.sectionListObj[this.json.id] = "";
  182. var dataObj = this.form.businessData.data[this.json.id];
  183. if (!dataObj) return "";
  184. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  185. if (key) this.form.sectionListObj[this.json.id] = key;
  186. return (key) ? (dataObj[key] || "") : "";
  187. },
  188. _getBusinessSectionDataBySplitValue: function(){
  189. this.form.sectionListObj[this.json.id] = "";
  190. var dataObj = this.form.businessData.data[this.json.id];
  191. if (!dataObj) return "";
  192. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  193. if (key) this.form.sectionListObj[this.json.id] = key;
  194. return (key) ? (dataObj[key] || "") : "";
  195. },
  196. _getBusinessSectionDataByScript: function(code){
  197. this.form.sectionListObj[this.json.id] = "";
  198. var dataObj = this.form.businessData.data[this.json.id];
  199. if (!dataObj) return "";
  200. var key = this.form.Macro.exec(code, this);
  201. if (key) this.form.sectionListObj[this.json.id] = key;
  202. return (key) ? (dataObj[key] || "") : "";
  203. },
  204. _setBusinessData: function(v){
  205. if (this.json.section=="yes"){
  206. this._setBusinessSectionData(v);
  207. }else {
  208. if (this.json.type==="Opinion"){
  209. this._setBusinessSectionDataByPerson(v);
  210. }else{
  211. if (this.form.businessData.data[this.json.id]){
  212. this.form.businessData.data[this.json.id] = v;
  213. }else{
  214. this.form.businessData.data[this.json.id] = v;
  215. this.form.Macro.environment.setData(this.form.businessData.data);
  216. }
  217. if (this.json.isTitle) this.form.businessData.work.title = v;
  218. }
  219. }
  220. },
  221. _setBusinessSectionData: function(v){
  222. switch (this.json.sectionBy){
  223. case "person":
  224. this._setBusinessSectionDataByPerson(v);
  225. break;
  226. case "unit":
  227. this._setBusinessSectionDataByUnit(v);
  228. break;
  229. case "activity":
  230. this._setBusinessSectionDataByActivity(v);
  231. break;
  232. case "splitValue":
  233. this._setBusinessSectionDataBySplitValue(v);
  234. break;
  235. case "script":
  236. this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v);
  237. break;
  238. default:
  239. if (this.form.businessData.data[this.json.id]){
  240. this.form.businessData.data[this.json.id] = v;
  241. }else{
  242. this.form.businessData.data[this.json.id] = v;
  243. this.form.Macro.environment.setData(this.form.businessData.data);
  244. }
  245. }
  246. },
  247. _setBusinessSectionDataByPerson: function(v){
  248. var resetData = false;
  249. var key = layout.desktop.session.user.id;
  250. var dataObj = this.form.businessData.data[this.json.id];
  251. if (!dataObj){
  252. dataObj = {};
  253. this.form.businessData.data[this.json.id] = dataObj;
  254. resetData = true;
  255. }
  256. if (!dataObj[key]) resetData = true;
  257. dataObj[key] = v;
  258. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  259. },
  260. _setBusinessSectionDataByUnit: function(v){
  261. var resetData = false;
  262. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  263. if (key){
  264. var dataObj = this.form.businessData.data[this.json.id];
  265. if (!dataObj){
  266. dataObj = {};
  267. this.form.businessData.data[this.json.id] = dataObj;
  268. resetData = true;
  269. }
  270. if (!dataObj[key]) resetData = true;
  271. dataObj[key] = v;
  272. }
  273. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  274. },
  275. _setBusinessSectionDataByActivity: function(v){
  276. var resetData = false;
  277. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  278. if (key){
  279. var dataObj = this.form.businessData.data[this.json.id];
  280. if (!dataObj){
  281. dataObj = {};
  282. this.form.businessData.data[this.json.id] = dataObj;
  283. resetData = true;
  284. }
  285. if (!dataObj[key]) resetData = true;
  286. dataObj[key] = v;
  287. }
  288. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  289. },
  290. _setBusinessSectionDataBySplitValue: function(v){
  291. var resetData = false;
  292. var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
  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. _setBusinessSectionDataByScript: function(code, v){
  306. var resetData = false;
  307. var key = this.form.Macro.exec(code, this);
  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. _queryLoaded: function(){},
  321. _afterLoaded: function(){},
  322. setValue: function(){
  323. },
  324. focus: function(){
  325. this.node.focus();
  326. }
  327. });