Main.js 24 KB

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