Main.js 14 KB

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