}\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