all-workflow2.js 82 KB

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