all-workflowscan.js 79 KB

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