all-workflow2.js 82 KB

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