tidy up and convert the gridpanel to a listview

This commit is contained in:
Damien Churchill 2010-04-27 21:40:55 +01:00
parent dd82f95975
commit 9f46958f20
1 changed files with 35 additions and 46 deletions

View File

@ -60,9 +60,8 @@
this.addButton(_('Close'), this.onClose, this); this.addButton(_('Close'), this.onClose, this);
this.addButton(_('Connect'), this.onConnect, this); this.addButton(_('Connect'), this.onConnect, this);
this.grid = this.add({ this.list = new Ext.list.ListView({
xtype: 'grid', store: new Ext.data.ArrayStore({
store: new Ext.data.SimpleStore({
fields: [ fields: [
{name: 'status', mapping: 3}, {name: 'status', mapping: 3},
{name: 'host', mapping: 1}, {name: 'host', mapping: 1},
@ -73,36 +72,31 @@
}), }),
columns: [{ columns: [{
header: _('Status'), header: _('Status'),
width: 65, width: .22,
sortable: true, sortable: true,
renderer: fplain,
dataIndex: 'status' dataIndex: 'status'
}, { }, {
id:'host', id:'host',
header: _('Host'), header: _('Host'),
width: 150, width: .51,
sortable: true, sortable: true,
renderer: hostRenderer, tpl: '{host}:{port}',
dataIndex: 'host' dataIndex: 'host'
}, { }, {
header: _('Version'), header: _('Version'),
width: 75, width: .25,
sortable: true, sortable: true,
renderer: fplain,
dataIndex: 'version' dataIndex: 'version'
}], }],
stripeRows: true, singleSelect: true,
selModel: new Ext.grid.RowSelectionModel({ listeners: {
singleSelect: true, 'selectionchange': {fn: this.onSelectionChanged, scope: this}
listeners: { }
'rowselect': {fn: this.onSelect, scope: this}, });
'selectionchange': {fn: this.onSelectionChanged, scope: this}
} this.panel = this.add({
}), autoScroll: true,
autoExpandColumn: 'host', items: [this.list],
deferredRender:false,
autoScroll:true,
margins: '0 0 0 0',
bbar: new Ext.Toolbar({ bbar: new Ext.Toolbar({
buttons: [ buttons: [
{ {
@ -117,7 +111,7 @@
cls: 'x-btn-text-icon', cls: 'x-btn-text-icon',
text: _('Remove'), text: _('Remove'),
iconCls: 'icon-remove', iconCls: 'icon-remove',
handler: this.onRemove, handler: this.onRemoveClick,
disabled: true, disabled: true,
scope: this scope: this
}, '->', { }, '->', {
@ -125,14 +119,13 @@
cls: 'x-btn-text-icon', cls: 'x-btn-text-icon',
text: _('Stop Daemon'), text: _('Stop Daemon'),
iconCls: 'icon-error', iconCls: 'icon-error',
handler: this.onStop, handler: this.onStopClick,
disabled: true, disabled: true,
scope: this scope: this
} }
] ]
}) })
}); });
this.update = this.update.createDelegate(this); this.update = this.update.createDelegate(this);
}, },
@ -165,7 +158,7 @@
}, },
update: function() { update: function() {
this.grid.getStore().each(function(r) { this.list.getStore().each(function(r) {
deluge.client.web.get_host_status(r.id, { deluge.client.web.get_host_status(r.id, {
success: this.onGetHostStatus, success: this.onGetHostStatus,
scope: this scope: this
@ -228,7 +221,7 @@
// private // private
onConnect: function(e) { onConnect: function(e) {
var selected = this.grid.getSelectionModel().getSelected(); var selected = this.list.getSelectedRecords()[0];
if (!selected) return; if (!selected) return;
if (selected.get('status') == _('Connected')) { if (selected.get('status') == _('Connected')) {
@ -253,6 +246,7 @@
} }
}, },
// private
onDisconnect: function() { onDisconnect: function() {
if (this.isVisible()) return; if (this.isVisible()) return;
this.show(); this.show();
@ -260,7 +254,7 @@
// private // private
onGetHosts: function(hosts) { onGetHosts: function(hosts) {
this.grid.getStore().loadData(hosts); this.list.getStore().loadData(hosts);
Ext.each(hosts, function(host) { Ext.each(hosts, function(host) {
deluge.client.web.get_host_status(host[0], { deluge.client.web.get_host_status(host[0], {
success: this.onGetHostStatus, success: this.onGetHostStatus,
@ -271,11 +265,11 @@
// private // private
onGetHostStatus: function(host) { onGetHostStatus: function(host) {
var record = this.grid.getStore().getById(host[0]); var record = this.list.getStore().getById(host[0]);
record.set('status', host[3]) record.set('status', host[3])
record.set('version', host[4]) record.set('version', host[4])
record.commit(); record.commit();
if (this.grid.getSelectionModel().getSelected() == record) this.updateButtons(record); if (this.list.getSelectedRecords()[0] == record) this.updateButtons(record);
}, },
// private // private
@ -311,8 +305,8 @@
}, },
// private // private
onRemove: function(button) { onRemoveClick: function(button) {
var connection = this.grid.getSelectionModel().getSelected(); var connection = this.list.getSelectedRecords()[0];
if (!connection) return; if (!connection) return;
deluge.client.web.remove_host(connection.id, { deluge.client.web.remove_host(connection.id, {
@ -327,7 +321,7 @@
iconCls: 'x-deluge-icon-error' iconCls: 'x-deluge-icon-error'
}); });
} else { } else {
this.grid.getStore().remove(connection); this.list.getStore().remove(connection);
} }
}, },
scope: this scope: this
@ -335,28 +329,23 @@
}, },
// private // private
onSelect: function(selModel, rowIndex, record) { onSelectionChanged: function(list, selections) {
this.selectedRow = rowIndex; if (selections[0]) {
},
// private
onSelectionChanged: function(selModel) {
var record = selModel.getSelected();
if (selModel.hasSelection()) {
this.removeHostButton.enable(); this.removeHostButton.enable();
this.stopHostButton.enable(); this.stopHostButton.enable();
this.stopHostButton.setText(_('Stop Daemon')); this.stopHostButton.setText(_('Stop Daemon'));
this.updateButtons(this.list.getRecord(selections[0]));
} else { } else {
this.removeHostButton.disable(); this.removeHostButton.disable();
this.stopHostButton.disable(); this.stopHostButton.disable();
this.updateButtons(null);
} }
this.updateButtons(record);
}, },
// private // private
onShow: function() { onShow: function() {
if (!this.addHostButton) { if (!this.addHostButton) {
var bbar = this.grid.getBottomToolbar(); var bbar = this.panel.getBottomToolbar();
this.addHostButton = bbar.items.get('cm-add'); this.addHostButton = bbar.items.get('cm-add');
this.removeHostButton = bbar.items.get('cm-remove'); this.removeHostButton = bbar.items.get('cm-remove');
this.stopHostButton = bbar.items.get('cm-stop'); this.stopHostButton = bbar.items.get('cm-stop');
@ -366,8 +355,8 @@
}, },
// private // private
onStop: function(button, e) { onStopClick: function(button, e) {
var connection = this.grid.getSelectionModel().getSelected(); var connection = this.list.getSelectedRecords()[0];
if (!connection) return; if (!connection) return;
if (connection.get('status') == 'Offline') { if (connection.get('status') == 'Offline') {