Main.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. "draftId": "",
  14. "draft": null,
  15. "workCompletedId": "",
  16. "taskId": "",
  17. "jobId": "",
  18. "form": null,
  19. "priorityWork": "",
  20. "isControl": false,
  21. "taskObject": null,
  22. "readonly": false,
  23. "worklogType": "record" //record, worklog
  24. },
  25. onQueryLoad: function(){
  26. debugger;
  27. this.lp = MWF.xApplication.process.Work.LP;
  28. if (!this.status) {
  29. } else {
  30. this.options.workId = this.status.workId;
  31. this.options.workCompletedId = this.status.workCompletedId;
  32. this.options.jobId = this.status.jobId;
  33. this.options.draftId = this.status.draftId;
  34. this.options.priorityWork = this.status.priorityWork;
  35. this.options.readonly = (this.status.readonly === "true");
  36. }
  37. this.action = MWF.Actions.get("x_processplatform_assemble_surface");
  38. },
  39. loadWorkApplication: function(callback, mask){
  40. debugger;
  41. var maskStyle = (Browser.name=="firefox") ? "work_firefox" : "desktop";
  42. //alert(maskStyle);
  43. if (mask) this.mask = new MWF.widget.Mask({"style": maskStyle, "loading": mask});
  44. this.formNode = new Element("div", {"styles": this.css.formNode}).inject(this.node);
  45. if (!this.options.isRefresh){
  46. this.maxSize(function(){
  47. if (mask) this.mask.loadNode(this.content);
  48. this.loadWork();
  49. }.bind(this));
  50. }else{
  51. if (mask) this.mask.loadNode(this.content);
  52. this.loadWork();
  53. }
  54. if (callback) callback();
  55. },
  56. loadApplication: function(callback){
  57. this.node = new Element("div", {"styles": this.css.content}).inject(this.content);
  58. if (layout.mobile){
  59. this.loadWorkApplication(callback, false)
  60. }else{
  61. if (layout.viewMode=="Default"){
  62. MWF.require("MWF.widget.Mask", function(){
  63. this.loadWorkApplication(callback, true);
  64. }.bind(this));
  65. }else{
  66. this.loadWorkApplication(callback, false);
  67. }
  68. }
  69. this.addEvent("postClose", function(){
  70. //this.refreshTaskCenter();
  71. }.bind(this));
  72. this.addKeyboardEvents();
  73. },
  74. refreshTaskCenter: function(){
  75. if (this.desktop.apps){
  76. if (this.desktop.apps["TaskCenter"]){
  77. this.desktop.apps["TaskCenter"].content.unmask();
  78. this.desktop.apps["TaskCenter"].refreshAll();
  79. }
  80. }
  81. },
  82. addKeyboardEvents: function(){
  83. this.addEvent("keySave", function(e){
  84. this.keySave(e);
  85. }.bind(this));
  86. },
  87. keySave: function(e){
  88. if (this.appForm){
  89. if (!this.options.readonly){
  90. this.appForm.saveWork();
  91. e.preventDefault();
  92. }
  93. }
  94. },
  95. reload: function(data){
  96. if (this.form){
  97. this.formNode.empty();
  98. MWF.release(this.form);
  99. this.form = null;
  100. }
  101. if (data){
  102. this.parseData(data);
  103. this.openWork();
  104. }else{
  105. this.loadWork();
  106. }
  107. },
  108. loadWork: function(){
  109. var id = this.options.workCompletedId || this.options.workId || this.options.workid || this.options.workcompletedid;
  110. // var methods = {
  111. // "loadWork": false,
  112. // "getWorkControl": false,
  113. // "getForm": false
  114. // };
  115. if (id){
  116. this.loadWorkByWork(id);
  117. // }.bind(this), "failure": function(){}}, [id, true, true, true], id);
  118. }else if (this.options.draftId || this.options.draftid){
  119. var draftId = this.options.draftId || this.options.draftid;
  120. MWF.Actions.get("x_processplatform_assemble_surface").getDraft(draftId, function(json){
  121. this.loadWorkByDraft(json.data.work, json.data.data);
  122. }.bind(this));
  123. }else if (this.options.draft){
  124. this.loadWorkByDraft(this.options.draft);
  125. }else if (this.options.jobId || this.options.jobid || this.options.job){
  126. var jobId = this.options.jobId || this.options.jobid || this.options.job;
  127. this.loadWorkByJob(jobId);
  128. }
  129. },
  130. loadWorkByWork: function(id){
  131. //var getWorkLogMothed = "getWorkLog"; //以前使用worklog,现在改成record了
  132. var getWorkLogMothed = (this.options.worklogType.toLowerCase()==="worklog") ? "getWorkLog" : "getRecordLog";
  133. if (this.options.form && this.options.form.id && this.options.form.app){
  134. o2.Actions.invokeAsync([
  135. {"action": this.action, "name": "getForm"},
  136. {"action": this.action, "name": "loadWork"},
  137. {"action": this.action, "name": "getWorkControl"},
  138. {"action": this.action, "name": "getWorkLog"},
  139. {"action": this.action, "name": "getRecordLog"},
  140. {"action": this.action, "name": "listAttachments"}
  141. ], {"success": function(json_form, json_work, json_control, json_log, json_record, json_att){
  142. if (json_work && json_control && json_form && json_log && json_att){
  143. this.parseData(json_work.data, json_control.data, json_form.data, json_log.data, json_record.data, json_att.data);
  144. if (this.mask) this.mask.hide();
  145. //if (layout.mobile) this.loadMobileActions();
  146. this.openWork();
  147. this.unLoading();
  148. } else{
  149. if (this.options.jobId || this.options.jobid || this.options.job){
  150. delete this.options.workCompletedId;
  151. delete this.options.workId;
  152. delete this.options.workid;
  153. delete this.options.workcompletedid;
  154. this.loadWork();
  155. }else{
  156. this.close();
  157. }
  158. }
  159. }.bind(this), "failure": function(){}}, [this.options.form.id, this.options.form.app], id);
  160. }else{
  161. o2.Actions.invokeAsync([
  162. {"action": this.action, "name": (layout.mobile) ? "getWorkFormMobile": "getWorkForm"},
  163. {"action": this.action, "name": "loadWork"},
  164. {"action": this.action, "name": "getWorkControl"},
  165. {"action": this.action, "name": "getWorkLog"},
  166. {"action": this.action, "name": "getRecordLog"},
  167. {"action": this.action, "name": "listAttachments"}
  168. ], {"success": function(json_form, json_work, json_control, json_log, json_record, json_att){
  169. if (json_work && json_control && json_form && json_log && json_att){
  170. this.parseData(json_work.data, json_control.data, json_form.data, json_log.data, json_record.data, json_att.data);
  171. if (this.mask) this.mask.hide();
  172. //if (layout.mobile) this.loadMobileActions();
  173. this.openWork();
  174. this.unLoading();
  175. } else{
  176. if (this.options.jobId || this.options.jobid || this.options.job){
  177. delete this.options.workCompletedId;
  178. delete this.options.workId;
  179. delete this.options.workid;
  180. delete this.options.workcompletedid;
  181. this.loadWork();
  182. }else{
  183. this.close();
  184. }
  185. }
  186. }.bind(this), "failure": function(){}}, id);
  187. }
  188. },
  189. loadWorkByJob: function(jobId){
  190. MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(jobId, function(json){
  191. var workCompletedCount = json.data.workCompletedList.length;
  192. var workCount = json.data.workList.length;
  193. var count = workCount+workCompletedCount;
  194. if (count===1){
  195. this.options.workId = (json.data.workList.length) ? json.data.workList[0].id : json.data.workCompletedList[0].id;
  196. this.loadWork();
  197. }else if (count>1){
  198. var id = this.filterId(json.data.workList, json.data.workCompletedList, this.options.priorityWork);
  199. if (id) {
  200. this.options.workId = id;
  201. this.loadWork();
  202. }else{
  203. var worksAreaNode = this.createWorksArea();
  204. // for (var x=0;x<3;x++){
  205. json.data.workList.each(function(work){
  206. this.createWorkNode(work, worksAreaNode);
  207. }.bind(this));
  208. json.data.workCompletedList.each(function(work){
  209. this.createWorkCompletedNode(work, worksAreaNode);
  210. }.bind(this));
  211. // }
  212. if (this.mask) this.mask.hide();
  213. this.formNode.setStyles(this.css.formNode_bg);
  214. }
  215. }else{
  216. }
  217. }.bind(this));
  218. },
  219. loadWorkByDraft: function(work, data){
  220. debugger;
  221. o2.Actions.invokeAsync([
  222. {"action": this.action, "name": (layout.mobile) ? "getFormMobile": "getForm"}
  223. ], {"success": function(json_form){
  224. if (json_form){
  225. var workData = {
  226. "activity": {},
  227. "data": data || {},
  228. "taskList": [],
  229. "work": work
  230. };
  231. var control = {
  232. "allowVisit": true,
  233. "allowProcessing": true,
  234. "allowSave": true,
  235. "allowDelete": false
  236. };
  237. this.parseData(workData, control, json_form.data, [], [], []);
  238. if (this.mask) this.mask.hide();
  239. //if (layout.mobile) this.loadMobileActions();
  240. this.openWork();
  241. this.unLoading();
  242. }
  243. }.bind(this), "failure": function(){}}, [work.form, work.application]);
  244. },
  245. createWorkNode: function(work, node, completed){
  246. var contentNode = node.getLast();
  247. var workNode = new Element("div", {"styles": this.css.workItemNode}).inject(contentNode);
  248. var titleNode = new Element("div", {"styles": this.css.workItemTitleNode}).inject(workNode);
  249. titleNode.set("text", work.title);
  250. var inforNode = new Element("div", {"styles": this.css.workItemInforNode}).inject(workNode);
  251. if (completed){
  252. inforNode.set("text", this.lp.completedWork);
  253. }else{
  254. var activityTitleNode = new Element("div", {"styles": this.css.workItemInforTitleNode, "text": this.lp.currentActivity}).inject(inforNode);
  255. var activityContentNode = new Element("div", {"styles": this.css.workItemInforContentNode, "text": work.activityName}).inject(inforNode);
  256. var userTitleNode = new Element("div", {"styles": this.css.workItemInforTitleNode, "text": this.lp.currentUsers}).inject(inforNode);
  257. var taskUsers = [];
  258. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  259. json.data.each(function(task){
  260. taskUsers.push(MWF.name.cn(task.person));
  261. }.bind(this));
  262. var activityContentNode = new Element("div", {"styles": this.css.workItemInforContentNode, "text": taskUsers.join(", ")}).inject(inforNode);
  263. }.bind(this));
  264. }
  265. var _self = this;
  266. workNode.store("workId", work.id);
  267. workNode.addEvents({
  268. "mouseover": function(){
  269. this.addClass("mainColor_border");
  270. this.setStyles(_self.css.workItemNode_over);
  271. },
  272. "mouseout": function(){
  273. this.removeClass("mainColor_border");
  274. this.setStyles(_self.css.workItemNode);
  275. },
  276. "click": function(){
  277. var id = this.retrieve("workId");
  278. if (id){
  279. _self.options.workId = id;
  280. _self.loadWork();
  281. }
  282. },
  283. });
  284. },
  285. createWorksArea: function(){
  286. var node = new Element("div", {"styles": this.css.workListArea}).inject(this.formNode);
  287. var titleNode = new Element("div", {"styles": this.css.workListAreaTitle, "text": this.lp.selectWork}).inject(node);
  288. var contentNode = new Element("div", {"styles": this.css.workListContent}).inject(node);
  289. return node;
  290. },
  291. filterId: function(list, completedList, id){
  292. if (!id) return "";
  293. if (!list.length && !completedList.length) return "";
  294. if (list.length){
  295. var o = list.filter(function(work){
  296. return work.id == id;
  297. }.bind(this));
  298. if (o.length) return o[0].id;
  299. }
  300. if (completedList.length) {
  301. o = completedList.filter(function(work){
  302. return work.id == id;
  303. }.bind(this));
  304. return (o.length) ? o[0].id : "";
  305. }
  306. return "";
  307. },
  308. parseData: function(workData, controlData, formData, logData, recordData, attData){
  309. var title = workData.work.title;
  310. //this.setTitle(this.options.title+"-"+title);
  311. this.setTitle(title || this.options.title);
  312. //routeList 等字段放在 properties 中了,这段代码是兼容以前的脚本
  313. //( workData.taskList || [] ).each(function(task){
  314. // if( task.properties && typeOf( task.properties ) === "object"){
  315. // if( !task.routeList )task.routeList = task.properties.routeList;
  316. // if( !task.routeNameList )task.routeNameList = task.properties.routeNameList;
  317. // if( !task.routeOpinionList )task.routeOpinionList = task.properties.routeOpinionList;
  318. // if( !task.routeDecisionOpinionList )task.routeDecisionOpinionList = task.properties.routeDecisionOpinionList;
  319. // }
  320. //});
  321. this.activity = workData.activity;
  322. this.data = workData.data;
  323. this.taskList = workData.taskList;
  324. this.currentTask = this.getCurrentTaskData(workData);
  325. this.taskList = workData.taskList;
  326. this.readList = workData.readList;
  327. this.work = workData.work;
  328. this.workCompleted = (workData.work.completedTime) ? workData.work : null;
  329. this.workLogList = logData;
  330. this.recordList = recordData;
  331. this.attachmentList = attData;
  332. //this.inheritedAttachmentList = data.inheritedAttachmentList;
  333. this.control = controlData;
  334. this.form = (formData.data) ? JSON.decode(MWF.decodeJsonString(formData.data)): null;
  335. delete formData.data;
  336. this.formInfor = formData;
  337. },
  338. // loadWork2: function(){
  339. // var method = "";
  340. // var id = "";
  341. //
  342. // if (this.options.workCompletedId){
  343. // method = (layout.mobile) ? "getJobByWorkCompletedMobile" : "getJobByWorkCompleted";
  344. // id = this.options.workCompletedId;
  345. // }else if (this.options.workId) {
  346. // method = (layout.mobile) ? "getJobByWorkMobile" : "getJobByWork";
  347. // id = this.options.workId;
  348. // }
  349. // if (method && id){
  350. // this.action[method](function(json){
  351. // if (this.mask) this.mask.hide();
  352. // this.parseData(json.data);
  353. // if (layout.mobile) this.loadMobileActions();
  354. // this.openWork();
  355. // }.bind(this), function(){
  356. // this.close();
  357. // }.bind(this), id);
  358. // }
  359. // },
  360. loadMobileActions: function(){
  361. if( this.control.allowSave || this.control.allowProcessing ){
  362. this.mobileActionBarNode = new Element("div", {"styles": this.css.mobileActionBarNode}).inject(this.node, "after");
  363. var size = this.content.getSize();
  364. var y = size.y-40;
  365. this.node.setStyles({
  366. "height": ""+y+"px",
  367. "min-height": ""+y+"px",
  368. "overflow": "auto",
  369. "padding-bottom": "40px"
  370. });
  371. //this.node.set("id", "formNode111111111");
  372. }
  373. if( this.control.allowSave ){
  374. this.mobileSaveActionNode = new Element("div", {"styles": this.css.mobileSaveActionNode, "text": this.lp.save}).inject(this.mobileActionBarNode);
  375. this.mobileSaveActionNode.addEvents({
  376. "click": function(){
  377. this.appForm.saveWork();
  378. }.bind(this),
  379. "touchstart": function(){
  380. this.setStyle("background-color", "#EEEEEE");
  381. },
  382. "touchcancel": function(){
  383. this.setStyle("background-color", "#ffffff");
  384. },
  385. "touchend": function(){
  386. this.setStyle("background-color", "#ffffff");
  387. }
  388. });
  389. if (this.control.allowProcessing){
  390. this.mobileSaveActionNode.setStyles({
  391. "width": "49%",
  392. "float": "left"
  393. });
  394. }
  395. }
  396. if( this.control.allowProcessing ){
  397. this.mobileProcessActionNode = new Element("div", {"styles": this.css.mobileSaveActionNode, "text": this.lp.process}).inject(this.mobileActionBarNode);
  398. this.mobileProcessActionNode.addEvents({
  399. "click": function(){
  400. this.appForm.processWork();
  401. }.bind(this),
  402. "touchstart": function(){
  403. this.setStyle("background-color", "#EEEEEE");
  404. },
  405. "touchcancel": function(){
  406. this.setStyle("background-color", "#ffffff");
  407. },
  408. "touchend": function(){
  409. this.setStyle("background-color", "#ffffff");
  410. }
  411. });
  412. if (this.control.allowSave){
  413. this.mobileProcessActionNode.setStyles({
  414. "width": "49%",
  415. "float": "right"
  416. });
  417. }
  418. }
  419. },
  420. errorWork: function(){
  421. if (this.mask) this.mask.hide();
  422. this.node.set("text", "openError");
  423. },
  424. getCurrentTaskData: function(data){
  425. if ((data.currentTaskIndex || data.currentTaskIndex===0) && data.currentTaskIndex != -1){
  426. this.options.taskId = this.taskList[data.currentTaskIndex].id;
  427. return this.taskList[data.currentTaskIndex];
  428. }
  429. //if (this.taskList){
  430. // if (this.taskList.length==1){
  431. // this.options.taskId = this.taskList[0].id;
  432. // return this.taskList[0];
  433. // }
  434. //}
  435. return null;
  436. },
  437. // parseData: function(data){
  438. // var title = "";
  439. // if (this.options.taskId){
  440. // title = data.work.title;
  441. // this.options.workId = data.work.id;
  442. // }else if (this.options.workCompletedId){
  443. // title = data.workCompleted.title;
  444. // this.options.workCompleted = data.workCompleted.id;
  445. // }else if (this.options.workId) {
  446. // title = data.work.title;
  447. // this.options.workId = data.work.id;
  448. // }
  449. //
  450. // this.setTitle(this.options.title+"-"+title);
  451. //
  452. // this.activity = data.activity;
  453. // this.data = data.data;
  454. // this.taskList = data.taskList;
  455. // this.currentTask = this.getCurrentTaskData(data);
  456. // this.taskList = data.taskList;
  457. // this.readList = data.readList;
  458. // this.work = data.work;
  459. // this.workCompleted = data.workCompleted;
  460. // this.workLogList = data.workLogList;
  461. // this.attachmentList = data.attachmentList;
  462. // this.inheritedAttachmentList = data.inheritedAttachmentList;
  463. // this.control = data.control;
  464. // this.form = (data.form) ? JSON.decode(MWF.decodeJsonString(data.form.data)): null;
  465. // this.formInfor = data.form;
  466. // },
  467. openWork: function(){
  468. if (this.form){
  469. //this.readonly = true;
  470. //if (this.currentTask) {
  471. // this.readonly = false;
  472. //}else if(this.options.isControl && this.work){
  473. // this.readonly = false;
  474. //}
  475. // MWF.xDesktop.requireApp("process.Xform", "Package", function(){
  476. // MWF.xApplication.process.Xform.require(function(){
  477. // this.appForm = new MWF.APPForm(this.formNode, this.form, {});
  478. // this.appForm.businessData = {
  479. // "data": this.data,
  480. // "taskList": this.taskList,
  481. // "readList": this.readList,
  482. // "work": this.work,
  483. // "workCompleted": this.workCompleted,
  484. // "control": this.control,
  485. // "activity": this.activity,
  486. // "task": this.currentTask,
  487. // "workLogList": this.workLogList,
  488. // "attachmentList": this.attachmentList,
  489. // "inheritedAttachmentList": this.inheritedAttachmentList,
  490. // "formInfor": this.formInfor,
  491. // "status": {
  492. // //"readonly": (this.options.readonly) ? true : false
  493. // "readonly": this.readonly
  494. // }
  495. // };
  496. // this.appForm.workAction = this.action;
  497. // this.appForm.app = this;
  498. // this.appForm.load();
  499. // }.bind(this));
  500. // }.bind(this));
  501. this.formNode.empty();
  502. this.formNode.setStyles(this.css.formNode);
  503. MWF.xDesktop.requireApp("process.Xform", "Form", function(){
  504. this.appForm = new MWF.APPForm(this.formNode, this.form, {});
  505. this.appForm.businessData = {
  506. "data": this.data,
  507. "originalData" : Object.clone( this.data ),
  508. "taskList": this.taskList,
  509. "readList": this.readList,
  510. "work": this.work,
  511. "workCompleted": this.workCompleted,
  512. "control": this.control,
  513. "activity": this.activity,
  514. "task": this.currentTask,
  515. "workLogList": this.workLogList,
  516. "recordList": this.recordList,
  517. "attachmentList": this.attachmentList,
  518. "inheritedAttachmentList": this.inheritedAttachmentList,
  519. "formInfor": this.formInfor,
  520. "status": {
  521. //"readonly": (this.options.readonly) ? true : false
  522. "readonly": this.readonly
  523. }
  524. };
  525. this.appForm.workAction = this.action;
  526. this.appForm.app = this;
  527. this.appForm.load(function(){
  528. if (this.mask) this.mask.hide();
  529. if (window.o2android && window.o2android.appFormLoaded){
  530. layout.appForm = this.appForm;
  531. window.o2android.appFormLoaded(JSON.stringify(this.appForm.mobileTools));
  532. }
  533. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.appFormLoaded){
  534. layout.appForm = this.appForm;
  535. window.webkit.messageHandlers.appFormLoaded.postMessage(JSON.stringify(this.appForm.mobileTools));
  536. }
  537. }.bind(this));
  538. }.bind(this));
  539. }
  540. },
  541. //errorWork: function(){
  542. //
  543. //},
  544. recordStatus: function(){
  545. debugger;
  546. return {"workId": this.options.workId, "workCompletedId": this.options.workCompletedId, "jobId": this.options.jobId, "draftId": this.options.draftId, "priorityWork": this.options.priorityWork, "readonly": this.readonly};
  547. },
  548. onPostClose: function(){
  549. if (this.appForm){
  550. this.appForm.modules.each(function(module){
  551. MWF.release(module);
  552. });
  553. MWF.release(this.appForm);
  554. }
  555. }
  556. });