all-workflow.js 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217
  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. ressubmit:model.pr_ressubmit,
  413. xml: xml,
  414. parentId:0
  415. }
  416. });
  417. }else{
  418. /*Ext.Msg.alert('提示','你未对流程做任何处理!');*/
  419. alert("请填写右边属性面板必填项!");
  420. }
  421. }else{
  422. Ext.Msg.alert('提示','请填写右边必填条款!');
  423. }
  424. }
  425. }, {
  426. text: '发布',
  427. iconCls: 'tb-deploy',
  428. id :'deploy',
  429. deployProcess:function(caller,counter){
  430. var me = this;
  431. Ext.Ajax.request({ //判断对应Caller的流程是否存在表JProcessDeploy中,存在即发布成功,不存在则失败,需要先保存再发布 2013-3-5 17:26:19 wuwu
  432. method: 'post',
  433. params: {
  434. caller:caller,
  435. },
  436. url: basePath+'common/exitsJProcessDeploy.action',
  437. success: function(response) {
  438. try {
  439. var o = Ext.decode(response.responseText);
  440. if (o.result=== true) {
  441. var processDefId = o.processDefId;
  442. var version = processDefId.substring(processDefId.lastIndexOf("-")+1);
  443. Ext.Msg.alert('信息', '操作成功, 你的流程定义编号为:'+o.processDefId+" ,版本号为:"+version);
  444. } else if(o.result==false){
  445. /*Ext.Msg.alert('错误', o.errors.msg);*/
  446. Ext.Msg.alert('提示',"不存在该表单对应的流程 ,请先设计流程,保存后再发布!");
  447. return ;
  448. }
  449. } catch(e) {
  450. /*console.log(caller);*/
  451. Ext.Msg.alert('系统错误', response.responseText);
  452. }
  453. },
  454. failure: function(response) {
  455. /*console.log(caller);*/
  456. Ext.Msg.alert('系统错误', response.responseText);
  457. }
  458. });
  459. },
  460. handler: function() {
  461. var me = this;
  462. var counter = 0;
  463. var win = new Ext.Window({
  464. title: '请填写流程对应的表单名称',
  465. layout: 'fit',
  466. height: 95,
  467. width: 300,
  468. closeAction: 'hide',
  469. modal: true,
  470. items:[{
  471. xtype:'textfield',
  472. id :'caller'
  473. }],
  474. buttonAlign:'center',
  475. buttons: [{
  476. text:'确定发布',
  477. handler:function(){
  478. var value = Ext.getCmp("caller").getValue();
  479. if(value==null||value==''){
  480. alert("请先填写表单名称");
  481. return ;
  482. }
  483. else{
  484. if(counter == 0){
  485. me.deployProcess(value,counter);
  486. counter = counter +1;
  487. }
  488. else{
  489. alert("请勿重复操作!");
  490. counter =0; //本行存在逻辑问题,应该删除 2013-3-5 17:32:38 wuw
  491. }
  492. }
  493. }
  494. }]
  495. });
  496. win.show();
  497. }
  498. }, {
  499. text: '清空',
  500. iconCls: 'tb-clear',
  501. handler: function() {
  502. Gef.activeEditor.clear();
  503. }
  504. }, {
  505. text: '撤销',
  506. iconCls: 'tb-undo',
  507. handler: function() {
  508. var viewer = Gef.activeEditor.getGraphicalViewer();
  509. var browserListener = viewer.getBrowserListener();
  510. var selectionManager = browserListener.getSelectionManager();
  511. selectionManager.clearAll();
  512. var commandStack = viewer.getEditDomain().getCommandStack();
  513. commandStack.undo();
  514. },
  515. scope: this
  516. }, {
  517. text: '重做',
  518. iconCls: 'tb-redo',
  519. handler: function() {
  520. var viewer = Gef.activeEditor.getGraphicalViewer();
  521. var model=viewer.getContents().getModel();
  522. var browserListener = viewer.getBrowserListener();
  523. var selectionManager = browserListener.getSelectionManager();
  524. selectionManager.selectIn((model.children)[2]);
  525. // selectionManager.clearAll();
  526. // var commandStack = viewer.getEditDomain().getCommandStack();
  527. // commandStack.redo();
  528. },
  529. scope: this
  530. }, {
  531. text: '布局',
  532. iconCls: 'tb-activity',
  533. handler: function() {
  534. var viewer = Gef.activeEditor.getGraphicalViewer();
  535. var browserListener = viewer.getBrowserListener();
  536. var selectionManager = browserListener.getSelectionManager();
  537. selectionManager.clearAll();
  538. new Layout(Gef.activeEditor).doLayout();
  539. },
  540. scope: this
  541. }, {
  542. text: '删除',
  543. iconCls: 'tb-delete',
  544. handler: this.removeSelected,
  545. scope: this
  546. }]);
  547. App.CanvasPanel.superclass.initComponent.call(this);
  548. },
  549. afterRender: function() {
  550. App.CanvasPanel.superclass.afterRender.call(this);
  551. var width = 3000;
  552. var height = 2500;
  553. Ext.DomHelper.append(this.body, [{
  554. id: '__gef_jbs__',
  555. tag: 'div',
  556. style: 'width:' + (width + 10) + 'px;height:' + (height + 10) + 'px;',
  557. children: [{
  558. id: '__gef_jbs_center__',
  559. tag: 'div',
  560. style: 'width:' + width + 'px;height:' + height + 'px;float:left;'
  561. }, {
  562. id: '__gef_jbs_right__',
  563. tag: 'div',
  564. style: 'width:10px;height:' + height + 'px;float:left;background-color:#EEEEEE;cursor:pointer;'
  565. }, {
  566. id: '__gef_jbs_bottom__',
  567. tag: 'div',
  568. style: 'width:' + (width + 10) + 'px;height:10px;float:left;background-color:#EEEEEE;cursor:pointer;'
  569. }]
  570. }]);
  571. var rightEl = Ext.fly('__gef_jbs_right__');
  572. rightEl.on('mouseover', function(e) {
  573. var t = e.getTarget();
  574. t.style.backgroundColor = 'yellow';
  575. t.style.backgroundImage = 'url(images/arrow/arrow-right.png)';
  576. });
  577. rightEl.on('mouseout', function(e) {
  578. var t = e.getTarget();
  579. t.style.backgroundColor = '#EEEEEE';
  580. t.style.backgroundImage = '';
  581. });
  582. rightEl.on('click', function(e) {
  583. Ext.fly('__gef_jbs__').setWidth(Ext.fly('__gef_jbs__').getWidth() + 100);
  584. Ext.fly('__gef_jbs_center__').setWidth(Ext.fly('__gef_jbs_center__').getWidth() + 100);
  585. Ext.fly('__gef_jbs_bottom__').setWidth(Ext.fly('__gef_jbs_bottom__').getWidth() + 100);
  586. Gef.activeEditor.addWidth(100);
  587. });
  588. var bottomEl = Ext.fly('__gef_jbs_bottom__');
  589. bottomEl.on('mouseover', function(e) {
  590. var t = e.getTarget();
  591. t.style.backgroundColor = 'yellow';
  592. t.style.backgroundImage = 'url(images/arrow/arrow-bottom.png)';
  593. });
  594. bottomEl.on('mouseout', function(e) {
  595. var t = e.getTarget();
  596. t.style.backgroundColor = '#EEEEEE';
  597. t.style.backgroundImage = '';
  598. });
  599. rightEl.on('click', function(e) {
  600. Ext.fly('__gef_jbs__').setHeight(Ext.fly('__gef_jbs__').getHeight() + 100);
  601. Ext.fly('__gef_jbs_center__').setHeight(Ext.fly('__gef_jbs_center__').getHeight() + 100);
  602. Ext.fly('__gef_jbs_right__').setHeight(Ext.fly('__gef_jbs_right__').getHeight() + 100);
  603. Gef.activeEditor.addHeight(100);
  604. });
  605. // this.body.on('contextmenu', this.onContextMenu, this);//取消面板上 右键 操作 2012-08-24
  606. },
  607. onContextMenu: function(e) { //面板上右键操作。。。上面已经被注释,现在没用 2013-3-6 10:30:53 wuw
  608. if (!this.contextMenu) {
  609. this.contextMenu = new Ext.menu.Menu({
  610. items: [{
  611. text: '详细配置',
  612. iconCls: 'tb-prop',
  613. handler: this.showWindow,
  614. scope: this
  615. }, {
  616. text: '删除',
  617. iconCls: 'tb-remove',
  618. handler: this.removeSelected,
  619. scope: this
  620. }]
  621. });
  622. }
  623. e.preventDefault();
  624. this.contextMenu.showAt(e.getXY());
  625. },
  626. showWindow: function() { //详细配置窗口 2013-3-6 10:31:38 wuw
  627. App.propertyManager.changePropertyStatus('max');
  628. },
  629. deleteProcess:function(){
  630. var id=Ext.getCmp('jd_id').getValue();
  631. if(id){
  632. Ext.Ajax.request({
  633. url : basePath + '',
  634. params: {
  635. id:id
  636. },
  637. method : 'post',
  638. callback : function(options,success,response){
  639. me.getActiveTab().setLoading(false);
  640. var localJson = new Ext.decode(response.responseText);
  641. if(localJson.exceptionInfo){
  642. showError(localJson.exceptionInfo);
  643. }
  644. if(localJson.success){
  645. //resAudit成功后刷新页面进入可编辑的页面
  646. resAuditSuccess();
  647. window.location.reload();
  648. }
  649. }
  650. });
  651. }
  652. },
  653. removeSelected: function() {
  654. //取消选中
  655. var viewer = Gef.activeEditor.getGraphicalViewer();
  656. var browserListener = viewer.getBrowserListener();
  657. var selectionManager = browserListener.getSelectionManager();
  658. var edge = selectionManager.selectedConnection;
  659. var nodes = selectionManager.items;
  660. //console.log(edge);
  661. //console.log(nodes);
  662. var request = {};
  663. if (edge != null) {
  664. request.role = {
  665. name: 'REMOVE_EDGE'
  666. };
  667. this.executeCommand(edge, request);
  668. selectionManager.removeSelectedConnection();
  669. } else if (nodes.length > 0) {
  670. request.role = {
  671. name: 'REMOVE_NODES',
  672. nodes: nodes
  673. };
  674. this.executeCommand(viewer.getContents(), request);
  675. selectionManager.clearAll();
  676. }
  677. },
  678. executeCommand: function(editPart, request) {
  679. var command = editPart.getCommand(request);
  680. // console.log(command); 他妈的,问题就出现在这一行,当一个task 节点 有两个节点时,上一行代码就有问题啊 啊啊啊啊啊啊啊啊啊啊啊啊,哈哈哈
  681. if (command != null) {
  682. Gef.activeEditor.getGraphicalViewer().getEditDomain().getCommandStack().execute(command);
  683. }
  684. }
  685. });
  686. /*
  687. * Compressed by JSA(www.xidea.org)
  688. */
  689. Layout = function(editor) {
  690. this.editor = editor;
  691. this.processEditPart = editor.getGraphicalViewer().getContents();
  692. this.processModel = this.processEditPart.getModel();
  693. };
  694. Layout.prototype = {
  695. doLayout: function() {
  696. var diagram = new Diagram();
  697. diagram.init(this.processModel);
  698. var sorter = new TopologicalSorter(diagram);
  699. var sortedElements = sorter.getSortedElements();
  700. var sortedIds = [];
  701. for (var i = 0; i < sortedElements.length; i++) {
  702. sortedIds.push(sortedElements[i].id);
  703. }
  704. //console.info(sortedIds);
  705. var layouter = new LeftToRightGridLayouter(diagram, sortedIds);
  706. layouter.doLayout();
  707. var edgeMap = diagram.getEdgeMap();
  708. for (var edgeId in edgeMap) {
  709. var edge = edgeMap[edgeId];
  710. new EdgeLayouter(layouter.grid, edge);
  711. }
  712. diagram.updateModel();
  713. }
  714. };
  715. ;
  716. Diagram = function() {
  717. };
  718. Diagram.prototype = {
  719. getNodeMap: function() {
  720. return this.nodeMap;
  721. },
  722. getEdgeMap: function() {
  723. return this.edgeMap;
  724. },
  725. init: function(process) {
  726. this.process = process;
  727. this.nodeMap = {};
  728. this.edgeMap = {};
  729. for (var i = 0; i < this.process.children.length; i++) {
  730. var child = process.children[i];
  731. var node = new Node();
  732. node.id = child.text;
  733. node.type = child.type;
  734. node.x = child.x;
  735. node.y = child.y;
  736. node.w = child.w;
  737. node.h = child.h;
  738. this.nodeMap[node.id] = node;
  739. }
  740. for (var i = 0; i < this.process.children.length; i++) {
  741. var child = process.children[i];
  742. for (var j = 0; j < child.getOutgoingConnections().length; j++) {
  743. var connection = child.getOutgoingConnections()[j];
  744. this.createEdge(connection);
  745. }
  746. }
  747. },
  748. createEdge: function(connection) {
  749. var connectionId = connection.getSource().text + '_' + connection.getTarget().text;
  750. var edge = this.edgeMap[connectionId];
  751. if (!edge) {
  752. edge = new Edge();
  753. edge.id = connectionId;
  754. edge.name = connection.text;
  755. edge.source = this.nodeMap[connection.getSource().text];
  756. edge.target = this.nodeMap[connection.getTarget().text];
  757. edge.source.outgoingLinks.push(edge);
  758. edge.target.incomingLinks.push(edge);
  759. this.edgeMap[connectionId] = edge;
  760. }
  761. },
  762. updateModel: function() {
  763. for (var nodeId in this.nodeMap) {
  764. var item = this.nodeMap[nodeId];
  765. var model = this.getModel(nodeId);
  766. model.x = item.x;
  767. model.y = item.y;
  768. model.getEditPart().getFigure().x = model.x;
  769. model.getEditPart().getFigure().y = model.y;
  770. for (var i = 0; i < item.outgoingLinks.length; i++) {
  771. var connection = item.outgoingLinks[i];
  772. var connectionModel = this.getConnectionModel(model, connection);
  773. if (connectionModel == null) {
  774. continue;
  775. }
  776. connectionModel.innerPoints = typeof connection.innerPoints == 'undefined' ? []
  777. : connection.innerPoints;
  778. connectionModel.textX = 0;
  779. connectionModel.textY = 0;
  780. connectionModel.getEditPart().getFigure().innerPoints = connectionModel.innerPoints;
  781. connectionModel.getEditPart().getFigure().textX = connectionModel.textX;
  782. connectionModel.getEditPart().getFigure().textY = connectionModel.textY;
  783. }
  784. }
  785. this.process.getEditPart().refresh();
  786. },
  787. getModel: function(name) {
  788. var model = null;
  789. Gef.each(this.process.children, function(item) {
  790. if (item.text == name) {
  791. model = item;
  792. return false;
  793. }
  794. });
  795. return model;
  796. },
  797. getConnectionModel: function(nodeModel, edge) {
  798. var model = null;
  799. Gef.each(nodeModel.getOutgoingConnections(), function(item) {
  800. if (item.getTarget().text == edge.getTarget().id) {
  801. model = item;
  802. return false;
  803. }
  804. });
  805. return model;
  806. }
  807. };
  808. ;
  809. // should be change name to LayoutingElement
  810. Node = function() {
  811. this.incomingLinks = [];
  812. this.outgoingLinks = [];
  813. };
  814. Node.prototype = {
  815. getIncomingLinks: function() {
  816. return this.incomingLinks;
  817. },
  818. getOutgoingLinks: function() {
  819. return this.outgoingLinks;
  820. },
  821. getPrecedingElements: function() {
  822. var previousElements = [];
  823. for (var i = 0; i < this.incomingLinks.length; i++) {
  824. previousElements.push(this.incomingLinks[i].source);
  825. }
  826. return previousElements;
  827. },
  828. getFollowingElements: function() {
  829. var followingElements = [];
  830. for (var i = 0; i < this.outgoingLinks.length; i++) {
  831. followingElements.push(this.outgoingLinks[i].target);
  832. }
  833. return followingElements;
  834. },
  835. isJoin: function() {
  836. return this.incomingLinks.length > 1;
  837. },
  838. isSplit: function() {
  839. return this.outgoingLinks.length > 1;
  840. },
  841. prevSplit: function() {
  842. var distance = 1000;
  843. var candidateDistance = 0;
  844. var split = null;
  845. var candidate = null;
  846. var precedingElements = this.getPrecedingElements();
  847. for (var i = 0; i < precedingElements.length; i++) {
  848. var elem = precedingElements[i];
  849. if (elem.isSplit()) {
  850. return elem;
  851. }
  852. candidate = elem.prevSplit();
  853. if (this.isJoin()) {
  854. // if this is not a join, we have only one precedingElement.
  855. candidateDistance = elem.backwardDistanceTo(candidate);
  856. }
  857. if (candidateDistance < distance) {
  858. split = candidate;
  859. distance = candidateDistance;
  860. }
  861. }
  862. return split;
  863. },
  864. backwardDistanceTo: function(other) {
  865. return this._backwardDistanceTo(other, []);
  866. },
  867. _backwardDistanceTo: function(other, historyElements) {
  868. if (other == this) {
  869. return 0;
  870. }
  871. if (historyElements.indexOf(this) != -1) {
  872. return 1000;
  873. }
  874. var d = 1000;
  875. var newHistory = [];
  876. newHistory.push(this);
  877. var precedingElements = this.getPrecedingElements();
  878. for (var i = 0; i < precedingElements.length; i++) {
  879. var el = precedingElements[i];
  880. d = Math.min(d, el._backwardDistanceTo(other, newHistory));
  881. }
  882. return d == 1000 ? d : d + 1;
  883. }
  884. };
  885. ;
  886. Edge = function() {
  887. this.source = null;
  888. this.target = null;
  889. };
  890. Edge.prototype = {
  891. getSource: function() {
  892. return this.source;
  893. },
  894. getTarget: function() {
  895. return this.target;
  896. },
  897. reverseOutgoingAndIncoming: function() {
  898. var index = 0;
  899. var oldSource = this.source;
  900. var oldTarget = this.target;
  901. index = oldSource.outgoingLinks.indexOf(this);
  902. oldSource.outgoingLinks.splice(index, 1);
  903. index = oldTarget.incomingLinks.indexOf(this);
  904. oldTarget.incomingLinks.splice(index, 1);
  905. var newSource = oldTarget;
  906. var newTarget = oldSource;
  907. newSource.outgoingLinks.push(this);
  908. newTarget.incomingLinks.push(this);
  909. this.source = newSource;
  910. this.target = newTarget;
  911. }
  912. };
  913. ;
  914. TopologicalSorter = function(diagram) {
  915. this.diagram = diagram;
  916. this.prepareDataAndSort(true);
  917. this.prepareDataAndSort(false);
  918. };
  919. TopologicalSorter.prototype = {
  920. getSortedElements: function() {
  921. return this.sortedElements;
  922. },
  923. prepareDataAndSort: function(shouldBackpatch) {
  924. this.sortedElements = [];
  925. this.elementsToSort = {};
  926. this.backwardsEdges = [];
  927. this.elementsToSortCount = 0;
  928. this.addAllChildren();
  929. this.topologicalSort();
  930. if (shouldBackpatch === true) {
  931. this.backpatchBackwardsEdges();
  932. }
  933. this.reverseBackwardsEdges();
  934. },
  935. addAllChildren: function() {
  936. for (var nodeId in this.diagram.nodeMap) {
  937. var node = this.diagram.nodeMap[nodeId];
  938. this.elementsToSort[nodeId] = new SortableLayoutingElement(node);
  939. this.elementsToSortCount++;
  940. }
  941. },
  942. topologicalSort: function() {
  943. var count = 0;
  944. var oldCount = 0;
  945. while (this.elementsToSortCount > 0) {
  946. var freeElements = this.getFreeElements();
  947. if (freeElements.length > 0) {
  948. for (var i = 0; i < freeElements.length; i++) {
  949. var freeElement = freeElements[i];
  950. this.sortedElements.push(freeElement.node);
  951. this.freeElementsFrom(freeElement);
  952. delete this.elementsToSort[freeElement.node.id];
  953. }
  954. } else {
  955. var entry = this.getLoopEntryPoint();
  956. for (var i = 0; i < entry.incomingLinks.length; i++) {
  957. var backId = entry.incomingLinks[i];
  958. entry.reverseIncomingLinkFrom(backId);
  959. var elem = this.elementsToSort[backId];
  960. elem.reverseOutgoingLinkTo(entry.node.id);
  961. this.backwardsEdges.push(new BackwardsEdge(backId, entry.node.id));
  962. }
  963. }
  964. }
  965. },
  966. backpatchBackwardsEdges: function() {
  967. var newBackwardsEdges = [];
  968. for (var i = 0; i < this.backwardsEdges.length; i++) {
  969. newBackwardsEdges.push(this.backwardsEdges[i]);
  970. }
  971. for (var i = 0; i < this.backwardsEdges.length; i++) {
  972. var edge = this.backwardsEdges[i];
  973. var sourceId = edge.getSource();
  974. var targetId = edge.getTarget();
  975. var sourceElement = this.diagram.nodeMap[sourceId];
  976. while (!(sourceElement.isJoin() || sourceElement.isSplit())) {
  977. var newSourceElement = sourceElement.getPrecedingElements()[0];
  978. targetId = newSourceElement.id;
  979. newBackwardsEdges.push(new BackwardsEdge(targetId, sourceId));
  980. sourceElement = newSourceElement;
  981. sourceId = targetId;
  982. }
  983. }
  984. this.backwardsEdges = newBackwardsEdges;
  985. },
  986. reverseBackwardsEdges: function() {
  987. var edgeMap = this.diagram.edgeMap;
  988. for (var i = 0; i < this.backwardsEdges.length; i++) {
  989. var backwardsEdge = this.backwardsEdges[i];
  990. var sourceId = backwardsEdge.getSource();
  991. var targetId = backwardsEdge.getTarget();
  992. var sourceElement = this.diagram.nodeMap[sourceId];
  993. var targetElement = this.diagram.nodeMap[targetId];
  994. var edge = this.getEdge(edgeMap, sourceElement, targetElement);
  995. backwardsEdge.setEdge(edge);
  996. if (edge) {
  997. // reverse edge outgoing and incoming
  998. edge.reverseOutgoingAndIncoming();
  999. }
  1000. }
  1001. },
  1002. getFreeElements: function() {
  1003. var freeElements = [];
  1004. for (var nodeId in this.elementsToSort) {
  1005. var elem = this.elementsToSort[nodeId];
  1006. if (elem.isFree()) {
  1007. freeElements.push(elem);
  1008. }
  1009. }
  1010. return freeElements;
  1011. },
  1012. freeElementsFrom: function(freeElement) {
  1013. for (var i = 0; i < freeElement.outgoingLinks.length; i++) {
  1014. var id = freeElement.outgoingLinks[i];
  1015. var targetElement = this.elementsToSort[id];
  1016. if (targetElement) {
  1017. targetElement.removeIncomingLinkFrom(freeElement.node.id);
  1018. }
  1019. }
  1020. this.elementsToSortCount--;
  1021. },
  1022. getLoopEntryPoint: function() {
  1023. for (var nodeId in this.elementsToSort) {
  1024. var candidate = this.elementsToSort[nodeId];
  1025. if (candidate.oldInCount > 1
  1026. && candidate.oldInCount > candidate.incomingLinks.length) {
  1027. return candidate;
  1028. }
  1029. }
  1030. throw new Error('Could not find a valid loop entry point');
  1031. },
  1032. getEdge: function(edgeMap, sourceElement, targetElement) {
  1033. for (var i = 0; i < sourceElement.outgoingLinks.length; i++) {
  1034. var edge = sourceElement.outgoingLinks[i];
  1035. if (edge.getTarget().id == targetElement.id) {
  1036. return edge;
  1037. }
  1038. }
  1039. return null;
  1040. }
  1041. };
  1042. ;
  1043. SortableLayoutingElement = function(node) {
  1044. this.node = node;
  1045. this.incomingLinks = [];
  1046. this.outgoingLinks = [];
  1047. for (var i = 0; i < node.incomingLinks.length; i++) {
  1048. this.incomingLinks.push(node.incomingLinks[i].source.id);
  1049. }
  1050. for (var i = 0; i < node.outgoingLinks.length; i++) {
  1051. this.outgoingLinks.push(node.outgoingLinks[i].target.id);
  1052. }
  1053. this.oldInCount = this.incomingLinks.length;
  1054. this.isJoin = node.isJoin();
  1055. };
  1056. SortableLayoutingElement.prototype = {
  1057. isFree: function() {
  1058. return this.incomingLinks.length == 0;
  1059. },
  1060. removeIncomingLinkFrom: function(sourceId) {
  1061. var index = this.incomingLinks.indexOf(sourceId);
  1062. this.incomingLinks.splice(index, 1);
  1063. },
  1064. reverseIncomingLinkFrom: function(id) {
  1065. this.removeIncomingLinkFrom(id);
  1066. this.outgoingLinks.push(id);
  1067. },
  1068. reverseOutgoingLinkTo: function(id) {
  1069. var index = this.outgoingLinks.indexOf(id);
  1070. this.outgoingLinks.splice(index, 1);
  1071. this.incomingLinks.push(id);
  1072. }
  1073. };
  1074. ;
  1075. BackwardsEdge = function(source, target) {
  1076. this.source = source;
  1077. this.target = target;
  1078. };
  1079. BackwardsEdge.prototype = {
  1080. getEdge: function() {
  1081. return this.edge;
  1082. },
  1083. setEdge: function(edge) {
  1084. this.edge = edge;
  1085. },
  1086. getSource: function() {
  1087. return this.source;
  1088. },
  1089. getTarget: function() {
  1090. return this.target;
  1091. }
  1092. };
  1093. ;
  1094. LeftToRightGridLayouter = function(diagram, sortedIds) {
  1095. this.diagram = diagram;
  1096. this.sortedIds = sortedIds;
  1097. };
  1098. LeftToRightGridLayouter.prototype = {
  1099. doLayout: function() {
  1100. this.grid = new Grid();
  1101. this.layoutElements();
  1102. this.calcGeometry(this.grid);
  1103. this.writeGeometry(this.grid);
  1104. this.diagram.updateModel();
  1105. },
  1106. layoutElements: function() {
  1107. for (var i = 0; i < this.sortedIds.length; i++) {
  1108. var sortedId = this.sortedIds[i];
  1109. var currentElement = this.diagram.nodeMap[sortedId];
  1110. var precedingElements = currentElement.getPrecedingElements();
  1111. var cellOfElement = this.placeElement(currentElement, precedingElements);
  1112. if (currentElement.isJoin() && precedingElements.length != 0) {
  1113. // there is an edge hitting us left, so lets forbid
  1114. // interleaving to use the left cell, if this is empty
  1115. cellOfElement.getPrevCell().setPackable(false);
  1116. }
  1117. if (currentElement.isSplit()) {
  1118. this.prelayoutSuccessors(currentElement, cellOfElement);
  1119. }
  1120. }
  1121. },
  1122. placeElement: function(currentElement, precedingElements) {
  1123. var newCell = null;
  1124. if (precedingElements.length == 0) {
  1125. this.grid.startCell.value = currentElement;
  1126. newCell = this.grid.startCell;
  1127. } else {
  1128. var leftCell = null;
  1129. var newCell = this.grid.getCellOfItem(currentElement);
  1130. if (currentElement.isJoin()) {
  1131. var splitFound = false;
  1132. var split = currentElement.prevSplit();
  1133. if (split != null) {
  1134. var splits = new PriorityQueue(currentElement);
  1135. splits.add(split);
  1136. for (var i = 0; i < precedingElements.length; i++) {
  1137. var elem = precedingElements[i];
  1138. split = elem.prevSplit();
  1139. if (split != null && !splits.contains(split)) {
  1140. splits.add(split);
  1141. //console.info(splits.items);
  1142. }
  1143. }
  1144. split = null;
  1145. // get split with most connections
  1146. var maxCon = 0;
  1147. for (var i = 0; i < splits.items.length; i++) {
  1148. var target = splits.items[i];
  1149. if (target == currentElement) {
  1150. continue;
  1151. }
  1152. // current connections
  1153. var curCon = 0;
  1154. for (var j = 0; j < precedingElements.length; j++) {
  1155. var elem = precedingElements[j];
  1156. if (elem.backwardDistanceTo(target) < 1000) {
  1157. curCon++;
  1158. }
  1159. }
  1160. if (curCon > maxCon) {
  1161. maxCon = curCon;
  1162. split = target;
  1163. }
  1164. }
  1165. splitFound = split != null;
  1166. }
  1167. // current cell position
  1168. var x = 0;
  1169. var yAcc = 0;
  1170. var yCnt = 0;
  1171. for (var i = 0; i < precedingElements.length; i++) {
  1172. var elem = precedingElements[i];
  1173. var tmp = this.grid.getCellOfItem(elem);
  1174. if (tmp == null) {
  1175. tmp = {
  1176. getColIndex: function() {
  1177. return 0;
  1178. }
  1179. };
  1180. } else {
  1181. yAcc += tmp.getRowIndex();
  1182. yCnt++;
  1183. }
  1184. x = Math.max(x, tmp.getColIndex());
  1185. }
  1186. // farthest to the right
  1187. if (splitFound) {
  1188. leftCell = this.grid.getCellOfItem(split).row.cells[x];
  1189. // set path to split unpackable
  1190. for (var c = leftCell; c.value != split; c = c.getPrevCell()) {
  1191. c.setPackable(false);
  1192. }
  1193. } else {
  1194. if (yCnt == 0) {
  1195. leftCell = this.grid.rows[0].above().cells[x];
  1196. } else {
  1197. leftCell = this.grid.rows[yAcc / yCnt].cells[x];
  1198. }
  1199. }
  1200. if (newCell != null && newCell.value == currentElement) {
  1201. newCell.value = null;
  1202. }
  1203. newCell = leftCell.after();
  1204. // set all incoming pathes unpackable
  1205. for (var i = 0; i < precedingElements.length; i++) {
  1206. var el = precedingElements[i];
  1207. var target = this.grid.getCellOfItem(el);
  1208. if (target == null) {
  1209. continue;
  1210. }
  1211. var start = target.row.cells[x + 1];
  1212. for (var c = start; c != target; c = c.getPrevCell()) {
  1213. c.setPackable(false);
  1214. }
  1215. }
  1216. } else if (newCell == null) {
  1217. // if not preLayouted
  1218. var preElem = precedingElements[0];
  1219. leftCell = this.grid.getCellOfItem(preElem);
  1220. newCell = leftCell.after();
  1221. }
  1222. if (newCell.isFilled() && newCell.value != currentElement) {
  1223. newCell.row.insertRowBeneath();
  1224. newCell = newCell.beneath();
  1225. }
  1226. newCell.value = currentElement;
  1227. newCell.getPrevCell().setPackable(false);
  1228. }
  1229. return newCell;
  1230. },
  1231. prelayoutSuccessors: function(currentElement, cellOfElement) {
  1232. var baseCell = cellOfElement.after();
  1233. var topCell = baseCell;
  1234. var followingElements = currentElement.getFollowingElements();
  1235. // heuristic for direct connection to join
  1236. var directJoin = null;
  1237. for (var i = 0; i < followingElements.length; i++) {
  1238. var possibleJoin = followingElements[i];
  1239. if (possibleJoin.isJoin()) {
  1240. directJoin = possibleJoin;
  1241. }
  1242. }
  1243. if (directJoin != null) {
  1244. // put in the middle
  1245. var index = followingElements.indexOf(directJoin);
  1246. // remove
  1247. followingElements.splice(index, 1);
  1248. var position = parseInt(followingElements.length / 2, 10);
  1249. // insert
  1250. followingElements.splice(position, 0, directJoin);
  1251. }
  1252. // normal preLayout following elements
  1253. var follow = parseInt(followingElements.length / 2, 10);
  1254. for (var i = 0; i < follow; i++) {
  1255. topCell.row.insertRowAbove();
  1256. baseCell.row.insertRowBeneath();
  1257. topCell = topCell.above();
  1258. }
  1259. for (var i = 0; i < followingElements.length; i++) {
  1260. var newElem = followingElements[i];
  1261. if (this.grid.getCellOfItem(newElem)) {
  1262. continue;
  1263. }
  1264. topCell.value = newElem;
  1265. topCell = topCell.beneath();
  1266. if (topCell == baseCell && followingElements.length % 2 == 0) {
  1267. topCell = topCell.beneath();
  1268. }
  1269. }
  1270. },
  1271. calcGeometry: function(grid) {
  1272. grid.pack();
  1273. var heightOfRow = [];
  1274. for (var i = 0; i < grid.rowCount; i++) {
  1275. heightOfRow.push(0);
  1276. }
  1277. var widthOfColumn = [];
  1278. for (var i = 0; i < grid.colCount; i++) {
  1279. widthOfColumn.push(0);
  1280. }
  1281. for (var i = 0; i < grid.rowCount; i++) {
  1282. var row = grid.rows[i];
  1283. for (var j = 0; j < grid.colCount; j++) {
  1284. var cell = row.cells[j];
  1285. if (cell.isFilled()) {
  1286. var elem = cell.value;
  1287. widthOfColumn[j] = Math.max(widthOfColumn[j], elem.w + 30);
  1288. heightOfRow[i] = Math.max(heightOfRow[i], elem.h + 30);
  1289. }
  1290. }
  1291. }
  1292. this.heightOfRow = heightOfRow;
  1293. this.widthOfColumn = widthOfColumn;
  1294. this.totalWidth = 0;
  1295. this.totalHeight = 0;
  1296. for (var i = 0; i < grid.colCount; i++) {
  1297. this.totalWidth += widthOfColumn[i];
  1298. }
  1299. for (var i = 0; i < grid.rowCount; i++) {
  1300. this.totalHeight += heightOfRow[i];
  1301. }
  1302. },
  1303. writeGeometry: function(grid) {
  1304. var x = 0;
  1305. var y = 0;
  1306. for (var i = 0; i < grid.rowCount; i++) {
  1307. var row = grid.rows[i];
  1308. var cellHeight = this.heightOfRow[i];
  1309. for (var j = 0; j < grid.colCount; j++) {
  1310. var cell = row.cells[j];
  1311. var cellWidth = this.widthOfColumn[j];
  1312. if (cell.isFilled()) {
  1313. var elem = cell.value;
  1314. var newX = x + cellWidth / 2 - elem.w / 2;
  1315. var newY = y + cellHeight / 2 - elem.h / 2;
  1316. elem.x = newX;
  1317. elem.y = newY;
  1318. }
  1319. x += cellWidth;
  1320. }
  1321. x = 0;
  1322. y += cellHeight;
  1323. }
  1324. }
  1325. };
  1326. ;
  1327. Grid = function() {
  1328. var cell = new Cell();
  1329. var row = new Row();
  1330. row.grid = this;
  1331. row.addCell(cell);
  1332. this.rows = [row];
  1333. this.startCell = cell;
  1334. this.colCount = 1;
  1335. this.rowCount = this.rows.length;
  1336. };
  1337. Grid.prototype = {
  1338. addFirstRow: function() {
  1339. var row = new Row();
  1340. row.grid = this;
  1341. for (var i = 0; i < this.rolCount; i++) {
  1342. var cell = new Cell();
  1343. row.addCell(cell);
  1344. }
  1345. this.rows.unshift(row);
  1346. this.rowCount = this.rows.length;
  1347. },
  1348. addLastRow: function() {
  1349. var row = new Row();
  1350. row.grid = this;
  1351. for (var i = 0; i < this.rolCount; i++) {
  1352. row.addCell(new Cell());
  1353. }
  1354. this.rows.push(row);
  1355. this.rowCount = this.rows.length;
  1356. },
  1357. addLastCol: function() {
  1358. for (var i = 0; i < this.rowCount; i++) {
  1359. var row = this.rows[i];
  1360. row.addCell(new Cell());
  1361. }
  1362. this.colCount++;
  1363. },
  1364. getCellOfItem: function(elem) {
  1365. for (var i = 0; i < this.rowCount; i++) {
  1366. var row = this.rows[i];
  1367. for (var j = 0; j < this.colCount; j++) {
  1368. var cell = row.cells[j];
  1369. if (cell.value == elem) {
  1370. return cell;
  1371. }
  1372. }
  1373. }
  1374. return null;
  1375. },
  1376. pack: function() {
  1377. var changed = false;
  1378. do {
  1379. changed = false;
  1380. for (var i = 0; i < this.rows.length; i++) {
  1381. var row = this.rows[i];
  1382. changed |= row.tryInterleaveWith(row.getPrevRow());
  1383. }
  1384. for (var i = 0; i < this.rows.length; i++) {
  1385. var row = this.rows[i];
  1386. changed |= row.tryInterleaveWith(row.getNextRow());
  1387. }
  1388. } while (changed);
  1389. },
  1390. info: function() {
  1391. var value = '';
  1392. for (var i = 0; i < this.rows.length; i++) {
  1393. var row = this.rows[i];
  1394. for (var j = 0; j < row.cells.length; j++) {
  1395. var cell = row.cells[j];
  1396. var id = '[ ]';
  1397. if (cell.isFilled()) {
  1398. id = cell.value.id;
  1399. } else if (cell.packable === false) {
  1400. id = '[ p ]';
  1401. }
  1402. value += id;
  1403. }
  1404. value += '\n'
  1405. }
  1406. return value;
  1407. }
  1408. };
  1409. ;
  1410. Cell = function() {
  1411. this.packable = true;
  1412. };
  1413. Cell.prototype = {
  1414. isFilled: function() {
  1415. return typeof this.value != 'undefined' && this.value != null;
  1416. },
  1417. isUnpackable: function() {
  1418. return this.isFilled() || (this.packable === false);
  1419. },
  1420. setPackable: function(packable) {
  1421. this.packable = packable;
  1422. },
  1423. getRowIndex: function() {
  1424. return this.row.getIndex();
  1425. },
  1426. getColIndex: function() {
  1427. for (var i = 0; i < this.row.cells.length; i++) {
  1428. if (this.row.cells[i] == this) {
  1429. return i;
  1430. }
  1431. }
  1432. },
  1433. after: function() {
  1434. var colIndex = this.getColIndex();
  1435. if (colIndex == this.row.cells.length - 1) {
  1436. this.grid.addLastCol();
  1437. }
  1438. return this.row.cells[colIndex + 1];
  1439. },
  1440. above: function() {
  1441. var rowIndex = this.getRowIndex();
  1442. var colIndex = this.getColIndex();
  1443. if (rowIndex == 0) {
  1444. this.row.insertRowAbove();
  1445. }
  1446. return this.grid.rows[rowIndex - 1].cells[colIndex];
  1447. },
  1448. beneath: function() {
  1449. var rowIndex = this.getRowIndex();
  1450. var colIndex = this.getColIndex();
  1451. if (rowIndex == this.grid.rowCount - 1) {
  1452. this.row.insertRowBeneath();
  1453. }
  1454. return this.grid.rows[rowIndex + 1].cells[colIndex];
  1455. },
  1456. getPrevCell: function() {
  1457. var index = this.getColIndex();
  1458. return this.row.cells[index - 1];
  1459. },
  1460. getNextCell: function() {
  1461. var index = this.getColIndex();
  1462. return this.row.cells[index + 1];
  1463. }
  1464. };
  1465. ;
  1466. Row = function() {
  1467. this.cells = [];
  1468. };
  1469. Row.prototype = {
  1470. addCell: function(cell) {
  1471. cell.row = this;
  1472. cell.grid = this.grid;
  1473. this.cells.push(cell);
  1474. },
  1475. getIndex: function() {
  1476. for (var i = 0; i < this.grid.rows.length; i++) {
  1477. if (this.grid.rows[i] == this) {
  1478. return i;
  1479. }
  1480. }
  1481. },
  1482. insertRowBeneath: function() {
  1483. var row = new Row();
  1484. row.grid = this.grid;
  1485. for (var i = 0; i < this.grid.colCount; i++) {
  1486. row.addCell(new Cell());
  1487. }
  1488. var rowIndex = this.getIndex();
  1489. var rows = this.grid.rows;
  1490. if (rowIndex == rows.length - 1) {
  1491. rows.push(row);
  1492. } else {
  1493. rows.splice(rowIndex + 1, 0, row);
  1494. }
  1495. this.grid.rowCount = rows.length;
  1496. },
  1497. insertRowAbove: function() {
  1498. var row = new Row();
  1499. row.grid = this.grid;
  1500. for (var i = 0; i < this.grid.colCount; i++) {
  1501. row.addCell(new Cell());
  1502. }
  1503. var rowIndex = this.getIndex();
  1504. var rows = this.grid.rows;
  1505. if (rowIndex == 0) {
  1506. rows.unshift(row);
  1507. } else {
  1508. rows.splice(rowIndex, 0, row);
  1509. }
  1510. this.grid.rowCount = rows.length;
  1511. },
  1512. getPrevRow: function() {
  1513. var index = this.getIndex();
  1514. if (index > 0) {
  1515. return this.grid.rows[index - 1];
  1516. } else {
  1517. return null;
  1518. }
  1519. },
  1520. getNextRow: function() {
  1521. var index = this.getIndex();
  1522. if (index < this.grid.rows.length) {
  1523. return this.grid.rows[index + 1];
  1524. } else {
  1525. return null;
  1526. }
  1527. },
  1528. tryInterleaveWith: function(other) {
  1529. if (!this.isInterleaveWith(other)) {
  1530. return false;
  1531. }
  1532. for (var i = 0; i < this.cells.length; i++) {
  1533. var cell = this.cells[i];
  1534. var otherCell = other.cells[i];
  1535. if (cell.isFilled()) {
  1536. other.cells[i] = cell;
  1537. } else if (cell.isUnpackable()) {
  1538. otherCell.setPackable(false);
  1539. }
  1540. }
  1541. this._remove();
  1542. return true;
  1543. },
  1544. isInterleaveWith: function(other) {
  1545. if (other == null || other == this) {
  1546. return false;
  1547. } else if (other.getPrevRow() != this && other.getNextRow() != this) {
  1548. return false;
  1549. }
  1550. for (var i = 0; i < this.cells.length; i++) {
  1551. var cell = this.cells[i];
  1552. var otherCell = other.cells[i];
  1553. if (cell.isUnpackable() && otherCell.isUnpackable()) {
  1554. return false;
  1555. }
  1556. }
  1557. return true;
  1558. },
  1559. _remove: function() {
  1560. var index = this.getIndex();
  1561. this.grid.rows.splice(index, 1);
  1562. this.grid.rowCount--;
  1563. }
  1564. };
  1565. ;
  1566. PriorityQueue = function(center) {
  1567. this.ce = center;
  1568. this.items = [];
  1569. };
  1570. PriorityQueue.prototype = {
  1571. add: function(element) {
  1572. this.items.push(element);
  1573. var len = this.items.length;
  1574. for (var i = 0; i < len; i++) {
  1575. for (var j = i; j < len; j++) {
  1576. var elem1 = this.items[i];
  1577. var elem2 = this.items[j];
  1578. if (this.compareTo(elem1, elem2) > 0) {
  1579. this.items[i] = elem2;
  1580. this.items[j] = elem1;
  1581. }
  1582. }
  1583. }
  1584. },
  1585. compareTo: function(elem1, elem2) {
  1586. return this.ce.backwardDistanceTo(elem1) - this.ce.backwardDistanceTo(elem2);
  1587. },
  1588. contains: function(element) {
  1589. return this.items.indexOf(element) != -1;
  1590. }
  1591. };
  1592. ;
  1593. EdgeLayouter = function(grid, edge) {
  1594. this.grid = grid;
  1595. this.edge = edge;
  1596. edge.innerPoints = [];
  1597. this.calculateGlobals();
  1598. this.pickLayoutForEdge();
  1599. };
  1600. EdgeLayouter.prototype = {
  1601. calculateGlobals: function() {
  1602. this.source = this.edge.source;
  1603. this.target = this.edge.target;
  1604. this.sourceRelativeCenterX = this.source.w / 2;
  1605. this.sourceRelativeCenterY = this.source.h / 2;
  1606. this.targetRelativeCenterX = this.target.w / 2;
  1607. this.targetRelativeCenterY = this.target.h / 2;
  1608. this.sourceAbsoluteCenterX = this.source.x + this.sourceRelativeCenterX;
  1609. this.sourceAbsoluteCenterY = this.source.y + this.sourceRelativeCenterY;
  1610. this.targetAbsoluteCenterX = this.target.x + this.targetRelativeCenterX;
  1611. this.targetAbsoluteCenterY = this.target.y + this.targetRelativeCenterY;
  1612. this.sourceAbsoluteX = this.source.x;
  1613. this.sourceAbsoluteY = this.source.y;
  1614. this.sourceAbsoluteX2 = this.source.x + this.source.w;
  1615. this.sourceAbsoluteY2 = this.source.y + this.source.h;
  1616. this.targetAbsoluteX = this.target.x;
  1617. this.targetAbsoluteY = this.target.y;
  1618. this.targetAbsoluteX2 = this.target.x + this.target.w;
  1619. this.targetAbsoluteY2 = this.target.y + this.target.h;
  1620. this.sourceJoin = this.source.isJoin();
  1621. this.sourceSplit = this.source.isSplit();
  1622. this.targetJoin = this.target.isJoin();
  1623. this.targetSplit = this.target.isSplit();
  1624. this.backwards = this.sourceAbsoluteCenterX > this.targetAbsoluteCenterX;
  1625. },
  1626. pickLayoutForEdge: function() {
  1627. // sourceX == targetX, up and down
  1628. if (this.sourceAbsoluteCenterX == this.targetAbsoluteCenterX) {
  1629. this.setEdgeDirectCenter();
  1630. return;
  1631. } else if (this.sourceAbsoluteCenterY == this.targetAbsoluteCenterY) {
  1632. if (this.areCellsHorizontalFree()) {
  1633. this.setEdgeDirectCenter();
  1634. } else {
  1635. this.setEdgeAroundTheCorner(true);
  1636. }
  1637. return;
  1638. }
  1639. if (this.sourceAbsoluteCenterX <= this.targetAbsoluteCenterX
  1640. && this.sourceAbsoluteCenterY <= this.targetAbsoluteCenterY) {
  1641. // target is right under
  1642. if (this.sourcejoin && this.sourceSplit) {
  1643. this.setEdgeStepRight();
  1644. return;
  1645. } else if (this.sourceSplit) {
  1646. this.setEdge90DegreeRightUnderAntiClockwise();
  1647. return;
  1648. } else if (this.targetJoin) {
  1649. this.setEdge90DegreeRightUnderClockwise();
  1650. return;
  1651. }
  1652. } else if (this.sourceAbsoluteCenterX <= this.targetAbsoluteCenterX
  1653. && this.sourceAbsoluteCenterY > this.targetAbsoluteCenterY) {
  1654. // target is right above
  1655. if (this.sourcejoin && this.sourceSplit) {
  1656. this.setEdgeStepRight();
  1657. return;
  1658. } else if (this.sourceSplit) {
  1659. this.setEdge90DegreeRightAboveClockwise();
  1660. return;
  1661. } else if (this.targetJoin) {
  1662. this.setEdge90DegreeRightAboveAntiClockwise();
  1663. return;
  1664. }
  1665. }
  1666. if (this.sourceJoin && sourceSplit && (!this.backwards)) {
  1667. this.setEdgeStepRight();
  1668. return;
  1669. }
  1670. if (this.sourceJoin && sourceSplit) {
  1671. this.setEdgeAroundTheCorner(true);
  1672. return;
  1673. }
  1674. this.setEdgeDirectCenter();
  1675. },
  1676. areCellsHorizontalFree: function() {
  1677. var fromCell = null;
  1678. var toCell = null;
  1679. if (this.sourceAbsoluteCenterX < this.targetAbsoluteCenterX) {
  1680. fromCell = this.grid.getCellOfItem(this.source);
  1681. toCell = this.grid.getCellOfItem(this.target);
  1682. } else {
  1683. fromCell = this.grid.getCellOfItem(this.target);
  1684. toCell = this.grid.getCellOfItem(this.source);
  1685. }
  1686. fromCell = fromCell.getNextCell();
  1687. while (fromCell != toCell) {
  1688. if (fromCell == null || fromCell.isFilled()) {
  1689. return false;
  1690. }
  1691. fromCell = fromCell.getNextCell();
  1692. }
  1693. return true;
  1694. },
  1695. setEdgeDirectCenter: function() {
  1696. var boundsMinX = Math.min(this.sourceAbsoluteCenterX,
  1697. this.targetAbsoluteCenterX);
  1698. var boundsMinY = Math.min(this.sourceAbsoluteCenterY,
  1699. this.targetAbsoluteCenterY);
  1700. var boundsMaxX = Math.max(this.sourceAbsoluteCenterX,
  1701. this.targetAbsoluteCenterX);
  1702. var boundsMaxY = Math.max(this.sourceAbsoluteCenterY,
  1703. this.targetAbsoluteCenterY);
  1704. // this.edge.innerPoints = [];
  1705. },
  1706. setEdge90DegreeRightAboveClockwise: function() {
  1707. this.edge.innerPoints = [
  1708. [this.sourceAbsoluteCenterX, this.targetAbsoluteCenterY]
  1709. ];
  1710. },
  1711. setEdge90DegreeRightAboveAntiClockwise: function() {
  1712. this.edge.innerPoints = [
  1713. [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY]
  1714. ];
  1715. },
  1716. setEdge90DegreeRightUnderClockwise: function() {
  1717. this.edge.innerPoints = [
  1718. [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY]
  1719. ];
  1720. },
  1721. setEdge90DegreeRightUnderAntiClockwise: function() {
  1722. this.edge.innerPoints = [
  1723. [this.sourceAbsoluteCenterX, this.targetAbsoluteCenterY]
  1724. ];
  1725. },
  1726. setEdgeAroundTheCorner: function(down) {
  1727. var height = Math.max(this.source.h / 2, this.target.h / 2) + 20;
  1728. if (down) {
  1729. height *= -1;
  1730. }
  1731. this.edge.innerPoints = [
  1732. [this.sourceAbsoluteCenterX, this.sourceAbsoluteCenterY + height],
  1733. [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY + height]
  1734. ];
  1735. }
  1736. };
  1737. Ext.ux.OneCombo = Ext.extend(Ext.form.ComboBox, {
  1738. initComponent: function() {
  1739. this.readOnly = true;
  1740. this.displayField = 'text';
  1741. this.valueField = 'text';
  1742. this.triggerAction = 'all';
  1743. this.mode = 'local';
  1744. this.emptyText = 'Please Select...';
  1745. this.store = new Ext.data.SimpleStore({
  1746. expandData: true,
  1747. fields: ['text']
  1748. });
  1749. this.store.loadData(this.data);
  1750. Ext.ux.OneCombo.superclass.initComponent.call(this);
  1751. }
  1752. });
  1753. Ext.reg('onecombo', Ext.ux.OneCombo);
  1754. App.PalettePanel = Ext.extend(Ext.Panel, {
  1755. initComponent: function() {
  1756. this.region = 'west';
  1757. this.title = '活动环节';
  1758. this.iconCls = 'tb-activity';
  1759. this.width = 130;
  1760. this.initPalette();
  1761. App.PalettePanel.superclass.initComponent.call(this);
  1762. },
  1763. initPalette: function() {
  1764. var paletteType = null;
  1765. if (!Gef.PALETTE_TYPE) {
  1766. paletteType = 'accordion';
  1767. } else {
  1768. paletteType = Gef.PALETTE_TYPE;
  1769. }
  1770. this.configLayout(paletteType);
  1771. this.configItems(paletteType);
  1772. },
  1773. createHtml: function(array, divId) {
  1774. var imageRoot = Gef.IMAGE_ROOT.replace('48/', '');
  1775. if (divId) {
  1776. var html = '<div id="' + divId + '" unselectable="on">';
  1777. } else {
  1778. var html = '<div unselectable="on">';
  1779. }
  1780. for (var i = 0; i < array.length; i++) {
  1781. var item = array[i];
  1782. html += '<div id="' + item.name
  1783. + '" class="paletteItem-' + item.name
  1784. + '" style="text-align:center;font-size:12px;cursor:pointer;" unselectable="on"><img id="'
  1785. + item.name + '-img" class="paletteItem-' + item.name
  1786. + '" src="' + imageRoot + item.image + '.png" unselectable="on"><br>'
  1787. + item.title + '</div>';
  1788. }
  1789. html += '</div>';
  1790. return html;
  1791. },
  1792. /**
  1793. * this.layout = 'accordion';
  1794. */
  1795. configLayout: function(type) {
  1796. if (!type || type == 'plain') {
  1797. //
  1798. } else if (type && type == 'accordion') {
  1799. this.layout = 'accordion';
  1800. }
  1801. },
  1802. configItems: function(type) {
  1803. if (type && type == 'accordion') {
  1804. this.createItemsForAccordion();
  1805. } else if (!type || type == 'plain') {
  1806. this.createItemsForHtml();
  1807. }
  1808. },
  1809. createItemsForAccordion: function() {
  1810. this.id = '__gef_jbs_palette__';
  1811. this.items = [{
  1812. title: '所有活动',
  1813. iconCls: 'tb-activity',
  1814. autoScroll: true,
  1815. html: this.createHtml([
  1816. {name: 'select', image: 'select32', title: '选择'},
  1817. {name: 'transition', image: '32/flow_sequence', title: '连线'},
  1818. {name: 'start', image: '32/start_event_empty', title: '开始'},
  1819. {name: 'end', image: '32/end_event_terminate', title: '结束'},
  1820. {name: 'cancel', image: '32/end_event_cancel', title: '取消'},
  1821. {name: 'error', image: '32/end_event_error', title: '错误'},
  1822. // {name: 'human', image: '32/task_empty', title: '人工'},
  1823. {name: 'task', image: '32/task_empty', title: '任务'},
  1824. {name: 'decision', image: '32/gateway_exclusive', title: '决策'},
  1825. {name: 'sql', image: '32/task_sql', title: 'SQL'},
  1826. /* {name: 'auto', image: '32/task_empty', title: '自动'},*/
  1827. /* {name: 'counter-sign', image: '32/task_empty', title: '会签'},*/
  1828. {name: 'fork', image: '32/gateway_parallel', title: '并行'},
  1829. {name: 'join', image: '32/gateway_parallel', title: '汇聚'}
  1830. ])
  1831. }/*, {
  1832. title: '高级活动',
  1833. iconCls: 'tb-activity',
  1834. autoScroll: true,
  1835. html: this.createHtml([
  1836. {name: 'cancel', image: '32/end_event_cancel', title: '取消'},
  1837. {name: 'state', image: '32/task_wait', title: '等待'},
  1838. //{name: 'task', image: '32/task_empty', title: '任务'},
  1839. {name: 'human', image: '32/task_empty', title: '人工'},
  1840. {name: 'decision', image: '32/gateway_exclusive', title: '决策'},
  1841. {name: 'fork', image: '32/gateway_exclusive', title: '并行'},
  1842. {name: 'join', image: '32/gateway_parallel', title: '汇聚'},
  1843. {name: 'java', image: '32/task_java', title: 'JAVA'},
  1844. {name: 'script', image: '32/task_java', title: '脚本'},
  1845. {name: 'hql', image: '32/task_hql', title: 'HQL'},
  1846. {name: 'sql', image: '32/task_sql', title: 'SQL'},
  1847. {name: 'mail', image: '32/task_empty', title: '邮件'},
  1848. {name: 'custom', image: '32/task_empty', title: '自定义'},
  1849. {name: 'subProcess', image: '32/task_empty', title: '子流程'},
  1850. {name: 'jms', image: '32/task_empty', title: 'JMS'},
  1851. {name: 'ruleDecision', image: '32/gateway_exclusive', title: '规则决策'},
  1852. {name: 'rules', image: '32/task_empty', title: '规则'},
  1853. {name: 'foreach', image: '32/gateway_exclusive', title: '动态分支'}
  1854. ])
  1855. }*/];
  1856. },
  1857. createItemsForHtml: function() {
  1858. this.autoScroll = true;
  1859. this.html = this.createHtml([
  1860. {name: 'select', image: 'select32', title: '选择'},
  1861. {name: 'transition', image: '32/flow_sequence', title: '连线'},
  1862. {name: 'start', image: '32/start_event_empty', title: '开始'},
  1863. {name: 'end', image: '32/end_event_terminate', title: '结束'},
  1864. {name: 'cancel', image: '32/end_event_cancel', title: '取消'},
  1865. {name: 'error', image: '32/end_event_error', title: '错误'},
  1866. {name: 'state', image: '32/task_wait', title: '等待'},
  1867. {name: 'task', image: '32/task_empty', title: '任务'},
  1868. {name: 'decision', image: '32/gateway_exclusive', title: '决策'},
  1869. {name: 'fork', image: '32/gateway_parallel', title: '并行'},
  1870. {name: 'join', image: '32/gateway_parallel', title: '汇聚'},
  1871. {name: 'java', image: '32/task_java', title: 'JAVA'},
  1872. {name: 'script', image: '32/task_java', title: '脚本'},
  1873. {name: 'hql', image: '32/task_hql', title: 'HQL'},
  1874. {name: 'sql', image: '32/task_sql', title: 'SQL'},
  1875. {name: 'mail', image: '32/task_empty', title: '邮件'},
  1876. {name: 'custom', image: '32/task_empty', title: '自定义'},
  1877. {name: 'subProcess', image: '32/task_empty', title: '子流程'},
  1878. {name: 'jms', image: '32/task_empty', title: 'JMS'},
  1879. {name: 'ruleDecision', image: '32/gateway_exclusive', title: '规则决策'},
  1880. {name: 'rules', image: '32/task_empty', title: '规则'},
  1881. {name: 'human', image: '32/task_empty', title: '人工节点'},
  1882. {name: 'auto', image: '32/task_empty', title: '自动节点'},
  1883. {name: 'counter-sign', image: '32/task_empty', title: '会签节点'}
  1884. ], '__gef_jbs_palette__');
  1885. }
  1886. });
  1887. Ext.ux.TwoCombo = Ext.extend(Ext.form.ComboBox, {
  1888. initComponent: function() {
  1889. this.readOnly = true;
  1890. this.displayField = 'text';
  1891. this.valueField = 'value';
  1892. this.triggerAction = 'all';
  1893. this.mode = 'local';
  1894. this.emptyText = 'Please Select...';
  1895. this.store = new Ext.data.SimpleStore({
  1896. fields: ['value', 'text']
  1897. });
  1898. this.store.loadData(this.data);
  1899. Ext.ux.TwoCombo.superclass.initComponent.call(this);
  1900. }
  1901. });
  1902. Ext.reg('twocombo', Ext.ux.TwoCombo);