all-workflowscan.js 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344
  1. /*
  2. * 仅用于查看流程图 只展示视图界面 不可编辑 流程图会跟随节点渲染颜色
  3. */
  4. Ext.ns('App');
  5. App = {
  6. webforms: {},
  7. init: function() {
  8. //初始化流程图
  9. Ext.QuickTips.init();
  10. this.propertyManager = new App.property.PropertyManager();
  11. this.workbenchWindow = new Gef.ui.support.DefaultWorkbenchWindow();
  12. var viewport = new Ext.Viewport({
  13. id:'viewport',
  14. layout: 'border',
  15. border: '0 0 0 0',
  16. bodyStyle: 'background:#f0f0f0;',
  17. frame:true,
  18. items: [
  19. // this.createNorth(),
  20. // this.createSouth(),
  21. // this.createWest(),
  22. // this.createEast(),
  23. this.createCenter()
  24. ]
  25. });
  26. this.initEditor();
  27. setTimeout(function() {
  28. Ext.get('loading').remove();
  29. Ext.get('loading-mask').fadeOut({remove:true});
  30. }, 100);
  31. },
  32. initEditor: function() {
  33. var me = this;
  34. var fd_fcid =getUrlParam('fd_fcid');
  35. var caller =getUrlParam('caller');
  36. var keyvalue =getUrlParam('keyvalue');
  37. var xmlInfo = '';
  38. Ext.Ajax.request({
  39. url: basePath + 'oa/flow/getFlowChart.action',
  40. params: {
  41. fcid: fd_fcid
  42. },
  43. success: function(response){
  44. //解析xml
  45. var text = new Ext.decode(response.responseText);
  46. var text = text.data;
  47. xmlInfo = text.xmlInfo;
  48. var xml = xmlInfo;
  49. var editor = new Gef.jbs.ExtEditor();
  50. var input = new Gef.jbs.JBSEditorInput();
  51. input.readXml(xml);
  52. me.workbenchWindow.getActivePage().openEditor(editor, input);
  53. me.workbenchWindow.render();
  54. Gef.activeEditor = editor;
  55. //获取历史流程顺序节点和操作
  56. var data;
  57. Ext.Ajax.request({
  58. url : basePath + 'oa/flow/getHistoryIntance.action',
  59. params: {
  60. caller: caller,
  61. id : keyvalue,
  62. condition : null
  63. },
  64. async:false,
  65. method : 'post',
  66. callback : function(options,success,response){
  67. var res = new Ext.decode(response.responseText);
  68. if(res.exceptionInfo){
  69. showError(res.exceptionInfo);
  70. return false;
  71. }
  72. if(res.data.length!=0){
  73. data = res.data
  74. for(var x=0;x<data.length;x++){
  75. //所有的节点
  76. var childrens=input.processModel.children;
  77. //渲染节点
  78. for(var i=0;i<childrens.length;i++){
  79. var figure=childrens[i].editPart.figure;
  80. //普通渲染
  81. if(childrens[i].text==data[x].FI_NODENAME){
  82. childrens[i].renderOver = true;
  83. if(figure.rectEl){
  84. figure.rectEl.strokwidth= 1;
  85. figure.rectEl.style.fill='#7FFFAA';
  86. figure.rectEl.style.stroke='#64a1ed';
  87. }
  88. figure.el.style.fill='#0E7D9F';
  89. me.propertyManager.selectSpecialNode(Gef.activeEditor,childrens[i].editPart);
  90. //给节点间的线段渲染颜色
  91. for(var j=0;j<childrens[i].outgoingConnections.length;j++){
  92. var figure=childrens[i].outgoingConnections[j].editPart.figure;
  93. if(data[x].FO_NAME=='commit'){
  94. data[x].FO_NAME='提交'
  95. }
  96. if(figure.name == data[x].FO_NAME){
  97. /*figure.el.style.fill='#15B10E';*/
  98. figure.el.style.stroke='#29EDAE';
  99. childrens[i].outgoingConnections[j].renderOver = true;
  100. }
  101. }
  102. //给进行中的节点渲染颜色
  103. if(x==(data.length-1)){
  104. for(var i=0;i<childrens.length;i++){
  105. if(!childrens[i].renderOver){
  106. for(var j=0;j<childrens[i].incomingConnections.length;j++){
  107. if(childrens[i].incomingConnections[j].renderOver){
  108. var figure=childrens[i].editPart.figure;
  109. if(figure.rectEl){
  110. figure.rectEl.strokwidth= 1;
  111. figure.rectEl.style.fill='#F08080';
  112. figure.rectEl.style.stroke='#64a1ed';
  113. }
  114. figure.el.style.fill='#0E7D9F';
  115. me.propertyManager.selectSpecialNode(Gef.activeEditor,childrens[i].editPart);
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }
  126. });
  127. }
  128. });
  129. },
  130. getProcessModel: function() {
  131. var viewer = Gef.activeEditor.getGraphicalViewer();
  132. var processEditPart = viewer.getContents();
  133. return processEditPart.model;
  134. },
  135. createNorth: function() {
  136. var p = null;
  137. if (Gef.MODE_DEMO === true) {
  138. p = new Ext.Panel({
  139. region: 'north'
  140. });
  141. } else {
  142. p = new Ext.Panel({
  143. region: 'north'
  144. });
  145. }
  146. App.northPanel = p;
  147. return p;
  148. },
  149. createSouth: function() {
  150. var p = this.propertyManager.getBottom();
  151. return p;
  152. },
  153. createWest: function() {
  154. var p = new App.PalettePanel({
  155. collapsible: true //修复bug 可以伸缩 zhouy
  156. });
  157. App.westPanel = p;
  158. return p;
  159. },
  160. createEast: function() {
  161. var p = this.propertyManager.getRight();
  162. return p;
  163. },
  164. createCenter: function() {
  165. var p = new App.CanvasPanel();
  166. App.centerPanel = p;
  167. return p;
  168. },
  169. getSelectionListener: function() {
  170. if (!this.selectionListener) {
  171. this.selectionListener = new Gef.jbs.ExtSelectionListener(null);
  172. }
  173. return this.selectionListener;
  174. }
  175. };
  176. /*
  177. Gef.override(App.PalettePanel, {
  178. configItems: function() {
  179. this.html = 'sdfasfdfdsa';
  180. }
  181. });
  182. */
  183. //Gef.PALETTE_TYPE = 'plain';
  184. Gef.PALETTE_TYPE = 'accordion';
  185. Ext.onReady(App.init, App);
  186. Gef.DEPLOY_URL = '../../console/d!deployJpdl.do';
  187. Gef.SAVE_URL = '../../console/d!saveJpdl.do';
  188. App.CanvasPanel = Ext.extend(Ext.Panel, {
  189. id:'canvaspanel',
  190. bodyStyle: 'background:#f0f0f0;',
  191. border: '0 0 0 0',
  192. //拖动滚动条后 自动收缩流程历史
  193. listeners: {
  194. render: function(p){
  195. p.body.on('scroll', function(){
  196. var viewgrid = parent.Ext.getCmp('view');
  197. if(viewgrid&&!viewgrid.collapsed){
  198. viewgrid.collapse();
  199. }
  200. }, p);
  201. }
  202. },
  203. xmlValidate:function(){
  204. var xmlString = arguments[0];
  205. var xmlDoc = null;
  206. try //IE 浏览器
  207. {
  208. xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  209. xmlDoc.async="false";
  210. xmlDoc.loadXML(xmlString);
  211. }
  212. catch(e)
  213. {
  214. console.log(e.message);
  215. try //Firefox, Mozilla, 浏览器
  216. {
  217. parser=new DOMParser();
  218. xmlDoc=parser.parseFromString(xmlString,"text/xml");
  219. var tasks = xmlDoc.getElementsByTagName('task');
  220. for(var i=0;i<tasks.length;i++){ // 对任务节点的校验……
  221. var transitions = tasks[i].getElementsByTagName('transition');
  222. if(transitions.length!=2){
  223. Ext.Msg.alert("温馨提示","任务".fontcolor("Red").fontsize(5)+new String(tasks[i].getAttribute('name')).fontcolor("Red").fontsize(5)+"只能有"+"两".fontcolor("Red")+"条"+"流出".fontcolor("Red")+"连线");
  224. return false;
  225. }
  226. for(var j=0;j<transitions.length;j++){
  227. var name = transitions[j].getAttribute('name');
  228. console.log(name);
  229. if(name!='同意'&&name!='不同意'){
  230. Ext.Msg.alert("温馨提示","任务".fontcolor("Red").fontsize(5)+new String(tasks[i].getAttribute('name')).fontcolor("Red").fontsize(5)+" 的流出连线名称必须为“同意” 或 “不同意” !");
  231. return false;
  232. }
  233. }
  234. }
  235. var sqls = xmlDoc.getElementsByTagName('sql'); //对sql 节点的校验……
  236. for(var i=0;i<sqls.length;i++){
  237. var querys = sqls[i].getElementsByTagName('query');
  238. console.log(querys);
  239. if(querys.length<1){
  240. Ext.Msg.alert("温馨提示",new String(sqls[i].getAttribute('name')).fontcolor("Red").fontsize(5)+"节点的查询语句未设置!");
  241. return false;
  242. }
  243. for(var j=0;j<querys.length;j++){
  244. var sqlString = new String(querys[j].childNodes[0].nodeValue);
  245. console.log("sql节点的 sql查询语句"+sqlString);
  246. if(sqlString.indexOf("drop")>=0||sqlString.indexOf("insert")>=0||sqlString.indexOf('delete')>=0){
  247. Ext.Msg.alert("温馨提示",new String(sqls[i].getAttribute('name')).fontcolor("Red").fontsize(5)+"节点的查询语句中含有敏感字符 !");
  248. return false;
  249. }
  250. if(sqlString.indexOf("select")<0||sqlString.indexOf("from")<0){
  251. Ext.Msg.alert("温馨提示",new String(sqls[i].getAttribute('name')).fontcolor("Red").fontsize(5)+"节点的查询语句语法错误 !");
  252. return false;
  253. }
  254. }
  255. var transitions = sqls[i].getElementsByTagName('transition');
  256. if(transitions.length>1){
  257. Ext.Msg.alert("温馨提示",new String(sqls[i].getAttribute('name')).fontcolor("Red").fontsize(5)+" 节点不能有两条及以上的流出连线 !");
  258. return false;
  259. }
  260. }
  261. var decisions = xmlDoc.getElementsByTagName('decision'); //对 decision 节点的校验……
  262. console.log(decisions);
  263. for(var i=0;i<decisions.length;i++){
  264. var expr = decisions[i].getAttribute('expr');
  265. console.log(expr);
  266. if(!expr){
  267. transitions = decisions[i].getElementsByTagName('transition');
  268. for(var j=0;j<transitions.length;j++){
  269. conditions = transitions[j].getElementsByTagName('condition');
  270. if(conditions.length!=1){
  271. Ext.Msg.alert("温馨提示",new String(decisions[i].getAttribute('name')).fontcolor("Red").fontsize(5)+" 节点分支条件设置错误 !");
  272. return false;
  273. }else{
  274. var condition = transitions[j].getElementsByTagName('condition')[0];
  275. var exp = new String(condition.getAttribute("expr"));
  276. if(exp.indexOf("#{")<0){ // 校验……………………
  277. Ext.Msg.alert("温馨提示",new String(decisions[i].getAttribute('name')).fontcolor("Red").fontsize(5)+" 节点分支条件设置错误 !");
  278. return false;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. return true;
  285. }
  286. catch(e) {alert(e.message); return false;}
  287. }
  288. },
  289. initComponent: function() {
  290. //this.on('bodyresize', function(p, w, h) {
  291. // var b = p.body.getBox();
  292. //});
  293. this.region = 'center';
  294. this.autoScroll = true;
  295. var mater=null;
  296. var contents=null;//行选择之后的xml
  297. var resetlength=null;//新建之后的xml的长度
  298. /**this.tbar = new Ext.Toolbar([{
  299. text: '新建',
  300. iconCls: 'tb-new',
  301. handler: function() {
  302. App.propertyManager.initSelectionListener(Gef.activeEditor);
  303. var model=Gef.activeEditor.getGraphicalViewer().getRootEditPart().getContents().getModel();
  304. if(model.dom.getAttribute('data')){
  305. model.dom.removeAttribute('data');
  306. }
  307. Ext.getCmp('FirstForm').getForm().reset();
  308. Gef.activeEditor.reset();
  309. resetlength=Gef.activeEditor.serial().length;
  310. contents=null;
  311. }
  312. }, {
  313. text: '导入',
  314. iconCls: 'tb-webform',
  315. handler: function() {
  316. var xml = Gef.activeEditor.serial();
  317. if (!this.openWin) {
  318. this.openWin = new Ext.Window({
  319. title: 'xml',
  320. layout: 'fit',
  321. width: 500,
  322. height: 300,
  323. closeAction: 'hide',
  324. modal: true,
  325. items: [{
  326. id: '__gef_jbpm4_xml_import__',
  327. xtype: 'textarea'
  328. }],
  329. buttons: [{
  330. text: '导入',
  331. handler: function() {
  332. var xml = Ext.getDom('__gef_jbpm4_xml_import__').value;
  333. Gef.activeEditor.resetAndOpen(xml);
  334. this.openWin.hide();
  335. var viewer = Gef.activeEditor.getGraphicalViewer();
  336. var browserListener = viewer.getBrowserListener();
  337. var editor=Gef.activeEditor;
  338. var data=Ext.getCmp('FirstForm').getForm().getValues();
  339. App.propertyManager.initSelectionListener2(Gef.activeEditor,data);
  340. },
  341. scope: this
  342. }, {
  343. text: '取消',
  344. handler: function() {
  345. this.openWin.hide();
  346. },
  347. scope: this
  348. }]
  349. });
  350. this.openWin.on('show', function() {
  351. Gef.activeEditor.disable();
  352. });
  353. this.openWin.on('hide', function() {
  354. Gef.activeEditor.enable();
  355. });
  356. }
  357. this.openWin.show(null, function() {
  358. Ext.getDom('__gef_jbpm4_xml_import__').value = xml;
  359. });
  360. }
  361. }, {
  362. text: '导出',
  363. iconCls: 'tb-prop',
  364. handler: function() {
  365. var xml = Gef.activeEditor.serial();
  366. if (!this.openWin) {
  367. this.openWin = new Ext.Window({
  368. title: 'xml',
  369. layout: 'fit',
  370. width: 500,
  371. height: 300,
  372. closeAction: 'hide',
  373. modal: true,
  374. items: [{
  375. id: '__gef_jbpm4_xml_export__',
  376. xtype: 'textarea'
  377. }],
  378. buttons: [{
  379. text: '关闭',
  380. handler: function() {
  381. this.openWin.hide();
  382. },
  383. scope: this
  384. }]
  385. });
  386. this.openWin.on('show', function() {
  387. Gef.activeEditor.disable();
  388. });
  389. this.openWin.on('hide', function() {
  390. Gef.activeEditor.enable();
  391. });
  392. }
  393. this.openWin.show(null, function() {
  394. Ext.getDom('__gef_jbpm4_xml_export__').value = xml;
  395. /*document.getElementById('__gef_jbpm4_xml_export__').value=xml;
  396. });
  397. }
  398. }, {
  399. text: '保存',
  400. iconCls: 'tb-save',
  401. handler: function() {
  402. //重复保存的情况 form 1.修改。。。Ext.getCmp('FirstForm').getForm().isDirty()
  403. // 2.xml文件做了修改 了contents resetlength=44;
  404. var editor = Gef.activeEditor;
  405. var xml = editor.serial();
  406. var str='<?xml version="1.0" encoding="UTF-8"?>\n'+xml;
  407. var param=str.replace("data='[object Object]'","");
  408. //Ext.Msg.wait('正在校验。。。');
  409. var result =Ext.getCmp('canvaspanel').xmlValidate(xml);// 自定义校验
  410. console.log("校验结果 " +result);
  411. if(!result){
  412. console.log("xml 格式错误!");
  413. return ;
  414. }else{
  415. console.log("自定义 校验通过,可以正常保存 !");
  416. }
  417. var model=editor.getGraphicalViewer().getRootEditPart().getContents().getModel();
  418. //检验页面元素是否填写正确
  419. // alert(Ext.getCmp('FirstForm'));
  420. App.propertyManager.initSelectionListener(editor);//add 选中面板便于拿到form 不是最好的解决办法 2012-08-21
  421. var form=Ext.getCmp('FirstForm');
  422. // if(resetlength==44||contents!=param||contests=param&&form.getForm().isDirty()){
  423. var isValid = new Validation(editor).validate();//可以对空xml进行校验
  424. if (!isValid) {
  425. return false;
  426. }
  427. //对form进行校验
  428. if(form.getForm().isValid()){
  429. console.log(resetlength);
  430. if(!form.getForm().isDirty()){
  431. var r = form.getForm().getValues();
  432. if(r.pr_caller==null||r.pr_defname==null||r.pr_caller==''||r.pr_defname==''){
  433. Ext.Msg.alert("提示","请填写右边属性面板必填项!");
  434. return;
  435. }
  436. var xml2 ="";
  437. if(xml.indexOf('data=')!=-1){
  438. xml2 = xml.replace("data='[object Object]'","name='"+r.pr_defname+"'");
  439. }
  440. console.log(xml2);
  441. Ext.Msg.wait('正在保存...');
  442. Ext.Ajax.request({
  443. method: 'post',
  444. url: basePath+'common/deployProcess.action',
  445. success: function(response) {
  446. try {
  447. var o = Ext.decode(response.responseText);
  448. if (o.success === true) {
  449. Ext.Msg.alert('提示', '保存成功, 你的流程定义编号为:'+o.id);
  450. } else {
  451. Ext.Msg.alert('错误', o.errors.msg);
  452. }
  453. } catch(e) {
  454. Ext.Msg.alert('保存失败','请重试!' );
  455. }
  456. },
  457. failure: function(response) {
  458. Ext.Msg.alert('保存失败','请检查 xml文件格式!' );
  459. },
  460. params: {
  461. processDefinitionName: r.pr_defname,
  462. processDescription: r.pr_descn,
  463. caller:r.pr_caller,
  464. enabled:r.pr_enabled,
  465. xml: xml2,
  466. parentId:0
  467. }
  468. });
  469. }else{
  470. alert("请填写右边属性面板必填项!");
  471. }
  472. }else{
  473. Ext.Msg.alert('提示','请填写右边必填条款!');
  474. }
  475. }
  476. },{
  477. text:'查看',
  478. iconCls:'tb_find',
  479. handler:function(){
  480. resetlength=null;
  481. var editor = Gef.activeEditor;
  482. var model=editor.getGraphicalViewer().getRootEditPart().getContents().getModel();
  483. Ext.Ajax.request({//拿到grid的数据总数count
  484. url : basePath + 'common/datalistCount.action',
  485. params: {
  486. caller:'Process',
  487. condition: "1=1",
  488. },
  489. method : 'post',
  490. callback : function(options,success,response){
  491. var res = new Ext.decode(response.responseText);
  492. var dataCount = res.count;
  493. Ext.Ajax.request({//拿到tree数据
  494. url : basePath+'common/datalist.action',
  495. params: {
  496. caller: 'Process',
  497. condition: '1=1',
  498. page: 1,
  499. pageSize: 20
  500. },
  501. method:'post',
  502. callback : function(options,success,response){
  503. res = new Ext.decode(response.responseText);
  504. var data=(res.data).replace(/,}/g,"}");
  505. var store= new Ext.data.JsonStore({
  506. fields : res.fields,
  507. data:Ext.decode(data),
  508. autoLoad : true,
  509. });
  510. var grid = new Ext.grid.GridPanel({
  511. id:'grid',
  512. width:600,
  513. height:300,
  514. autoExpandColumn:true,
  515. stripeRows:true,
  516. border:true,
  517. title:'ERP流程列表',
  518. columns:res.columns,
  519. iconCls:'icon-grid',
  520. store: store,
  521. viewConfig: {
  522. forceFit: true
  523. },
  524. listeners:{
  525. 'rowclick':function(grid,row, e){
  526. var k=grid.getSelectionModel();
  527. Ext.getCmp('win').close();
  528. //Ext.getCmp('FirstForm').getForm().setValues(k.selections.items[0].data);
  529. //拿到Xml字符串 向后台传回一个id 在拿到contents
  530. var Id=k.selections.items[0].data.pr_id;
  531. Ext.Ajax.request({//拿到tree数据
  532. url : basePath+'common/process/getContentsById.action',
  533. params: {
  534. param:Id,
  535. },
  536. method:'post',
  537. callback : function(options,success,response){
  538. res = new Ext.decode(response.responseText);
  539. if(res.success){
  540. contents=res.contents;
  541. var editor = Gef.activeEditor;
  542. // var model=editor.getGraphicalViewer().getRootEditPart().getContents().getModel();
  543. Ext.getCmp('FirstForm').getForm().setValues(k.selections.items[0].data);
  544. Gef.activeEditor.resetAndOpen(res.contents);
  545. var data=Ext.getCmp('FirstForm').getForm().getValues();
  546. App.propertyManager.initSelectionListener2(editor,data);
  547. }else{
  548. Ext.Msg.alert('提示','操作失败!');
  549. }
  550. }
  551. });
  552. }
  553. },
  554. });
  555. var win = new Ext.Window({
  556. id :'win',
  557. title: '人事',
  558. layout: 'fit',
  559. height: 500,
  560. width: 600,
  561. closeAction: 'hide',
  562. modal: true,
  563. items: [grid],
  564. listeners:{
  565. 'beforehide':function(c){
  566. Gef.activeEditor.enable();
  567. },
  568. 'beforeshow':function(c){
  569. Gef.activeEditor.disable();
  570. }
  571. },
  572. });
  573. win.show();
  574. }
  575. });
  576. }
  577. });
  578. },
  579. scope:this,
  580. },{
  581. text: '发布',
  582. iconCls: 'tb-deploy',
  583. deployProcess:function(caller){
  584. Ext.Ajax.request({
  585. method: 'post',
  586. params: {
  587. caller:caller,
  588. },
  589. url: basePath+'common/exitsJProcessDeploy.action',
  590. success: function(response) {
  591. try {
  592. var o = Ext.decode(response.responseText);
  593. if (o.result=== true) {
  594. var processDefId = o.processDefId;
  595. var version = processDefId.substring(processDefId.lastIndexOf("-")+1);
  596. Ext.Msg.alert('信息', '操作成功, 你的流程定义编号为:'+o.processDefId+" ,版本号为:"+version);
  597. } else if(o.result==false){
  598. /*Ext.Msg.alert('错误', o.errors.msg);
  599. Ext.Msg.alert('提示',"不存在该表单对应的流程 ,请先设计流程,保存后再发布!");
  600. return ;
  601. }
  602. } catch(e) {
  603. /*console.log(caller);
  604. Ext.Msg.alert('系统错误', response.responseText);
  605. }
  606. },
  607. failure: function(response) {
  608. /*console.log(caller);
  609. Ext.Msg.alert('系统错误', response.responseText);
  610. }
  611. });
  612. },
  613. handler: function() {
  614. var me = this;
  615. var counter = 0;
  616. var win = new Ext.Window({
  617. title: '请填写流程对应的表单名称',
  618. layout: 'fit',
  619. height: 95,
  620. width: 300,
  621. closeAction: 'hide',
  622. modal: true,
  623. items:[{
  624. xtype:'textfield',
  625. id :'caller'
  626. }],
  627. buttonAlign:'center',
  628. buttons: [{
  629. text:'确定发布',
  630. handler:function(){
  631. var value = Ext.getCmp("caller").getValue();
  632. if(value==null||value==''){
  633. alert("请先填写表单名称");
  634. return ;
  635. }
  636. else{
  637. if(counter == 0){
  638. me.deployProcess(value);
  639. counter = counter+1;
  640. }
  641. else{
  642. Ext.Msg.alert("提示","你已经发布该流程,不能重复发布!");
  643. Ext.Msg.alert("提示","请勿重复操作!");
  644. counter = 0;
  645. }
  646. }
  647. }
  648. }]
  649. });
  650. win.show();
  651. }
  652. }, {
  653. text: '清空',
  654. iconCls: 'tb-clear',
  655. handler: function() {
  656. Gef.activeEditor.clear();
  657. }
  658. }, {
  659. text: '撤销',
  660. iconCls: 'tb-undo',
  661. handler: function() {
  662. var viewer = Gef.activeEditor.getGraphicalViewer();
  663. var browserListener = viewer.getBrowserListener();
  664. var selectionManager = browserListener.getSelectionManager();
  665. selectionManager.clearAll();
  666. var commandStack = viewer.getEditDomain().getCommandStack();
  667. commandStack.undo();
  668. },
  669. scope: this
  670. }, {
  671. text: '重做',
  672. iconCls: 'tb-redo',
  673. handler: function() {
  674. var viewer = Gef.activeEditor.getGraphicalViewer();
  675. var model=viewer.getContents().getModel();
  676. var browserListener = viewer.getBrowserListener();
  677. var selectionManager = browserListener.getSelectionManager();
  678. selectionManager.selectIn((model.children)[2]);
  679. // selectionManager.clearAll();
  680. // var commandStack = viewer.getEditDomain().getCommandStack();
  681. // commandStack.redo();
  682. },
  683. scope: this
  684. }, {
  685. text: '布局',
  686. iconCls: 'tb-activity',
  687. handler: function() {
  688. var viewer = Gef.activeEditor.getGraphicalViewer();
  689. var browserListener = viewer.getBrowserListener();
  690. var selectionManager = browserListener.getSelectionManager();
  691. selectionManager.clearAll();
  692. new Layout(Gef.activeEditor).doLayout();
  693. },
  694. scope: this
  695. }, {
  696. text: '删除',
  697. iconCls: 'tb-delete',
  698. handler: this.removeSelected,
  699. scope: this
  700. },{
  701. text:'流程删除',
  702. iconCls: 'tb-delete',
  703. handler: this.deleteProcess,
  704. scope: this
  705. }]);**/
  706. App.CanvasPanel.superclass.initComponent.call(this);
  707. },
  708. afterRender: function() {
  709. App.CanvasPanel.superclass.afterRender.call(this);
  710. var width = 3000;
  711. var height = 2500;
  712. Ext.DomHelper.append(this.body, [{
  713. id: '__gef_jbs__',
  714. tag: 'div',
  715. style: 'width:' + (width + 10) + 'px;height:' + (height + 10) + 'px;',
  716. children: [{
  717. id: '__gef_jbs_center__',
  718. tag: 'div',
  719. style: 'width:' + width + 'px;height:' + height + 'px;float:left;'
  720. }, {
  721. id: '__gef_jbs_right__',
  722. tag: 'div',
  723. style: 'width:10px;height:' + height + 'px;float:left;background-color:#EEEEEE;cursor:pointer;'
  724. }, {
  725. id: '__gef_jbs_bottom__',
  726. tag: 'div',
  727. style: 'width:' + (width + 10) + 'px;height:10px;float:left;background-color:#EEEEEE;cursor:pointer;'
  728. }]
  729. }]);
  730. var rightEl = Ext.fly('__gef_jbs_right__');
  731. rightEl.on('mouseover', function(e) {
  732. var t = e.getTarget();
  733. t.style.backgroundColor = 'yellow';
  734. t.style.backgroundImage = 'url(images/arrow/arrow-right.png)';
  735. });
  736. rightEl.on('mouseout', function(e) {
  737. var t = e.getTarget();
  738. t.style.backgroundColor = '#EEEEEE';
  739. t.style.backgroundImage = '';
  740. });
  741. rightEl.on('click', function(e) {
  742. Ext.fly('__gef_jbs__').setWidth(Ext.fly('__gef_jbs__').getWidth() + 100);
  743. Ext.fly('__gef_jbs_center__').setWidth(Ext.fly('__gef_jbs_center__').getWidth() + 100);
  744. Ext.fly('__gef_jbs_bottom__').setWidth(Ext.fly('__gef_jbs_bottom__').getWidth() + 100);
  745. Gef.activeEditor.addWidth(100);
  746. });
  747. var bottomEl = Ext.fly('__gef_jbs_bottom__');
  748. bottomEl.on('mouseover', function(e) {
  749. var t = e.getTarget();
  750. t.style.backgroundColor = 'yellow';
  751. t.style.backgroundImage = 'url(images/arrow/arrow-bottom.png)';
  752. });
  753. bottomEl.on('mouseout', function(e) {
  754. var t = e.getTarget();
  755. t.style.backgroundColor = '#EEEEEE';
  756. t.style.backgroundImage = '';
  757. });
  758. rightEl.on('click', function(e) {
  759. Ext.fly('__gef_jbs__').setHeight(Ext.fly('__gef_jbs__').getHeight() + 100);
  760. Ext.fly('__gef_jbs_center__').setHeight(Ext.fly('__gef_jbs_center__').getHeight() + 100);
  761. Ext.fly('__gef_jbs_right__').setHeight(Ext.fly('__gef_jbs_right__').getHeight() + 100);
  762. Gef.activeEditor.addHeight(100);
  763. });
  764. // this.body.on('contextmenu', this.onContextMenu, this);//取消面板上 右键 操作 2012-08-24
  765. },
  766. onContextMenu: function(e) {
  767. if (!this.contextMenu) {
  768. this.contextMenu = new Ext.menu.Menu({
  769. items: [{
  770. text: '详细配置',
  771. iconCls: 'tb-prop',
  772. handler: this.showWindow,
  773. scope: this
  774. }, {
  775. text: '删除',
  776. iconCls: 'tb-remove',
  777. handler: this.removeSelected,
  778. scope: this
  779. }]
  780. });
  781. }
  782. e.preventDefault();
  783. this.contextMenu.showAt(e.getXY());
  784. },
  785. showWindow: function() {
  786. App.propertyManager.changePropertyStatus('max');
  787. },
  788. deleteProcess:function(){
  789. var id=parent.Ext.getCmp('jd_id').getValue();
  790. if(id){
  791. Ext.Ajax.request({
  792. url : basePath + 'common/deleteProcessDeploy.action',
  793. params: {
  794. id:id
  795. },
  796. method : 'post',
  797. callback : function(options,success,response){
  798. var localJson = new Ext.decode(response.responseText);
  799. if(localJson.exceptionInfo){
  800. showError(localJson.exceptionInfo);
  801. }
  802. if(localJson.success){
  803. Ext.Msg.alert('提示','删除成功!',function(){
  804. var main = parent.parent.Ext.getCmp("content-panel");
  805. main.getActiveTab().close();
  806. });
  807. }
  808. }
  809. });
  810. }
  811. },
  812. removeSelected: function() {
  813. //取消选中
  814. var viewer = Gef.activeEditor.getGraphicalViewer();
  815. var browserListener = viewer.getBrowserListener();
  816. var selectionManager = browserListener.getSelectionManager();
  817. var edge = selectionManager.selectedConnection;
  818. var nodes = selectionManager.items;
  819. var request = {};
  820. if (edge != null) {
  821. request.role = {
  822. name: 'REMOVE_EDGE'
  823. };
  824. this.executeCommand(edge, request);
  825. selectionManager.removeSelectedConnection();
  826. } if (nodes.length > 0) {
  827. request.role = {
  828. name: 'REMOVE_NODES',
  829. nodes: nodes
  830. };
  831. this.executeCommand(viewer.getContents(), request);
  832. selectionManager.clearAll();
  833. }
  834. },
  835. executeCommand: function(editPart, request) {
  836. var command = editPart.getCommand(request);
  837. if (command != null) {
  838. Gef.activeEditor.getGraphicalViewer().getEditDomain().getCommandStack().execute(command);
  839. }
  840. }
  841. });
  842. /*
  843. * Compressed by JSA(www.xidea.org)
  844. */
  845. Layout = function(editor) {
  846. this.editor = editor;
  847. this.processEditPart = editor.getGraphicalViewer().getContents();
  848. this.processModel = this.processEditPart.getModel();
  849. };
  850. Layout.prototype = {
  851. doLayout: function() {
  852. var diagram = new Diagram();
  853. diagram.init(this.processModel);
  854. var sorter = new TopologicalSorter(diagram);
  855. var sortedElements = sorter.getSortedElements();
  856. var sortedIds = [];
  857. for (var i = 0; i < sortedElements.length; i++) {
  858. sortedIds.push(sortedElements[i].id);
  859. }
  860. //console.info(sortedIds);
  861. var layouter = new LeftToRightGridLayouter(diagram, sortedIds);
  862. layouter.doLayout();
  863. var edgeMap = diagram.getEdgeMap();
  864. for (var edgeId in edgeMap) {
  865. var edge = edgeMap[edgeId];
  866. new EdgeLayouter(layouter.grid, edge);
  867. }
  868. diagram.updateModel();
  869. }
  870. };
  871. ;
  872. Diagram = function() {
  873. };
  874. Diagram.prototype = {
  875. getNodeMap: function() {
  876. return this.nodeMap;
  877. },
  878. getEdgeMap: function() {
  879. return this.edgeMap;
  880. },
  881. init: function(process) {
  882. this.process = process;
  883. this.nodeMap = {};
  884. this.edgeMap = {};
  885. for (var i = 0; i < this.process.children.length; i++) {
  886. var child = process.children[i];
  887. var node = new Node();
  888. node.id = child.text;
  889. node.type = child.type;
  890. node.x = child.x;
  891. node.y = child.y;
  892. node.w = child.w;
  893. node.h = child.h;
  894. this.nodeMap[node.id] = node;
  895. }
  896. for (var i = 0; i < this.process.children.length; i++) {
  897. var child = process.children[i];
  898. for (var j = 0; j < child.getOutgoingConnections().length; j++) {
  899. var connection = child.getOutgoingConnections()[j];
  900. this.createEdge(connection);
  901. }
  902. }
  903. },
  904. createEdge: function(connection) {
  905. var connectionId = connection.getSource().text + '_' + connection.getTarget().text;
  906. var edge = this.edgeMap[connectionId];
  907. if (!edge) {
  908. edge = new Edge();
  909. edge.id = connectionId;
  910. edge.name = connection.text;
  911. edge.source = this.nodeMap[connection.getSource().text];
  912. edge.target = this.nodeMap[connection.getTarget().text];
  913. edge.source.outgoingLinks.push(edge);
  914. edge.target.incomingLinks.push(edge);
  915. this.edgeMap[connectionId] = edge;
  916. }
  917. },
  918. updateModel: function() {
  919. for (var nodeId in this.nodeMap) {
  920. var item = this.nodeMap[nodeId];
  921. var model = this.getModel(nodeId);
  922. model.x = item.x;
  923. model.y = item.y;
  924. model.getEditPart().getFigure().x = model.x;
  925. model.getEditPart().getFigure().y = model.y;
  926. for (var i = 0; i < item.outgoingLinks.length; i++) {
  927. var connection = item.outgoingLinks[i];
  928. var connectionModel = this.getConnectionModel(model, connection);
  929. if (connectionModel == null) {
  930. continue;
  931. }
  932. connectionModel.innerPoints = typeof connection.innerPoints == 'undefined' ? []
  933. : connection.innerPoints;
  934. connectionModel.textX = 0;
  935. connectionModel.textY = 0;
  936. connectionModel.getEditPart().getFigure().innerPoints = connectionModel.innerPoints;
  937. connectionModel.getEditPart().getFigure().textX = connectionModel.textX;
  938. connectionModel.getEditPart().getFigure().textY = connectionModel.textY;
  939. }
  940. }
  941. this.process.getEditPart().refresh();
  942. },
  943. getModel: function(name) {
  944. var model = null;
  945. Gef.each(this.process.children, function(item) {
  946. if (item.text == name) {
  947. model = item;
  948. return false;
  949. }
  950. });
  951. return model;
  952. },
  953. getConnectionModel: function(nodeModel, edge) {
  954. var model = null;
  955. Gef.each(nodeModel.getOutgoingConnections(), function(item) {
  956. if (item.getTarget().text == edge.getTarget().id) {
  957. model = item;
  958. return false;
  959. }
  960. });
  961. return model;
  962. }
  963. };
  964. ;
  965. // should be change name to LayoutingElement
  966. Node = function() {
  967. this.incomingLinks = [];
  968. this.outgoingLinks = [];
  969. };
  970. Node.prototype = {
  971. getIncomingLinks: function() {
  972. return this.incomingLinks;
  973. },
  974. getOutgoingLinks: function() {
  975. return this.outgoingLinks;
  976. },
  977. getPrecedingElements: function() {
  978. var previousElements = [];
  979. for (var i = 0; i < this.incomingLinks.length; i++) {
  980. previousElements.push(this.incomingLinks[i].source);
  981. }
  982. return previousElements;
  983. },
  984. getFollowingElements: function() {
  985. var followingElements = [];
  986. for (var i = 0; i < this.outgoingLinks.length; i++) {
  987. followingElements.push(this.outgoingLinks[i].target);
  988. }
  989. return followingElements;
  990. },
  991. isJoin: function() {
  992. return this.incomingLinks.length > 1;
  993. },
  994. isSplit: function() {
  995. return this.outgoingLinks.length > 1;
  996. },
  997. prevSplit: function() {
  998. var distance = 1000;
  999. var candidateDistance = 0;
  1000. var split = null;
  1001. var candidate = null;
  1002. var precedingElements = this.getPrecedingElements();
  1003. for (var i = 0; i < precedingElements.length; i++) {
  1004. var elem = precedingElements[i];
  1005. if (elem.isSplit()) {
  1006. return elem;
  1007. }
  1008. candidate = elem.prevSplit();
  1009. if (this.isJoin()) {
  1010. // if this is not a join, we have only one precedingElement.
  1011. candidateDistance = elem.backwardDistanceTo(candidate);
  1012. }
  1013. if (candidateDistance < distance) {
  1014. split = candidate;
  1015. distance = candidateDistance;
  1016. }
  1017. }
  1018. return split;
  1019. },
  1020. backwardDistanceTo: function(other) {
  1021. return this._backwardDistanceTo(other, []);
  1022. },
  1023. _backwardDistanceTo: function(other, historyElements) {
  1024. if (other == this) {
  1025. return 0;
  1026. }
  1027. if (historyElements.indexOf(this) != -1) {
  1028. return 1000;
  1029. }
  1030. var d = 1000;
  1031. var newHistory = [];
  1032. newHistory.push(this);
  1033. var precedingElements = this.getPrecedingElements();
  1034. for (var i = 0; i < precedingElements.length; i++) {
  1035. var el = precedingElements[i];
  1036. d = Math.min(d, el._backwardDistanceTo(other, newHistory));
  1037. }
  1038. return d == 1000 ? d : d + 1;
  1039. }
  1040. };
  1041. ;
  1042. Edge = function() {
  1043. this.source = null;
  1044. this.target = null;
  1045. };
  1046. Edge.prototype = {
  1047. getSource: function() {
  1048. return this.source;
  1049. },
  1050. getTarget: function() {
  1051. return this.target;
  1052. },
  1053. reverseOutgoingAndIncoming: function() {
  1054. var index = 0;
  1055. var oldSource = this.source;
  1056. var oldTarget = this.target;
  1057. index = oldSource.outgoingLinks.indexOf(this);
  1058. oldSource.outgoingLinks.splice(index, 1);
  1059. index = oldTarget.incomingLinks.indexOf(this);
  1060. oldTarget.incomingLinks.splice(index, 1);
  1061. var newSource = oldTarget;
  1062. var newTarget = oldSource;
  1063. newSource.outgoingLinks.push(this);
  1064. newTarget.incomingLinks.push(this);
  1065. this.source = newSource;
  1066. this.target = newTarget;
  1067. }
  1068. };
  1069. ;
  1070. TopologicalSorter = function(diagram) {
  1071. this.diagram = diagram;
  1072. this.prepareDataAndSort(true);
  1073. this.prepareDataAndSort(false);
  1074. };
  1075. TopologicalSorter.prototype = {
  1076. getSortedElements: function() {
  1077. return this.sortedElements;
  1078. },
  1079. prepareDataAndSort: function(shouldBackpatch) {
  1080. this.sortedElements = [];
  1081. this.elementsToSort = {};
  1082. this.backwardsEdges = [];
  1083. this.elementsToSortCount = 0;
  1084. this.addAllChildren();
  1085. this.topologicalSort();
  1086. if (shouldBackpatch === true) {
  1087. this.backpatchBackwardsEdges();
  1088. }
  1089. this.reverseBackwardsEdges();
  1090. },
  1091. addAllChildren: function() {
  1092. for (var nodeId in this.diagram.nodeMap) {
  1093. var node = this.diagram.nodeMap[nodeId];
  1094. this.elementsToSort[nodeId] = new SortableLayoutingElement(node);
  1095. this.elementsToSortCount++;
  1096. }
  1097. },
  1098. topologicalSort: function() {
  1099. var count = 0;
  1100. var oldCount = 0;
  1101. while (this.elementsToSortCount > 0) {
  1102. var freeElements = this.getFreeElements();
  1103. if (freeElements.length > 0) {
  1104. for (var i = 0; i < freeElements.length; i++) {
  1105. var freeElement = freeElements[i];
  1106. this.sortedElements.push(freeElement.node);
  1107. this.freeElementsFrom(freeElement);
  1108. delete this.elementsToSort[freeElement.node.id];
  1109. }
  1110. } else {
  1111. var entry = this.getLoopEntryPoint();
  1112. for (var i = 0; i < entry.incomingLinks.length; i++) {
  1113. var backId = entry.incomingLinks[i];
  1114. entry.reverseIncomingLinkFrom(backId);
  1115. var elem = this.elementsToSort[backId];
  1116. elem.reverseOutgoingLinkTo(entry.node.id);
  1117. this.backwardsEdges.push(new BackwardsEdge(backId, entry.node.id));
  1118. }
  1119. }
  1120. }
  1121. },
  1122. backpatchBackwardsEdges: function() {
  1123. var newBackwardsEdges = [];
  1124. for (var i = 0; i < this.backwardsEdges.length; i++) {
  1125. newBackwardsEdges.push(this.backwardsEdges[i]);
  1126. }
  1127. for (var i = 0; i < this.backwardsEdges.length; i++) {
  1128. var edge = this.backwardsEdges[i];
  1129. var sourceId = edge.getSource();
  1130. var targetId = edge.getTarget();
  1131. var sourceElement = this.diagram.nodeMap[sourceId];
  1132. while (!(sourceElement.isJoin() || sourceElement.isSplit())) {
  1133. var newSourceElement = sourceElement.getPrecedingElements()[0];
  1134. targetId = newSourceElement.id;
  1135. newBackwardsEdges.push(new BackwardsEdge(targetId, sourceId));
  1136. sourceElement = newSourceElement;
  1137. sourceId = targetId;
  1138. }
  1139. }
  1140. this.backwardsEdges = newBackwardsEdges;
  1141. },
  1142. reverseBackwardsEdges: function() {
  1143. var edgeMap = this.diagram.edgeMap;
  1144. for (var i = 0; i < this.backwardsEdges.length; i++) {
  1145. var backwardsEdge = this.backwardsEdges[i];
  1146. var sourceId = backwardsEdge.getSource();
  1147. var targetId = backwardsEdge.getTarget();
  1148. var sourceElement = this.diagram.nodeMap[sourceId];
  1149. var targetElement = this.diagram.nodeMap[targetId];
  1150. var edge = this.getEdge(edgeMap, sourceElement, targetElement);
  1151. backwardsEdge.setEdge(edge);
  1152. if (edge) {
  1153. // reverse edge outgoing and incoming
  1154. edge.reverseOutgoingAndIncoming();
  1155. }
  1156. }
  1157. },
  1158. getFreeElements: function() {
  1159. var freeElements = [];
  1160. for (var nodeId in this.elementsToSort) {
  1161. var elem = this.elementsToSort[nodeId];
  1162. if (elem.isFree()) {
  1163. freeElements.push(elem);
  1164. }
  1165. }
  1166. return freeElements;
  1167. },
  1168. freeElementsFrom: function(freeElement) {
  1169. for (var i = 0; i < freeElement.outgoingLinks.length; i++) {
  1170. var id = freeElement.outgoingLinks[i];
  1171. var targetElement = this.elementsToSort[id];
  1172. if (targetElement) {
  1173. targetElement.removeIncomingLinkFrom(freeElement.node.id);
  1174. }
  1175. }
  1176. this.elementsToSortCount--;
  1177. },
  1178. getLoopEntryPoint: function() {
  1179. for (var nodeId in this.elementsToSort) {
  1180. var candidate = this.elementsToSort[nodeId];
  1181. if (candidate.oldInCount > 1
  1182. && candidate.oldInCount > candidate.incomingLinks.length) {
  1183. return candidate;
  1184. }
  1185. }
  1186. throw new Error('Could not find a valid loop entry point');
  1187. },
  1188. getEdge: function(edgeMap, sourceElement, targetElement) {
  1189. for (var i = 0; i < sourceElement.outgoingLinks.length; i++) {
  1190. var edge = sourceElement.outgoingLinks[i];
  1191. if (edge.getTarget().id == targetElement.id) {
  1192. return edge;
  1193. }
  1194. }
  1195. return null;
  1196. }
  1197. };
  1198. ;
  1199. SortableLayoutingElement = function(node) {
  1200. this.node = node;
  1201. this.incomingLinks = [];
  1202. this.outgoingLinks = [];
  1203. for (var i = 0; i < node.incomingLinks.length; i++) {
  1204. this.incomingLinks.push(node.incomingLinks[i].source.id);
  1205. }
  1206. for (var i = 0; i < node.outgoingLinks.length; i++) {
  1207. this.outgoingLinks.push(node.outgoingLinks[i].target.id);
  1208. }
  1209. this.oldInCount = this.incomingLinks.length;
  1210. this.isJoin = node.isJoin();
  1211. };
  1212. SortableLayoutingElement.prototype = {
  1213. isFree: function() {
  1214. return this.incomingLinks.length == 0;
  1215. },
  1216. removeIncomingLinkFrom: function(sourceId) {
  1217. var index = this.incomingLinks.indexOf(sourceId);
  1218. this.incomingLinks.splice(index, 1);
  1219. },
  1220. reverseIncomingLinkFrom: function(id) {
  1221. this.removeIncomingLinkFrom(id);
  1222. this.outgoingLinks.push(id);
  1223. },
  1224. reverseOutgoingLinkTo: function(id) {
  1225. var index = this.outgoingLinks.indexOf(id);
  1226. this.outgoingLinks.splice(index, 1);
  1227. this.incomingLinks.push(id);
  1228. }
  1229. };
  1230. ;
  1231. BackwardsEdge = function(source, target) {
  1232. this.source = source;
  1233. this.target = target;
  1234. };
  1235. BackwardsEdge.prototype = {
  1236. getEdge: function() {
  1237. return this.edge;
  1238. },
  1239. setEdge: function(edge) {
  1240. this.edge = edge;
  1241. },
  1242. getSource: function() {
  1243. return this.source;
  1244. },
  1245. getTarget: function() {
  1246. return this.target;
  1247. }
  1248. };
  1249. ;
  1250. LeftToRightGridLayouter = function(diagram, sortedIds) {
  1251. this.diagram = diagram;
  1252. this.sortedIds = sortedIds;
  1253. };
  1254. LeftToRightGridLayouter.prototype = {
  1255. doLayout: function() {
  1256. this.grid = new Grid();
  1257. this.layoutElements();
  1258. this.calcGeometry(this.grid);
  1259. this.writeGeometry(this.grid);
  1260. this.diagram.updateModel();
  1261. },
  1262. layoutElements: function() {
  1263. for (var i = 0; i < this.sortedIds.length; i++) {
  1264. var sortedId = this.sortedIds[i];
  1265. var currentElement = this.diagram.nodeMap[sortedId];
  1266. var precedingElements = currentElement.getPrecedingElements();
  1267. var cellOfElement = this.placeElement(currentElement, precedingElements);
  1268. if (currentElement.isJoin() && precedingElements.length != 0) {
  1269. // there is an edge hitting us left, so lets forbid
  1270. // interleaving to use the left cell, if this is empty
  1271. cellOfElement.getPrevCell().setPackable(false);
  1272. }
  1273. if (currentElement.isSplit()) {
  1274. this.prelayoutSuccessors(currentElement, cellOfElement);
  1275. }
  1276. }
  1277. },
  1278. placeElement: function(currentElement, precedingElements) {
  1279. var newCell = null;
  1280. if (precedingElements.length == 0) {
  1281. this.grid.startCell.value = currentElement;
  1282. newCell = this.grid.startCell;
  1283. } else {
  1284. var leftCell = null;
  1285. var newCell = this.grid.getCellOfItem(currentElement);
  1286. if (currentElement.isJoin()) {
  1287. var splitFound = false;
  1288. var split = currentElement.prevSplit();
  1289. if (split != null) {
  1290. var splits = new PriorityQueue(currentElement);
  1291. splits.add(split);
  1292. for (var i = 0; i < precedingElements.length; i++) {
  1293. var elem = precedingElements[i];
  1294. split = elem.prevSplit();
  1295. if (split != null && !splits.contains(split)) {
  1296. splits.add(split);
  1297. //console.info(splits.items);
  1298. }
  1299. }
  1300. split = null;
  1301. // get split with most connections
  1302. var maxCon = 0;
  1303. for (var i = 0; i < splits.items.length; i++) {
  1304. var target = splits.items[i];
  1305. if (target == currentElement) {
  1306. continue;
  1307. }
  1308. // current connections
  1309. var curCon = 0;
  1310. for (var j = 0; j < precedingElements.length; j++) {
  1311. var elem = precedingElements[j];
  1312. if (elem.backwardDistanceTo(target) < 1000) {
  1313. curCon++;
  1314. }
  1315. }
  1316. if (curCon > maxCon) {
  1317. maxCon = curCon;
  1318. split = target;
  1319. }
  1320. }
  1321. splitFound = split != null;
  1322. }
  1323. // current cell position
  1324. var x = 0;
  1325. var yAcc = 0;
  1326. var yCnt = 0;
  1327. for (var i = 0; i < precedingElements.length; i++) {
  1328. var elem = precedingElements[i];
  1329. var tmp = this.grid.getCellOfItem(elem);
  1330. if (tmp == null) {
  1331. tmp = {
  1332. getColIndex: function() {
  1333. return 0;
  1334. }
  1335. };
  1336. } else {
  1337. yAcc += tmp.getRowIndex();
  1338. yCnt++;
  1339. }
  1340. x = Math.max(x, tmp.getColIndex());
  1341. }
  1342. // farthest to the right
  1343. if (splitFound) {
  1344. leftCell = this.grid.getCellOfItem(split).row.cells[x];
  1345. // set path to split unpackable
  1346. for (var c = leftCell; c.value != split; c = c.getPrevCell()) {
  1347. c.setPackable(false);
  1348. }
  1349. } else {
  1350. if (yCnt == 0) {
  1351. leftCell = this.grid.rows[0].above().cells[x];
  1352. } else {
  1353. leftCell = this.grid.rows[yAcc / yCnt].cells[x];
  1354. }
  1355. }
  1356. if (newCell != null && newCell.value == currentElement) {
  1357. newCell.value = null;
  1358. }
  1359. newCell = leftCell.after();
  1360. // set all incoming pathes unpackable
  1361. for (var i = 0; i < precedingElements.length; i++) {
  1362. var el = precedingElements[i];
  1363. var target = this.grid.getCellOfItem(el);
  1364. if (target == null) {
  1365. continue;
  1366. }
  1367. var start = target.row.cells[x + 1];
  1368. for (var c = start; c != target; c = c.getPrevCell()) {
  1369. c.setPackable(false);
  1370. }
  1371. }
  1372. } else if (newCell == null) {
  1373. // if not preLayouted
  1374. var preElem = precedingElements[0];
  1375. leftCell = this.grid.getCellOfItem(preElem);
  1376. newCell = leftCell.after();
  1377. }
  1378. if (newCell.isFilled() && newCell.value != currentElement) {
  1379. newCell.row.insertRowBeneath();
  1380. newCell = newCell.beneath();
  1381. }
  1382. newCell.value = currentElement;
  1383. newCell.getPrevCell().setPackable(false);
  1384. }
  1385. return newCell;
  1386. },
  1387. prelayoutSuccessors: function(currentElement, cellOfElement) {
  1388. var baseCell = cellOfElement.after();
  1389. var topCell = baseCell;
  1390. var followingElements = currentElement.getFollowingElements();
  1391. // heuristic for direct connection to join
  1392. var directJoin = null;
  1393. for (var i = 0; i < followingElements.length; i++) {
  1394. var possibleJoin = followingElements[i];
  1395. if (possibleJoin.isJoin()) {
  1396. directJoin = possibleJoin;
  1397. }
  1398. }
  1399. if (directJoin != null) {
  1400. // put in the middle
  1401. var index = followingElements.indexOf(directJoin);
  1402. // remove
  1403. followingElements.splice(index, 1);
  1404. var position = parseInt(followingElements.length / 2, 10);
  1405. // insert
  1406. followingElements.splice(position, 0, directJoin);
  1407. }
  1408. // normal preLayout following elements
  1409. var follow = parseInt(followingElements.length / 2, 10);
  1410. for (var i = 0; i < follow; i++) {
  1411. topCell.row.insertRowAbove();
  1412. baseCell.row.insertRowBeneath();
  1413. topCell = topCell.above();
  1414. }
  1415. for (var i = 0; i < followingElements.length; i++) {
  1416. var newElem = followingElements[i];
  1417. if (this.grid.getCellOfItem(newElem)) {
  1418. continue;
  1419. }
  1420. topCell.value = newElem;
  1421. topCell = topCell.beneath();
  1422. if (topCell == baseCell && followingElements.length % 2 == 0) {
  1423. topCell = topCell.beneath();
  1424. }
  1425. }
  1426. },
  1427. calcGeometry: function(grid) {
  1428. grid.pack();
  1429. var heightOfRow = [];
  1430. for (var i = 0; i < grid.rowCount; i++) {
  1431. heightOfRow.push(0);
  1432. }
  1433. var widthOfColumn = [];
  1434. for (var i = 0; i < grid.colCount; i++) {
  1435. widthOfColumn.push(0);
  1436. }
  1437. for (var i = 0; i < grid.rowCount; i++) {
  1438. var row = grid.rows[i];
  1439. for (var j = 0; j < grid.colCount; j++) {
  1440. var cell = row.cells[j];
  1441. if (cell.isFilled()) {
  1442. var elem = cell.value;
  1443. widthOfColumn[j] = Math.max(widthOfColumn[j], elem.w + 30);
  1444. heightOfRow[i] = Math.max(heightOfRow[i], elem.h + 30);
  1445. }
  1446. }
  1447. }
  1448. this.heightOfRow = heightOfRow;
  1449. this.widthOfColumn = widthOfColumn;
  1450. this.totalWidth = 0;
  1451. this.totalHeight = 0;
  1452. for (var i = 0; i < grid.colCount; i++) {
  1453. this.totalWidth += widthOfColumn[i];
  1454. }
  1455. for (var i = 0; i < grid.rowCount; i++) {
  1456. this.totalHeight += heightOfRow[i];
  1457. }
  1458. },
  1459. writeGeometry: function(grid) {
  1460. var x = 0;
  1461. var y = 0;
  1462. for (var i = 0; i < grid.rowCount; i++) {
  1463. var row = grid.rows[i];
  1464. var cellHeight = this.heightOfRow[i];
  1465. for (var j = 0; j < grid.colCount; j++) {
  1466. var cell = row.cells[j];
  1467. var cellWidth = this.widthOfColumn[j];
  1468. if (cell.isFilled()) {
  1469. var elem = cell.value;
  1470. var newX = x + cellWidth / 2 - elem.w / 2;
  1471. var newY = y + cellHeight / 2 - elem.h / 2;
  1472. elem.x = newX;
  1473. elem.y = newY;
  1474. }
  1475. x += cellWidth;
  1476. }
  1477. x = 0;
  1478. y += cellHeight;
  1479. }
  1480. }
  1481. };
  1482. ;
  1483. Grid = function() {
  1484. var cell = new Cell();
  1485. var row = new Row();
  1486. row.grid = this;
  1487. row.addCell(cell);
  1488. this.rows = [row];
  1489. this.startCell = cell;
  1490. this.colCount = 1;
  1491. this.rowCount = this.rows.length;
  1492. };
  1493. Grid.prototype = {
  1494. addFirstRow: function() {
  1495. var row = new Row();
  1496. row.grid = this;
  1497. for (var i = 0; i < this.rolCount; i++) {
  1498. var cell = new Cell();
  1499. row.addCell(cell);
  1500. }
  1501. this.rows.unshift(row);
  1502. this.rowCount = this.rows.length;
  1503. },
  1504. addLastRow: function() {
  1505. var row = new Row();
  1506. row.grid = this;
  1507. for (var i = 0; i < this.rolCount; i++) {
  1508. row.addCell(new Cell());
  1509. }
  1510. this.rows.push(row);
  1511. this.rowCount = this.rows.length;
  1512. },
  1513. addLastCol: function() {
  1514. for (var i = 0; i < this.rowCount; i++) {
  1515. var row = this.rows[i];
  1516. row.addCell(new Cell());
  1517. }
  1518. this.colCount++;
  1519. },
  1520. getCellOfItem: function(elem) {
  1521. for (var i = 0; i < this.rowCount; i++) {
  1522. var row = this.rows[i];
  1523. for (var j = 0; j < this.colCount; j++) {
  1524. var cell = row.cells[j];
  1525. if (cell.value == elem) {
  1526. return cell;
  1527. }
  1528. }
  1529. }
  1530. return null;
  1531. },
  1532. pack: function() {
  1533. var changed = false;
  1534. do {
  1535. changed = false;
  1536. for (var i = 0; i < this.rows.length; i++) {
  1537. var row = this.rows[i];
  1538. changed |= row.tryInterleaveWith(row.getPrevRow());
  1539. }
  1540. for (var i = 0; i < this.rows.length; i++) {
  1541. var row = this.rows[i];
  1542. changed |= row.tryInterleaveWith(row.getNextRow());
  1543. }
  1544. } while (changed);
  1545. },
  1546. info: function() {
  1547. var value = '';
  1548. for (var i = 0; i < this.rows.length; i++) {
  1549. var row = this.rows[i];
  1550. for (var j = 0; j < row.cells.length; j++) {
  1551. var cell = row.cells[j];
  1552. var id = '[ ]';
  1553. if (cell.isFilled()) {
  1554. id = cell.value.id;
  1555. } else if (cell.packable === false) {
  1556. id = '[ p ]';
  1557. }
  1558. value += id;
  1559. }
  1560. value += '\n'
  1561. }
  1562. return value;
  1563. }
  1564. };
  1565. ;
  1566. Cell = function() {
  1567. this.packable = true;
  1568. };
  1569. Cell.prototype = {
  1570. isFilled: function() {
  1571. return typeof this.value != 'undefined' && this.value != null;
  1572. },
  1573. isUnpackable: function() {
  1574. return this.isFilled() || (this.packable === false);
  1575. },
  1576. setPackable: function(packable) {
  1577. this.packable = packable;
  1578. },
  1579. getRowIndex: function() {
  1580. return this.row.getIndex();
  1581. },
  1582. getColIndex: function() {
  1583. for (var i = 0; i < this.row.cells.length; i++) {
  1584. if (this.row.cells[i] == this) {
  1585. return i;
  1586. }
  1587. }
  1588. },
  1589. after: function() {
  1590. var colIndex = this.getColIndex();
  1591. if (colIndex == this.row.cells.length - 1) {
  1592. this.grid.addLastCol();
  1593. }
  1594. return this.row.cells[colIndex + 1];
  1595. },
  1596. above: function() {
  1597. var rowIndex = this.getRowIndex();
  1598. var colIndex = this.getColIndex();
  1599. if (rowIndex == 0) {
  1600. this.row.insertRowAbove();
  1601. }
  1602. return this.grid.rows[rowIndex - 1].cells[colIndex];
  1603. },
  1604. beneath: function() {
  1605. var rowIndex = this.getRowIndex();
  1606. var colIndex = this.getColIndex();
  1607. if (rowIndex == this.grid.rowCount - 1) {
  1608. this.row.insertRowBeneath();
  1609. }
  1610. return this.grid.rows[rowIndex + 1].cells[colIndex];
  1611. },
  1612. getPrevCell: function() {
  1613. var index = this.getColIndex();
  1614. return this.row.cells[index - 1];
  1615. },
  1616. getNextCell: function() {
  1617. var index = this.getColIndex();
  1618. return this.row.cells[index + 1];
  1619. }
  1620. };
  1621. ;
  1622. Row = function() {
  1623. this.cells = [];
  1624. };
  1625. Row.prototype = {
  1626. addCell: function(cell) {
  1627. cell.row = this;
  1628. cell.grid = this.grid;
  1629. this.cells.push(cell);
  1630. },
  1631. getIndex: function() {
  1632. for (var i = 0; i < this.grid.rows.length; i++) {
  1633. if (this.grid.rows[i] == this) {
  1634. return i;
  1635. }
  1636. }
  1637. },
  1638. insertRowBeneath: function() {
  1639. var row = new Row();
  1640. row.grid = this.grid;
  1641. for (var i = 0; i < this.grid.colCount; i++) {
  1642. row.addCell(new Cell());
  1643. }
  1644. var rowIndex = this.getIndex();
  1645. var rows = this.grid.rows;
  1646. if (rowIndex == rows.length - 1) {
  1647. rows.push(row);
  1648. } else {
  1649. rows.splice(rowIndex + 1, 0, row);
  1650. }
  1651. this.grid.rowCount = rows.length;
  1652. },
  1653. insertRowAbove: function() {
  1654. var row = new Row();
  1655. row.grid = this.grid;
  1656. for (var i = 0; i < this.grid.colCount; i++) {
  1657. row.addCell(new Cell());
  1658. }
  1659. var rowIndex = this.getIndex();
  1660. var rows = this.grid.rows;
  1661. if (rowIndex == 0) {
  1662. rows.unshift(row);
  1663. } else {
  1664. rows.splice(rowIndex, 0, row);
  1665. }
  1666. this.grid.rowCount = rows.length;
  1667. },
  1668. getPrevRow: function() {
  1669. var index = this.getIndex();
  1670. if (index > 0) {
  1671. return this.grid.rows[index - 1];
  1672. } else {
  1673. return null;
  1674. }
  1675. },
  1676. getNextRow: function() {
  1677. var index = this.getIndex();
  1678. if (index < this.grid.rows.length) {
  1679. return this.grid.rows[index + 1];
  1680. } else {
  1681. return null;
  1682. }
  1683. },
  1684. tryInterleaveWith: function(other) {
  1685. if (!this.isInterleaveWith(other)) {
  1686. return false;
  1687. }
  1688. for (var i = 0; i < this.cells.length; i++) {
  1689. var cell = this.cells[i];
  1690. var otherCell = other.cells[i];
  1691. if (cell.isFilled()) {
  1692. other.cells[i] = cell;
  1693. } else if (cell.isUnpackable()) {
  1694. otherCell.setPackable(false);
  1695. }
  1696. }
  1697. this._remove();
  1698. return true;
  1699. },
  1700. isInterleaveWith: function(other) {
  1701. if (other == null || other == this) {
  1702. return false;
  1703. } else if (other.getPrevRow() != this && other.getNextRow() != this) {
  1704. return false;
  1705. }
  1706. for (var i = 0; i < this.cells.length; i++) {
  1707. var cell = this.cells[i];
  1708. var otherCell = other.cells[i];
  1709. if (cell.isUnpackable() && otherCell.isUnpackable()) {
  1710. return false;
  1711. }
  1712. }
  1713. return true;
  1714. },
  1715. _remove: function() {
  1716. var index = this.getIndex();
  1717. this.grid.rows.splice(index, 1);
  1718. this.grid.rowCount--;
  1719. }
  1720. };
  1721. ;
  1722. PriorityQueue = function(center) {
  1723. this.ce = center;
  1724. this.items = [];
  1725. };
  1726. PriorityQueue.prototype = {
  1727. add: function(element) {
  1728. this.items.push(element);
  1729. var len = this.items.length;
  1730. for (var i = 0; i < len; i++) {
  1731. for (var j = i; j < len; j++) {
  1732. var elem1 = this.items[i];
  1733. var elem2 = this.items[j];
  1734. if (this.compareTo(elem1, elem2) > 0) {
  1735. this.items[i] = elem2;
  1736. this.items[j] = elem1;
  1737. }
  1738. }
  1739. }
  1740. },
  1741. compareTo: function(elem1, elem2) {
  1742. return this.ce.backwardDistanceTo(elem1) - this.ce.backwardDistanceTo(elem2);
  1743. },
  1744. contains: function(element) {
  1745. return this.items.indexOf(element) != -1;
  1746. }
  1747. };
  1748. ;
  1749. EdgeLayouter = function(grid, edge) {
  1750. this.grid = grid;
  1751. this.edge = edge;
  1752. edge.innerPoints = [];
  1753. this.calculateGlobals();
  1754. this.pickLayoutForEdge();
  1755. };
  1756. EdgeLayouter.prototype = {
  1757. calculateGlobals: function() {
  1758. this.source = this.edge.source;
  1759. this.target = this.edge.target;
  1760. this.sourceRelativeCenterX = this.source.w / 2;
  1761. this.sourceRelativeCenterY = this.source.h / 2;
  1762. this.targetRelativeCenterX = this.target.w / 2;
  1763. this.targetRelativeCenterY = this.target.h / 2;
  1764. this.sourceAbsoluteCenterX = this.source.x + this.sourceRelativeCenterX;
  1765. this.sourceAbsoluteCenterY = this.source.y + this.sourceRelativeCenterY;
  1766. this.targetAbsoluteCenterX = this.target.x + this.targetRelativeCenterX;
  1767. this.targetAbsoluteCenterY = this.target.y + this.targetRelativeCenterY;
  1768. this.sourceAbsoluteX = this.source.x;
  1769. this.sourceAbsoluteY = this.source.y;
  1770. this.sourceAbsoluteX2 = this.source.x + this.source.w;
  1771. this.sourceAbsoluteY2 = this.source.y + this.source.h;
  1772. this.targetAbsoluteX = this.target.x;
  1773. this.targetAbsoluteY = this.target.y;
  1774. this.targetAbsoluteX2 = this.target.x + this.target.w;
  1775. this.targetAbsoluteY2 = this.target.y + this.target.h;
  1776. this.sourceJoin = this.source.isJoin();
  1777. this.sourceSplit = this.source.isSplit();
  1778. this.targetJoin = this.target.isJoin();
  1779. this.targetSplit = this.target.isSplit();
  1780. this.backwards = this.sourceAbsoluteCenterX > this.targetAbsoluteCenterX;
  1781. },
  1782. pickLayoutForEdge: function() {
  1783. // sourceX == targetX, up and down
  1784. if (this.sourceAbsoluteCenterX == this.targetAbsoluteCenterX) {
  1785. this.setEdgeDirectCenter();
  1786. return;
  1787. } else if (this.sourceAbsoluteCenterY == this.targetAbsoluteCenterY) {
  1788. if (this.areCellsHorizontalFree()) {
  1789. this.setEdgeDirectCenter();
  1790. } else {
  1791. this.setEdgeAroundTheCorner(true);
  1792. }
  1793. return;
  1794. }
  1795. if (this.sourceAbsoluteCenterX <= this.targetAbsoluteCenterX
  1796. && this.sourceAbsoluteCenterY <= this.targetAbsoluteCenterY) {
  1797. // target is right under
  1798. if (this.sourcejoin && this.sourceSplit) {
  1799. this.setEdgeStepRight();
  1800. return;
  1801. } else if (this.sourceSplit) {
  1802. this.setEdge90DegreeRightUnderAntiClockwise();
  1803. return;
  1804. } else if (this.targetJoin) {
  1805. this.setEdge90DegreeRightUnderClockwise();
  1806. return;
  1807. }
  1808. } else if (this.sourceAbsoluteCenterX <= this.targetAbsoluteCenterX
  1809. && this.sourceAbsoluteCenterY > this.targetAbsoluteCenterY) {
  1810. // target is right above
  1811. if (this.sourcejoin && this.sourceSplit) {
  1812. this.setEdgeStepRight();
  1813. return;
  1814. } else if (this.sourceSplit) {
  1815. this.setEdge90DegreeRightAboveClockwise();
  1816. return;
  1817. } else if (this.targetJoin) {
  1818. this.setEdge90DegreeRightAboveAntiClockwise();
  1819. return;
  1820. }
  1821. }
  1822. if (this.sourceJoin && sourceSplit && (!this.backwards)) {
  1823. this.setEdgeStepRight();
  1824. return;
  1825. }
  1826. if (this.sourceJoin && sourceSplit) {
  1827. this.setEdgeAroundTheCorner(true);
  1828. return;
  1829. }
  1830. this.setEdgeDirectCenter();
  1831. },
  1832. areCellsHorizontalFree: function() {
  1833. var fromCell = null;
  1834. var toCell = null;
  1835. if (this.sourceAbsoluteCenterX < this.targetAbsoluteCenterX) {
  1836. fromCell = this.grid.getCellOfItem(this.source);
  1837. toCell = this.grid.getCellOfItem(this.target);
  1838. } else {
  1839. fromCell = this.grid.getCellOfItem(this.target);
  1840. toCell = this.grid.getCellOfItem(this.source);
  1841. }
  1842. fromCell = fromCell.getNextCell();
  1843. while (fromCell != toCell) {
  1844. if (fromCell == null || fromCell.isFilled()) {
  1845. return false;
  1846. }
  1847. fromCell = fromCell.getNextCell();
  1848. }
  1849. return true;
  1850. },
  1851. setEdgeDirectCenter: function() {
  1852. var boundsMinX = Math.min(this.sourceAbsoluteCenterX,
  1853. this.targetAbsoluteCenterX);
  1854. var boundsMinY = Math.min(this.sourceAbsoluteCenterY,
  1855. this.targetAbsoluteCenterY);
  1856. var boundsMaxX = Math.max(this.sourceAbsoluteCenterX,
  1857. this.targetAbsoluteCenterX);
  1858. var boundsMaxY = Math.max(this.sourceAbsoluteCenterY,
  1859. this.targetAbsoluteCenterY);
  1860. // this.edge.innerPoints = [];
  1861. },
  1862. setEdge90DegreeRightAboveClockwise: function() {
  1863. this.edge.innerPoints = [
  1864. [this.sourceAbsoluteCenterX, this.targetAbsoluteCenterY]
  1865. ];
  1866. },
  1867. setEdge90DegreeRightAboveAntiClockwise: function() {
  1868. this.edge.innerPoints = [
  1869. [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY]
  1870. ];
  1871. },
  1872. setEdge90DegreeRightUnderClockwise: function() {
  1873. this.edge.innerPoints = [
  1874. [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY]
  1875. ];
  1876. },
  1877. setEdge90DegreeRightUnderAntiClockwise: function() {
  1878. this.edge.innerPoints = [
  1879. [this.sourceAbsoluteCenterX, this.targetAbsoluteCenterY]
  1880. ];
  1881. },
  1882. setEdgeAroundTheCorner: function(down) {
  1883. var height = Math.max(this.source.h / 2, this.target.h / 2) + 20;
  1884. if (down) {
  1885. height *= -1;
  1886. }
  1887. this.edge.innerPoints = [
  1888. [this.sourceAbsoluteCenterX, this.sourceAbsoluteCenterY + height],
  1889. [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY + height]
  1890. ];
  1891. }
  1892. };
  1893. Ext.ux.OneCombo = Ext.extend(Ext.form.ComboBox, {
  1894. initComponent: function() {
  1895. this.readOnly = true;
  1896. this.displayField = 'text';
  1897. this.valueField = 'text';
  1898. this.triggerAction = 'all';
  1899. this.mode = 'local';
  1900. this.emptyText = 'Please Select...';
  1901. this.store = new Ext.data.SimpleStore({
  1902. expandData: true,
  1903. fields: ['text']
  1904. });
  1905. this.store.loadData(this.data);
  1906. Ext.ux.OneCombo.superclass.initComponent.call(this);
  1907. }
  1908. });
  1909. Ext.reg('onecombo', Ext.ux.OneCombo);
  1910. App.PalettePanel = Ext.extend(Ext.Panel, {
  1911. initComponent: function() {
  1912. this.region = 'west';
  1913. this.title = '活动环节';
  1914. this.iconCls = 'tb-activity';
  1915. this.width = 130;
  1916. this.initPalette();
  1917. App.PalettePanel.superclass.initComponent.call(this);
  1918. },
  1919. initPalette: function() {
  1920. var paletteType = null;
  1921. if (!Gef.PALETTE_TYPE) {
  1922. paletteType = 'accordion';
  1923. } else {
  1924. paletteType = Gef.PALETTE_TYPE;
  1925. }
  1926. this.configLayout(paletteType);
  1927. this.configItems(paletteType);
  1928. },
  1929. createHtml: function(array, divId) {
  1930. var imageRoot = Gef.IMAGE_ROOT.replace('48/', '');
  1931. if (divId) {
  1932. var html = '<div id="' + divId + '" unselectable="on">';
  1933. } else {
  1934. var html = '<div unselectable="on">';
  1935. }
  1936. for (var i = 0; i < array.length; i++) {
  1937. var item = array[i];
  1938. html += '<div id="' + item.name
  1939. + '" class="paletteItem-' + item.name
  1940. + '" style="text-align:center;font-size:12px;cursor:pointer;" unselectable="on"><img id="'
  1941. + item.name + '-img" class="paletteItem-' + item.name
  1942. + '" src="' + imageRoot + item.image + '.png" unselectable="on"><br>'
  1943. + item.title + '</div>';
  1944. }
  1945. html += '</div>';
  1946. return html;
  1947. },
  1948. /**
  1949. * this.layout = 'accordion';
  1950. */
  1951. configLayout: function(type) {
  1952. if (!type || type == 'plain') {
  1953. //
  1954. } else if (type && type == 'accordion') {
  1955. this.layout = 'accordion';
  1956. }
  1957. },
  1958. configItems: function(type) {
  1959. if (type && type == 'accordion') {
  1960. this.createItemsForAccordion();
  1961. } else if (!type || type == 'plain') {
  1962. this.createItemsForHtml();
  1963. }
  1964. },
  1965. createItemsForAccordion: function() {
  1966. this.id = '__gef_jbs_palette__';
  1967. this.items = [{
  1968. title: '所有活动',
  1969. iconCls: 'tb-activity',
  1970. autoScroll: true,
  1971. html: this.createHtml([
  1972. {name: 'select', image: 'select32', title: '选择'},
  1973. {name: 'transition', image: '32/flow_sequence', title: '连线'},
  1974. {name: 'start', image: '32/start_event_empty', title: '开始'},
  1975. {name: 'end', image: '32/end_event_terminate', title: '结束'},
  1976. {name: 'cancel', image: '32/end_event_cancel', title: '取消'},
  1977. {name: 'error', image: '32/end_event_error', title: '错误'},
  1978. {name: 'task', image: '32/task_empty', title: '任务'},
  1979. {name: 'decision', image: '32/gateway_exclusive', title: '决策'},
  1980. {name: 'sql', image: '32/task_sql', title: 'SQL'},
  1981. {name: 'fork', image: '32/gateway_parallel', title: '并行'},
  1982. {name: 'join', image: '32/gateway_parallel', title: '汇聚'}
  1983. ])
  1984. }];
  1985. },
  1986. createItemsForHtml: function() {
  1987. this.autoScroll = true;
  1988. this.html = this.createHtml([
  1989. {name: 'select', image: 'select32', title: '选择'},
  1990. {name: 'transition', image: '32/flow_sequence', title: '连线'},
  1991. {name: 'start', image: '32/start_event_empty', title: '开始'},
  1992. {name: 'end', image: '32/end_event_terminate', title: '结束'},
  1993. {name: 'cancel', image: '32/end_event_cancel', title: '取消'},
  1994. {name: 'error', image: '32/end_event_error', title: '错误'},
  1995. {name: 'state', image: '32/task_wait', title: '等待'},
  1996. {name: 'task', image: '32/task_empty', title: '任务'},
  1997. {name: 'decision', image: '32/gateway_exclusive', title: '决策'},
  1998. {name: 'fork', image: '32/gateway_parallel', title: '并行'},
  1999. {name: 'join', image: '32/gateway_parallel', title: '汇聚'},
  2000. {name: 'java', image: '32/task_java', title: 'JAVA'},
  2001. {name: 'script', image: '32/task_java', title: '脚本'},
  2002. {name: 'hql', image: '32/task_hql', title: 'HQL'},
  2003. {name: 'sql', image: '32/task_sql', title: 'SQL'},
  2004. {name: 'mail', image: '32/task_empty', title: '邮件'},
  2005. {name: 'custom', image: '32/task_empty', title: '自定义'},
  2006. {name: 'subProcess', image: '32/task_empty', title: '子流程'},
  2007. {name: 'jms', image: '32/task_empty', title: 'JMS'},
  2008. {name: 'ruleDecision', image: '32/gateway_exclusive', title: '规则决策'},
  2009. {name: 'rules', image: '32/task_empty', title: '规则'},
  2010. {name: 'human', image: '32/task_empty', title: '人工节点'},
  2011. {name: 'auto', image: '32/task_empty', title: '自动节点'},
  2012. {name: 'counter-sign', image: '32/task_empty', title: '会签节点'}
  2013. ], '__gef_jbs_palette__');
  2014. }
  2015. });
  2016. Ext.ux.TwoCombo = Ext.extend(Ext.form.ComboBox, {
  2017. initComponent: function() {
  2018. this.readOnly = true;
  2019. this.displayField = 'text';
  2020. this.valueField = 'value';
  2021. this.triggerAction = 'all';
  2022. this.mode = 'local';
  2023. this.emptyText = 'Please Select...';
  2024. this.store = new Ext.data.SimpleStore({
  2025. fields: ['value', 'text']
  2026. });
  2027. this.store.loadData(this.data);
  2028. Ext.ux.TwoCombo.superclass.initComponent.call(this);
  2029. }
  2030. });
  2031. Ext.reg('twocombo', Ext.ux.TwoCombo);