2016-10-24 22:10:17 +08:00
|
|
|
|
$(function () {
|
2016-11-16 11:00:12 +08:00
|
|
|
|
var $dialogUser = $("#dialogUser");
|
|
|
|
|
var $dialogGroup = $("#dialogGroup");
|
|
|
|
|
var $dialogMenu = $('#dialogMenu');
|
|
|
|
|
var $dialogSubMenu = $('#dialogSubMenu').find('.modal-content');
|
|
|
|
|
var $btnSubmitMenu = $('#btnSubmitMenu');
|
|
|
|
|
var $nestMenu = $('#nestable_menu');
|
|
|
|
|
var $nestMenuInput = $nestMenu.find('div.dd3-content');
|
|
|
|
|
$nestMenuInput.find('label:last').hide();
|
|
|
|
|
|
2016-10-24 22:10:17 +08:00
|
|
|
|
var bsa = new BootstrapAdmin({
|
|
|
|
|
url: '../api/Roles',
|
|
|
|
|
dataEntity: new DataEntity({
|
|
|
|
|
map: {
|
|
|
|
|
ID: "roleID",
|
|
|
|
|
RoleName: "roleName",
|
2016-11-09 00:34:47 +08:00
|
|
|
|
Description: "roleDesc"
|
2016-10-24 22:10:17 +08:00
|
|
|
|
}
|
2016-10-28 20:18:12 +08:00
|
|
|
|
}),
|
|
|
|
|
click: {
|
|
|
|
|
assign: [{
|
|
|
|
|
id: 'btn_assignUser',
|
|
|
|
|
click: function (row) {
|
|
|
|
|
User.getUsersByRoleId(row.ID, function (data) {
|
2016-11-16 11:00:12 +08:00
|
|
|
|
$dialogUser.find("div.modal-header").find('h4').text($.format('{0}-用户授权窗口', row.RoleName));
|
|
|
|
|
$dialogUser.find('form').html(data);
|
|
|
|
|
$dialogUser.modal('show');
|
2016-10-28 20:18:12 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
id: 'btn_assignGroup',
|
|
|
|
|
click: function (row) {
|
2016-10-29 09:24:55 +08:00
|
|
|
|
Group.getGroupsByRoleId(row.ID, function (data) {
|
2016-11-16 11:00:12 +08:00
|
|
|
|
$dialogGroup.find("div.modal-header").find("h4").text($.format('{0}-部门授权窗口', row.RoleName));
|
|
|
|
|
$dialogGroup.find('form').html(data);
|
|
|
|
|
$dialogGroup.modal('show');
|
2016-10-29 09:24:55 +08:00
|
|
|
|
})
|
2016-10-28 20:18:12 +08:00
|
|
|
|
}
|
|
|
|
|
}, {
|
2016-10-31 11:13:46 +08:00
|
|
|
|
id: 'btnSubmitUser',
|
2016-10-28 20:18:12 +08:00
|
|
|
|
click: function (row) {
|
|
|
|
|
var roleId = row.ID;
|
2016-11-16 11:00:12 +08:00
|
|
|
|
var userIds = $dialogUser.find(':checked').map(function (index, element) {
|
2016-10-28 20:18:12 +08:00
|
|
|
|
return $(element).val();
|
|
|
|
|
}).toArray().join(',');
|
2016-10-28 21:26:13 +08:00
|
|
|
|
User.saveUsersByRoleId(roleId, userIds, { modal: 'dialogUser' });
|
2016-10-28 20:18:12 +08:00
|
|
|
|
}
|
2016-10-29 09:24:55 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
2016-10-31 11:13:46 +08:00
|
|
|
|
id: 'btnSubmitGroup',
|
2016-10-29 09:24:55 +08:00
|
|
|
|
click: function (row) {
|
|
|
|
|
var roleId = row.ID;
|
2016-11-16 11:00:12 +08:00
|
|
|
|
var groupIds = $dialogGroup.find(':checked').map(function (index, element) {
|
2016-10-29 09:24:55 +08:00
|
|
|
|
return $(element).val();
|
|
|
|
|
}).toArray().join(',');
|
2016-11-09 00:34:47 +08:00
|
|
|
|
Group.saveGroupsByRoleId(roleId, groupIds, { modal: 'dialogGroup' });
|
2016-11-07 21:41:17 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'btn_assignMenu',
|
|
|
|
|
click: function (row) {
|
|
|
|
|
Menu.getMenusByRoleId(row.ID, function (data) {
|
2016-11-16 11:00:12 +08:00
|
|
|
|
$dialogSubMenu.find("div.modal-header").find('h4').text($.format('{0}-菜单授权窗口', row.RoleName));
|
|
|
|
|
$btnSubmitMenu.data('type', 'menu');
|
2016-11-14 20:44:08 +08:00
|
|
|
|
// set checkbox status
|
2016-11-16 11:00:12 +08:00
|
|
|
|
var menus = $nestMenu.find('input:checkbox');
|
2016-11-14 20:44:08 +08:00
|
|
|
|
menus.removeProp('checked');
|
|
|
|
|
$.each(data, function (index, item) {
|
|
|
|
|
var selector = $.format('[value={0}]', item.ID);
|
|
|
|
|
menus.filter(selector).prop('checked', 'checked');
|
|
|
|
|
});
|
2016-11-16 11:00:12 +08:00
|
|
|
|
$dialogSubMenu.show();
|
|
|
|
|
$dialogMenu.modal('show');
|
2016-11-07 21:41:17 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'btnSubmitMenu',
|
|
|
|
|
click: function (row) {
|
|
|
|
|
var roleId = row.ID;
|
2016-11-16 11:00:12 +08:00
|
|
|
|
var type = $btnSubmitMenu.data('type');
|
2016-11-07 21:41:17 +08:00
|
|
|
|
switch (type) {
|
|
|
|
|
case "menu":
|
2016-11-16 11:00:12 +08:00
|
|
|
|
var menuIds = $nestMenuInput.find('input:checkbox:checked').map(function (index, element) {
|
2016-11-07 21:41:17 +08:00
|
|
|
|
return $(element).val();
|
|
|
|
|
}).toArray().join(',');
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Menu.saveMenusByRoleId(roleId, menuIds, { modal: 'dialogMenu' });
|
2016-10-29 09:24:55 +08:00
|
|
|
|
}
|
2016-10-28 20:18:12 +08:00
|
|
|
|
}]
|
|
|
|
|
}
|
2016-10-24 22:10:17 +08:00
|
|
|
|
});
|
|
|
|
|
|
2016-11-14 22:12:23 +08:00
|
|
|
|
$nestMenu.nestable();
|
2016-11-07 21:41:17 +08:00
|
|
|
|
|
2016-10-24 22:10:17 +08:00
|
|
|
|
$('table').smartTable({
|
|
|
|
|
url: '../api/Roles', //请求后台的URL(*)
|
|
|
|
|
sortName: 'RoleName',
|
|
|
|
|
queryParams: function (params) { return $.extend(params, { roleName: $("#txt_search_name").val(), description: $("#txt_role_desc").val() }); }, //传递参数(*)
|
|
|
|
|
columns: [{ checkbox: true },
|
|
|
|
|
{ title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
|
|
|
|
|
{ title: "角色名称", field: "RoleName", sortable: true },
|
|
|
|
|
{ title: "角色描述", field: "Description", sortable: false }
|
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// validate
|
|
|
|
|
$('#dataForm').autoValidate({
|
|
|
|
|
roleName: {
|
|
|
|
|
required: true,
|
|
|
|
|
maxlength: 50
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|