1 _kiwi
.model
.NewConnection
= Backbone
.Collection
.extend({
2 initialize: function() {
3 this.view
= new _kiwi
.view
.ServerSelect();
5 this.view
.bind('server_connect', this.onMakeConnection
, this);
10 onMakeConnection: function(new_connection_event
) {
13 auto_connect_details
= new_connection_event
;
15 this.view
.networkConnecting();
18 // If we don't have socket.io loaded, load it before opening a new connection
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());
23 $script(transport_path
, function() {
25 that
.onKiwiServerNotFound();
29 _kiwi
.gateway
.set('kiwi_server', _kiwi
.app
.kiwi_server
+ '/kiwi');
30 _kiwi
.gateway
.connect(function() {
31 that
.makeConnection(new_connection_event
);
36 this.makeConnection(new_connection_event
);
43 onKiwiServerNotFound: function() {
44 this.view
.showError();
48 makeConnection: function(new_connection_event
) {
51 this.connect_details
= new_connection_event
;
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
);
65 onNewNetwork: function(err
, network
) {
66 // Show any errors if given
68 this.view
.showError(err
);
71 if (network
&& this.connect_details
) {
73 channel
: this.connect_details
.channel
,
74 key
: this.connect_details
.channel_key
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();