You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

294 lines
7.7 KiB

$(function() {
//设置工具类按钮
$("#add").click(function(){
$("#addDialog").dialog("open");
});
//删除
$("#delete").click(function(){
var selectRow = $("#dataList").datagrid("getSelected");
//console.log(selectRow);
if(selectRow == null){
$.messager.alert("消息提醒", "请选择数据进行删除!", "warning");
} else{
var RoleMenuid = selectRow.id;
$.messager.confirm("消息提醒", "将删除角色信息,确认继续?", function(r){
if(r){
$.ajax({
type: "post",
url: "../../RoleMenuServlet?method=DeleteRoleMenu",
data: {RoleMenuid: RoleMenuid},
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","删除成功!","info");
//刷新表格
$("#dataList").datagrid("reload");
} else{
$.messager.alert("消息提醒","删除失败!","warning");
return;
}
}
});
}
});
}
});
//设置添加角色窗口
$("#addDialog").dialog({
title: "添加角色",
width: 500,
height: 400,
iconCls: "icon-add",
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
draggable: true,
closed: true,
buttons: [
{
text:'添加',
plain: true,
iconCls:'icon-add',
handler:function(){
var validate = $("#addForm").form("validate");
if(!validate){
$.messager.alert("消息提醒","请检查你输入的数据!","warning");
return;
} else{
//var gradeid = $("#add_gradeList").combobox("getValue");
$.ajax({
type: "post",
url: "../../RoleMenuServlet?method=AddRoleMenu",
data: $("#addForm").serialize(),
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","操作成功!","info");
//关闭窗口
$("#addDialog").dialog("close");
//清空原表格数据
$("#add_name").textbox('setValue', "");
$("#info").val("");
//重新刷新页面数据
//$('#gradeList').combobox("setValue", gradeid);
$('#dataList').datagrid("reload");
} else{
$.messager.alert("消息提醒","添加失败!","warning");
return;
}
}
});
}
}
},
{
text:'重置',
plain: true,
iconCls:'icon-reload',
handler:function(){
$("#add_name").textbox('setValue', "");
//重新加载年级
$("#info").val("");
}
},
]
});
//角色下拉框
$("#rolename").combobox({
url: "../../RoleServlet?method=getRoleList&t="+new Date().getTime()+"&from=combox",
valueField: "id",
textField: "rolename",
onLoadSuccess: function(){
//默认选择第一条数据
var data = $(this).combobox("getData");;
$(this).combobox("setValue", data[0].id);
loadtree();
}
});
// 动态树加载 RoleMenuServlet?method=getRoleMenuList&t="+new Date().getTime(),
//搜索按钮监听事件
$("#search-btn").click(function(){
loadtree();
});
//修改按钮监听事件
$("#edit-btn").click(function(){
var selectRow = $("#dataList").datagrid("getSelected");
//console.log(selectRow);
if(selectRow == null){
$.messager.alert("消息提醒", "请选择数据进行修改!", "warning");
return;
}
$("#editDialog").dialog("open");
});
//设置编辑角色窗口
$("#editDialog").dialog({
title: "编辑角色",
width: 500,
height: 400,
iconCls: "icon-add",
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
draggable: true,
closed: true,
buttons: [
{
text:'确定修改',
plain: true,
iconCls:'icon-add',
handler:function(){
var validate = $("#editForm").form("validate");
if(!validate){
$.messager.alert("消息提醒","请检查你输入的数据!","warning");
return;
} else{
//var gradeid = $("#add_gradeList").combobox("getValue");
$.ajax({
type: "post",
url: "../../RoleMenuServlet?method=EditRoleMenu",
data: $("#editForm").serialize(),
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","修改成功!","info");
//关闭窗口
$("#editDialog").dialog("close");
//清空原表格数据
$("#edit_name").textbox('setValue', "");
$("#edit_info").val("");
//重新刷新页面数据
//$('#gradeList').combobox("setValue", gradeid);
$('#dataList').datagrid("reload");
} else{
$.messager.alert("消息提醒","修改失败!","warning");
return;
}
}
});
}
}
},
{
text:'重置',
plain: true,
iconCls:'icon-reload',
handler:function(){
$("#edit_name").textbox('setValue', "");
//重新加载年级
$("#edit_info").val("");
}
},
],
onBeforeOpen: function(){
var selectRow = $("#dataList").datagrid("getSelected");
//console.log(selectRow);
//设置值
$("#edit_name").textbox('setValue', selectRow.RoleMenuname);
$("#edit-id").val(selectRow.id);
}
});
});
function getChecked() {
if($('#rolename').combobox('getValue')=='')
{
alert('请选择角色');
return;
}
var menuids='';
var nodes = $('#dynamicTree').tree('getChecked',['checked','indeterminate']);
var s = '';
for (var i = 0; i < nodes.length; i++) {
if (s != '') s += ',';
s += nodes[i].text+"id::"+nodes[i].id;
menuids+=nodes[i].id+",";
}
// alert(s);
menuids=menuids.substring(0, menuids.length-1)
$.ajax({
type: "post",
url: "../../RoleMenuServlet?method=AddRoleMenu",
data:{
menuids:menuids,
roleid:$('#rolename').combobox('getValue')
},
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","操作成功!","info");
//关闭窗口
$("#addDialog").dialog("close");
//清空原表格数据
$("#add_name").textbox('setValue', "");
$("#info").val("");
//重新刷新页面数据
//$('#gradeList').combobox("setValue", gradeid);
$('#dataList').datagrid("reload");
} else{
$.messager.alert("消息提醒","添加失败!","warning");
return;
}
}
});
}
function loadtree()
{
//alert($('#rolename').combobox('getValue'));
$("#dynamicTree").tree({
url : "../../MenuServlet?method=getMenuTreeList&t="+new Date().getTime()+"&roleid="+$('#rolename').combobox('getValue'),
checkbox:true,
onClick : function(node) {
// 若所选节点为空则执行请求
if ($('#dynamicTree').tree('isLeaf', node.target)) {
$.ajax({
url : 'getTreeById?id=' + node.id,
type : 'POST',
success : function(data) {
$('#dynamicTree').tree('append', {
parent : node.target,
data : data
})
}
})
}
// 展开/折叠
if (node.state === 'open') {
$('#dynamicTree').tree('collapse', node.target);
} else {
$('#dynamicTree').tree('expand', node.target);
}
}
})
}