mydesigner.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. var workflow;
  2. var processDefinitionId="";//流程主键ID
  3. var processDefinitionName = "";
  4. var processDefinitionVariables = "";
  5. var nodeid="";
  6. var rows="";
  7. //根据Id获取流程XML
  8. function openProcessDef(id) {
  9. $.ajax({
  10. //update-begin--Author:scott Date:20170703 for:重构变更请求control类-----
  11. url : "designerController.do?getProcessXml",
  12. //update-end--Author:scott Date:20170703 for:重构变更请求control类-----
  13. dataType : 'xml',
  14. data : {
  15. processId : id
  16. },
  17. error : function(data) {
  18. return "";
  19. },
  20. success : function(data)
  21. {
  22. parseProcessDescriptor(data);
  23. }
  24. });
  25. }
  26. //编辑流程时初始化流程图
  27. function createCanvas(processid,disabled) {
  28. processDefinitionId =processid;
  29. try {
  30. workflow = new draw2d.MyCanvas("paintarea");
  31. workflow.scrollArea = document.getElementById("designer-area");
  32. if (disabled)
  33. workflow.setDisabled();
  34. //update-begin--Author:chenxu Date:20130327 for:流程设计,开始节点,设置发起人表达式存在浏览器兼容问题,在google和360浏览器下,保存不了
  35. if (typeof processDefinitionId != "undefined" && processDefinitionId != "0")
  36. { //update-end--Author:chenxu Date:20130327 for:流程设计,开始节点,设置发起人表达式存在浏览器兼容问题,在google和360浏览器下,保存不了
  37. openProcessDef(processDefinitionId);
  38. } else {
  39. var id = "process" + Sequence.create();
  40. workflow.process.category = 'http://www.jeecg.org';
  41. workflow.process.id = id;
  42. workflow.process.name = id;
  43. workflow.process.documentation='流程描述';
  44. var startObj = new draw2d.Start();
  45. startObj.setId("start");
  46. workflow.addFigure(startObj, 200, 50);
  47. var endObj = new draw2d.End();
  48. endObj.setId("end");
  49. workflow.addFigure(endObj, 200, 400);
  50. }
  51. } catch (e) {
  52. tip(e.message);
  53. }
  54. }
  55. //添加流程元素模型
  56. function addModel(name, x, y, icon) {
  57. var model = null;
  58. if (icon != null && icon != undefined)
  59. model = eval("new draw2d." + name + "('" + icon + "')");
  60. else
  61. model = eval("new draw2d." + name + "()");
  62. model.generateId();
  63. workflow.addModel(model, x, y);
  64. }
  65. //删除流程元素模型
  66. function deleteModel(id) {
  67. var task = workflow.getFigure(id);
  68. workflow.removeFigure(task);
  69. }
  70. //打开属性页面
  71. function openProperties(id, turnpage, type) {
  72. var processId = workflow.process.id;
  73. $('#properties-panel').panel('refresh', 'designerController.do?processProperties&turn=' + turnpage + '&id=' + id + '&processId=' + processId + '&processDefinitionId=' + processDefinitionId);
  74. }
  75. //上一步
  76. function redo() {
  77. workflow.getCommandStack().redo();
  78. }
  79. //下一步
  80. function undo() {
  81. workflow.getCommandStack().undo();
  82. }
  83. //保存流程
  84. //update-begin--Author:chenxu Date:20130426 for:流程保存提示消息,跑到层后面了【流程创建成功】,且一直存在,除非刷新页面
  85. function saveProcessDef() {
  86. gridname='processList';
  87. var typeid=$("#typeid").val();//流程类型Id
  88. if(typeid==0)
  89. {
  90. tip("请选择流程类型");
  91. }
  92. else
  93. {
  94. var params = "";
  95. var nodes = "";
  96. var xml = workflow.toXML();
  97. var processId = workflow.process.id;
  98. var descriptor = $(xml);
  99. var userTasks = descriptor.find('userTask');
  100. var manualTasks = descriptor.find('manualTask');
  101. var serviceTasks = descriptor.find('serviceTask');
  102. var scriptTasks = descriptor.find('scriptTask');
  103. var receiveTasks = descriptor.find('receiveTask');
  104. var businessRuleTasks = descriptor.find('businessRuleTask');
  105. userTasks.each(function(i) {
  106. var tid = $(this).attr('id');
  107. var nodeName = $(this).attr('name');
  108. nodes = nodes + "id=" + tid + "###nodeName=" + nodeName + "@@@";
  109. });
  110. manualTasks.each(function(i) {
  111. var tid = $(this).attr('id');
  112. var nodeName = $(this).attr('name');
  113. nodes = nodes + "id=" + tid + "###nodeName=" + nodeName + "@@@";
  114. });
  115. serviceTasks.each(function(i) {
  116. var tid = $(this).attr('id');
  117. var flag = $(this).attr('activiti:type');
  118. var nodeName = "";
  119. if (flag == 'mail') {
  120. nodeName = "邮件任务";
  121. } else {
  122. nodeName = $(this).attr('name');
  123. }
  124. nodes = nodes + "id=" + tid + "###nodeName=" + nodeName + "@@@";
  125. });
  126. scriptTasks.each(function(i) {
  127. var tid = $(this).attr('id');
  128. var nodeName = $(this).attr('name');
  129. nodes = nodes + "id=" + tid + "###nodeName=" + nodeName + "@@@";
  130. });
  131. receiveTasks.each(function(i) {
  132. var tid = $(this).attr('id');
  133. var nodeName = $(this).attr('name');
  134. nodes = nodes + "id=" + tid + "###nodeName=" + nodeName + "@@@";
  135. });
  136. businessRuleTasks.each(function(i) {
  137. var tid = $(this).attr('id');
  138. var nodeName = "业务规则";
  139. nodes = nodes + "id=" + tid + "###nodeName=" + nodeName + "@@@";
  140. });
  141. if (params.length > 3) {
  142. params = params.substring(0, params.length - 3);
  143. }
  144. if (nodes.length > 3) {
  145. nodes = nodes.substring(0, nodes.length - 3);
  146. }
  147. $.ajax({
  148. url : "designerController.do?saveProcess",
  149. type : 'POST',
  150. data : {
  151. processDescriptor : xml,//流程定义XML
  152. processName : workflow.process.name,//流程对象名称
  153. processkey : workflow.process.id,//流程对象ID
  154. typeid:typeid,//流程类型Id
  155. params : params,//
  156. nodes : nodes,//流程节点
  157. processDefinitionId : processDefinitionId//流程ID
  158. },
  159. dataType : 'json',
  160. error : function(data) {
  161. tip(data.msg);
  162. },
  163. success : function(data) {
  164. var win = frameElement.api.opener;
  165. if (data.success) {
  166. win.reloadTable();//刷新列表
  167. tip(data.msg);
  168. }
  169. }
  170. });
  171. }
  172. }
  173. //update-end--Author:chenxu Date:20130426 for:流程保存提示消息,跑到层后面了【流程创建成功】,且一直存在,除非刷新页面
  174. //导出流程
  175. function exportProcessDef(obj) {
  176. //obj.href="${ctx}/wf/procdef/procdef!exportProcessDef.action?procdefId="+processDefinitionId+"&processName="+processDefinitionName;
  177. }
  178. //流程图绘制
  179. function parseProcessDescriptor(data) {
  180. var BPMNShape = ($.browser.webkit) ? 'BPMNShape' : 'bpmndi\\:BPMNShape';
  181. var BPMNEdge = ($.browser.webkit) ? 'BPMNEdge' : 'bpmndi\\:BPMNEdge';
  182. var executionListener = ($.browser.webkit) ? 'executionListener' : 'activiti\\:executionListener';
  183. var Bounds = ($.browser.webkit) ? 'Bounds' : 'omgdc\\:Bounds';
  184. var waypoint = ($.browser.webkit) ? 'waypoint' : 'omgdi\\:waypoint';
  185. var taskListener = ($.browser.webkit) ? 'taskListener' : 'activiti\\:taskListener';
  186. var formProperty = ($.browser.webkit) ? 'formProperty' : 'activiti\\:formProperty';
  187. var field = ($.browser.webkit) ? 'activiti\\:field' : 'field';
  188. var expression = ($.browser.webkit) ? 'expression' : 'activiti\\:expression';
  189. var intag = ($.browser.webkit) ? 'in' : 'activiti\\:in';
  190. var outtag = ($.browser.webkit) ? 'out' : 'activiti\\:out';
  191. var descriptor = $(data);
  192. var definitions = descriptor.find('definitions');
  193. var process = descriptor.find('process');
  194. var startEvent = descriptor.find('startEvent');
  195. var endEvent = descriptor.find('endEvent');
  196. var manualTasks = descriptor.find('manualTask');
  197. var userTasks = descriptor.find('userTask');
  198. var serviceTasks = descriptor.find('serviceTask');
  199. var scriptTasks = descriptor.find('scriptTask');
  200. var receiveTasks = descriptor.find('receiveTask');
  201. var exclusiveGateway = descriptor.find('exclusiveGateway');
  202. var parallelGateway = descriptor.find('parallelGateway');
  203. var timerBoundary = descriptor.find('boundaryEvent');
  204. var callActivitys = descriptor.find('callActivity');
  205. var businessRuleTasks = descriptor.find('businessRuleTask');
  206. var lines = descriptor.find('sequenceFlow');
  207. var shapes = descriptor.find(BPMNShape);
  208. var edges = descriptor.find(BPMNEdge);
  209. workflow.process.category = definitions.attr('targetNamespace');
  210. workflow.process.id = process.attr('id');
  211. workflow.process.name = process.attr('name');
  212. var documentation = trim(descriptor.find('process > documentation').text());
  213. if (documentation != null && documentation != "")
  214. workflow.process.documentation = documentation;
  215. var extentsion = descriptor.find('process > extensionElements');
  216. if (extentsion != null) {
  217. var listeners = extentsion.find(executionListener);
  218. workflow.process.setListeners(parseListeners(listeners, "draw2d.Process.Listener", "draw2d.Process.Listener.Field"));
  219. }
  220. $.each(processDefinitionVariables, function(i, n) {
  221. var variable = new draw2d.Process.variable();
  222. variable.name = n.name;
  223. variable.type = n.type;
  224. variable.scope = n.scope;
  225. variable.defaultValue = n.defaultValue;
  226. variable.remark = n.remark;
  227. workflow.process.addVariable(variable);
  228. });
  229. startEvent.each(function(i) {
  230. var start = new draw2d.Start();
  231. start.id = $(this).attr('id');
  232. start.eventId = $(this).attr('id');
  233. start.eventName = $(this).attr('name');
  234. var expression = $(this).attr('activiti:initiator');
  235. if (expression == null || expression == 'null') {
  236. expression = "";
  237. }
  238. start.expression = expression;
  239. shapes.each(function(i) {
  240. var id = $(this).attr('bpmnElement');
  241. if (id == start.id) {
  242. var x = parseInt($(this).find(Bounds).attr('x'));
  243. var y = parseInt($(this).find(Bounds).attr('y'));
  244. var w = parseInt($(this).find(Bounds).attr('width'));
  245. var h = parseInt($(this).find(Bounds).attr('height'));
  246. start.setDimension(w, h);
  247. workflow.addFigure(start, x, y);
  248. return false;
  249. }
  250. });
  251. });
  252. endEvent.each(function(i) {
  253. var end = new draw2d.End();
  254. end.id = $(this).attr('id');
  255. end.eventId = $(this).attr('id');
  256. end.eventName = $(this).attr('name');
  257. shapes.each(function(i) {
  258. var id = $(this).attr('bpmnElement');
  259. if (id == end.id) {
  260. var x = parseInt($(this).find(Bounds).attr('x'));
  261. var y = parseInt($(this).find(Bounds).attr('y'));
  262. var w = parseInt($(this).find(Bounds).attr('width'));
  263. var h = parseInt($(this).find(Bounds).attr('height'));
  264. end.setDimension(w, h);
  265. workflow.addFigure(end, x, y);
  266. return false;
  267. }
  268. });
  269. });
  270. userTasks.each(function(i) {
  271. var task = new draw2d.UserTask();
  272. var tid = $(this).attr('id');
  273. task.id = tid;
  274. var tname = $(this).attr('name');
  275. var assignee = $(this).attr('activiti:assignee');
  276. var candidataUsers = $(this).attr('activiti:candidateUsers');
  277. var candidataGroups = $(this).attr('activiti:candidateGroups');
  278. var formKey = $(this).attr('activiti:formKey');
  279. if (assignee != null && assignee != "") {
  280. task.isUseExpression = true;
  281. task.performerType = "assignee";
  282. task.expression = assignee;
  283. } else if (candidataUsers != null && candidataUsers != "") {
  284. task.isUseExpression = true;
  285. task.performerType = "candidateUsers";
  286. task.expression = candidataUsers;
  287. } else if (candidataGroups != null && candidataGroups != "") {
  288. task.isUseExpression = true;
  289. task.performerType = "candidateGroups";
  290. task.expression = candidataGroups;
  291. }
  292. if (formKey != null && formKey != "") {
  293. task.formKey = formKey;
  294. }
  295. //begin---author:zhangdaihao date:20140730 for:动态会签
  296. var multiInstanceLoopCharacteristics = $(this).find('multiInstanceLoopCharacteristics');
  297. var isSequential = $(multiInstanceLoopCharacteristics).attr('isSequential');
  298. var collection = $(multiInstanceLoopCharacteristics).attr('activiti:collection');
  299. var elementVariable = $(multiInstanceLoopCharacteristics).attr('activiti:elementVariable');
  300. var loopCardinality = $(this).find('loopCardinality').text();
  301. var completionCondition = $(this).find('completionCondition').text();
  302. if(isSequential!=null&&isSequential!=""){
  303. task.task_extend = isSequential;//作废
  304. task.isSequential = isSequential;
  305. task.collection = collection;
  306. task.elementVariable = elementVariable;
  307. task.completionCondition = completionCondition;
  308. task.loopCardinality = loopCardinality;
  309. }
  310. //end---author:zhangdaihao date:20140730 for:动态会签
  311. var documentation = trim($(this).find('documentation').text());
  312. if (documentation != null && documentation != "")
  313. task.documentation = documentation;
  314. task.taskId = tid;
  315. task.taskName = tname;
  316. //if (tid != tname)
  317. task.setContent(tname);
  318. var listeners = $(this).find('extensionElements').find(taskListener);
  319. task.setListeners(parseListeners(listeners, "draw2d.Task.Listener", "draw2d.Task.Listener.Field"));
  320. var forms = $(this).find('extensionElements').find('activiti\\:formProperty');
  321. task.setForms(parseForms(forms, "draw2d.Task.Form"));
  322. var performersExpression = $(this).find('potentialOwner').find('resourceAssignmentExpression').find('formalExpression').text();
  323. if (performersExpression.indexOf('user(') != -1) {
  324. task.performerType = "candidateUsers";
  325. } else if (performersExpression.indexOf('group(') != -1) {
  326. task.performerType = "candidateGroups";
  327. }
  328. var performers = performersExpression.split(',');
  329. $.each(performers, function(i, n) {
  330. var start = 0;
  331. var end = n.lastIndexOf(')');
  332. if (n.indexOf('user(') != -1) {
  333. start = 'user('.length;
  334. var performer = n.substring(start, end);
  335. task.addCandidateUser({
  336. sso : performer
  337. });
  338. } else if (n.indexOf('group(') != -1) {
  339. start = 'group('.length;
  340. var performer = n.substring(start, end);
  341. task.addCandidateGroup(performer);
  342. }
  343. });
  344. shapes.each(function(i) {
  345. var id = $(this).attr('bpmnElement');
  346. if (id == task.id) {
  347. var x = parseInt($(this).find(Bounds).attr('x'));
  348. var y = parseInt($(this).find(Bounds).attr('y'));
  349. var w = parseInt($(this).find(Bounds).attr('width'));
  350. var h = parseInt($(this).find(Bounds).attr('height'));
  351. task.setDimension(w, h);
  352. workflow.addModel(task, x, y);
  353. return false;
  354. }
  355. });
  356. });
  357. manualTasks.each(function(i) {
  358. var task = new draw2d.ManualTask();
  359. var tid = $(this).attr('id');
  360. task.id = tid;
  361. var tname = $(this).attr('name');
  362. var assignee = $(this).attr('activiti:assignee');
  363. var candidataUsers = $(this).attr('activiti:candidateUsers');
  364. var candidataGroups = $(this).attr('activiti:candidateGroups');
  365. var formKey = $(this).attr('activiti:formKey');
  366. if (assignee != null && assignee != "") {
  367. task.isUseExpression = true;
  368. task.performerType = "assignee";
  369. task.expression = assignee;
  370. } else if (candidataUsers != null && candidataUsers != "") {
  371. task.isUseExpression = true;
  372. task.performerType = "candidateUsers";
  373. task.expression = candidataUsers;
  374. } else if (candidataGroups != null && candidataGroups != "") {
  375. task.isUseExpression = true;
  376. task.performerType = "candidateGroups";
  377. task.expression = candidataGroups;
  378. }
  379. if (formKey != null && formKey != "") {
  380. task.formKey = formKey;
  381. }
  382. var documentation = trim($(this).find('documentation').text());
  383. if (documentation != null && documentation != "")
  384. task.documentation = documentation;
  385. task.taskId = tid;
  386. task.taskName = tname;
  387. //if (tid != tname)
  388. task.setContent(tname);
  389. var listeners = $(this).find('extensionElements').find('activiti\\:taskListener');
  390. task.setListeners(parseListeners(listeners, "draw2d.Task.Listener", "draw2d.Task.Listener.Field"));
  391. var performersExpression = $(this).find('potentialOwner').find('resourceAssignmentExpression').find('formalExpression').text();
  392. if (performersExpression.indexOf('user(') != -1) {
  393. task.performerType = "candidateUsers";
  394. } else if (performersExpression.indexOf('group(') != -1) {
  395. task.performerType = "candidateGroups";
  396. }
  397. var performers = performersExpression.split(',');
  398. $.each(performers, function(i, n) {
  399. var start = 0;
  400. var end = n.lastIndexOf(')');
  401. if (n.indexOf('user(') != -1) {
  402. start = 'user('.length;
  403. var performer = n.substring(start, end);
  404. task.addCandidateUser({
  405. sso : performer
  406. });
  407. } else if (n.indexOf('group(') != -1) {
  408. start = 'group('.length;
  409. var performer = n.substring(start, end);
  410. task.addCandidateGroup(performer);
  411. }
  412. });
  413. shapes.each(function(i) {
  414. var id = $(this).attr('bpmnElement');
  415. if (id == task.id) {
  416. var x = parseInt($(this).find(Bounds).attr('x'));
  417. var y = parseInt($(this).find(Bounds).attr('y'));
  418. var w = parseInt($(this).find(Bounds).attr('width'));
  419. var h = parseInt($(this).find(Bounds).attr('height'));
  420. task.setDimension(w, h);
  421. workflow.addModel(task, x, y);
  422. return false;
  423. }
  424. });
  425. });
  426. serviceTasks.each(function(i) {
  427. var flag = $(this).attr('activiti:type');
  428. if (flag == 'mail') {
  429. var task = new draw2d.MailTask();
  430. var tid = $(this).attr('id');
  431. task.id = tid;
  432. var elements = $(this).find('activiti\\:field');
  433. elements.each(function(i) {
  434. if ($(this).attr('name') == 'to') {
  435. task.toEmail = $(this).attr('expression');
  436. }
  437. if ($(this).attr('name') == 'from') {
  438. task.fromEmail = $(this).attr('expression');
  439. }
  440. if ($(this).attr('name') == 'subject') {
  441. task.subjectEmail = $(this).attr('expression');
  442. }
  443. if ($(this).attr('name') == 'cc') {
  444. task.ccEmail = $(this).attr('expression');
  445. }
  446. if ($(this).attr('name') == 'bcc') {
  447. task.bccEmail = $(this).attr('expression');
  448. }
  449. if ($(this).attr('name') == 'charset') {
  450. task.charsetEmail = $(this).attr('expression');
  451. }
  452. if ($(this).attr('name') == 'html') {
  453. task.htmlEmail = trim($(this).find('activiti\\:expression').text());
  454. }
  455. if ($(this).attr('name') == 'text') {
  456. task.textEmail = trim($(this).find('activiti\\:expression').text());
  457. }
  458. });
  459. task.taskId = tid;
  460. shapes.each(function(i) {
  461. var id = $(this).attr('bpmnElement');
  462. if (id == task.id) {
  463. var x = parseInt($(this).find(Bounds).attr('x'));
  464. var y = parseInt($(this).find(Bounds).attr('y'));
  465. workflow.addModel(task, x, y);
  466. return false;
  467. }
  468. });
  469. } else {
  470. //服务任务
  471. var task = new draw2d.ServiceTask();
  472. var tid = $(this).attr('id');
  473. task.id = tid;
  474. var tname = $(this).attr('name');
  475. var assignee = $(this).attr('activiti:assignee');
  476. var candidataUsers = $(this).attr('activiti:candidateUsers');
  477. var candidataGroups = $(this).attr('activiti:candidateGroups');
  478. var formKey = $(this).attr('activiti:formKey');
  479. if (assignee != null && assignee != "") {
  480. task.isUseExpression = true;
  481. task.performerType = "assignee";
  482. task.expression = assignee;
  483. } else if (candidataUsers != null && candidataUsers != "") {
  484. task.isUseExpression = true;
  485. task.performerType = "candidateUsers";
  486. task.expression = candidataUsers;
  487. } else if (candidataGroups != null && candidataGroups != "") {
  488. task.isUseExpression = true;
  489. task.performerType = "candidateGroups";
  490. task.expression = candidataGroups;
  491. }
  492. if (formKey != null && formKey != "") {
  493. task.formKey = formKey;
  494. }
  495. var documentation = trim($(this).find('documentation').text());
  496. if (documentation != null && documentation != "")
  497. task.documentation = documentation;
  498. task.taskId = tid;
  499. task.taskName = tname;
  500. //if (tid != tname)
  501. task.setContent(tname);
  502. //update-begin-----author:qinfeng------date:20150916------for:服务任务不好用-------
  503. var javaClass = $(this).attr('activiti:class');
  504. var expression = $(this).attr('activiti:expression');
  505. var delegateExpression = $(this).attr('activiti:delegateExpression');
  506. if(javaClass){
  507. task.serviceType="javaClass";
  508. task.expression=javaClass;
  509. }else if(expression){
  510. task.serviceType="expression";
  511. task.expression=expression;
  512. }else if(delegateExpression){
  513. task.serviceType="delegateExpression";
  514. task.expression=delegateExpression;
  515. }
  516. var resultVariableName = $(this).attr('activiti:resultVariableName');
  517. if (resultVariableName != null && resultVariableName != "") {
  518. task.resultVariable = resultVariableName;
  519. }
  520. //update-end-----author:qinfeng------date:20150916------for:服务任务不好用-------
  521. var listeners = $(this).find('extensionElements').find('activiti\\:taskListener');
  522. task.setListeners(parseListeners(listeners, "draw2d.Task.Listener", "draw2d.Task.Listener.Field"));
  523. var performersExpression = $(this).find('potentialOwner').find('resourceAssignmentExpression').find('formalExpression').text();
  524. if (performersExpression.indexOf('user(') != -1) {
  525. task.performerType = "candidateUsers";
  526. } else if (performersExpression.indexOf('group(') != -1) {
  527. task.performerType = "candidateGroups";
  528. }
  529. var performers = performersExpression.split(',');
  530. $.each(performers, function(i, n) {
  531. var start = 0;
  532. var end = n.lastIndexOf(')');
  533. if (n.indexOf('user(') != -1) {
  534. start = 'user('.length;
  535. var performer = n.substring(start, end);
  536. task.addCandidateUser({
  537. sso : performer
  538. });
  539. } else if (n.indexOf('group(') != -1) {
  540. start = 'group('.length;
  541. var performer = n.substring(start, end);
  542. task.addCandidateGroup(performer);
  543. }
  544. });
  545. shapes.each(function(i) {
  546. var id = $(this).attr('bpmnElement');
  547. if (id == task.id) {
  548. var x = parseInt($(this).find(Bounds).attr('x'));
  549. var y = parseInt($(this).find(Bounds).attr('y'));
  550. var w = parseInt($(this).find(Bounds).attr('width'));
  551. var h = parseInt($(this).find(Bounds).attr('height'));
  552. task.setDimension(w, h);
  553. workflow.addModel(task, x, y);
  554. return false;
  555. }
  556. });
  557. }
  558. });
  559. scriptTasks.each(function(i) {
  560. var task = new draw2d.ScriptTask();
  561. var tid = $(this).attr('id');
  562. task.id = tid;
  563. var tname = $(this).attr('name');
  564. var scriptFormat = $(this).attr('scriptFormat');
  565. var resultVariable = $(this).attr('activiti:resultVariable');
  566. task.scriptFormat = scriptFormat;
  567. task.resultVariable = resultVariable;
  568. var documentation = trim($(this).find('documentation').text());
  569. if (documentation != null && documentation != "")
  570. task.documentation = documentation;
  571. var script = trim($(this).find('script').text());
  572. if (script != null && script != "")
  573. task.expression = script;
  574. task.taskId = tid;
  575. task.taskName = tname;
  576. //if (tid != tname)
  577. task.setContent(tname);
  578. shapes.each(function(i) {
  579. var id = $(this).attr('bpmnElement');
  580. if (id == task.id) {
  581. var x = parseInt($(this).find(Bounds).attr('x'));
  582. var y = parseInt($(this).find(Bounds).attr('y'));
  583. var w = parseInt($(this).find(Bounds).attr('width'));
  584. var h = parseInt($(this).find(Bounds).attr('height'));
  585. task.setDimension(w, h);
  586. workflow.addModel(task, x, y);
  587. return false;
  588. }
  589. });
  590. });
  591. receiveTasks.each(function(i) {
  592. var task = new draw2d.ReceiveTask();
  593. var tid = $(this).attr('id');
  594. task.id = tid;
  595. var tname = $(this).attr('name');
  596. task.taskId = tid;
  597. task.taskName = tname;
  598. //if (tid != tname)
  599. task.setContent(tname);
  600. shapes.each(function(i) {
  601. var id = $(this).attr('bpmnElement');
  602. if (id == task.id) {
  603. var x = parseInt($(this).find(Bounds).attr('x'));
  604. var y = parseInt($(this).find(Bounds).attr('y'));
  605. var w = parseInt($(this).find(Bounds).attr('width'));
  606. var h = parseInt($(this).find(Bounds).attr('height'));
  607. task.setDimension(w, h);
  608. workflow.addModel(task, x, y);
  609. return false;
  610. }
  611. });
  612. });
  613. exclusiveGateway.each(function(i) {
  614. var gateway = new draw2d.ExclusiveGateway();
  615. var gtwid = $(this).attr('id');
  616. var gtwname = $(this).attr('name');
  617. gateway.id = gtwid;
  618. gateway.gatewayId = gtwid;
  619. gateway.gatewayName = gtwname;
  620. shapes.each(function(i) {
  621. var id = $(this).attr('bpmnElement');
  622. if (id == gateway.id) {
  623. var x = parseInt($(this).find(Bounds).attr('x'));
  624. var y = parseInt($(this).find(Bounds).attr('y'));
  625. var w = parseInt($(this).find(Bounds).attr('width'));
  626. var h = parseInt($(this).find(Bounds).attr('height'));
  627. gateway.setDimension(w, h);
  628. workflow.addModel(gateway, x, y);
  629. return false;
  630. }
  631. });
  632. });
  633. parallelGateway.each(function(i) {
  634. var gateway = new draw2d.ParallelGateway();
  635. var gtwid = $(this).attr('id');
  636. var gtwname = $(this).attr('name');
  637. gateway.id = gtwid;
  638. gateway.gatewayId = gtwid;
  639. gateway.gatewayName = gtwname;
  640. shapes.each(function(i) {
  641. var id = $(this).attr('bpmnElement');
  642. if (id == gateway.id) {
  643. var x = parseInt($(this).find(Bounds).attr('x'));
  644. var y = parseInt($(this).find(Bounds).attr('y'));
  645. var w = parseInt($(this).find(Bounds).attr('width'));
  646. var h = parseInt($(this).find(Bounds).attr('height'));
  647. gateway.setDimension(w, h);
  648. workflow.addModel(gateway, x, y);
  649. return false;
  650. }
  651. });
  652. });
  653. timerBoundary.each(function(i) {
  654. if ($(this).find('timeDate').text() != '') {
  655. var timeBoundaryevent = new draw2d.TimerBoundary("plug-in/designer/icons/timer.png");
  656. var boundaryId = $(this).attr('id');
  657. var cancelActivity = $(this).attr('cancelActivity');
  658. var attachedToRef = $(this).attr('attachedToRef');
  659. timeBoundaryevent.id = boundaryId;
  660. timeBoundaryevent.boundaryId = boundaryId;
  661. timeBoundaryevent.cancelActivity = cancelActivity;
  662. timeBoundaryevent.attached = attachedToRef;
  663. timeBoundaryevent.timeType = 'timeDate';
  664. timeBoundaryevent.expression = $(this).find('timeDate').text();
  665. } else if ($(this).find('timeDuration').text() != '') {
  666. var timeBoundaryevent = new draw2d.TimerBoundary("plug-in/designer/icons/timer.png");
  667. var boundaryId = $(this).attr('id');
  668. var cancelActivity = $(this).attr('cancelActivity');
  669. var attachedToRef = $(this).attr('attachedToRef');
  670. timeBoundaryevent.id = boundaryId;
  671. timeBoundaryevent.boundaryId = boundaryId;
  672. timeBoundaryevent.cancelActivity = cancelActivity;
  673. timeBoundaryevent.attached = attachedToRef;
  674. timeBoundaryevent.timeType = 'timeDuration';
  675. timeBoundaryevent.expression = $(this).find('timeDuration').text();
  676. } else if ($(this).find('timeCycle').text() != '') {
  677. var timeBoundaryevent = new draw2d.TimerBoundary("plug-in/designer/icons/timer.png");
  678. var boundaryId = $(this).attr('id');
  679. var cancelActivity = $(this).attr('cancelActivity');
  680. var attachedToRef = $(this).attr('attachedToRef');
  681. timeBoundaryevent.id = boundaryId;
  682. timeBoundaryevent.boundaryId = boundaryId;
  683. timeBoundaryevent.cancelActivity = cancelActivity;
  684. timeBoundaryevent.attached = attachedToRef;
  685. timeBoundaryevent.timeType = 'timeCycle';
  686. timeBoundaryevent.expression = $(this).find('timeCycle').text();
  687. } else {
  688. var timeBoundaryevent = new draw2d.ErrorBoundary("plug-in/designer/icons/error.png");
  689. var boundaryId = $(this).attr('id');
  690. var attachedToRef = $(this).attr('attachedToRef');
  691. timeBoundaryevent.id = boundaryId;
  692. timeBoundaryevent.boundaryId = boundaryId;
  693. timeBoundaryevent.attached = attachedToRef;
  694. timeBoundaryevent.expression = $(this).find('errorEventDefinition').attr('errorRef');
  695. }
  696. shapes.each(function(i) {
  697. var id = $(this).attr('bpmnElement');
  698. if (id == timeBoundaryevent.id) {
  699. var x = parseInt($(this).find(Bounds).attr('x'));
  700. var y = parseInt($(this).find(Bounds).attr('y'));
  701. var w = parseInt($(this).find(Bounds).attr('width'));
  702. var h = parseInt($(this).find(Bounds).attr('height'));
  703. timeBoundaryevent.setDimension(w, h);
  704. workflow.addModel(timeBoundaryevent, x, y);
  705. return false;
  706. }
  707. });
  708. });
  709. callActivitys.each(function(i) {
  710. var callActivity = new draw2d.CallActivity("plug-in/designer/icons/callactivity.png");
  711. var subProcessId = $(this).attr('id');
  712. var name = $(this).attr('name');
  713. var callSubProcess = $(this).attr('calledElement');
  714. callActivity.id = subProcessId;
  715. callActivity.subProcessId = subProcessId;
  716. callActivity.callSubProcess = callSubProcess;
  717. callActivity.name = name;
  718. var flag = $(this).find('extensionElements');
  719. if (flag != null) {
  720. callActivity.insource = $(this).find(intag).attr('source');
  721. callActivity.intarget = $(this).find(intag).attr('target');
  722. callActivity.outsource = $(this).find(outtag).attr('source');
  723. callActivity.outtarget = $(this).find(outtag).attr('target');
  724. }
  725. shapes.each(function(i) {
  726. var id = $(this).attr('bpmnElement');
  727. if (id == callActivity.id) {
  728. var x = parseInt($(this).find(Bounds).attr('x'));
  729. var y = parseInt($(this).find(Bounds).attr('y'));
  730. var w = parseInt($(this).find(Bounds).attr('width'));
  731. var h = parseInt($(this).find(Bounds).attr('height'));
  732. callActivity.setDimension(w, h);
  733. workflow.addModel(callActivity, x, y);
  734. return false;
  735. }
  736. });
  737. });
  738. businessRuleTasks.each(function(i) {
  739. var task = new draw2d.BusinessRuleTask();
  740. var tid = $(this).attr('id');
  741. var valueInput = $(this).attr('activiti:ruleVariablesInput');
  742. var valueOutput = $(this).attr('activiti:resultVariables');
  743. var rules = $(this).attr('activiti:rules');
  744. var exclude = $(this).attr('exclude');
  745. if (rules != null && rules != '') {
  746. task.rules = rules;
  747. if (exclude != null && exclude != '') {
  748. task.isclude = 'exclude';
  749. } else {
  750. task.isclude = 'include';
  751. }
  752. } else {
  753. task.isclude = '';
  754. }
  755. task.id = tid;
  756. task.taskId = tid;
  757. task.rulesInput = valueInput;
  758. task.rulesOutputs = valueOutput;
  759. shapes.each(function(i) {
  760. var id = $(this).attr('bpmnElement');
  761. if (id == task.id) {
  762. var x = parseInt($(this).find(Bounds).attr('x'));
  763. var y = parseInt($(this).find(Bounds).attr('y'));
  764. var w = parseInt($(this).find(Bounds).attr('width'));
  765. var h = parseInt($(this).find(Bounds).attr('height'));
  766. task.setDimension(w, h);
  767. workflow.addModel(task, x, y);
  768. return false;
  769. }
  770. });
  771. });
  772. lines.each(function(i) {
  773. var lid = $(this).attr('id');
  774. var name = $(this).attr('name');
  775. var condition = $(this).find('conditionExpression').text();
  776. var sourceRef = $(this).attr('sourceRef');
  777. var targetRef = $(this).attr('targetRef');
  778. //update--begin---author:zhangdaihao date:20150716 for:分支监听
  779. var executionListener = $(this).find('extensionElements').find('executionListener');
  780. var loc_listeners = parseListeners(executionListener, "draw2d.DecoratedConnection.Listener", "draw2d.DecoratedConnection.Listener.Field");
  781. //alert( 'Index' + i +' | loc_listeners:'+ loc_listeners.getSize());
  782. //update--end---author:zhangdaihao date:20150716 for:分支监听
  783. var source = workflow.getFigure(sourceRef);
  784. var target = workflow.getFigure(targetRef);
  785. edges.each(function(i) {
  786. var eid = $(this).attr('bpmnElement');
  787. if (eid == lid) {
  788. var startPort = null;
  789. var endPort = null;
  790. var points = $(this).find(waypoint);
  791. var len = points.length;
  792. var startX = $(points[0]).attr('x');
  793. var startY = $(points[0]).attr('y');
  794. var endX = $(points[len - 1]).attr('x');
  795. var endY = $(points[len - 1]).attr('y');
  796. var sports = source.getPorts();
  797. for ( var i = 0; i < sports.getSize(); i++) {
  798. var s = sports.get(i);
  799. var x = parseInt(s.getAbsoluteX());
  800. var y = parseInt(s.getAbsoluteY());
  801. if (x == startX && y == startY) {
  802. startPort = s;
  803. break;
  804. }
  805. }
  806. var tports = target.getPorts();
  807. for ( var i = 0; i < tports.getSize(); i++) {
  808. var t = tports.get(i);
  809. var x = parseInt(t.getAbsoluteX());
  810. var y = parseInt(t.getAbsoluteY());
  811. if (x == endX && y == endY) {
  812. endPort = t;
  813. break;
  814. }
  815. }
  816. if (startPort != null && endPort != null) {
  817. var cmd = new draw2d.CommandConnect(workflow, startPort, endPort);
  818. var connection = new draw2d.DecoratedConnection();
  819. connection.id = lid;
  820. connection.lineId = lid;
  821. connection.lineName = name;
  822. connection.setLabel(name);
  823. if (condition != null && condition != "") {
  824. connection.condition = condition;
  825. }
  826. //update--begin---author:zhangdaihao date:20150716 for:分支监听
  827. connection.listeners = loc_listeners;
  828. //update--end---author:zhangdaihao date:20150716 for:分支监听
  829. cmd.setConnection(connection);
  830. workflow.getCommandStack().execute(cmd);
  831. }
  832. return false;
  833. }
  834. });
  835. });
  836. if (typeof setHightlight != "undefined") {
  837. setHightlight();
  838. }
  839. populateProcessProperites();
  840. }
  841. /**
  842. * 监听器转换
  843. * @param listeners
  844. * @param listenerType
  845. * @param fieldType
  846. * @returns {draw2d.ArrayList}
  847. */
  848. function parseListeners(listeners, listenerType, fieldType) {
  849. var parsedListeners = new draw2d.ArrayList();
  850. listeners.each(function(i) {
  851. var listener = eval("new " + listenerType + "()");
  852. listener.event = $(this).attr('event');
  853. listener.id = $(this).attr('id');
  854. var expression = $(this).attr('delegateExpression');
  855. var clazz = $(this).attr('class');
  856. if (expression != null && expression != "") {
  857. listener.serviceType = 'expression';
  858. listener.serviceExpression = expression;
  859. } else if (clazz != null && clazz != "") {
  860. listener.serviceType = 'javaClass';
  861. listener.serviceClass = clazz;
  862. }
  863. var fields = $(this).find('activiti\\:field');
  864. fields.each(function(i) {
  865. var field = eval("new " + fieldType + "()");
  866. field.name = $(this).attr('name');
  867. var string = $(this).find('activiti\\:string').text();
  868. var expression = $(this).find('activiti\\:expression').text();
  869. if (string != null && string != "") {
  870. field.type = 'string';
  871. field.value = string;
  872. } else if (expression != null && expression != "") {
  873. field.type = 'expression';
  874. field.value = expression;
  875. }
  876. listener.setField(field);
  877. });
  878. parsedListeners.add(listener);
  879. });
  880. return parsedListeners;
  881. }
  882. function parseForms(forms, formType) {
  883. var parsedForms = new draw2d.ArrayList();
  884. forms.each(function(i) {
  885. var form = eval("new " + formType + "()");
  886. form.id = $(this).attr('id');
  887. var name = $(this).attr('name');
  888. form.name = name;
  889. var type = $(this).attr('type');
  890. form.type = type;
  891. var value = $(this).attr('value');
  892. form.value = value;
  893. var exp = $(this).attr('exp');
  894. form.exp = exp;
  895. var remark = $(this).attr('remark');
  896. form.remark = remark;
  897. parsedForms.add(form);
  898. });
  899. return parsedForms;
  900. }