2016-10-24 22:10:17 +08:00
|
|
|
|
$(function () {
|
2016-11-16 11:00:12 +08:00
|
|
|
|
var $dialogUser = $("#dialogUser");
|
2016-11-18 20:49:44 +08:00
|
|
|
|
var $dialogUserHeader = $('#myUserModalLabel');
|
|
|
|
|
var $dialogUserForm = $('#userForm');
|
2016-11-16 11:00:12 +08:00
|
|
|
|
var $dialogGroup = $("#dialogGroup");
|
2016-11-18 20:49:44 +08:00
|
|
|
|
var $dialogGroupHeader = $('#myGroupModalLabel');
|
|
|
|
|
var $dialogGroupForm = $('#groupForm');
|
2016-11-16 11:00:12 +08:00
|
|
|
|
var $dialogMenu = $('#dialogMenu');
|
2016-11-18 20:49:44 +08:00
|
|
|
|
var $dialogMenuHeader = $('#myMenuModalLabel');
|
2016-11-16 11:00:12 +08:00
|
|
|
|
var $dialogSubMenu = $('#dialogSubMenu').find('.modal-content');
|
|
|
|
|
var $btnSubmitMenu = $('#btnSubmitMenu');
|
|
|
|
|
var $nestMenu = $('#nestable_menu');
|
|
|
|
|
var $nestMenuInput = $nestMenu.find('div.dd3-content');
|
|
|
|
|
|
2016-10-24 22:10:17 +08:00
|
|
|
|
var bsa = new BootstrapAdmin({
|
2016-11-18 20:49:44 +08:00
|
|
|
|
url: Role.url,
|
2016-10-24 22:10:17 +08:00
|
|
|
|
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) {
|
2016-11-18 20:49:44 +08:00
|
|
|
|
$.bc({
|
2017-03-30 16:15:45 +08:00
|
|
|
|
Id: row.Id, url: User.url, data: { type: "role" }, swal: false,
|
2016-11-18 20:49:44 +08:00
|
|
|
|
callback: function (result) {
|
|
|
|
|
var htmlTemplate = this.htmlTemplate;
|
|
|
|
|
var html = $.map(result, function (element, index) {
|
2017-03-30 16:15:45 +08:00
|
|
|
|
return $.format(htmlTemplate, element.Id, element.DisplayName, element.Checked, element.UserName);
|
2016-11-18 20:49:44 +08:00
|
|
|
|
}).join('');
|
|
|
|
|
$dialogUserHeader.text($.format('{0}-用户授权窗口', row.RoleName));
|
2017-01-14 16:45:12 +08:00
|
|
|
|
$dialogUserForm.html(html).find('[role="tooltip"]').each(function (index, label) {
|
2016-12-26 13:16:13 +08:00
|
|
|
|
if (label.title == "") label.title = "未设置";
|
2017-01-14 18:05:55 +08:00
|
|
|
|
}).lgbTooltip();
|
2016-11-18 20:49:44 +08:00
|
|
|
|
$dialogUser.modal('show');
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-28 20:18:12 +08:00
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
id: 'btn_assignGroup',
|
|
|
|
|
click: function (row) {
|
2016-11-18 20:49:44 +08:00
|
|
|
|
$.bc({
|
2017-03-30 16:15:45 +08:00
|
|
|
|
Id: row.Id, url: Group.url, data: { type: "role" }, swal: false,
|
2016-11-18 20:49:44 +08:00
|
|
|
|
callback: function (result) {
|
|
|
|
|
var htmlTemplate = this.htmlTemplate;
|
|
|
|
|
var html = $.map(result, function (element, index) {
|
2017-03-30 16:15:45 +08:00
|
|
|
|
return $.format(htmlTemplate, element.Id, element.GroupName, element.Checked, element.Description);
|
2016-11-18 20:49:44 +08:00
|
|
|
|
}).join('');
|
|
|
|
|
$dialogGroupHeader.text($.format('{0}-部门授权窗口', row.RoleName));
|
2017-01-14 16:45:12 +08:00
|
|
|
|
$dialogGroupForm.html(html).find('[role="tooltip"]').each(function (index, label) {
|
2016-12-26 13:16:13 +08:00
|
|
|
|
if (label.title == "") label.title = "未设置";
|
2017-01-14 18:05:55 +08:00
|
|
|
|
}).lgbTooltip();
|
2016-11-18 20:49:44 +08:00
|
|
|
|
$dialogGroup.modal('show');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
id: 'btn_assignMenu',
|
|
|
|
|
click: function (row) {
|
|
|
|
|
$.bc({
|
2017-03-30 16:15:45 +08:00
|
|
|
|
Id: row.Id, url: Menu.url, data: { type: "role" }, swal: false,
|
2016-11-18 20:49:44 +08:00
|
|
|
|
callback: function (result) {
|
|
|
|
|
$dialogMenuHeader.text($.format('{0}-菜单授权窗口', row.RoleName));
|
|
|
|
|
$btnSubmitMenu.data('type', 'menu');
|
|
|
|
|
// set checkbox status
|
|
|
|
|
var menus = $nestMenu.find('input:checkbox');
|
|
|
|
|
menus.removeProp('checked');
|
|
|
|
|
$.each(result, function (index, item) {
|
2017-03-30 16:15:45 +08:00
|
|
|
|
var selector = $.format('[value={0}]', item.Id);
|
2016-11-18 20:49:44 +08:00
|
|
|
|
menus.filter(selector).prop('checked', 'checked');
|
|
|
|
|
});
|
|
|
|
|
$dialogSubMenu.show();
|
|
|
|
|
$dialogMenu.modal('show');
|
|
|
|
|
}
|
|
|
|
|
});
|
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) {
|
2017-03-30 16:15:45 +08:00
|
|
|
|
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-11-18 20:49:44 +08:00
|
|
|
|
$.bc({ Id: roleId, url: User.url, method: "PUT", data: { type: "role", userIds: userIds }, modal: 'dialogUser', title: User.title });
|
2016-10-28 20:18:12 +08:00
|
|
|
|
}
|
2016-11-18 20:49:44 +08:00
|
|
|
|
}, {
|
2016-10-31 11:13:46 +08:00
|
|
|
|
id: 'btnSubmitGroup',
|
2016-10-29 09:24:55 +08:00
|
|
|
|
click: function (row) {
|
2017-03-30 16:15:45 +08:00
|
|
|
|
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-18 20:49:44 +08:00
|
|
|
|
$.bc({ Id: roleId, url: Group.url, method: "PUT", data: { type: "role", groupIds: groupIds }, modal: 'dialogGroup', title: Group.title });
|
2016-11-07 21:41:17 +08:00
|
|
|
|
}
|
2016-11-18 20:49:44 +08:00
|
|
|
|
}, {
|
2016-11-07 21:41:17 +08:00
|
|
|
|
id: 'btnSubmitMenu',
|
|
|
|
|
click: function (row) {
|
2017-03-30 16:15:45 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
2016-11-18 20:49:44 +08:00
|
|
|
|
$.bc({ Id: roleId, url: Menu.url, method: "PUT", data: { type: "role", menuIds: menuIds }, modal: 'dialogMenu', title: Menu.title });
|
2016-10-29 09:24:55 +08:00
|
|
|
|
}
|
2016-10-28 20:18:12 +08:00
|
|
|
|
}]
|
|
|
|
|
}
|
2016-10-24 22:10:17 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('table').smartTable({
|
2016-11-18 20:49:44 +08:00
|
|
|
|
url: Role.url, //请求后台的URL(*)
|
2016-10-24 22:10:17 +08:00
|
|
|
|
sortName: 'RoleName',
|
|
|
|
|
queryParams: function (params) { return $.extend(params, { roleName: $("#txt_search_name").val(), description: $("#txt_role_desc").val() }); }, //传递参数(*)
|
|
|
|
|
columns: [{ checkbox: true },
|
2017-03-30 16:15:45 +08:00
|
|
|
|
{ title: "Id", field: "Id", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
|
|
|
|
|
{ title: "角色名称", field: "RoleName", sortable: true },
|
|
|
|
|
{ title: "角色描述", field: "Description", sortable: false }
|
2016-10-24 22:10:17 +08:00
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// validate
|
|
|
|
|
$('#dataForm').autoValidate({
|
|
|
|
|
roleName: {
|
|
|
|
|
required: true,
|
|
|
|
|
maxlength: 50
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-12-11 14:01:12 +08:00
|
|
|
|
|
2016-12-20 16:28:00 +08:00
|
|
|
|
$nestMenu.nestMenu(function () {
|
|
|
|
|
$nestMenuInput = $nestMenu.find('div.dd3-content');
|
|
|
|
|
$nestMenuInput.on('click', ':checkbox', function () {
|
|
|
|
|
var val = $(this).prop('checked');
|
|
|
|
|
var child = $(this).parent().parent().next();
|
|
|
|
|
if (child.hasClass('dd-list')) {
|
|
|
|
|
child.find(':checkbox').prop('checked', val);
|
|
|
|
|
}
|
|
|
|
|
}).find('label:last').hide();
|
2016-12-11 14:01:12 +08:00
|
|
|
|
});
|
2016-10-24 22:10:17 +08:00
|
|
|
|
});
|