From 17f187e64889b86419d9c733767fa7c0be188941 Mon Sep 17 00:00:00 2001 From: Darren Date: Sat, 8 Mar 2014 14:18:56 +0000 Subject: [PATCH] Startup screen is now a configurable applet --- client/assets/themes/basic/style.css | 1 + client/assets/themes/cli/style.css | 1 + client/assets/themes/mini/style.css | 1 + client/assets/themes/relaxed/style.css | 1 + client/src/applets/startup.js | 49 +++ client/src/index.html.tmpl | 1 + client/src/models/applet.js | 26 +- client/src/models/application.js | 199 +-------- client/src/models/network.js | 12 +- client/src/models/newconnection.js | 166 +++++++- client/src/views/apptoolbar.js | 11 +- client/src/views/serverselect.js | 558 +++++++++++++------------ server/settingsgenerator.js | 12 +- 13 files changed, 553 insertions(+), 485 deletions(-) create mode 100644 client/src/applets/startup.js diff --git a/client/assets/themes/basic/style.css b/client/assets/themes/basic/style.css index e0aae24..8721911 100644 --- a/client/assets/themes/basic/style.css +++ b/client/assets/themes/basic/style.css @@ -286,6 +286,7 @@ border:1px solid #A33F3F; background-color:#D28A8A; padding:0.5em; margin-top:1em; margin-bottom:1em; margin-right:2em; } +#kiwi .server_select .show_server { margin-left: 1em; font-size:0.9em; color: #555555; } #kiwi .server_select .kiwi_logo { margin-top:30px; text-align:center; display:block; } diff --git a/client/assets/themes/cli/style.css b/client/assets/themes/cli/style.css index a800c3c..e323fac 100644 --- a/client/assets/themes/cli/style.css +++ b/client/assets/themes/cli/style.css @@ -214,6 +214,7 @@ border:1px solid #A33F3F; background-color:#D28A8A; padding:0.5em; margin-top:1em; margin-bottom:1em; margin-right:2em; } +#kiwi .server_select .show_server { margin-left: 1em; font-size:0.9em; color: #eeeeee; } #kiwi .server_select .basic tr.channel .icon-key { color:#555; } diff --git a/client/assets/themes/mini/style.css b/client/assets/themes/mini/style.css index 24f8ab6..c6fa7c7 100644 --- a/client/assets/themes/mini/style.css +++ b/client/assets/themes/mini/style.css @@ -233,6 +233,7 @@ border:1px solid #A33F3F; background-color:#D28A8A; padding:0.5em; margin-top:1em; margin-bottom:1em; margin-right:2em; } +#kiwi .server_select .show_server { margin-left: 1em; font-size:0.9em; color: #555555; } #kiwi .server_select .kiwi_logo h1 span { font-size:14px; diff --git a/client/assets/themes/relaxed/style.css b/client/assets/themes/relaxed/style.css index e816849..c58762a 100644 --- a/client/assets/themes/relaxed/style.css +++ b/client/assets/themes/relaxed/style.css @@ -348,6 +348,7 @@ border:1px solid #A33F3F; background-color:#D28A8A; padding:0.5em; margin-top:1em; margin-bottom:1em; margin-right:2em; } +#kiwi .server_select .show_server { margin-left: 1em; font-size:0.9em; color: #555555; } #kiwi .server_select .kiwi_logo { margin-top:30px; } diff --git a/client/src/applets/startup.js b/client/src/applets/startup.js new file mode 100644 index 0000000..54d7eef --- /dev/null +++ b/client/src/applets/startup.js @@ -0,0 +1,49 @@ +(function () { + var view = Backbone.View.extend({ + events: {}, + + + initialize: function (options) { + this.showConnectionDialog(); + }, + + + showConnectionDialog: function() { + var connection_dialog = this.connection_dialog = new _kiwi.model.NewConnection(); + connection_dialog.populateDefaultServerSettings(); + + connection_dialog.view.$el.addClass('initial'); + this.$el.append(connection_dialog.view.$el); + + var $info = $($('#tmpl_new_connection_info').html().trim()); + + if ($info.html()) { + connection_dialog.view.infoBoxSet($info); + connection_dialog.view.infoBoxShow(); + } + + this.listenTo(connection_dialog, 'connected', this.newConnectionConnected); + + _.defer(function(){ + connection_dialog.view.$el.find('.nick').select(); + }); + }, + + + newConnectionConnected: function(network) { + // Once connected, reset the connection form to be used again in future + this.connection_dialog.view.reset(); + } + }); + + + + var applet = Backbone.Model.extend({ + initialize: function () { + this.view = new view({model: this}); + } + }); + + + _kiwi.model.Applet.register('kiwi_startup', applet); +})(); \ No newline at end of file diff --git a/client/src/index.html.tmpl b/client/src/index.html.tmpl index 8c32f7e..2d2a04c 100644 --- a/client/src/index.html.tmpl +++ b/client/src/index.html.tmpl @@ -23,6 +23,7 @@
diff --git a/client/src/models/applet.js b/client/src/models/applet.js index 3414ebf..0175791 100644 --- a/client/src/models/applet.js +++ b/client/src/models/applet.js @@ -68,7 +68,7 @@ _kiwi.model.Applet = _kiwi.model.Panel.extend({ close: function () { this.view.$el.remove(); this.destroy(); - + this.view = undefined; // Call the applets dispose method if it has one @@ -110,24 +110,34 @@ _kiwi.model.Applet = _kiwi.model.Panel.extend({ }, - load: function (applet_name) { - var applet; + load: function (applet_name, options) { + var applet, applet_obj; + + options = options || {}; + + applet_obj = this.getApplet(applet_name); - // Find the applet within the registered applets - if (!_kiwi.applets[applet_name]) return; + if (!applet_obj) + return; // Create the applet and load the content applet = new _kiwi.model.Applet(); - applet.load(new _kiwi.applets[applet_name]({_applet_name: applet_name})); + applet.load(new applet_obj({_applet_name: applet_name})); - // Add it into the tab list - _kiwi.app.applet_panels.add(applet); + // Add it into the tab list if needed (default) + if (!options.no_tab) + _kiwi.app.applet_panels.add(applet); return applet; }, + getApplet: function (applet_name) { + return _kiwi.applets[applet_name] || null; + }, + + register: function (applet_name, applet) { _kiwi.applets[applet_name] = applet; } diff --git a/client/src/models/application.js b/client/src/models/application.js index d8d6ba6..ecd5279 100644 --- a/client/src/models/application.js +++ b/client/src/models/application.js @@ -32,6 +32,9 @@ // Best guess at where the kiwi server is if not already specified this.kiwi_server = options.kiwi_server || this.detectKiwiServer(); + // The applet to initially load + this.startup_applet_name = options.startup || 'kiwi_startup'; + // Set any default settings before anything else is applied if (this.server_settings && this.server_settings.client && this.server_settings.client.settings) { this.applyDefaultClientSettings(this.server_settings.client.settings); @@ -49,7 +52,7 @@ this.view.barsHide(true); - this.showIntialConenctionDialog(); + this.showStartup(); }, @@ -64,37 +67,10 @@ }, - showIntialConenctionDialog: function() { - var connection_dialog = new _kiwi.model.NewConnection(); - this.populateDefaultServerSettings(connection_dialog); - - connection_dialog.view.$el.addClass('initial'); - this.view.$el.find('.panel_container:first').append(connection_dialog.view.$el); - - var $info = $($('#tmpl_new_connection_info').html().trim()); - - if ($info.html()) { - connection_dialog.view.infoBoxSet($info); - connection_dialog.view.infoBoxShow(); - } - - // TODO: Shouldn't really be here but it's not working in the view.. :/ - // Hack for firefox browers: Focus is not given on this event loop iteration - setTimeout(function(){ - connection_dialog.view.$el.find('.nick').select(); - }, 0); - - // Once connected, close this dialog and remove its own event - var fn = function() { - connection_dialog.view.$el.slideUp(function() { - connection_dialog.view.dispose(); - connection_dialog = null; - - _kiwi.gateway.off('onconnect', fn); - }); - - }; - _kiwi.gateway.on('onconnect', fn); + showStartup: function() { + this.startup_applet = _kiwi.model.Applet.load(this.startup_applet_name, {no_tab: true}); + this.startup_applet.tab = this.view.$('.console'); + this.startup_applet.view.show(); }, @@ -149,165 +125,6 @@ }, - populateDefaultServerSettings: function (new_connection_dialog) { - var parts; - var defaults = { - nick: '', - server: '', - port: 6667, - ssl: false, - channel: '#chat', - 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 (this.server_settings.client) { - if (this.server_settings.client.nick) - defaults.nick = this.server_settings.client.nick; - - if (this.server_settings.client.server) - defaults.server = this.server_settings.client.server; - - if (this.server_settings.client.port) - defaults.port = this.server_settings.client.port; - - if (this.server_settings.client.ssl) - defaults.ssl = this.server_settings.client.ssl; - - if (this.server_settings.client.channel) - defaults.channel = this.server_settings.client.channel; - - if (this.server_settings.client.channel_key) - defaults.channel_key = this.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(this.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]://[:]/[[?]] - 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 (this.server_settings && this.server_settings.connection) { - if (this.server_settings.connection.server) { - defaults.server = this.server_settings.connection.server; - } - - if (this.server_settings.connection.port) { - defaults.port = this.server_settings.connection.port; - } - - if (this.server_settings.connection.ssl) { - defaults.ssl = this.server_settings.connection.ssl; - } - - if (this.server_settings.connection.channel) { - defaults.channel = this.server_settings.connection.channel; - } - - if (this.server_settings.connection.channel_key) { - defaults.channel_key = this.server_settings.connection.channel_key; - } - - if (this.server_settings.connection.nick) { - defaults.nick = this.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'); - - // Populate the server select box with defaults - new_connection_dialog.view.populateFields(defaults); - }, - - panels: (function() { var active_panel; diff --git a/client/src/models/network.js b/client/src/models/network.js index 2b890ab..810cdae 100644 --- a/client/src/models/network.js +++ b/client/src/models/network.js @@ -462,7 +462,7 @@ function onNotice(event) { - var panel, channel_name; + var panel, active_panel, channel_name; // An ignored user? don't do anything with it if (!event.from_server && event.nick && this.isNickIgnored(event.nick)) { @@ -492,9 +492,13 @@ panel.addMsg('[' + (event.nick||'') + ']', event.msg, 'notice', {time: event.time}); - // Show this notice to the active panel if it didn't have a set target - if (!event.from_server && panel === this.panels.server && _kiwi.app.panels().active !== this.panels.server) - _kiwi.app.panels().active.addMsg('[' + (event.nick||'') + ']', event.msg, 'notice', {time: event.time}); + // Show this notice to the active panel if it didn't have a set target, but only in an active channel or query window + active_panel = _kiwi.app.panels().active; + + if (!event.from_server && panel === this.panels.server && active_panel !== this.panels.server) { + if (active_panel.isChannel() || active_panel.isQuery()) + active_panel.addMsg('[' + (event.nick||'') + ']', event.msg, 'notice', {time: event.time}); + } } diff --git a/client/src/models/newconnection.js b/client/src/models/newconnection.js index 90db39b..a2e16e7 100644 --- a/client/src/models/newconnection.js +++ b/client/src/models/newconnection.js @@ -1,12 +1,170 @@ _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]://[:]/[[?]] + 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 = '', @@ -62,12 +220,8 @@ _kiwi.model.NewConnection = Backbone.Collection.extend({ 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 diff --git a/client/src/views/apptoolbar.js b/client/src/views/apptoolbar.js index 1fc5148..5d4b87b 100644 --- a/client/src/views/apptoolbar.js +++ b/client/src/views/apptoolbar.js @@ -1,12 +1,19 @@ _kiwi.view.AppToolbar = Backbone.View.extend({ events: { - 'click .settings': 'clickSettings' + 'click .settings': 'clickSettings', + 'click .startup': 'clickStartup' }, initialize: function () { }, clickSettings: function (event) { + event.preventDefault(); _kiwi.app.controlbox.processInput('/settings'); - } + }, + + clickStartup: function (event) { + event.preventDefault(); + _kiwi.app.startup_applet.view.show(); + }, }); \ No newline at end of file diff --git a/client/src/views/serverselect.js b/client/src/views/serverselect.js index ceb11da..ded2203 100644 --- a/client/src/views/serverselect.js +++ b/client/src/views/serverselect.js @@ -1,299 +1,321 @@ -_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(''); + }, + + 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 diff --git a/server/settingsgenerator.js b/server/settingsgenerator.js index d797535..89d1d25 100644 --- a/server/settingsgenerator.js +++ b/server/settingsgenerator.js @@ -213,12 +213,6 @@ function addScripts(vars, debug) { [ 'src/models/query.js', 'src/models/server.js', // Depends on models/channel.js - 'src/applets/settings.js', - 'src/applets/chanlist.js', - 'src/applets/scripteditor.js' - ], - - [ 'src/models/pluginmanager.js', 'src/models/datastore.js', 'src/helpers/utils.js' @@ -250,6 +244,12 @@ function addScripts(vars, debug) { 'src/views/userbox.js', 'src/views/channeltools.js', 'src/views/channelinfo.js' + ], + [ + 'src/applets/settings.js', + 'src/applets/chanlist.js', + 'src/applets/scripteditor.js', + 'src/applets/startup.js' ] ]); } \ No newline at end of file -- 2.25.1