Auto panel scrolling; Sending raw IRC commands; Tab closing panels correctly; Panels...
authorDarren <darren@darrenwhitlen.com>
Wed, 18 Jul 2012 20:15:58 +0000 (21:15 +0100)
committerDarren <darren@darrenwhitlen.com>
Wed, 18 Jul 2012 20:15:58 +0000 (21:15 +0100)
client_backbone/img/redcross.png [new file with mode: 0644]
client_backbone/img/scroll_handle.png [new file with mode: 0644]
client_backbone/model.js
client_backbone/model_application.js
client_backbone/style.css
client_backbone/view.js

diff --git a/client_backbone/img/redcross.png b/client_backbone/img/redcross.png
new file mode 100644 (file)
index 0000000..e5f5fe0
Binary files /dev/null and b/client_backbone/img/redcross.png differ
diff --git a/client_backbone/img/scroll_handle.png b/client_backbone/img/scroll_handle.png
new file mode 100644 (file)
index 0000000..a196e65
Binary files /dev/null and b/client_backbone/img/scroll_handle.png differ
index f767b3ba60eb9b331e1c81c36c7f9e454f6b16ae..3a523443789bc2334ab9e67f5d4106bc7d15a448 100644 (file)
@@ -227,6 +227,23 @@ kiwi.model.Panel = Backbone.Model.extend({
         this.set({"scrollback": bs}, {silent: true});
 
         this.trigger("msg", message_obj);
+    },
+
+    close: function () {
+        this.view.remove();
+        delete this.view;
+
+        var members = this.get('members');
+        if (members) {
+            members.reset([]);
+            this.unset('members');
+        }
+
+        this.destroy();
+
+        if (this.cid === kiwi.current_panel.cid) {
+            kiwi.app.panels.server.view.show();
+        }
     }
 });
 
index 1cd98d23beb45be8539926a6ce166359f68e670e..0eb1d285cea247c19a6a2cc02cafa9bfe1ac2a7d 100644 (file)
@@ -80,6 +80,12 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
             channel = that.panels.getByName(event.channel);
             if (!channel) return;
 
+            // If this is us, close the panel
+            if (event.nick === kiwi.gateway.get('nick')) {
+                channel.close();
+                return;
+            }
+
             members = channel.get('members');
             if (!members) return;
 
@@ -163,6 +169,8 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
      * Bind to certain commands that may be typed into the control box
      */
     this.bindControllboxCommands = function (controlbox) {
+        controlbox.on('unknown_command', this.unknownCommand);
+
         controlbox.on('command', this.allCommands);
         controlbox.on('command_msg', this.msgCommand);
 
@@ -183,6 +191,11 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
             });
         });
     };
+
+    this.unknownCommand = function (ev) {
+        kiwi.gateway.raw(ev.command + ' ' + ev.params.join(' '));
+    };
+
     this.allCommands = function (ev) {
         console.log('allCommands', ev);
     };
