Main.js 33 KB

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