Startup screen is now a configurable applet
authorDarren <darren@darrenwhitlen.com>
Sat, 8 Mar 2014 14:18:56 +0000 (14:18 +0000)
committerDarren <darren@darrenwhitlen.com>
Sat, 8 Mar 2014 14:18:56 +0000 (14:18 +0000)
13 files changed:
client/assets/themes/basic/style.css
client/assets/themes/cli/style.css
client/assets/themes/mini/style.css
client/assets/themes/relaxed/style.css
client/src/applets/startup.js [new file with mode: 0644]
client/src/index.html.tmpl
client/src/models/applet.js
client/src/models/application.js
client/src/models/network.js
client/src/models/newconnection.js
client/src/views/apptoolbar.js
client/src/views/serverselect.js
server/settingsgenerator.js

index e0aae246c40008001a5a19ae18d505aa9e976aa0..8721911685a93c15312716c8f6cee6beea1cf30d 100644 (file)
     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; }
index a800c3c0784074cb0682edabfe11bca9d77aa4b6..e323fac9e3f1416d50fd558a31b2fbb695009735 100644 (file)
     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; }
 
index 24f8ab6eef8e3b0972d59864ce5b3b8be48044fc..c6fa7c7fc6d8e30763066c81aa4964843ce29715 100644 (file)
     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;
index e816849e17e1ee7c367d616f3cfd74ad76e727b4..c58762a856566dcbaab601cc5c7c75fb26808cce 100644 (file)
     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 (file)
index 0000000..54d7eef
--- /dev/null
@@ -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
index 8c32f7e586645564a212809a5b3b9b09ecf3dd12..2d2a04ce597808af5d10e7a0b5702c570aa01211 100644 (file)
@@ -23,6 +23,7 @@
                 <div class="app_tools">\r
                     <ul class="main">\r
                         <li class="settings"><i class="icon-cogs" title="Settings"></i></li>\r
+                        <li class="startup"><i class="icon-home" title="Home"></i></li>\r
                         <li><a href="https://kiwiirc.com/" target="_blank"><img src="<%base_path%>/assets/img/ico.png" alt="KiwiIRC" title="KiwiIRC" /></a></li>\r
                     </ul>\r
                 </div>\r
index 3414ebf314cadc44d546a6ddd079d50fc11c1173..0175791acf9c43a901cbfdbf59fb823c5149ea3d 100644 (file)
@@ -68,7 +68,7 @@ _kiwi.model.Applet = _kiwi.model.Panel.extend({
     close: function () {\r
         this.view.$el.remove();\r
         this.destroy();\r
-        \r
+\r
         this.view = undefined;\r
 \r
         // Call the applets dispose method if it has one\r
@@ -110,24 +110,34 @@ _kiwi.model.Applet = _kiwi.model.Panel.extend({
     },\r
 \r
 \r
-    load: function (applet_name) {\r
-        var applet;\r
+    load: function (applet_name, options) {\r
+        var applet, applet_obj;\r
+\r
+        options = options || {};\r
+\r
+        applet_obj = this.getApplet(applet_name);\r
 \r
-        // Find the applet within the registered applets\r
-        if (!_kiwi.applets[applet_name]) return;\r
+        if (!applet_obj)\r
+            return;\r
 \r
         // Create the applet and load the content\r
         applet = new _kiwi.model.Applet();\r
-        applet.load(new _kiwi.applets[applet_name]({_applet_name: applet_name}));\r
+        applet.load(new applet_obj({_applet_name: applet_name}));\r
 \r
-        // Add it into the tab list\r
-        _kiwi.app.applet_panels.add(applet);\r
+        // Add it into the tab list if needed (default)\r
+        if (!options.no_tab)\r
+            _kiwi.app.applet_panels.add(applet);\r
 \r
 \r
         return applet;\r
     },\r
 \r
 \r
+    getApplet: function (applet_name) {\r
+        return _kiwi.applets[applet_name] || null;\r
+    },\r
+\r
+\r
     register: function (applet_name, applet) {\r
         _kiwi.applets[applet_name] = applet;\r
     }\r
index d8d6ba64d6132a346bb11195aa2c89bb1884bd4b..ecd5279a897ada76c163a3dbe500dacaf9bf7cc4 100644 (file)
@@ -32,6 +32,9 @@
             // 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
@@ -49,7 +52,7 @@
 \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
index 2b890abfa0bd022f79b61bf0f4862c546dad1264..810cdaef4205a821f538fe23aa99b703ff21f192 100644 (file)
 
 
     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)) {
 
         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});
+        }
     }
 
 
index 90db39b1ab5b4aa22743694353ff5b44a9209592..a2e16e79612e1fcf8cf3f2510229db7d740e9ad5 100644 (file)
 _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 = '',
@@ -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
index 1fc51486749d7a155777f371afca1f5d676c9110..5d4b87b8b96337009008d0ec9c5eb3546e607c1d 100644 (file)
@@ -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
index ceb11dafff8159eebe894f569f6b8a06603a8f9f..ded2203c435634ab7d1a013f117e97db90a0c058 100644 (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
index d79753564a1fcf4a0cead80395ca1dea5f612d83..89d1d25d54fe4dcda4b840eb92722636d9bdaf5e 100644 (file)
@@ -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