Main.js 25 KB

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