var App = function () { this.data = {}; this.selectedRow = []; this.AddDialog = new AddDialog(this); this.EditDialog = new EditDialog(this); this.Startup = function () { $('#manage').addClass('active'); this.ReLayout(); this.InitOrgList(); this.InitDataGrid(); this.ReLoadTableData(); 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)); $('#delete-dialog-close').on('click', this.CloseDeleteDialog.bind(this)); $('#dialog-sure').on('click', this.OnSureOfDeleteButtonClick.bind(this)); $('#dialog-cancel').on('click', this.CloseDeleteDialog.bind(this)); 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.InitOrgList = function () { $.ajax({ type: "POST", dataType: 'text', url: '/OrgManagement/Query', data: { pageIndex: 1, pageSize: 10000 }, success: function (result) { console.log(JSON.parse(result)); $('#org-list').combobox({ valueField: 'Id', textField: 'Name', data: JSON.parse(result).rows }); }.bind(this) }); }; this.InitDataGrid = function () { $('#task-grid').datagrid({ columns: [[ { 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 }, { field: 'CreateTime', title: '最后登录时间', align: 'left', width: 60, formatter: this.formatTime.bind(this) } ]], striped: true, singleSelect: false, fitColumns: true, fit: true, scrollbarSize: 0, pageNumber: 1, pageSize: 30, pageList: [30, 40, 50], pagination: true, onSelect: this.OnTaskSelected.bind(this), onUnselect: this.OnTaskUnselected.bind(this), onBeforeLoad: this.OnTableGridBeforeLoad.bind(this) }); }; this.ReLoadTableData = function () { $.ajax({ type: "POST", dataType: 'text', url: '/UserManagement/Query', data: { pageIndex: 1, pageSize: 30 }, success: function (result) { $('#task-grid').datagrid('loadData', JSON.parse(result)); }.bind(this) }); }; this.formatTime = function (time) { return '{0}'.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.OnTableGridBeforeLoad = function () { var page = $('#task-grid').datagrid('getPager'); $(page).pagination({ beforePageText: '第', afterPageText: '页   共{pages}页', displayMsg: '当前显示{from}-{to}条记录   共{total}条记录', layout: ['list', 'sep', 'first', 'prev', 'sep', 'manual', 'sep', 'next', 'last', 'sep', 'refresh', 'info'] }); }; 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.RealName)); }; this.OnSureOfDeleteButtonClick = function () { this.CloseDeleteDialog(); this.DeleteUser(); }; this.CloseDeleteDialog = function () { $('.dialog-delete').hide(); }; this.DeleteUser = function () { $.ajax({ type: "POST", dataType: 'text', url: '/UserManagement/Delete', data: { id: this.selectedRow.Id }, success: function () { this.ReLoadTableData(); }.bind(this) }); }; }; $(document).ready(function () { var app = new App(); app.Startup(); });