From ad07cfe2e2802b3838fdbc2050c721ebae57aa2f Mon Sep 17 00:00:00 2001 From: Darren Date: Sun, 23 Sep 2012 13:29:10 +0100 Subject: [PATCH] Tidying up nickchanging #78 --- client_backbone/dev/model_application.js | 7 +- client_backbone/dev/view.js | 206 ++++++++++++++--------- 2 files changed, 131 insertions(+), 82 deletions(-) diff --git a/client_backbone/dev/model_application.js b/client_backbone/dev/model_application.js index c9c5fd1..6d01fa9 100755 --- a/client_backbone/dev/model_application.js +++ b/client_backbone/dev/model_application.js @@ -496,7 +496,12 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { if (kiwi.app.panels.server !== kiwi.app.panels.active) { kiwi.app.message.text('The nickname "' + data.nick + '" is already in use. Please select a new nickname'); } - (new kiwi.view.NickChangeBox()).render(); + + // Only show the nickchange component if the controlbox is open + if (that.controlbox.$el.css('display') !== 'none') { + (new kiwi.view.NickChangeBox()).render(); + } + break; default: // We don't know what data contains, so don't do anything with it. diff --git a/client_backbone/dev/view.js b/client_backbone/dev/view.js index 944df04..b0773b6 100755 --- a/client_backbone/dev/view.js +++ b/client_backbone/dev/view.js @@ -91,91 +91,135 @@ kiwi.view.NickChangeBox = Backbone.View.extend({ } }); -kiwi.view.ServerSelect = Backbone.View.extend({ - events: { - 'submit form': 'submitLogin', - 'click .show_more': 'showMore' - }, - - initialize: function () { - this.$el = $($('#tmpl_server_select').html()); - - kiwi.gateway.bind('onconnect', this.networkConnected, this); - kiwi.gateway.bind('connecting', this.networkConnecting, this); - }, - - submitLogin: function (event) { - var values = { - nick: $('.nick', this.$el).val(), - server: $('.server', this.$el).val(), - port: $('.port', this.$el).val(), - ssl: $('.ssl', this.$el).prop('checked'), - password: $('.password', this.$el).val(), - channel: $('.channel', this.$el).val() - }; - - this.trigger('server_connect', values); - return false; - }, - - showMore: function (event) { - $('.more', this.$el).slideDown('fast'); - }, - - populateFields: function (defaults) { - var nick, server, channel; - - defaults = defaults || {}; - - nick = defaults.nick || ''; - server = defaults.server || ''; - port = defaults.port || 6667; - ssl = defaults.ssl || 0; - password = defaults.password || ''; - channel = defaults.channel || ''; - - $('.nick', this.$el).val(nick); - $('.server', this.$el).val(server); - $('.port', this.$el).val(port); - $('.ssl', this.$el).prop('checked', ssl); - $('.password', this.$el).val(password); - $('.channel', this.$el).val(channel); - }, - - hide: function () { - this.$el.slideUp(); - }, - - show: function () { - this.$el.show(); - $('.nick', this.$el).focus(); - }, +kiwi.view.ServerSelect = function () { + // Are currently showing all the controlls or just a nick_change box? + var state = 'all'; + + var model = Backbone.View.extend({ + events: { + 'submit form': 'submitForm', + 'click .show_more': 'showMore' + }, + + initialize: function () { + this.$el = $($('#tmpl_server_select').html()); + + kiwi.gateway.bind('onconnect', this.networkConnected, this); + kiwi.gateway.bind('connecting', this.networkConnecting, this); + + kiwi.gateway.bind('onirc_error', function (data) { + if (data.error == 'nickname_in_use') { + this.setStatus('Nickname already taken'); + this.show('nick_change'); + } + }, this); + }, + + submitForm: function (event) { + if (state === 'nick_change') { + this.submitNickChange(event); + } else { + this.submitLogin(event); + } - setStatus: function (text, class_name) { - $('.status', this.$el) - .text(text) - .attr('class', 'status') - .addClass(class_name) - .show(); - }, - clearStatus: function () { - $('.status', this.$el).hide(); - }, + return false; + }, + + submitLogin: function (event) { + var values = { + nick: $('.nick', this.$el).val(), + server: $('.server', this.$el).val(), + port: $('.port', this.$el).val(), + ssl: $('.ssl', this.$el).prop('checked'), + password: $('.password', this.$el).val(), + channel: $('.channel', this.$el).val() + }; + + this.trigger('server_connect', values); + }, + + submitNickChange: function (event) { + kiwi.gateway.changeNick($('.nick', this.$el).val()); + this.networkConnecting(); + }, + + showMore: function (event) { + $('.more', this.$el).slideDown('fast'); + }, + + populateFields: function (defaults) { + var nick, server, channel; + + defaults = defaults || {}; + + nick = defaults.nick || ''; + server = defaults.server || ''; + port = defaults.port || 6667; + ssl = defaults.ssl || 0; + password = defaults.password || ''; + channel = defaults.channel || ''; + + $('.nick', this.$el).val(nick); + $('.server', this.$el).val(server); + $('.port', this.$el).val(port); + $('.ssl', this.$el).prop('checked', ssl); + $('.password', this.$el).val(password); + $('.channel', this.$el).val(channel); + }, + + hide: function () { + this.$el.slideUp(); + }, + + show: function (new_state) { + new_state = new_state || 'all'; + + this.$el.show(); + + if (new_state === 'all') { + $('.show_more', this.$el).show(); + $('.nick', this.$el).focus(); + + } else if (new_state === 'more') { + $('.more', this.$el).slideDown('fast'); + + } else if (new_state === 'nick_change') { + $('.more', this.$el).hide(); + $('.show_more', this.$el).hide(); + } - networkConnected: function (event) { - this.setStatus('Connected :)', 'ok'); - $('form', this.$el).hide(); - }, + state = new_state; + }, + + setStatus: function (text, class_name) { + $('.status', this.$el) + .text(text) + .attr('class', 'status') + .addClass(class_name) + .show(); + }, + clearStatus: function () { + $('.status', this.$el).hide(); + }, + + networkConnected: function (event) { + this.setStatus('Connected :)', 'ok'); + $('form', this.$el).hide(); + }, + + networkConnecting: function (event) { + this.setStatus('Connecting..', 'ok'); + }, + + showError: function (event) { + this.setStatus('Error connecting', 'error'); + this.show(); + } + }); - networkConnecting: function (event) { - this.setStatus('Connecting..', 'ok'); - }, - showError: function (event) { - this.setStatus('Error connecting', 'error'); - $('form', this.$el).show(); - } -}); + return new model(arguments); +}; kiwi.view.Panel = Backbone.View.extend({ -- 2.25.1