BootstrapAdmin/Bootstrap.Admin/wwwroot/js/roles.js

117 lines
6.0 KiB
JavaScript
Raw Normal View History

2018-06-07 00:45:47 +08:00
$(function () {
var $dialogUser = $("#dialogUser");
var $dialogUserHeader = $('#myUserModalLabel');
var $dialogUserForm = $('#userForm');
var $dialogGroup = $("#dialogGroup");
var $dialogGroupHeader = $('#myGroupModalLabel');
var $dialogGroupForm = $('#groupForm');
var $dialogMenu = $('#dialogMenu');
var $dialogMenuHeader = $('#myMenuModalLabel');
var $dialogSubMenu = $('#dialogSubMenu').find('.modal-content');
var $btnSubmitMenu = $('#btnSubmitMenu');
var $nestMenu = $('#nestable_menu');
var $nestMenuInput = $nestMenu.find('div.dd3-content');
$('table').lgbTable({
2018-06-07 00:45:47 +08:00
url: Role.url,
dataBinder: {
2018-06-07 00:45:47 +08:00
map: {
Id: "#roleID",
RoleName: "#roleName",
Description: "#roleDesc"
},
events: {
'#btn_assignUser': function (row) {
2018-06-07 00:45:47 +08:00
$.bc({
id: row.Id, url: User.url, query: { type: "role" }, method: "post",
2018-06-07 00:45:47 +08:00
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
return $.format(htmlTemplate, element.Id, element.DisplayName, element.Checked, element.UserName);
}).join('');
$dialogUserHeader.text($.format('{0}-用户授权窗口', row.RoleName));
$dialogUserForm.html(html).find('[data-toggle="tooltip"]').each(function (index, label) {
if (label.title === "") label.title = "未设置";
2018-08-03 18:12:35 +08:00
}).tooltip();
2018-06-07 00:45:47 +08:00
$dialogUser.modal('show');
}
});
},
'#btn_assignGroup': function (row) {
2018-06-07 00:45:47 +08:00
$.bc({
id: row.Id, url: Group.url, query: { type: "role" }, method: "post",
2018-06-07 00:45:47 +08:00
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
return $.format(htmlTemplate, element.Id, element.GroupName, element.Checked, element.Description);
}).join('');
$dialogGroupHeader.text($.format('{0}-部门授权窗口', row.RoleName));
$dialogGroupForm.html(html).find('[data-toggle="tooltip"]').each(function (index, label) {
if (label.title === "") label.title = "未设置";
2018-08-03 18:12:35 +08:00
}).tooltip();
2018-06-07 00:45:47 +08:00
$dialogGroup.modal('show');
}
});
},
'#btn_assignMenu': function (row) {
2018-06-07 00:45:47 +08:00
$.bc({
id: row.Id, url: Menu.url, query: { type: "role" }, method: "post",
2018-06-07 00:45:47 +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.attr('checked', false);
2018-06-07 00:45:47 +08:00
$.each(result, function (index, item) {
var selector = $.format('[value={0}]', item.Id);
menus.filter(selector).attr('checked', true);
2018-06-07 00:45:47 +08:00
});
$dialogSubMenu.show();
$dialogMenu.modal('show');
}
});
},
'#btnSubmitUser': function (row) {
2018-06-07 00:45:47 +08:00
var roleId = row.Id;
var userIds = $dialogUser.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray();
$.bc({ id: roleId, url: User.url, method: "put", data: userIds, query: { type: "role" }, modal: '#dialogUser', title: User.title });
},
'#btnSubmitGroup': function (row) {
2018-06-07 00:45:47 +08:00
var roleId = row.Id;
var groupIds = $dialogGroup.find(':checked').map(function (index, element) {
return $(element).val();
}).toArray();
$.bc({ id: roleId, url: Group.url, method: "put", data: groupIds, query: { type: "role" }, modal: '#dialogGroup', title: Group.title });
},
'#btnSubmitMenu': function (row) {
2018-06-07 00:45:47 +08:00
var roleId = row.Id;
var menuIds = $nestMenuInput.find('input:checkbox:checked').map(function (index, element) {
return $(element).val();
}).toArray();
$.bc({ id: roleId, url: Menu.url, method: "put", data: menuIds, modal: '#dialogMenu', title: Menu.title });
2018-06-07 00:45:47 +08:00
}
}
},
smartTable: {
sortName: 'RoleName',
queryParams: function (params) { return $.extend(params, { roleName: $("#txt_search_name").val(), description: $("#txt_role_desc").val() }); }, //传递参数(*
columns: [
{ title: "角色名称", field: "RoleName", sortable: true },
{ title: "角色描述", field: "Description", sortable: false }
]
2018-06-07 00:45:47 +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);
}
}).children('.radio').hide();
});
});