Macedonian translation #583
[KiwiIRC.git] / client / src / app.js
index df454bcd24160fbd4a150aa173de1a93975228e9..e7d643d626c28f6ac4e901e4d4070a9ce52ddf09 100644 (file)
@@ -4,6 +4,7 @@
 */\r
 var _kiwi = {};\r
 \r
+_kiwi.misc = {};\r
 _kiwi.model = {};\r
 _kiwi.view = {};\r
 _kiwi.applets = {};\r
@@ -19,7 +20,21 @@ _kiwi.global = {
     settings: undefined, // Instance of _kiwi.model.DataStore\r
     plugins: undefined, // Instance of _kiwi.model.PluginManager\r
     events: undefined, // Instance of PluginInterface\r
-    utils: {}, // TODO: Re-usable methods\r
+    utils: {}, // References to misc. re-usable helpers / functions\r
+\r
+    initUtils: function() {\r
+        this.utils.randomString = randomString;\r
+        this.utils.secondsToTime = secondsToTime;\r
+        this.utils.parseISO8601 = parseISO8601;\r
+        this.utils.escapeRegex = escapeRegex;\r
+        this.utils.formatIRCMsg = formatIRCMsg;\r
+        this.utils.styleText = styleText;\r
+        this.utils.hsl2rgb = hsl2rgb;\r
+    },\r
+\r
+    rpc: function() {\r
+        _kiwi.gateway.rpc.call.call(_kiwi.gateway.rpc, arguments);\r
+    },\r
 \r
     addMediaMessageType: function(match, buildHtml) {\r
         _kiwi.view.MediaMessage.addType(match, buildHtml);\r
@@ -48,8 +63,6 @@ _kiwi.global = {
              */\r
             function proxyEvent(event_name, event_data) {\r
                 if (proxy_event_name == 'all') {\r
-                    event_name = event_data.event_name;\r
-                    event_data = event_data.event_data;\r
                 } else {\r
                     event_data = event_name.event_data;\r
                     event_name = event_name.event_name;\r
@@ -61,7 +74,6 @@ _kiwi.global = {
             // The event we are to proxy\r
             proxy_event_name = proxy_event_name || 'all';\r
 \r
-\r
             _.extend(this, Backbone.Events);\r
             this._source = event_source;\r
 \r
@@ -79,20 +91,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'\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
@@ -106,6 +134,34 @@ _kiwi.global = {
                 };\r
             });\r
 \r
+            // Add the networks getters/setters\r
+            obj.get = function(name) {\r
+                var network, restricted_keys;\r
+\r
+                network = getNetwork();\r
+                if (!network) {\r
+                    return;\r
+                }\r
+\r
+                restricted_keys = [\r
+                    'password'\r
+                ];\r
+                if (restricted_keys.indexOf(name) > -1) {\r
+                    return undefined;\r
+                }\r
+\r
+                return network.get(name);\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
@@ -131,6 +187,8 @@ _kiwi.global = {
         var jobs, locale, localeLoaded, textThemeLoaded, text_theme;\r
         opts = opts || {};\r
 \r
+        this.initUtils();\r
+\r
         jobs = new JobManager();\r
         jobs.onFinish(function(locale, s, xhr) {\r
             _kiwi.app = new _kiwi.model.Application(opts);\r
@@ -371,4 +429,4 @@ if (typeof global !== 'undefined') {
 } else {\r
     // Not within a closure so set a var in the current scope\r
     var kiwi = _kiwi.global;\r
-}
\ No newline at end of file
+}\r