summaryrefslogtreecommitdiffstats
path: root/deluge/ui/web/js/deluge-all/ConnectionManager.js
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/ui/web/js/deluge-all/ConnectionManager.js')
-rw-r--r--deluge/ui/web/js/deluge-all/ConnectionManager.js75
1 files changed, 44 insertions, 31 deletions
diff --git a/deluge/ui/web/js/deluge-all/ConnectionManager.js b/deluge/ui/web/js/deluge-all/ConnectionManager.js
index d02ee9d4d..ef9bcc4be 100644
--- a/deluge/ui/web/js/deluge-all/ConnectionManager.js
+++ b/deluge/ui/web/js/deluge-all/ConnectionManager.js
@@ -72,7 +72,8 @@ Ext.define('Deluge.ConnectionManager', {
type: 'memory',
reader: {
type: 'json',
- root: 'hosts'
+ root: 'hosts',
+ idProperty: 'id'
}
}
}),
@@ -102,7 +103,7 @@ Ext.define('Deluge.ConnectionManager', {
{xtype: 'button', text: _('Add'), iconCls: 'icon-add', handler: this.onAddClick, scope: this},
{xtype: 'button', text: _('Remove'), iconCls: 'icon-remove', handler: this.onRemoveClick, scope: this},
'->',
- {xtype: 'button', text: _('Stop Daemon'), iconCls: 'icon-error', handler: this.onStopClick, scope: this}
+ {xtype: 'button', text: _('Stop Daemon'), iconCls: 'icon-error', handler: this.onStopClick, scope: this, disabled: true}
]
});
@@ -143,7 +144,7 @@ Ext.define('Deluge.ConnectionManager', {
update: function() {
this.grid.getStore().each(function(r) {
- deluge.client.web.get_host_status(r.id, {
+ deluge.client.web.get_host_status(r.getId(), {
success: this.onGetHostStatus,
scope: this
});
@@ -156,21 +157,23 @@ Ext.define('Deluge.ConnectionManager', {
* @param {Ext.data.Record} record The hosts record to update the UI for
*/
updateButtons: function(record) {
- var button = this.buttons[1], status = record.get('status');
+ var btns = this.query('toolbar[dock=bottom] button'),
+ btn = btns[4],
+ s = record.get('status');
// Update the Connect/Disconnect button
- if (status == _('Connected')) {
- button.enable();
- button.setText(_('Disconnect'));
- } else if (status == _('Offline')) {
- button.disable();
+ if (s == _('Connected')) {
+ btn.enable();
+ btn.setText(_('Disconnect'));
+ } else if (s == _('Offline')) {
+ btn.disable();
} else {
- button.enable();
- button.setText(_('Connect'));
+ btn.enable();
+ btn.setText(_('Connect'));
}
// Update the Stop/Start Daemon button
- if (status == _('Offline')) {
+ if (s == _('Offline')) {
if (record.get('host') == '127.0.0.1' || record.get('host') == 'localhost') {
this.stopHostButton.enable();
this.stopHostButton.setText(_('Start Daemon'));
@@ -204,7 +207,9 @@ Ext.define('Deluge.ConnectionManager', {
// private
onConnect: function(e) {
- var selected = this.grid.getSelectedRecords()[0];
+ var sm = this.grid.getSelectionModel(),
+ selected = sm.getLastSelected();
+
if (!selected) return;
if (selected.get('status') == _('Connected')) {
@@ -216,8 +221,7 @@ Ext.define('Deluge.ConnectionManager', {
scope: this
});
} else {
- var id = selected.id;
- deluge.client.web.connect(id, {
+ deluge.client.web.connect(selected.getId(), {
success: function(methods) {
deluge.client.reloadMethods();
deluge.client.on('connected', function(e) {
@@ -231,9 +235,13 @@ Ext.define('Deluge.ConnectionManager', {
// private
onGetHosts: function(hosts) {
- this.grid.getStore().loadData(hosts);
+ // FIXME: Why on earth do I need to do it like this?!
+ var store = this.grid.getStore(),
+ results = store.proxy.reader.readRecords(hosts);
+ store.loadRecords(results.records);
+
Ext.each(hosts, function(host) {
- deluge.client.web.get_host_status(host[0], {
+ deluge.client.web.get_host_status(host['id'], {
success: this.onGetHostStatus,
scope: this
});
@@ -242,11 +250,14 @@ Ext.define('Deluge.ConnectionManager', {
// private
onGetHostStatus: function(host) {
- var record = this.grid.getStore().getById(host[0]);
- record.set('status', host[3])
- record.set('version', host[4])
+ var record = this.grid.getStore().getById(host['id']);
+ record.set('status', host['status'])
+ record.set('version', host['version'])
record.commit();
- if (this.grid.getSelectedRecords()[0] == record) this.updateButtons(record);
+
+ if (this.grid.getSelectionModel().isSelected(record)) {
+ this.updateButtons(record);
+ }
},
// private
@@ -283,10 +294,12 @@ Ext.define('Deluge.ConnectionManager', {
// private
onRemoveClick: function(button) {
- var connection = this.grid.getSelectedRecords()[0];
- if (!connection) return;
+ var sm = this.grid.getSelectionModel(),
+ selected = sm.getLastSelected();
+
+ if (!selected) return;
- deluge.client.web.remove_host(connection.id, {
+ deluge.client.web.remove_host(selected.getId(), {
success: function(result) {
if (!result) {
Ext.MessageBox.show({
@@ -298,7 +311,7 @@ Ext.define('Deluge.ConnectionManager', {
iconCls: 'x-deluge-icon-error'
});
} else {
- this.grid.getStore().remove(connection);
+ this.grid.getStore().remove(selected);
}
},
scope: this
@@ -306,12 +319,12 @@ Ext.define('Deluge.ConnectionManager', {
},
// private
- onSelectionChanged: function(list, selections) {
+ onSelectionChanged: function(grid, selections) {
if (selections[0]) {
this.removeHostButton.enable();
this.stopHostButton.enable();
this.stopHostButton.setText(_('Stop Daemon'));
- this.updateButtons(this.grid.getRecord(selections[0]));
+ this.updateButtons(selections[0]);
} else {
this.removeHostButton.disable();
this.stopHostButton.disable();
@@ -322,10 +335,10 @@ Ext.define('Deluge.ConnectionManager', {
// private
onShow: function() {
if (!this.addHostButton) {
- var bbar = this.grid.getDockedItems()[0];
- this.addHostButton = bbar.items.get('cm-add');
- this.removeHostButton = bbar.items.get('cm-remove');
- this.stopHostButton = bbar.items.get('cm-stop');
+ var buttons = this.grid.query('button');
+ this.addHostButton = buttons[0];
+ this.removeHostButton = buttons[1];
+ this.stopHostButton = buttons[2];
}
this.loadHosts();
if (this.running) return;