$Module.js 7.1 KB

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