ProcessStarter.js 19 KB

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