Moving defaultServerSettings() into the global kiwi API
[KiwiIRC.git] / client / src / models / newconnection.js
CommitLineData
f2bb5380
D
1_kiwi.model.NewConnection = Backbone.Collection.extend({
2 initialize: function() {
17f187e6 3 this.view = new _kiwi.view.ServerSelect({model: this});
f2bb5380
D
4
5 this.view.bind('server_connect', this.onMakeConnection, this);
6
7 },
8
9
6b8fbed0 10 populateDefaultServerSettings: function() {
d0734219 11 var defaults = _kiwi.global.defaultServerSettings();
17f187e6
D
12 this.view.populateFields(defaults);
13 },
14
15
f2bb5380 16 onMakeConnection: function(new_connection_event) {
f2bb5380
D
17 var that = this;
18
4047ee2b
D
19 this.connect_details = new_connection_event;
20
28b4b095
D
21 this.view.networkConnecting();
22
f2bb5380
D
23 _kiwi.gateway.newConnection({
24 nick: new_connection_event.nick,
25 host: new_connection_event.server,
26 port: new_connection_event.port,
27 ssl: new_connection_event.ssl,
cc54c0a1
D
28 password: new_connection_event.password,
29 options: new_connection_event.options
f2bb5380
D
30 }, function(err, network) {
31 that.onNewNetwork(err, network);
32 });
33 },
34
35
36 onNewNetwork: function(err, network) {
13cdb96e
D
37 // Show any errors if given
38 if (err) {
39 this.view.showError(err);
40 }
41
4047ee2b
D
42 if (network && this.connect_details) {
43 network.auto_join = {
44 channel: this.connect_details.channel,
45 key: this.connect_details.channel_key
46 };
4047ee2b 47
17f187e6 48 this.trigger('new_network', network);
f2bb5380
D
49 }
50 }
51});