TopicBar now editable to set topic
authorDarren <darren@darrenwhitlen.com>
Sun, 2 Sep 2012 00:58:09 +0000 (01:58 +0100)
committerDarren <darren@darrenwhitlen.com>
Sun, 2 Sep 2012 00:58:09 +0000 (01:58 +0100)
client_backbone/model_application.js
client_backbone/view.js

index 80c1521ba1e55d3d7a8a6a300dcce4e7dafaabd9..2f508e3250507de8fba7e21db87d36cc52810ab0 100644 (file)
@@ -40,6 +40,8 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
         this.controlbox = new kiwi.view.ControlBox({el: $('#controlbox')[0]});\r
         this.bindControllboxCommands(this.controlbox);\r
 \r
+        this.topicbar = new kiwi.view.TopicBar({el: $('#topic')[0]});\r
+\r
         // Container for the channels\r
         this.panels = new kiwi.model.PanelList();\r
         this.panels.server.view.show();\r
@@ -206,7 +208,7 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
 \r
             // If this is the active channel, update the topic bar too\r
             if (c.get('name') === kiwi.current_panel.get('name')) {\r
-                that.setCurrentTopic(event.topic);\r
+                that.topicbar.setCurrentTopic(event.topic);\r
             }\r
         });\r
 \r
@@ -404,6 +406,7 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
                 kiwi.gateway.part(channel);\r
             });\r
         }\r
+        // TODO: More responsive = close tab now, more accurate = leave until part event\r
         //kiwi.app.panels.remove(kiwi.current_panel);\r
     };\r
 \r
@@ -438,10 +441,6 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
 \r
 \r
 \r
-    this.setCurrentTopic = function (new_topic) {\r
-        $('#topic input').val(new_topic);\r
-    };\r
-\r
     this.isChannelName = function (channel_name) {\r
         var channel_prefix = kiwi.gateway.get('channel_prefix');\r
 \r
index 1edda45407bebe75a0c9f79698233dc84aa70bbf..e2de6e54496155de6b4709402efd114bb0fdac63 100644 (file)
@@ -222,7 +222,7 @@ kiwi.view.Panel = Backbone.View.extend({
 \r
         // TODO: Why is kiwi.app not defined when this is fist called :/\r
         if (kiwi.app) {\r
-            kiwi.app.setCurrentTopic(this.model.get("topic") || "");\r
+            kiwi.app.topicbar.setCurrentTopic(this.model.get("topic") || "");\r
         }\r
 \r
         this.scrollToBottom();\r
@@ -255,7 +255,7 @@ kiwi.view.Channel = kiwi.view.Panel.extend({
 \r
         // If this is the active channel then update the topic bar\r
         if (kiwi.current_panel === this) {\r
-            kiwi.app.setCurrentTopic(this.model.get("topic"));\r
+            kiwi.app.topicbar.setCurrentTopic(this.model.get("topic"));\r
         }\r
     }\r
 });\r
@@ -338,9 +338,33 @@ kiwi.view.Tabs = Backbone.View.extend({
 \r
 \r
 \r
-kiwi.view.ControlBox = Backbone.View.extend({\r
-    that: this,\r
+kiwi.view.TopicBar = Backbone.View.extend({\r
+    events: {\r
+        'keydown input': 'process'\r
+    },\r
+\r
+    initialize: function () {\r
+    },\r
+\r
+    process: function (ev) {\r
+        var inp = $(ev.currentTarget),\r
+            inp_val = inp.val();\r
 \r
+        if (ev.keyCode !== 13) return;\r
+\r
+        if (kiwi.current_panel.isChannel && kiwi.current_panel.isChannel()) {\r
+            kiwi.gateway.topic(kiwi.current_panel.get('name'), inp_val);\r
+        }\r
+    },\r
+\r
+    setCurrentTopic: function (new_topic) {\r
+        $('input', this.$el).val(new_topic);\r
+    }\r
+});\r
+\r
+\r
+\r
+kiwi.view.ControlBox = Backbone.View.extend({\r
     buffer: [],  // Stores previously run commands\r
     buffer_pos: 0,  // The current position in the buffer\r
 \r
@@ -371,7 +395,7 @@ kiwi.view.ControlBox = Backbone.View.extend({
                 this.buffer.push(inp.val());\r
                 this.buffer_pos = this.buffer.length;\r
             }\r
-            \r
+\r
             inp.val('');\r
 \r
             break;\r