BootstrapAdmin/Bootstrap.Admin/Scripts/Groups.js

95 lines
4.4 KiB
JavaScript
Raw Normal View History

$(function () {
2016-11-18 20:49:44 +08:00
var $dialogUser = $("#dialogUser");
var $dialogUserHeader = $('#myUserModalLabel');
var $dialogUserForm = $('#userForm');
var $dialogRole = $('#dialogRole');
var $dialogRoleHeader = $('#myRoleModalLabel');
var $dialogRoleForm = $('#roleForm');
var bsa = new BootstrapAdmin({
2016-11-18 20:49:44 +08:00
url: Group.url,
dataEntity: new DataEntity({
map: {
ID: "groupID",
GroupName: "groupName",
2016-11-10 00:47:42 +08:00
Description: "groupDesc"
}
2016-10-27 17:56:00 +08:00
}),
click: {
assign: [{
id: 'btn_assignRole',
click: function (row) {
2016-11-18 20:49:44 +08:00
$.bc({
Id: row.ID, url: Role.url, data: { type: "group" }, swal: false,
callback: function (result) {
var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) {
return $.format(htmlTemplate, element.ID, element.RoleName, element.Checked, element.Description);
}).join('')
$dialogRoleHeader.text($.format('{0}-角色授权窗口', row.GroupName));
$dialogRoleForm.html(html).find('.tipso_style').each(function (index, label) {
if (label.title == "") label.title = "未设置";
}).tipso();
2016-11-18 20:49:44 +08:00
$dialogRole.modal('show');
}
2016-10-27 17:56:00 +08:00
});
}
}, {
2016-10-29 17:38:23 +08:00
id: 'btn_assignUser',
2016-10-27 17:56:00 +08:00
click: function (row) {
2016-11-18 20:49:44 +08:00
$.bc({
Id: row.ID, url: User.url, data: { type: "group" }, swal: false,
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.GroupName));
$dialogUserForm.html(html).find('.tipso_style').each(function (index, label) {
if (label.title == "") label.title = "未设置";
}).tipso();
2016-11-18 20:49:44 +08:00
$dialogUser.modal('show');
}
2016-10-29 17:38:23 +08:00
});
2016-10-27 17:56:00 +08:00
}
}, {
id: 'btnSubmitRole',
2016-10-27 17:56:00 +08:00
click: function (row) {
2016-10-29 17:38:23 +08:00
var groupId = row.ID;
2016-11-18 20:49:44 +08:00
var roleIds = $dialogRole.find('input:checked').map(function (index, element) {
2016-10-27 17:56:00 +08:00
return $(element).val();
}).toArray().join(',');
2016-11-18 20:49:44 +08:00
$.bc({ Id: groupId, url: Role.url, method: "PUT", data: { type: "group", roleIds: roleIds }, title: Role.title, modal: 'dialogRole' });
2016-10-29 17:38:23 +08:00
}
2016-11-10 00:47:42 +08:00
}, {
id: 'btnSubmitUser',
2016-10-29 17:38:23 +08:00
click: function (row) {
var groupId = row.ID;
2016-11-18 20:49:44 +08:00
var userIds = $dialogUser.find(':checked').map(function (index, element) {
2016-10-29 17:38:23 +08:00
return $(element).val();
}).toArray().join(',');
2016-11-18 20:49:44 +08:00
$.bc({ Id: groupId, url: User.url, method: "PUT", data: { type: "group", userIds: userIds }, title: User.title, modal: 'dialogUser' });
2016-10-27 17:56:00 +08:00
}
}]
}
});
$('table').smartTable({
2016-11-18 20:49:44 +08:00
url: Group.url, //请求后台的URL*
sortName: 'GroupName',
queryParams: function (params) { return $.extend(params, { groupName: $("#txt_search_name").val(), description: $("#txt_group_desc").val() }); }, //传递参数(*
columns: [{ checkbox: true },
{ title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "部门名称", field: "GroupName", sortable: true },
{ title: "部门描述", field: "Description", sortable: false }
]
});
// validate
$('#dataForm').autoValidate({
groupName: {
required: true,
maxlength: 50
}
});
});