Network components get/set
authorDarren <darren@darrenwhitlen.com>
Tue, 12 Aug 2014 13:14:30 +0000 (14:14 +0100)
committerDarren <darren@darrenwhitlen.com>
Tue, 12 Aug 2014 13:14:30 +0000 (14:14 +0100)
client/src/app.js

index add00f143c212178f4c1b2f7b6d60512dae0d163..afc76a02addfff57d0ec5f94487b88d88d9dfbfd 100644 (file)
@@ -94,22 +94,36 @@ _kiwi.global = {
         Network: function(connection_id) {\r
             var connection_event;\r
 \r
+            // If no connection id given, use all connections\r
             if (typeof connection_id !== 'undefined') {\r
                 connection_event = 'connection:' + connection_id.toString();\r
             } else {\r
                 connection_event = 'connection';\r
             }\r
 \r
+            // Helper to get the network object\r
+            var getNetwork = function() {\r
+                var network = typeof connection_id === 'undefined' ?\r
+                    _kiwi.app.connections.active_connection :\r
+                    _kiwi.app.connections.getByConnectionId(connection_id);\r
+\r
+                return network ?\r
+                    network :\r
+                    undefined;\r
+            };\r
+\r
+            // Create the return object (events proxy from the gateway)\r
             var obj = new this.EventComponent(_kiwi.gateway, connection_event);\r
+\r
+            // Proxy several gateway functions onto the return object\r
             var funcs = {\r
                 kiwi: 'kiwi', raw: 'raw', kick: 'kick', topic: 'topic',\r
                 part: 'part', join: 'join', action: 'action', ctcp: 'ctcp',\r
                 ctcpRequest: 'ctcpRequest', ctcpResponse: 'ctcpResponse',\r
                 notice: 'notice', msg: 'privmsg', changeNick: 'changeNick',\r
-                channelInfo: 'channelInfo', mode: 'mode', quit: 'quit'\r
+                channelInfo: 'channelInfo', mode: 'mode', quit: 'quit',\r
             };\r
 \r
-            // Proxy each gateway method\r
             _.each(funcs, function(gateway_fn, func_name) {\r
                 obj[func_name] = function() {\r
                     var fn_name = gateway_fn;\r
@@ -123,6 +137,25 @@ _kiwi.global = {
                 };\r
             });\r
 \r
+            // Add the networks getters/setters\r
+            obj.get = function() {\r
+                var network = getNetwork();\r
+                if (!network) {\r
+                    return;\r
+                }\r
+\r
+                return network.get.apply(network, arguments);\r
+            };\r
+\r
+            obj.set = function() {\r
+                var network = getNetwork();\r
+                if (!network) {\r
+                    return;\r
+                }\r
+\r
+                return network.set.apply(network, arguments);\r
+            };\r
+\r
             return obj;\r
         },\r
 \r