Main.js 14 KB

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