var App = function () { this.data = {}; this.selectedRow = []; this.EditLineWidth = new EditLineWidth(this); this.EditLineColor = new EditLineColor(this); this.EditLocateIcon = new EditLocateIcon(this); this.Startup = function () { $('#manage').addClass('active'); this.ReLayout(); this.InitDataGrid(); this.ReLoadTableData(); this.EditLineWidth.Setup(); this.EditLineColor.Setup(); this.EditLocateIcon.Setup(); $('#edit-btn').on('click', this.onEditButtonClick.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.InitDataGrid = function () { $('#task-grid').datagrid({ columns: [[ { field: 'Id', title: '名称', align: 'center', width: 10 }, { field: 'Value', title: '值', align: 'center', width: 10 }, { field: 'Unit', title: '单位', align: 'center', width: 10, formatter: this.formatUnit.bind(this) }, { field: 'Description', title: '描述', align: 'left', width: 60, formatter: this.formatDescription.bind(this) } ]], striped: true, singleSelect: false, fitColumns: true, fit: true, scrollbarSize: 0, onSelect: this.OnTaskSelected.bind(this), onUnselect: this.OnTaskUnselected.bind(this) }); }; this.ReLoadTableData = function () { $.ajax({ type: "POST", dataType: 'text', url: '/ConfigManagement/Query', data: { page: 1, rows: 1000 }, success: function (result) { var value = JSON.parse(result); this.data['total'] = value.length; this.data['rows'] = value; $('#task-grid').datagrid('loadData', this.data); }.bind(this) }); }; this.formatUnit = function (value) { return value === "像素" ? value : '-'; }; this.formatDescription = function (value) { return '{0}'.format(value); }; 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); }; this.OnTaskUnselected = function (index, row) { this.DisabledEvent(); }; this.DisabledEvent = function () { $('#edit-btn').prop('disabled', true); }; this.onEditButtonClick = function () { if (this.selectedRow.Id === 'line-width') this.EditLineWidth.Show(this.selectedRow); else if (this.selectedRow.Id === 'line-color') this.EditLineColor.Show(this.selectedRow); else if (this.selectedRow.Id === 'marker-icon') this.EditLocateIcon.Show(this.selectedRow); }; }; $(document).ready(function () { var app = new App(); app.Startup(); });