easyUIlist.vm 9.19 KB
#set($page_title="菜单列表")
#set($crumbs="首页:/home,菜单列表")


	<link rel="stylesheet" type="text/css" href="$!{webUtils.getLocalPath("/static/jquery_easyui/themes/default/easyui.css")}">
	<link rel="stylesheet" type="text/css" href="$!{webUtils.getLocalPath("/static/jquery_easyui/themes/icon.css")}">
	<link rel="stylesheet" type="text/css" href="$!{webUtils.getLocalPath("/static/jquery_easyui/demo/demo.css")}">
		
	<div class="demo-info">
		<div class="demo-tip icon-tip"></div>
		<div>选择一行记录右键进行操作.</div>
	</div>
	
	##Create Dialog
	<div id="dd" class="easyui-dialog" closed="true"  title="资源列表" iconCls="icon-ok"
			toolbar="#dlg-toolbar" buttons="#dlg-buttons" style="width:1000px;height:350px"  data-options="resizable:true,modal:true,closable:false,shadow:false">
		
		<table id="tt" class="easyui-datagrid" toolbar="#tb" 
			data-options="
			singleSelect:true,
			striped:true,
			fit:true,
			nowrap:false,
			url:'/resource/listAllResourceJson.do',
			checkbox:true,
			fitColumns:true,
			method:'get'">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:false"></th>
				<th data-options="field:'id'">Resource ID</th>
				<th data-options="field:'navbarName'">所属系统</th>
				<th data-options="field:'resourceName'">资源名</th>
				<th data-options="field:'url'">Url</th>
			</tr>
		</thead>
	</table>
		
		<div id="tb" style="padding:3px">  
		    <span>资源名:</span>  
		    <input id="resourceName" style="line-height:26px;border:1px solid #ccc">  
		    <span>URL:</span>  
		    <input id="url" style="line-height:26px;border:1px solid #ccc">  
		    <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">Search</a>  
		</div>
		
		
		
	</div>
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="getChecked()">Ok</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="closeDi()">Cancel</a>
	</div>
	
	
		<div id="mm" class="easyui-menu" style="width:120px;">
			<div onclick="edit()" data-options="iconCls:'icon-edit'">编辑</div>
			<div onclick="append()" data-options="iconCls:'icon-add'">添加同级</div>
			<div onclick="appendNextLevel()" data-options="iconCls:'icon-add'">添加子级</div>
			<div onclick="removeIt()" data-options="iconCls:'icon-remove'">删除</div>
			<div class="menu-sep"></div>
			<div onclick="openDialog()">关联资源</div>
			<div onclick="moveup()">向上移动</div>
			<div onclick="movedown()">向下移动</div>
		</div>
	
	<div style="margin:10px 0;">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="save()">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="cancel()">取消</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="collapseAll()">合并树</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="expandAll()">展开树</a>
	</div>
	<table id="tg" class="easyui-treegrid" title="菜单树列表"  style="width:1000px;height:800px"
			data-options="
				iconCls: 'icon-ok',
				rownumbers: true,
				singleSelect: true,
				animate: false,
				collapsible: true,
				fitColumns: true,
				url: '/menu/getAllMenuJson.do',
				method: 'get',
				idField: 'id',
				treeField: 'label',
				onContextMenu: onContextMenu
			">
		<thead>
			<tr>
				<th data-options="field:'id',width:80">Id</th>
				<th data-options="field:'label',width:180,editor:'text'">菜单名</th>
				<th data-options="field:'menuUrl',width:280">菜单Url</th>
				<th data-options="field:'description',width:180,editor:'text'">菜单描述</th>
			##	<th data-options="field:'_parentId',width:80">父级id</th>
			##	<th data-options="field:'sort',width:80">排序序号</th>
			</tr>
		</thead>
	</table>
	<script type="text/javascript">
		
		function onContextMenu(e,row){
			e.preventDefault();
			$(this).treegrid('select', row.id);
			$('#mm').menu('show',{
				left: e.pageX,
				top: e.pageY
			});
		}
		
		
		var editingId;
		function edit(){
		
		if (editingId != undefined){
			var t = $('#tg');
			t.treegrid('endEdit', editingId);
			}
		
		var row = $('#tg').treegrid('getSelected');
			if (row == undefined ) {
				alert("请选择一个菜单进行 ");
				return false;
			}
		
			var row = $('#tg').treegrid('getSelected');
			if (row){
				editingId = row.id
				$('#tg').treegrid('beginEdit', editingId);
			}
		}
		function save(){
			
			if (editingId != undefined){
				var t = $('#tg');
				t.treegrid('endEdit', editingId);
				var newRow = $('#tg').treegrid('getSelected');
				$.ajax({
                    type: "post",
                    url: "/menu/save.do",
                    data: {id:newRow.id, menuUrl:newRow.menuUrl, label:newRow.label, description:newRow.description, parentId:newRow._parentId },
                    dataType : 'json'
                });
                editingId = undefined;
                $('#tg').treegrid('reload', newRow._parentId);
			}
		}
		function cancel(){
			if (editingId != undefined){
				$('#tg').treegrid('cancelEdit', editingId);
				editingId = undefined;
			}
		}
		
		function collapse(){
			var node = $('#tg').treegrid('getSelected');
			if (node){
				$('#tg').treegrid('collapse', node.id);
			}
		}
		function expand(){
			var node = $('#tg').treegrid('getSelected');
			if (node){
				$('#tg').treegrid('expand', node.id);
			}
		}
		
		function removeIt(){
			
			var choice=confirm("您确认要删除吗?");
			if(choice) {
				var node = $('#tg').treegrid('getSelected');
				$.ajax({
	                    type: "get",
	                    url: "/menu/delete.do",
	                    data: "id=" + node.id,
	                    success: function (result) {
	                        $('#tg').treegrid('remove', node.id);
	                    }
	                });
                }
		}
		
		function collapseAll(){
			$('#tg').treegrid('collapseAll');
		}
		function expandAll(){
			$('#tg').treegrid('expandAll');
		}
		
		
		var idIndex = 100;
		var newNodeIdIndex = -1;
		function append(){
		    idIndex++;
		    newNodeIdIndex--;
			 var node = $('#tg').treegrid('getSelected');
			 
			 if(node._parentId == 0) {
			 	alert("对不起不能添加根节点");
			 	return false;
			 }
			 
			  if (node){
			  	$('#tg').treegrid('insert', {
			  	    after: node.id,
			  		data: {id:newNodeIdIndex,label:'NewLabel'+idIndex, _parentId:node._parentId}
			  	});
			  }
			
		}
		
		function appendNextLevel(){
		    newNodeIdIndex--;
		    idIndex++;
			 var node = $('#tg').treegrid('getSelected');
			  if (node){
			  	$('#tg').treegrid('append', {
			  	    parent: node.id,
			  		data: [{id:newNodeIdIndex,label:'NewLabel'+idIndex, _parentId:node.id}]
			  	});
			  }
			
		}
		
		function openDialog() {
		var row = $('#tg').treegrid('getSelected');
			if (row == undefined ) {
				alert("请选择一个菜单");
				return false;
			}
			
			if ($('#tg').treegrid('getChildren', row.id).length > 0) {
				alert("对不起,只能给最后一层添加链接!");
				return false;
			}
			
			$('#dd').dialog('open');
			
			var row = $('#tg').treegrid('getSelected');
			if (row){
				editingId = row.id
				$('#tg').treegrid('beginEdit', editingId);
			}
			
		}
		
		function getChecked() {
			var node = $('#tt').datagrid('getChecked');
			
			if (editingId != undefined){
				var t = $('#tg');
				t.treegrid('endEdit', editingId);
				var newRow = $('#tg').treegrid('getSelected');
				$.ajax({
                    type: "post",
                    url: "/menu/save.do",
                    data: {id:newRow.id, menuUrl:node[0].url, label:newRow.label, description:newRow.description, parentId:newRow._parentId,resourceId:node[0].id },
                    dataType : 'json'
                });
				
			}
			$('#dd').dialog('close');
			$('#tg').treegrid('reload', newRow._parentId);
			editingId = undefined;
		##	alert(node[0].productid +'---'+ $('#tg').treegrid('getSelected').id);
		}
		
		function closeDi() {
			$('#dd').dialog('close');
			if (editingId != undefined){
				$('#tg').treegrid('cancelEdit', editingId);
				editingId = undefined;
			}
		}
		
		function moveup() {
				var row = $('#tg').treegrid('getSelected');
				$.ajax({
                    type: "post",
                    url: "/menu/sort.do",
                    data: {id:row.id,sort:row.sort-1},
                    dataType : 'json'
                });
                
                $('#tg').treegrid('reload', row._parentId);
				editingId = undefined;
                
			}
			
		function movedown() {
				var row = $('#tg').treegrid('getSelected');
				$.ajax({
                    type: "post",
                    url: "/menu/sort.do",
                    data: {id:row.id,sort:row.sort+1},
                    dataType : 'json'
                });
                $('#tg').treegrid('reload', row._parentId);
				editingId = undefined;
			}
			
		function doSearch(){  
		    $('#tt').datagrid('load',{  
		        resourceName: $('#resourceName').val(),  
		        url: $('#url').val()  
		    });  
		}  
			
		
	</script>



<script type="text/javascript" src="$!{webUtils.getAssetsPath("/jquery_easyui/jquery.min.js")}"></script>
<script type="text/javascript" src="$!{webUtils.getAssetsPath("/jquery_easyui/jquery.easyui.min.js")}"></script>
<script src="$!{webUtils.getAssetsPath("/ace1.3/assets/js/diligrp.form.js")}"></script>