function delPermission(permissionId){
	confirm("确认删除吗",function(){
		ajax("deletepermission.do",{"permissionId" : permissionId},function(res){
			if(res.code == 1)
				alert("删除成功。",1,function(){
					window.location.href = "permissionlist.do";
				});
			else
				alert(res.msg);
		});
	});
}

function checkPermissionAdd(){
	var data = $("#addPermissionForm").serializeJSON();
	if(data.name.isEmpty()){
		top.alert("请输入权限名称。");
		$("#name").focus();
		return false;
	}
	if(data.type=='submenu' && data.pid.isEmpty()){
		top.alert("请选择父权限。");
		return false;
	}
	if(data.code.isEmpty()){
		top.alert("请输入权限编码。");
		$("#code").focus();
		return false;
	}
	if(data.url.isEmpty()){
		top.alert("请输入权限链接。");
		$("#url").focus();
		return false;
	}
	if(data.rank.isEmpty()){
		top.alert("请输入权限级别。");
		$("#rank").focus();
		return false;
	}
	if(isNaN(data['rank'])){
		top.alert("权限级别请输入整数类型")
	}
	if(data.logo.isEmpty()){
		top.alert("请输入权限logo。");
		$("#logo").focus();
		return false;
	}
	ajax("savepermission.do",data,function(res){
		if(res.code == 1)
			top.alert("权限添加成功",1,function(){
				top.window.location.href = "permissionlist.do";
				top.$.closeWindow();
			});
		else
			alert(res.msg);
	});
	return false;
}

function checkPermissionModfiy(){
	var data = $("#modfiyPermissionForm").serializeJSON();
	if(data.name.isEmpty()){
		top.alert("请输入权限名称。");
		$("#name").focus();
		return false;
	}
	if(data.type=='submenu' && data.pid.isEmpty()){
		top.alert("请选择父权限。");
		return false;
	}
	if(data.code.isEmpty()){
		top.alert("请输入权限编码。");
		$("#code").focus();
		return false;
	}
	if(data.url.isEmpty()){
		top.alert("请输入权限链接。");
		$("#url").focus();
		return false;
	}
	if(data.rank.isEmpty()){
		top.alert("请输入权限级别。");
		$("#rank").focus();
		return false;
	}
	if(data.logo.isEmpty()){
		top.alert("请输入权限logo。");
		$("#logo").focus();
		return false;
	}
	ajax("updatepermission.do",data,function(res){
		if(res.code == 1)
			top.alert(res.msg,1,function(){
				top.window.location.href = "permissionlist.do";
				top.$.closeWindow();
			});
		else
			alert(res.msg);
	});
	return false;
}


function getList(page){
	page = page || 1;
	var pageSize = 10, data = {
		"pageNo": page,
		"pageSize": pageSize,
		"name": $("#name").val()
	}, html = "";
	$("#page, #list").empty();
	ajax("ajaxSearchPermissionList.do",data,function(res){
		if(res.code == 1 && res.list.length > 0){
			$.each(res.list, function(index, item){
				html += '<tr>'+
					'<td>'+$.orderNum(page, pageSize, index)+'</td>'+
					'<td>'+item.name+'</td>'+
					'<td>'+item.code+'</td>'+
					'<td>'+item.url+'</td>'+
					'<td>'+item.rank+'</td>'+
                    /*'<td class=\'edit\'><a href="javascript:$.openWindow("修改权限", "editpermission.do?permissionId='+item.permissionId+'", 650, 330, true);" class="btnManage">编辑</a>&nbsp;&nbsp;<a onclick="javascript:delPermission('+item.permissionId+');" class="btnManage">删除</a></td>'+*/
				'</tr>';
			});
			$("#list").html(html);
			var newpage = new createPage(res.count,page,pageSize,3);
			$("#page").html(newpage.pageHtml);
			$('#count').html(res.count);
		}else{
			$("#list").info("暂无数据。");
			$('#count').html(0);
		}
	});
}

pageGo = getList;
