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.

222 lines
8.0 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
this.formatLastColumn();
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: 120 },
3 years ago
{ field: 'OrgName', title: '所属机构', align: 'left', width: 180 },
{ field: 'LoginName', title: '登录账户', align: 'left', width: 150 },
3 years ago
//{ field: 'LoginPassWord', title: '登录密码', align: 'left', width: 120, formatter: this.formatPassword.bind(this) },
3 years ago
{ field: 'ComputeCount', title: '计算次数', align: 'center', width: 80 },
{ field: 'LastComputeTime', title: '最后计算时间', align: 'center', width: 160, formatter: this.formatLastComputeTime.bind(this) },
{ field: 'LoginCount', title: '登录次数', align: 'center', width: 80 },
{ field: 'LastLoginTime', title: '最后登录时间', align: 'center', width: 160, formatter: this.formatLastLoginTime.bind(this) },
{ field: 'CreateTime', title: '创建时间', align: 'center', width: 160, formatter: this.formatTime.bind(this) },
3 years ago
{ field: 'Null', title: '', align: 'left' }
3 years ago
]],
striped: true,
singleSelect: false,
fit: true,
scrollbarSize: 0,
3 years ago
pagination: true,
3 years ago
pageNumber: 1,
3 years ago
pageSize: 50,
3 years ago
pageList: [10, 20, 50, 100, 150, 200],
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
this.formatLastColumn();
}.bind(this)
3 years ago
});
};
3 years ago
this.formatLastColumn = function () {
var width = $('.container').width();
var headerTable = $('.datagrid-header');
var bodyTable = $('.datagrid-body');
var headerTd = headerTable.find('td:last');
3 years ago
headerTd.css('width', (width - 1093) + 'px');
bodyTable.find('tr').find('td:last').css('width', (width - 1093) + 'px');
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.formatPassword = function (password) {
var len = password.length - 2;
var symbol = '';
for (var i = 0; i < len; i++) {
symbol += '*';
}
return password.substring(0, 1) + symbol + password.substring(password.length - 1);
};
3 years ago
this.formatTime = function (time) {
return '<span>{0}</span>'.format(moment(time).format('YYYY/MM/DD HH:mm:ss'));
3 years ago
};
3 years ago
3 years ago
this.formatLastComputeTime = function (time) {
var value = time === null ? '-' : moment(time).format('YYYY/MM/DD HH:mm:ss');
3 years ago
return '<span>{0}</span>'.format(value);
};
3 years ago
this.formatLastLoginTime = function (time) {
var value = time === null ? '-' : moment(time).format('YYYY/MM/DD HH:mm:ss');
return '<span>{0}</span>'.format(value);
}
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
};
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));
3 years ago
};
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();
});