ProcessStarter.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. MWF.require("MWF.widget.Mask", null, false);
  2. MWF.xApplication.process = MWF.xApplication.process || {};
  3. MWF.xApplication.process.TaskCenter = MWF.xApplication.process.TaskCenter || {};
  4. MWF.xDesktop.requireApp("process.TaskCenter", "lp."+o2.language, null, false);
  5. MWF.xApplication.process.TaskCenter.ProcessStarter = new Class({
  6. Extends: MWF.widget.Common,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "default",
  10. "workData" : null,
  11. "identity": null,
  12. "latest": false,
  13. "skipDraftCheck": null
  14. },
  15. initialize: function(data, app, options){
  16. this.setOptions(options);
  17. this.path = "../x_component_process_TaskCenter/$ProcessStarter/";
  18. this.cssPath = "../x_component_process_TaskCenter/$ProcessStarter/"+this.options.style+"/css.wcss";
  19. this._loadCss();
  20. MWF.xDesktop.requireApp("process.TaskCenter", "$ProcessStarter."+MWF.language, null, false);
  21. this.lp = MWF.xApplication.process.TaskCenter.ProcessStarter.lp;
  22. this.data = data;
  23. this.app = app;
  24. },
  25. load: function(){
  26. this.getOrgAction(function(){
  27. if (this.app.desktop.session.user.distinguishedName){
  28. o2.Actions.load("x_processplatform_assemble_surface").ProcessAction.listAvailableIdentityWithProcess(this.data.id, function(json){
  29. this.identitys = json.data || [];
  30. if (this.identitys.length){
  31. if (this.options.identity){
  32. var identityList = typeOf( this.options.identity ) === "array" ? this.options.identity : [this.options.identity];
  33. this.identitys = this.identitys.filter(function(id){
  34. for( var i=0; i<identityList.length; i++ ){
  35. var identity = identityList[i] || "";
  36. var dn = (typeOf(identity)==="string") ? identity : identity.distinguishedName;
  37. id.index = i;
  38. if( id.distinguishedName===dn )return true;
  39. }
  40. return false;
  41. }.bind(this));
  42. this.identitys.sort(function(a, b){
  43. return a.index - b.index
  44. });
  45. }
  46. if (this.identitys.length){
  47. if (this.identitys.length==1){
  48. var data = {
  49. "title": this.data.name+"-"+this.lp.unnamed,
  50. "identity": this.identitys[0].distinguishedName,
  51. "latest": this.options.latest,
  52. "skipDraftCheck": this.options.skipDraftCheck
  53. };
  54. if( this.options.workData ){
  55. data.data = this.options.workData;
  56. if (data.data.title || data.data.subject) data.title = data.data.title || data.data.subject;
  57. }
  58. this.mask = new MWF.widget.Mask({"style": "desktop"});
  59. this.mask.loadNode(this.app.content);
  60. this.fireEvent("beforeStarted", [data]);
  61. this.getWorkAction(function(){
  62. this.workAction.startWork(function(json){
  63. debugger;
  64. this.mask.hide();
  65. //this.markNode.destroy();
  66. //this.areaNode.destroy();
  67. this.fireEvent("started", [json.data, data.title, this.data.name]);
  68. if (this.app.refreshAll) this.app.refreshAll();
  69. //this.app.notice(this.lp.processStarted, "success");
  70. // this.app.processConfig();
  71. }.bind(this), function(xhr, text, error){
  72. if (xhr.status!=0){
  73. var errorText = error;
  74. if (xhr){
  75. var json = JSON.decode(xhr.responseText);
  76. if (json){
  77. errorText = json.message.trim() || "request json error";
  78. }else{
  79. errorText = "request json error: "+xhr.responseText;
  80. }
  81. }
  82. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  83. }
  84. if(this.mask)this.mask.hide();
  85. }.bind(this), this.data.id, data);
  86. }.bind(this));
  87. }else{
  88. this.createMarkNode();
  89. this.createAreaNode();
  90. this.createStartNode();
  91. this.areaNode.inject(this.markNode, "after");
  92. this.areaNode.fade("in");
  93. //$("form_startSubject").focus();
  94. this.setStartNodeSize();
  95. this.setStartNodeSizeFun = this.setStartNodeSize.bind(this);
  96. this.app.addEvent("resize", this.setStartNodeSizeFun);
  97. this.fireEvent("selectId");
  98. }
  99. }else{
  100. var dns = [];
  101. var iList = typeOf( this.options.identity ) === "array" ? this.options.identity : [this.options.identity];
  102. for( var i=0; i<iList.length; i++ ){
  103. var identity = iList[i] || "";
  104. var dn = (typeOf(identity)==="string") ? identity : identity.distinguishedName;
  105. if(dn)dns.push(dn);
  106. }
  107. var t = this.lp.identityNotInRange.replace("{name}", dns.join("、"));
  108. this.app.notice(t, "error");
  109. }
  110. }else{
  111. var t = this.lp.noIdentitys.replace("{name}", this.app.desktop.session.user.name);
  112. this.app.notice(t, "error");
  113. }
  114. }.bind(this))
  115. }
  116. }.bind(this));
  117. },
  118. createMarkNode: function(){
  119. var app = (this.app.embeded && this.app.eventTarget) ? this.app.eventTarget : this.app;
  120. this.markNode = new Element("div#mark", {
  121. "styles": this.css.markNode,
  122. "events": {
  123. "mouseover": function(e){e.stopPropagation();},
  124. "mouseout": function(e){e.stopPropagation();}
  125. }
  126. }).inject(app.content);
  127. },
  128. createAreaNode: function(){
  129. this.areaNode = new Element("div#area", {
  130. "styles": this.css.areaNode
  131. });
  132. },
  133. createStartNode: function(){
  134. this.createNode = new Element("div", {
  135. "styles": this.css.createNode
  136. }).inject(this.areaNode);
  137. this.createNewNode = new Element("div", {
  138. "styles": this.css.createNewNode
  139. }).inject(this.createNode);
  140. this.createCloseNode = new Element("div", {
  141. "styles": this.css.createCloseNode
  142. }).inject(this.createNode);
  143. this.createCloseNode.addEvent("click", function(e){
  144. this.cancelStartProcess(e);
  145. }.bind(this));
  146. this.formNode = new Element("div", {
  147. "styles": this.css.formNode
  148. }).inject(this.createNode);
  149. var html = "<table width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  150. "<tr><td style=\"height: 50px; line-height: 50px; text-align: left; font-size: 16px; color:#333333; \">" +
  151. this.lp.start+" - "+this.data.name+"</td></tr>" +
  152. "<tr><td style=\"height: 60px; color: #0044cc; line-height: 80px; text-align: left; font-size: 16px; color:#333333; display: block; overflow: hidden\"><div style='padding-left:30px; line-height:80px'>" +
  153. this.lp.selectStartIdentity+"</div></td></tr>" +
  154. "<tr><td id=\"form_startIdentity\"></td></tr>" +
  155. "</table>";
  156. this.formNode.set("html", html);
  157. this.identityArea = this.formNode.getElementById("form_startIdentity");
  158. // MWF.xDesktop.requireApp("Organization", "PersonExplorer", function(){
  159. // var o = {
  160. // "data": this.app.desktop.session.user,
  161. // "explorer":{
  162. // "app": {
  163. // "lp":this.lp
  164. // },
  165. // "actions": this.orgAction
  166. // }
  167. // };
  168. var _self = this;
  169. this.identitys.each(function(item){
  170. //if (item.woUnit){
  171. var id = new MWF.xApplication.process.TaskCenter.ProcessStarter.Identity(this.identityArea, item, this, this.css);
  172. id.node.store("identity", id);
  173. id.node.addEvents({
  174. "mouseover": function(){
  175. this.addClass("mainColor_border");
  176. this.setStyles(_self.css.identityNode_over);
  177. this.getFirst().getLast().setStyles(_self.css.identityInforNameTextNode_over);
  178. this.getFirst().getNext().getFirst().setStyles(_self.css.identityTitleNode_over);
  179. this.getFirst().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode_over);
  180. //this.getFirst().getNext().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode_over);
  181. },
  182. "mouseout": function(){
  183. this.removeClass("mainColor_border");
  184. this.setStyles((layout.mobile) ? _self.css.identityNode_mobile : _self.css.identityNode);
  185. this.getFirst().getLast().setStyles(_self.css.identityInforNameTextNode);
  186. this.getFirst().getNext().getFirst().setStyles(_self.css.identityTitleNode);
  187. this.getFirst().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode);
  188. //this.getFirst().getNext().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode);
  189. },
  190. "click": function(){
  191. var identity = this.retrieve("identity");
  192. if (identity){
  193. _self.okStartProcess(identity.data.distinguishedName);
  194. }
  195. }
  196. });
  197. // if (id.data.major){
  198. // id.node.setStyles(this.css.identityNode_over);
  199. // id.node.getFirst().getLast().setStyles(this.css.identityInforNameTextNode_over);
  200. // id.node.getFirst().getNext().getFirst().setStyles(this.css.identityTitleNode_over);
  201. // id.node.getFirst().getNext().getNext().getFirst().setStyles(this.css.identityTitleNode_over);
  202. // }
  203. }.bind(this));
  204. if (layout.mobile){
  205. this.areaNode.setStyles(this.css.areaNode_mobile);
  206. this.createNode.setStyles(this.css.createNode_mobile);
  207. }
  208. },
  209. getOrgAction: function(callback){
  210. if (!this.orgAction){
  211. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  212. if (callback) callback();
  213. // MWF.xDesktop.requireApp("Selector", "Actions.RestActions", function(){
  214. // this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  215. // if (callback) callback();
  216. // }.bind(this));
  217. }else{
  218. if (callback) callback();
  219. }
  220. },
  221. setStartNodeSize: function(){
  222. if (!layout.mobile){
  223. var app = (this.app.embeded && this.app.eventTarget) ? this.app.eventTarget : this.app;
  224. var size = app.content.getSize();
  225. var allSize = app.content.getSize();
  226. this.markNode.setStyles({
  227. "width": ""+allSize.x+"px",
  228. "height": ""+allSize.y+"px"
  229. });
  230. this.areaNode.setStyles({
  231. "width": ""+size.x+"px",
  232. "height": ""+size.y+"px"
  233. });
  234. var hY = size.y*0.7;
  235. var mY = size.y*0.3/2;
  236. this.createNode.setStyles({
  237. "height": ""+hY+"px",
  238. "margin-top": ""+mY+"px"
  239. });
  240. var count = this.identitys.length;
  241. if (count>2) count=2;
  242. var w = count*320;
  243. this.formNode.setStyles({
  244. "width": ""+w+"px"
  245. });
  246. w = w + 60;
  247. this.createNode.setStyles({
  248. "width": ""+w+"px"
  249. });
  250. }
  251. },
  252. cancelStartProcess: function(e){
  253. this.markNode.destroy();
  254. this.areaNode.destroy();
  255. },
  256. okStartProcess: function(identity){
  257. var data = {
  258. "title": this.data.name+"-"+this.lp.unnamed,
  259. "latest": this.options.latest,
  260. "skipDraftCheck": this.options.skipDraftCheck,
  261. "identity": identity
  262. };
  263. if( this.options.workData ){
  264. data.data = this.options.workData;
  265. if (data.data.title || data.data.subject) data.title = data.data.title || data.data.subject;
  266. }
  267. if (!data.identity){
  268. this.departmentSelArea.setStyle("border-color", "red");
  269. if (this.app && this.app.notice) this.app.notice(this.lp.selectStartId, "error");
  270. }else{
  271. this.mask = new MWF.widget.Mask({"style": "desktop"});
  272. this.mask.loadNode(this.areaNode);
  273. this.fireEvent("beforeStarted", [data]);
  274. this.getWorkAction(function(){
  275. this.workAction.startWork(function(json){
  276. this.mask.hide();
  277. this.markNode.destroy();
  278. this.areaNode.destroy();
  279. this.fireEvent("started", [json.data, data.title, this.data.name]);
  280. if (this.app && this.app.refreshAll) this.app.refreshAll();
  281. //if (this.app && this.app.notice) this.app.notice(this.lp.processStarted, "success");
  282. // this.app.processConfig();
  283. }.bind(this), function(xhr, text, error){
  284. if (xhr.status!=0){
  285. var errorText = error;
  286. if (xhr){
  287. var json = JSON.decode(xhr.responseText);
  288. if (json){
  289. errorText = json.message.trim() || "request json error";
  290. }else{
  291. errorText = "request json error: "+xhr.responseText;
  292. }
  293. }
  294. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  295. }
  296. if(this.mask)this.mask.hide();
  297. // if(this.markNode)this.markNode.destroy();
  298. // if(this.areaNode)this.areaNode.destroy();
  299. }.bind(this), this.data.id, data);
  300. }.bind(this));
  301. }
  302. },
  303. getWorkAction: function(callback){
  304. if (!this.workAction){
  305. this.workAction = MWF.Actions.get("x_processplatform_assemble_surface");
  306. if (callback) callback();
  307. // MWF.xDesktop.requireApp("process.TaskCenter", "Actions.RestActions", function(){
  308. // this.workAction = new MWF.xApplication.process.TaskCenter.Actions.RestActions();
  309. // if (callback) callback();
  310. // }.bind(this));
  311. }else{
  312. if (callback) callback();
  313. }
  314. }
  315. });
  316. MWF.xApplication.process.TaskCenter.ProcessStarter.Identity = new Class({
  317. initialize: function(container, data, starter, style){
  318. this.container = $(container);
  319. this.data = data;
  320. this.starter = starter;
  321. this.action = this.starter.orgAction;
  322. this.style = style;
  323. //this.item = item;
  324. this.load();
  325. },
  326. load: function(){
  327. this.node = new Element("div", {
  328. "styles": (layout.mobile) ? this.style.identityNode_mobile : this.style.identityNode
  329. }).inject(this.container);
  330. var nameNode = new Element("div", {
  331. "styles": this.style.identityInforNameNode
  332. }).inject(this.node);
  333. var url = this.action.getPersonIcon(this.starter.app.desktop.session.user.id);
  334. var img = "<img width='50' height='50' border='0' src='"+url+"'></img>";
  335. // if (this.item.data.icon){
  336. // img = "<img width='50' height='50' border='0' src='data:image/png;base64,"+this.item.data.icon+"'></img>"
  337. // }else{
  338. // if (this.item.data.genderType=="f"){
  339. // img = "<img width='50' height='50' border='0' src='"+"../x_component_Organization/$PersonExplorer/default/icon/female.png'></img>";
  340. // }else{
  341. // img = "<img width='50' height='50' border='0' src='"+"../x_component_Organization/$PersonExplorer/default/icon/man.png'></img>";
  342. // }
  343. // }
  344. var picNode = new Element("div", {
  345. "styles": this.style.identityInforPicNode,
  346. "html": img
  347. }).inject(nameNode);
  348. var nameTextNode = new Element("div", {
  349. "styles": this.style.identityInforNameTextNode,
  350. "text": this.data.name
  351. }).inject(nameNode);
  352. var unitNode = new Element("div", {"styles": this.style.identityDepartmentNode}).inject(this.node);
  353. var unitTitleNode = new Element("div", {
  354. "styles": this.style.identityTitleNode,
  355. "text": MWF.xApplication.process.TaskCenter.LP.unit
  356. }).inject(unitNode);
  357. this.unitTextNode = new Element("div", {"styles": this.style.identityTextNode}).inject(unitNode);
  358. if (this.data.woUnit) this.unitTextNode.set({"text": this.data.woUnit.levelName, "title": this.data.woUnit.levelName});
  359. // var companyNode = new Element("div", {"styles": this.style.identityCompanyNode}).inject(this.node);
  360. // var companyTitleNode = new Element("div", {
  361. // "styles": this.style.identityTitleNode,
  362. // "text": this.item.explorer.app.lp.company
  363. // }).inject(companyNode);
  364. // this.companyTextNode = new Element("div", {"styles": this.style.identityTextNode}).inject(companyNode);
  365. var dutyNode = new Element("div", {"styles": this.style.identityDutyNode}).inject(this.node);
  366. var dutyTitleNode = new Element("div", {
  367. "styles": this.style.identityTitleNode,
  368. "text": MWF.xApplication.process.TaskCenter.LP.duty
  369. }).inject(dutyNode);
  370. this.dutyTextNode = new Element("div", {"styles": this.style.identityTextNode}).inject(dutyNode);
  371. var dutyTextList = [];
  372. var dutyTitleList = [];
  373. this.data.woUnitDutyList.each(function(duty){
  374. dutyTextList.push(duty.name);
  375. if (duty.woUnit) dutyTitleList.push(duty.name+"("+duty.woUnit.levelName+")");
  376. }.bind(this));
  377. this.dutyTextNode.set({"text": dutyTextList.join(", "), "title": dutyTitleList.join(", ")});
  378. var unitTextNode = new Element("div.mainColor_color", {
  379. "styles": this.style.identityInforUnitTextNode,
  380. "text": "【"+this.data.woUnit.name+"】"
  381. }).inject(this.node);
  382. // this.item.explorer.actions.getDepartment(function(json){
  383. // this.department = json.data;
  384. // this.departmentTextNode.set({"text": this.department.name, "title": this.department.name});
  385. //
  386. // this.item.explorer.actions.getCompany(function(json){
  387. // this.company = json.data;
  388. // this.companyTextNode.set({"text": this.company.name, "title": this.company.name});
  389. // }.bind(this), null, this.department.company);
  390. //
  391. // }.bind(this), null, this.data.department);
  392. //
  393. //
  394. // this.item.explorer.actions.listCompanyDutyByIdentity(function(json){
  395. // json.data.each(function(duty){
  396. // var text = this.dutyTextNode.get("text");
  397. // if (text){
  398. // text = text+", "+duty.name;
  399. // }else{
  400. // text = duty.name;
  401. // }
  402. // this.dutyTextNode.set({"text": text, "title": text});
  403. // }.bind(this));
  404. // }.bind(this), null, this.data.id);
  405. // this.item.explorer.actions.listDepartmentDutyByIdentity(function(json){
  406. // json.data.each(function(duty){
  407. // var text = this.dutyTextNode.get("text");
  408. // if (text){
  409. // text = text+", "+duty.name;
  410. // }else{
  411. // text = duty.name;
  412. // }
  413. // this.dutyTextNode.set({"text": text, "title": text});
  414. // }.bind(this));
  415. // }.bind(this), null, this.data.id);
  416. }
  417. });
  418. // MWF.xApplication.process.TaskCenter.ProcessStarter.DepartmentSel = new Class({
  419. // initialize: function(data, starter, container, idArea){
  420. // this.data = data;
  421. // this.starter = starter;
  422. // this.container = container;
  423. // this.idArea = idArea;
  424. // this.css = this.starter.css;
  425. // this.isSelected = false;
  426. // this.load();
  427. // },
  428. // load: function(){
  429. //
  430. // this.node = new Element("div", {"styles": this.css.departSelNode}).inject(this.container);
  431. // this.starter.orgAction.getDepartmentByIdentity(function(department){
  432. // this.node.set("text", department.data.name);
  433. // }.bind(this), null, this.data.name);
  434. //
  435. // this.node.addEvents({
  436. // "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_over);}.bind(this),
  437. // "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_out);}.bind(this),
  438. // "click": function(){
  439. // this.selected();
  440. // }.bind(this),
  441. // });
  442. // },
  443. // selected: function(){
  444. // if (!this.isSelected){
  445. // if (this.starter.currentDepartment) this.starter.currentDepartment.unSelected();
  446. // this.node.setStyles(this.css.departSelNode_selected);
  447. // this.isSelected = true;
  448. // this.starter.currentDepartment = this;
  449. //
  450. // this.idArea.set({
  451. // "text": this.data.display,
  452. // "value": this.data.name
  453. // });
  454. // }
  455. // },
  456. // unSelected: function(){
  457. // if (this.isSelected){
  458. // if (this.starter.currentDepartment) this.starter.currentDepartment = null;;
  459. // this.node.setStyles(this.css.departSelNode);
  460. // this.isSelected = false;
  461. // }
  462. // }
  463. //
  464. // });