Client API implimentation
authorDarren <darren@Darrens-MacBook-Pro.local>
Thu, 21 Feb 2013 23:53:43 +0000 (23:53 +0000)
committerDarren <darren@Darrens-MacBook-Pro.local>
Thu, 21 Feb 2013 23:53:43 +0000 (23:53 +0000)
client/assets/dev/app.js
client/assets/dev/model_application.js
client/assets/dev/model_gateway.js

index 5155b00a81c3deffbeb44c46efbd1572bdbfc8d7..c6b4370949834d3269dfe74ddac2d2e8c166f193 100644 (file)
@@ -18,14 +18,59 @@ _kiwi.global = {
        settings: undefined,\r
        plugins: undefined,\r
        utils: undefined, // TODO: Re-usable methods\r
-       gateway: undefined, // TODO: Access to gateway\r
        user: undefined, // TODO: Limited user methods\r
        server: undefined, // TODO: Limited server methods\r
-       command: undefined,  // The control box\r
 \r
        // TODO: think of a better term for this as it will also refer to queries\r
        channels: undefined, // TODO: Limited access to panels list\r
 \r
+       // Event managers for plugins\r
+       components: {\r
+           EventComponent: function(event_source) {\r
+               function proxyEvent(event_name, event_data) {\r
+                   this.trigger(event_name, event_data);\r
+               }\r
+\r
+               _.extend(this, Backbone.Events);\r
+\r
+               // Proxy the events to this dispatcher\r
+               event_source.on('all', proxyEvent, this);\r
+\r
+               // Clean up this object\r
+               this.dispose = function () {\r
+                   event_source.off('all', proxyEvent);\r
+                   this.off();\r
+               };\r
+           },\r
+\r
+           Irc: function() {\r
+               var obj = new this.EventComponent(_kiwi.gateway);\r
+               var funcs = {\r
+                       kiwi: 'kiwi', raw: 'raw', kick: 'kick', topic: 'topic',\r
+                       part: 'part', join: 'join', action: 'action', ctcp: 'ctcp',\r
+                       notice: 'notice', msg: 'privmsg'\r
+               };\r
+\r
+               _.each(funcs, function(gateway_fn, func_name) {\r
+                       obj[func_name] = _kiwi.gateway[gateway_fn];\r
+               });\r
+\r
+               return obj;\r
+           },\r
+           ControlInput: function() {\r
+               var obj = new this.EventComponent(_kiwi.app.controlbox);\r
+               var funcs = {\r
+                       processInput: 'run'\r
+               };\r
+\r
+               _.each(funcs, function(controlbox_fn, func_name) {\r
+                       obj[func_name] = _kiwi.app.controlbox[controlbox_fn];\r
+               });\r
+\r
+               return obj;\r
+           }\r
+       },\r
+\r
        // Entry point to start the kiwi application\r
        start: function (opts) {\r
                opts = opts || {};\r
index 50a3b15585d4d93bbb3789516a5a835d27bc65df..bc3a86880fcbe53a764a1b2dd4bcc001e4e8d01f 100644 (file)
@@ -132,14 +132,10 @@ _kiwi.model.Application = function () {
 \r
 \r
         this.initializeGlobals = function () {\r
-            _kiwi.global.control = this.controlbox;\r
-            _kiwi.global.gateway = _kiwi.gateway;\r
             _kiwi.global.panels = this.panels;\r
             \r
-            _kiwi.global.components = {\r
-                Applet: _kiwi.model.Applet,\r
-                Panel: _kiwi.model.Panel\r
-            };\r
+            _kiwi.global.components.Applet = _kiwi.model.Applet;\r
+            _kiwi.global.components.Panel =_kiwi.model.Panel;\r
         };\r
 \r
 \r
index 5b9ffe9fee520aa6e0d4a2a1cda3d025ed94269e..48ea4ac00d5db9b3687b52cd87d4a3426431f851 100644 (file)
@@ -47,9 +47,74 @@ _kiwi.model.Gateway = function () {
         \r
         // For ease of access. The socket.io object\r
         this.socket = this.get('socket');\r
+\r
+        this.applyEventHandlers();\r
     };\r
 \r
 \r
+    this.applyEventHandlers = function () {\r
+        /*\r
+        TODO: Impliment event 'groups' to remove a listener group\r
+        kiwi.gateway.on('msg:#channel', my_function);\r
+        kiwi.gateway.on('msg:somenick', my_function);\r
+\r
+        kiwi.gateway.on('notice:#channel', my_function);\r
+        kiwi.gateway.on('action:somenick', my_function);\r
+\r
+        kiwi.gateway.on('join:#channel', my_function);\r
+        kiwi.gateway.on('part:#channel', my_function);\r
+        kiwi.gateway.on('quit', my_function);\r
+        */\r
+        var that = this;\r
+        \r
+        // Some easier handler events\r
+        this.on('onmsg', function (event) {\r
+            var source,\r
+                is_pm = (event.channel == that.get('nick'));\r
+\r
+            source = is_pm ? event.nick : event.channel;\r
+            \r
+            that.trigger('msg:' + source, event);\r
+\r
+            if (is_pm) {\r
+                that.trigger('pm', event);\r
+                that.trigger('pm:' + source, event);\r
+            }\r
+        }, this);\r
+\r
+\r
+        this.on('onnotice', function (event) {\r
+            // The notice towards a channel or a query window?\r
+            var source = event.target || event.nick;\r
+\r
+            this.trigger('notice', event);\r
+            this.trigger('notice:' + source, event);\r
+        }, this);\r
+\r
+\r
+        this.on('onaction', function (event) {\r
+            var source,\r
+                is_pm = (event.channel == that.get('nick'));\r
+\r
+            source = is_pm ? event.nick : event.channel;\r
+            \r
+            that.trigger('action:' + source, event);\r
+\r
+            if (is_pm) {\r
+                that.trigger('action', event);\r
+                that.trigger('action:' + source, event);\r
+            }\r
+        }, this);\r
+\r
+\r
+        this.on('ontopic', function (event) {\r
+            that.trigger('topic', event);\r
+            that.trigger('topic:' + event.channel, event);\r
+        });\r
+    };\r
+\r
+\r
+\r
     /**\r
     *   Connects to the server\r
     *   @param  {String}    host        The hostname or IP address of the IRC server to connect to\r