Main.js 25 KB

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