Main.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. MWF.xApplication.process.Work.options = Object.clone(o2.xApplication.Common.options);
  2. MWF.xApplication.process.Work.options.multitask = true;
  3. MWF.xApplication.process.Work.Main = new Class({
  4. Extends: MWF.xApplication.Common.Main,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "name": "process.Work",
  9. "icon": "icon.png",
  10. "width": "1200",
  11. "height": "800",
  12. "title": MWF.xApplication.process.Work.LP.title,
  13. "workId": "",
  14. "draftId": "",
  15. "draft": null,
  16. "workCompletedId": "",
  17. "taskId": "",
  18. "jobId": "",
  19. "form": null,
  20. "priorityWork": "",
  21. "isControl": false,
  22. "taskObject": null,
  23. "readonly": false,
  24. "worklogType": "record" //record, worklog
  25. },
  26. onQueryLoad: function(){
  27. debugger;
  28. this.lp = MWF.xApplication.process.Work.LP;
  29. if (!this.status) {
  30. } else {
  31. this.options.workId = this.status.workId;
  32. this.options.workCompletedId = this.status.workCompletedId;
  33. this.options.jobId = this.status.jobId;
  34. this.options.draftId = this.status.draftId;
  35. this.options.priorityWork = this.status.priorityWork;
  36. this.options.readonly = (this.status.readonly === "true");
  37. }
  38. this.action = MWF.Actions.get("x_processplatform_assemble_surface");
  39. },
  40. loadWorkApplication: function(callback, mask){
  41. debugger;
  42. var maskStyle = (Browser.name=="firefox") ? "work_firefox" : "desktop";
  43. //alert(maskStyle);
  44. if (mask) this.mask = new MWF.widget.Mask({"style": maskStyle, "loading": mask});
  45. this.formNode = new Element("div", {"styles": this.css.formNode}).inject(this.node);
  46. if (!this.options.isRefresh){
  47. this.maxSize(function(){
  48. if (mask) this.mask.loadNode(this.content);
  49. this.loadWork();
  50. }.bind(this));
  51. }else{
  52. if (mask) this.mask.loadNode(this.content);
  53. this.loadWork();
  54. }
  55. if (callback) callback();
  56. },
  57. loadApplication: function(callback){
  58. this.node = new Element("div", {"styles": this.css.content}).inject(this.content);
  59. if (layout.mobile){
  60. this.loadWorkApplication(callback, false)
  61. }else{
  62. if (layout.viewMode=="Default"){
  63. MWF.require("MWF.widget.Mask", function(){
  64. this.loadWorkApplication(callback, true);
  65. }.bind(this));
  66. }else{
  67. this.loadWorkApplication(callback, false);
  68. }
  69. }
  70. this.addEvent("postClose", function(){
  71. //this.refreshTaskCenter();
  72. }.bind(this));
  73. this.addKeyboardEvents();
  74. },
  75. refreshTaskCenter: function(){
  76. if (this.desktop.apps){
  77. if (this.desktop.apps["TaskCenter"]){
  78. if(this.desktop.apps["TaskCenter"].content){
  79. this.desktop.apps["TaskCenter"].content.unmask();
  80. }
  81. if(this.desktop.apps["TaskCenter"].refreshAll){
  82. this.desktop.apps["TaskCenter"].refreshAll();
  83. }
  84. }
  85. }
  86. },
  87. addKeyboardEvents: function(){
  88. this.addEvent("keySave", function(e){
  89. this.keySave(e);
  90. }.bind(this));
  91. },
  92. keySave: function(e){
  93. if (this.appForm){
  94. if (!this.options.readonly){
  95. this.appForm.saveWork();
  96. e.preventDefault();
  97. }
  98. }
  99. },
  100. reload: function(data){
  101. if (this.form){
  102. this.formNode.empty();
  103. MWF.release(this.form);
  104. this.form = null;
  105. }
  106. if (data){
  107. this.parseData(data);
  108. this.openWork();
  109. }else{
  110. this.loadWork();
  111. }
  112. },
  113. loadWork: function(){
  114. var id = this.options.workCompletedId || this.options.workId || this.options.workid || this.options.workcompletedid;
  115. // var methods = {
  116. // "loadWork": false,
  117. // "getWorkControl": false,
  118. // "getForm": false
  119. // };
  120. if (id){
  121. this.loadWorkByWork(id);
  122. // }.bind(this), "failure": function(){}}, [id, true, true, true], id);
  123. }else if (this.options.draftId || this.options.draftid){
  124. var draftId = this.options.draftId || this.options.draftid;
  125. MWF.Actions.get("x_processplatform_assemble_surface").getDraft(draftId, function(json){
  126. this.loadWorkByDraft(json.data.work, json.data.data);
  127. }.bind(this));
  128. }else if (this.options.draft){
  129. this.loadWorkByDraft(this.options.draft);
  130. }else if (this.options.jobId || this.options.jobid || this.options.job){
  131. var jobId = this.options.jobId || this.options.jobid || this.options.job;
  132. delete this.options.jobId;
  133. delete this.options.jobid;
  134. delete this.options.job;
  135. this.loadWorkByJob(jobId);
  136. }
  137. },
  138. loadWorkByWork: function(id){
  139. debugger;
  140. //var getWorkLogMothed = "getWorkLog"; //以前使用worklog,现在改成record了
  141. //var getWorkLogMothed = (this.options.worklogType.toLowerCase()==="worklog") ? "getWorkLog" : "getRecordLog";
  142. var loadFormFlag = false;
  143. var loadWorkFlag = false;
  144. var loadModuleFlag = false;
  145. var json_work, json_log, json_control, json_form;
  146. var check = function(){
  147. if (loadWorkFlag && loadFormFlag && loadModuleFlag){
  148. if (json_work && json_control && json_form && json_log){
  149. this.parseData(json_work.data, json_control.data, json_form.data, json_log.data, json_work.data.recordList, json_work.data.attachmentList);
  150. if (this.mask) this.mask.hide();
  151. //if (layout.mobile) this.loadMobileActions();
  152. if (layout.session && layout.session.user){
  153. this.openWork();
  154. this.unLoading();
  155. }else{
  156. if (layout.sessionPromise){
  157. layout.sessionPromise.then(function(){
  158. this.openWork();
  159. this.unLoading();
  160. }.bind(this), function(){});
  161. }
  162. }
  163. } else{
  164. if (this.options.jobId || this.options.jobid || this.options.job){
  165. delete this.options.workCompletedId;
  166. delete this.options.workId;
  167. delete this.options.workid;
  168. delete this.options.workcompletedid;
  169. this.loadWork();
  170. }else{
  171. layout.sessionPromise.then(function(){
  172. this.close();
  173. }.bind(this), function(){});
  174. //this.close();
  175. }
  176. }
  177. }
  178. }.bind(this);
  179. if ((this.options.form && this.options.form.id) || this.options.formid){
  180. o2.Actions.invokeAsync([
  181. {"action": this.action, "name": "loadWorkV2"},
  182. {"action": this.action, "name": "getWorkLog"},
  183. {"action": this.action, "name": "getWorkControl"},
  184. {"action": this.action, "name": ((layout.mobile) ? "getFormV2Mobile": "getFormV2")}
  185. ], {"success": function(jsonWork, jsonLog, jsonControl, jsonForm){
  186. json_work = jsonWork;
  187. json_log = jsonLog;
  188. json_control = jsonControl;
  189. json_form = jsonForm;
  190. loadWorkFlag = true;
  191. loadFormFlag = true;
  192. check();
  193. }.bind(this), "failure": function(){
  194. // layout.sessionPromise.then(function(){
  195. // this.close();
  196. // }.bind(this), function(){});
  197. //this.close();
  198. }.bind(this)}, id, id, id, [this.options.formid || this.options.form.id]);
  199. }else{
  200. this.action.lookupFormWithWork(id, function(json){
  201. var formId = json.data.id;
  202. if (json.data.form){
  203. json_form = json;
  204. loadFormFlag = true;
  205. check();
  206. }else{
  207. //临时查看效果
  208. // if (formId=="4f8b4fde-d963-468c-b6c9-9e7b919f0bd0"){
  209. // o2.JSON.get("../x_desktop/res/form/4f8b4fde-d963-468c-b6c9-9e7b919f0bd0.json", function(formJson){
  210. // json_form = formJson;
  211. // loadFormFlag = true;
  212. // check();
  213. // });
  214. // }else{
  215. var cacheTag = json.data.cacheTag || "";
  216. this.action[((layout.mobile) ? "getFormV2Mobile": "getFormV2")](formId, cacheTag, function(formJson){
  217. json_form = formJson;
  218. loadFormFlag = true;
  219. check();
  220. }, function(){
  221. loadFormFlag = true;
  222. check();
  223. });
  224. // }
  225. }
  226. }.bind(this), function(){
  227. loadFormFlag = true;
  228. check();
  229. });
  230. o2.Actions.invokeAsync([
  231. {"action": this.action, "name": "loadWorkV2"},
  232. {"action": this.action, "name": "getWorkLog"},
  233. {"action": this.action, "name": "getWorkControl"}
  234. ], {"success": function(jsonWork, jsonLog, jsonControl){
  235. json_work = jsonWork;
  236. json_log = jsonLog;
  237. json_control = jsonControl;
  238. loadWorkFlag = true;
  239. check();
  240. }.bind(this), "failure": function(){
  241. // layout.sessionPromise.then(function(){
  242. // this.close();
  243. // }.bind(this), function(){});
  244. //this.close();
  245. }.bind(this)}, id
  246. );
  247. }
  248. var cl = "$all";
  249. MWF.xDesktop.requireApp("process.Xform", cl, function(){
  250. loadModuleFlag = true;
  251. check();
  252. });
  253. // if (this.options.form && this.options.form.id && this.options.form.app){
  254. // o2.Actions.invokeAsync([
  255. // {"action": this.action, "name": "loadWork"},
  256. // {"action": this.action, "name": "getWorkLog"},
  257. // {"action": this.action, "name": "getRecordLog"},
  258. // {"action": this.action, "name": "getWorkControl"},
  259. // {"action": this.action, "name": "listAttachments"},
  260. // {"action": this.action, "name": "getForm"}
  261. // ], {"success": function(json_work, json_log, json_record, json_control, json_att, json_form){
  262. // if (json_work && json_control && json_form && json_log && json_att){
  263. // this.parseData(json_work.data, json_control.data, json_form.data, json_log.data, json_record.data, json_att.data);
  264. // if (this.mask) this.mask.hide();
  265. // //if (layout.mobile) this.loadMobileActions();
  266. // this.openWork();
  267. // this.unLoading();
  268. // } else{
  269. // if (this.options.jobId || this.options.jobid || this.options.job){
  270. // delete this.options.workCompletedId;
  271. // delete this.options.workId;
  272. // delete this.options.workid;
  273. // delete this.options.workcompletedid;
  274. // this.loadWork();
  275. // }else{
  276. // this.close();
  277. // }
  278. // }
  279. // }.bind(this), "failure": function(){
  280. // //this.close();
  281. // }.bind(this)}, id, id, id, id, id, [this.options.form.id, this.options.form.app]);
  282. // }else{
  283. // o2.Actions.invokeAsync([
  284. // {"action": this.action, "name": "loadWork"},
  285. // {"action": this.action, "name": "getWorkLog"},
  286. // {"action": this.action, "name": "getRecordLog"},
  287. // {"action": this.action, "name": "getWorkControl"},
  288. // {"action": this.action, "name": "listAttachments"},
  289. // {"action": this.action, "name": (layout.mobile) ? "getWorkFormMobile": "getWorkForm"}
  290. // ], {"success": function(json_work, json_log, json_record, json_control, json_att, json_form){
  291. // if (json_work && json_control && json_form && json_log && json_att){
  292. // this.parseData(json_work.data, json_control.data, json_form.data, json_log.data, json_record.data, json_att.data);
  293. // if (this.mask) this.mask.hide();
  294. // //if (layout.mobile) this.loadMobileActions();
  295. // this.openWork();
  296. // this.unLoading();
  297. // } else{
  298. // if (this.options.jobId || this.options.jobid || this.options.job){
  299. // delete this.options.workCompletedId;
  300. // delete this.options.workId;
  301. // delete this.options.workid;
  302. // delete this.options.workcompletedid;
  303. // this.loadWork();
  304. // }else{
  305. // this.close();
  306. // }
  307. // }
  308. // }.bind(this), "failure": function(){
  309. // //this.close();
  310. // }.bind(this)}, id);
  311. //}
  312. },
  313. loadWorkByJob: function(jobId){
  314. MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(jobId, function(json){
  315. var workCompletedCount = json.data.workCompletedList.length;
  316. var workCount = json.data.workList.length;
  317. var count = workCount+workCompletedCount;
  318. if (count===1){
  319. this.options.workId = (json.data.workList.length) ? json.data.workList[0].id : json.data.workCompletedList[0].id;
  320. this.loadWork();
  321. }else if (count>1){
  322. var id = this.filterId(json.data.workList, json.data.workCompletedList, this.options.priorityWork);
  323. if (id) {
  324. this.options.workId = id;
  325. this.loadWork();
  326. }else{
  327. if (this.options.choice){
  328. var worksAreaNode = this.createWorksArea();
  329. // for (var x=0;x<3;x++){
  330. json.data.workList.each(function(work){
  331. this.createWorkNode(work, worksAreaNode);
  332. }.bind(this));
  333. json.data.workCompletedList.each(function(work){
  334. this.createWorkCompletedNode(work, worksAreaNode);
  335. }.bind(this));
  336. // }
  337. if (this.mask) this.mask.hide();
  338. this.formNode.setStyles(this.css.formNode_bg);
  339. }else{
  340. if (json.data.workList.length){
  341. this.options.workId = json.data.workList[0].id;
  342. }else{
  343. this.options.workId = json.data.workCompletedList[0].id;
  344. }
  345. this.loadWork();
  346. }
  347. }
  348. }else{
  349. layout.sessionPromise.then(function(){
  350. this.close();
  351. }.bind(this), function(){});
  352. //this.close();
  353. }
  354. }.bind(this), function(){
  355. //this.close();
  356. }.bind(this));
  357. },
  358. loadWorkByDraft: function(work, data){
  359. debugger;
  360. o2.Actions.invokeAsync([
  361. {"action": this.action, "name": (layout.mobile) ? "getFormMobile": "getForm"}
  362. ], {"success": function(json_form){
  363. if (json_form){
  364. var workData = {
  365. "activity": {},
  366. "data": data || {},
  367. "taskList": [],
  368. "work": work
  369. };
  370. var control = {
  371. "allowVisit": true,
  372. "allowProcessing": true,
  373. "allowSave": true,
  374. "allowDelete": true
  375. };
  376. this.parseData(workData, control, json_form.data, [], [], []);
  377. if (this.mask) this.mask.hide();
  378. if (layout.session && layout.session.user){
  379. this.openWork();
  380. this.unLoading();
  381. }else{
  382. if (layout.sessionPromise){
  383. layout.sessionPromise.then(function(){
  384. this.openWork();
  385. this.unLoading();
  386. }.bind(this), function(){});
  387. }
  388. }
  389. // this.openWork();
  390. // this.unLoading();
  391. }
  392. }.bind(this), "failure": function(){}}, [work.form, work.application]);
  393. },
  394. createWorkNode: function(work, node, completed){
  395. var contentNode = node.getLast();
  396. var workNode = new Element("div", {"styles": this.css.workItemNode}).inject(contentNode);
  397. var titleNode = new Element("div", {"styles": this.css.workItemTitleNode}).inject(workNode);
  398. titleNode.set("text", work.title);
  399. var inforNode = new Element("div", {"styles": this.css.workItemInforNode}).inject(workNode);
  400. if (completed){
  401. inforNode.set("text", this.lp.completedWork);
  402. }else{
  403. var activityTitleNode = new Element("div", {"styles": this.css.workItemInforTitleNode, "text": this.lp.currentActivity}).inject(inforNode);
  404. var activityContentNode = new Element("div", {"styles": this.css.workItemInforContentNode, "text": work.activityName}).inject(inforNode);
  405. var userTitleNode = new Element("div", {"styles": this.css.workItemInforTitleNode, "text": this.lp.currentUsers}).inject(inforNode);
  406. var taskUsers = [];
  407. MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
  408. json.data.each(function(task){
  409. taskUsers.push(MWF.name.cn(task.person));
  410. }.bind(this));
  411. var activityContentNode = new Element("div", {"styles": this.css.workItemInforContentNode, "text": taskUsers.join(", ")}).inject(inforNode);
  412. }.bind(this));
  413. }
  414. var _self = this;
  415. workNode.store("workId", work.id);
  416. workNode.addEvents({
  417. "mouseover": function(){
  418. this.addClass("mainColor_border");
  419. this.setStyles(_self.css.workItemNode_over);
  420. },
  421. "mouseout": function(){
  422. this.removeClass("mainColor_border");
  423. this.setStyles(_self.css.workItemNode);
  424. },
  425. "click": function(){
  426. var id = this.retrieve("workId");
  427. if (id){
  428. _self.options.workId = id;
  429. _self.loadWork();
  430. }
  431. },
  432. });
  433. },
  434. createWorksArea: function(){
  435. var node = new Element("div", {"styles": this.css.workListArea}).inject(this.formNode);
  436. var titleNode = new Element("div", {"styles": this.css.workListAreaTitle, "text": this.lp.selectWork}).inject(node);
  437. var contentNode = new Element("div", {"styles": this.css.workListContent}).inject(node);
  438. return node;
  439. },
  440. filterId: function(list, completedList, id){
  441. if (!id) return "";
  442. if (!list.length && !completedList.length) return "";
  443. if (list.length){
  444. var o = list.filter(function(work){
  445. return work.id == id;
  446. }.bind(this));
  447. if (o.length) return o[0].id;
  448. }
  449. if (completedList.length) {
  450. o = completedList.filter(function(work){
  451. return work.id == id;
  452. }.bind(this));
  453. return (o.length) ? o[0].id : "";
  454. }
  455. return "";
  456. },
  457. parseData: function(workData, controlData, formData, logData, recordData, attData){
  458. debugger;
  459. var title = workData.work.title;
  460. //this.setTitle(this.options.title+"-"+title);
  461. this.setTitle(title || this.options.title);
  462. //routeList 等字段放在 properties 中了,这段代码是兼容以前的脚本
  463. //( workData.taskList || [] ).each(function(task){
  464. // if( task.properties && typeOf( task.properties ) === "object"){
  465. // if( !task.routeList )task.routeList = task.properties.routeList;
  466. // if( !task.routeNameList )task.routeNameList = task.properties.routeNameList;
  467. // if( !task.routeOpinionList )task.routeOpinionList = task.properties.routeOpinionList;
  468. // if( !task.routeDecisionOpinionList )task.routeDecisionOpinionList = task.properties.routeDecisionOpinionList;
  469. // }
  470. //});
  471. this.activity = workData.activity;
  472. this.data = workData.data;
  473. this.taskList = workData.taskList;
  474. this.currentTask = this.getCurrentTaskData(workData);
  475. this.taskList = workData.taskList;
  476. this.readList = workData.readList;
  477. this.routeList = workData.routeList;
  478. this.work = workData.work;
  479. this.workCompleted = (workData.work.completedTime) ? workData.work : null;
  480. this.workLogList = logData;
  481. this.recordList = recordData;
  482. this.attachmentList = attData;
  483. //this.inheritedAttachmentList = data.inheritedAttachmentList;
  484. this.control = controlData;
  485. if (formData){
  486. if (formData.form){
  487. this.form = (formData.form.data) ? JSON.decode(MWF.decodeJsonString(formData.form.data)): null;
  488. //
  489. // var rex = /mwftype="subform"/gi;
  490. //
  491. //
  492. // debugger;
  493. this.relatedFormMap = formData.relatedFormMap;
  494. this.relatedScriptMap = formData.relatedScriptMap;
  495. delete formData.form.data;
  496. this.formInfor = formData.form;
  497. }else{
  498. this.form = (formData.data) ? JSON.decode(MWF.decodeJsonString(formData.data)): null;
  499. delete formData.data;
  500. this.formInfor = formData;
  501. }
  502. }
  503. },
  504. // loadWork2: function(){
  505. // var method = "";
  506. // var id = "";
  507. //
  508. // if (this.options.workCompletedId){
  509. // method = (layout.mobile) ? "getJobByWorkCompletedMobile" : "getJobByWorkCompleted";
  510. // id = this.options.workCompletedId;
  511. // }else if (this.options.workId) {
  512. // method = (layout.mobile) ? "getJobByWorkMobile" : "getJobByWork";
  513. // id = this.options.workId;
  514. // }
  515. // if (method && id){
  516. // this.action[method](function(json){
  517. // if (this.mask) this.mask.hide();
  518. // this.parseData(json.data);
  519. // if (layout.mobile) this.loadMobileActions();
  520. // this.openWork();
  521. // }.bind(this), function(){
  522. // this.close();
  523. // }.bind(this), id);
  524. // }
  525. // },
  526. loadMobileActions: function(){
  527. if( this.control.allowSave || this.control.allowProcessing ){
  528. this.mobileActionBarNode = new Element("div", {"styles": this.css.mobileActionBarNode}).inject(this.node, "after");
  529. var size = this.content.getSize();
  530. var y = size.y-40;
  531. this.node.setStyles({
  532. "height": ""+y+"px",
  533. "min-height": ""+y+"px",
  534. "overflow": "auto",
  535. "padding-bottom": "40px"
  536. });
  537. //this.node.set("id", "formNode111111111");
  538. }
  539. if( this.control.allowSave ){
  540. this.mobileSaveActionNode = new Element("div", {"styles": this.css.mobileSaveActionNode, "text": this.lp.save}).inject(this.mobileActionBarNode);
  541. this.mobileSaveActionNode.addEvents({
  542. "click": function(){
  543. this.appForm.saveWork();
  544. }.bind(this),
  545. "touchstart": function(){
  546. this.setStyle("background-color", "#EEEEEE");
  547. },
  548. "touchcancel": function(){
  549. this.setStyle("background-color", "#ffffff");
  550. },
  551. "touchend": function(){
  552. this.setStyle("background-color", "#ffffff");
  553. }
  554. });
  555. if (this.control.allowProcessing){
  556. this.mobileSaveActionNode.setStyles({
  557. "width": "49%",
  558. "float": "left"
  559. });
  560. }
  561. }
  562. if( this.control.allowProcessing ){
  563. this.mobileProcessActionNode = new Element("div", {"styles": this.css.mobileSaveActionNode, "text": this.lp.process}).inject(this.mobileActionBarNode);
  564. this.mobileProcessActionNode.addEvents({
  565. "click": function(){
  566. this.appForm.processWork();
  567. }.bind(this),
  568. "touchstart": function(){
  569. this.setStyle("background-color", "#EEEEEE");
  570. },
  571. "touchcancel": function(){
  572. this.setStyle("background-color", "#ffffff");
  573. },
  574. "touchend": function(){
  575. this.setStyle("background-color", "#ffffff");
  576. }
  577. });
  578. if (this.control.allowSave){
  579. this.mobileProcessActionNode.setStyles({
  580. "width": "49%",
  581. "float": "right"
  582. });
  583. }
  584. }
  585. },
  586. errorWork: function(){
  587. if (this.mask) this.mask.hide();
  588. this.node.set("text", "openError");
  589. },
  590. getCurrentTaskData: function(data){
  591. if ((data.currentTaskIndex || data.currentTaskIndex===0) && data.currentTaskIndex != -1){
  592. this.options.taskId = this.taskList[data.currentTaskIndex].id;
  593. return this.taskList[data.currentTaskIndex];
  594. }
  595. //if (this.taskList){
  596. // if (this.taskList.length==1){
  597. // this.options.taskId = this.taskList[0].id;
  598. // return this.taskList[0];
  599. // }
  600. //}
  601. return null;
  602. },
  603. // parseData: function(data){
  604. // var title = "";
  605. // if (this.options.taskId){
  606. // title = data.work.title;
  607. // this.options.workId = data.work.id;
  608. // }else if (this.options.workCompletedId){
  609. // title = data.workCompleted.title;
  610. // this.options.workCompleted = data.workCompleted.id;
  611. // }else if (this.options.workId) {
  612. // title = data.work.title;
  613. // this.options.workId = data.work.id;
  614. // }
  615. //
  616. // this.setTitle(this.options.title+"-"+title);
  617. //
  618. // this.activity = data.activity;
  619. // this.data = data.data;
  620. // this.taskList = data.taskList;
  621. // this.currentTask = this.getCurrentTaskData(data);
  622. // this.taskList = data.taskList;
  623. // this.readList = data.readList;
  624. // this.work = data.work;
  625. // this.workCompleted = data.workCompleted;
  626. // this.workLogList = data.workLogList;
  627. // this.attachmentList = data.attachmentList;
  628. // this.inheritedAttachmentList = data.inheritedAttachmentList;
  629. // this.control = data.control;
  630. // this.form = (data.form) ? JSON.decode(MWF.decodeJsonString(data.form.data)): null;
  631. // this.formInfor = data.form;
  632. // },
  633. openWork: function(){
  634. if (this.form){
  635. //this.readonly = true;
  636. //if (this.currentTask) {
  637. // this.readonly = false;
  638. //}else if(this.options.isControl && this.work){
  639. // this.readonly = false;
  640. //}
  641. // MWF.xDesktop.requireApp("process.Xform", "Package", function(){
  642. // MWF.xApplication.process.Xform.require(function(){
  643. // this.appForm = new MWF.APPForm(this.formNode, this.form, {});
  644. // this.appForm.businessData = {
  645. // "data": this.data,
  646. // "taskList": this.taskList,
  647. // "readList": this.readList,
  648. // "work": this.work,
  649. // "workCompleted": this.workCompleted,
  650. // "control": this.control,
  651. // "activity": this.activity,
  652. // "task": this.currentTask,
  653. // "workLogList": this.workLogList,
  654. // "attachmentList": this.attachmentList,
  655. // "inheritedAttachmentList": this.inheritedAttachmentList,
  656. // "formInfor": this.formInfor,
  657. // "status": {
  658. // //"readonly": (this.options.readonly) ? true : false
  659. // "readonly": this.readonly
  660. // }
  661. // };
  662. // this.appForm.workAction = this.action;
  663. // this.appForm.app = this;
  664. // this.appForm.load();
  665. // }.bind(this));
  666. // }.bind(this));
  667. this.formNode.empty();
  668. this.formNode.setStyles(this.css.formNode);
  669. var uri = window.location.href;
  670. //var cl = (uri.indexOf("$all")!=-1) ? "$all" : "Form";
  671. var cl = "$all";
  672. MWF.xDesktop.requireApp("process.Xform", cl, function(){
  673. //MWF.xDesktop.requireApp("process.Xform", "Form", function(){
  674. this.appForm = new MWF.APPForm(this.formNode, this.form, {});
  675. this.appForm.businessData = {
  676. "data": this.data,
  677. "originalData" : Object.clone( this.data ),
  678. "taskList": this.taskList,
  679. "readList": this.readList,
  680. "work": this.work,
  681. "workCompleted": this.workCompleted,
  682. "control": this.control,
  683. "activity": this.activity,
  684. "task": this.currentTask,
  685. "workLogList": this.workLogList,
  686. "recordList": this.recordList,
  687. "routeList" : this.routeList,
  688. "attachmentList": this.attachmentList,
  689. "inheritedAttachmentList": this.inheritedAttachmentList,
  690. "formInfor": this.formInfor,
  691. "status": {
  692. //"readonly": (this.options.readonly) ? true : false
  693. "readonly": this.readonly
  694. }
  695. };
  696. this.appForm.workAction = this.action;
  697. this.appForm.app = this;
  698. if (layout.desktop.type !== "layout") layout.appForm = this.appForm;
  699. if( this.$events && this.$events.queryLoadForm ){
  700. this.appForm.addEvent( "queryLoad", function () {
  701. this.fireEvent("queryLoadForm");
  702. }.bind(this));
  703. }
  704. this.appForm.load(function(){
  705. if (this.mask) this.mask.hide();
  706. if (window.o2android && window.o2android.appFormLoaded){
  707. layout.appForm = this.appForm;
  708. window.o2android.appFormLoaded(JSON.stringify(this.appForm.mobileTools));
  709. }
  710. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.appFormLoaded){
  711. layout.appForm = this.appForm;
  712. window.webkit.messageHandlers.appFormLoaded.postMessage(JSON.stringify(this.appForm.mobileTools));
  713. }
  714. if (this.options.action=="processTask"){
  715. this.appForm.processWork();
  716. this.options.action = "";
  717. }
  718. this.fireEvent("postLoadForm");
  719. }.bind(this));
  720. }.bind(this));
  721. }
  722. },
  723. //errorWork: function(){
  724. //
  725. //},
  726. recordStatus: function(){
  727. debugger;
  728. return {"workId": this.options.workId, "workCompletedId": this.options.workCompletedId, "jobId": this.options.jobId, "draftId": this.options.draftId, "priorityWork": this.options.priorityWork, "readonly": this.readonly};
  729. },
  730. onPostClose: function(){
  731. if (this.appForm){
  732. this.appForm.modules.each(function(module){
  733. MWF.release(module);
  734. });
  735. MWF.release(this.appForm);
  736. }
  737. }
  738. });