<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();
grid.sortBy("userId", "desc");//依据userId倒序排序
var wid = document.body.clientWidth/2;
var hei = document.body.clientHeight;
//根据返回的值判断是普通用户还是管理员 0管理员 1普通用户
function userRight(e) {
if (e.value == 0) {
return "管理员";
} else {
return "普通用户";
}
}
function onPassrRenderer(e){
var reg = /\w|\d/g;
var va = "";
if(e.value!=""){
va = e.value;
va = va.replace(reg,"*");
}
return va;
}
//获取查询条件
function getValue(){
var userName = mini.get("key").getValue();
return userName;
}
//根据条件查询
function serch(){
grid.load({'userName':getValue()});
}
$("#key").bind("keydown", function (e) {
if (e.keyCode == 13) {
serch();
}
});
//添加用户
function addUser(){
mini.open({
url: mini_JSPath + "../../../handleUser.jsp",
title: "新增用户", width: 600, height: 400,
onload: function () {
var iframe = this.getIFrameEl();
var data = { action: "new"};
iframe.contentWindow.SetData(data);
},
ondestroy: function (action) {
grid.reload();
}
});
}
//修改用户
function editUser(){
var row = grid.getSelected();//获取当前选中行
if(row){
mini.open({
url: mini_JSPath + "../../../handleUser.jsp",
title: "修改用户", width: wid, height: hei,
onload: function () {
var iframe = this.getIFrameEl();
var data = { action: "edit",id:row.userId};
iframe.contentWindow.SetData(data);
},
ondestroy: function (action) {
grid.reload();
}
});
}else{
mini.alert("请选择一条记录");
}
}
//删除用户
function removeUsser(){
var rows = grid.getSelecteds( );//获取当前选中行
if(rows.length>0){
mini.confirm("确定删除记录吗","确定",function(action){
var ids = [];
for( var i = 0;i<rows.length;i++){
var r = rows[i];
ids.push(r.userId);//必须对应的idField="userId"
}
var id = ids.join(",");
if(action=="ok"){
$.post("user/removeUserById.do",{"userId":id},function(data){
if(data.success == "true"){
mini.alert("删除成功");
grid.reload();
}
});
}
});
}else{
mini.alert("请选择记录");
}
}
</script>
</body>
</html>