ProcessStarter.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. this.markNode = new Element("div#mark", {
  120. "styles": this.css.markNode,
  121. "events": {
  122. "mouseover": function(e){e.stopPropagation();},
  123. "mouseout": function(e){e.stopPropagation();}
  124. }
  125. }).inject(this.app.content);
  126. },
  127. createAreaNode: function(){
  128. this.areaNode = new Element("div#area", {
  129. "styles": this.css.areaNode
  130. });
  131. },
  132. createStartNode: function(){
  133. this.createNode = new Element("div", {
  134. "styles": this.css.createNode
  135. }).inject(this.areaNode);
  136. this.createNewNode = new Element("div", {
  137. "styles": this.css.createNewNode
  138. }).inject(this.createNode);
  139. this.createCloseNode = new Element("div", {
  140. "styles": this.css.createCloseNode
  141. }).inject(this.createNode);
  142. this.createCloseNode.addEvent("click", function(e){
  143. this.cancelStartProcess(e);
  144. }.bind(this));
  145. this.formNode = new Element("div", {
  146. "styles": this.css.formNode
  147. }).inject(this.createNode);
  148. var html = "<table width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  149. "<tr><td style=\"height: 50px; line-height: 50px; text-align: left; font-size: 16px; color:#333333; \">" +
  150. this.lp.start+" - "+this.data.name+"</td></tr>" +
  151. "<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'>" +
  152. this.lp.selectStartIdentity+"</div></td></tr>" +
  153. "<tr><td id=\"form_startIdentity\"></td></tr>" +
  154. "</table>";
  155. this.formNode.set("html", html);
  156. this.identityArea = this.formNode.getElementById("form_startIdentity");
  157. // MWF.xDesktop.requireApp("Organization", "PersonExplorer", function(){
  158. // var o = {
  159. // "data": this.app.desktop.session.user,
  160. // "explorer":{
  161. // "app": {
  162. // "lp":this.lp
  163. // },
  164. // "actions": this.orgAction
  165. // }
  166. // };
  167. var _self = this;
  168. this.identitys.each(function(item){
  169. //if (item.woUnit){
  170. var id = new MWF.xApplication.process.TaskCenter.ProcessStarter.Identity(this.identityArea, item, this, this.css);
  171. id.node.store("identity", id);
  172. id.node.addEvents({
  173. "mouseover": function(){
  174. this.addClass("mainColor_border");
  175. this.setStyles(_self.css.identityNode_over);
  176. this.getFirst().getLast().setStyles(_self.css.identityInforNameTextNode_over);
  177. this.getFirst().getNext().getFirst().setStyles(_self.css.identityTitleNode_over);
  178. this.getFirst().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode_over);
  179. //this.getFirst().getNext().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode_over);
  180. },
  181. "mouseout": function(){
  182. this.removeClass("mainColor_border");
  183. this.setStyles((layout.mobile) ? _self.css.identityNode_mobile : _self.css.identityNode);
  184. this.getFirst().getLast().setStyles(_self.css.identityInforNameTextNode);
  185. this.getFirst().getNext().getFirst().setStyles(_self.css.identityTitleNode);
  186. this.getFirst().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode);
  187. //this.getFirst().getNext().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode);
  188. },
  189. "click": function(){
  190. var identity = this.retrieve("identity");
  191. if (identity){
  192. _self.okStartProcess(identity.data.distinguishedName);
  193. }
  194. }
  195. });
  196. // if (id.data.major){
  197. // id.node.setStyles(this.css.identityNode_over);
  198. // id.node.getFirst().getLast().setStyles(this.css.identityInforNameTextNode_over);
  199. // id.node.getFirst().getNext().getFirst().setStyles(this.css.identityTitleNode_over);
  200. // id.node.getFirst().getNext().getNext().getFirst().setStyles(this.css.identityTitleNode_over);
  201. // }
  202. }.bind(this));
  203. if (layout.mobile){
  204. this.areaNode.setStyles(this.css.areaNode_mobile);
  205. this.createNode.setStyles(this.css.createNode_mobile);
  206. }
  207. },
  208. getOrgAction: function(callback){
  209. if (!this.orgAction){
  210. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  211. if (callback) callback();
  212. // MWF.xDesktop.requireApp("Selector", "Actions.RestActions", function(){
  213. // this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
  214. // if (callback) callback();
  215. // }.bind(this));
  216. }else{
  217. if (callback) callback();
  218. }
  219. },
  220. setStartNodeSize: function(){
  221. if (!layout.mobile){
  222. var size = this.app.content.getSize();
  223. var allSize = this.app.content.getSize();
  224. this.markNode.setStyles({
  225. "width": ""+allSize.x+"px",
  226. "height": ""+allSize.y+"px"
  227. });
  228. this.areaNode.setStyles({
  229. "width": ""+size.x+"px",
  230. "height": ""+size.y+"px"
  231. });
  232. var hY = size.y*0.7;
  233. var mY = size.y*0.3/2;
  234. this.createNode.setStyles({
  235. "height": ""+hY+"px",
  236. "margin-top": ""+mY+"px"
  237. });
  238. var count = this.identitys.length;
  239. if (count>2) count=2;
  240. var w = count*320;
  241. this.formNode.setStyles({
  242. "width": ""+w+"px"
  243. });
  244. w = w + 60;
  245. this.createNode.setStyles({
  246. "width": ""+w+"px"
  247. });
  248. }
  249. },
  250. cancelStartProcess: function(e){
  251. this.markNode.destroy();
  252. this.areaNode.destroy();
  253. },
  254. okStartProcess: function(identity){
  255. var data = {
  256. "title": this.data.name+"-"+this.lp.unnamed,
  257. "latest": this.options.latest,
  258. "skipDraftCheck": this.options.skipDraftCheck,
  259. "identity": identity
  260. };
  261. if( this.options.workData ){
  262. data.data = this.options.workData;
  263. if (data.data.title || data.data.subject) data.title = data.data.title || data.data.subject;
  264. }
  265. if (!data.identity){
  266. this.departmentSelArea.setStyle("border-color", "red");
  267. if (this.app && this.app.notice) this.app.notice(this.lp.selectStartId, "error");
  268. }else{
  269. this.mask = new MWF.widget.Mask({"style": "desktop"});
  270. this.mask.loadNode(this.areaNode);
  271. this.fireEvent("beforeStarted", [data]);
  272. this.getWorkAction(function(){
  273. this.workAction.startWork(function(json){
  274. this.mask.hide();
  275. this.markNode.destroy();
  276. this.areaNode.destroy();
  277. this.fireEvent("started", [json.data, data.title, this.data.name]);
  278. if (this.app && this.app.refreshAll) this.app.refreshAll();
  279. //if (this.app && this.app.notice) this.app.notice(this.lp.processStarted, "success");
  280. // this.app.processConfig();
  281. }.bind(this), function(xhr, text, error){
  282. if (xhr.status!=0){
  283. var errorText = error;
  284. if (xhr){
  285. var json = JSON.decode(xhr.responseText);
  286. if (json){
  287. errorText = json.message.trim() || "request json error";
  288. }else{
  289. errorText = "request json error: "+xhr.responseText;
  290. }
  291. }
  292. MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText);
  293. }
  294. if(this.mask)this.mask.hide();
  295. // if(this.markNode)this.markNode.destroy();
  296. // if(this.areaNode)this.areaNode.destroy();
  297. }.bind(this), this.data.id, data);
  298. }.bind(this));
  299. }
  300. },
  301. getWorkAction: function(callback){
  302. if (!this.workAction){
  303. this.workAction = MWF.Actions.get("x_processplatform_assemble_surface");
  304. if (callback) callback();
  305. // MWF.xDesktop.requireApp("process.TaskCenter", "Actions.RestActions", function(){
  306. // this.workAction = new MWF.xApplication.process.TaskCenter.Actions.RestActions();
  307. // if (callback) callback();
  308. // }.bind(this));
  309. }else{
  310. if (callback) callback();
  311. }
  312. }
  313. });
  314. MWF.xApplication.process.TaskCenter.ProcessStarter.Identity = new Class({
  315. initialize: function(container, data, starter, style){
  316. this.container = $(container);
  317. this.data = data;
  318. this.starter = starter;
  319. this.action = this.starter.orgAction;
  320. this.style = style;
  321. //this.item = item;
  322. this.load();
  323. },
  324. load: function(){
  325. this.node = new Element("div", {
  326. "styles": (layout.mobile) ? this.style.identityNode_mobile : this.style.identityNode
  327. }).inject(this.container);
  328. var nameNode = new Element("div", {
  329. "styles": this.style.identityInforNameNode
  330. }).inject(this.node);
  331. var url = this.action.getPersonIcon(this.starter.app.desktop.session.user.id);
  332. var img = "<img width='50' height='50' border='0' src='"+url+"'></img>";
  333. // if (this.item.data.icon){
  334. // img = "<img width='50' height='50' border='0' src='data:image/png;base64,"+this.item.data.icon+"'></img>"
  335. // }else{
  336. // if (this.item.data.genderType=="f"){
  337. // img = "<img width='50' height='50' border='0' src='"+"../x_component_Organization/$PersonExplorer/default/icon/female.png'></img>";
  338. // }else{
  339. // img = "<img width='50' height='50' border='0' src='"+"../x_component_Organization/$PersonExplorer/default/icon/man.png'></img>";
  340. // }
  341. // }
  342. var picNode = new Element("div", {
  343. "styles": this.style.identityInforPicNode,
  344. "html": img
  345. }).inject(nameNode);
  346. var nameTextNode = new Element("div", {
  347. "styles": this.style.identityInforNameTextNode,
  348. "text": this.data.name
  349. }).inject(nameNode);
  350. var unitNode = new Element("div", {"styles": this.style.identityDepartmentNode}).inject(this.node);
  351. var unitTitleNode = new Element("div", {
  352. "styles": this.style.identityTitleNode,
  353. "text": MWF.xApplication.process.TaskCenter.LP.unit
  354. }).inject(unitNode);
  355. this.unitTextNode = new Element("div", {"styles": this.style.identityTextNode}).inject(unitNode);
  356. if (this.data.woUnit) this.unitTextNode.set({"text": this.data.woUnit.levelName, "title": this.data.woUnit.levelName});
  357. // var companyNode = new Element("div", {"styles": this.style.identityCompanyNode}).inject(this.node);
  358. // var companyTitleNode = new Element("div", {
  359. // "styles": this.style.identityTitleNode,
  360. // "text": this.item.explorer.app.lp.company
  361. // }).inject(companyNode);
  362. // this.companyTextNode = new Element("div", {"styles": this.style.identityTextNode}).inject(companyNode);
  363. var dutyNode = new Element("div", {"styles": this.style.identityDutyNode}).inject(this.node);
  364. var dutyTitleNode = new Element("div", {
  365. "styles": this.style.identityTitleNode,
  366. "text": MWF.xApplication.process.TaskCenter.LP.duty
  367. }).inject(dutyNode);
  368. this.dutyTextNode = new Element("div", {"styles": this.style.identityTextNode}).inject(dutyNode);
  369. var dutyTextList = [];
  370. var dutyTitleList = [];
  371. this.data.woUnitDutyList.each(function(duty){
  372. dutyTextList.push(duty.name);
  373. if (duty.woUnit) dutyTitleList.push(duty.name+"("+duty.woUnit.levelName+")");
  374. }.bind(this));
  375. this.dutyTextNode.set({"text": dutyTextList.join(", "), "title": dutyTitleList.join(", ")});
  376. var unitTextNode = new Element("div.mainColor_color", {
  377. "styles": this.style.identityInforUnitTextNode,
  378. "text": "【"+this.data.woUnit.name+"】"
  379. }).inject(this.node);
  380. // this.item.explorer.actions.getDepartment(function(json){
  381. // this.department = json.data;
  382. // this.departmentTextNode.set({"text": this.department.name, "title": this.department.name});
  383. //
  384. // this.item.explorer.actions.getCompany(function(json){
  385. // this.company = json.data;
  386. // this.companyTextNode.set({"text": this.company.name, "title": this.company.name});
  387. // }.bind(this), null, this.department.company);
  388. //
  389. // }.bind(this), null, this.data.department);
  390. //
  391. //
  392. // this.item.explorer.actions.listCompanyDutyByIdentity(function(json){
  393. // json.data.each(function(duty){
  394. // var text = this.dutyTextNode.get("text");
  395. // if (text){
  396. // text = text+", "+duty.name;
  397. // }else{
  398. // text = duty.name;
  399. // }
  400. // this.dutyTextNode.set({"text": text, "title": text});
  401. // }.bind(this));
  402. // }.bind(this), null, this.data.id);
  403. // this.item.explorer.actions.listDepartmentDutyByIdentity(function(json){
  404. // json.data.each(function(duty){
  405. // var text = this.dutyTextNode.get("text");
  406. // if (text){
  407. // text = text+", "+duty.name;
  408. // }else{
  409. // text = duty.name;
  410. // }
  411. // this.dutyTextNode.set({"text": text, "title": text});
  412. // }.bind(this));
  413. // }.bind(this), null, this.data.id);
  414. }
  415. });
  416. // MWF.xApplication.process.TaskCenter.ProcessStarter.DepartmentSel = new Class({
  417. // initialize: function(data, starter, container, idArea){
  418. // this.data = data;
  419. // this.starter = starter;
  420. // this.container = container;
  421. // this.idArea = idArea;
  422. // this.css = this.starter.css;
  423. // this.isSelected = false;
  424. // this.load();
  425. // },
  426. // load: function(){
  427. //
  428. // this.node = new Element("div", {"styles": this.css.departSelNode}).inject(this.container);
  429. // this.starter.orgAction.getDepartmentByIdentity(function(department){
  430. // this.node.set("text", department.data.name);
  431. // }.bind(this), null, this.data.name);
  432. //
  433. // this.node.addEvents({
  434. // "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_over);}.bind(this),
  435. // "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_out);}.bind(this),
  436. // "click": function(){
  437. // this.selected();
  438. // }.bind(this),
  439. // });
  440. // },
  441. // selected: function(){
  442. // if (!this.isSelected){
  443. // if (this.starter.currentDepartment) this.starter.currentDepartment.unSelected();
  444. // this.node.setStyles(this.css.departSelNode_selected);
  445. // this.isSelected = true;
  446. // this.starter.currentDepartment = this;
  447. //
  448. // this.idArea.set({
  449. // "text": this.data.display,
  450. // "value": this.data.name
  451. // });
  452. // }
  453. // },
  454. // unSelected: function(){
  455. // if (this.isSelected){
  456. // if (this.starter.currentDepartment) this.starter.currentDepartment = null;;
  457. // this.node.setStyles(this.css.departSelNode);
  458. // this.isSelected = false;
  459. // }
  460. // }
  461. //
  462. // });