您的位置:首页 > Web前端 > JavaScript

Extjs3.0角色权限管理系统-角色管理模块篇

2017-11-17 23:02 549 查看
1.角色管理功能模块效果图如下



2.角色管理功能->角色授权效果图如下



角色管理模块后台controller代码

package com.gsww.controller.sys;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springside.modules.web.Servlets;

import com.gsww.controller.BaseController;
import com.gsww.entity.sys.SysMenu;
import com.gsww.entity.sys.SysRoleInfo;
import com.gsww.entity.sys.SysRoleMenu;
import com.gsww.entity.sys.SysUserRole;
import com.gsww.service.sys.SysRoleInfoService;
import com.gsww.service.sys.SysRoleMenuService;
import com.gsww.service.sys.SysUserRoleService;
import com.gsww.util.PageUtils;
import com.gsww.util.TimeHelper;

/**
* 系统角色管理
* @author Administrator
*
*/
@Controller
@RequestMapping(value = "/sysRole")
public class SysRoleInfoController extends BaseController{

@Autowired
private SysRoleInfoService sysRoleInfoService;

@Autowired
private SysUserRoleService sysUserRoleService;

@Autowired
private SysRoleMenuService sysRoleMenuService;

/*
* 返回系统系统角色管理页面
*/
@RequestMapping(value = "/getSysRoleIndex")
public String getSysRoleIndex(HttpServletRequest request,
HttpServletResponse response) throws Exception{
return "sysManage/sysRoleInfo";
}

/*
* 获取系统角色分页列表
*/
@RequestMapping(value = "/getSysRoleInfoPage",method = RequestMethod.GET)
public void getSysRoleInfoPage(@RequestParam(value = "start", defaultValue = "1") int page,
@RequestParam(value = "limit", defaultValue = LIMIT) int pageSize,
@RequestParam(value = "orderField", defaultValue = "createTime") String orderField,
@RequestParam(value = "orderSort", defaultValue = "DESC") String orderSort,
@RequestParam(value = "roleName", defaultValue = "") String roleName,
@RequestParam(value = "findNowPage", defaultValue = "false") String findNowPage,
Model model,HttpServletRequest request,HttpServletResponse response){
try {
//初始化分页数据
page = page/pageSize + 1;
PageUtils pageUtils=new PageUtils(page,pageSize,orderField,orderSort);
PageRequest pageRequest=super.buildPageRequest(request,pageUtils,SysRoleInfo.class,findNowPage);
//获取页面的参数
Map<String, Object> searchParams = Servlets.getParametersStartingWith(request, "search_");
if(StringUtils.isNotBlank(roleName)){
searchParams.put("LIKE_roleName", roleName);
}
Specification<SysRoleInfo> spec=super.toSpecification(searchParams, SysRoleInfo.class);
//分页
Page<SysRoleInfo> sysRolePage = sysRoleInfoService.getSysRoleInfoPage(spec, pageRequest);
Map<String,Object> dataMap = new HashMap<String,Object>();
dataMap.put("data", sysRolePage.getContent());
dataMap.put("count", sysRolePage.getTotalElements());
this.getJson(response, dataMap);
} catch (Exception e) {
e.printStackTrace();
}
}

/*
* 系统角色新增
*/
@RequestMapping(value = "/sysRoleInfoSave",method = RequestMethod.POST)
public void sysRoleInfoSave(HttpServletRequest request,
HttpServletResponse response,SysRoleInfo sysRoleInfo) throws Exception{
String RoleId = sysRoleInfo.getRoleId();
if(StringUtils.isBlank(RoleId)){
sysRoleInfo.setCreateTime(TimeHelper.getCurrentTime());
}else{
sysRoleInfo.setUpdateTime(TimeHelper.getCurrentTime());
}
sysRoleInfoService.sysRoleInfoSave(sysRoleInfo);
}

/*
* 系统角色删除
*/
@RequestMapping(value = "/sysRoleInfoDelete",method = RequestMethod.GET)
public void sysRoleInfoDelete(HttpServletRequest request,
HttpServletResponse response,String idStr) throws Exception{
if(StringUtils.isNotBlank(idStr)){
String[] arr = idStr.split(",");
int delSum = 0;
for (String roleId : arr) {
//判断该角色下是否有用户
List<SysUserRole> sysurList = sysUserRoleService.getSysUserRoleByRoleId(roleId);
if(sysurList.size()==0){
sysRoleInfoService.sysRoleInfoDelet(roleId);
delSum++;
}
}
String message = "您成功删除了"+delSum+"条记录!";
int failSum = arr.length-delSum;
if(failSum>0){
message+=","+failSum+"条记录由于下面有用户,删除失败!";
}
this.getJson(response, message);
}
}

/*
* 系统角色启用停用
*/
@RequestMapping(value = "/sysRoleInfoUpdate",method = RequestMethod.GET)
public void sysRoleInfoUpdate(HttpServletRequest request,
HttpServletResponse response,String idStr,String roleState) throws Exception{
if(StringUtils.isNotBlank(idStr)){
String[] arr = idStr.split(",");
int sucSum = 0;
for (String roleId : arr) {
SysRoleInfo sysRoleInfo = sysRoleInfoService.getSysRoleInfoByRoleId(roleId);
if(sysRoleInfo!=null){
String rstate = sysRoleInfo.getRoleState();
if(!rstate.equals(roleState)){
sysRoleInfoService.sysRoleInfoUpdate(roleState, roleId);
sucSum++;
}
}
}
String roleStateText = roleState!=null&&roleState.equals("1")?"启用":"停用";
String message = "您成功"+roleStateText+sucSum+"条记录!";
int failSum = arr.length-sucSum;
if(failSum>0){
message+=","+failSum+"条记录由于已"+roleStateText+","+roleStateText+"失败!";
}
this.getJson(response, message);
}
}

/*
* 新增用户分配角色获取数据
*/
@RequestMapping(value = "/getSysUserRoleJson",method = RequestMethod.POST)
public void getSysUserRoleJson(HttpServletRequest request,
HttpServletResponse response,String roleId) throws Exception{
//获取有效的角色信息
List<SysRoleInfo> lr = sysRoleInfoService.getSysRoleInfoList("1");
List<SysMenu> listRoles = new ArrayList<SysMenu>();
if(lr.size()>0){
for (SysRoleInfo sysRoleInfo : lr) {
SysMenu syMenu = new SysMenu();
syMenu.setId(sysRoleInfo.getRoleId());
syMenu.setText(sysRoleInfo.getRoleName());
syMenu.setLeaf("true");
syMenu.setMenuPid("0");
listRoles.add(syMenu);
}
JSONArray jsonarr = JSONArray.fromObject(listRoles);
this.getJson(response, jsonarr.toString());
}
}

/*
* 根据角色ID获取授权树Json
*/
@RequestMapping(value = "/getAuthTreeJsonByRoleId",method = RequestMethod.GET)
public void getAuthTreeJsonByRoleId(HttpServletRequest request,
HttpServletResponse response,String roleId) throws Exception{
if(StringUtils.isNotBlank(roleId)){
List<SysRoleMenu> sysrmList = sysRoleMenuService.getSysRoleMenuByRoleId(roleId);
String menuIds = "";
for (SysRoleMenu sysRoleMenu : sysrmList) {
menuIds += sysRoleMenu.getMenuId()+",";
}
this.getJson(response, menuIds);
}
}

/*
* 根据角色ID保存角色授权
*/
@RequestMapping(value = "/sysAuthTreeJsonSave",method = RequestMethod.GET)
public void sysAuthTreeJsonSave(HttpServletRequest request,
HttpServletResponse response,String roleId,String idStr) throws Exception{
if(StringUtils.isNotBlank(roleId)&&StringUtils.isNotBlank(idStr)){
//在进行授权之前先删除原先的角色授权
List<SysRoleMenu> sysrmList = sysRoleMenuService.getSysRoleMenuByRoleId(roleId);
if(sysrmList.size()>0){
for (SysRoleMenu sysRoleMenu : sysrmList) {
sysRoleMenuService.sysRoleMenuDelete(sysRoleMenu);
}
}
String[] arr =idStr.split(",");
//进行角色授权
for (int i = 0; i < arr.length; i++) {
SysRoleMenu sysRoleMenu = sysRoleMenuService.getSysRoleMenu(roleId,arr[i]);
if(null==sysRoleMenu){
SysRoleMenu sysrm = new SysRoleMenu();
sysrm.setRoleId(roleId);
sysrm.setMenuId(arr[i]);
sysRoleMenuService.sysRoleMenuSave(sysrm);
}
}
}
}
}角色管理模块后台jsp代码
<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
<%@ include file="/resource/include/meta.jsp"%>
<head>
<title>角色管理</title>
<script type="text/javascript" src="${ctx}/resource/common/js/sysManage/sysRoleInfo.js"></script>
</head>
<body>
</body>
</html>
角色管理模块后台js代码

