You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
6.4 KiB

3 years ago
var App = function () {
3 years ago
this.userGrid = $('#task-grid');
3 years ago
this.data = {};
3 years ago
this.selectedRow = [];
this.AddDialog = new AddDialog(this);
this.EditDialog = new EditDialog(this);
this.Startup = function () {
3 years ago
$('#manage').addClass('active');
3 years ago
this.ReLayout();
3 years ago
this.InitOrgList();
3 years ago
this.InitDataGrid();
3 years ago
3 years ago
this.AddDialog.Setup();
this.EditDialog.Setup();
$('#add-btn').on('click', this.OnAddButtonClick.bind(this));
$('#edit-btn').on('click', this.onEditButtonClick.bind(this));
$('#delete-btn').on('click', this.onDeleteButtonClick.bind(this));
3 years ago
$('#query-btn').on('click', this.onQueryButtonClick.bind(this));
3 years ago
$('#delete-dialog-close').on('click', this.CloseDeleteDialog.bind(this));
3 years ago
$('#dialog-sure').on('click', this.OnSureOfDeleteButtonClick.bind(this));
3 years ago
$('#dialog-cancel').on('click', this.CloseDeleteDialog.bind(this));
3 years ago
$('#query-btn').trigger('click');
3 years ago
window.onresize = this.ReLayout.bind(this);
};
this.ReLayout = function () {
var width = $(window).width();
var height = $(window).height();
$('.manage-table, .manage-table .datagrid').width(width -247);
$('.manage-table, .manage-table .datagrid').height(height - 109);
3 years ago
};
3 years ago
this.InitOrgList = function () {
$.ajax({
type: "POST",
dataType: 'text',
url: '/OrgManagement/Query',
data: {
3 years ago
page: 1,
rows: 10000
3 years ago
},
success: function (result) {
3 years ago
var data = JSON.parse(result).rows;
var newData = data.splice(0, 0, { Id: 0, Name: '全部' });
3 years ago
$('#org-list').combobox({
valueField: 'Id',
textField: 'Name',
3 years ago
editable: false,
panelHeight: 'auto',
panelMaxHeight: 190,
data: data
3 years ago
});
3 years ago
$('#org-list').combobox('setValue', 0);
3 years ago
}.bind(this)
});
};
3 years ago
this.InitDataGrid = function () {
3 years ago
this.userGrid.datagrid({
3 years ago
columns: [[
3 years ago
{ field: 'RealName', title: '姓名', align: 'center', width: 10 },
{ field: 'LoginName', title: '登录账户', align: 'center', width: 10 },
{ field: 'LoginPassWord', title: '登录密码', align: 'center', width: 10 },
{ field: 'ComputeCount', title: '登录次数', align: 'center', width: 10 },
3 years ago
{ field: 'CreateTime', title: '最后登录时间', align: 'left', width: 60, formatter: this.formatTime.bind(this) }
3 years ago
]],
striped: true,
singleSelect: false,
fitColumns: true,
fit: true,
scrollbarSize: 0,
3 years ago
pagination: true,
3 years ago
pageNumber: 1,
3 years ago
pageSize: 20,
pageList: [10, 20, 50, 100, 150, 200],
loadMsg: '正在加载数据,请稍后...',
3 years ago
onSelect: this.OnTaskSelected.bind(this),
3 years ago
onUnselect: this.OnTaskUnselected.bind(this),
3 years ago
onBeforeLoad: this.OnTableGridBeforeLoad.bind(this),
onLoadSuccess: function (data) {
if (data.total === 0) {
var body = $(this).data().datagrid.dc.body2;
body.addClass('null-data-body');
body.append('<div class="null-data"><span></span><p>暂无数据</p></div>');
}
}
3 years ago
});
};
3 years ago
this.onQueryButtonClick = function () {
var orgId = $('#org-list').combobox('getValue') === '' ? 0 : $('#org-list').combobox('getValue');
this.ReLoadTableData(orgId);
};
this.ReLoadTableData = function (orgId) {
3 years ago
this.userGrid.datagrid({
method: "POST",
url: '/UserManagement/Query',
queryParams: {
orgId: orgId
}
3 years ago
});
3 years ago
};
3 years ago
this.formatTime = function (time) {
return '<span>{0}</span>'.format(moment(time).format('YYYY/MM/DD HH:mm:ss'));
}
3 years ago
this.OnTaskSelected = function (index, row) {
this.selectedRow = row;
$('.datagrid-btable tr').removeClass('datagrid-row-selected');
$('.datagrid-btable tr').eq(index).addClass('datagrid-row-selected');
//set buttons disabled state
$('#edit-btn').prop('disabled', row === null);
$('#delete-btn').prop('disabled', row === null);
$('#enable-btn').prop('disabled', row.isEnable !== 1 ? null : true);
$('#disable-btn').prop('disabled', row.isEnable === 1 ? null : true);
};
this.OnTaskUnselected = function (index, row) {
3 years ago
this.DisabledEvent();
3 years ago
};
3 years ago
this.OnTableGridBeforeLoad = function () {
3 years ago
this.userGrid.datagrid('getPager').pagination({
3 years ago
beforePageText: '第',
afterPageText: '页&nbsp;&nbsp;&nbsp;共{pages}页',
displayMsg: '当前显示{from}-{to}条记录&nbsp;&nbsp;&nbsp;共{total}条记录',
layout: ['list', 'sep', 'first', 'prev', 'sep', 'manual', 'sep', 'next', 'last', 'sep', 'refresh', 'info']
});
3 years ago
};
3 years ago
this.OnAddButtonClick = function () {
this.AddDialog.Show();
};
this.onEditButtonClick = function () {
this.EditDialog.Show(this.selectedRow);
};
this.onDeleteButtonClick = function () {
$('.dialog-delete').show();
3 years ago
$('.dialog-clear h2').text('确定删除名为「{0}」的账户吗?'.format(this.selectedRow.RealName));
};
this.OnSureOfDeleteButtonClick = function () {
this.DeleteUser();
3 years ago
this.CloseDeleteDialog();
this.DisabledEvent();
3 years ago
};
3 years ago
this.CloseDeleteDialog = function () {
$('.dialog-delete').hide();
};
3 years ago
this.DeleteUser = function () {
$.ajax({
type: "POST",
dataType: 'text',
url: '/UserManagement/Delete',
data: {
id: this.selectedRow.Id
},
success: function () {
3 years ago
this.ReLoadTableData($('#org-list').combobox('getValue'));
3 years ago
}.bind(this)
});
};
3 years ago
this.DisabledEvent = function () {
$('#edit-btn').prop('disabled', true);
$('#delete-btn').prop('disabled', true);
$('#enable-btn').prop('disabled', true);
$('#disable-btn').prop('disabled', true);
};
3 years ago
};
$(document).ready(function () {
var app = new App();
app.Startup();
});