Main.js 34 KB

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