Adding panel_access to the application model for tracking tab history
[KiwiIRC.git] / client / src / models / newconnection.js
CommitLineData
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
eb2acc92
D
17 // If not connected already, connect then send the IRC connect info
18 if (!_kiwi.gateway.isConnected()) {
eb2acc92
D
19 _kiwi.gateway.connect(function() {
20 that.makeConnection(new_connection_event);
21 });
22
23 } else {
24 this.makeConnection(new_connection_event);
25 }
d99e7823 26
f2bb5380
D
27
28 },
29
30
31 onKiwiServerNotFound: function() {
32 this.view.showError();
33 },
34
35
36 makeConnection: function(new_connection_event) {
37 var that = this;
38
4047ee2b
D
39 this.connect_details = new_connection_event;
40
f2bb5380
D
41 _kiwi.gateway.newConnection({
42 nick: new_connection_event.nick,
43 host: new_connection_event.server,
44 port: new_connection_event.port,
45 ssl: new_connection_event.ssl,
cc54c0a1
D
46 password: new_connection_event.password,
47 options: new_connection_event.options
f2bb5380
D
48 }, function(err, network) {
49 that.onNewNetwork(err, network);
50 });
51 },
52
53
54 onNewNetwork: function(err, network) {
13cdb96e
D
55 // Show any errors if given
56 if (err) {
57 this.view.showError(err);
58 }
59
4047ee2b
D
60 if (network && this.connect_details) {
61 network.auto_join = {
62 channel: this.connect_details.channel,
63 key: this.connect_details.channel_key
64 };
65 }
66
67
f2bb5380
D
68 // Show the server panel if this is our first network
69 if (network && network.get('connection_id') === 0) {
70 network.panels.server.view.show();
71 }
72 }
73});