list.jsp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@taglib prefix="p" uri="http://www.test.com/jsp/permission" %>
  4. <!doctype html>
  5. <html>
  6. <head>
  7. <%@ include file="../../common/head.jsp"%>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  9. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  10. <link rel="stylesheet" href="../res/js/plugins/ztree/demo.css" type="text/css">
  11. <link rel="stylesheet" href="../res/js/plugins/ztree/metroStyle/metroStyle.css" type="text/css">
  12. <script type="text/javascript" src="../res/js/plugins/ztree/jquery.ztree.core.js"></script>
  13. <script type="text/javascript" src="../res/js/plugins/ztree/jquery.ztree.excheck.js"></script>
  14. <script type="text/javascript" src="../res/js/plugins/ztree/jquery.ztree.exedit.js"></script>
  15. <script type="text/javascript">
  16. function test(value,row,index){
  17. // return '<a href="#">' + row['id'] + '</a>';
  18. return '<a href="#">编辑 </a>|<a href="#">删除</a>';
  19. }
  20. var _width = "768px";
  21. var _height = "420px";
  22. function setAction(){
  23. var data = getSelectedRow("tab_menu");
  24. if(null == data){
  25. return;
  26. }
  27. $.openDlg({
  28. url:'transfer.cs?action=setAction&id=' + data.id,
  29. title:"设定操作权限 - " + data.name,
  30. width:'100%',
  31. height:'100%',
  32. });
  33. }
  34. var setting = {
  35. view: {
  36. addHoverDom: addHoverDom,
  37. removeHoverDom: removeHoverDom,
  38. selectedMulti: false
  39. },
  40. check: {
  41. enable: true,
  42. chkStyle: "radio",
  43. radioType: "all"
  44. },
  45. data: {
  46. simpleData: {
  47. enable: true
  48. }
  49. },
  50. edit: {
  51. enable: true,
  52. },
  53. callback: {
  54. // onCheck: zTreeOnCheck
  55. beforeRemove: zTreeBeforeRemove,
  56. beforeEditName: zTreeBeforeEditName
  57. }
  58. };
  59. function addAction(){
  60. var nodes = $.fn.zTree.getZTreeObj("treeMenu").getCheckedNodes(true);
  61. var _id = 0 ;
  62. if(nodes.length > 0){
  63. if(nodes[0].level == 1){
  64. _id = nodes[0].id;
  65. $.openDlg({
  66. url:'transfer2.cs?action=addAction&id=0&menu_id=' + _id,
  67. title:'新增Action',
  68. width:'769px',
  69. height:'240px',
  70. });
  71. }
  72. }
  73. }
  74. var newCount = 1;
  75. function addHoverDom(treeId, treeNode) {
  76. var sObj = $("#" + treeNode.tId + "_span");
  77. if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
  78. var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
  79. + "' title='add node' onfocus='this.blur();'></span>";
  80. sObj.after(addStr);
  81. var btn = $("#addBtn_"+treeNode.tId);
  82. if (btn) btn.bind("click", function(){
  83. // var zTree = $.fn.zTree.getZTreeObj("treeMenu");
  84. // zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
  85. // alert(treeNode.id);
  86. if(treeNode.level == 2){
  87. $.openDlg({
  88. url:'transfer2.cs?action=addAction&id=0&menu_id=' + treeNode.getParentNode().id,
  89. title:'新增Action',
  90. width:'769px',
  91. height:'240px',
  92. });
  93. }
  94. else{
  95. $.openDlg({
  96. url:'transfer.cs?action=add&id=' + treeNode.id,
  97. title:'新增菜单',
  98. width:_width,
  99. height:_height,
  100. });
  101. }
  102. return false;
  103. });
  104. };
  105. function removeHoverDom(treeId, treeNode) {
  106. $("#addBtn_"+treeNode.tId).unbind().remove();
  107. // var btn = $("#addBtn_"+treeNode.tId);
  108. // if (btn)btn.bind("click", function(){
  109. // $.confirm("确定删除吗? ", function(){
  110. // $.post('del.cs?id=' + treeId.id,
  111. // function(result){
  112. // window.location.reload();
  113. // }
  114. // );
  115. // });
  116. // });
  117. };
  118. function zTreeBeforeRemove(treeId, treeNode) {
  119. var url = '';
  120. if(treeNode.level == 2){
  121. url = 'delAction.cs?id=' + treeNode.id
  122. }
  123. else{
  124. url = 'del.cs?id=' + treeNode.id
  125. }
  126. $.confirm("确定删除吗? ", function(){
  127. $.post(url,
  128. function(result){
  129. window.location.reload();
  130. }
  131. );
  132. });
  133. return false;
  134. }
  135. function zTreeBeforeEditName(treeId, treeNode) {
  136. if(treeNode.level == 2){
  137. $.openDlg({
  138. url:'transfer2.cs?action=editAction&id=' + treeNode.id + '&menu_id=' + treeNode.getParentNode().id,
  139. title:'编辑Action',
  140. width:'769px',
  141. height:'280px',
  142. });
  143. }
  144. else{
  145. $.openDlg({
  146. url:'transfer.cs?action=edit&id=' + treeNode.id,
  147. title:'编辑菜单',
  148. width:_width,
  149. height:_height,
  150. });
  151. }
  152. return false;
  153. }
  154. $(document).ready(function(){
  155. $.get('list2.cs', function(data){
  156. zNodes = data;
  157. $.fn.zTree.init($("#treeMenu"), setting, zNodes);
  158. });
  159. });
  160. // 预览事件
  161. function view(){
  162. var nodes = $.fn.zTree.getZTreeObj("treeMenu").getCheckedNodes(true);
  163. if(nodes.length < 1 ){
  164. return ;
  165. }
  166. var data = nodes[0];
  167. $.openDlg({
  168. url:'transfer.cs?action=view&id=' + data.id,
  169. title:'查看菜单',
  170. width:_width,
  171. height:_height,
  172. });
  173. }
  174. // 新增事件
  175. function add(){
  176. var nodes = $.fn.zTree.getZTreeObj("treeMenu").getCheckedNodes(true);
  177. var _id = 0 ;
  178. if(nodes.length > 0){
  179. if(nodes[0].level == 2){
  180. nodes = nodes[0].getParentNode().getParentNode();
  181. _id = nodes.id;
  182. }
  183. else if(nodes[0].level == 1){
  184. _id = nodes[0].getParentNode().id;
  185. }
  186. // if(nodes[0].level != 0) return;
  187. }
  188. $.openDlg({
  189. // url:'transfer.cs?action=add&id=0',
  190. url:'transfer.cs?action=add&id=' + _id,
  191. title:'新增菜单',
  192. width:_width,
  193. height:_height,
  194. });
  195. }
  196. // 编辑事件
  197. function edit(){
  198. var nodes = $.fn.zTree.getZTreeObj("treeMenu").getCheckedNodes(true);
  199. var _id = 0 ;
  200. if(nodes.length > 0 ){
  201. _id = nodes[0].id;
  202. }
  203. else{
  204. return ;
  205. }
  206. $.openDlg({
  207. url:'transfer.cs?action=edit&id=' + _id,
  208. title:'编辑菜单',
  209. width:_width,
  210. height:_height,
  211. });
  212. }
  213. // 删除事件
  214. function del(){
  215. var nodes = $.fn.zTree.getZTreeObj("treeMenu").getCheckedNodes(true);
  216. var _id = 0 ;
  217. if(nodes.length > 0 ){
  218. _id = nodes[0].id;
  219. }
  220. else{
  221. return ;
  222. }
  223. $.confirm("确定删除吗? ", function(){
  224. $.post('del.cs?id=' + _id,
  225. function(result){
  226. window.location.reload();
  227. }
  228. );
  229. });
  230. }
  231. </script>
  232. </head>
  233. <body class="gray-bg">
  234. <div class="wrapper wrapper-content animated fadeInUp">
  235. <div class="row row-lg">
  236. <div class="col-sm-12">
  237. <p:permission menuCode="${menuCode }" action="1">
  238. <button class="btn btn-sm btn-info" type="button" onclick="view()"><i class="fa fa-info"></i>&nbsp;查看</button>
  239. </p:permission>
  240. <p:permission menuCode="${menuCode }" action="2">
  241. <button class="btn btn-sm btn-success" type="button" onclick="add()"><i class="fa fa-plus"></i>&nbsp;新增菜单</button>
  242. </p:permission>
  243. <p:permission menuCode="${menuCode }" action="4">
  244. <button class="btn btn-sm btn-warning" type="button" onclick="addAction()"><i class="fa fa-pencil-square-o"></i> 新增action</button>
  245. </p:permission>
  246. <%-- <p:permission menuCode="181" action="8"> --%>
  247. <!-- <button class="btn btn-sm btn-danger" type="button" onclick="del()"><i class="fa fa-minus"></i> 删除</button> -->
  248. <%-- </p:permission> --%>
  249. <ul id="treeMenu" class="ztree" style="width:100%;"></ul>
  250. </div>
  251. </div>
  252. </div>
  253. </body>
  254. </html>