Commit | Line | Data |
---|---|---|
f2bb5380 D |
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 | ||
d99e7823 D |
17 | |
18 | _kiwi.gateway.set('kiwi_server', _kiwi.app.kiwi_server); | |
19 | _kiwi.gateway.connect(function() { | |
20 | that.makeConnection(new_connection_event); | |
21 | }); | |
22 | ||
f2bb5380 D |
23 | |
24 | }, | |
25 | ||
26 | ||
27 | onKiwiServerNotFound: function() { | |
28 | this.view.showError(); | |
29 | }, | |
30 | ||
31 | ||
32 | makeConnection: function(new_connection_event) { | |
33 | var that = this; | |
34 | ||
4047ee2b D |
35 | this.connect_details = new_connection_event; |
36 | ||
f2bb5380 D |
37 | _kiwi.gateway.newConnection({ |
38 | nick: new_connection_event.nick, | |
39 | host: new_connection_event.server, | |
40 | port: new_connection_event.port, | |
41 | ssl: new_connection_event.ssl, | |
cc54c0a1 D |
42 | password: new_connection_event.password, |
43 | options: new_connection_event.options | |
f2bb5380 D |
44 | }, function(err, network) { |
45 | that.onNewNetwork(err, network); | |
46 | }); | |
47 | }, | |
48 | ||
49 | ||
50 | onNewNetwork: function(err, network) { | |
13cdb96e D |
51 | // Show any errors if given |
52 | if (err) { | |
53 | this.view.showError(err); | |
54 | } | |
55 | ||
4047ee2b D |
56 | if (network && this.connect_details) { |
57 | network.auto_join = { | |
58 | channel: this.connect_details.channel, | |
59 | key: this.connect_details.channel_key | |
60 | }; | |
61 | } | |
62 | ||
63 | ||
f2bb5380 D |
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 | }); |