Nick change box hiding on change; Only show 1 nick change box
authorDarren <darren@darrenwhitlen.com>
Sun, 16 Feb 2014 17:37:41 +0000 (17:37 +0000)
committerDarren <darren@darrenwhitlen.com>
Sun, 16 Feb 2014 17:37:41 +0000 (17:37 +0000)
client/src/views/controlbox.js
client/src/views/nickchangebox.js

index abb90c612603b50628337f55364a2d5fadc4fd00..8fb5cb2c08ab668e4f27b688bcca12333a650d36 100644 (file)
@@ -32,7 +32,16 @@ _kiwi.view.ControlBox = Backbone.View.extend({
     },
 
     showNickChange: function (ev) {
-        (new _kiwi.view.NickChangeBox()).render();
+        // Nick box already open? Don't do it again
+        if (this.nick_change)
+            return;
+
+        this.nick_change = new _kiwi.view.NickChangeBox();
+        this.nick_change.render();
+
+        this.listenTo(this.nick_change, 'close', function() {
+            delete this.nick_change;
+        });
     },
 
     process: function (ev) {
@@ -53,7 +62,7 @@ _kiwi.view.ControlBox = Backbone.View.extend({
             this.tabcomplete.data = [];
             this.tabcomplete.prefix = '';
         }
-        
+
         switch (true) {
         case (ev.keyCode === 13):              // return
             inp_val = inp_val.trim();
@@ -128,10 +137,10 @@ _kiwi.view.ControlBox = Backbone.View.extend({
             return false;
 
         case (ev.keyCode === 9     //Check if ONLY tab is pressed
-            && !ev.shiftKey        //(user could be using some browser 
+            && !ev.shiftKey        //(user could be using some browser
             && !ev.altKey          //keyboard shortcut)
-            && !ev.metaKey 
-            && !ev.ctrlKey):                     
+            && !ev.metaKey
+            && !ev.ctrlKey):
             this.tabcomplete.active = true;
             if (_.isEqual(this.tabcomplete.data, [])) {
                 // Get possible autocompletions
@@ -157,11 +166,11 @@ _kiwi.view.ControlBox = Backbone.View.extend({
             if (inp_val[inp[0].selectionStart - 1] === ' ') {
                 return false;
             }
-            
+
             (function () {
                 var tokens,              // Words before the cursor position
                     val,                 // New value being built up
-                    p1,                  // Position in the value just before the nick 
+                    p1,                  // Position in the value just before the nick
                     newnick,             // New nick to be displayed (cycles through)
                     range,               // TextRange for setting new text cursor position
                     nick,                // Current nick in the value
@@ -223,7 +232,7 @@ _kiwi.view.ControlBox = Backbone.View.extend({
     processInput: function (command_raw) {
         var command, params,
             pre_processed;
-        
+
         // The default command
         if (command_raw[0] !== '/' || command_raw.substr(0, 2) === '//') {
             // Remove any slash escaping at the start (ie. //)
index 94e74ac225d1298c2aecdd225cad63ae39cedf82..a054949b412c5400a29ca8b00cf95c1d9b0f8565 100644 (file)
@@ -20,20 +20,20 @@ _kiwi.view.NickChangeBox = Backbone.View.extend({
 
         this.$el.css('bottom', _kiwi.app.controlbox.$el.outerHeight(true));
     },
-    
+
     close: function () {
         this.$el.remove();
-
+        this.trigger('close');
     },
 
     changeNick: function (event) {
-        var that = this;
-
         event.preventDefault();
 
-        _kiwi.app.connections.active_connection.gateway.changeNick(this.$el.find('input').val(), function (err, val) {
-            that.close();
+        var connection = _kiwi.app.connections.active_connection;
+        this.listenTo(connection, 'change:nick', function() {
+            this.close();
         });
-        return false;
+
+        connection.gateway.changeNick(this.$('input').val());
     }
 });
\ No newline at end of file