123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331 |
- Ext.ns('App');
- App = {
- webforms: {},
- init: function() {
- Ext.QuickTips.init();
- this.propertyManager = new App.property.PropertyManager();
- this.workbenchWindow = new Gef.ui.support.DefaultWorkbenchWindow();
- var viewport = new Ext.Viewport({
- id:'viewport',
- layout: 'border',
- border: '0 0 0 0',
- bodyStyle: 'background:#f0f0f0;',
- frame:true,
- items: [
- this.createNorth(),
- this.createSouth(),
- // this.createWest(),
- this.createEast(),
- this.createCenter()
- ],
- listeners: {
- click: {
- element: 'el', //bind to the underlying el property on the panel
- fn: function(){ console.log('click el'); }
- },
- dblclick: {
- element: 'body', //bind to the underlying body property on the panel
- fn: function(){ console.log('dblclick body'); }
- }
- }
-
- });
- this.initEditor();
- setTimeout(function() {
- Ext.get('loading').remove();
- Ext.get('loading-mask').fadeOut({remove:true});
- }, 100);
- },
- initEditor: function() {
- var me = this;
- var jdId =getUrlParam('jdId');
- var nodeId=getUrlParam('nodeId');
- var type=getUrlParam('type');
- var caller=getUrlParam('caller');
- var xmlInfo = '';
- Ext.Ajax.request({
- url: basePath + 'common/getJProcessDeployInfo.action',
- params: {
- jdId: jdId,
- caller:caller
- },
- success: function(response){
- var text = new Ext.decode(response.responseText);
- xmlInfo = text.xmlInfo;
- var xml = xmlInfo;
- var editor = new Gef.jbs.ExtEditor();
- var input = new Gef.jbs.JBSEditorInput();
- input.readXml(xml);
- me.workbenchWindow.getActivePage().openEditor(editor, input);
- me.workbenchWindow.render();
- Gef.activeEditor = editor;
- var childrens=input.processModel.children;
- if(nodeId){
- var param=new Object();
- param.nodeId=nodeId;
- if(type&&type!=null){
- param.type=type;
- }
- Ext.Ajax.request({
- url:basePath+'common/getAllExecuteProcessInfo.action',
- params:param,
- method:'POST',
- callback:function(options,success,response){
- var localJson = new Ext.decode(response.responseText);
- if(localJson.success){
- var currentnode=localJson.currentNode;
- var nodes=localJson.nodes;
- var bool=true;
- for(var i=0;i<childrens.length;i++){
- var figure=childrens[i].editPart.figure;
- if(childrens[i].text==currentnode.jp_nodeName&¤tnode.jp_status=='待审批'){
- figure.rectEl.strok='red';
- figure.rectEl.strokwidth= 1;
- figure.rectEl.style.fill='red';
- figure.el.style.fill='#CDBE70';
- bool=false;
- me.propertyManager.selectSpecialNode(Gef.activeEditor,childrens[i].editPart);
- }
- for(var j=0;j<nodes.length;j++){
- if(nodes[j].jn_name==childrens[i].text){
- bool=false;
- //已处理的记录
- figure.rectEl.strok='#71C671';
- figure.rectEl.strokwidth=1;
- figure.rectEl.style.fill='#71C671';
- figure.el.style.fill='#9400D3';
- }
- }
- if(bool){
- if(figure.rectEl){
- figure.rectEl.strok='#CCCCCC';
- figure.rectEl.strokwidth=1;
- figure.rectEl.style.fill='#CCCCCC';
- }
- figure.el.style.fill='black';
- }
- }
-
- }else if(localJson.exceptionInfo){
- showError(localJson.exceptionInfo);
- }
- }
- });
- }else {
- var data = {};
- data.pr_defname = text.processDefName;
- data.pr_caller = text.caller;
- data.pr_enabled = text.enabled;
- data.pr_descn = text.processDescription;
- me.propertyManager.initSelectionListener2(Gef.activeEditor,data);
- }
-
- }
- });
- },
- getProcessModel: function() {
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var processEditPart = viewer.getContents();
- return processEditPart.model;
- },
- createNorth: function() {
- var p = null;
- if (Gef.MODE_DEMO === true) {
- p = new Ext.Panel({
- region: 'north'
- });
- } else {
- p = new Ext.Panel({
- region: 'north'
- });
- }
- App.northPanel = p;
- return p;
- },
- createSouth: function() {
- var p = this.propertyManager.getBottom();
- return p;
- },
- createWest: function() {
- var p = new App.PalettePanel({
- collapsible: true //修复bug 可以伸缩 zhouy
- });
- App.westPanel = p;
- return p;
- },
- createEast: function() {
- var p = this.propertyManager.getRight();
- return p;
- },
- createCenter: function() {
- var p = new App.CanvasPanel();
- App.centerPanel = p;
-
- return p;
- },
- getSelectionListener: function() {
- if (!this.selectionListener) {
- this.selectionListener = new Gef.jbs.ExtSelectionListener(null);
- }
- return this.selectionListener;
- }
- };
- /*
- Gef.override(App.PalettePanel, {
- configItems: function() {
- this.html = 'sdfasfdfdsa';
- }
- });
- */
- //Gef.PALETTE_TYPE = 'plain';
- Gef.PALETTE_TYPE = 'accordion';
- Ext.onReady(App.init, App);
- Gef.DEPLOY_URL = '../../console/d!deployJpdl.do';
- Gef.SAVE_URL = '../../console/d!saveJpdl.do';
- App.CanvasPanel = Ext.extend(Ext.Panel, {
- id:'canvaspanel',
- bodyStyle: 'background:#f0f0f0;',
- border: '0 0 0 0',
- xmlValidate:function(){
- var xmlString = arguments[0];
- var xmlDoc = null;
- try //IE 浏览器
- {
- xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.async="false";
- xmlDoc.loadXML(xmlString);
- }
- catch(e)
- {
- console.log(e.message);
- try //Firefox, Mozilla, 浏览器
- {
- parser=new DOMParser();
- xmlDoc=parser.parseFromString(xmlString,"text/xml");
- var tasks = xmlDoc.getElementsByTagName('task');
- for(var i=0;i<tasks.length;i++){ // 对任务节点的校验……
- var transitions = tasks[i].getElementsByTagName('transition');
- if(transitions.length!=2){
- Ext.Msg.alert("温馨提示","任务".fontcolor("Red").fontsize(5)+new String(tasks[i].getAttribute('name')).fontcolor("Red").fontsize(5)+"只能有"+"两".fontcolor("Red")+"条"+"流出".fontcolor("Red")+"连线");
- return false;
- }
- for(var j=0;j<transitions.length;j++){
- var name = transitions[j].getAttribute('name');
- console.log(name);
- if(name!='同意'&&name!='不同意'){
- Ext.Msg.alert("温馨提示","任务".fontcolor("Red").fontsize(5)+new String(tasks[i].getAttribute('name')).fontcolor("Red").fontsize(5)+" 的流出连线名称必须为“同意” 或 “不同意” !");
- return false;
-
- }
- }
- }
-
- var sqls = xmlDoc.getElementsByTagName('sql'); //对sql 节点的校验……
- for(var i=0;i<sqls.length;i++){
- var querys = sqls[i].getElementsByTagName('query');
- console.log(querys);
- if(querys.length<1){
- Ext.Msg.alert("温馨提示",new String(sqls[i].getAttribute('name')).fontcolor("Red").fontsize(5)+"节点的查询语句未设置!");
- return false;
- }
- for(var j=0;j<querys.length;j++){
- var sqlString = new String(querys[j].childNodes[0].nodeValue);
- console.log("sql节点的 sql查询语句"+sqlString);
- if(sqlString.indexOf("drop")>=0||sqlString.indexOf("insert")>=0||sqlString.indexOf('delete')>=0){
-
- Ext.Msg.alert("温馨提示",new String(sqls[i].getAttribute('name')).fontcolor("Red").fontsize(5)+"节点的查询语句中含有敏感字符 !");
- return false;
- }
- if(sqlString.indexOf("select")<0||sqlString.indexOf("from")<0){
- Ext.Msg.alert("温馨提示",new String(sqls[i].getAttribute('name')).fontcolor("Red").fontsize(5)+"节点的查询语句语法错误 !");
- return false;
- }
- }
- var transitions = sqls[i].getElementsByTagName('transition');
- if(transitions.length>1){
- Ext.Msg.alert("温馨提示",new String(sqls[i].getAttribute('name')).fontcolor("Red").fontsize(5)+" 节点不能有两条及以上的流出连线 !");
- return false;
- }
- }
-
- var decisions = xmlDoc.getElementsByTagName('decision'); //对 decision 节点的校验……
- console.log(decisions);
- for(var i=0;i<decisions.length;i++){
- var expr = decisions[i].getAttribute('expr');
- console.log(expr);
- if(!expr){
- transitions = decisions[i].getElementsByTagName('transition');
- for(var j=0;j<transitions.length;j++){
- conditions = transitions[j].getElementsByTagName('condition');
- if(conditions.length!=1){
- Ext.Msg.alert("温馨提示",new String(decisions[i].getAttribute('name')).fontcolor("Red").fontsize(5)+" 节点分支条件设置错误 !");
- return false;
- }else{
- var condition = transitions[j].getElementsByTagName('condition')[0];
- var exp = new String(condition.getAttribute("expr"));
- if(exp.indexOf("#{")<0){ // 校验……………………
- Ext.Msg.alert("温馨提示",new String(decisions[i].getAttribute('name')).fontcolor("Red").fontsize(5)+" 节点分支条件设置错误 !");
- return false;
- }
- }
- }
- }
- }
-
- return true;
- }
- catch(e) {alert(e.message); return false;}
- }
- },
- initComponent: function() {
- //this.on('bodyresize', function(p, w, h) {
- // var b = p.body.getBox();
- //});
-
- this.region = 'center';
- this.autoScroll = true;
- var mater=null;
- var contents=null;//行选择之后的xml
- var resetlength=null;//新建之后的xml的长度
- /**this.tbar = new Ext.Toolbar([{
- text: '新建',
- iconCls: 'tb-new',
- handler: function() {
- App.propertyManager.initSelectionListener(Gef.activeEditor);
- var model=Gef.activeEditor.getGraphicalViewer().getRootEditPart().getContents().getModel();
- if(model.dom.getAttribute('data')){
- model.dom.removeAttribute('data');
- }
- Ext.getCmp('FirstForm').getForm().reset();
- Gef.activeEditor.reset();
- resetlength=Gef.activeEditor.serial().length;
- contents=null;
-
- }
- }, {
- text: '导入',
- iconCls: 'tb-webform',
- handler: function() {
- var xml = Gef.activeEditor.serial();
- if (!this.openWin) {
- this.openWin = new Ext.Window({
- title: 'xml',
- layout: 'fit',
- width: 500,
- height: 300,
- closeAction: 'hide',
- modal: true,
- items: [{
- id: '__gef_jbpm4_xml_import__',
- xtype: 'textarea'
- }],
- buttons: [{
- text: '导入',
- handler: function() {
- var xml = Ext.getDom('__gef_jbpm4_xml_import__').value;
- Gef.activeEditor.resetAndOpen(xml);
- this.openWin.hide();
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var browserListener = viewer.getBrowserListener();
- var editor=Gef.activeEditor;
- var data=Ext.getCmp('FirstForm').getForm().getValues();
- App.propertyManager.initSelectionListener2(Gef.activeEditor,data);
- },
- scope: this
- }, {
- text: '取消',
- handler: function() {
- this.openWin.hide();
- },
- scope: this
- }]
- });
- this.openWin.on('show', function() {
- Gef.activeEditor.disable();
- });
- this.openWin.on('hide', function() {
- Gef.activeEditor.enable();
- });
- }
- this.openWin.show(null, function() {
- Ext.getDom('__gef_jbpm4_xml_import__').value = xml;
- });
- }
- }, {
- text: '导出',
- iconCls: 'tb-prop',
- handler: function() {
- var xml = Gef.activeEditor.serial();
- if (!this.openWin) {
- this.openWin = new Ext.Window({
- title: 'xml',
- layout: 'fit',
- width: 500,
- height: 300,
- closeAction: 'hide',
- modal: true,
- items: [{
- id: '__gef_jbpm4_xml_export__',
- xtype: 'textarea'
- }],
- buttons: [{
- text: '关闭',
- handler: function() {
- this.openWin.hide();
- },
- scope: this
- }]
- });
- this.openWin.on('show', function() {
- Gef.activeEditor.disable();
- });
- this.openWin.on('hide', function() {
- Gef.activeEditor.enable();
- });
- }
- this.openWin.show(null, function() {
- Ext.getDom('__gef_jbpm4_xml_export__').value = xml;
- /*document.getElementById('__gef_jbpm4_xml_export__').value=xml;
-
- });
- }
- }, {
- text: '保存',
- iconCls: 'tb-save',
- handler: function() {
- //重复保存的情况 form 1.修改。。。Ext.getCmp('FirstForm').getForm().isDirty()
- // 2.xml文件做了修改 了contents resetlength=44;
- var editor = Gef.activeEditor;
- var xml = editor.serial();
- var str='<?xml version="1.0" encoding="UTF-8"?>\n'+xml;
- var param=str.replace("data='[object Object]'","");
- //Ext.Msg.wait('正在校验。。。');
-
- var result =Ext.getCmp('canvaspanel').xmlValidate(xml);// 自定义校验
- console.log("校验结果 " +result);
- if(!result){
- console.log("xml 格式错误!");
- return ;
- }else{
- console.log("自定义 校验通过,可以正常保存 !");
- }
-
- var model=editor.getGraphicalViewer().getRootEditPart().getContents().getModel();
- //检验页面元素是否填写正确
- // alert(Ext.getCmp('FirstForm'));
- App.propertyManager.initSelectionListener(editor);//add 选中面板便于拿到form 不是最好的解决办法 2012-08-21
- var form=Ext.getCmp('FirstForm');
- // if(resetlength==44||contents!=param||contests=param&&form.getForm().isDirty()){
- var isValid = new Validation(editor).validate();//可以对空xml进行校验
- if (!isValid) {
- return false;
- }
- //对form进行校验
- if(form.getForm().isValid()){
- console.log(resetlength);
- if(!form.getForm().isDirty()){
- var r = form.getForm().getValues();
- if(r.pr_caller==null||r.pr_defname==null||r.pr_caller==''||r.pr_defname==''){
- Ext.Msg.alert("提示","请填写右边属性面板必填项!");
- return;
- }
- var xml2 ="";
- if(xml.indexOf('data=')!=-1){
-
- xml2 = xml.replace("data='[object Object]'","name='"+r.pr_defname+"'");
-
- }
- console.log(xml2);
- Ext.Msg.wait('正在保存...');
- Ext.Ajax.request({
- method: 'post',
- url: basePath+'common/deployProcess.action',
- success: function(response) {
- try {
- var o = Ext.decode(response.responseText);
- if (o.success === true) {
- Ext.Msg.alert('提示', '保存成功, 你的流程定义编号为:'+o.id);
- } else {
- Ext.Msg.alert('错误', o.errors.msg);
- }
- } catch(e) {
- Ext.Msg.alert('保存失败','请重试!' );
- }
- },
- failure: function(response) {
- Ext.Msg.alert('保存失败','请检查 xml文件格式!' );
- },
- params: {
- processDefinitionName: r.pr_defname,
- processDescription: r.pr_descn,
- caller:r.pr_caller,
- enabled:r.pr_enabled,
- xml: xml2,
- parentId:0
- }
- });
- }else{
- alert("请填写右边属性面板必填项!");
- }
- }else{
- Ext.Msg.alert('提示','请填写右边必填条款!');
- }
-
- }
- },{
- text:'查看',
- iconCls:'tb_find',
- handler:function(){
- resetlength=null;
- var editor = Gef.activeEditor;
- var model=editor.getGraphicalViewer().getRootEditPart().getContents().getModel();
- Ext.Ajax.request({//拿到grid的数据总数count
- url : basePath + 'common/datalistCount.action',
- params: {
- caller:'Process',
- condition: "1=1",
- },
- method : 'post',
- callback : function(options,success,response){
- var res = new Ext.decode(response.responseText);
- var dataCount = res.count;
- Ext.Ajax.request({//拿到tree数据
- url : basePath+'common/datalist.action',
- params: {
- caller: 'Process',
- condition: '1=1',
- page: 1,
- pageSize: 20
- },
- method:'post',
- callback : function(options,success,response){
- res = new Ext.decode(response.responseText);
- var data=(res.data).replace(/,}/g,"}");
- var store= new Ext.data.JsonStore({
- fields : res.fields,
- data:Ext.decode(data),
- autoLoad : true,
- });
- var grid = new Ext.grid.GridPanel({
- id:'grid',
- width:600,
- height:300,
- autoExpandColumn:true,
- stripeRows:true,
- border:true,
- title:'ERP流程列表',
- columns:res.columns,
- iconCls:'icon-grid',
- store: store,
- viewConfig: {
- forceFit: true
- },
- listeners:{
- 'rowclick':function(grid,row, e){
- var k=grid.getSelectionModel();
- Ext.getCmp('win').close();
- //Ext.getCmp('FirstForm').getForm().setValues(k.selections.items[0].data);
- //拿到Xml字符串 向后台传回一个id 在拿到contents
- var Id=k.selections.items[0].data.pr_id;
- Ext.Ajax.request({//拿到tree数据
- url : basePath+'common/process/getContentsById.action',
- params: {
- param:Id,
- },
- method:'post',
- callback : function(options,success,response){
- res = new Ext.decode(response.responseText);
- if(res.success){
- contents=res.contents;
-
- var editor = Gef.activeEditor;
- // var model=editor.getGraphicalViewer().getRootEditPart().getContents().getModel();
- Ext.getCmp('FirstForm').getForm().setValues(k.selections.items[0].data);
- Gef.activeEditor.resetAndOpen(res.contents);
- var data=Ext.getCmp('FirstForm').getForm().getValues();
- App.propertyManager.initSelectionListener2(editor,data);
-
- }else{
- Ext.Msg.alert('提示','操作失败!');
- }
- }
- });
-
- }
-
- },
- });
- var win = new Ext.Window({
- id :'win',
- title: '人事',
- layout: 'fit',
- height: 500,
- width: 600,
- closeAction: 'hide',
- modal: true,
- items: [grid],
- listeners:{
- 'beforehide':function(c){
- Gef.activeEditor.enable();
- },
- 'beforeshow':function(c){
- Gef.activeEditor.disable();
- }
-
- },
- });
- win.show();
-
- }
- });
- }
- });
- },
- scope:this,
-
- },{
- text: '发布',
- iconCls: 'tb-deploy',
- deployProcess:function(caller){
- Ext.Ajax.request({
- method: 'post',
- params: {
- caller:caller,
- },
- url: basePath+'common/exitsJProcessDeploy.action',
- success: function(response) {
- try {
- var o = Ext.decode(response.responseText);
- if (o.result=== true) {
- var processDefId = o.processDefId;
- var version = processDefId.substring(processDefId.lastIndexOf("-")+1);
- Ext.Msg.alert('信息', '操作成功, 你的流程定义编号为:'+o.processDefId+" ,版本号为:"+version);
- } else if(o.result==false){
- /*Ext.Msg.alert('错误', o.errors.msg);
- Ext.Msg.alert('提示',"不存在该表单对应的流程 ,请先设计流程,保存后再发布!");
- return ;
- }
- } catch(e) {
- /*console.log(caller);
- Ext.Msg.alert('系统错误', response.responseText);
- }
- },
- failure: function(response) {
- /*console.log(caller);
- Ext.Msg.alert('系统错误', response.responseText);
- }
-
- });
-
- },
- handler: function() {
- var me = this;
- var counter = 0;
- var win = new Ext.Window({
- title: '请填写流程对应的表单名称',
- layout: 'fit',
- height: 95,
- width: 300,
- closeAction: 'hide',
- modal: true,
- items:[{
- xtype:'textfield',
- id :'caller'
- }],
- buttonAlign:'center',
- buttons: [{
- text:'确定发布',
- handler:function(){
- var value = Ext.getCmp("caller").getValue();
- if(value==null||value==''){
- alert("请先填写表单名称");
- return ;
- }
- else{
- if(counter == 0){
- me.deployProcess(value);
- counter = counter+1;
- }
- else{
- Ext.Msg.alert("提示","你已经发布该流程,不能重复发布!");
- Ext.Msg.alert("提示","请勿重复操作!");
- counter = 0;
- }
-
- }
- }
- }]
-
-
- });
- win.show();
- }
- }, {
- text: '清空',
- iconCls: 'tb-clear',
- handler: function() {
- Gef.activeEditor.clear();
- }
- }, {
- text: '撤销',
- iconCls: 'tb-undo',
- handler: function() {
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var browserListener = viewer.getBrowserListener();
- var selectionManager = browserListener.getSelectionManager();
- selectionManager.clearAll();
- var commandStack = viewer.getEditDomain().getCommandStack();
- commandStack.undo();
- },
- scope: this
- }, {
- text: '重做',
- iconCls: 'tb-redo',
- handler: function() {
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var model=viewer.getContents().getModel();
- var browserListener = viewer.getBrowserListener();
- var selectionManager = browserListener.getSelectionManager();
- selectionManager.selectIn((model.children)[2]);
- // selectionManager.clearAll();
- // var commandStack = viewer.getEditDomain().getCommandStack();
- // commandStack.redo();
- },
- scope: this
- }, {
- text: '布局',
- iconCls: 'tb-activity',
- handler: function() {
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var browserListener = viewer.getBrowserListener();
- var selectionManager = browserListener.getSelectionManager();
- selectionManager.clearAll();
- new Layout(Gef.activeEditor).doLayout();
- },
- scope: this
- }, {
- text: '删除',
- iconCls: 'tb-delete',
- handler: this.removeSelected,
- scope: this
- },{
- text:'流程删除',
- iconCls: 'tb-delete',
- handler: this.deleteProcess,
- scope: this
- }]);**/
- App.CanvasPanel.superclass.initComponent.call(this);
- },
- afterRender: function() {
- App.CanvasPanel.superclass.afterRender.call(this);
- var width = 3000;
- var height = 2500;
- Ext.DomHelper.append(this.body, [{
- id: '__gef_jbs__',
- tag: 'div',
- style: 'width:' + (width + 10) + 'px;height:' + (height + 10) + 'px;',
- children: [{
- id: '__gef_jbs_center__',
- tag: 'div',
- style: 'width:' + width + 'px;height:' + height + 'px;float:left;'
- }, {
- id: '__gef_jbs_right__',
- tag: 'div',
- style: 'width:10px;height:' + height + 'px;float:left;background-color:#EEEEEE;cursor:pointer;'
- }, {
- id: '__gef_jbs_bottom__',
- tag: 'div',
- style: 'width:' + (width + 10) + 'px;height:10px;float:left;background-color:#EEEEEE;cursor:pointer;'
- }]
- }]);
- var rightEl = Ext.fly('__gef_jbs_right__');
- rightEl.on('mouseover', function(e) {
- var t = e.getTarget();
- t.style.backgroundColor = 'yellow';
- t.style.backgroundImage = 'url(images/arrow/arrow-right.png)';
- });
- rightEl.on('mouseout', function(e) {
- var t = e.getTarget();
- t.style.backgroundColor = '#EEEEEE';
- t.style.backgroundImage = '';
- });
- rightEl.on('click', function(e) {
- Ext.fly('__gef_jbs__').setWidth(Ext.fly('__gef_jbs__').getWidth() + 100);
- Ext.fly('__gef_jbs_center__').setWidth(Ext.fly('__gef_jbs_center__').getWidth() + 100);
- Ext.fly('__gef_jbs_bottom__').setWidth(Ext.fly('__gef_jbs_bottom__').getWidth() + 100);
- Gef.activeEditor.addWidth(100);
- });
- var bottomEl = Ext.fly('__gef_jbs_bottom__');
- bottomEl.on('mouseover', function(e) {
- var t = e.getTarget();
- t.style.backgroundColor = 'yellow';
- t.style.backgroundImage = 'url(images/arrow/arrow-bottom.png)';
- });
- bottomEl.on('mouseout', function(e) {
- var t = e.getTarget();
- t.style.backgroundColor = '#EEEEEE';
- t.style.backgroundImage = '';
- });
- rightEl.on('click', function(e) {
- Ext.fly('__gef_jbs__').setHeight(Ext.fly('__gef_jbs__').getHeight() + 100);
- Ext.fly('__gef_jbs_center__').setHeight(Ext.fly('__gef_jbs_center__').getHeight() + 100);
- Ext.fly('__gef_jbs_right__').setHeight(Ext.fly('__gef_jbs_right__').getHeight() + 100);
- Gef.activeEditor.addHeight(100);
- });
- // this.body.on('contextmenu', this.onContextMenu, this);//取消面板上 右键 操作 2012-08-24
- },
- onContextMenu: function(e) {
- if (!this.contextMenu) {
- this.contextMenu = new Ext.menu.Menu({
- items: [{
- text: '详细配置',
- iconCls: 'tb-prop',
- handler: this.showWindow,
- scope: this
- }, {
- text: '删除',
- iconCls: 'tb-remove',
- handler: this.removeSelected,
- scope: this
- }]
- });
- }
- e.preventDefault();
- this.contextMenu.showAt(e.getXY());
- },
- showWindow: function() {
- App.propertyManager.changePropertyStatus('max');
- },
- deleteProcess:function(){
- var id=parent.Ext.getCmp('jd_id').getValue();
- if(id){
- Ext.Ajax.request({
- url : basePath + 'common/deleteProcessDeploy.action',
- params: {
- id:id
- },
- method : 'post',
- callback : function(options,success,response){
- var localJson = new Ext.decode(response.responseText);
- if(localJson.exceptionInfo){
- showError(localJson.exceptionInfo);
- }
- if(localJson.success){
- Ext.Msg.alert('提示','删除成功!',function(){
- var main = parent.parent.Ext.getCmp("content-panel");
- main.getActiveTab().close();
- });
-
- }
- }
- });
- }
-
- },
- removeSelected: function() {
- //取消选中
- var viewer = Gef.activeEditor.getGraphicalViewer();
- var browserListener = viewer.getBrowserListener();
- var selectionManager = browserListener.getSelectionManager();
- var edge = selectionManager.selectedConnection;
- var nodes = selectionManager.items;
- var request = {};
-
- if (edge != null) {
- request.role = {
- name: 'REMOVE_EDGE'
- };
- this.executeCommand(edge, request);
- selectionManager.removeSelectedConnection();
- } if (nodes.length > 0) {
- request.role = {
- name: 'REMOVE_NODES',
- nodes: nodes
- };
- this.executeCommand(viewer.getContents(), request);
- selectionManager.clearAll();
- }
- },
- executeCommand: function(editPart, request) {
- var command = editPart.getCommand(request);
- if (command != null) {
- Gef.activeEditor.getGraphicalViewer().getEditDomain().getCommandStack().execute(command);
- }
- }
- });
- /*
- * Compressed by JSA(www.xidea.org)
- */
- Layout = function(editor) {
- this.editor = editor;
- this.processEditPart = editor.getGraphicalViewer().getContents();
- this.processModel = this.processEditPart.getModel();
- };
- Layout.prototype = {
- doLayout: function() {
- var diagram = new Diagram();
- diagram.init(this.processModel);
- var sorter = new TopologicalSorter(diagram);
- var sortedElements = sorter.getSortedElements();
- var sortedIds = [];
- for (var i = 0; i < sortedElements.length; i++) {
- sortedIds.push(sortedElements[i].id);
- }
- //console.info(sortedIds);
- var layouter = new LeftToRightGridLayouter(diagram, sortedIds);
- layouter.doLayout();
- var edgeMap = diagram.getEdgeMap();
- for (var edgeId in edgeMap) {
- var edge = edgeMap[edgeId];
- new EdgeLayouter(layouter.grid, edge);
- }
- diagram.updateModel();
- }
- };
- ;
- Diagram = function() {
- };
- Diagram.prototype = {
- getNodeMap: function() {
- return this.nodeMap;
- },
- getEdgeMap: function() {
- return this.edgeMap;
- },
- init: function(process) {
- this.process = process;
- this.nodeMap = {};
- this.edgeMap = {};
- for (var i = 0; i < this.process.children.length; i++) {
- var child = process.children[i];
- var node = new Node();
- node.id = child.text;
- node.type = child.type;
- node.x = child.x;
- node.y = child.y;
- node.w = child.w;
- node.h = child.h;
- this.nodeMap[node.id] = node;
- }
- for (var i = 0; i < this.process.children.length; i++) {
- var child = process.children[i];
- for (var j = 0; j < child.getOutgoingConnections().length; j++) {
- var connection = child.getOutgoingConnections()[j];
- this.createEdge(connection);
- }
- }
- },
- createEdge: function(connection) {
- var connectionId = connection.getSource().text + '_' + connection.getTarget().text;
- var edge = this.edgeMap[connectionId];
- if (!edge) {
- edge = new Edge();
- edge.id = connectionId;
- edge.name = connection.text;
- edge.source = this.nodeMap[connection.getSource().text];
- edge.target = this.nodeMap[connection.getTarget().text];
- edge.source.outgoingLinks.push(edge);
- edge.target.incomingLinks.push(edge);
- this.edgeMap[connectionId] = edge;
- }
- },
- updateModel: function() {
- for (var nodeId in this.nodeMap) {
- var item = this.nodeMap[nodeId];
- var model = this.getModel(nodeId);
- model.x = item.x;
- model.y = item.y;
- model.getEditPart().getFigure().x = model.x;
- model.getEditPart().getFigure().y = model.y;
- for (var i = 0; i < item.outgoingLinks.length; i++) {
- var connection = item.outgoingLinks[i];
- var connectionModel = this.getConnectionModel(model, connection);
- if (connectionModel == null) {
- continue;
- }
- connectionModel.innerPoints = typeof connection.innerPoints == 'undefined' ? []
- : connection.innerPoints;
- connectionModel.textX = 0;
- connectionModel.textY = 0;
- connectionModel.getEditPart().getFigure().innerPoints = connectionModel.innerPoints;
- connectionModel.getEditPart().getFigure().textX = connectionModel.textX;
- connectionModel.getEditPart().getFigure().textY = connectionModel.textY;
- }
- }
- this.process.getEditPart().refresh();
- },
- getModel: function(name) {
- var model = null;
- Gef.each(this.process.children, function(item) {
- if (item.text == name) {
- model = item;
- return false;
- }
- });
- return model;
- },
- getConnectionModel: function(nodeModel, edge) {
- var model = null;
- Gef.each(nodeModel.getOutgoingConnections(), function(item) {
- if (item.getTarget().text == edge.getTarget().id) {
- model = item;
- return false;
- }
- });
- return model;
- }
- };
- ;
- // should be change name to LayoutingElement
- Node = function() {
- this.incomingLinks = [];
- this.outgoingLinks = [];
- };
- Node.prototype = {
- getIncomingLinks: function() {
- return this.incomingLinks;
- },
- getOutgoingLinks: function() {
- return this.outgoingLinks;
- },
- getPrecedingElements: function() {
- var previousElements = [];
- for (var i = 0; i < this.incomingLinks.length; i++) {
- previousElements.push(this.incomingLinks[i].source);
- }
- return previousElements;
- },
- getFollowingElements: function() {
- var followingElements = [];
- for (var i = 0; i < this.outgoingLinks.length; i++) {
- followingElements.push(this.outgoingLinks[i].target);
- }
- return followingElements;
- },
- isJoin: function() {
- return this.incomingLinks.length > 1;
- },
- isSplit: function() {
- return this.outgoingLinks.length > 1;
- },
- prevSplit: function() {
- var distance = 1000;
- var candidateDistance = 0;
- var split = null;
- var candidate = null;
- var precedingElements = this.getPrecedingElements();
- for (var i = 0; i < precedingElements.length; i++) {
- var elem = precedingElements[i];
- if (elem.isSplit()) {
- return elem;
- }
- candidate = elem.prevSplit();
- if (this.isJoin()) {
- // if this is not a join, we have only one precedingElement.
- candidateDistance = elem.backwardDistanceTo(candidate);
- }
- if (candidateDistance < distance) {
- split = candidate;
- distance = candidateDistance;
- }
- }
- return split;
- },
- backwardDistanceTo: function(other) {
- return this._backwardDistanceTo(other, []);
- },
- _backwardDistanceTo: function(other, historyElements) {
- if (other == this) {
- return 0;
- }
- if (historyElements.indexOf(this) != -1) {
- return 1000;
- }
- var d = 1000;
- var newHistory = [];
- newHistory.push(this);
- var precedingElements = this.getPrecedingElements();
- for (var i = 0; i < precedingElements.length; i++) {
- var el = precedingElements[i];
- d = Math.min(d, el._backwardDistanceTo(other, newHistory));
- }
- return d == 1000 ? d : d + 1;
- }
- };
- ;
- Edge = function() {
- this.source = null;
- this.target = null;
- };
- Edge.prototype = {
- getSource: function() {
- return this.source;
- },
- getTarget: function() {
- return this.target;
- },
- reverseOutgoingAndIncoming: function() {
- var index = 0;
- var oldSource = this.source;
- var oldTarget = this.target;
- index = oldSource.outgoingLinks.indexOf(this);
- oldSource.outgoingLinks.splice(index, 1);
- index = oldTarget.incomingLinks.indexOf(this);
- oldTarget.incomingLinks.splice(index, 1);
- var newSource = oldTarget;
- var newTarget = oldSource;
- newSource.outgoingLinks.push(this);
- newTarget.incomingLinks.push(this);
- this.source = newSource;
- this.target = newTarget;
- }
- };
- ;
- TopologicalSorter = function(diagram) {
- this.diagram = diagram;
- this.prepareDataAndSort(true);
- this.prepareDataAndSort(false);
- };
- TopologicalSorter.prototype = {
- getSortedElements: function() {
- return this.sortedElements;
- },
- prepareDataAndSort: function(shouldBackpatch) {
- this.sortedElements = [];
- this.elementsToSort = {};
- this.backwardsEdges = [];
- this.elementsToSortCount = 0;
- this.addAllChildren();
- this.topologicalSort();
- if (shouldBackpatch === true) {
- this.backpatchBackwardsEdges();
- }
- this.reverseBackwardsEdges();
- },
- addAllChildren: function() {
- for (var nodeId in this.diagram.nodeMap) {
- var node = this.diagram.nodeMap[nodeId];
- this.elementsToSort[nodeId] = new SortableLayoutingElement(node);
- this.elementsToSortCount++;
- }
- },
- topologicalSort: function() {
- var count = 0;
- var oldCount = 0;
- while (this.elementsToSortCount > 0) {
- var freeElements = this.getFreeElements();
- if (freeElements.length > 0) {
- for (var i = 0; i < freeElements.length; i++) {
- var freeElement = freeElements[i];
- this.sortedElements.push(freeElement.node);
- this.freeElementsFrom(freeElement);
- delete this.elementsToSort[freeElement.node.id];
- }
- } else {
- var entry = this.getLoopEntryPoint();
- for (var i = 0; i < entry.incomingLinks.length; i++) {
- var backId = entry.incomingLinks[i];
- entry.reverseIncomingLinkFrom(backId);
- var elem = this.elementsToSort[backId];
- elem.reverseOutgoingLinkTo(entry.node.id);
- this.backwardsEdges.push(new BackwardsEdge(backId, entry.node.id));
- }
- }
- }
- },
- backpatchBackwardsEdges: function() {
- var newBackwardsEdges = [];
- for (var i = 0; i < this.backwardsEdges.length; i++) {
- newBackwardsEdges.push(this.backwardsEdges[i]);
- }
- for (var i = 0; i < this.backwardsEdges.length; i++) {
- var edge = this.backwardsEdges[i];
- var sourceId = edge.getSource();
- var targetId = edge.getTarget();
- var sourceElement = this.diagram.nodeMap[sourceId];
- while (!(sourceElement.isJoin() || sourceElement.isSplit())) {
- var newSourceElement = sourceElement.getPrecedingElements()[0];
- targetId = newSourceElement.id;
- newBackwardsEdges.push(new BackwardsEdge(targetId, sourceId));
- sourceElement = newSourceElement;
- sourceId = targetId;
- }
- }
- this.backwardsEdges = newBackwardsEdges;
- },
- reverseBackwardsEdges: function() {
- var edgeMap = this.diagram.edgeMap;
- for (var i = 0; i < this.backwardsEdges.length; i++) {
- var backwardsEdge = this.backwardsEdges[i];
- var sourceId = backwardsEdge.getSource();
- var targetId = backwardsEdge.getTarget();
- var sourceElement = this.diagram.nodeMap[sourceId];
- var targetElement = this.diagram.nodeMap[targetId];
- var edge = this.getEdge(edgeMap, sourceElement, targetElement);
- backwardsEdge.setEdge(edge);
- if (edge) {
- // reverse edge outgoing and incoming
- edge.reverseOutgoingAndIncoming();
- }
- }
- },
- getFreeElements: function() {
- var freeElements = [];
- for (var nodeId in this.elementsToSort) {
- var elem = this.elementsToSort[nodeId];
- if (elem.isFree()) {
- freeElements.push(elem);
- }
- }
- return freeElements;
- },
- freeElementsFrom: function(freeElement) {
- for (var i = 0; i < freeElement.outgoingLinks.length; i++) {
- var id = freeElement.outgoingLinks[i];
- var targetElement = this.elementsToSort[id];
- if (targetElement) {
- targetElement.removeIncomingLinkFrom(freeElement.node.id);
- }
- }
- this.elementsToSortCount--;
- },
- getLoopEntryPoint: function() {
- for (var nodeId in this.elementsToSort) {
- var candidate = this.elementsToSort[nodeId];
- if (candidate.oldInCount > 1
- && candidate.oldInCount > candidate.incomingLinks.length) {
- return candidate;
- }
- }
- throw new Error('Could not find a valid loop entry point');
- },
- getEdge: function(edgeMap, sourceElement, targetElement) {
- for (var i = 0; i < sourceElement.outgoingLinks.length; i++) {
- var edge = sourceElement.outgoingLinks[i];
- if (edge.getTarget().id == targetElement.id) {
- return edge;
- }
- }
- return null;
- }
- };
- ;
- SortableLayoutingElement = function(node) {
- this.node = node;
- this.incomingLinks = [];
- this.outgoingLinks = [];
- for (var i = 0; i < node.incomingLinks.length; i++) {
- this.incomingLinks.push(node.incomingLinks[i].source.id);
- }
- for (var i = 0; i < node.outgoingLinks.length; i++) {
- this.outgoingLinks.push(node.outgoingLinks[i].target.id);
- }
- this.oldInCount = this.incomingLinks.length;
- this.isJoin = node.isJoin();
- };
- SortableLayoutingElement.prototype = {
- isFree: function() {
- return this.incomingLinks.length == 0;
- },
- removeIncomingLinkFrom: function(sourceId) {
- var index = this.incomingLinks.indexOf(sourceId);
- this.incomingLinks.splice(index, 1);
- },
- reverseIncomingLinkFrom: function(id) {
- this.removeIncomingLinkFrom(id);
- this.outgoingLinks.push(id);
- },
- reverseOutgoingLinkTo: function(id) {
- var index = this.outgoingLinks.indexOf(id);
- this.outgoingLinks.splice(index, 1);
- this.incomingLinks.push(id);
- }
- };
- ;
- BackwardsEdge = function(source, target) {
- this.source = source;
- this.target = target;
- };
- BackwardsEdge.prototype = {
- getEdge: function() {
- return this.edge;
- },
- setEdge: function(edge) {
- this.edge = edge;
- },
- getSource: function() {
- return this.source;
- },
- getTarget: function() {
- return this.target;
- }
- };
- ;
- LeftToRightGridLayouter = function(diagram, sortedIds) {
- this.diagram = diagram;
- this.sortedIds = sortedIds;
- };
- LeftToRightGridLayouter.prototype = {
- doLayout: function() {
- this.grid = new Grid();
- this.layoutElements();
- this.calcGeometry(this.grid);
- this.writeGeometry(this.grid);
- this.diagram.updateModel();
- },
- layoutElements: function() {
- for (var i = 0; i < this.sortedIds.length; i++) {
- var sortedId = this.sortedIds[i];
- var currentElement = this.diagram.nodeMap[sortedId];
- var precedingElements = currentElement.getPrecedingElements();
- var cellOfElement = this.placeElement(currentElement, precedingElements);
- if (currentElement.isJoin() && precedingElements.length != 0) {
- // there is an edge hitting us left, so lets forbid
- // interleaving to use the left cell, if this is empty
- cellOfElement.getPrevCell().setPackable(false);
- }
- if (currentElement.isSplit()) {
- this.prelayoutSuccessors(currentElement, cellOfElement);
- }
- }
- },
- placeElement: function(currentElement, precedingElements) {
- var newCell = null;
- if (precedingElements.length == 0) {
- this.grid.startCell.value = currentElement;
- newCell = this.grid.startCell;
- } else {
- var leftCell = null;
- var newCell = this.grid.getCellOfItem(currentElement);
- if (currentElement.isJoin()) {
- var splitFound = false;
- var split = currentElement.prevSplit();
- if (split != null) {
- var splits = new PriorityQueue(currentElement);
- splits.add(split);
- for (var i = 0; i < precedingElements.length; i++) {
- var elem = precedingElements[i];
- split = elem.prevSplit();
- if (split != null && !splits.contains(split)) {
- splits.add(split);
- //console.info(splits.items);
- }
- }
- split = null;
- // get split with most connections
- var maxCon = 0;
- for (var i = 0; i < splits.items.length; i++) {
- var target = splits.items[i];
- if (target == currentElement) {
- continue;
- }
- // current connections
- var curCon = 0;
- for (var j = 0; j < precedingElements.length; j++) {
- var elem = precedingElements[j];
- if (elem.backwardDistanceTo(target) < 1000) {
- curCon++;
- }
- }
- if (curCon > maxCon) {
- maxCon = curCon;
- split = target;
- }
- }
- splitFound = split != null;
- }
- // current cell position
- var x = 0;
- var yAcc = 0;
- var yCnt = 0;
- for (var i = 0; i < precedingElements.length; i++) {
- var elem = precedingElements[i];
- var tmp = this.grid.getCellOfItem(elem);
- if (tmp == null) {
- tmp = {
- getColIndex: function() {
- return 0;
- }
- };
- } else {
- yAcc += tmp.getRowIndex();
- yCnt++;
- }
- x = Math.max(x, tmp.getColIndex());
- }
- // farthest to the right
- if (splitFound) {
- leftCell = this.grid.getCellOfItem(split).row.cells[x];
- // set path to split unpackable
- for (var c = leftCell; c.value != split; c = c.getPrevCell()) {
- c.setPackable(false);
- }
- } else {
- if (yCnt == 0) {
- leftCell = this.grid.rows[0].above().cells[x];
- } else {
- leftCell = this.grid.rows[yAcc / yCnt].cells[x];
- }
- }
- if (newCell != null && newCell.value == currentElement) {
- newCell.value = null;
- }
- newCell = leftCell.after();
- // set all incoming pathes unpackable
- for (var i = 0; i < precedingElements.length; i++) {
- var el = precedingElements[i];
- var target = this.grid.getCellOfItem(el);
- if (target == null) {
- continue;
- }
- var start = target.row.cells[x + 1];
- for (var c = start; c != target; c = c.getPrevCell()) {
- c.setPackable(false);
- }
- }
- } else if (newCell == null) {
- // if not preLayouted
- var preElem = precedingElements[0];
- leftCell = this.grid.getCellOfItem(preElem);
- newCell = leftCell.after();
- }
- if (newCell.isFilled() && newCell.value != currentElement) {
- newCell.row.insertRowBeneath();
- newCell = newCell.beneath();
- }
- newCell.value = currentElement;
- newCell.getPrevCell().setPackable(false);
- }
- return newCell;
- },
- prelayoutSuccessors: function(currentElement, cellOfElement) {
- var baseCell = cellOfElement.after();
- var topCell = baseCell;
- var followingElements = currentElement.getFollowingElements();
- // heuristic for direct connection to join
- var directJoin = null;
- for (var i = 0; i < followingElements.length; i++) {
- var possibleJoin = followingElements[i];
- if (possibleJoin.isJoin()) {
- directJoin = possibleJoin;
- }
- }
- if (directJoin != null) {
- // put in the middle
- var index = followingElements.indexOf(directJoin);
- // remove
- followingElements.splice(index, 1);
- var position = parseInt(followingElements.length / 2, 10);
- // insert
- followingElements.splice(position, 0, directJoin);
- }
- // normal preLayout following elements
- var follow = parseInt(followingElements.length / 2, 10);
- for (var i = 0; i < follow; i++) {
- topCell.row.insertRowAbove();
- baseCell.row.insertRowBeneath();
- topCell = topCell.above();
- }
- for (var i = 0; i < followingElements.length; i++) {
- var newElem = followingElements[i];
- if (this.grid.getCellOfItem(newElem)) {
- continue;
- }
- topCell.value = newElem;
- topCell = topCell.beneath();
- if (topCell == baseCell && followingElements.length % 2 == 0) {
- topCell = topCell.beneath();
- }
- }
- },
- calcGeometry: function(grid) {
- grid.pack();
- var heightOfRow = [];
- for (var i = 0; i < grid.rowCount; i++) {
- heightOfRow.push(0);
- }
- var widthOfColumn = [];
- for (var i = 0; i < grid.colCount; i++) {
- widthOfColumn.push(0);
- }
- for (var i = 0; i < grid.rowCount; i++) {
- var row = grid.rows[i];
- for (var j = 0; j < grid.colCount; j++) {
- var cell = row.cells[j];
- if (cell.isFilled()) {
- var elem = cell.value;
- widthOfColumn[j] = Math.max(widthOfColumn[j], elem.w + 30);
- heightOfRow[i] = Math.max(heightOfRow[i], elem.h + 30);
- }
- }
- }
- this.heightOfRow = heightOfRow;
- this.widthOfColumn = widthOfColumn;
- this.totalWidth = 0;
- this.totalHeight = 0;
- for (var i = 0; i < grid.colCount; i++) {
- this.totalWidth += widthOfColumn[i];
- }
- for (var i = 0; i < grid.rowCount; i++) {
- this.totalHeight += heightOfRow[i];
- }
- },
- writeGeometry: function(grid) {
- var x = 0;
- var y = 0;
- for (var i = 0; i < grid.rowCount; i++) {
- var row = grid.rows[i];
- var cellHeight = this.heightOfRow[i];
- for (var j = 0; j < grid.colCount; j++) {
- var cell = row.cells[j];
- var cellWidth = this.widthOfColumn[j];
- if (cell.isFilled()) {
- var elem = cell.value;
- var newX = x + cellWidth / 2 - elem.w / 2;
- var newY = y + cellHeight / 2 - elem.h / 2;
- elem.x = newX;
- elem.y = newY;
- }
- x += cellWidth;
- }
- x = 0;
- y += cellHeight;
- }
- }
- };
- ;
- Grid = function() {
- var cell = new Cell();
- var row = new Row();
- row.grid = this;
- row.addCell(cell);
- this.rows = [row];
- this.startCell = cell;
- this.colCount = 1;
- this.rowCount = this.rows.length;
- };
- Grid.prototype = {
- addFirstRow: function() {
- var row = new Row();
- row.grid = this;
- for (var i = 0; i < this.rolCount; i++) {
- var cell = new Cell();
- row.addCell(cell);
- }
- this.rows.unshift(row);
- this.rowCount = this.rows.length;
- },
- addLastRow: function() {
- var row = new Row();
- row.grid = this;
- for (var i = 0; i < this.rolCount; i++) {
- row.addCell(new Cell());
- }
- this.rows.push(row);
- this.rowCount = this.rows.length;
- },
- addLastCol: function() {
- for (var i = 0; i < this.rowCount; i++) {
- var row = this.rows[i];
- row.addCell(new Cell());
- }
- this.colCount++;
- },
- getCellOfItem: function(elem) {
- for (var i = 0; i < this.rowCount; i++) {
- var row = this.rows[i];
- for (var j = 0; j < this.colCount; j++) {
- var cell = row.cells[j];
- if (cell.value == elem) {
- return cell;
- }
- }
- }
- return null;
- },
- pack: function() {
- var changed = false;
- do {
- changed = false;
- for (var i = 0; i < this.rows.length; i++) {
- var row = this.rows[i];
- changed |= row.tryInterleaveWith(row.getPrevRow());
- }
- for (var i = 0; i < this.rows.length; i++) {
- var row = this.rows[i];
- changed |= row.tryInterleaveWith(row.getNextRow());
- }
- } while (changed);
- },
- info: function() {
- var value = '';
- for (var i = 0; i < this.rows.length; i++) {
- var row = this.rows[i];
- for (var j = 0; j < row.cells.length; j++) {
- var cell = row.cells[j];
- var id = '[ ]';
- if (cell.isFilled()) {
- id = cell.value.id;
- } else if (cell.packable === false) {
- id = '[ p ]';
- }
- value += id;
- }
- value += '\n'
- }
- return value;
- }
- };
- ;
- Cell = function() {
- this.packable = true;
- };
- Cell.prototype = {
- isFilled: function() {
- return typeof this.value != 'undefined' && this.value != null;
- },
- isUnpackable: function() {
- return this.isFilled() || (this.packable === false);
- },
- setPackable: function(packable) {
- this.packable = packable;
- },
- getRowIndex: function() {
- return this.row.getIndex();
- },
- getColIndex: function() {
- for (var i = 0; i < this.row.cells.length; i++) {
- if (this.row.cells[i] == this) {
- return i;
- }
- }
- },
- after: function() {
- var colIndex = this.getColIndex();
- if (colIndex == this.row.cells.length - 1) {
- this.grid.addLastCol();
- }
- return this.row.cells[colIndex + 1];
- },
- above: function() {
- var rowIndex = this.getRowIndex();
- var colIndex = this.getColIndex();
- if (rowIndex == 0) {
- this.row.insertRowAbove();
- }
- return this.grid.rows[rowIndex - 1].cells[colIndex];
- },
- beneath: function() {
- var rowIndex = this.getRowIndex();
- var colIndex = this.getColIndex();
- if (rowIndex == this.grid.rowCount - 1) {
- this.row.insertRowBeneath();
- }
- return this.grid.rows[rowIndex + 1].cells[colIndex];
- },
- getPrevCell: function() {
- var index = this.getColIndex();
- return this.row.cells[index - 1];
- },
- getNextCell: function() {
- var index = this.getColIndex();
- return this.row.cells[index + 1];
- }
- };
- ;
- Row = function() {
- this.cells = [];
- };
- Row.prototype = {
- addCell: function(cell) {
- cell.row = this;
- cell.grid = this.grid;
- this.cells.push(cell);
- },
- getIndex: function() {
- for (var i = 0; i < this.grid.rows.length; i++) {
- if (this.grid.rows[i] == this) {
- return i;
- }
- }
- },
- insertRowBeneath: function() {
- var row = new Row();
- row.grid = this.grid;
- for (var i = 0; i < this.grid.colCount; i++) {
- row.addCell(new Cell());
- }
- var rowIndex = this.getIndex();
- var rows = this.grid.rows;
- if (rowIndex == rows.length - 1) {
- rows.push(row);
- } else {
- rows.splice(rowIndex + 1, 0, row);
- }
- this.grid.rowCount = rows.length;
- },
- insertRowAbove: function() {
- var row = new Row();
- row.grid = this.grid;
- for (var i = 0; i < this.grid.colCount; i++) {
- row.addCell(new Cell());
- }
- var rowIndex = this.getIndex();
- var rows = this.grid.rows;
- if (rowIndex == 0) {
- rows.unshift(row);
- } else {
- rows.splice(rowIndex, 0, row);
- }
- this.grid.rowCount = rows.length;
- },
- getPrevRow: function() {
- var index = this.getIndex();
- if (index > 0) {
- return this.grid.rows[index - 1];
- } else {
- return null;
- }
- },
- getNextRow: function() {
- var index = this.getIndex();
- if (index < this.grid.rows.length) {
- return this.grid.rows[index + 1];
- } else {
- return null;
- }
- },
- tryInterleaveWith: function(other) {
- if (!this.isInterleaveWith(other)) {
- return false;
- }
- for (var i = 0; i < this.cells.length; i++) {
- var cell = this.cells[i];
- var otherCell = other.cells[i];
- if (cell.isFilled()) {
- other.cells[i] = cell;
- } else if (cell.isUnpackable()) {
- otherCell.setPackable(false);
- }
- }
- this._remove();
- return true;
- },
- isInterleaveWith: function(other) {
- if (other == null || other == this) {
- return false;
- } else if (other.getPrevRow() != this && other.getNextRow() != this) {
- return false;
- }
- for (var i = 0; i < this.cells.length; i++) {
- var cell = this.cells[i];
- var otherCell = other.cells[i];
- if (cell.isUnpackable() && otherCell.isUnpackable()) {
- return false;
- }
- }
- return true;
- },
- _remove: function() {
- var index = this.getIndex();
- this.grid.rows.splice(index, 1);
- this.grid.rowCount--;
- }
- };
- ;
- PriorityQueue = function(center) {
- this.ce = center;
- this.items = [];
- };
- PriorityQueue.prototype = {
- add: function(element) {
- this.items.push(element);
- var len = this.items.length;
- for (var i = 0; i < len; i++) {
- for (var j = i; j < len; j++) {
- var elem1 = this.items[i];
- var elem2 = this.items[j];
- if (this.compareTo(elem1, elem2) > 0) {
- this.items[i] = elem2;
- this.items[j] = elem1;
- }
- }
- }
- },
- compareTo: function(elem1, elem2) {
- return this.ce.backwardDistanceTo(elem1) - this.ce.backwardDistanceTo(elem2);
- },
- contains: function(element) {
- return this.items.indexOf(element) != -1;
- }
- };
- ;
- EdgeLayouter = function(grid, edge) {
- this.grid = grid;
- this.edge = edge;
- edge.innerPoints = [];
- this.calculateGlobals();
- this.pickLayoutForEdge();
- };
- EdgeLayouter.prototype = {
- calculateGlobals: function() {
- this.source = this.edge.source;
- this.target = this.edge.target;
- this.sourceRelativeCenterX = this.source.w / 2;
- this.sourceRelativeCenterY = this.source.h / 2;
- this.targetRelativeCenterX = this.target.w / 2;
- this.targetRelativeCenterY = this.target.h / 2;
- this.sourceAbsoluteCenterX = this.source.x + this.sourceRelativeCenterX;
- this.sourceAbsoluteCenterY = this.source.y + this.sourceRelativeCenterY;
- this.targetAbsoluteCenterX = this.target.x + this.targetRelativeCenterX;
- this.targetAbsoluteCenterY = this.target.y + this.targetRelativeCenterY;
- this.sourceAbsoluteX = this.source.x;
- this.sourceAbsoluteY = this.source.y;
- this.sourceAbsoluteX2 = this.source.x + this.source.w;
- this.sourceAbsoluteY2 = this.source.y + this.source.h;
- this.targetAbsoluteX = this.target.x;
- this.targetAbsoluteY = this.target.y;
- this.targetAbsoluteX2 = this.target.x + this.target.w;
- this.targetAbsoluteY2 = this.target.y + this.target.h;
- this.sourceJoin = this.source.isJoin();
- this.sourceSplit = this.source.isSplit();
- this.targetJoin = this.target.isJoin();
- this.targetSplit = this.target.isSplit();
- this.backwards = this.sourceAbsoluteCenterX > this.targetAbsoluteCenterX;
- },
- pickLayoutForEdge: function() {
- // sourceX == targetX, up and down
- if (this.sourceAbsoluteCenterX == this.targetAbsoluteCenterX) {
- this.setEdgeDirectCenter();
- return;
- } else if (this.sourceAbsoluteCenterY == this.targetAbsoluteCenterY) {
- if (this.areCellsHorizontalFree()) {
- this.setEdgeDirectCenter();
- } else {
- this.setEdgeAroundTheCorner(true);
- }
- return;
- }
- if (this.sourceAbsoluteCenterX <= this.targetAbsoluteCenterX
- && this.sourceAbsoluteCenterY <= this.targetAbsoluteCenterY) {
- // target is right under
- if (this.sourcejoin && this.sourceSplit) {
- this.setEdgeStepRight();
- return;
- } else if (this.sourceSplit) {
- this.setEdge90DegreeRightUnderAntiClockwise();
- return;
- } else if (this.targetJoin) {
- this.setEdge90DegreeRightUnderClockwise();
- return;
- }
- } else if (this.sourceAbsoluteCenterX <= this.targetAbsoluteCenterX
- && this.sourceAbsoluteCenterY > this.targetAbsoluteCenterY) {
- // target is right above
- if (this.sourcejoin && this.sourceSplit) {
- this.setEdgeStepRight();
- return;
- } else if (this.sourceSplit) {
- this.setEdge90DegreeRightAboveClockwise();
- return;
- } else if (this.targetJoin) {
- this.setEdge90DegreeRightAboveAntiClockwise();
- return;
- }
- }
- if (this.sourceJoin && sourceSplit && (!this.backwards)) {
- this.setEdgeStepRight();
- return;
- }
- if (this.sourceJoin && sourceSplit) {
- this.setEdgeAroundTheCorner(true);
- return;
- }
- this.setEdgeDirectCenter();
- },
- areCellsHorizontalFree: function() {
- var fromCell = null;
- var toCell = null;
- if (this.sourceAbsoluteCenterX < this.targetAbsoluteCenterX) {
- fromCell = this.grid.getCellOfItem(this.source);
- toCell = this.grid.getCellOfItem(this.target);
- } else {
- fromCell = this.grid.getCellOfItem(this.target);
- toCell = this.grid.getCellOfItem(this.source);
- }
- fromCell = fromCell.getNextCell();
- while (fromCell != toCell) {
- if (fromCell == null || fromCell.isFilled()) {
- return false;
- }
- fromCell = fromCell.getNextCell();
- }
- return true;
- },
- setEdgeDirectCenter: function() {
- var boundsMinX = Math.min(this.sourceAbsoluteCenterX,
- this.targetAbsoluteCenterX);
- var boundsMinY = Math.min(this.sourceAbsoluteCenterY,
- this.targetAbsoluteCenterY);
- var boundsMaxX = Math.max(this.sourceAbsoluteCenterX,
- this.targetAbsoluteCenterX);
- var boundsMaxY = Math.max(this.sourceAbsoluteCenterY,
- this.targetAbsoluteCenterY);
- // this.edge.innerPoints = [];
- },
- setEdge90DegreeRightAboveClockwise: function() {
- this.edge.innerPoints = [
- [this.sourceAbsoluteCenterX, this.targetAbsoluteCenterY]
- ];
- },
- setEdge90DegreeRightAboveAntiClockwise: function() {
- this.edge.innerPoints = [
- [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY]
- ];
- },
- setEdge90DegreeRightUnderClockwise: function() {
- this.edge.innerPoints = [
- [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY]
- ];
- },
- setEdge90DegreeRightUnderAntiClockwise: function() {
- this.edge.innerPoints = [
- [this.sourceAbsoluteCenterX, this.targetAbsoluteCenterY]
- ];
- },
- setEdgeAroundTheCorner: function(down) {
- var height = Math.max(this.source.h / 2, this.target.h / 2) + 20;
- if (down) {
- height *= -1;
- }
- this.edge.innerPoints = [
- [this.sourceAbsoluteCenterX, this.sourceAbsoluteCenterY + height],
- [this.targetAbsoluteCenterX, this.sourceAbsoluteCenterY + height]
- ];
- }
- };
- Ext.ux.OneCombo = Ext.extend(Ext.form.ComboBox, {
- initComponent: function() {
- this.readOnly = true;
- this.displayField = 'text';
- this.valueField = 'text';
- this.triggerAction = 'all';
- this.mode = 'local';
- this.emptyText = 'Please Select...';
- this.store = new Ext.data.SimpleStore({
- expandData: true,
- fields: ['text']
- });
- this.store.loadData(this.data);
- Ext.ux.OneCombo.superclass.initComponent.call(this);
- }
- });
- Ext.reg('onecombo', Ext.ux.OneCombo);
- App.PalettePanel = Ext.extend(Ext.Panel, {
- initComponent: function() {
- this.region = 'west';
- this.title = '活动环节';
- this.iconCls = 'tb-activity';
- this.width = 130;
- this.initPalette();
- App.PalettePanel.superclass.initComponent.call(this);
- },
- initPalette: function() {
- var paletteType = null;
- if (!Gef.PALETTE_TYPE) {
- paletteType = 'accordion';
- } else {
- paletteType = Gef.PALETTE_TYPE;
- }
- this.configLayout(paletteType);
- this.configItems(paletteType);
- },
- createHtml: function(array, divId) {
- var imageRoot = Gef.IMAGE_ROOT.replace('48/', '');
- if (divId) {
- var html = '<div id="' + divId + '" unselectable="on">';
- } else {
- var html = '<div unselectable="on">';
- }
- for (var i = 0; i < array.length; i++) {
- var item = array[i];
- html += '<div id="' + item.name
- + '" class="paletteItem-' + item.name
- + '" style="text-align:center;font-size:12px;cursor:pointer;" unselectable="on"><img id="'
- + item.name + '-img" class="paletteItem-' + item.name
- + '" src="' + imageRoot + item.image + '.png" unselectable="on"><br>'
- + item.title + '</div>';
- }
- html += '</div>';
- return html;
- },
- /**
- * this.layout = 'accordion';
- */
- configLayout: function(type) {
- if (!type || type == 'plain') {
- //
- } else if (type && type == 'accordion') {
- this.layout = 'accordion';
- }
- },
- configItems: function(type) {
- if (type && type == 'accordion') {
- this.createItemsForAccordion();
- } else if (!type || type == 'plain') {
- this.createItemsForHtml();
- }
- },
- createItemsForAccordion: function() {
- this.id = '__gef_jbs_palette__';
- this.items = [{
- title: '所有活动',
- iconCls: 'tb-activity',
- autoScroll: true,
- html: this.createHtml([
- {name: 'select', image: 'select32', title: '选择'},
- {name: 'transition', image: '32/flow_sequence', title: '连线'},
- {name: 'start', image: '32/start_event_empty', title: '开始'},
- {name: 'end', image: '32/end_event_terminate', title: '结束'},
- {name: 'cancel', image: '32/end_event_cancel', title: '取消'},
- {name: 'error', image: '32/end_event_error', title: '错误'},
- {name: 'task', image: '32/task_empty', title: '任务'},
- {name: 'decision', image: '32/gateway_exclusive', title: '决策'},
- {name: 'sql', image: '32/task_sql', title: 'SQL'},
- {name: 'fork', image: '32/gateway_parallel', title: '并行'},
- {name: 'join', image: '32/gateway_parallel', title: '汇聚'}
- ])
- }];
- },
- createItemsForHtml: function() {
- this.autoScroll = true;
- this.html = this.createHtml([
- {name: 'select', image: 'select32', title: '选择'},
- {name: 'transition', image: '32/flow_sequence', title: '连线'},
- {name: 'start', image: '32/start_event_empty', title: '开始'},
- {name: 'end', image: '32/end_event_terminate', title: '结束'},
- {name: 'cancel', image: '32/end_event_cancel', title: '取消'},
- {name: 'error', image: '32/end_event_error', title: '错误'},
- {name: 'state', image: '32/task_wait', title: '等待'},
- {name: 'task', image: '32/task_empty', title: '任务'},
- {name: 'decision', image: '32/gateway_exclusive', title: '决策'},
- {name: 'fork', image: '32/gateway_parallel', title: '并行'},
- {name: 'join', image: '32/gateway_parallel', title: '汇聚'},
- {name: 'java', image: '32/task_java', title: 'JAVA'},
- {name: 'script', image: '32/task_java', title: '脚本'},
- {name: 'hql', image: '32/task_hql', title: 'HQL'},
- {name: 'sql', image: '32/task_sql', title: 'SQL'},
- {name: 'mail', image: '32/task_empty', title: '邮件'},
- {name: 'custom', image: '32/task_empty', title: '自定义'},
- {name: 'subProcess', image: '32/task_empty', title: '子流程'},
- {name: 'jms', image: '32/task_empty', title: 'JMS'},
- {name: 'ruleDecision', image: '32/gateway_exclusive', title: '规则决策'},
- {name: 'rules', image: '32/task_empty', title: '规则'},
- {name: 'human', image: '32/task_empty', title: '人工节点'},
- {name: 'auto', image: '32/task_empty', title: '自动节点'},
- {name: 'counter-sign', image: '32/task_empty', title: '会签节点'}
- ], '__gef_jbs_palette__');
- }
- });
- Ext.ux.TwoCombo = Ext.extend(Ext.form.ComboBox, {
- initComponent: function() {
- this.readOnly = true;
- this.displayField = 'text';
- this.valueField = 'value';
- this.triggerAction = 'all';
- this.mode = 'local';
- this.emptyText = 'Please Select...';
- this.store = new Ext.data.SimpleStore({
- fields: ['value', 'text']
- });
- this.store.loadData(this.data);
- Ext.ux.TwoCombo.superclass.initComponent.call(this);
- }
- });
- Ext.reg('twocombo', Ext.ux.TwoCombo);
|