move over to a more event driven style

This commit is contained in:
Damien Churchill 2009-02-19 02:14:35 +00:00
parent 9e19ae79c8
commit ea4f734863
3 changed files with 88 additions and 77 deletions

View File

@ -1,4 +1,71 @@
Deluge.ToolBar = new Ext.Toolbar({
Deluge.ToolBar = {
onConnect: function() {
Deluge.ToolBar.Bar.items.each(function(bn) {
bn.enable();
});
},
onDisconnect: function() {
Deluge.ToolBar.items.each(function(bn) {
bn.disable();
});
},
onToolbarRender: function(toolbar) {
Deluge.Connections.on("connect", this.onConnect.bindWithEvent(this));
}
}
function torrentAction(item) {
var selection = Deluge.Torrents.getSelectionModel().getSelections();
var ids = new Array();
$each(selection, function(record) {
ids.include(record.id);
});
switch (item.id) {
case "remove":
Deluge.Client.core.remove_torrent(ids, null, {
onSuccess: function() {
Deluge.Ui.update();
}
});
break;
case "pause":
Deluge.Client.core.pause_torrent(ids, {
onSuccess: function() {
Deluge.Ui.update();
}
});
break;
case "resume":
Deluge.Client.core.resume_torrent(ids, {
onSuccess: function() {
Deluge.Ui.update();
}
});
break;
case "up":
Deluge.Client.core.queue_up(ids, {
onSuccess: function() {
Deluge.Ui.update();
}
});
break;
case "down":
Deluge.Client.core.queue_down(ids, {
onSuccess: function() {
Deluge.Ui.update();
}
});
break;
case "connectionman":
Deluge.Connections.Window.show();
break;
}
}
Deluge.ToolBar.Bar = new Ext.Toolbar({
items: [
{
id: 'create',
@ -62,69 +129,11 @@ Deluge.ToolBar = new Ext.Toolbar({
icon: '/icons/16/connection_manager.png',
handler: torrentAction
}
]
],
listeners: {'render': Deluge.ToolBar.onToolbarRender, scope: Deluge.ToolBar}
});
Deluge.ToolBar.connected = function() {
Deluge.ToolBar.items.each(function(bn) {
bn.enable();
});
}
Deluge.ToolBar.disconnected = function() {
Deluge.ToolBar.items.each(function(bn) {
bn.disable();
});
}
function torrentAction(item) {
var selection = Deluge.Torrents.getSelectionModel().getSelections();
var ids = new Array();
$each(selection, function(record) {
ids.include(record.id);
});
switch (item.id) {
case "remove":
Deluge.Client.core.remove_torrent(ids, null, {
onSuccess: function() {
Deluge.Ui.update();
}
});
break;
case "pause":
Deluge.Client.core.pause_torrent(ids, {
onSuccess: function() {
Deluge.Ui.update();
}
});
break;
case "resume":
Deluge.Client.core.resume_torrent(ids, {
onSuccess: function() {
Deluge.Ui.update();
}
});
break;
case "up":
Deluge.Client.core.queue_up(ids, {
onSuccess: function() {
Deluge.Ui.update();
}
});
break;
case "down":
Deluge.Client.core.queue_down(ids, {
onSuccess: function() {
Deluge.Ui.update();
}
});
break;
case "connectionman":
Deluge.Connections.Window.show();
break;
}
}
Deluge.SideBar = {
region: 'west',

View File

@ -1,6 +1,5 @@
Deluge.Connections = {
connects: new Array(),
disconnects: new Array()
_events: new Hash(),
onClose: function(e) {
$clear(Deluge.Connections.running);
@ -17,7 +16,7 @@ Deluge.Connections = {
Deluge.Client = new JSON.RPC('/json', {
methods: methods
});
Deluge.Ui.connected();
Deluge.Connections.fire("connect");
}
});
},
@ -37,19 +36,22 @@ Deluge.Connections = {
Deluge.Connections.runCheck();
},
addConnect: function(fn) {
fire: function(eventName) {
if (!this._events[eventName]) return;
$each(this._events[eventName], function(fn) {
fn(Deluge.Client);
});
},
removeConnect: function(fn) {
on: function(eventName, fn) {
var e = $pick(this._events[eventName], new Array());
e.include(fn);
this._events[eventName] = e;
},
addDisconnect: function(fn) {
},
removeDisconnect: function(fn) {
removeListener: function(eventName, fn) {
if (!this._events[eventName]) return;
this._events[eventName].remove(fn);
},
runCheck: function() {

View File

@ -6,7 +6,7 @@ Deluge.Ui = {
id: 'mainPanel',
title: 'Deluge',
layout: 'border',
tbar: Deluge.ToolBar,
tbar: Deluge.ToolBar.Bar,
items: [Deluge.SideBar, Deluge.Details.Panel, Deluge.Torrents],
bbar: Deluge.StatusBar
});
@ -17,6 +17,7 @@ Deluge.Ui = {
});
Deluge.Login.Window.show();
Deluge.Connections.on("connect", this.onConnect.bindWithEvent(this));
Deluge.Client = new JSON.RPC('/json');
Deluge.SideBar = this.MainPanel.items.get('sidebar');
@ -145,14 +146,13 @@ Deluge.Ui = {
information.
Example:
Deluge.UI.connected();
Deluge.UI.onConnect();
*/
connected: function() {
onConnect: function() {
if (!this.running) {
this.running = this.update.periodical(2000, this);
this.update();
}
Deluge.ToolBar.connected();
},
/*