index 3c7c8a0d1e32627bdf745dff16a8bcb950c9cfe8..3e4ab266e94e39a1ef851518e7c24f94f84eb98e 100644 (file)
@@ -15,9 +15,9 @@ body {
 /**
  * Main layout blocks
  */
-#toolbar { border-bottom:1px solid red; position:absolute; top:0px; width:100%; background-color:#1B1B1B; font-size:0.9em; }
-#panels { border:1px green solid; position:absolute; left:0px; right:200px; bottom:100px; top:100px; overflow-y:scroll; }
-#memberlists { border:1px blue solid; position:absolute; right:0px; width:200px; bottom:100px; top:100px; }
+#toolbar { position:absolute; top:0px; width:100%; background-color:#1B1B1B; font-size:0.9em; }
+#panels { position:absolute; left:0px; right:200px; bottom:100px; top:100px; overflow-y:scroll; }
+#memberlists { position:absolute; right:0px; width:200px; bottom:100px; top:100px; }
 #controlbox { position: absolute; bottom:0px; width:100%; background-color:#1B1B1B; }
 
 
@@ -75,6 +75,7 @@ body {
 
 .messages {
     overflow-x:wrap;
+    overflow-y:scroll;
     border:none; display: none;
     height: 100%;
 }
index a7172c96b21442fc24da94900ecc2d7e82f814d0..695f22ab8c2e2ab93a8a54a65e5f0aaaaf2f646b 100644 (file)
@@ -70,6 +70,10 @@ kiwi.view.Panel = Backbone.View.extend({
         line_msg = '<div class="msg <%= type %>"><div class="time"><%- time %></div><div class="nick"><%- nick %></div><div class="text" style="<%= style %>"><%= msg %> </div></div>';
         $this.append(_.template(line_msg, msg));
 
+        // Scroll to the bottom of the channel
+        // TODO: Don't scroll down if we're scrolled up the channel a little
+        $this[0].scrollTop = $this[0].scrollHeight;
+
         // Make sure our DOM isn't getting too large (Acts as scrollback)
         this.msg_count++;
         if (this.msg_count > 250) {
@@ -102,6 +106,8 @@ kiwi.view.Panel = Backbone.View.extend({
         }
 
         kiwi.current_panel = this.model;
+
+        this.trigger('active', this.model);
     }
 });
 
@@ -117,17 +123,21 @@ kiwi.view.Channel = kiwi.view.Panel.extend({
         }
         
         this.model.addMsg('', '=== Topic for ' + this.model.get('name') + ' is: ' + topic, 'topic');
-        if ($(this.el).css('display') === 'block') {
-            // TODO: Update the active topic bar
-            //kiwi.front.ui.setTopicText(this.model.get("topic"));
+
+        // If this is the active channel then update the topic bar
+        if (kiwi.current_panel === this) {
+            kiwi.app.setCurrentTopic(this.model.get("topic"));
         }
     }
 });
 
+// Model for this = kiwi.model.PanelList
 kiwi.view.Tabs = Backbone.View.extend({
     events: {
-        "click li": "tabClick"
+        "click li": "tabClick",
+        'click li img': 'partClick'
     },
+
     initialize: function () {
         this.model.on("add", this.panelAdded, this);
         this.model.on("remove", this.panelRemoved, this);
@@ -144,7 +154,7 @@ kiwi.view.Tabs = Backbone.View.extend({
             .appendTo($this);
 
         this.model.forEach(function (panel) {
-            // If this si the server panel, ignor as it's already added
+            // If this is the server panel, ignore as it's already added
             if (panel == that.model.server) return;
 
             $('<li><span>' + panel.get("name") + '</span></li>')
@@ -154,27 +164,40 @@ kiwi.view.Tabs = Backbone.View.extend({
     },
 
     panelAdded: function (panel) {
+        // Add a tab to the panel
         panel.tab = $('<li><span>' + panel.get("name") + '</span></li>');
         panel.tab.data('panel_id', panel.cid)
             .appendTo(this.$el);
+
+        panel.view.on('active', this.panelActive, this);
     },
     panelRemoved: function (panel) {
-        $(panel.tab).remove();
-        panel.view.remove();
-        panel.destroy();
+        panel.tab.remove();
+        delete panel.tab;
     },
 
-    tabClick: function (e) {
+    panelActive: function (panel) {
+        // Remove any existing tabs or part images
+        $('img', this.$el).remove();
         this.$el.children().removeClass('active');
 
+        panel.tab.addClass('active');
+        panel.tab.append('<img src="img/redcross.png" />');
+    },
+
+    tabClick: function (e) {
         var panel = this.model.getByCid($(e.currentTarget).data('panel_id'));
         if (!panel) {
             // A panel wasn't found for this tab... wadda fuck
             return;
         }
 
-        panel.tab.addClass('active');
         panel.view.show();
+    },
+
+    partClick: function (e) {
+        var panel = this.model.getByCid($(e.currentTarget).parent().data('panel_id'));
+        kiwi.gateway.part(panel.get('name'));
     }
 });
 
@@ -219,7 +242,7 @@ kiwi.view.ControlBox = Backbone.View.extend({
                 }
                 break;
 
-            case (ev.keyCode === 40):
+            case (ev.keyCode === 40):              // down
                 if (this.buffer_pos < this.buffer.length) {
                     this.buffer_pos++;
                     inp.val(this.buffer[this.buffer_pos]);
@@ -243,6 +266,12 @@ kiwi.view.ControlBox = Backbone.View.extend({
         // Trigger the command events
         this.trigger('command', {command: command, params: params});
         this.trigger('command_' + command, {command: command, params: params});
+
+        // If we didn't have any listeners for this event, fire a special case
+        // TODO: This feels dirty. Should this really be done..?
+        if (!this._callbacks['command' + command]) {
+            this.trigger('unknown_command', {command: command, params: params});
+        }
     }
 });