Main.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. MWF.xApplication.process.Work.options.multitask = true;
  2. MWF.xApplication.process.Work.Main = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "name": "process.Work",
  8. "icon": "icon.png",
  9. "width": "1200",
  10. "height": "800",
  11. "title": MWF.xApplication.process.Work.LP.title,
  12. "workId": "",
  13. "workCompletedId": "",
  14. "taskId": "",
  15. "isControl": false,
  16. "taskObject": null,
  17. "readonly": false
  18. },
  19. onQueryLoad: function(){
  20. this.lp = MWF.xApplication.process.Work.LP;
  21. if (!this.status) {
  22. } else {
  23. this.options.workId = this.status.workId;
  24. this.options.workCompletedId = this.status.workCompletedId;
  25. this.options.readonly = (this.status.readonly === "true");
  26. }
  27. this.action = MWF.Actions.get("x_processplatform_assemble_surface");
  28. },
  29. loadApplication: function(callback){
  30. this.node = new Element("div", {"styles": this.css.content}).inject(this.content);
  31. MWF.require("MWF.widget.Mask", function(){
  32. this.mask = new MWF.widget.Mask({"style": "desktop"});
  33. this.formNode = new Element("div", {"styles": this.css.formNode}).inject(this.node);
  34. if (!this.options.isRefresh){
  35. this.maxSize(function(){
  36. this.mask.loadNode(this.content);
  37. this.loadWork();
  38. }.bind(this));
  39. }else{
  40. this.mask.loadNode(this.content);
  41. this.loadWork();
  42. }
  43. if (callback) callback();
  44. //}.bind(this));
  45. }.bind(this));
  46. this.addEvent("postClose", function(){
  47. //this.refreshTaskCenter();
  48. }.bind(this));
  49. this.addKeyboardEvents();
  50. },
  51. refreshTaskCenter: function(){
  52. if (this.desktop.apps){
  53. if (this.desktop.apps["TaskCenter"]){
  54. this.desktop.apps["TaskCenter"].content.unmask();
  55. this.desktop.apps["TaskCenter"].refreshAll();
  56. }
  57. }
  58. },
  59. addKeyboardEvents: function(){
  60. this.addEvent("keySave", function(e){
  61. this.keySave(e);
  62. }.bind(this));
  63. },
  64. keySave: function(e){
  65. if (this.appForm){
  66. if (!this.options.readonly){
  67. this.appForm.saveWork();
  68. e.preventDefault();
  69. }
  70. }
  71. },
  72. reload: function(data){
  73. if (this.form){
  74. this.formNode.empty();
  75. MWF.release(this.form);
  76. this.form = null;
  77. }
  78. if (data){
  79. this.parseData(data);
  80. this.openWork();
  81. }else{
  82. this.loadWork();
  83. }
  84. },
  85. loadWork: function(){
  86. // var method = "";
  87. var id = this.options.workCompletedId || this.options.workId;
  88. // var methods = {
  89. // "loadWork": false,
  90. // "getWorkControl": false,
  91. // "getForm": false
  92. // };
  93. if (id){
  94. debugger;
  95. MWF.Actions.invokeAsync([
  96. {"action": this.action, "name": "loadWork"},
  97. {"action": this.action, "name": "getWorkControl"},
  98. {"action": this.action, "name": (layout.mobile) ? "getWorkFormMobile": "getWorkForm"},
  99. {"action": this.action, "name": "getWorkLog"},
  100. {"action": this.action, "name": "listAttachments"}
  101. ], {"success": function(json_work, json_control, json_form, json_log, json_att){
  102. if (json_work && json_control && json_form && json_log && json_att){
  103. this.parseData(json_work.data, json_control.data, json_form.data, json_log.data, json_att.data);
  104. if (this.mask) this.mask.hide();
  105. if (layout.mobile) this.loadMobileActions();
  106. this.openWork();
  107. } else{
  108. this.close();
  109. }
  110. }.bind(this), "failure": function(){}}, id);
  111. }
  112. },
  113. parseData: function(workData, controlData, formData, logData, attData){
  114. debugger;
  115. var title = workData.work.title;
  116. this.setTitle(this.options.title+"-"+title);
  117. this.activity = workData.activity;
  118. this.data = workData.data;
  119. this.taskList = workData.taskList;
  120. this.currentTask = this.getCurrentTaskData(workData);
  121. this.taskList = workData.taskList;
  122. this.readList = workData.readList;
  123. this.work = workData.work;
  124. this.workCompleted = (workData.work.completedTime) ? workData.work : null;
  125. this.workLogList = logData;
  126. this.attachmentList = attData;
  127. //this.inheritedAttachmentList = data.inheritedAttachmentList;
  128. this.control = controlData;
  129. this.form = (formData.data) ? JSON.decode(MWF.decodeJsonString(formData.data)): null;
  130. delete formData.data;
  131. this.formInfor = formData;
  132. },
  133. // loadWork2: function(){
  134. // var method = "";
  135. // var id = "";
  136. //
  137. // if (this.options.workCompletedId){
  138. // method = (layout.mobile) ? "getJobByWorkCompletedMobile" : "getJobByWorkCompleted";
  139. // id = this.options.workCompletedId;
  140. // }else if (this.options.workId) {
  141. // method = (layout.mobile) ? "getJobByWorkMobile" : "getJobByWork";
  142. // id = this.options.workId;
  143. // }
  144. // if (method && id){
  145. // this.action[method](function(json){
  146. // if (this.mask) this.mask.hide();
  147. // this.parseData(json.data);
  148. // if (layout.mobile) this.loadMobileActions();
  149. // this.openWork();
  150. // }.bind(this), function(){
  151. // this.close();
  152. // }.bind(this), id);
  153. // }
  154. // },
  155. loadMobileActions: function(){
  156. if( this.control.allowSave || this.control.allowProcessing ){
  157. this.mobileActionBarNode = new Element("div", {"styles": this.css.mobileActionBarNode}).inject(this.node, "after");
  158. var size = this.content.getSize();
  159. var y = size.y-40;
  160. this.node.setStyles({
  161. "height": ""+y+"px",
  162. "min-height": ""+y+"px",
  163. "overflow": "auto",
  164. "padding-bottom": "40px"
  165. });
  166. //this.node.set("id", "formNode111111111");
  167. }
  168. if( this.control.allowSave ){
  169. this.mobileSaveActionNode = new Element("div", {"styles": this.css.mobileSaveActionNode, "text": this.lp.save}).inject(this.mobileActionBarNode);
  170. this.mobileSaveActionNode.addEvents({
  171. "click": function(){
  172. this.appForm.saveWork();
  173. }.bind(this),
  174. "touchstart": function(){
  175. this.setStyle("background-color", "#EEEEEE");
  176. },
  177. "touchcancel": function(){
  178. this.setStyle("background-color", "#ffffff");
  179. },
  180. "touchend": function(){
  181. this.setStyle("background-color", "#ffffff");
  182. }
  183. });
  184. if (this.control.allowProcessing){
  185. this.mobileSaveActionNode.setStyles({
  186. "width": "49%",
  187. "float": "left"
  188. });
  189. }
  190. }
  191. if( this.control.allowProcessing ){
  192. this.mobileProcessActionNode = new Element("div", {"styles": this.css.mobileSaveActionNode, "text": this.lp.process}).inject(this.mobileActionBarNode);
  193. this.mobileProcessActionNode.addEvents({
  194. "click": function(){
  195. this.appForm.processWork();
  196. }.bind(this),
  197. "touchstart": function(){
  198. this.setStyle("background-color", "#EEEEEE");
  199. },
  200. "touchcancel": function(){
  201. this.setStyle("background-color", "#ffffff");
  202. },
  203. "touchend": function(){
  204. this.setStyle("background-color", "#ffffff");
  205. }
  206. });
  207. if (this.control.allowSave){
  208. this.mobileProcessActionNode.setStyles({
  209. "width": "49%",
  210. "float": "right"
  211. });
  212. }
  213. }
  214. },
  215. errorWork: function(){
  216. if (this.mask) this.mask.hide();
  217. this.node.set("text", "openError");
  218. },
  219. getCurrentTaskData: function(data){
  220. if ((data.currentTaskIndex || data.currentTaskIndex===0) && data.currentTaskIndex != -1){
  221. this.options.taskId = this.taskList[data.currentTaskIndex].id;
  222. return this.taskList[data.currentTaskIndex];
  223. }
  224. //if (this.taskList){
  225. // if (this.taskList.length==1){
  226. // this.options.taskId = this.taskList[0].id;
  227. // return this.taskList[0];
  228. // }
  229. //}
  230. return null;
  231. },
  232. // parseData: function(data){
  233. // var title = "";
  234. // if (this.options.taskId){
  235. // title = data.work.title;
  236. // this.options.workId = data.work.id;
  237. // }else if (this.options.workCompletedId){
  238. // title = data.workCompleted.title;
  239. // this.options.workCompleted = data.workCompleted.id;
  240. // }else if (this.options.workId) {
  241. // title = data.work.title;
  242. // this.options.workId = data.work.id;
  243. // }
  244. //
  245. // this.setTitle(this.options.title+"-"+title);
  246. //
  247. // this.activity = data.activity;
  248. // this.data = data.data;
  249. // this.taskList = data.taskList;
  250. // this.currentTask = this.getCurrentTaskData(data);
  251. // this.taskList = data.taskList;
  252. // this.readList = data.readList;
  253. // this.work = data.work;
  254. // this.workCompleted = data.workCompleted;
  255. // this.workLogList = data.workLogList;
  256. // this.attachmentList = data.attachmentList;
  257. // this.inheritedAttachmentList = data.inheritedAttachmentList;
  258. // this.control = data.control;
  259. // this.form = (data.form) ? JSON.decode(MWF.decodeJsonString(data.form.data)): null;
  260. // this.formInfor = data.form;
  261. // },
  262. openWork: function(){
  263. if (this.form){
  264. //this.readonly = true;
  265. //if (this.currentTask) {
  266. // this.readonly = false;
  267. //}else if(this.options.isControl && this.work){
  268. // this.readonly = false;
  269. //}
  270. // MWF.xDesktop.requireApp("process.Xform", "Package", function(){
  271. // MWF.xApplication.process.Xform.require(function(){
  272. // this.appForm = new MWF.APPForm(this.formNode, this.form, {});
  273. // this.appForm.businessData = {
  274. // "data": this.data,
  275. // "taskList": this.taskList,
  276. // "readList": this.readList,
  277. // "work": this.work,
  278. // "workCompleted": this.workCompleted,
  279. // "control": this.control,
  280. // "activity": this.activity,
  281. // "task": this.currentTask,
  282. // "workLogList": this.workLogList,
  283. // "attachmentList": this.attachmentList,
  284. // "inheritedAttachmentList": this.inheritedAttachmentList,
  285. // "formInfor": this.formInfor,
  286. // "status": {
  287. // //"readonly": (this.options.readonly) ? true : false
  288. // "readonly": this.readonly
  289. // }
  290. // };
  291. // this.appForm.workAction = this.action;
  292. // this.appForm.app = this;
  293. // this.appForm.load();
  294. // }.bind(this));
  295. // }.bind(this));
  296. MWF.xDesktop.requireApp("process.Xform", "Form", function(){
  297. this.appForm = new MWF.APPForm(this.formNode, this.form, {});
  298. this.appForm.businessData = {
  299. "data": this.data,
  300. "taskList": this.taskList,
  301. "readList": this.readList,
  302. "work": this.work,
  303. "workCompleted": this.workCompleted,
  304. "control": this.control,
  305. "activity": this.activity,
  306. "task": this.currentTask,
  307. "workLogList": this.workLogList,
  308. "attachmentList": this.attachmentList,
  309. "inheritedAttachmentList": this.inheritedAttachmentList,
  310. "formInfor": this.formInfor,
  311. "status": {
  312. //"readonly": (this.options.readonly) ? true : false
  313. "readonly": this.readonly
  314. }
  315. };
  316. this.appForm.workAction = this.action;
  317. this.appForm.app = this;
  318. this.appForm.load();
  319. }.bind(this));
  320. }
  321. },
  322. //errorWork: function(){
  323. //
  324. //},
  325. recordStatus: function(){
  326. return {"workId": this.options.workId, "workCompletedId": this.options.workCompletedId, "readonly": this.readonly};
  327. },
  328. onPostClose: function(){
  329. if (this.appForm){
  330. this.appForm.modules.each(function(module){
  331. MWF.release(module);
  332. });
  333. MWF.release(this.appForm);
  334. }
  335. }
  336. });