all-workflow.js 74 KB

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