all-workflowonlyeditor.js 66 KB

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