$Module.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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"]
  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 && (parent.get("MWFtype")!="source" && parent.get("MWFtype")!="subSource" && parent.get("MWFtype")!="subSourceItem")) parent = parent.getParent();
  16. return (parent) ? parent.retrieve("module") : null;
  17. },
  18. load: function(){
  19. if (this.fireEvent("queryLoad")){
  20. this._queryLoaded();
  21. this._loadUserInterface();
  22. this._loadStyles();
  23. this._loadEvents();
  24. this._afterLoaded();
  25. this.fireEvent("postLoad");
  26. this.fireEvent("load");
  27. }
  28. },
  29. _loadUserInterface: function(){
  30. // this.node = this.node;
  31. },
  32. _loadStyles: function(){
  33. if (this.json.styles) this.node.setStyles(this.json.styles);
  34. },
  35. _loadEvents: function(){
  36. Object.each(this.json.events, function(e, key){
  37. if (e.code){
  38. if (this.options.moduleEvents.indexOf(key)!=-1){
  39. this.addEvent(key, function(event){
  40. return this.form.Macro.fire(e.code, this, event);
  41. }.bind(this));
  42. }else{
  43. this.node.addEvent(key, function(event){
  44. return this.form.Macro.fire(e.code, this, event);
  45. }.bind(this));
  46. }
  47. }
  48. }.bind(this));
  49. },
  50. _getBusinessData: function(){
  51. if (this.json.section=="yes"){
  52. return this._getBusinessSectionData();
  53. }else {
  54. return this.form.businessData.data[this.json.id] || "";
  55. }
  56. },
  57. _getBusinessSectionData: function(){
  58. switch (this.json.sectionBy){
  59. case "person":
  60. return this._getBusinessSectionDataByPerson();
  61. break;
  62. case "department":
  63. return this._getBusinessSectionDataByDepartment();
  64. break;
  65. case "activity":
  66. return this._getBusinessSectionDataByActivity();
  67. break;
  68. case "script":
  69. return this._getBusinessSectionDataByScript(this.json.sectionByScript.code);
  70. break;
  71. default:
  72. return this.form.businessData.data[this.json.id] || "";
  73. }
  74. },
  75. _getBusinessSectionDataByPerson: function(){
  76. var dataObj = this.form.businessData.data[this.json.id];
  77. return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
  78. },
  79. _getBusinessSectionDataByDepartment: function(){
  80. var dataObj = this.form.businessData.data[this.json.id];
  81. if (!dataObj) return "";
  82. var key = (this.form.businessData.task) ? this.form.businessData.task.department : "";
  83. return (key) ? (dataObj[key] || "") : "";
  84. },
  85. _getBusinessSectionDataByActivity: function(){
  86. var dataObj = this.form.businessData.data[this.json.id];
  87. if (!dataObj) return "";
  88. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  89. return (key) ? (dataObj[key] || "") : "";
  90. },
  91. _getBusinessSectionDataByScript: function(code){
  92. var dataObj = this.form.businessData.data[this.json.id];
  93. if (!dataObj) return "";
  94. var key = this.form.Macro.exec(code, this);
  95. return (key) ? (dataObj[key] || "") : "";
  96. },
  97. _setBusinessData: function(v){
  98. if (this.json.section=="yes"){
  99. this._setBusinessSectionData(v);
  100. }else {
  101. if (this.form.businessData.data[this.json.id]){
  102. this.form.businessData.data[this.json.id] = v;
  103. }else{
  104. this.form.businessData.data[this.json.id] = v;
  105. this.form.Macro.environment.setData(this.form.businessData.data);
  106. }
  107. if (this.json.isTitle) this.form.businessData.work.title = v;
  108. }
  109. },
  110. _setBusinessSectionData: function(v){
  111. switch (this.json.sectionBy){
  112. case "person":
  113. this._setBusinessSectionDataByPerson(v);
  114. break;
  115. case "department":
  116. this._setBusinessSectionDataByDepartment(v);
  117. break;
  118. case "activity":
  119. this._setBusinessSectionDataByActivity(v);
  120. break;
  121. case "script":
  122. this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v);
  123. break;
  124. default:
  125. if (this.form.businessData.data[this.json.id]){
  126. this.form.businessData.data[this.json.id] = v;
  127. }else{
  128. this.form.businessData.data[this.json.id] = v;
  129. this.form.Macro.environment.setData(this.form.businessData.data);
  130. }
  131. }
  132. },
  133. _setBusinessSectionDataByPerson: function(v){
  134. var resetData = false;
  135. var key = layout.desktop.session.user.id;
  136. var dataObj = this.form.businessData.data[this.json.id];
  137. if (!dataObj){
  138. dataObj = {};
  139. this.form.businessData.data[this.json.id] = dataObj;
  140. resetData = true;
  141. }
  142. if (!dataObj[key]) resetData = true;
  143. dataObj[key] = v;
  144. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  145. },
  146. _setBusinessSectionDataByDepartment: function(v){
  147. var resetData = false;
  148. var key = (this.form.businessData.task) ? this.form.businessData.task.department : "";
  149. if (key){
  150. var dataObj = this.form.businessData.data[this.json.id];
  151. if (!dataObj){
  152. dataObj = {};
  153. this.form.businessData.data[this.json.id] = dataObj;
  154. resetData = true;
  155. }
  156. if (!dataObj[key]) resetData = true;
  157. dataObj[key] = v;
  158. }
  159. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  160. },
  161. _setBusinessSectionDataByActivity: function(v){
  162. var resetData = false;
  163. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  164. if (key){
  165. var dataObj = this.form.businessData.data[this.json.id];
  166. if (!dataObj){
  167. dataObj = {};
  168. this.form.businessData.data[this.json.id] = dataObj;
  169. resetData = true;
  170. }
  171. if (!dataObj[key]) resetData = true;
  172. dataObj[key] = v;
  173. }
  174. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  175. },
  176. _setBusinessSectionDataByScript: function(code, v){
  177. var resetData = false;
  178. var key = this.form.Macro.exec(code, this);
  179. if (key){
  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. }
  189. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  190. },
  191. _queryLoaded: function(){},
  192. _afterLoaded: function(){},
  193. setValue: function(){
  194. },
  195. focus: function(){
  196. this.node.focus();
  197. }
  198. });