Actions.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. /**
  2. *$id:Action 。JS,V 2017-12-19
  3. *$author shen.zhi
  4. */
  5. /**
  6. *结构对于给定的UI操作的对象。
  7. *编辑函数方法管理
  8. */
  9. function Actions(editorUi)
  10. {
  11. this.editorUi = editorUi;
  12. this.actions = new Object();
  13. this.init();
  14. };
  15. /**
  16. * 添加默认的函数
  17. */
  18. Actions.prototype.init = function()
  19. {
  20. var ui = this.editorUi;
  21. var editor = ui.editor;
  22. var graph = editor.graph;
  23. graph.cellsMovable=!0; //设置不可移动
  24. graph.cellsDisconnectable=!0; //设置边不可编辑
  25. graph.cellsResizable=!0; //设置不可改变大小
  26. var icw = (ui.container.clientWidth-190-20)/2;
  27. var ich = 30;
  28. currentObject = this ;
  29. //文件操作
  30. this.addAction('new', function() { window.open(ui.getUrl());});
  31. this.addAction('open', function()
  32. {
  33. window.openNew = true;
  34. window.openKey = 'open';
  35. ui.openFile();
  36. });
  37. this.addAction('import', function()
  38. {
  39. window.openNew = false;
  40. window.openKey = 'import';
  41. //关闭对话框后打开
  42. window.openFile = new OpenFile(mxUtils.bind(this, function()
  43. {
  44. ui.hideDialog();
  45. }));
  46. window.openFile.setConsumer(mxUtils.bind(this, function(xml, filename)
  47. {
  48. try
  49. {
  50. var doc = mxUtils.parseXml(xml);
  51. var model = new mxGraphModel();
  52. var codec = new mxCodec(doc);
  53. codec.decode(doc.documentElement, model);
  54. var children = model.getChildren(model.getChildAt(model.getRoot(), 0));
  55. //editor.graph.setSelectionCells(editor.graph.importCells(children));
  56. editor.graph.importCells(children);
  57. }
  58. catch (e)
  59. {
  60. mxUtils.alert(mxResources.get('invalidOrMissingFile') + ': ' + e.message);
  61. }
  62. }));
  63. //如果删除打开文件对话框关闭
  64. ui.showDialog(new OpenDialog(this).container, 300, 180, true, true, function()
  65. {
  66. window.openFile = null;
  67. });
  68. });
  69. this.addAction('save', function() { ui.save(); }, null, null, 'Ctrl+S');
  70. //this.addAction('saveAs', function() { ui.saveFile(true); }, null, null, 'Ctrl+Shift-S');
  71. //this.addAction('export', function() { ui.showDialog(new ExportDialog(ui).container, 300, 200, true, true); }, null, null, 'Ctrl+E');
  72. //this.put('editFile', new Action(mxResources.get('edit'), mxUtils.bind(this, function()
  73. //{
  74. //this.editorUi.showDialog(new EditFileDialog(ui).container, 620, 420, true, true);
  75. //})));
  76. this.addAction('pageSetup', function() { ui.showDialog(new PageSetupDialog(ui).container, 300, 200, true, true); });
  77. //打印
  78. this.addAction('print', function() { ui.showDialog(new PrintDialog(ui).container, 300, 200, true, true); }, null, 'sprite-print', 'Ctrl+P');
  79. this.addAction('preview', function() { mxUtils.show(graph, null, 10, 10); });
  80. //编辑操作
  81. this.addAction('undo', function() { editor.undoManager.undo(); }, null, 'sprite-undo', 'Ctrl+Z');
  82. this.addAction('redo', function() { editor.undoManager.redo(); }, null, 'sprite-redo', 'Ctrl+Y');
  83. this.addAction('cut', function() { mxClipboard.cut(graph); }, null, 'sprite-cut', 'Ctrl+X');
  84. this.addAction('copy', function() { mxClipboard.copy(graph); }, null, 'sprite-copy', 'Ctrl+C');
  85. this.addAction('paste', function() { mxClipboard.paste(graph); }, false, 'sprite-paste', 'Ctrl+V');
  86. this.addAction('delete', function() { graph.removeCells(); }, null, null, 'Delete');
  87. this.addAction('duplicate', function()
  88. {
  89. var s = graph.gridSize;
  90. graph.setSelectionCells(graph.moveCells(graph.getSelectionCells(), s, s, true));
  91. }, null, null, 'Ctrl+D');
  92. this.addAction('selectVertices', function() { graph.selectVertices(); }, null, null, 'Ctrl+Shift+V');
  93. this.addAction('selectEdges', function() { graph.selectEdges(); }, null, null, 'Ctrl+Shift+E');
  94. this.addAction('selectAll', function() { graph.selectAll(); }, null, null, 'Ctrl+A');
  95. //导航行动
  96. this.addAction('home', function() { graph.home(); }, null, null, 'Home');
  97. this.addAction('exitGroup', function() { graph.exitGroup(); }, null, null, 'Page Up');
  98. this.addAction('enterGroup', function() { graph.enterGroup(); }, null, null, 'Page Down');
  99. this.addAction('expand', function() { graph.foldCells(false); }, null, null, 'Enter');
  100. this.addAction('collapse', function() { graph.foldCells(true); }, null, null, 'Backspace');
  101. //安排行动
  102. this.addAction('toFront', function() { graph.orderCells(false); }, null, null, 'Ctrl+F');
  103. this.addAction('toBack', function() { graph.orderCells(true); }, null, null, 'Ctrl+B');
  104. this.addAction('group', function() { graph.setSelectionCell(graph.groupCells(null, 0)); }, null, null, 'Ctrl+G');
  105. this.addAction('ungroup', function() { graph.setSelectionCells(graph.ungroupCells()); }, null, null, 'Ctrl+U');
  106. this.addAction('removeFromGroup', function() { graph.removeCellsFromParent(); });
  107. this.addAction('editLink', function()
  108. {
  109. var cell = graph.getSelectionCell();
  110. var link = graph.getLinkForCell(cell);
  111. if (link == null)
  112. {
  113. link = '';
  114. }
  115. link = mxUtils.prompt(mxResources.get('enterValue'), link);
  116. if (link != null)
  117. {
  118. graph.setLinkForCell(cell, link);
  119. }
  120. });
  121. this.addAction('openLink', function()
  122. {
  123. var cell = graph.getSelectionCell();
  124. var link = graph.getLinkForCell(cell);
  125. if (link != null)
  126. {
  127. window.open(link);
  128. }
  129. });
  130. this.addAction('autosize', function()
  131. {
  132. var cells = graph.getSelectionCells();
  133. if (cells != null)
  134. {
  135. graph.getModel().beginUpdate();
  136. try
  137. {
  138. for (var i = 0; i < cells.length; i++)
  139. {
  140. var cell = cells[i];
  141. if (graph.getModel().getChildCount(cell))
  142. {
  143. graph.updateGroupBounds([cell], 20);
  144. }
  145. else
  146. {
  147. graph.updateCellSize(cell);
  148. }
  149. }
  150. }
  151. finally
  152. {
  153. graph.getModel().endUpdate();
  154. }
  155. }
  156. });
  157. this.addAction('rotation', function()
  158. {
  159. var value = '0';
  160. var state = graph.getView().getState(graph.getSelectionCell());
  161. if (state != null)
  162. {
  163. value = state.style[mxConstants.STYLE_ROTATION] || value;
  164. }
  165. value = mxUtils.prompt(mxResources.get('enterValue') + ' (' +
  166. mxResources.get('rotation') + ' 0-360)', value);
  167. if (value != null)
  168. {
  169. graph.setCellStyles(mxConstants.STYLE_ROTATION, value);
  170. }
  171. });
  172. this.addAction('rotate', function()
  173. {
  174. var cells = graph.getSelectionCells();
  175. if (cells != null)
  176. {
  177. graph.getModel().beginUpdate();
  178. try
  179. {
  180. for (var i = 0; i < cells.length; i++)
  181. {
  182. var cell = cells[i];
  183. if (graph.getModel().isVertex(cell) && graph.getModel().getChildCount(cell) == 0)
  184. {
  185. var geo = graph.getCellGeometry(cell);
  186. if (geo != null)
  187. {
  188. //旋转的几何尺寸及位置
  189. geo = geo.clone();
  190. geo.x += geo.width / 2 - geo.height / 2;
  191. geo.y += geo.height / 2 - geo.width / 2;
  192. var tmp = geo.width;
  193. geo.width = geo.height;
  194. geo.height = tmp;
  195. graph.getModel().setGeometry(cell, geo);
  196. //方向和进展90度读
  197. var state = graph.view.getState(cell);
  198. if (state != null)
  199. {
  200. var dir = state.style[mxConstants.STYLE_DIRECTION] || 'east'/*default*/;
  201. if (dir == 'east')
  202. {
  203. dir = 'south';
  204. }
  205. else if (dir == 'south')
  206. {
  207. dir = 'west';
  208. }
  209. else if (dir == 'west')
  210. {
  211. dir = 'north';
  212. }
  213. else if (dir == 'north')
  214. {
  215. dir = 'east';
  216. }
  217. graph.setCellStyles(mxConstants.STYLE_DIRECTION, dir, [cell]);
  218. }
  219. }
  220. }
  221. }
  222. }
  223. finally
  224. {
  225. graph.getModel().endUpdate();
  226. }
  227. }
  228. }, null, null, 'Ctrl+R');
  229. //查看下级
  230. this.addAction('initNext', mxUtils.bind(this, function(subRootId,opttype)
  231. {
  232. var intype = opttype ;
  233. var incurrentResId = subRootId ;
  234. var currentObje = this ;
  235. if(subRootId&&subRootId!=""&&subRootId!="null"&&subRootId!="undefined"
  236. &&opttype&&opttype!=""&&opttype!="null"&&opttype!="undefined"){
  237. incurrentResId = subRootId ;
  238. }else{
  239. var edges = graph.getSelectionCell().edges;
  240. incurrentResId = graph.getSelectionCell().id;
  241. if(incurrentResId.length>10&&"2736"==incurrentResId.substring(5,9)){
  242. alert("ONT无下级资源");
  243. return;
  244. }
  245. for(var e_i = 0;edges&&e_i<edges.length; e_i++){
  246. if(edges[e_i].source.id==incurrentResId){
  247. //已经有了下级,不重新加载,避免重复生成子节点
  248. return;
  249. }
  250. }
  251. if(opttype&&opttype&&opttype!=""&&opttype!="null"&&opttype!="undefined"){
  252. intype = opttype ;
  253. }else{
  254. intype = "2" ;
  255. }
  256. }
  257. if(intype=="6"&&incurrentResId.length>10&&"2736"!=incurrentResId.substring(5,9)&&"2530"!=incurrentResId.substring(5,9)){
  258. alert("只有OBD和ONT支持查看上联通路");
  259. return;
  260. }
  261. graph.getModel().beginUpdate();
  262. try
  263. {
  264. $.getJSON($("#path").val()+"/topo/topo.spr?method=getMxTopoById",{"params":incurrentResId,"sfFunctionName":sfFunctionName,"type":intype,"inx":"0","iny":"0","topoDefId":topoDefId},function(data){
  265. var cels = null;//graph.getSelectionCell();
  266. var inx= 0 ;//cels.geometry.x;
  267. var iny= 0 ;//cels.geometry.y;
  268. var iwidth = 40 ;
  269. var iheight = 40 ;
  270. var isroot = 0;
  271. if(data&&data.root==1){
  272. isroot = 1;
  273. inx=icw;
  274. graph.selectAll();
  275. graph.removeCells();
  276. }else if(data&&data.root==3){
  277. isroot = 3;
  278. inx=icw;
  279. graph.selectAll();
  280. graph.removeCells();
  281. }else{
  282. cels = graph.getSelectionCell();
  283. inx=cels.geometry.x;
  284. iny=cels.geometry.y;
  285. if(befor_sel_cell&&befor_sel_cell.length>0){
  286. graph.setCellStyle(befor_sel_cell [0].style.replace("_sel.png",".png"), befor_sel_cell);
  287. }
  288. var cells = graph.getSelectionCells();
  289. if (cells != null && cells.length > 0)
  290. {
  291. graph.setCellStyle(cells[0].style.replace(".png","_sel.png"), cells);
  292. befor_sel_cell = graph.getSelectionCells();
  293. }
  294. if(data==null||data==""||data=="null"){
  295. alert("无下级资源");
  296. return;
  297. }
  298. }
  299. currentNeedSelNodeiny = iny;
  300. currentNeedSelNodeinx = inx;
  301. currentNeedSelGraph = graph;
  302. currentSelCellObject = cels;
  303. if(isroot==0&&data&&data.nodes.length>0){
  304. var subdata = new Array();
  305. for(var di=0;data&&di<data.nodes.length;di++){
  306. var sobj = {"ID":data.nodes[di].id,"NAME":data.nodes[di].value,"CHECK":data.nodes[di].id};
  307. subdata.push(sobj);
  308. }
  309. cleanGrid();
  310. $(".grid-content").llygrid({
  311. columns:[
  312. {align:"center",key:"ID",label:"ID", width:"0"},
  313. {align:"center",key:"CHECK", width:"50",format:{type:"checkbox"}},
  314. {align:"center",key:"NAME",label:"资源名称", width:"250"}
  315. ],
  316. ds:{type:"data",records:subdata},
  317. limit:20,
  318. pageSizes:[10,20,30,40],
  319. height:180,
  320. title:"请选择需要展示的资源",
  321. indexColumn:false,
  322. querys:{name:""},
  323. options:"reload",
  324. loadMsg:"数据加载中,请稍候......"
  325. }) ;
  326. var ibttonhtml = '选择需要展示的资源 <button style="margin-left: 50px;" onclick="viewSelectRes()"> 确认</button><button style="margin-left: 50px;" onclick="hideSelectRes()"> 关闭</button>';
  327. $(".grid-content .ui-corner-all .ui-helper-clearfix").html(ibttonhtml);
  328. currentNeedSelNode = data.nodes;
  329. //下级数量小于7时直接展示,多的时候才弹出选项框
  330. if(data.nodes.length<7){
  331. viewSelectRes(1);
  332. }else{
  333. $('#divSubResDetailGrid').slideDown("slow");
  334. }
  335. }else if(isroot==3&&data&&data.nodes.length>0){
  336. var rootCel;
  337. for(var di=0;data&&di<data.nodes.length;di++){
  338. iny = iny+120 ;
  339. var linx = inx;
  340. var liny = iny;
  341. var dataNode = data.nodes[di];
  342. var newcells = graph.insertVertex(graph.getDefaultParent(), dataNode.id,dataNode.value, linx, liny, iwidth, iheight,"image;image=stencils/clipart/"+dataNode.type+".png");
  343. if(di==0){
  344. rootCel=newcells;
  345. }else{
  346. var newEdge = graph.insertEdge(graph.getDefaultParent(), "edge"+dataNode.id, "", currentSelCellObject, newcells, "edgeStyle=topToBottomEdgeStyle;");
  347. }
  348. currentSelCellObject = newcells;
  349. }
  350. editor.graph.setSelectionCells([rootCel]);
  351. currentObject.get('initResProperties').funct();
  352. }else{
  353. iny = iny+120 ;
  354. for(var di=0;data&&di<data.nodes.length;di++){
  355. var linx = inx;
  356. var liny = iny;
  357. if(di%2==0){
  358. linx = inx+60*di;
  359. }else{
  360. linx = inx-60*di;
  361. }
  362. var dataNode = data.nodes[di];
  363. var newcells = graph.insertVertex(graph.getDefaultParent(), dataNode.id,dataNode.value, linx, liny, iwidth, iheight,"image;image=stencils/clipart/"+dataNode.type+".png");
  364. editor.graph.setSelectionCells([newcells]);
  365. }
  366. if(isroot==1){
  367. currentObject.get('initNext').funct(subRootId,"2");
  368. }
  369. }
  370. });
  371. }
  372. finally
  373. {
  374. graph.getModel().endUpdate();
  375. }
  376. }));
  377. this.get('initNext').funct(inResId,intype);
  378. //刷新-重新加载
  379. this.addAction('refreshView', function()
  380. {
  381. graph.getModel().beginUpdate();
  382. try
  383. {
  384. var icw = (ui.container.clientWidth-190-20)/2;
  385. var ich = 30;
  386. $.getJSON($("#path").val()+"/topo/topo.spr?method=getMxTopoById",{"params":inResId,"sfFunctionName":sfFunctionName,"type":"1","inx":"0","iny":"0","topoDefId":topoDefId},function(data){
  387. var cels = null;//graph.getSelectionCell();
  388. var inx= icw ;//cels.geometry.x;
  389. var iny= ich ;//cels.geometry.y;
  390. var iwidth = 40 ;
  391. var iheight = 40 ;
  392. var isroot = 0;
  393. if(data&&data.root==1){
  394. isroot = 1;
  395. }else{
  396. cels = graph.getSelectionCell();
  397. inx=cels.geometry.x;
  398. iny=cels.geometry.y;
  399. }
  400. iny = iny+120 ;
  401. for(var di=0;data&&di<data.nodes.length;di++){
  402. var linx = inx
  403. if(di%2==0){
  404. linx = inx+50*di;
  405. }else{
  406. linx = inx-50*di;
  407. }
  408. var dataNode = data.nodes[di];
  409. var newcells = graph.insertVertex(graph.getDefaultParent(), dataNode.id,dataNode.value, linx, iny, iwidth, iheight,"image;image=stencils/clipart/"+dataNode.type+".png");
  410. if(isroot==0){
  411. //根节点不需要创建连线
  412. var newEdge = graph.insertEdge(graph.getDefaultParent(), "edge"+dataNode.id, "", cels, newcells, "edgeStyle=topToBottomEdgeStyle;");
  413. }
  414. }
  415. });
  416. }
  417. finally
  418. {
  419. graph.getModel().endUpdate();
  420. }
  421. });
  422. //查看资源属性
  423. this.addAction('initResProperties', function()
  424. {
  425. graph.getModel().beginUpdate();
  426. try
  427. {
  428. $.getJSON($("#path").val()+"/topo/topo.spr?method=getMxTopoById",{"params":graph.getSelectionCell().id,"sfFunctionName":sfFunctionName,"type":"3","inx":"0","iny":"0"},function(data){
  429. $(".grid-content-attr").html("");
  430. if($('.grid-content-attr').data("cacheDs")&&$('.grid-content-attr').data("cacheDs").records){
  431. $('.grid-content-attr').data("cacheDs").records=[];
  432. }
  433. $(".grid-content-attr").llygrid({
  434. columns:[
  435. {align:"center",key:"ATTR_NAME",label:"资源属性", width:"80"},
  436. {align:"center",key:"ATTR_VALUE",label:"属性值", width:"160"}
  437. ],
  438. ds:{type:"data",records:data},
  439. limit:100,
  440. pager: true,
  441. height:200,
  442. title:"点击收起",
  443. loadMsg:"数据加载中,请稍候......"
  444. }) ;
  445. $('#divSubResPropertyGrid').show("slide", {direction : "right" }, 500,function(){});
  446. $(".grid-content-attr .ui-corner-all .ui-helper-clearfix").click(function () {
  447. $('#divSubResPropertyGrid').hide("slide", {direction : "right" }, 500,function(){});
  448. });
  449. });
  450. }
  451. finally
  452. {
  453. graph.getModel().endUpdate();
  454. }
  455. });
  456. //查看资源端口端子信息
  457. this.addAction('initSubRes', function()
  458. {
  459. graph.getModel().beginUpdate();
  460. try
  461. {
  462. $.getJSON($("#path").val()+"/topo/topo.spr?method=getMxTopoById",{"params":graph.getSelectionCell().id,"sfFunctionName":sfFunctionName,"type":"4","inx":"0","iny":"0"},function(data){
  463. cleanGrid();
  464. $(".grid-content").llygrid({
  465. columns:data.heard,
  466. ds:{type:"data",records:data.body},
  467. limit:20,
  468. pageSizes:[10,20,30,40],
  469. height:180,
  470. title:"数据列表-点击收起",
  471. loadMsg:"数据加载中,请稍候......"
  472. }) ;
  473. $('#divSubResDetailGrid').slideDown("slow");
  474. $(".grid-content .ui-corner-all .ui-helper-clearfix").click(function () {
  475. $("#divSubResDetailGrid").slideUp("slow");
  476. });
  477. });
  478. }
  479. finally
  480. {
  481. graph.getModel().endUpdate();
  482. }
  483. });
  484. //查看上级连接信息
  485. this.addAction('viewLink', function()
  486. {
  487. graph.getModel().beginUpdate();
  488. try
  489. {
  490. var target = graph.getSelectionCell().target;
  491. $.getJSON($("#path").val()+"/topo/topo.spr?method=getMxTopoById",{"params":target.id,"sfFunctionName":sfFunctionName,"type":"5","inx":"0","iny":"0"},function(data){
  492. cleanGrid();
  493. $(".grid-content").llygrid({
  494. columns:data.heard,
  495. ds:{type:"data",records:data.body},
  496. limit:20,
  497. pageSizes:[10,20,30,40],
  498. height:180,
  499. title:"数据列表-点击收起",
  500. loadMsg:"数据加载中,请稍候......"
  501. }) ;
  502. $('#divSubResDetailGrid').slideDown("slow");
  503. $(".grid-content .ui-corner-all .ui-helper-clearfix").click(function () {
  504. $("#divSubResDetailGrid").slideUp("slow");
  505. });
  506. });
  507. }
  508. finally
  509. {
  510. graph.getModel().endUpdate();
  511. }
  512. });
  513. //查看上级全程路由
  514. this.addAction('viewSuperRoute', function()
  515. {
  516. var target = graph.getSelectionCell();
  517. //6 从下往上 找全程路由
  518. currentObject.get('initNext').funct(target.id,"6");
  519. });
  520. this.addAction('invisibleSub', function() {
  521. var needRemoveCells = [];
  522. needRemoveCells.push.apply(needRemoveCells,getTarget(graph.getSelectionCell(),null));
  523. graph.removeCells(needRemoveCells);
  524. });
  525. this.addAction('invisibleOrther',mxUtils.bind(this, function() {
  526. var currentObjectCell = graph.getSelectionCell();
  527. var parentObjectCell = null ;
  528. var isroot = 0;
  529. if(currentObjectCell&&currentObjectCell.edges&&currentObjectCell.edges.length>0){
  530. if(currentObjectCell.edges.length==0){
  531. isroot = 1;
  532. }
  533. for(var c_i = 0; c_i <currentObjectCell.edges.length;c_i++ ){
  534. if(currentObjectCell.edges[c_i]&&currentObjectCell.edges[c_i].target&&currentObjectCell.edges[c_i].target==currentObjectCell){
  535. parentObjectCell = currentObjectCell.edges[c_i].source;
  536. break;
  537. }
  538. }
  539. }
  540. var needRemoveCells = [];
  541. needRemoveCells.push.apply(needRemoveCells,getTarget(parentObjectCell,currentObjectCell));
  542. graph.removeCells(needRemoveCells);
  543. if(isroot == 1){
  544. editor.graph.setSelectionCells([parentObjectCell]);
  545. var layout_mx = new mxCompactTreeLayout(graph, false);
  546. layout_mx.edgeRouting = false;
  547. layout_mx.levelDistance = 30;
  548. this.editorUi.executeLayout(layout_mx, true, true);
  549. }
  550. }));
  551. this.addAction('zoomIn', function() { graph.zoomIn(); }, null, null, 'Add');
  552. this.addAction('zoomOut', function() { graph.zoomOut(); }, null, null, 'Subtract');
  553. this.addAction('fitWindow', function() { graph.fit(); });
  554. //视图的操作
  555. this.addAction('actualSize', function()
  556. {
  557. graph.zoomTo(1);
  558. });
  559. this.addAction('fitPage', mxUtils.bind(this, function()
  560. {
  561. if (!graph.pageVisible)
  562. {
  563. this.get('pageView').funct();
  564. }
  565. var fmt = graph.pageFormat;
  566. var ps = graph.pageScale;
  567. var cw = graph.container.clientWidth - 20;
  568. var ch = graph.container.clientHeight - 20;
  569. var scale = Math.floor(100 * Math.min(cw / fmt.width / ps, ch / fmt.height / ps)) / 100;
  570. graph.zoomTo(scale);
  571. graph.container.scrollLeft = Math.round(graph.view.translate.x * scale - Math.max(10, (graph.container.clientWidth - fmt.width * ps * scale) / 2));
  572. graph.container.scrollTop = Math.round(graph.view.translate.y * scale - Math.max(10, (graph.container.clientHeight - fmt.height * ps * scale) / 2));
  573. }));
  574. this.addAction('fitPageWidth', mxUtils.bind(this, function()
  575. {
  576. if (!graph.pageVisible)
  577. {
  578. this.get('pageView').funct();
  579. }
  580. var fmt = graph.pageFormat;
  581. var ps = graph.pageScale;
  582. var cw = graph.container.clientWidth - 20;
  583. var scale = Math.floor(100 * cw / fmt.width / ps) / 100;
  584. graph.zoomTo(scale);
  585. graph.container.scrollLeft = Math.round(graph.view.translate.x * scale - Math.max(10, (graph.container.clientWidth - fmt.width * ps * scale) / 2));
  586. graph.container.scrollTop = Math.round(graph.view.translate.y * scale - Math.max(10, (graph.container.clientHeight - fmt.height * ps * scale) / 2));
  587. }));
  588. this.put('customZoom', new Action(mxResources.get('custom'), function()
  589. {
  590. var value = mxUtils.prompt(mxResources.get('enterValue') + ' (%)', parseInt(graph.getView().getScale() * 100));
  591. if (value != null && value.length > 0 && !isNaN(parseInt(value)))
  592. {
  593. graph.zoomTo(parseInt(value) / 100);
  594. }
  595. }));
  596. //选择行动
  597. var action = null;
  598. action = this.addAction('grid', function()
  599. {
  600. graph.setGridEnabled(!graph.isGridEnabled());
  601. editor.updateGraphComponents();
  602. }, null, null, 'Ctrl+Shift+G');
  603. action.setToggleAction(true);
  604. action.setSelectedCallback(function() { return graph.isGridEnabled(); });
  605. action = this.addAction('guides', function() { graph.graphHandler.guidesEnabled = !graph.graphHandler.guidesEnabled; });
  606. action.setToggleAction(true);
  607. action.setSelectedCallback(function() { return graph.graphHandler.guidesEnabled; });
  608. action = this.addAction('tooltips', function()
  609. {
  610. graph.tooltipHandler.setEnabled(!graph.tooltipHandler.isEnabled());
  611. });
  612. action.setToggleAction(true);
  613. action.setSelectedCallback(function() { return graph.tooltipHandler.isEnabled(); });
  614. action = this.addAction('navigation', function()
  615. {
  616. graph.foldingEnabled = !graph.foldingEnabled;
  617. graph.view.revalidate();
  618. });
  619. action.setToggleAction(true);
  620. action.setSelectedCallback(function() { return graph.foldingEnabled; });
  621. action = this.addAction('scrollbars', function()
  622. {
  623. graph.scrollbars = !graph.scrollbars;
  624. editor.updateGraphComponents();
  625. if (!graph.scrollbars)
  626. {
  627. var t = graph.view.translate;
  628. graph.view.setTranslate(t.x - graph.container.scrollLeft / graph.view.scale, t.y - graph.container.scrollTop / graph.view.scale);
  629. graph.container.scrollLeft = 0;
  630. graph.container.scrollTop = 0;
  631. graph.sizeDidChange();
  632. }
  633. else
  634. {
  635. var dx = graph.view.translate.x;
  636. var dy = graph.view.translate.y;
  637. graph.view.translate.x = 0;
  638. graph.view.translate.y = 0;
  639. graph.sizeDidChange();
  640. graph.container.scrollLeft -= Math.round(dx * graph.view.scale);
  641. graph.container.scrollTop -= Math.round(dy * graph.view.scale);
  642. }
  643. }, !mxClient.IS_TOUCH);
  644. action.setToggleAction(true);
  645. action.setSelectedCallback(function() { return graph.container.style.overflow == 'auto'; });
  646. action = this.addAction('pageView', mxUtils.bind(this, function()
  647. {
  648. graph.pageVisible = !graph.pageVisible;
  649. graph.pageBreaksVisible = graph.pageVisible;
  650. graph.preferPageSize = graph.pageBreaksVisible;
  651. graph.view.validate();
  652. graph.sizeDidChange();
  653. editor.updateGraphComponents();
  654. editor.outline.update();
  655. if (mxUtils.hasScrollbars(graph.container))
  656. {
  657. if (graph.pageVisible)
  658. {
  659. graph.container.scrollLeft -= 20;
  660. graph.container.scrollTop -= 20;
  661. }
  662. else
  663. {
  664. graph.container.scrollLeft += 20;
  665. graph.container.scrollTop += 20;
  666. }
  667. }
  668. }));
  669. action.setToggleAction(true);
  670. action.setSelectedCallback(function() { return graph.pageVisible; });
  671. this.put('pageBackgroundColor', new Action(mxResources.get('backgroundColor'), function()
  672. {
  673. var apply = function(color)
  674. {
  675. graph.background = color;
  676. editor.updateGraphComponents();
  677. };
  678. var cd = new ColorDialog(ui, graph.background || 'none', apply);
  679. ui.showDialog(cd.container, 220, 360, true, false);
  680. if (!mxClient.IS_TOUCH)
  681. {
  682. cd.colorInput.focus();
  683. }
  684. }));
  685. action = this.addAction('connect', function()
  686. {
  687. graph.setConnectable(!graph.connectionHandler.isEnabled());
  688. }, null, null, 'Ctrl+Q');
  689. action.setToggleAction(true);
  690. action.setSelectedCallback(function() { return graph.connectionHandler.isEnabled(); });
  691. //帮助行为
  692. this.addAction('help', function()
  693. {
  694. var ext = '';
  695. if (mxResources.isLanguageSupported(mxClient.language))
  696. {
  697. ext = '_' + mxClient.language;
  698. }
  699. window.open(RESOURCES_PATH + '/help' + ext + '.html');
  700. });
  701. this.put('about', new Action(mxResources.get('about') + ' Graph Editor', function()
  702. {
  703. ui.showDialog(new AboutDialog(ui).container, 320, 280, true, true);
  704. }, null, null, 'F1'));
  705. //字体风格的动作
  706. var toggleFontStyle = mxUtils.bind(this, function(key, style)
  707. {
  708. this.addAction(key, function()
  709. {
  710. graph.toggleCellStyleFlags(mxConstants.STYLE_FONTSTYLE, style);
  711. });
  712. });
  713. toggleFontStyle('bold', mxConstants.FONT_BOLD);
  714. toggleFontStyle('italic', mxConstants.FONT_ITALIC);
  715. toggleFontStyle('underline', mxConstants.FONT_UNDERLINE);
  716. //颜色动作
  717. this.addAction('fontColor', function() { ui.menus.pickColor(mxConstants.STYLE_FONTCOLOR); });
  718. this.addAction('strokeColor', function() { ui.menus.pickColor(mxConstants.STYLE_STROKECOLOR); });
  719. this.addAction('fillColor', function() { ui.menus.pickColor(mxConstants.STYLE_FILLCOLOR); });
  720. this.addAction('gradientColor', function() { ui.menus.pickColor(mxConstants.STYLE_GRADIENTCOLOR); });
  721. this.addAction('backgroundColor', function() { ui.menus.pickColor(mxConstants.STYLE_LABEL_BACKGROUNDCOLOR); });
  722. this.addAction('borderColor', function() { ui.menus.pickColor(mxConstants.STYLE_LABEL_BORDERCOLOR); });
  723. //格式的行为
  724. this.addAction('shadow', function() { graph.toggleCellStyles(mxConstants.STYLE_SHADOW); });
  725. this.addAction('dashed', function() { graph.toggleCellStyles(mxConstants.STYLE_DASHED); });
  726. this.addAction('rounded', function() { graph.toggleCellStyles(mxConstants.STYLE_ROUNDED); });
  727. this.addAction('style', function()
  728. {
  729. var cells = graph.getSelectionCells();
  730. if (cells != null && cells.length > 0)
  731. {
  732. var model = graph.getModel();
  733. var style = mxUtils.prompt(mxResources.get('enterValue')+ ' (' + mxResources.get('style') + ')',
  734. model.getStyle(cells[0]) || '');
  735. if (style != null)
  736. {
  737. graph.setCellStyle(style, cells);
  738. }
  739. }
  740. });
  741. this.addAction('setAsDefaultEdge', function()
  742. {
  743. var cell = graph.getSelectionCell();
  744. if (cell != null && graph.getModel().isEdge(cell))
  745. {
  746. //采取快照的细胞在调用的时刻
  747. var proto = graph.getModel().cloneCells([cell])[0];
  748. //删除输入/ exitxy风格
  749. var style = proto.getStyle();
  750. style = mxUtils.setStyle(style, mxConstants.STYLE_ENTRY_X, '');
  751. style = mxUtils.setStyle(style, mxConstants.STYLE_ENTRY_Y, '');
  752. style = mxUtils.setStyle(style, mxConstants.STYLE_EXIT_X, '');
  753. style = mxUtils.setStyle(style, mxConstants.STYLE_EXIT_Y, '');
  754. proto.setStyle(style);
  755. //使用边缘模板连接预览
  756. graph.connectionHandler.createEdgeState = function(me)
  757. {
  758. return graph.view.createState(proto);
  759. };
  760. //创建新的连接边缘模板
  761. graph.connectionHandler.factoryMethod = function()
  762. {
  763. return graph.cloneCells([proto])[0];
  764. };
  765. }
  766. });
  767. this.addAction('image', function()
  768. {
  769. function updateImage(value, w, h)
  770. {
  771. var select = null;
  772. var cells = graph.getSelectionCells();
  773. graph.getModel().beginUpdate();
  774. try
  775. {
  776. //没有选中单元格
  777. if (cells.length == 0)
  778. {
  779. var gs = graph.getGridSize();
  780. cells = [graph.insertVertex(graph.getDefaultParent(), null, '', gs, gs, w, h)];
  781. select = cells;
  782. }
  783. graph.setCellStyles(mxConstants.STYLE_IMAGE, value, cells);
  784. graph.setCellStyles(mxConstants.STYLE_SHAPE, 'image', cells);
  785. if (graph.getSelectionCount() == 1)
  786. {
  787. if (w != null && h != null)
  788. {
  789. var cell = cells[0];
  790. var geo = graph.getModel().getGeometry(cell);
  791. if (geo != null)
  792. {
  793. geo = geo.clone();
  794. geo.width = w;
  795. geo.height = h;
  796. graph.getModel().setGeometry(cell, geo);
  797. }
  798. }
  799. }
  800. }
  801. finally
  802. {
  803. graph.getModel().endUpdate();
  804. }
  805. if (select != null)
  806. {
  807. graph.setSelectionCells(select);
  808. graph.scrollCellToVisible(select[0]);
  809. }
  810. };
  811. var value = '';
  812. var state = graph.getView().getState(graph.getSelectionCell());
  813. if (state != null)
  814. {
  815. value = state.style[mxConstants.STYLE_IMAGE] || value;
  816. }
  817. value = mxUtils.prompt(mxResources.get('enterValue') + ' (' + mxResources.get('url') + ')', value);
  818. if (value != null)
  819. {
  820. if (value.length > 0)
  821. {
  822. var img = new Image();
  823. img.onload = function()
  824. {
  825. updateImage(value, img.width, img.height);
  826. };
  827. img.onerror = function()
  828. {
  829. mxUtils.alert(mxResources.get('fileNotFound'));
  830. };
  831. img.src = value;
  832. }
  833. }
  834. });
  835. };
  836. /**
  837. * 寄存器的作用在给定的名称.
  838. */
  839. Actions.prototype.addAction = function(key, funct, enabled, iconCls, shortcut)
  840. {
  841. return this.put(key, new Action(mxResources.get(key), funct, enabled, iconCls, shortcut));
  842. };
  843. /**
  844. * 寄存器的作用在给定的名称。
  845. */
  846. Actions.prototype.put = function(name, action)
  847. {
  848. this.actions[name] = action;
  849. return action;
  850. };
  851. /**
  852. * 返回给定名称或空如果没有这样的行动存在的动作。
  853. */
  854. Actions.prototype.get = function(name)
  855. {
  856. return this.actions[name];
  857. };
  858. /**
  859. * 对于给定的参数的一种新的活动构造。
  860. */
  861. function Action(label, funct, enabled, iconCls, shortcut)
  862. {
  863. mxEventSource.call(this);
  864. this.label = label;
  865. this.funct = funct;
  866. this.enabled = (enabled != null) ? enabled : true;
  867. this.iconCls = iconCls;
  868. this.shortcut = shortcut;
  869. };
  870. //行动继承mxeventsource
  871. mxUtils.extend(Action, mxEventSource);
  872. Action.prototype.setEnabled = function(value)
  873. {
  874. if (this.enabled != value)
  875. {
  876. this.enabled = value;
  877. this.fireEvent(new mxEventObject('stateChanged'));
  878. }
  879. };
  880. /**
  881. *套动作启用状态statechanged事件。
  882. */
  883. Action.prototype.setToggleAction = function(value)
  884. {
  885. this.toggleAction = value;
  886. };
  887. /**
  888. *套动作启用状态statechanged事件。
  889. */
  890. Action.prototype.setSelectedCallback = function(funct)
  891. {
  892. this.selectedCallback = funct;
  893. };
  894. /**
  895. * 套动作启用状态statechanged事件。
  896. */
  897. Action.prototype.isSelected = function()
  898. {
  899. return this.selectedCallback();
  900. };
  901. function getTarget(selTarget,ortherObjectCell){
  902. var needRemoveCells = [];
  903. for(var e_i = 0;selTarget&&selTarget.edges&&e_i<selTarget.edges.length; e_i++){
  904. var target = selTarget.edges[e_i].target;
  905. if(ortherObjectCell&&ortherObjectCell!=null&&target==ortherObjectCell){
  906. continue;
  907. }else if(target==selTarget){
  908. continue;
  909. }
  910. needRemoveCells.push(target);
  911. if(target.edges&&target.edges.length>1){
  912. needRemoveCells.push.apply(needRemoveCells,getTarget(target,null));
  913. }
  914. }
  915. return needRemoveCells;
  916. };
  917. function cleanGrid(){
  918. $(".grid-content").html("");
  919. if($('.grid-content').data("cacheDs")&&$('.grid-content').data("cacheDs").records){
  920. $('.grid-content').data("cacheDs").records=[];
  921. }
  922. };
  923. function viewSelectRes(initype){
  924. var iwidth = 40 ;
  925. var iheight = 40 ;
  926. var iny = currentNeedSelNodeiny;
  927. var inx = currentNeedSelNodeinx;
  928. var data =currentNeedSelNode;
  929. var seldata = $('.grid-content').llygrid('getSelectedValue','CHECK');
  930. iny = iny+120 ;
  931. graph = currentNeedSelGraph;
  932. for(var di=0;data&&di<data.length;di++){
  933. var needView = 0;
  934. for(var vi=0;vi<seldata.length;vi++){
  935. if(data[di].id==seldata[vi]){
  936. needView = 1;
  937. vi = 999999999;
  938. }
  939. }
  940. //1 代表加载当页所有
  941. if(initype==1){
  942. needView = 1;
  943. }
  944. if(needView==0){
  945. continue;
  946. }
  947. var linx = inx;
  948. var liny = iny;
  949. if(di%2==0){
  950. linx = inx+60*di;
  951. }else{
  952. linx = inx-60*di;
  953. }
  954. var dataNode = data[di];
  955. var newcells = graph.insertVertex(graph.getDefaultParent(), dataNode.id,dataNode.value, linx, liny, iwidth, iheight,"image;image=stencils/clipart/"+dataNode.type+".png");
  956. var newEdge = graph.insertEdge(graph.getDefaultParent(), "edge"+dataNode.id, "", currentSelCellObject, newcells, "edgeStyle=topToBottomEdgeStyle;");
  957. }
  958. var layout_mx = new mxCompactTreeLayout(graph, false);
  959. layout_mx.edgeRouting = false;
  960. layout_mx.levelDistance = 120;
  961. currentObject.editorUi.executeLayout(layout_mx, true, true);
  962. hideSelectRes();
  963. };
  964. function hideSelectRes(){
  965. $("#divSubResDetailGrid").slideUp("slow");
  966. };