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.
 
 
 
 

176 lines
6.1 KiB

var App = function () {
this.statisticGrid = $('#task-grid');
this.selectedRow = [];
this.Startup = function () {
$('#manage').addClass('active');
this.ReLayout();
this.InitDate();
this.InitDataGrid();
$('#query-btn').on('click', this.OnQueryButtonClick.bind(this));
$('#query-btn').trigger('click');
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);
this.formatLastColumn();
};
this.OnQueryButtonClick = function () {
this.ReLoadTableData();
};
this.ReLoadTableData = function () {
this.statisticGrid.datagrid({
method: "POST",
url: '/StatisticAnalysis/Query',
queryParams: {
fromTime: $("#from-date").datetimebox('getValue'),
toTime: $("#to-date").datetimebox('getValue'),
}
});
};
this.InitDate = function () {
$('#from-date').datetimebox({
panelAlign: 'right',
panelWidth: 200,
panelHeight: 230,
showSeconds: false,
currentText: '现在',
onSelect: function (date) {
var startTime = date.getTime();
var endDate = $('#to-date').val();
if (endDate) {
var endTime = new Date(endDate).getTime();
if (startTime > endTime)
alert('开始日期不能大于结束日期,请重新选择。');
}
}
});
$('#to-date').datetimebox({
panelWidth: 190,
panelHeight: 230,
panelAlign: 'right',
showSeconds: false,
currentText: '现在',
onSelect: function (date) {
var endTime = date.getTime();
var startDate = $('#from-date').val();
if (startDate) {
var startTime = new Date(startDate).getTime();
if (startTime > endTime)
alert('结束日期不能小于开始日期,请重新选择。');
}
}
});
$("#from-date").datetimebox('setValue', moment().add(-30, 'days').format('YYYY/MM/DD HH:mm'));
};
this.InitDataGrid = function () {
this.statisticGrid.datagrid({
columns: [[
{ field: 'UserName', title: '姓名', align: 'center', width: 120 },
{ field: 'OrgName', title: '所属机构', align: 'left', width: 180 },
{ field: 'ComputeCount', title: '计算次数', align: 'center', width: 100 },
{ field: 'LastComputeTime', title: '最后计算时间', align: 'center', width: 160, formatter: this.formatTime.bind(this) },
{ field: 'Null', title: '', align: 'left' }
]],
striped: true,
singleSelect: false,
fit: true,
scrollbarSize: 0,
pagination: true,
pageNumber: 1,
pageSize: 50,
pageList: [10, 20, 50, 100, 150, 200],
onSelect: this.OnTaskSelected.bind(this),
onUnselect: this.OnTaskUnselected.bind(this),
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>');
}
this.formatLastColumn();
}.bind(this)
});
};
this.formatLastColumn = function () {
var width = $('.container').width();
var headerTable = $('.datagrid-header');
var bodyTable = $('.datagrid-body');
var headerTd = headerTable.find('td:last');
headerTd.css('width', (width - 562) + 'px');
bodyTable.find('tr').find('td:last').css('width', (width - 562) + 'px');
};
this.formatTime = function (time) {
return '<span>{0}</span>'.format(moment(time).format('YYYY/MM/DD HH:mm:ss'));
};
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) {
$('#edit-btn').prop('disabled', true);
$('#delete-btn').prop('disabled', true);
$('#enable-btn').prop('disabled', true);
$('#disable-btn').prop('disabled', true);
};
this.OnAddButtonClick = function () {
this.AddDialog.Show();
};
this.onEditButtonClick = function () {
this.EditDialog.Show(this.selectedRow);
};
this.onDeleteButtonClick = function () {
$('.dialog-delete').show();
$('.dialog-clear h2').text('确定删除名为「{0}」的账户吗?'.format(this.selectedRow.Name));
};
this.CloseDeleteDialog = function () {
$('.dialog-delete').hide();
};
this.OnTableGridBeforeLoad = function () {
this.statisticGrid.datagrid('getPager').pagination({
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']
});
};
};
$(document).ready(function () {
var app = new App();
app.Startup();
});