ProcessStarter.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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.xApplication.process.TaskCenter.ProcessStarter = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default"
  9. },
  10. initialize: function(data, app, options){
  11. this.setOptions(options);
  12. this.path = "/x_component_process_TaskCenter/$ProcessStarter/";
  13. this.cssPath = "/x_component_process_TaskCenter/$ProcessStarter/"+this.options.style+"/css.wcss";
  14. this._loadCss();
  15. MWF.xDesktop.requireApp("process.TaskCenter", "$ProcessStarter."+MWF.language, null, false);
  16. this.lp = MWF.xApplication.process.TaskCenter.ProcessStarter.lp;
  17. this.data = data;
  18. this.app = app;
  19. },
  20. load: function(){
  21. this.getOrgAction(function(){
  22. if (this.app.desktop.session.user.name){
  23. this.orgAction.listIdentityByPerson(function(json){
  24. this.identitys = json.data;
  25. if (json.data.length){
  26. if (json.data.length==1){
  27. var data = {
  28. "title": this.data.name+"-"+this.lp.unnamed,
  29. "identity": this.identitys[0].name
  30. };
  31. this.mask = new MWF.widget.Mask({"style": "desktop"});
  32. this.mask.loadNode(this.app.content);
  33. this.getWorkAction(function(){
  34. this.workAction.startWork(function(json){
  35. this.mask.hide();
  36. //this.markNode.destroy();
  37. //this.areaNode.destroy();
  38. this.fireEvent("started", [json.data, data.title, this.data.name]);
  39. this.app.refreshAll();
  40. this.app.notice(this.lp.processStarted, "success");
  41. // this.app.processConfig();
  42. }.bind(this), null, this.data.id, data);
  43. }.bind(this));
  44. }else{
  45. this.createMarkNode();
  46. this.createAreaNode();
  47. this.createStartNode();
  48. this.areaNode.inject(this.markNode, "after");
  49. this.areaNode.fade("in");
  50. //$("form_startSubject").focus();
  51. this.setStartNodeSize();
  52. this.setStartNodeSizeFun = this.setStartNodeSize.bind(this);
  53. this.app.addEvent("resize", this.setStartNodeSizeFun);
  54. }
  55. }
  56. }.bind(this), null, this.app.desktop.session.user.id)
  57. }
  58. }.bind(this));
  59. },
  60. createMarkNode: function(){
  61. this.markNode = new Element("div#mark", {
  62. "styles": this.css.markNode,
  63. "events": {
  64. "mouseover": function(e){e.stopPropagation();},
  65. "mouseout": function(e){e.stopPropagation();}
  66. }
  67. }).inject(this.app.content);
  68. },
  69. createAreaNode: function(){
  70. this.areaNode = new Element("div#area", {
  71. "styles": this.css.areaNode
  72. });
  73. },
  74. createStartNode: function(){
  75. this.createNode = new Element("div", {
  76. "styles": this.css.createNode
  77. }).inject(this.areaNode);
  78. this.createNewNode = new Element("div", {
  79. "styles": this.css.createNewNode
  80. }).inject(this.createNode);
  81. this.createCloseNode = new Element("div", {
  82. "styles": this.css.createCloseNode
  83. }).inject(this.createNode);
  84. this.createCloseNode.addEvent("click", function(e){
  85. this.cancelStartProcess(e);
  86. }.bind(this));
  87. this.formNode = new Element("div", {
  88. "styles": this.css.formNode
  89. }).inject(this.createNode);
  90. var html = "<table width=\"100%\" height=\"90%\" border=\"0\" cellPadding=\"0\" cellSpacing=\"0\">" +
  91. "<tr><td colSpan=\"2\" style=\"height: 50px; line-height: 60px; text-align: center; font-size: 24px; font-weight: bold\">" +
  92. this.lp.start+" - "+this.data.name+"</td></tr>" +
  93. "<tr><td colSpan=\"2\" style=\"height: 40px; color: #0044cc; line-height: 60px; text-align: center; font-size: 18px; font-weight: bold\">" +
  94. this.lp.selectStartIdentity+"</td></tr>" +
  95. "<tr><td colSpan=\"2\" id=\"form_startIdentity\"></td></tr>" +
  96. //"<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.department+":</td>" +
  97. //"<td style=\"; text-align: left;\" id=\"form_startDepartment\"></td></tr>" +
  98. //"<tr><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.identity+":</td>" +
  99. //"<td style=\"; text-align: left;\"><div id=\"form_startIdentity\"></div></td></tr>" +
  100. //"<tr style=\"display: none\"><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.date+":</td>" +
  101. //"<td style=\"; text-align: left;\"><div id=\"form_startDate\"></div></td></tr>" +
  102. //"<tr style=\"display: none\"><td style=\"height: 30px; line-height: 30px; text-align: left\">"+this.lp.subject+":</td>" +
  103. //"<td style=\"text-align: left;\"><input type=\"text\" id=\"form_startSubject\" " +
  104. //"style=\"width: 99%; border:1px solid #999; background-color:#FFF; border-radius: 3px; box-shadow: 0px 0px 6px #CCC; " +
  105. //"height: 26px;\"/></td></tr>" +
  106. "</table>";
  107. this.formNode.set("html", html);
  108. this.identityArea = this.formNode.getElementById("form_startIdentity");
  109. MWF.xDesktop.requireApp("Organization", "PersonExplorer", function(){
  110. var o = {
  111. "data": this.app.desktop.session.user,
  112. "explorer":{
  113. "app": {
  114. "lp":this.lp
  115. },
  116. "actions": this.orgAction
  117. }
  118. };
  119. var _self = this;
  120. this.identitys.each(function(item){
  121. var id = new MWF.xApplication.Organization.PersonExplorer.Identity(this.identityArea, item, o, this.css);
  122. id.node.store("identity", id);
  123. id.node.addEvents({
  124. "mouseover": function(){
  125. this.setStyles(_self.css.identityNode_over);
  126. this.getFirst().getLast().setStyles(_self.css.identityInforNameTextNode_over);
  127. this.getFirst().getNext().getFirst().setStyles(_self.css.identityTitleNode_over);
  128. this.getFirst().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode_over);
  129. this.getFirst().getNext().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode_over);
  130. },
  131. "mouseout": function(){
  132. this.setStyles(_self.css.identityNode);
  133. this.getFirst().getLast().setStyles(_self.css.identityInforNameTextNode);
  134. this.getFirst().getNext().getFirst().setStyles(_self.css.identityTitleNode);
  135. this.getFirst().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode);
  136. this.getFirst().getNext().getNext().getNext().getFirst().setStyles(_self.css.identityTitleNode);
  137. },
  138. "click": function(){
  139. var identity = this.retrieve("identity");
  140. if (identity){
  141. _self.okStartProcess(identity.data.name);
  142. }
  143. }
  144. });
  145. }.bind(this));
  146. }.bind(this));
  147. //
  148. //this.setStartFormContent();
  149. //this.actionNode = new Element("div", {
  150. // "styles": this.css.actionNode
  151. //}).inject(this.formNode);
  152. //
  153. //
  154. //this.cancelActionNode.addEvent("click", function(e){
  155. // this.cancelStartProcess(e);
  156. //}.bind(this));
  157. //this.startOkActionNode.addEvent("click", function(e){
  158. // this.okStartProcess(e);
  159. //}.bind(this));
  160. },
  161. setStartFormContent: function(){
  162. this.dateArea = this.formNode.getElementById("form_startDate");
  163. var d = new Date();
  164. this.dateArea.set("text", d.format("%Y-%m-%d %H:%M"));
  165. this.departmentSelArea = this.formNode.getElementById("form_startDepartment");
  166. this.identityArea = this.formNode.getElementById("form_startIdentity");
  167. this.getOrgAction(function(){
  168. //if (!this.app.desktop.user.id){
  169. // this.orgAction.listPersonByKey(function(json){
  170. // if (json.data.length) this.app.desktop.user.id = json.data[0].id
  171. // this.loadDepartments();
  172. // }.bind(this), null, this.app.desktop.user.name);
  173. //}else{
  174. // this.loadDepartments();
  175. //}
  176. this.loadDepartments();
  177. }.bind(this));
  178. },
  179. loadDepartments: function(){
  180. //if (this.app.desktop.user.id){
  181. // this.orgAction.listIdentityByPerson(function(json){
  182. // var selected = (json.data.length==1) ? true : false;
  183. // json.data.each(function(id){
  184. // var departSel = new MWF.xApplication.process.TaskCenter.ProcessStarter.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  185. // if (selected) departSel.selected();
  186. // }.bind(this));
  187. // }.bind(this), null, this.app.desktop.user.id)
  188. //}
  189. //if (this.app.desktop.session.user.name){
  190. // this.orgAction.listIdentityByPerson(function(json){
  191. // var selected = (json.data.length==1) ? true : false;
  192. // json.data.each(function(id){
  193. // var departSel = new MWF.xApplication.process.TaskCenter.ProcessStarter.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  194. // if (selected) departSel.selected();
  195. // }.bind(this));
  196. // }.bind(this), null, this.app.desktop.session.user.name)
  197. //}
  198. var selected = (this.identitys.length==1);
  199. this.identitys.each(function(id){
  200. var departSel = new MWF.xApplication.process.TaskCenter.ProcessStarter.DepartmentSel(id, this, this.departmentSelArea, this.identityArea);
  201. if (selected) departSel.selected();
  202. }.bind(this));
  203. },
  204. getOrgAction: function(callback){
  205. if (!this.orgAction){
  206. MWF.xDesktop.requireApp("Organization", "Actions.RestActions", function(){
  207. this.orgAction = new MWF.xApplication.Organization.Actions.RestActions();
  208. if (callback) callback();
  209. }.bind(this));
  210. //MWF.require("MWF.xAction.org.express.RestActions", function(){
  211. // this.orgAction = new MWF.xAction.org.express.RestActions();
  212. // if (callback) callback();
  213. //}.bind(this));
  214. }else{
  215. if (callback) callback();
  216. }
  217. },
  218. setStartNodeSize: function(){
  219. var size = this.app.content.getSize();
  220. var allSize = this.app.content.getSize();
  221. this.markNode.setStyles({
  222. "width": ""+allSize.x+"px",
  223. "height": ""+allSize.y+"px"
  224. });
  225. this.areaNode.setStyles({
  226. "width": ""+size.x+"px",
  227. "height": ""+size.y+"px"
  228. });
  229. var hY = size.y*0.7;
  230. var mY = size.y*0.3/2;
  231. this.createNode.setStyles({
  232. "height": ""+hY+"px",
  233. "margin-top": ""+mY+"px"
  234. });
  235. var w = this.identitys.length*294;
  236. this.formNode.setStyles({
  237. "width": ""+w+"px"
  238. });
  239. w = w + 60;
  240. this.createNode.setStyles({
  241. "width": ""+w+"px"
  242. });
  243. //var iconSize = this.createNewNode.getSize();
  244. //var formHeight = hY*0.7;
  245. //if (formHeight>250) formHeight = 250;
  246. //var formMargin = hY*0.3/2-iconSize.y;
  247. //this.formNode.setStyles({
  248. // "height": ""+formHeight+"px",
  249. // "margin-top": ""+formMargin+"px"
  250. //});
  251. },
  252. cancelStartProcess: function(e){
  253. //var _self = this;
  254. //if ($("form_startSubject").get("value")){
  255. // this.app.confirm("warn", e, this.lp.startProcess_cancel_title, this.lp.startProcess_cancel, "320px", "100px", function(){
  256. // _self.markNode.destroy();
  257. // _self.areaNode.destroy();
  258. // this.close();
  259. // },function(){
  260. // this.close();
  261. // }, null, this.app.content);
  262. //}else{
  263. // this.markNode.destroy();
  264. // this.areaNode.destroy();
  265. //}
  266. this.markNode.destroy();
  267. this.areaNode.destroy();
  268. },
  269. okStartProcess: function(identity){
  270. //var title = $("form_startSubject").get("value");
  271. //var data = {
  272. // "title": title,
  273. // "identity": this.identityArea.get("value")
  274. //};
  275. var data = {
  276. "title": this.data.name+"-"+this.lp.unnamed,
  277. //"identity": this.identityArea.get("value")
  278. "identity": identity
  279. };
  280. //if (!data.title){
  281. // $("form_startSubject").setStyle("border-color", "red");
  282. // $("form_startSubject").focus();
  283. // this.app.notice(this.lp.inputProcessSubject, "error");
  284. //}else
  285. if (!data.identity){
  286. this.departmentSelArea.setStyle("border-color", "red");
  287. this.app.notice(this.lp.selectStartId, "error");
  288. }else{
  289. this.mask = new MWF.widget.Mask({"style": "desktop"});
  290. this.mask.loadNode(this.areaNode);
  291. this.getWorkAction(function(){
  292. this.workAction.startWork(function(json){
  293. this.mask.hide();
  294. this.markNode.destroy();
  295. this.areaNode.destroy();
  296. this.fireEvent("started", [json.data, data.title, this.data.name]);
  297. this.app.refreshAll();
  298. this.app.notice(this.lp.processStarted, "success");
  299. // this.app.processConfig();
  300. }.bind(this), null, this.data.id, data);
  301. }.bind(this));
  302. }
  303. },
  304. getWorkAction: function(callback){
  305. if (!this.workAction){
  306. MWF.xDesktop.requireApp("process.TaskCenter", "Actions.RestActions", function(){
  307. this.workAction = new MWF.xApplication.process.TaskCenter.Actions.RestActions();
  308. if (callback) callback();
  309. }.bind(this));
  310. }else{
  311. if (callback) callback();
  312. }
  313. }
  314. });
  315. MWF.xApplication.process.TaskCenter.ProcessStarter.DepartmentSel = new Class({
  316. initialize: function(data, starter, container, idArea){
  317. this.data = data;
  318. this.starter = starter;
  319. this.container = container;
  320. this.idArea = idArea;
  321. this.css = this.starter.css;
  322. this.isSelected = false;
  323. this.load();
  324. },
  325. load: function(){
  326. this.node = new Element("div", {"styles": this.css.departSelNode}).inject(this.container);
  327. this.starter.orgAction.getDepartmentByIdentity(function(department){
  328. this.node.set("text", department.data.name);
  329. }.bind(this), null, this.data.name);
  330. this.node.addEvents({
  331. "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_over);}.bind(this),
  332. "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.departSelNode_out);}.bind(this),
  333. "click": function(){
  334. this.selected();
  335. }.bind(this),
  336. });
  337. },
  338. selected: function(){
  339. if (!this.isSelected){
  340. if (this.starter.currentDepartment) this.starter.currentDepartment.unSelected();
  341. this.node.setStyles(this.css.departSelNode_selected);
  342. this.isSelected = true;
  343. this.starter.currentDepartment = this;
  344. this.idArea.set({
  345. "text": this.data.display,
  346. "value": this.data.name
  347. });
  348. }
  349. },
  350. unSelected: function(){
  351. if (this.isSelected){
  352. if (this.starter.currentDepartment) this.starter.currentDepartment = null;;
  353. this.node.setStyles(this.css.departSelNode);
  354. this.isSelected = false;
  355. }
  356. }
  357. });