Main.js 30 KB

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