ProcessStarter.js 19 KB

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