From 39341f623f1b24a5bcb35a269f0552c4424241ad Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Sat, 23 Jan 2010 15:38:07 +0000 Subject: [PATCH] fix the formatting and change it so the events manager is started on the login event --- deluge/ui/web/js/Deluge.Events.js | 77 +++++++++++++++++-------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/deluge/ui/web/js/Deluge.Events.js b/deluge/ui/web/js/Deluge.Events.js index 0e26ff48a..687581d2c 100644 --- a/deluge/ui/web/js/Deluge.Events.js +++ b/deluge/ui/web/js/Deluge.Events.js @@ -41,52 +41,59 @@ Copyright: (function() { Events = Ext.extend(Ext.util.Observable, { constructor: function() { - this.toRegister = []; + this.toRegister = []; + this.on('login', this.onLogin, this); Events.superclass.constructor.call(this); }, addListener: function(eventName, fn, scope, o) { this.addEvents(eventName); - if (/[A-Z]/.test(eventName.substring(0, 1))) { - if (!Deluge.Client) { - this.toRegister.push(eventName); - } else { - Deluge.Client.web.register_event_listener(eventName); - } - } + if (/[A-Z]/.test(eventName.substring(0, 1))) { + if (!Deluge.Client) { + this.toRegister.push(eventName); + } else { + Deluge.Client.web.register_event_listener(eventName); + } + } Events.superclass.addListener.call(this, eventName, fn, scope, o); }, - poll: function() { - Deluge.Client.web.get_events({ - success: this.onPollSuccess, - scope: this - }); - }, + poll: function() { + Deluge.Client.web.get_events({ + success: this.onPollSuccess, + scope: this + }); + }, - start: function() { - Ext.each(this.toRegister, function(eventName) { - Deluge.Client.web.register_event_listener(eventName); - }); - this.poll = this.poll.bind(this); - this.running = setInterval(this.poll, 2000); - this.poll(); - }, + start: function() { + Ext.each(this.toRegister, function(eventName) { + Deluge.Client.web.register_event_listener(eventName); + }); + this.poll = this.poll.bind(this); + this.running = setInterval(this.poll, 2000); + this.poll(); + }, - stop: function() { - if (this.running) { - clearInterval(this.running); - } - }, + stop: function() { + if (this.running) { + clearInterval(this.running); + } + }, + + onLogin: function() { + this.start(); + this.on('PluginEnabledEvent', this.onPluginEnabled, this); + this.on('PluginDisabledEvent', this.onPluginDisabled, this); + }, - onPollSuccess: function(events) { - if (!events) return; - Ext.each(events, function(event) { - var name = event[0], args = event[1]; - args.splice(0, 0, name); - this.fireEvent.apply(this, args); - }, this); - } + onPollSuccess: function(events) { + if (!events) return; + Ext.each(events, function(event) { + var name = event[0], args = event[1]; + args.splice(0, 0, name); + this.fireEvent.apply(this, args); + }, this); + } }); Events.prototype.on = Events.prototype.addListener Events.prototype.fire = Events.prototype.fireEvent