$Module.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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) this.node.setStyles(this.json.styles);
  49. },
  50. _loadEvents: function(){
  51. Object.each(this.json.events, function(e, key){
  52. if (e.code){
  53. if (this.options.moduleEvents.indexOf(key)!=-1){
  54. this.addEvent(key, function(event){
  55. return this.form.Macro.fire(e.code, this, event);
  56. }.bind(this));
  57. }else{
  58. this.node.addEvent(key, function(event){
  59. return this.form.Macro.fire(e.code, this, event);
  60. }.bind(this));
  61. }
  62. }
  63. }.bind(this));
  64. },
  65. _getBusinessData: function(){
  66. if (this.json.section=="yes"){
  67. return this._getBusinessSectionData();
  68. }else {
  69. if (this.json.type==="Opinion"){
  70. return this._getBusinessSectionDataByPerson();
  71. }else{
  72. return this.form.businessData.data[this.json.id] || "";
  73. }
  74. }
  75. },
  76. _getBusinessSectionData: function(){
  77. switch (this.json.sectionBy){
  78. case "person":
  79. return this._getBusinessSectionDataByPerson();
  80. break;
  81. case "unit":
  82. return this._getBusinessSectionDataByUnit();
  83. break;
  84. case "activity":
  85. return this._getBusinessSectionDataByActivity();
  86. break;
  87. case "script":
  88. return this._getBusinessSectionDataByScript(this.json.sectionByScript.code);
  89. break;
  90. default:
  91. return this.form.businessData.data[this.json.id] || "";
  92. }
  93. },
  94. _getBusinessSectionDataByPerson: function(){
  95. var dataObj = this.form.businessData.data[this.json.id];
  96. return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
  97. },
  98. _getBusinessSectionDataByUnit: function(){
  99. var dataObj = this.form.businessData.data[this.json.id];
  100. if (!dataObj) return "";
  101. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  102. return (key) ? (dataObj[key] || "") : "";
  103. },
  104. _getBusinessSectionDataByActivity: function(){
  105. var dataObj = this.form.businessData.data[this.json.id];
  106. if (!dataObj) return "";
  107. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  108. return (key) ? (dataObj[key] || "") : "";
  109. },
  110. _getBusinessSectionDataByScript: function(code){
  111. var dataObj = this.form.businessData.data[this.json.id];
  112. if (!dataObj) return "";
  113. var key = this.form.Macro.exec(code, this);
  114. return (key) ? (dataObj[key] || "") : "";
  115. },
  116. _setBusinessData: function(v){
  117. if (this.json.section=="yes"){
  118. this._setBusinessSectionData(v);
  119. }else {
  120. if (this.json.type==="Opinion"){
  121. this._setBusinessSectionDataByPerson(v);
  122. }else{
  123. if (this.form.businessData.data[this.json.id]){
  124. this.form.businessData.data[this.json.id] = v;
  125. }else{
  126. this.form.businessData.data[this.json.id] = v;
  127. this.form.Macro.environment.setData(this.form.businessData.data);
  128. }
  129. if (this.json.isTitle) this.form.businessData.work.title = v;
  130. }
  131. }
  132. },
  133. _setBusinessSectionData: function(v){
  134. switch (this.json.sectionBy){
  135. case "person":
  136. this._setBusinessSectionDataByPerson(v);
  137. break;
  138. case "unit":
  139. this._setBusinessSectionDataByUnit(v);
  140. break;
  141. case "activity":
  142. this._setBusinessSectionDataByActivity(v);
  143. break;
  144. case "script":
  145. this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v);
  146. break;
  147. default:
  148. if (this.form.businessData.data[this.json.id]){
  149. this.form.businessData.data[this.json.id] = v;
  150. }else{
  151. this.form.businessData.data[this.json.id] = v;
  152. this.form.Macro.environment.setData(this.form.businessData.data);
  153. }
  154. }
  155. },
  156. _setBusinessSectionDataByPerson: function(v){
  157. var resetData = false;
  158. var key = layout.desktop.session.user.id;
  159. var dataObj = this.form.businessData.data[this.json.id];
  160. if (!dataObj){
  161. dataObj = {};
  162. this.form.businessData.data[this.json.id] = dataObj;
  163. resetData = true;
  164. }
  165. if (!dataObj[key]) resetData = true;
  166. dataObj[key] = v;
  167. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  168. },
  169. _setBusinessSectionDataByUnit: function(v){
  170. var resetData = false;
  171. var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
  172. if (key){
  173. var dataObj = this.form.businessData.data[this.json.id];
  174. if (!dataObj){
  175. dataObj = {};
  176. this.form.businessData.data[this.json.id] = dataObj;
  177. resetData = true;
  178. }
  179. if (!dataObj[key]) resetData = true;
  180. dataObj[key] = v;
  181. }
  182. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  183. },
  184. _setBusinessSectionDataByActivity: function(v){
  185. var resetData = false;
  186. var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
  187. if (key){
  188. var dataObj = this.form.businessData.data[this.json.id];
  189. if (!dataObj){
  190. dataObj = {};
  191. this.form.businessData.data[this.json.id] = dataObj;
  192. resetData = true;
  193. }
  194. if (!dataObj[key]) resetData = true;
  195. dataObj[key] = v;
  196. }
  197. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  198. },
  199. _setBusinessSectionDataByScript: function(code, v){
  200. var resetData = false;
  201. var key = this.form.Macro.exec(code, this);
  202. if (key){
  203. var dataObj = this.form.businessData.data[this.json.id];
  204. if (!dataObj){
  205. dataObj = {};
  206. this.form.businessData.data[this.json.id] = dataObj;
  207. resetData = true;
  208. }
  209. if (!dataObj[key]) resetData = true;
  210. dataObj[key] = v;
  211. }
  212. if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
  213. },
  214. _queryLoaded: function(){},
  215. _afterLoaded: function(){},
  216. setValue: function(){
  217. },
  218. focus: function(){
  219. this.node.focus();
  220. }
  221. });