Main.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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": true
  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. if (formData){
  335. this.form = (formData.data) ? JSON.decode(MWF.decodeJsonString(formData.data)): null;
  336. delete formData.data;
  337. this.formInfor = formData;
  338. }
  339. },
  340. // loadWork2: function(){
  341. // var method = "";
  342. // var id = "";
  343. //
  344. // if (this.options.workCompletedId){
  345. // method = (layout.mobile) ? "getJobByWorkCompletedMobile" : "getJobByWorkCompleted";
  346. // id = this.options.workCompletedId;
  347. // }else if (this.options.workId) {
  348. // method = (layout.mobile) ? "getJobByWorkMobile" : "getJobByWork";
  349. // id = this.options.workId;
  350. // }
  351. // if (method && id){
  352. // this.action[method](function(json){
  353. // if (this.mask) this.mask.hide();
  354. // this.parseData(json.data);
  355. // if (layout.mobile) this.loadMobileActions();
  356. // this.openWork();
  357. // }.bind(this), function(){
  358. // this.close();
  359. // }.bind(this), id);
  360. // }
  361. // },
  362. loadMobileActions: function(){
  363. if( this.control.allowSave || this.control.allowProcessing ){
  364. this.mobileActionBarNode = new Element("div", {"styles": this.css.mobileActionBarNode}).inject(this.node, "after");
  365. var size = this.content.getSize();
  366. var y = size.y-40;
  367. this.node.setStyles({
  368. "height": ""+y+"px",
  369. "min-height": ""+y+"px",
  370. "overflow": "auto",
  371. "padding-bottom": "40px"
  372. });
  373. //this.node.set("id", "formNode111111111");
  374. }
  375. if( this.control.allowSave ){
  376. this.mobileSaveActionNode = new Element("div", {"styles": this.css.mobileSaveActionNode, "text": this.lp.save}).inject(this.mobileActionBarNode);
  377. this.mobileSaveActionNode.addEvents({
  378. "click": function(){
  379. this.appForm.saveWork();
  380. }.bind(this),
  381. "touchstart": function(){
  382. this.setStyle("background-color", "#EEEEEE");
  383. },
  384. "touchcancel": function(){
  385. this.setStyle("background-color", "#ffffff");
  386. },
  387. "touchend": function(){
  388. this.setStyle("background-color", "#ffffff");
  389. }
  390. });
  391. if (this.control.allowProcessing){
  392. this.mobileSaveActionNode.setStyles({
  393. "width": "49%",
  394. "float": "left"
  395. });
  396. }
  397. }
  398. if( this.control.allowProcessing ){
  399. this.mobileProcessActionNode = new Element("div", {"styles": this.css.mobileSaveActionNode, "text": this.lp.process}).inject(this.mobileActionBarNode);
  400. this.mobileProcessActionNode.addEvents({
  401. "click": function(){
  402. this.appForm.processWork();
  403. }.bind(this),
  404. "touchstart": function(){
  405. this.setStyle("background-color", "#EEEEEE");
  406. },
  407. "touchcancel": function(){
  408. this.setStyle("background-color", "#ffffff");
  409. },
  410. "touchend": function(){
  411. this.setStyle("background-color", "#ffffff");
  412. }
  413. });
  414. if (this.control.allowSave){
  415. this.mobileProcessActionNode.setStyles({
  416. "width": "49%",
  417. "float": "right"
  418. });
  419. }
  420. }
  421. },
  422. errorWork: function(){
  423. if (this.mask) this.mask.hide();
  424. this.node.set("text", "openError");
  425. },
  426. getCurrentTaskData: function(data){
  427. if ((data.currentTaskIndex || data.currentTaskIndex===0) && data.currentTaskIndex != -1){
  428. this.options.taskId = this.taskList[data.currentTaskIndex].id;
  429. return this.taskList[data.currentTaskIndex];
  430. }
  431. //if (this.taskList){
  432. // if (this.taskList.length==1){
  433. // this.options.taskId = this.taskList[0].id;
  434. // return this.taskList[0];
  435. // }
  436. //}
  437. return null;
  438. },
  439. // parseData: function(data){
  440. // var title = "";
  441. // if (this.options.taskId){
  442. // title = data.work.title;
  443. // this.options.workId = data.work.id;
  444. // }else if (this.options.workCompletedId){
  445. // title = data.workCompleted.title;
  446. // this.options.workCompleted = data.workCompleted.id;
  447. // }else if (this.options.workId) {
  448. // title = data.work.title;
  449. // this.options.workId = data.work.id;
  450. // }
  451. //
  452. // this.setTitle(this.options.title+"-"+title);
  453. //
  454. // this.activity = data.activity;
  455. // this.data = data.data;
  456. // this.taskList = data.taskList;
  457. // this.currentTask = this.getCurrentTaskData(data);
  458. // this.taskList = data.taskList;
  459. // this.readList = data.readList;
  460. // this.work = data.work;
  461. // this.workCompleted = data.workCompleted;
  462. // this.workLogList = data.workLogList;
  463. // this.attachmentList = data.attachmentList;
  464. // this.inheritedAttachmentList = data.inheritedAttachmentList;
  465. // this.control = data.control;
  466. // this.form = (data.form) ? JSON.decode(MWF.decodeJsonString(data.form.data)): null;
  467. // this.formInfor = data.form;
  468. // },
  469. openWork: function(){
  470. if (this.form){
  471. //this.readonly = true;
  472. //if (this.currentTask) {
  473. // this.readonly = false;
  474. //}else if(this.options.isControl && this.work){
  475. // this.readonly = false;
  476. //}
  477. // MWF.xDesktop.requireApp("process.Xform", "Package", function(){
  478. // MWF.xApplication.process.Xform.require(function(){
  479. // this.appForm = new MWF.APPForm(this.formNode, this.form, {});
  480. // this.appForm.businessData = {
  481. // "data": this.data,
  482. // "taskList": this.taskList,
  483. // "readList": this.readList,
  484. // "work": this.work,
  485. // "workCompleted": this.workCompleted,
  486. // "control": this.control,
  487. // "activity": this.activity,
  488. // "task": this.currentTask,
  489. // "workLogList": this.workLogList,
  490. // "attachmentList": this.attachmentList,
  491. // "inheritedAttachmentList": this.inheritedAttachmentList,
  492. // "formInfor": this.formInfor,
  493. // "status": {
  494. // //"readonly": (this.options.readonly) ? true : false
  495. // "readonly": this.readonly
  496. // }
  497. // };
  498. // this.appForm.workAction = this.action;
  499. // this.appForm.app = this;
  500. // this.appForm.load();
  501. // }.bind(this));
  502. // }.bind(this));
  503. this.formNode.empty();
  504. this.formNode.setStyles(this.css.formNode);
  505. MWF.xDesktop.requireApp("process.Xform", "Form", function(){
  506. this.appForm = new MWF.APPForm(this.formNode, this.form, {});
  507. this.appForm.businessData = {
  508. "data": this.data,
  509. "originalData" : Object.clone( this.data ),
  510. "taskList": this.taskList,
  511. "readList": this.readList,
  512. "work": this.work,
  513. "workCompleted": this.workCompleted,
  514. "control": this.control,
  515. "activity": this.activity,
  516. "task": this.currentTask,
  517. "workLogList": this.workLogList,
  518. "recordList": this.recordList,
  519. "attachmentList": this.attachmentList,
  520. "inheritedAttachmentList": this.inheritedAttachmentList,
  521. "formInfor": this.formInfor,
  522. "status": {
  523. //"readonly": (this.options.readonly) ? true : false
  524. "readonly": this.readonly
  525. }
  526. };
  527. this.appForm.workAction = this.action;
  528. this.appForm.app = this;
  529. this.appForm.load(function(){
  530. if (this.mask) this.mask.hide();
  531. if (window.o2android && window.o2android.appFormLoaded){
  532. layout.appForm = this.appForm;
  533. window.o2android.appFormLoaded(JSON.stringify(this.appForm.mobileTools));
  534. }
  535. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.appFormLoaded){
  536. layout.appForm = this.appForm;
  537. window.webkit.messageHandlers.appFormLoaded.postMessage(JSON.stringify(this.appForm.mobileTools));
  538. }
  539. }.bind(this));
  540. }.bind(this));
  541. }
  542. },
  543. //errorWork: function(){
  544. //
  545. //},
  546. recordStatus: function(){
  547. debugger;
  548. return {"workId": this.options.workId, "workCompletedId": this.options.workCompletedId, "jobId": this.options.jobId, "draftId": this.options.draftId, "priorityWork": this.options.priorityWork, "readonly": this.readonly};
  549. },
  550. onPostClose: function(){
  551. if (this.appForm){
  552. this.appForm.modules.each(function(module){
  553. MWF.release(module);
  554. });
  555. MWF.release(this.appForm);
  556. }
  557. }
  558. });