ProcessStarter.js 17 KB

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