// Best guess at where the kiwi server is if not already specified\r
this.kiwi_server = options.kiwi_server || this.detectKiwiServer();\r
\r
+ // The applet to initially load\r
+ this.startup_applet_name = options.startup || 'kiwi_startup';\r
+\r
// Set any default settings before anything else is applied\r
if (this.server_settings && this.server_settings.client && this.server_settings.client.settings) {\r
this.applyDefaultClientSettings(this.server_settings.client.settings);\r
\r
this.view.barsHide(true);\r
\r
- this.showIntialConenctionDialog();\r
+ this.showStartup();\r
},\r
\r
\r
},\r
\r
\r
- showIntialConenctionDialog: function() {\r
- var connection_dialog = new _kiwi.model.NewConnection();\r
- this.populateDefaultServerSettings(connection_dialog);\r
-\r
- connection_dialog.view.$el.addClass('initial');\r
- this.view.$el.find('.panel_container:first').append(connection_dialog.view.$el);\r
-\r
- var $info = $($('#tmpl_new_connection_info').html().trim());\r
-\r
- if ($info.html()) {\r
- connection_dialog.view.infoBoxSet($info);\r
- connection_dialog.view.infoBoxShow();\r
- }\r
-\r
- // TODO: Shouldn't really be here but it's not working in the view.. :/\r
- // Hack for firefox browers: Focus is not given on this event loop iteration\r
- setTimeout(function(){\r
- connection_dialog.view.$el.find('.nick').select();\r
- }, 0);\r
-\r
- // Once connected, close this dialog and remove its own event\r
- var fn = function() {\r
- connection_dialog.view.$el.slideUp(function() {\r
- connection_dialog.view.dispose();\r
- connection_dialog = null;\r
-\r
- _kiwi.gateway.off('onconnect', fn);\r
- });\r
-\r
- };\r
- _kiwi.gateway.on('onconnect', fn);\r
+ showStartup: function() {\r
+ this.startup_applet = _kiwi.model.Applet.load(this.startup_applet_name, {no_tab: true});\r
+ this.startup_applet.tab = this.view.$('.console');\r
+ this.startup_applet.view.show();\r
},\r
\r
\r
},\r
\r
\r
- populateDefaultServerSettings: function (new_connection_dialog) {\r
- var parts;\r
- var defaults = {\r
- nick: '',\r
- server: '',\r
- port: 6667,\r
- ssl: false,\r
- channel: '#chat',\r
- channel_key: ''\r
- };\r
- var uricheck;\r
-\r
-\r
- /**\r
- * Get any settings set by the server\r
- * These settings may be changed in the server selection dialog or via URL parameters\r
- */\r
- if (this.server_settings.client) {\r
- if (this.server_settings.client.nick)\r
- defaults.nick = this.server_settings.client.nick;\r
-\r
- if (this.server_settings.client.server)\r
- defaults.server = this.server_settings.client.server;\r
-\r
- if (this.server_settings.client.port)\r
- defaults.port = this.server_settings.client.port;\r
-\r
- if (this.server_settings.client.ssl)\r
- defaults.ssl = this.server_settings.client.ssl;\r
-\r
- if (this.server_settings.client.channel)\r
- defaults.channel = this.server_settings.client.channel;\r
-\r
- if (this.server_settings.client.channel_key)\r
- defaults.channel_key = this.server_settings.client.channel_key;\r
- }\r
-\r
-\r
-\r
- /**\r
- * Get any settings passed in the URL\r
- * These settings may be changed in the server selection dialog\r
- */\r
-\r
- // Any query parameters first\r
- if (getQueryVariable('nick'))\r
- defaults.nick = getQueryVariable('nick');\r
-\r
- if (window.location.hash)\r
- defaults.channel = window.location.hash;\r
-\r
-\r
- // Process the URL part by part, extracting as we go\r
- parts = window.location.pathname.toString().replace(this.get('base_path'), '').split('/');\r
-\r
- if (parts.length > 0) {\r
- parts.shift();\r
-\r
- if (parts.length > 0 && parts[0]) {\r
- // Check to see if we're dealing with an irc: uri, or whether we need to extract the server/channel info from the HTTP URL path.\r
- uricheck = parts[0].substr(0, 7).toLowerCase();\r
- if ((uricheck === 'ircs%3a') || (uricheck.substr(0,6) === 'irc%3a')) {\r
- parts[0] = decodeURIComponent(parts[0]);\r
- // irc[s]://<host>[:<port>]/[<channel>[?<password>]]\r
- uricheck = /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts[0]);\r
- /*\r
- uricheck[1] = ssl (optional)\r
- uricheck[2] = host\r
- uricheck[3] = port (optional)\r
- uricheck[4] = channel (optional)\r
- uricheck[5] = channel key (optional, channel must also be set)\r
- */\r
- if (uricheck) {\r
- if (typeof uricheck[1] !== 'undefined') {\r
- defaults.ssl = true;\r
- if (defaults.port === 6667) {\r
- defaults.port = 6697;\r
- }\r
- }\r
- defaults.server = uricheck[2];\r
- if (typeof uricheck[3] !== 'undefined') {\r
- defaults.port = uricheck[3];\r
- }\r
- if (typeof uricheck[4] !== 'undefined') {\r
- defaults.channel = '#' + uricheck[4];\r
- if (typeof uricheck[5] !== 'undefined') {\r
- defaults.channel_key = uricheck[5];\r
- }\r
- }\r
- }\r
- parts = [];\r
- } else {\r
- // Extract the port+ssl if we find one\r
- if (parts[0].search(/:/) > 0) {\r
- defaults.port = parts[0].substring(parts[0].search(/:/) + 1);\r
- defaults.server = parts[0].substring(0, parts[0].search(/:/));\r
- if (defaults.port[0] === '+') {\r
- defaults.port = parseInt(defaults.port.substring(1), 10);\r
- defaults.ssl = true;\r
- } else {\r
- defaults.ssl = false;\r
- }\r
-\r
- } else {\r
- defaults.server = parts[0];\r
- }\r
-\r
- parts.shift();\r
- }\r
- }\r
-\r
- if (parts.length > 0 && parts[0]) {\r
- defaults.channel = '#' + parts[0];\r
- parts.shift();\r
- }\r
- }\r
-\r
- // If any settings have been given by the server.. override any auto detected settings\r
- /**\r
- * Get any server restrictions as set in the server config\r
- * These settings can not be changed in the server selection dialog\r
- */\r
- if (this.server_settings && this.server_settings.connection) {\r
- if (this.server_settings.connection.server) {\r
- defaults.server = this.server_settings.connection.server;\r
- }\r
-\r
- if (this.server_settings.connection.port) {\r
- defaults.port = this.server_settings.connection.port;\r
- }\r
-\r
- if (this.server_settings.connection.ssl) {\r
- defaults.ssl = this.server_settings.connection.ssl;\r
- }\r
-\r
- if (this.server_settings.connection.channel) {\r
- defaults.channel = this.server_settings.connection.channel;\r
- }\r
-\r
- if (this.server_settings.connection.channel_key) {\r
- defaults.channel_key = this.server_settings.connection.channel_key;\r
- }\r
-\r
- if (this.server_settings.connection.nick) {\r
- defaults.nick = this.server_settings.connection.nick;\r
- }\r
- }\r
-\r
- // Set any random numbers if needed\r
- defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString());\r
-\r
- if (getQueryVariable('encoding'))\r
- defaults.encoding = getQueryVariable('encoding');\r
-\r
- // Populate the server select box with defaults\r
- new_connection_dialog.view.populateFields(defaults);\r
- },\r
-\r
-\r
panels: (function() {\r
var active_panel;\r
\r
_kiwi.model.NewConnection = Backbone.Collection.extend({
initialize: function() {
- this.view = new _kiwi.view.ServerSelect();
+ this.view = new _kiwi.view.ServerSelect({model: this});
this.view.bind('server_connect', this.onMakeConnection, this);
},
+ populateDefaultServerSettings: function () {
+ var parts;
+ var defaults = {
+ nick: '',
+ server: '',
+ port: 6667,
+ ssl: false,
+ channel: '',
+ channel_key: ''
+ };
+ var uricheck;
+
+
+ /**
+ * Get any settings set by the server
+ * These settings may be changed in the server selection dialog or via URL parameters
+ */
+ if (_kiwi.app.server_settings.client) {
+ if (_kiwi.app.server_settings.client.nick)
+ defaults.nick = _kiwi.app.server_settings.client.nick;
+
+ if (_kiwi.app.server_settings.client.server)
+ defaults.server = _kiwi.app.server_settings.client.server;
+
+ if (_kiwi.app.server_settings.client.port)
+ defaults.port = _kiwi.app.server_settings.client.port;
+
+ if (_kiwi.app.server_settings.client.ssl)
+ defaults.ssl = _kiwi.app.server_settings.client.ssl;
+
+ if (_kiwi.app.server_settings.client.channel)
+ defaults.channel = _kiwi.app.server_settings.client.channel;
+
+ if (_kiwi.app.server_settings.client.channel_key)
+ defaults.channel_key = _kiwi.app.server_settings.client.channel_key;
+ }
+
+
+
+ /**
+ * Get any settings passed in the URL
+ * These settings may be changed in the server selection dialog
+ */
+
+ // Any query parameters first
+ if (getQueryVariable('nick'))
+ defaults.nick = getQueryVariable('nick');
+
+ if (window.location.hash)
+ defaults.channel = window.location.hash;
+
+
+ // Process the URL part by part, extracting as we go
+ parts = window.location.pathname.toString().replace(_kiwi.app.get('base_path'), '').split('/');
+
+ if (parts.length > 0) {
+ parts.shift();
+
+ if (parts.length > 0 && parts[0]) {
+ // Check to see if we're dealing with an irc: uri, or whether we need to extract the server/channel info from the HTTP URL path.
+ uricheck = parts[0].substr(0, 7).toLowerCase();
+ if ((uricheck === 'ircs%3a') || (uricheck.substr(0,6) === 'irc%3a')) {
+ parts[0] = decodeURIComponent(parts[0]);
+ // irc[s]://<host>[:<port>]/[<channel>[?<password>]]
+ uricheck = /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts[0]);
+ /*
+ uricheck[1] = ssl (optional)
+ uricheck[2] = host
+ uricheck[3] = port (optional)
+ uricheck[4] = channel (optional)
+ uricheck[5] = channel key (optional, channel must also be set)
+ */
+ if (uricheck) {
+ if (typeof uricheck[1] !== 'undefined') {
+ defaults.ssl = true;
+ if (defaults.port === 6667) {
+ defaults.port = 6697;
+ }
+ }
+ defaults.server = uricheck[2];
+ if (typeof uricheck[3] !== 'undefined') {
+ defaults.port = uricheck[3];
+ }
+ if (typeof uricheck[4] !== 'undefined') {
+ defaults.channel = '#' + uricheck[4];
+ if (typeof uricheck[5] !== 'undefined') {
+ defaults.channel_key = uricheck[5];
+ }
+ }
+ }
+ parts = [];
+ } else {
+ // Extract the port+ssl if we find one
+ if (parts[0].search(/:/) > 0) {
+ defaults.port = parts[0].substring(parts[0].search(/:/) + 1);
+ defaults.server = parts[0].substring(0, parts[0].search(/:/));
+ if (defaults.port[0] === '+') {
+ defaults.port = parseInt(defaults.port.substring(1), 10);
+ defaults.ssl = true;
+ } else {
+ defaults.ssl = false;
+ }
+
+ } else {
+ defaults.server = parts[0];
+ }
+
+ parts.shift();
+ }
+ }
+
+ if (parts.length > 0 && parts[0]) {
+ defaults.channel = '#' + parts[0];
+ parts.shift();
+ }
+ }
+
+ // If any settings have been given by the server.. override any auto detected settings
+ /**
+ * Get any server restrictions as set in the server config
+ * These settings can not be changed in the server selection dialog
+ */
+ if (_kiwi.app.server_settings && _kiwi.app.server_settings.connection) {
+ if (_kiwi.app.server_settings.connection.server) {
+ defaults.server = _kiwi.app.server_settings.connection.server;
+ }
+
+ if (_kiwi.app.server_settings.connection.port) {
+ defaults.port = _kiwi.app.server_settings.connection.port;
+ }
+
+ if (_kiwi.app.server_settings.connection.ssl) {
+ defaults.ssl = _kiwi.app.server_settings.connection.ssl;
+ }
+
+ if (_kiwi.app.server_settings.connection.channel) {
+ defaults.channel = _kiwi.app.server_settings.connection.channel;
+ }
+
+ if (_kiwi.app.server_settings.connection.channel_key) {
+ defaults.channel_key = _kiwi.app.server_settings.connection.channel_key;
+ }
+
+ if (_kiwi.app.server_settings.connection.nick) {
+ defaults.nick = _kiwi.app.server_settings.connection.nick;
+ }
+ }
+
+ // Set any random numbers if needed
+ defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString());
+
+ if (getQueryVariable('encoding'))
+ defaults.encoding = getQueryVariable('encoding');
+
+ this.view.populateFields(defaults);
+ },
+
+
onMakeConnection: function(new_connection_event) {
var that = this,
transport_path = '',
channel: this.connect_details.channel,
key: this.connect_details.channel_key
};
- }
-
- // Show the server panel if this is our first network
- if (network && network.get('connection_id') === 0) {
- network.panels.server.view.show();
+ this.trigger('new_network', network);
}
}
});
\ No newline at end of file
-_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',
- 'change .have_pass input': 'showPass',
- 'change .have_key input': 'showKey',
- 'click .icon-key': 'channelKeyIconClick'
- },
-
- initialize: function () {
- var that = this,
- text = {
- think_nick: _kiwi.global.i18n.translate('client_views_serverselect_form_title').fetch(),
- nickname: _kiwi.global.i18n.translate('client_views_serverselect_nickname').fetch(),
- have_password: _kiwi.global.i18n.translate('client_views_serverselect_enable_password').fetch(),
- password: _kiwi.global.i18n.translate('client_views_serverselect_password').fetch(),
- channel: _kiwi.global.i18n.translate('client_views_serverselect_channel').fetch(),
- channel_key: _kiwi.global.i18n.translate('client_views_serverselect_channelkey').fetch(),
- require_key: _kiwi.global.i18n.translate('client_views_serverselect_channelkey_required').fetch(),
- key: _kiwi.global.i18n.translate('client_views_serverselect_key').fetch(),
- start: _kiwi.global.i18n.translate('client_views_serverselect_connection_start').fetch(),
- server_network: _kiwi.global.i18n.translate('client_views_serverselect_server_and_network').fetch(),
- server: _kiwi.global.i18n.translate('client_views_serverselect_server').fetch(),
- port: _kiwi.global.i18n.translate('client_views_serverselect_port').fetch(),
- powered_by: _kiwi.global.i18n.translate('client_views_serverselect_poweredby').fetch()
- };
-
- this.$el = $(_.template($('#tmpl_server_select').html().trim(), text));
-
- // Remove the 'more' link if the server has disabled server changing
- if (_kiwi.app.server_settings && _kiwi.app.server_settings.connection) {
- if (!_kiwi.app.server_settings.connection.allow_change) {
- this.$el.find('.show_more').remove();
- this.$el.addClass('single_server');
- }
- }
+_kiwi.view.ServerSelect = Backbone.View.extend({
+ events: {
+ 'submit form': 'submitForm',
+ 'click .show_more': 'showMore',
+ 'change .have_pass input': 'showPass',
+ 'change .have_key input': 'showKey',
+ 'click .icon-key': 'channelKeyIconClick',
+ 'click .show_server': 'showServer'
+ },
+
+ initialize: function () {
+ var that = this,
+ text = {
+ think_nick: _kiwi.global.i18n.translate('client_views_serverselect_form_title').fetch(),
+ nickname: _kiwi.global.i18n.translate('client_views_serverselect_nickname').fetch(),
+ have_password: _kiwi.global.i18n.translate('client_views_serverselect_enable_password').fetch(),
+ password: _kiwi.global.i18n.translate('client_views_serverselect_password').fetch(),
+ channel: _kiwi.global.i18n.translate('client_views_serverselect_channel').fetch(),
+ channel_key: _kiwi.global.i18n.translate('client_views_serverselect_channelkey').fetch(),
+ require_key: _kiwi.global.i18n.translate('client_views_serverselect_channelkey_required').fetch(),
+ key: _kiwi.global.i18n.translate('client_views_serverselect_key').fetch(),
+ start: _kiwi.global.i18n.translate('client_views_serverselect_connection_start').fetch(),
+ server_network: _kiwi.global.i18n.translate('client_views_serverselect_server_and_network').fetch(),
+ server: _kiwi.global.i18n.translate('client_views_serverselect_server').fetch(),
+ port: _kiwi.global.i18n.translate('client_views_serverselect_port').fetch(),
+ powered_by: _kiwi.global.i18n.translate('client_views_serverselect_poweredby').fetch()
+ };
- this.more_shown = false;
+ this.$el = $(_.template($('#tmpl_server_select').html().trim(), text));
+
+ // Remove the 'more' link if the server has disabled server changing
+ if (_kiwi.app.server_settings && _kiwi.app.server_settings.connection) {
+ if (!_kiwi.app.server_settings.connection.allow_change) {
+ this.$el.find('.show_more').remove();
+ this.$el.addClass('single_server');
+ }
+ }
- _kiwi.gateway.bind('onconnect', this.networkConnected, this);
- _kiwi.gateway.bind('connecting', this.networkConnecting, this);
- _kiwi.gateway.bind('onirc_error', this.onIrcError, this);
- },
+ // Are currently showing all the controlls or just a nick_change box?
+ this.state = 'all';
- dispose: function() {
- _kiwi.gateway.off('onconnect', this.networkConnected, this);
- _kiwi.gateway.off('connecting', this.networkConnecting, this);
- _kiwi.gateway.off('onirc_error', this.onIrcError, this);
+ this.more_shown = false;
- this.$el.remove();
- },
+ this.model.bind('new_network', this.newNetwork, this);
+ _kiwi.gateway.bind('onconnect', this.networkConnected, this);
+ _kiwi.gateway.bind('connecting', this.networkConnecting, this);
+ _kiwi.gateway.bind('onirc_error', this.onIrcError, this);
+ },
- submitForm: function (event) {
- event.preventDefault();
+ dispose: function() {
+ this.model.off('new_network', this.newNetwork, this);
+ _kiwi.gateway.off('onconnect', this.networkConnected, this);
+ _kiwi.gateway.off('connecting', this.networkConnecting, this);
+ _kiwi.gateway.off('onirc_error', this.onIrcError, this);
- // Make sure a nick is chosen
- if (!$('input.nick', this.$el).val().trim()) {
- this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_nickname_error_empty').fetch());
- $('input.nick', this.$el).select();
- return;
- }
+ this.remove();
+ },
- if (state === 'nick_change') {
- this.submitNickChange(event);
- } else {
- this.submitLogin(event);
- }
+ submitForm: function (event) {
+ event.preventDefault();
- $('button', this.$el).attr('disabled', 1);
+ // Make sure a nick is chosen
+ if (!$('input.nick', this.$el).val().trim()) {
+ this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_nickname_error_empty').fetch());
+ $('input.nick', this.$el).select();
return;
- },
-
- submitLogin: function (event) {
- // If submitting is disabled, don't do anything
- if ($('button', this.$el).attr('disabled')) return;
-
- var values = {
- nick: $('input.nick', this.$el).val(),
- server: $('input.server', this.$el).val(),
- port: $('input.port', this.$el).val(),
- ssl: $('input.ssl', this.$el).prop('checked'),
- password: $('input.password', this.$el).val(),
- channel: $('input.channel', this.$el).val(),
- channel_key: $('input.channel_key', this.$el).val(),
- options: this.server_options
- };
+ }
- this.trigger('server_connect', values);
- },
+ if (this.state === 'nick_change') {
+ this.submitNickChange(event);
+ } else {
+ this.submitLogin(event);
+ }
- submitNickChange: function (event) {
- _kiwi.gateway.changeNick(null, $('input.nick', this.$el).val());
- this.networkConnecting();
- },
+ $('button', this.$el).attr('disabled', 1);
+ return;
+ },
+
+ submitLogin: function (event) {
+ // If submitting is disabled, don't do anything
+ if ($('button', this.$el).attr('disabled')) return;
+
+ var values = {
+ nick: $('input.nick', this.$el).val(),
+ server: $('input.server', this.$el).val(),
+ port: $('input.port', this.$el).val(),
+ ssl: $('input.ssl', this.$el).prop('checked'),
+ password: $('input.password', this.$el).val(),
+ channel: $('input.channel', this.$el).val(),
+ channel_key: $('input.channel_key', this.$el).val(),
+ options: this.server_options
+ };
+
+ this.trigger('server_connect', values);
+ },
+
+ submitNickChange: function (event) {
+ _kiwi.gateway.changeNick(null, $('input.nick', this.$el).val());
+ this.networkConnecting();
+ },
+
+ showPass: function (event) {
+ if (this.$el.find('tr.have_pass input').is(':checked')) {
+ this.$el.find('tr.pass').show().find('input').focus();
+ } else {
+ this.$el.find('tr.pass').hide().find('input').val('');
+ }
+ },
- showPass: function (event) {
- if (this.$el.find('tr.have_pass input').is(':checked')) {
- this.$el.find('tr.pass').show().find('input').focus();
- } else {
- this.$el.find('tr.pass').hide().find('input').val('');
- }
- },
+ channelKeyIconClick: function (event) {
+ this.$el.find('tr.have_key input').click();
+ },
- channelKeyIconClick: function (event) {
- this.$el.find('tr.have_key input').click();
- },
+ showKey: function (event) {
+ if (this.$el.find('tr.have_key input').is(':checked')) {
+ this.$el.find('tr.key').show().find('input').focus();
+ } else {
+ this.$el.find('tr.key').hide().find('input').val('');
+ }
+ },
+
+ showMore: function (event) {
+ if (!this.more_shown) {
+ $('.more', this.$el).slideDown('fast');
+ $('.show_more', this.$el)
+ .children('.icon-caret-down')
+ .removeClass('icon-caret-down')
+ .addClass('icon-caret-up');
+ $('input.server', this.$el).select();
+ this.more_shown = true;
+ } else {
+ $('.more', this.$el).slideUp('fast');
+ $('.show_more', this.$el)
+ .children('.icon-caret-up')
+ .removeClass('icon-caret-up')
+ .addClass('icon-caret-down');
+ $('input.nick', this.$el).select();
+ this.more_shown = false;
+ }
+ },
+
+ populateFields: function (defaults) {
+ var nick, server, port, channel, channel_key, ssl, password;
+
+ defaults = defaults || {};
+
+ nick = defaults.nick || '';
+ server = defaults.server || '';
+ port = defaults.port || 6667;
+ ssl = defaults.ssl || 0;
+ password = defaults.password || '';
+ channel = defaults.channel || '';
+ channel_key = defaults.channel_key || '';
+
+ $('input.nick', this.$el).val(nick);
+ $('input.server', this.$el).val(server);
+ $('input.port', this.$el).val(port);
+ $('input.ssl', this.$el).prop('checked', ssl);
+ $('input#server_select_show_pass', this.$el).prop('checked', !(!password));
+ $('input.password', this.$el).val(password);
+ if (!(!password)) {
+ $('tr.pass', this.$el).show();
+ }
+ $('input.channel', this.$el).val(channel);
+ $('input#server_select_show_channel_key', this.$el).prop('checked', !(!channel_key));
+ $('input.channel_key', this.$el).val(channel_key);
+ if (!(!channel_key)) {
+ $('tr.key', this.$el).show();
+ }
- showKey: function (event) {
- if (this.$el.find('tr.have_key input').is(':checked')) {
- this.$el.find('tr.key').show().find('input').focus();
- } else {
- this.$el.find('tr.key').hide().find('input').val('');
- }
- },
-
- showMore: function (event) {
- if (!this.more_shown) {
- $('.more', this.$el).slideDown('fast');
- $('.show_more', this.$el)
- .children('.icon-caret-down')
- .removeClass('icon-caret-down')
- .addClass('icon-caret-up');
- $('input.server', this.$el).select();
- this.more_shown = true;
- } else {
- $('.more', this.$el).slideUp('fast');
- $('.show_more', this.$el)
- .children('.icon-caret-up')
- .removeClass('icon-caret-up')
- .addClass('icon-caret-down');
- $('input.nick', this.$el).select();
- this.more_shown = false;
- }
- },
-
- populateFields: function (defaults) {
- var nick, server, port, channel, channel_key, ssl, password;
-
- defaults = defaults || {};
-
- nick = defaults.nick || '';
- server = defaults.server || '';
- port = defaults.port || 6667;
- ssl = defaults.ssl || 0;
- password = defaults.password || '';
- channel = defaults.channel || '';
- channel_key = defaults.channel_key || '';
-
- $('input.nick', this.$el).val(nick);
- $('input.server', this.$el).val(server);
- $('input.port', this.$el).val(port);
- $('input.ssl', this.$el).prop('checked', ssl);
- $('input#server_select_show_pass', this.$el).prop('checked', !(!password));
- $('input.password', this.$el).val(password);
- if (!(!password)) {
- $('tr.pass', this.$el).show();
- }
- $('input.channel', this.$el).val(channel);
- $('input#server_select_show_channel_key', this.$el).prop('checked', !(!channel_key));
- $('input.channel_key', this.$el).val(channel_key);
- if (!(!channel_key)) {
- $('tr.key', this.$el).show();
- }
+ // Temporary values
+ this.server_options = {};
- // Temporary values
- this.server_options = {};
+ if (defaults.encoding)
+ this.server_options.encoding = defaults.encoding;
+ },
- if (defaults.encoding)
- this.server_options.encoding = defaults.encoding;
- },
+ hide: function () {
+ this.$el.slideUp();
+ },
- hide: function () {
- this.$el.slideUp();
- },
+ show: function (new_state) {
+ new_state = new_state || 'all';
- show: function (new_state) {
- new_state = new_state || 'all';
+ this.$el.show();
- this.$el.show();
+ if (new_state === 'all') {
+ $('.show_more', this.$el).show();
- if (new_state === 'all') {
- $('.show_more', this.$el).show();
+ } else if (new_state === 'more') {
+ $('.more', this.$el).slideDown('fast');
- } 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();
+ $('input.nick', this.$el).select();
- } else if (new_state === 'nick_change') {
- $('.more', this.$el).hide();
- $('.show_more', this.$el).hide();
- $('input.nick', this.$el).select();
+ } else if (new_state === 'enter_password') {
+ $('.more', this.$el).hide();
+ $('.show_more', this.$el).hide();
+ $('input.password', this.$el).select();
+ }
- } else if (new_state === 'enter_password') {
- $('.more', this.$el).hide();
- $('.show_more', this.$el).hide();
- $('input.password', this.$el).select();
- }
+ this.state = new_state;
+ },
- state = new_state;
- },
-
- infoBoxShow: function() {
- var $side_panel = this.$el.find('.side_panel');
-
- // Some theme may hide the info panel so check before we
- // resize ourselves
- if (!$side_panel.is(':visible'))
- return;
-
- this.$el.animate({
- width: parseInt($side_panel.css('left'), 10) + $side_panel.find('.content:first').outerWidth()
- });
- },
-
- infoBoxHide: function() {
- var $side_panel = this.$el.find('.side_panel');
- this.$el.animate({
- width: parseInt($side_panel.css('left'), 10)
- });
- },
-
- infoBoxSet: function($info_view) {
- this.$el.find('.side_panel .content')
- .empty()
- .append($info_view);
- },
-
- 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(_kiwi.global.i18n.translate('client_views_serverselect_connection_successfully').fetch() + ' :)', 'ok');
- $('form', this.$el).hide();
- },
-
- networkConnecting: function (event) {
- this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_connection_trying').fetch(), 'ok');
- },
-
- onIrcError: function (data) {
- $('button', this.$el).attr('disabled', null);
-
- switch(data.error) {
- case 'nickname_in_use':
- this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_nickname_error_alreadyinuse').fetch());
- this.show('nick_change');
- this.$el.find('.nick').select();
- break;
- case 'erroneus_nickname':
- this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_nickname_invalid').fetch());
- this.show('nick_change');
- this.$el.find('.nick').select();
- break;
- case 'password_mismatch':
- this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_password_incorrect').fetch());
- this.show('enter_password');
- this.$el.find('.password').select();
- break;
- }
- },
+ infoBoxShow: function() {
+ var $side_panel = this.$el.find('.side_panel');
- showError: function (error_reason) {
- var err_text = _kiwi.global.i18n.translate('client_views_serverselect_connection_error').fetch();
+ // Some theme may hide the info panel so check before we
+ // resize ourselves
+ if (!$side_panel.is(':visible'))
+ return;
- if (error_reason) {
- switch (error_reason) {
- case 'ENOTFOUND':
- err_text = _kiwi.global.i18n.translate('client_views_serverselect_server_notfound').fetch();
- break;
+ this.$el.animate({
+ width: parseInt($side_panel.css('left'), 10) + $side_panel.find('.content:first').outerWidth()
+ });
+ },
+
+ infoBoxHide: function() {
+ var $side_panel = this.$el.find('.side_panel');
+ this.$el.animate({
+ width: parseInt($side_panel.css('left'), 10)
+ });
+ },
+
+ infoBoxSet: function($info_view) {
+ this.$el.find('.side_panel .content')
+ .empty()
+ .append($info_view);
+ },
+
+ setStatus: function (text, class_name) {
+ $('.status', this.$el)
+ .text(text)
+ .attr('class', 'status')
+ .addClass(class_name||'')
+ .show();
+ },
+ clearStatus: function () {
+ $('.status', this.$el).hide();
+ },
+
+ reset: function() {
+ this.populateFields();
+ this.clearStatus();
+
+ this.$('button').attr('disabled', null);
+ },
+
+ newNetwork: function(network) {
+ // Keep a reference to this network so we can interact with it
+ this.model.current_connecting_network = network;
+ },
+
+ networkConnected: function (event) {
+ this.model.trigger('connected', _kiwi.app.connections.getByConnectionId(event.server));
+ this.model.current_connecting_network = null;
+ },
+
+ networkConnecting: function (event) {
+ this.model.trigger('connecting');
+ this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_connection_trying').fetch(), 'ok');
+
+ this.$('.status').append('<a class="show_server"><i class="icon-info-sign"></i></a>');
+ },
+
+ showServer: function() {
+ // If we don't have a current connection in the making then we have nothing to show
+ if (!this.model.current_connecting_network)
+ return;
- case 'ECONNREFUSED':
- err_text += ' (' + _kiwi.global.i18n.translate('client_views_serverselect_connection_refused').fetch() + ')';
- break;
+ _kiwi.app.view.barsShow();
+ this.model.current_connecting_network.panels.server.view.show();
+ },
+
+ onIrcError: function (data) {
+ $('button', this.$el).attr('disabled', null);
+
+ switch(data.error) {
+ case 'nickname_in_use':
+ this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_nickname_error_alreadyinuse').fetch());
+ this.show('nick_change');
+ this.$el.find('.nick').select();
+ break;
+ case 'erroneus_nickname':
+ this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_nickname_invalid').fetch());
+ this.show('nick_change');
+ this.$el.find('.nick').select();
+ break;
+ case 'password_mismatch':
+ this.setStatus(_kiwi.global.i18n.translate('client_views_serverselect_password_incorrect').fetch());
+ this.show('enter_password');
+ this.$el.find('.password').select();
+ break;
+ }
+ },
- default:
- err_text += ' (' + error_reason + ')';
- }
- }
+ showError: function (error_reason) {
+ var err_text = _kiwi.global.i18n.translate('client_views_serverselect_connection_error').fetch();
- this.setStatus(err_text, 'error');
- $('button', this.$el).attr('disabled', null);
- this.show();
- }
- });
+ if (error_reason) {
+ switch (error_reason) {
+ case 'ENOTFOUND':
+ err_text = _kiwi.global.i18n.translate('client_views_serverselect_server_notfound').fetch();
+ break;
+ case 'ECONNREFUSED':
+ err_text += ' (' + _kiwi.global.i18n.translate('client_views_serverselect_connection_refused').fetch() + ')';
+ break;
+
+ default:
+ err_text += ' (' + error_reason + ')';
+ }
+ }
- return new model(arguments);
-};
\ No newline at end of file
+ this.setStatus(err_text, 'error');
+ $('button', this.$el).attr('disabled', null);
+ this.show();
+ }
+});
\ No newline at end of file