$Module.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. MWF.require("MWF.widget.Common", null, false);
  2. MWF.xApplication.process.Xform.$Module = MWF.APP$Module = new Class({
  3. Implements: [Events],
  4. options: {
  5. "moduleEvents": ["load", "queryLoad", "postLoad"]
  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. },
  13. _getSource: function(){
  14. var parent = this.node.getParent();
  15. while(parent && (
  16. parent.get("MWFtype")!="source" &&
  17. parent.get("MWFtype")!="subSource" &&
  18. parent.get("MWFtype")!="subSourceItem"
  19. )) parent = parent.getParent();
  20. return (parent) ? parent.retrieve("module") : null;
  21. },
  22. hide: function(){
  23. var dsp = this.node.getStyle("display");
  24. if (dsp!=="none") this.node.store("mwf_display", dsp);
  25. this.node.setStyle("display", "none");
  26. if (this.iconNode) this.iconNode.setStyle("display", "none");
  27. },
  28. show: function(){
  29. var dsp = this.node.retrieve("mwf_display", dsp);
  30. this.node.setStyle("display", dsp);
  31. if (this.iconNode) this.iconNode.setStyle("display", "block");
  32. },
  33. load: function(){
  34. if (this.fireEvent("queryLoad")){
  35. this._queryLoaded();
  36. this._loadUserInterface();
  37. this._loadStyles();
  38. this._loadEvents();
  39. this._afterLoaded();
  40. this.fireEvent("postLoad");
  41. this.fireEvent("load");
  42. }
  43. },
  44. _loadUserInterface: function(){
  45. // this.node = this.node;
  46. },
  47. _loadStyles: function(){
  48. if (this.json.styles) Object.each(this.json.styles, function(value, key){
  49. if ((value.indexOf("x_processplatform_assemble_surface")!=-1 || value.indexOf("x_portal_assemble_surface")!=-1)){
  50. var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface");
  51. var host2 = MWF.Actions.getHost("x_portal_assemble_surface");
  52. if (value.indexOf("/x_processplatform_assemble_surface")!==-1){
  53. value = value.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  54. }else if (value.indexOf("x_processplatform_assemble_surface")!==-1){
  55. value = value.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface");
  56. }
  57. if (value.indexOf("/x_portal_assemble_surface")!==-1){
  58. value = value.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  59. }else if (value.indexOf("x_portal_assemble_surface")!==-1){
  60. value = value.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface");
  61. }
  62. }
  63. this.node.setStyle(key, value);
  64. }.bind(this));
  65. // if (["x_processplatform_assemble_surface", "x_portal_assemble_surface"].indexOf(root.toLowerCase())!==-1){
  66. // var host = MWF.Actions.getHost(root);
  67. // return (flag==="/") ? host+this.json.template : host+"/"+this.json.template
  68. // }
  69. //if (this.json.styles) this.node.setStyles(this.json.styles);
  70. },
  71. _loadEvents: function(){
  72. Object.each(this.json.events, function(e, key){
  73. if (e.code){
  74. if (this.options.moduleEvents.indexOf(key)!=-1){
  75. this.addEvent(key, function(event){
  76. return this.form.Macro.fire(e.code, this, event);
  77. }.bind(this));
  78. }else{
  79. this.node.addEvent(key, function(event){
  80. return this.form.Macro.fire(e.code, this, event);
  81. }.bind(this));
  82. }
  83. }
  84. }.bind(this));
  85. },
  86. _getBusinessData: function(){
  87. if (this.json.section=="yes"){
  88. return this._getBusinessSectionData();
  89. }else {
  90. if (this.json.type==="Opinion"){
  91. return this._getBusinessSectionDataByPerson();
  92. }else{
  93. return this.form.businessData.data[this.json.id] || "";
  94. }
  95. }
  96. },
  97. _getBusinessSectionData: function(){
  98. switch (this.json.sectionBy){
  99. case "person":
  100. return this._getBusinessSectionDataByPerson();
  101. break;
  102. case "unit":
  103. return this._getBusinessSectionDataByUnit();
  104. break;
  105. case "activity":
  106. return this._getBusinessSectionDataByActivity();
  107. break;
  108. case "script":
  109. return this._getBusinessSectionDataByScript(this.json.sectionByScript.code);
  110. break;
  111. default:
  112. return this.form.businessData.data[this.json.id] || "";
  113. }
  114. },
  115. _getBusinessSectionDataByPerson: function(){
  116. var dataObj = this.form.businessData.data[this.json.id];
  117. return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
  118. },
  119. _getBusinessSectionDataByUnit: function(){
  120. var dataObj = this.form.businessData.data[this.json.id];
  121. if (!dataObj) return "";
  122. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  123. return (key) ? (dataObj[key] || "") : "";
  124. },
  125. _getBusinessSectionDataByActivity: function(){
  126. var dataObj = this.form.businessData.data[this.json.id];
  127. if (!dataObj) return "";
  128. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  129. return (key) ? (dataObj[key] || "") : "";
  130. },
  131. _getBusinessSectionDataByScript: function(code){
  132. var dataObj = this.form.businessData.data[this.json.id];
  133. if (!dataObj) return "";
  134. var key = this.form.Macro.exec(code, this);
  135. return (key) ? (dataObj[key] || "") : "";
  136. },
  137. _setBusinessData: function(v){
  138. if (this.json.section=="yes"){
  139. this._setBusinessSectionData(v);
  140. }else {
  141. if (this.json.type==="Opinion"){
  142. this._setBusinessSectionDataByPerson(v);
  143. }else{
  144. if (this.form.businessData.data[this.json.id]){
  145. this.form.businessData.data[this.json.id] = v;
  146. }else{
  147. this.form.businessData.data[this.json.id] = v;
  148. this.form.Macro.environment.setData(this.form.businessData.data);
  149. }
  150. if (this.json.isTitle) this.form.businessData.work.title = v;
  151. }
  152. }
  153. },
  154. _setBusinessSectionData: function(v){
  155. switch (this.json.sectionBy){
  156. case "person":
  157. this._setBusinessSectionDataByPerson(v);
  158. break;
  159. case "unit":
  160. this._setBusinessSectionDataByUnit(v);
  161. break;
  162. case "activity":
  163. this._setBusinessSectionDataByActivity(v);
  164. break;
  165. case "script":
  166. this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v);
  167. break;
  168. default:
  169. if (this.form.businessData.data[this.json.id]){
  170. this.form.businessData.data[this.json.id] = v;
  171. }else{
  172. this.form.businessData.data[this.json.id] = v;
  173. this.form.Macro.environment.setData(this.form.businessData.data);
  174. }
  175. }
  176. },
  177. _setBusinessSectionDataByPerson: function(v){
  178. var resetData = false;
  179. var key = layout.desktop.session.user.id;
  180. var dataObj = this.form.businessData.data[this.json.id];
  181. if (!dataObj){
  182. dataObj = {};
  183. this.form.businessData.data[this.json.id] = dataObj;
  184. resetData = true;
  185. }
  186. if (!dataObj[key]) resetData = true;
  187. dataObj[key] = v;
  188. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  189. },
  190. _setBusinessSectionDataByUnit: function(v){
  191. var resetData = false;
  192. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  193. if (key){
  194. var dataObj = this.form.businessData.data[this.json.id];
  195. if (!dataObj){
  196. dataObj = {};
  197. this.form.businessData.data[this.json.id] = dataObj;
  198. resetData = true;
  199. }
  200. if (!dataObj[key]) resetData = true;
  201. dataObj[key] = v;
  202. }
  203. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  204. },
  205. _setBusinessSectionDataByActivity: function(v){
  206. var resetData = false;
  207. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  208. if (key){
  209. var dataObj = this.form.businessData.data[this.json.id];
  210. if (!dataObj){
  211. dataObj = {};
  212. this.form.businessData.data[this.json.id] = dataObj;
  213. resetData = true;
  214. }
  215. if (!dataObj[key]) resetData = true;
  216. dataObj[key] = v;
  217. }
  218. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  219. },
  220. _setBusinessSectionDataByScript: function(code, v){
  221. var resetData = false;
  222. var key = this.form.Macro.exec(code, this);
  223. if (key){
  224. var dataObj = this.form.businessData.data[this.json.id];
  225. if (!dataObj){
  226. dataObj = {};
  227. this.form.businessData.data[this.json.id] = dataObj;
  228. resetData = true;
  229. }
  230. if (!dataObj[key]) resetData = true;
  231. dataObj[key] = v;
  232. }
  233. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  234. },
  235. _queryLoaded: function(){},
  236. _afterLoaded: function(){},
  237. setValue: function(){
  238. },
  239. focus: function(){
  240. this.node.focus();
  241. }
  242. });