Setting and changing topics
authorDarren <darren@darrenwhitlen.com>
Sat, 25 Aug 2012 18:42:56 +0000 (19:42 +0100)
committerDarren <darren@darrenwhitlen.com>
Sat, 25 Aug 2012 18:42:56 +0000 (19:42 +0100)
client_backbone/model_application.js

index d5cc4bcd0b10b4317d5e6b6842211387772295ae..2ae0dd11d35aaea23d0f069733c909a9283b5aa4 100644 (file)
@@ -1,6 +1,9 @@
 kiwi.model.Application = Backbone.Model.extend(new (function () {\r
     var that = this;\r
 \r
+    /** Instance of kiwi.model.PanelList */\r
+    this.panels = null;\r
+\r
     this.initialize = function () {\r
         // Update `that` with this new Model object\r
         that = this;\r
@@ -28,7 +31,7 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
 \r
 \r
     this.initializeClient = function () {\r
-        this.view = new kiwi.view.Application({model: this, el: this.get('container')})\r
+        this.view = new kiwi.view.Application({model: this, el: this.get('container')});\r
 \r
         \r
         /**\r
@@ -57,7 +60,6 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
 \r
 \r
         gw.on('onjoin', function (event) {\r
-            console.log(event);\r
             var c, members, user;\r
             c = that.panels.getByName(event.channel);\r
             if (!c) {\r
@@ -192,6 +194,8 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
             kiwi.gateway.changeNick(ev.params[0]);\r
         });\r
 \r
+        controlbox.on('command_topic', this.topicCommand);\r
+\r
         controlbox.on('command_css', function (ev) {\r
             var queryString = '?reload=' + new Date().getTime();\r
             $('link[rel="stylesheet"]').each(function () {\r
@@ -231,6 +235,21 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
         //kiwi.app.panels.remove(kiwi.current_panel);\r
     };\r
 \r
+    this.topicCommand = function (ev) {\r
+        var channel_name;\r
+\r
+        if (ev.params.length === 0) return;\r
+\r
+        if (that.isChannelName(ev.params[0])) {\r
+            channel_name = ev.params[0];\r
+            ev.params.shift();\r
+        } else {\r
+            channel_name = kiwi.current_panel.get('name');\r
+        }\r
+\r
+        kiwi.gateway.topic(channel_name, ev.params.join(' '));\r
+    };\r
+\r
 \r
 \r
 \r
@@ -239,4 +258,11 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
         $('#topic input').val(new_topic);\r
     };\r
 \r
+    this.isChannelName = function (channel_name) {\r
+        var channel_prefix = kiwi.gateway.get('channel_prefix');\r
+\r
+        if (!channel_name || !channel_name.length) return false;\r
+        return (channel_prefix.indexOf(channel_name[0]) > -1);\r
+    };\r
+\r
 })());
\ No newline at end of file