/********************************************Ext入口函数,相当于java中的主函数开始********************************************/
Ext.onReady(function() {
Ext.QuickTips.init();
var roleStateStore = new Ext.data.ArrayStore({
fields : ['key', 'value'],
data : [['启用','1'],['停用', '0']]
});
var record = Ext.data.Record.create([
{name:'roleId'},
{name:'roleName'},
{name:'roleState'},
{name:'createTime'},
{name:'updateTime'},
{name:'roleDesc'}
]);
/*****************************      表格数据代理Store开始       *******************************************/
var dataStore = new Ext.data.Store({
restful : true,
autoLoad : true,
proxy : new Ext.data.HttpProxy({
url:basepath+'/sysRole/getSysRoleInfoPage',
method : 'GET'
}),
reader : new Ext.data.JsonReader({
successProperty : 'success',
idProperty : 'ID',
messageProperty : 'message',
root : 'data',
totalProperty : 'count'
}, record)
});
/*****************************      表格数据代理Store结束       *******************************************/

/*****************************      定义自动当前页行号开始       *******************************************/
var rownum = new Ext.grid.RowNumberer({
header : 'No.',
width : 28
});
/*****************************      定义自动当前页行号结束       *******************************************/

/*****************************      定义复选框开始       *******************************************/
var sm = new Ext.grid.CheckboxSelectionModel();
/*****************************      定义复选框结束       *******************************************/

/*****************************      设置分页参数开始       *******************************************/
var pagesize_combo = new Ext.form.ComboBox({
name : 'pagesize',
triggerAction : 'all',
mode : 'local',
store : new Ext.data.ArrayStore({
fields : ['value', 'text'],
data : [ [ 10, '10条/页' ], [ 20, '20条/页' ], [ 50, '50条/页' ],
[ 100, '100条/页' ], [ 250, '250条/页' ],
[ 500, '500条/页' ] ]
}),
valueField : 'value',
displayField : 'text',
value: 20,
editable : false,
width : 85
});

var bbar = new Ext.PagingToolbar({					//分页组件
pageSize : parseInt(pagesize_combo.getValue()),
store : dataStore,
displayInfo : true,
displayMsg : '显示{0}条到{1}条,共{2}条',
emptyMsg : "没有符合条件的记录",
items : ['-', '  ', pagesize_combo]
});
pagesize_combo.on("select", function(comboBox) {
bbar.pageSize = parseInt(pagesize_combo.getValue()),
dataStore.reload({
params : {
start : 0,
limit : parseInt(pagesize_combo.getValue())
}
});
});
/*****************************       设置分页参数结束       *******************************************/

/*****************************************   新增editForm开始  **************************************************/
var editForm = new Ext.form.FormPanel({
formId:'editForm',
frame:true,
border:false,
labelAlign:'center',
standardSubmit:false,
layout : 'form',//*form布局
items : [{
layout:'column',
items : [{
columnWidth : .5,					//列宽为25%
layout : 'form',					//*form布局
items: [{
fieldLabel : '<font color="red">*</font>角色名称',
name : 'roleName',
xtype : 'textfield', 			// 设置为数字输入框类型
labelStyle : 'text-align:right;',//右对齐
emptyText:'请您输入角色名称',	//水印提示
allowBlank:false,               //allowBlank : false就是已经定义好的校验规则,extjs getForm().isValid()函数会调用已经定义的校验规则来验证输入框中的值
anchor : '90%'
}]
},{
columnWidth : .5,					//列宽为25%
layout : 'form',					//*form布局
items : [{ //下拉框
id : 'rState',
xtype : 'combo',
fieldLabel : '<font color="red">*</font>角色状态',
name : 'rState',
store : roleStateStore,			//*加载客户类型Store
//下列属性在复用时一般不作修改
editable : false,				//false为不可编辑,页面效果为点击下拉框空白处直接触发下拉角色
labelStyle : 'text-align:right;',//fieldLabel右对齐
triggerAction : 'all',			//*触发器被激活时执行allQuery查询
displayField : 'key',			//*下列列表选项的中文名,对应Store中的value
valueField : 'value',				//*下列列表选项对应的key值,对应Store中的key
mode : 'local',					//*读取本地数据
emptyText:'请您选择',				//*水印提示
resizable : false,				//*下拉框下部的缩放柄,可改变下拉框大小
allowBlank:false,               //allowBlank : false就是已经定义好的校验规则,extjs getForm().isValid()函数会调用已经定义的校验规则来验证输入框中的值
anchor : '90%'
}]
}]
},{
columnWidth : 1,					//列宽为25%
layout : 'form',					//*form布局
items: [{
xtype : 'htmleditor',
height : 140,
width : 700,
fontFamilies : ['宋体','黑体','隶书','微软雅黑','Arial','Courier New','Tahoma','Times New Roman','Verdana'],
defaultFont: '宋体',
defaultLinkValue:"http://www.",
enableAlignments:true,
enableColors:true,
enableFont:true,
enableFontSize:true,
enableFormat:true,
enableLinks:true,
enableSourceEdit:true,
fieldLabel:'角色描述',
labelStyle:'text-align:right;',
name:'roleDesc',
anchor:'95%'
}]
},{
id:'roleId',
name : 'roleId',
xtype : 'hidden'
},{
id:'createTime',
name : 'createTime',
xtype : 'hidden'
},{
id:'roleState',
name : 'roleState',
xtype : 'hidden'
}]
});
/*****************************************   新增editForm结束  **************************************************/

/*****************************************   新增和修改editWindow窗口开始  **************************************************/
var editWindow=new Ext.Window({
id:'editWindow',
width : 880,
height :350,
closable : true,
resizable : false,
collapsible : false,
draggable : true,
closeAction : 'hide',
title : '新增系统角色',
modal : true,
animCollapse : false,
border : false,
closable : true,
animateTarget : Ext.getBody(),
constrain : true,
items : [editForm],
buttonAlign:'center',
buttons:[{
text:'保存',
handler:function(){
if(!editForm.getForm().isValid()){
Ext.MessageBox.alert('系统提示', '请您正确输入各项信息!');
return false;
}
var pars = editForm.getForm().getFieldValues();
//提交表单的方法
var value = Ext.getCmp("rState").value;	//取到valueField中的值
Ext.getCmp("roleState").setValue(value);
editForm.getForm().submit({
url : basepath + '/sysRole/sysRoleInfoSave',
method : 'POST',
waitTilte : '系统提示',
waitMsg : '正在提交数据,请稍后!',
success:function(response){
Ext.Msg.alert('系统提示', '保存成功!',function(btn){
if(btn == 'ok'){
dataStore.load({
params : {
start : 0,
limit : parseInt(pagesize_combo.getValue())
}
});
}
});
},
failure : function(form, action){
Ext.MessageBox.alert('系统提示', '保存失败!');
},
});
editWindow.hide();
}
},{
text: '关闭',
handler:function(){
editWindow.hide();
}
}]
});
/*****************************************   新增和修改editWindow窗口结束  **************************************************/

/*****************************************   详情detailForm开始  **************************************************/
var detailForm=new Ext.FormPanel({
formId:'detailForm',
frame:true,
border:false,
labelAlign:'right',
standardSubmit:false,
width : '100%',
layout:'form',
items : [{
layout:'column',
items : [{
columnWidth : .5,
layout : 'form',
items : [{
xtype : 'textfield',
fieldLabel : '角色ID',
name : 'roleId',
editable : false,
anchor : '90%'
}]
},{
columnWidth : .5,
layout : 'form',
items : [{
xtype : 'textfield',
fieldLabel : '角色名称',
name : 'roleName',
readOnly:true,
editable : false,
anchor : '90%'
}]
},{
columnWidth : .5,
layout : 'form',
items : [{
xtype : 'combo',
fieldLabel : '角色状态',
labelStyle:{
width:'120px'
},
name : 'roleState',
allowBlank:false,
mode:'local',
emptyText:'请您选择',
store:roleStateStore,
triggerAction:'all',
valueField:'value',
editable : false,
displayField:'key',
anchor : '90%'
},{
xtype : 'textfield',
fieldLabel : '更新时间',
name : 'updateTime',
readOnly:true,
editable : false,
anchor : '90%'
}]
},{
columnWidth : .5,
layout : 'form',
items : [{
xtype : 'textfield',
fieldLabel : '创建时间',
name : 'createTime',
readOnly:true,
editable : false,
anchor : '90%'
}]
}]
},{
columnWidth : .5,
layout : 'form',
items : [{
xtype : 'htmleditor',
height : 140,
fontFamilies : ['宋体','黑体','隶书','微软雅黑','Arial','Courier New','Tahoma','Times New Roman','Verdana'],
defaultFont: '宋体',
defaultLinkValue:"http://www.",
enableAlignments:true,
enableColors:true,
enableFont:true,
enableFontSize:true,
enableFormat:true,
enableLinks:true,
enableLists:true,
enableSourceEdit:true,
id:'noticeContentBaby',
fieldLabel : '角色描述',
readOnly:true,
name : 'roleDesc',
anchor : '95%'
}]
}]
});
/*****************************************   详情detailForm结束  **************************************************/

/*****************************************   详情detailWindow窗口开始  **************************************************/
var detailWindow = new Ext.Window({
id:'detailWindow',
width : 880,
height :350,
closable : true,
resizable : false,
collapsible : false,
draggable : true,
closeAction : 'hide',
title : '系统角色详情',
modal : true,
animCollapse : false,
border : false,
closable : true,
animateTarget : Ext.getBody(),
constrain : true,
items : [detailForm],
buttonAlign:'center',
buttons : [{
text : '关闭',
handler : function() {
detailWindow.hide();
dataStore.reload();
}
}]
});
/*****************************************   详情detailWindow窗口结束  **************************************************/

/*****************************************   授权authorityWindow窗口结束  **************************************************/
var roleId = "",menuIds = "";
var authorityPanel = new Ext.tree.TreePanel({
id: 'menuTree',
border:false,
rootVisible: false,
loader: new Ext.tree.TreeLoader({
url: basepath + '/sysMenu/getAuthSysMenuInfoJson'
}),
root: new Ext.tree.AsyncTreeNode({
text: 'root',
}),
listeners: {
beforeload:function(node){
if(""!=roleId){
//在树加载之前,获取当前编辑角色的菜单id
Ext.Ajax.request({
url : basepath	+ '/sysRole/getAuthTreeJsonByRoleId?roleId=' + roleId,
success : function(response) {
menuIds = response.responseText;
},
failure : function() {
Ext.MessageBox.alert('系统提示', '获取数据失败!');
}
});
}
},
load:function(node){
//在树加载完成之后给编辑角色动态给角色授权树赋值
if(null!=menuIds){
var arr = menuIds.split(",");
var allNodes = node.childNodes;
for(var i = 0; i < allNodes.length; i++){
allNodes[i].expanded=true;
var menuId = allNodes[i].attributes.id;
allNodes[i].attributes.checked=false;
for ( var pj = 0; pj < arr.length; pj++) {
if(menuId==arr[pj]){
allNodes[i].attributes.checked=true;
}
}
var childNodes = allNodes[i].attributes.children;
for(var c=0;c<childNodes.length;c++){
childNodes[c].checked=false;
for ( var cj = 0; cj < arr.length; cj++) {
if(menuId==arr[cj]){
childNodes[c].checked=true;
}
}
}
}
}
},
checkchange: function(node,checked) {
checkParent(node, checked);
checkChild(node, checked);
}
}
});
//这个方法是选择父节点,自动选中所有的子节点
function checkParent(node, checked) {
if (node.hasChildNodes()) {
node.eachChild(function(child) {
child.attributes.checked = checked;
var cb = child.ui.checkbox;
if (cb){
cb.checked = checked;
}
checkParent(child, checked);
});
};
}
//这个方法是选择子节点,自动选中父节点的父节点
function checkChild(node, checked) {
var parentNode = node.parentNode;
if(checked){
if (parentNode != undefined) {
parentNode.attributes.checked = checked;
var cb = parentNode.ui.checkbox;
if (cb){
cb.checked = checked;
}
checkChild(parentNode, checked);
}
}else{
cancelCurrNode(node,parentNode, checked);
}
}
//取消选中当前节点,关联父节点
function cancelCurrNode(node,parentNode,checked) {
if (parentNode.hasChildNodes()) {
var bool = false;
//遍历当前节点的兄弟节点
parentNode.eachChild(function(child) {
//排除当前节点
if(node.id!=child.id){
bool = child.attributes.checked;
if(bool){
return false;
}
}
});
if(!bool){
parentNode.attributes.checked = checked;
var cb = parentNode.ui.checkbox;
if (cb){
cb.checked = checked;
}
cancelCurrNode(parentNode,parentNode.parentNode,checked);
}
};
}
var authorityWindow = new Ext.Window({
width : 350,
height :400,
modal : true,
border : false,
closable : true,
autoScroll: true,
draggable : true,
constrain : true,
closable : true,
resizable : false,
collapsible : false,
animCollapse : false,
closeAction : 'hide',
id:'authorityWindow',
title : '系统角色授权',
animateTarget : Ext.getBody(),
items : [authorityPanel],
bodyStyle: 'background:#fff;font-size:20px;font-family:"微软雅黑";font-weight:900;color:#fff;',
buttonAlign:'center',
buttons : [{
text : '保存',
handler : function() {
var idStr = "";
var treeNodes = Ext.getCmp('menuTree').getChecked();
for(var i=0;i<treeNodes.length;i++){
if(treeNodes[i].text!='root'){
idStr+=treeNodes[i].id + ',';
}
}
if(""!=idStr&&""!=roleId){
//角色授权操作提交到数据库
Ext.Ajax.request({
url : basepath	+ '/sysRole/sysAuthTreeJsonSave?roleId=' + roleId + '&idStr=' + idStr,
waitTilte : '系统提示',
waitMsg : '正在进行授权,请您等待...', // 显示读盘的动画效果,执行完成后效果消失
success : function(response) {
Ext.Msg.alert("系统提示", "授权成功!");
authorityWindow.hide();
},
failure : function() {
Ext.MessageBox.alert('系统提示', '操作失败!');
}
});
}else{
Ext.MessageBox.alert('系统提示', '必须选择一个菜单,请您先授权...');
}
}
},{
text : '关闭',
handler : function() {
authorityWindow.hide();
}
}]
});
/*****************************************   授权authorityWindow窗口结束  **************************************************/

/*****************************************  系统角色信息表格开始  **************************************************/
var grid = new Ext.grid.GridPanel({
title : '系统角色信息',
store : dataStore,
region : 'center',
stripeRows : true,
border : false,
tbar : [
{
text : '新增',
iconCls : 'addIconCss',   //定义图标
handler : function(){	  //调用新增方法
editWindow.setTitle("新增系统角色");
editForm.getForm().reset();
editWindow.restore();
editWindow.show();
}
}, '-', {
text : '修改',
iconCls : 'editIconCss',
handler : function() {
if(grid.selModel.hasSelection()){
// 得到被选择的行
var record = grid.getSelectionModel();
if (record.selections.length>1) {
Ext.MessageBox.alert('系统提示', '请您选择其中一条记录进行修改!');
return false;
} else {
editWindow.setTitle("修改系统角色");
editForm.getForm().loadRecord(record.getSelected());
editWindow.restore();
editWindow.show();
}
}else{
Ext.Msg.alert("系统提示", "请您先选择一条要修改的记录!");
}
}
}, '-', {
text : '删除',
iconCls : 'deleteIconCss',
handler : function() {
var checkedNodes = grid.getSelectionModel().selections.items;
if(checkedNodes.length==0){
Ext.Msg.alert("系统提示", "请您先选择一条要删除的记录!");
return ;
}else{
Ext.MessageBox.confirm("系统提示","您确定要删除吗?",
function(button,text){
if( button == 'yes'){
var idStr = "";
for(var i=0;i<checkedNodes.length;i++){
var roleId = checkedNodes[i].data.roleId;
idStr +=roleId+",";
}
Ext.Ajax.request({
url : basepath	+ '/sysRole/sysRoleInfoDelete?idStr=' + idStr,
waitTilte : '系统提示',
waitMsg : '正在删除数据,请您等待...', // 显示读盘的动画效果,执行完成后效果消失
success : function(response) {
Ext.Msg.alert("系统提示", response.responseText);
dataStore.reload();
},
failure : function() {
Ext.MessageBox.alert('系统提示', '操作失败!');
}
});
}
}
);
}
}
}, '-', {
text : '详情',
iconCls : 'detailIconCss',
handler : function() {
if(grid.selModel.hasSelection()){
var _record = grid.getSelectionModel();
detailForm.getForm().loadRecord(_record.getSelected());
detailWindow.restore();
detailWindow.show();
}else{
Ext.Msg.alert("系统提示", "请您先选择一条要查看的记录!");
}
}
},'-', {
text : '启用',
iconCls : 'optionIconCss',
handler : function() {
if(grid.selModel.hasSelection()){
var idStr = "";
var _record = grid.getSelectionModel().selections.items;
for(var i=0;i<_record.length;i++){
var roleId = _record[i].data.roleId;
idStr +=roleId+",";
}
Ext.Ajax.request({
url : basepath	+ '/sysRole/sysRoleInfoUpdate?idStr=' + idStr+'&roleState=1',
waitTilte : '系统提示',
waitMsg : '正在启用数据,请您等待...', // 显示读盘的动画效果,执行完成后效果消失
success : function(response) {
Ext.Msg.alert("系统提示", response.responseText);
dataStore.reload();
},
failure : function() {
Ext.MessageBox.alert('系统提示', '操作失败!');
}
});
}else{
Ext.Msg.alert("系统提示", "请您先选择一条要启用的记录!");
}
}
},'-', {
text : '停用',
iconCls : 'optionIconCss',
handler : function() {
if(grid.selModel.hasSelection()){
var idStr = "";
var _record = grid.getSelectionModel().selections.items;
for(var i=0;i<_record.length;i++){
var roleId = _record[i].data.roleId;
idStr +=roleId+",";
}
Ext.Ajax.request({
url : basepath	+ '/sysRole/sysRoleInfoUpdate?idStr=' + idStr+'&roleState=0',
waitTilte : '系统提示',
waitMsg : '正在停用数据,请您等待...', // 显示读盘的动画效果,执行完成后效果消失
success : function(response) {
Ext.Msg.alert("系统提示", response.responseText);
dataStore.reload();
},
failure : function() {
Ext.MessageBox.alert('系统提示', '操作失败!');
}
});
}else{
Ext.Msg.alert("系统提示", "请您先选择一条要停用的记录!");
}
}
},'-', {
text : '授权',
iconCls : 'optionIconCss',
handler : function() {
if(grid.selModel.hasSelection()){
var _record = grid.getSelectionModel();
if (_record.selections.length>1) {
Ext.MessageBox.alert('系统提示', '请您选择其中一条记录进行授权!');
return false;
} else {
var _record = grid.getSelectionModel().selections.items;
//保存角色roleId
roleId = _record[0].data.roleId;
var tree = Ext.getCmp('menuTree');
tree.getRootNode().reload();
authorityWindow.restore();
authorityWindow.show();
}
}else{
Ext.Msg.alert("系统提示", "请您先选择一条要授权的记录!");
}
}
},{
xtype : 'textfield',
id : 'roleName',
name : 'roleName',
emptyText : '请您输入要查询的角色名称',
anchor : '90%'
},{
text : '搜索',
iconCls : 'searchIconCss',
handler : function(){
var roleName = Ext.getCmp("roleName").getValue();
dataStore.load({
params : {
start : 0,
roleName :roleName,
limit : parseInt(pagesize_combo.getValue())
}
});
}
},{
text : '重置',
iconCls : 'resetIconCss',
handler : function(){
Ext.getCmp("roleName").setValue('');
dataStore.load({
params : {
start : 0,
limit : parseInt(pagesize_combo.getValue())
}
});
}
}
],
cm : new Ext.grid.ColumnModel([					//定义列模型
rownum,sm,
{header : 'ID',dataIndex : 'roleId',sortable : true/*表示为可在该列上进行排列*/,hidden : true},
{header : '角色名称',dataIndex : 'roleName',width : 180,sortable : true},
{header : '角色状态',dataIndex : 'roleState',width : 80,sortable : true,
renderer : function(value){
if(value=="1"){
return "<span style='color:green;'>有效</span>";
}else if( value=="0"){
return "<span style='color:red;'>无效</span>";
}
}
},
{header : '创建时间',dataIndex : 'createTime',width : 150,sortable : true},
{header : '更新时间',dataIndex : 'updateTime',width : 150,sortable : true},
{header : '角色描述',dataIndex : 'roleDesc',width : 250,sortable : true}
]),
sm : sm,		//定义复选框
bbar : bbar,
viewConfig : {
},
loadMask : {
msg : '正在加载表格数据,请您稍等...'
},
listeners:{
rowdblclick:function(grid,row){
var _record = grid.getSelectionModel();
if (_record.selections.length>1) {
Ext.MessageBox.alert('系统提示', '请您选择其中一条记录进行查看!');
return false;
} else {
detailForm.getForm().loadRecord(_record.getSelected());
dataStore.load({
params : {
id :_record.getSelected().data.id
},
callback:function(){
detailWindow.show();
}
});
}
}
}
});
/*****************************************  系统角色信息表格结束  **************************************************/

/*****************************************   布局模型开始  **************************************************/
var viewport = new Ext.Viewport({
layout:'fit',
items:[{
layout : 'border',
items: [grid]
}]
});
/*****************************************   布局模型结束  **************************************************/
});
/********************************************Ext入口函数,相当于java中的主函数结束********************************************/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