ControlInput updating nick view properly
[KiwiIRC.git] / client / assets / dev / model_newconnection.js
1 _kiwi.model.NewConnection = Backbone.Collection.extend({
2 initialize: function() {
3 this.view = new _kiwi.view.ServerSelect();
4
5 this.view.bind('server_connect', this.onMakeConnection, this);
6
7 },
8
9
10 onMakeConnection: function(new_connection_event) {
11 var that = this,
12 transport_path = '',
13 auto_connect_details = new_connection_event;
14
15 this.view.networkConnecting();
16
17
18 // If we don't have socket.io loaded, load it before opening a new connection
19 if (!window.io) {
20 // Path to get the socket.io transport code
21 transport_path = _kiwi.app.kiwi_server + _kiwi.app.get('base_path') + '/transport/socket.io.js?ts='+(new Date().getTime());
22
23 $script(transport_path, function() {
24 if (!window.io) {
25 that.onKiwiServerNotFound();
26 return;
27 }
28
29 _kiwi.gateway.set('kiwi_server', _kiwi.app.kiwi_server + '/kiwi');
30 _kiwi.gateway.connect(function() {
31 that.makeConnection(new_connection_event);
32 });
33 });
34
35 } else {
36 this.makeConnection(new_connection_event);
37
38 }
39
40 },
41
42
43 onKiwiServerNotFound: function() {
44 this.view.showError();
45 },
46
47
48 makeConnection: function(new_connection_event) {
49 var that = this;
50
51 _kiwi.gateway.newConnection({
52 nick: new_connection_event.nick,
53 host: new_connection_event.server,
54 port: new_connection_event.port,
55 ssl: new_connection_event.ssl,
56 password: new_connection_event.password
57 }, function(err, network) {
58 that.onNewNetwork(err, network);
59 });
60 },
61
62
63 onNewNetwork: function(err, network) {
64 // Show the server panel if this is our first network
65 if (network && network.get('connection_id') === 0) {
66 network.panels.server.view.show();
67 }
68 }
69 });