Tidying up nickchanging #78
authorDarren <darren@darrenwhitlen.com>
Sun, 23 Sep 2012 12:29:10 +0000 (13:29 +0100)
committerDarren <darren@darrenwhitlen.com>
Sun, 23 Sep 2012 12:29:10 +0000 (13:29 +0100)
client_backbone/dev/model_application.js
client_backbone/dev/view.js

index c9c5fd1b4bc3a1e639ef771e2c6de1a7758087e7..6d01fa9829224fdedd1c80a165efac35daeb40e0 100755 (executable)
@@ -496,7 +496,12 @@ kiwi.model.Application = Backbone.Model.extend(new (function () {
                 if (kiwi.app.panels.server !== kiwi.app.panels.active) {\r
                     kiwi.app.message.text('The nickname "' + data.nick + '" is already in use. Please select a new nickname');\r
                 }\r
-                (new kiwi.view.NickChangeBox()).render();\r
+\r
+                // Only show the nickchange component if the controlbox is open\r
+                if (that.controlbox.$el.css('display') !== 'none') {\r
+                    (new kiwi.view.NickChangeBox()).render();\r
+                }\r
+\r
                 break;\r
             default:\r
                 // We don't know what data contains, so don't do anything with it.\r
index 944df04383943e18f091012432b7a55aa477adcc..b0773b6b835c6139bd324bcfd287e940ada60ec9 100755 (executable)
@@ -91,91 +91,135 @@ kiwi.view.NickChangeBox = Backbone.View.extend({
     }\r
 });\r
 \r
-kiwi.view.ServerSelect = Backbone.View.extend({\r
-    events: {\r
-        'submit form': 'submitLogin',\r
-        'click .show_more': 'showMore'\r
-    },\r
-\r
-    initialize: function () {\r
-        this.$el = $($('#tmpl_server_select').html());\r
-\r
-        kiwi.gateway.bind('onconnect', this.networkConnected, this);\r
-        kiwi.gateway.bind('connecting', this.networkConnecting, this);\r
-    },\r
-\r
-    submitLogin: function (event) {\r
-        var values = {\r
-            nick: $('.nick', this.$el).val(),\r
-            server: $('.server', this.$el).val(),\r
-            port: $('.port', this.$el).val(),\r
-            ssl: $('.ssl', this.$el).prop('checked'),\r
-            password: $('.password', this.$el).val(),\r
-            channel: $('.channel', this.$el).val()\r
-        };\r
-\r
-        this.trigger('server_connect', values);\r
-        return false;\r
-    },\r
-\r
-    showMore: function (event) {\r
-        $('.more', this.$el).slideDown('fast');\r
-    },\r
-\r
-    populateFields: function (defaults) {\r
-        var nick, server, channel;\r
-\r
-        defaults = defaults || {};\r
-\r
-        nick = defaults.nick || '';\r
-        server = defaults.server || '';\r
-        port = defaults.port || 6667;\r
-        ssl = defaults.ssl || 0;\r
-        password = defaults.password || '';\r
-        channel = defaults.channel || '';\r
-\r
-        $('.nick', this.$el).val(nick);\r
-        $('.server', this.$el).val(server);\r
-        $('.port', this.$el).val(port);\r
-        $('.ssl', this.$el).prop('checked', ssl);\r
-        $('.password', this.$el).val(password);\r
-        $('.channel', this.$el).val(channel);\r
-    },\r
-\r
-    hide: function () {\r
-        this.$el.slideUp();\r
-    },\r
-\r
-    show: function () {\r
-        this.$el.show();\r
-        $('.nick', this.$el).focus();\r
-    },\r
+kiwi.view.ServerSelect = function () {\r
+    // Are currently showing all the controlls or just a nick_change box?\r
+    var state = 'all';\r
+\r
+    var model = Backbone.View.extend({\r
+        events: {\r
+            'submit form': 'submitForm',\r
+            'click .show_more': 'showMore'\r
+        },\r
+\r
+        initialize: function () {\r
+            this.$el = $($('#tmpl_server_select').html());\r
+\r
+            kiwi.gateway.bind('onconnect', this.networkConnected, this);\r
+            kiwi.gateway.bind('connecting', this.networkConnecting, this);\r
+\r
+            kiwi.gateway.bind('onirc_error', function (data) {\r
+                if (data.error == 'nickname_in_use') {\r
+                    this.setStatus('Nickname already taken');\r
+                    this.show('nick_change');\r
+                }\r
+            }, this);\r
+        },\r
+\r
+        submitForm: function (event) {\r
+            if (state === 'nick_change') {\r
+                this.submitNickChange(event);\r
+            } else {\r
+                this.submitLogin(event);\r
+            }\r
 \r
-    setStatus: function (text, class_name) {\r
-        $('.status', this.$el)\r
-            .text(text)\r
-            .attr('class', 'status')\r
-            .addClass(class_name)\r
-            .show();\r
-    },\r
-    clearStatus: function () {\r
-        $('.status', this.$el).hide();\r
-    },\r
+            return false;\r
+        },\r
+\r
+        submitLogin: function (event) {\r
+            var values = {\r
+                nick: $('.nick', this.$el).val(),\r
+                server: $('.server', this.$el).val(),\r
+                port: $('.port', this.$el).val(),\r
+                ssl: $('.ssl', this.$el).prop('checked'),\r
+                password: $('.password', this.$el).val(),\r
+                channel: $('.channel', this.$el).val()\r
+            };\r
+\r
+            this.trigger('server_connect', values);\r
+        },\r
+\r
+        submitNickChange: function (event) {\r
+            kiwi.gateway.changeNick($('.nick', this.$el).val());\r
+            this.networkConnecting();\r
+        },\r
+\r
+        showMore: function (event) {\r
+            $('.more', this.$el).slideDown('fast');\r
+        },\r
+\r
+        populateFields: function (defaults) {\r
+            var nick, server, channel;\r
+\r
+            defaults = defaults || {};\r
+\r
+            nick = defaults.nick || '';\r
+            server = defaults.server || '';\r
+            port = defaults.port || 6667;\r
+            ssl = defaults.ssl || 0;\r
+            password = defaults.password || '';\r
+            channel = defaults.channel || '';\r
+\r
+            $('.nick', this.$el).val(nick);\r
+            $('.server', this.$el).val(server);\r
+            $('.port', this.$el).val(port);\r
+            $('.ssl', this.$el).prop('checked', ssl);\r
+            $('.password', this.$el).val(password);\r
+            $('.channel', this.$el).val(channel);\r
+        },\r
+\r
+        hide: function () {\r
+            this.$el.slideUp();\r
+        },\r
+\r
+        show: function (new_state) {\r
+            new_state = new_state || 'all';\r
+\r
+            this.$el.show();\r
+\r
+            if (new_state === 'all') {\r
+                $('.show_more', this.$el).show();\r
+                $('.nick', this.$el).focus();\r
+\r
+            } else if (new_state === 'more') {\r
+                $('.more', this.$el).slideDown('fast');\r
+\r
+            } else if (new_state === 'nick_change') {\r
+                $('.more', this.$el).hide();\r
+                $('.show_more', this.$el).hide();\r
+            }\r
 \r
-    networkConnected: function (event) {\r
-        this.setStatus('Connected :)', 'ok');\r
-        $('form', this.$el).hide();\r
-    },\r
+            state = new_state;\r
+        },\r
+\r
+        setStatus: function (text, class_name) {\r
+            $('.status', this.$el)\r
+                .text(text)\r
+                .attr('class', 'status')\r
+                .addClass(class_name)\r
+                .show();\r
+        },\r
+        clearStatus: function () {\r
+            $('.status', this.$el).hide();\r
+        },\r
+\r
+        networkConnected: function (event) {\r
+            this.setStatus('Connected :)', 'ok');\r
+            $('form', this.$el).hide();\r
+        },\r
+\r
+        networkConnecting: function (event) {\r
+            this.setStatus('Connecting..', 'ok');\r
+        },\r
+\r
+        showError: function (event) {\r
+            this.setStatus('Error connecting', 'error');\r
+            this.show();\r
+        }\r
+    });\r
 \r
-    networkConnecting: function (event) {\r
-        this.setStatus('Connecting..', 'ok');\r
-    },\r
 \r
-    showError: function (event) {\r
-        this.setStatus('Error connecting', 'error');\r
-        $('form', this.$el).show();\r
-    }\r
-});\r
+    return new model(arguments);\r
+};\r
 \r
 \r
 kiwi.view.Panel = Backbone.View.extend({\r