BootstrapAdmin/Bootstrap.Admin/Scripts/Users.js

85 lines
3.3 KiB
JavaScript
Raw Normal View History

$(function () {
2016-10-24 19:12:22 +08:00
var bsa = new BootstrapAdmin({
url: '../api/Users',
dataEntity: new DataEntity({
map: {
ID: "userID",
UserName: "userName",
Password: "password",
DisplayName: "displayName"
}
}),
2016-10-25 18:47:33 +08:00
click: {
assign: [{
id: 'btn_assignRole',
click: function (row) {
2016-10-26 21:32:54 +08:00
Role.getRolesByUserId(row.ID, function (roles) {
2016-10-25 18:47:33 +08:00
$("#dialogRole .modal-title").text($.format('{0}-角色授权窗口', row.DisplayName));
var data = $.map(roles, function (element, index) {
return $.format('<div class="checkbox col-lg-3 col-xs-4"><label title="{3}"><input type="checkbox" value="{0}" {2}>{1}</label></div>', element.ID, element.RoleName, element.Checked, element.Description);
2016-10-25 18:47:33 +08:00
}).join('');
$('#dialogRole form').html(data);
$('#dialogRole').modal('show');
});
}
}, {
id: 'btn_assignGroup',
click: function (row) {
var userId = row.ID;
}
}, {
id: 'btnSubmitUserRole',
click: function (row) {
var userId = row.ID;
var roleIds = $('#dialogRole :checked').map(function (index, element) {
return $(element).val();
}).toArray().join(',');
2016-10-26 21:32:54 +08:00
Role.saveRolesByUserId(userId, roleIds, function (result) {
if (result) {
$('#dialogRole').modal("hide");
swal("成功", "修改角色", "success");
} else {
swal("失败", "修改角色", "error");
}
});
2016-10-25 18:47:33 +08:00
}
}]
},
success: function (src, data) {
if (src === 'save' && data.ID === $('#userId').val()) {
$('.username').text(data.DisplayName);
}
}
});
$('table').smartTable({
url: '../api/Users', //请求后台的URL*
sortName: 'UserName',
queryParams: function (params) { return $.extend(params, { name: $("#txt_search_name").val(), displayName: $('#txt_display_name').val() }); }, //传递参数(*
columns: [{ checkbox: true },
2016-10-24 19:12:22 +08:00
{ title: "Id", field: "ID", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "登陆名称", field: "UserName", sortable: true },
{ title: "显示名称", field: "DisplayName", sortable: false }
]
});
// validate
$('#dataForm').autoValidate({
userName: {
required: true,
maxlength: 50
},
password: {
required: true,
maxlength: 50
},
confirm: {
required: true,
equalTo: "#password"
},
displayName: {
required: true,
maxlength: 50
}
});
});