No more need to specify a set of available encodings
[KiwiIRC.git] / client / assets / 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
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
4047ee2b
D
51 this.connect_details = new_connection_event;
52
f2bb5380
D
53 _kiwi.gateway.newConnection({
54 nick: new_connection_event.nick,
55 host: new_connection_event.server,
56 port: new_connection_event.port,
57 ssl: new_connection_event.ssl,
58 password: new_connection_event.password
59 }, function(err, network) {
60 that.onNewNetwork(err, network);
61 });
62 },
63
64
65 onNewNetwork: function(err, network) {
13cdb96e
D
66 // Show any errors if given
67 if (err) {
68 this.view.showError(err);
69 }
70
4047ee2b
D
71 if (network && this.connect_details) {
72 network.auto_join = {
73 channel: this.connect_details.channel,
74 key: this.connect_details.channel_key
75 };
76 }
77
78
f2bb5380
D
79 // Show the server panel if this is our first network
80 if (network && network.get('connection_id') === 0) {
81 network.panels.server.view.show();
82 }
83 }
84});