From f2bb538081e9e7a603f2e22d8c1dcadc3fa4fffd Mon Sep 17 00:00:00 2001 From: Darren Date: Sat, 27 Apr 2013 22:06:25 +0100 Subject: [PATCH] Connection dialog removed from the server panel --- client/assets/dev/build.js | 1 + client/assets/dev/index.html.tmpl | 3 +- client/assets/dev/model_application.js | 91 ++++++++++-------------- client/assets/dev/model_gateway.js | 19 ++--- client/assets/dev/model_newconnection.js | 69 ++++++++++++++++++ client/assets/dev/model_server.js | 5 -- client/assets/dev/view.js | 49 ++++++++----- 7 files changed, 147 insertions(+), 90 deletions(-) create mode 100644 client/assets/dev/model_newconnection.js diff --git a/client/assets/dev/build.js b/client/assets/dev/build.js index 8adba49..adb6e61 100644 --- a/client/assets/dev/build.js +++ b/client/assets/dev/build.js @@ -35,6 +35,7 @@ var src = concat([ __dirname + '/model_network.js', __dirname + '/model_member.js', __dirname + '/model_memberlist.js', + __dirname + 'dev/model_newconnection.js', __dirname + '/model_panel.js', __dirname + '/model_panellist.js', __dirname + '/model_networkpanellist.js', diff --git a/client/assets/dev/index.html.tmpl b/client/assets/dev/index.html.tmpl index 40cd32e..4b34b58 100644 --- a/client/assets/dev/index.html.tmpl +++ b/client/assets/dev/index.html.tmpl @@ -38,7 +38,7 @@
-
+
@@ -274,6 +274,7 @@ 'dev/model_gateway.js' ], [ + 'dev/model_newconnection.js', 'dev/model_panellist.js', 'dev/model_networkpanellist.js', 'dev/model_panel.js', diff --git a/client/assets/dev/model_application.js b/client/assets/dev/model_application.js index caf879b..f884c2b 100644 --- a/client/assets/dev/model_application.js +++ b/client/assets/dev/model_application.js @@ -44,7 +44,7 @@ _kiwi.model.Application = function () { } else { //manageDebug(true); } - + // Set the gateway up _kiwi.gateway = new _kiwi.model.Gateway(); this.bindGatewayCommands(_kiwi.gateway); @@ -54,45 +54,10 @@ _kiwi.model.Application = function () { this.view.barsHide(true); - this.connections.getByConnectionId(0).panels.server.server_login.bind('server_connect', function (event) { - var server_login = this, - transport_path = ''; - auto_connect_details = event; - - server_login.networkConnecting(); - - // Path to get the socket.io transport code - transport_path = that.kiwi_server + that.get('base_path') + '/transport/socket.io.js?ts='+(new Date().getTime()); - - $script(transport_path, function () { - if (!window.io) { - kiwiServerNotFound(); - return; - } - _kiwi.gateway.set('kiwi_server', that.kiwi_server + '/kiwi'); - _kiwi.gateway.set('nick', event.nick); - - _kiwi.gateway.connect(event.nick, event.server, event.port, event.ssl, event.password, function (error) { - if (error) { - kiwiServerNotFound(); - } - }); - }); - }); - - // 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(){ - _kiwi.app.connections.getByConnectionId(0).panels.server.server_login.$el.find('.nick').select(); - }, 0); + this.showIntialConenctionDialog(); }; - function kiwiServerNotFound (e) { - that.connections.getByConnectionId(0).panels.server.server_login.showError(); - } - - this.detectKiwiServer = function () { // If running from file, default to localhost:7777 by default if (window.location.protocol === 'file:') { @@ -104,22 +69,48 @@ _kiwi.model.Application = function () { }; + this.showIntialConenctionDialog = function() { + var connection_dialog = new _kiwi.model.NewConnection(); + this.populateDefaultServerSettings(connection_dialog); + + var m = new _kiwi.view.MenuBox(); + m.showFooter(false); + m.closeOnBlur(false); + m.addItem('new_connection', connection_dialog.view.$el); + m.show(); + + // Center the connection dialog + m.$el.addClass('first'); + m.$el.offset({ + left: (this.view.$el.width() / 2) - (m.$el.width() / 2) + }); + + // 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('fast', function() { + m.dispose(); + _kiwi.gateway.off('onconnect', fn); + }); + + }; + _kiwi.gateway.on('onconnect', fn); + }; + + this.initializeClient = function () { this.view = new _kiwi.view.Application({model: this, el: this.get('container')}); + // Applets panel list this.applet_panels = new _kiwi.model.PanelList(); this.applet_panels.view.$el.addClass('panellist applets'); this.view.$el.find('#tabs').append(this.applet_panels.view.$el); - /** - * This is temporary. - * While multiple server support is being worked on, - * we will keep this single server variable here until - * It all gets moved over - */ - var connection = new _kiwi.model.Network({connection_id: 0}); - this.connections.add(connection); - /** * Set the UI components up */ @@ -133,13 +124,9 @@ _kiwi.model.Application = function () { this.message = new _kiwi.view.StatusMessage({el: $('#status_message')[0]}); this.resize_handle = new _kiwi.view.ResizeHandler({el: $('#memberlists_resize_handle')[0]}); - - this.connections.getByConnectionId(0).panels.server.view.show(); // Rejigg the UI sizes this.view.doLayout(); - - this.populateDefaultServerSettings(); }; @@ -151,7 +138,7 @@ _kiwi.model.Application = function () { }; - this.populateDefaultServerSettings = function () { + this.populateDefaultServerSettings = function (new_connection_dialog) { var parts; var defaults = { nick: getQueryVariable('nick') || '', @@ -288,7 +275,7 @@ _kiwi.model.Application = function () { defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString()); // Populate the server select box with defaults - this.connections.getByConnectionId(0).panels.server.server_login.populateFields(defaults); + new_connection_dialog.view.populateFields(defaults); }; diff --git a/client/assets/dev/model_gateway.js b/client/assets/dev/model_gateway.js index abe95d8..0cf09fb 100644 --- a/client/assets/dev/model_gateway.js +++ b/client/assets/dev/model_gateway.js @@ -132,14 +132,9 @@ _kiwi.model.Gateway = function () { /** * Connects to the server - * @param {String} nick The nickname of the user to use on the network - * @param {String} host The hostname or IP address of the IRC server to connect to - * @param {Number} port The port of the IRC server to connect to - * @param {Boolean} ssl Whether or not to connect to the IRC server using SSL - * @param {String} password The password to supply to the IRC server during registration * @param {Function} callback A callback function to be invoked once Kiwi's server has connected to the IRC server */ - this.connect = function (nick, host, port, ssl, password, callback) { + this.connect = function (callback) { var resource; // Work out the resource URL for socket.io @@ -153,7 +148,7 @@ _kiwi.model.Gateway = function () { this.socket = io.connect(this.get('kiwi_server'), { 'resource': resource, - + 'try multiple transports': true, 'connect timeout': 3000, 'max reconnection attempts': 7, @@ -182,13 +177,7 @@ _kiwi.model.Gateway = function () { * IRCD and the nick has been accepted. */ this.socket.on('connect', function () { - that.newConnection({ - nick: nick, - host: host, - port: port, - ssl: ssl, - password: password - }, callback); + callback && callback(); /* this.emit('kiwi', {command: 'connect', nick: that.get('nick'), hostname: host, port: port, ssl: ssl, password:password}, function (err, server_num) { if (!err) { @@ -244,7 +233,7 @@ _kiwi.model.Gateway = function () { if (!err) { // TODO: Remove this whole premature connection thing when panel code is tidied - if (server_num != 0 && !_kiwi.app.connections.getByConnectionId(server_num)){ + if (!_kiwi.app.connections.getByConnectionId(server_num)){ connection = new _kiwi.model.Network({connection_id: server_num}); _kiwi.app.connections.add(connection); } diff --git a/client/assets/dev/model_newconnection.js b/client/assets/dev/model_newconnection.js new file mode 100644 index 0000000..3c8cf78 --- /dev/null +++ b/client/assets/dev/model_newconnection.js @@ -0,0 +1,69 @@ +_kiwi.model.NewConnection = Backbone.Collection.extend({ + initialize: function() { + this.view = new _kiwi.view.ServerSelect(); + + this.view.bind('server_connect', this.onMakeConnection, this); + + }, + + + onMakeConnection: function(new_connection_event) { + var that = this, + transport_path = '', + auto_connect_details = new_connection_event; + + this.view.networkConnecting(); + + + // If we don't have socket.io loaded, load it before opening a new connection + if (!window.io) { + // Path to get the socket.io transport code + transport_path = _kiwi.app.kiwi_server + _kiwi.app.get('base_path') + '/transport/socket.io.js?ts='+(new Date().getTime()); + + $script(transport_path, function() { + if (!window.io) { + that.onKiwiServerNotFound(); + return; + } + + _kiwi.gateway.set('kiwi_server', _kiwi.app.kiwi_server + '/kiwi'); + _kiwi.gateway.connect(function() { + that.makeConnection(new_connection_event); + }); + }); + + } else { + this.makeConnection(new_connection_event); + + } + + }, + + + onKiwiServerNotFound: function() { + this.view.showError(); + }, + + + makeConnection: function(new_connection_event) { + var that = this; + + _kiwi.gateway.newConnection({ + nick: new_connection_event.nick, + host: new_connection_event.server, + port: new_connection_event.port, + ssl: new_connection_event.ssl, + password: new_connection_event.password + }, function(err, network) { + that.onNewNetwork(err, network); + }); + }, + + + onNewNetwork: function(err, network) { + // Show the server panel if this is our first network + if (network && network.get('connection_id') === 0) { + network.panels.server.view.show(); + } + } +}); \ No newline at end of file diff --git a/client/assets/dev/model_server.js b/client/assets/dev/model_server.js index 196ab7d..2f7ddee 100644 --- a/client/assets/dev/model_server.js +++ b/client/assets/dev/model_server.js @@ -11,10 +11,5 @@ _kiwi.model.Server = _kiwi.model.Panel.extend({ }, {"silent": true}); //this.addMsg(' ', '--> Kiwi IRC: Such an awesome IRC client', '', {style: 'color:#009900;'}); - - this.server_login = new _kiwi.view.ServerSelect(); - - this.view.$el.append(this.server_login.$el); - this.server_login.show(); } }); \ No newline at end of file diff --git a/client/assets/dev/view.js b/client/assets/dev/view.js index 1d24cc0..7956e72 100644 --- a/client/assets/dev/view.js +++ b/client/assets/dev/view.js @@ -188,24 +188,15 @@ _kiwi.view.ServerSelect = function () { } } - _kiwi.gateway.bind('onconnect', this.networkConnected, this); _kiwi.gateway.bind('connecting', this.networkConnecting, this); + _kiwi.gateway.bind('onirc_error', this.onIrcError, this); + }, - _kiwi.gateway.bind('onirc_error', function (data) { - $('button', this.$el).attr('disabled', null); - - if (data.error == 'nickname_in_use') { - this.setStatus('Nickname already taken'); - this.show('nick_change'); - } - - if (data.error == 'password_mismatch') { - this.setStatus('Incorrect Password'); - this.show('nick_change'); - that.$el.find('.password').select(); - } - }, this); + dispose: function() { + _kiwi.gateway.off('onconnect', this.networkConnected, this); + _kiwi.gateway.off('connecting', this.networkConnecting, this); + _kiwi.gateway.off('onirc_error', this.onIrcError, this); }, submitForm: function (event) { @@ -231,7 +222,7 @@ _kiwi.view.ServerSelect = function () { 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(), @@ -329,6 +320,21 @@ _kiwi.view.ServerSelect = function () { this.setStatus('Connecting..', 'ok'); }, + onIrcError: function (data) { + $('button', this.$el).attr('disabled', null); + + if (data.error == 'nickname_in_use') { + this.setStatus('Nickname already taken'); + this.show('nick_change'); + } + + if (data.error == 'password_mismatch') { + this.setStatus('Incorrect Password'); + this.show('nick_change'); + that.$el.find('.password').select(); + } + }, + showError: function (event) { this.setStatus('Error connecting', 'error'); $('button', this.$el).attr('disabled', null); @@ -1655,6 +1661,7 @@ _kiwi.view.MenuBox = Backbone.View.extend({ this._title = title || ''; this._items = {}; this._display_footer = true; + this._close_on_blur = true; this._close_proxy = function(event) { that.onDocumentClick(event); @@ -1690,6 +1697,9 @@ _kiwi.view.MenuBox = Backbone.View.extend({ onDocumentClick: function(event) { var $target = $(event.target); + if (!this._close_on_blur) + return; + // If this is not itself AND we don't contain this element, dispose $el if ($target[0] != this.$el[0] && this.$el.has($target).length === 0) this.dispose(); @@ -1722,7 +1732,12 @@ _kiwi.view.MenuBox = Backbone.View.extend({ showFooter: function(show) { - this._show_footer = show; + this._display_footer = show; + }, + + + closeOnBlur: function(close_it) { + this._close_on_blur = close_it; }, -- 2.25.1