Task.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. draw2d.Task = function() {
  2. this.cornerWidth = 15;
  3. this.cornerHeight = 15;
  4. this.rightOutputPort = null;
  5. this.bottomOutputPort = null;
  6. this.topOutputPort = null;
  7. this.leftOutputPort = null;
  8. this.alpha=1;
  9. draw2d.Node.call(this);
  10. this.setDimension(90,50);
  11. this.originalHeight = -1;
  12. this.taskId=null;
  13. this.taskName=null;
  14. this.performerType=null;
  15. this.isUseExpression=false;
  16. this.expression=null;
  17. this.formKey = null;
  18. this.documentation=null;
  19. this.scriptFormat=null;
  20. this.resultVariable=null;
  21. this.toEmail=null;
  22. this.fromEmail=null;
  23. this.subjectEmail=null;
  24. this.ccEmail=null;
  25. this.bccEmail=null;
  26. this.charsetEmail=null;
  27. this.htmlEmail=null;
  28. this.textEmail=null;
  29. this.rulesInput=null;
  30. this.rulesOutputs=null;
  31. this.rules=null;
  32. this.isclude="";
  33. //begin---author:zhangdaihao date:20140730 for:动态会签
  34. this.task_extend=null;
  35. this.isSequential=null;
  36. this.loopCardinality=null;
  37. this.collection=null;
  38. this.elementVariable=null;
  39. this.completionCondition=null;
  40. //end---author:zhangdaihao date:20140730 for:动态会签
  41. this.listeners=new draw2d.ArrayList();
  42. this.forms=new draw2d.ArrayList();
  43. this.candidateUsers=new draw2d.ArrayList();
  44. this.candidateGroups=new draw2d.ArrayList();
  45. };
  46. draw2d.Task.prototype = new draw2d.Node();
  47. draw2d.Task.prototype.type = "Task";
  48. draw2d.Task.prototype.generateId=function(){
  49. this.id="task"+Sequence.create();
  50. this.taskId=this.id;
  51. this.taskName=this.id;
  52. this.scriptFormat='Groovy';
  53. this.charsetEmail='UTF8';
  54. };
  55. //双击流程元素打开属性页面
  56. draw2d.Task.prototype.figureDoubleClick=function(){
  57. var data = {event:this};
  58. var event = data.event;
  59. nodeid = event.getId();
  60. openProperties(nodeid,'taskProperties','task');
  61. };
  62. draw2d.Task.prototype.createHTMLElement = function() {
  63. var item = document.createElement("div");
  64. item.id = this.id;
  65. item.style.position = "absolute";
  66. item.style.left = this.x + "px";
  67. item.style.top = this.y + "px";
  68. item.style.height = this.width + "px";
  69. item.style.width = this.height + "px";
  70. item.className="task";
  71. item.style.zIndex = "" + draw2d.Figure.ZOrderBaseIndex;
  72. this.top_left = document.createElement("div");
  73. this.top_left.className="task-top-left";
  74. this.top_left.style.width = this.cornerWidth + "px";
  75. this.top_left.style.height = this.cornerHeight + "px";
  76. this.top_right = document.createElement("div");
  77. this.top_right.className="task-top-right";
  78. this.top_right.style.width = this.cornerWidth + "px";
  79. this.top_right.style.height = this.cornerHeight + "px";
  80. this.bottom_left = document.createElement("div");
  81. this.bottom_left.className="bottom-top-left";
  82. this.bottom_left.style.width = this.cornerWidth + "px";
  83. this.bottom_left.style.height = this.cornerHeight + "px";
  84. this.bottom_right = document.createElement("div");
  85. this.bottom_right.className="bottom-top-right";
  86. this.bottom_right.style.width = this.cornerWidth + "px";
  87. this.bottom_right.style.height = this.cornerHeight + "px";
  88. this.header = document.createElement("div");
  89. this.header.className="task-header";
  90. this.header.style.position = "absolute";
  91. this.header.style.left = this.cornerWidth + "px";
  92. this.header.style.top = "0px";
  93. this.header.style.height = (this.cornerHeight) + "px";
  94. this.disableTextSelection(this.header);
  95. this.footer = document.createElement("div");
  96. this.footer.className="task-footer";
  97. this.footer.style.position = "absolute";
  98. this.footer.style.left = this.cornerWidth + "px";
  99. this.footer.style.top = "0px";
  100. this.footer.style.height = (this.cornerHeight-1) + "px";
  101. this.textarea = document.createElement("div");
  102. this.textarea.className="task-textarea";
  103. this.textarea.style.position = "absolute";
  104. this.textarea.style.left = "0px";
  105. this.textarea.style.top = this.cornerHeight + "px";
  106. this.disableTextSelection(this.textarea);
  107. item.appendChild(this.top_left);
  108. item.appendChild(this.header);
  109. item.appendChild(this.top_right);
  110. item.appendChild(this.textarea);
  111. item.appendChild(this.bottom_left);
  112. item.appendChild(this.footer);
  113. item.appendChild(this.bottom_right);
  114. return item;
  115. };
  116. draw2d.Task.prototype.setDimension = function(w, h) {
  117. try{
  118. draw2d.Node.prototype.setDimension.call(this, w, h);
  119. if (this.top_left !== null) {
  120. this.top_right.style.left = (this.width - this.cornerWidth) + "px";
  121. this.bottom_right.style.left = (this.width - this.cornerWidth) + "px";
  122. this.bottom_right.style.top = (this.height - this.cornerHeight) + "px";
  123. this.bottom_left.style.top = (this.height - this.cornerHeight) + "px";
  124. this.textarea.style.width = (this.width - 2) + "px";
  125. this.textarea.style.height = (this.height - this.cornerHeight * 2)
  126. + "px";
  127. this.header.style.width = (this.width - this.cornerWidth * 2) + "px";
  128. this.footer.style.width = (this.width - this.cornerWidth * 2) + "px";
  129. this.footer.style.top = (this.height - this.cornerHeight) + "px";
  130. }
  131. if (this.rightOutputPort !== null) {
  132. this.rightOutputPort.setPosition(this.width + 5, this.height / 2);
  133. }
  134. if (this.bottomOutputPort !== null) {
  135. this.bottomOutputPort.setPosition(this.width/2, this.height + 5);
  136. }
  137. if (this.leftOutputPort !== null) {
  138. this.leftOutputPort.setPosition(-5, this.height / 2);
  139. }
  140. if (this.topOutputPort !== null) {
  141. this.topOutputPort.setPosition(this.width/2, -5);
  142. }
  143. }catch(e){
  144. }
  145. };
  146. draw2d.Task.prototype.setTitle = function(title) {
  147. this.header.innerHTML = title;
  148. };
  149. draw2d.Task.prototype.setContent = function(_5014) {
  150. this.textarea.innerHTML = _5014;
  151. };
  152. draw2d.Task.prototype.onDragstart = function(x, y) {
  153. var _5017 = draw2d.Node.prototype.onDragstart.call(this, x, y);
  154. if (this.header === null) {
  155. return false;
  156. }
  157. if (y < this.cornerHeight && x < this.width
  158. && x > (this.width - this.cornerWidth)) {
  159. this.toggle();
  160. return false;
  161. }
  162. if (this.originalHeight == -1) {
  163. if (this.canDrag === true && x < parseInt(this.header.style.width)
  164. && y < parseInt(this.header.style.height)) {
  165. return true;
  166. }
  167. } else {
  168. return _5017;
  169. }
  170. };
  171. draw2d.Task.prototype.setCanDrag = function(flag) {
  172. draw2d.Node.prototype.setCanDrag.call(this, flag);
  173. this.html.style.cursor = "";
  174. if (this.header === null) {
  175. return;
  176. }
  177. if (flag) {
  178. this.header.style.cursor = "move";
  179. } else {
  180. this.header.style.cursor = "";
  181. }
  182. };
  183. draw2d.Task.prototype.setWorkflow = function(_5019) {
  184. draw2d.Node.prototype.setWorkflow.call(this, _5019);
  185. if (_5019 !== null && this.leftOutputPort === null) {
  186. this.leftOutputPort = new draw2d.MyOutputPort();
  187. this.leftOutputPort.setWorkflow(_5019);
  188. this.leftOutputPort.setName("leftOutputPort");
  189. this.addPort(this.leftOutputPort, -5, this.height / 2);
  190. this.topOutputPort = new draw2d.MyOutputPort();
  191. this.topOutputPort.setWorkflow(_5019);
  192. this.topOutputPort.setName("topOutputPort");
  193. this.addPort(this.topOutputPort, this.width/2, -5);
  194. this.rightOutputPort = new draw2d.MyOutputPort();
  195. this.rightOutputPort.setMaxFanOut(5);
  196. this.rightOutputPort.setWorkflow(_5019);
  197. this.rightOutputPort.setName("rightOutputPort");
  198. this.addPort(this.rightOutputPort, this.width + 5, this.height / 2);
  199. this.bottomOutputPort = new draw2d.MyOutputPort();
  200. this.bottomOutputPort.setMaxFanOut(5);
  201. this.bottomOutputPort.setWorkflow(_5019);
  202. this.bottomOutputPort.setName("bottomOutputPort");
  203. this.addPort(this.bottomOutputPort, this.width/2, this.height + 5);
  204. }
  205. };
  206. //点击加号收缩任务节点
  207. draw2d.Task.prototype.toggle = function() {
  208. if (this.originalHeight == -1) {
  209. //this.originalHeight = this.height;
  210. //this.setDimension(this.width, this.cornerHeight * 2);
  211. //this.setResizeable(false);
  212. } else {
  213. //this.setDimension(this.width, this.originalHeight);
  214. // this.originalHeight = -1;
  215. // this.setResizeable(true);
  216. }
  217. };
  218. /*
  219. draw2d.Task.prototype.onDoubleClick=function(){
  220. var tid = this.getId();
  221. openTaskProperties(tid);
  222. };
  223. */
  224. draw2d.Task.prototype.getContextMenu=function(){
  225. if(this.workflow.disabled)return null;
  226. var menu =new draw2d.ContextMenu(100, 50);
  227. var data = {task:this};
  228. menu.appendMenuItem(new draw2d.ContextMenuItem("属性", "properties-icon",data,function(x,y)
  229. {
  230. var data = this.getData();
  231. var task = data.task;
  232. nodeid = task.getId();
  233. if(typeof openProperties != "undefined"){
  234. openProperties(nodeid,'taskProperties','task');
  235. }
  236. }));
  237. menu.appendMenuItem(new draw2d.ContextMenuItem("删除", "icon-remove",data,function(x,y)
  238. {
  239. var data = this.getData();
  240. var task = data.task;
  241. var tid = task.getId();
  242. var wf = task.getWorkflow();
  243. wf.getCommandStack().execute(new draw2d.CommandDelete(task));
  244. //wf.removeFigure(task);
  245. }));
  246. return menu;
  247. };
  248. draw2d.Task.prototype.setIcon = function(){
  249. this.icon = document.createElement("div");
  250. this.icon.style.position = "absolute";
  251. this.icon.style.width = this.cornerWidth + "px";
  252. this.icon.style.height = this.cornerHeight + "px";
  253. this.icon.style.left = "6px";
  254. this.icon.style.top = "1px";
  255. this.getHTMLElement().appendChild(this.icon);
  256. return this.icon;
  257. };
  258. draw2d.Task.prototype.getListener=function(id){
  259. for(var i=0;i<this.listeners.getSize();i++){
  260. var listener = this.listeners.get(i);
  261. if(listener.getId()=== id){
  262. return listener;
  263. }
  264. }
  265. };
  266. draw2d.Task.prototype.getForm=function(id){
  267. for(var i=0;i<this.forms.getSize();i++){
  268. var form = this.forms.get(i);
  269. if(form.getId()=== id){
  270. return form;
  271. }
  272. }
  273. };
  274. draw2d.Task.prototype.deleteListener=function(id){
  275. var listener = this.getListener(id);
  276. this.listeners.remove(listener);
  277. };
  278. draw2d.Task.prototype.deleteForm=function(id){
  279. var form = this.getForm(id);
  280. this.forms.remove(form);
  281. };
  282. draw2d.Task.prototype.addListener=function(listener){
  283. this.listeners.add(listener);
  284. };
  285. draw2d.Task.prototype.addForm=function(form){
  286. this.forms.add(form);
  287. };
  288. draw2d.Task.prototype.setListeners=function(listeners){
  289. this.listeners = listeners;
  290. };
  291. draw2d.Task.prototype.setForms=function(forms){
  292. this.forms = forms;
  293. };
  294. draw2d.Task.prototype.getCandidateUser=function(sso){
  295. for(var i=0;i<this.candidateUsers.getSize();i++){
  296. var candidate = this.candidateUsers.get(i);
  297. if(candidate.sso===sso){
  298. return candidate;
  299. }
  300. }
  301. return null;
  302. };
  303. draw2d.Task.prototype.deleteCandidateUser=function(sso){
  304. var candidate = this.getCandidateUser(sso);
  305. this.candidateUsers.remove(candidate);
  306. };
  307. draw2d.Task.prototype.addCandidateUser=function(user){
  308. if(this.getCandidateUser(user.sso)==null)
  309. this.candidateUsers.add(user);
  310. };
  311. draw2d.Task.prototype.getCandidateGroup=function(name){
  312. for(var i=0;i<this.candidateGroups.getSize();i++){
  313. var candidate = this.candidateGroups.get(i);
  314. if(candidate===name){
  315. return candidate;
  316. }
  317. }
  318. return null;
  319. };
  320. draw2d.Task.prototype.deleteCandidateGroup=function(name){
  321. var candidate = this.getCandidateGroup(name);
  322. this.candidateGroups.remove(candidate);
  323. };
  324. draw2d.Task.prototype.addCandidateGroup=function(name){
  325. if(!this.candidateGroups.contains(name))
  326. this.candidateGroups.add(name);
  327. };
  328. draw2d.Task.prototype.setHighlight=function(){
  329. this.getHTMLElement().className="task-highlight";
  330. };
  331. draw2d.Task.prototype.onMouseEnter=function(){
  332. if(typeof onTaskMouseEnter != "undefined"){
  333. onTaskMouseEnter(this);
  334. }
  335. };
  336. draw2d.Task.prototype.onMouseLeave=function(){
  337. if(typeof onTaskMouseLeave != "undefined"){
  338. onTaskMouseLeave(this);
  339. }
  340. };