Merge branch 'development' of https://github.com/crtaylor123/KiwiIRC into crtaylor123...
[KiwiIRC.git] / client / src / models / newconnection.js
1 _kiwi.model.NewConnection = Backbone.Collection.extend({
2 initialize: function() {
3 this.view = new _kiwi.view.ServerSelect({model: this});
4
5 this.view.bind('server_connect', this.onMakeConnection, this);
6
7 },
8
9
10 populateDefaultServerSettings: function() {
11 var defaults = _kiwi.global.defaultServerSettings();
12 this.view.populateFields(defaults);
13 },
14
15
16 onMakeConnection: function(new_connection_event) {
17 var that = this;
18
19 this.connect_details = new_connection_event;
20
21 this.view.networkConnecting();
22
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,
28 password: new_connection_event.password,
29 options: new_connection_event.options
30 }, function(err, network) {
31 that.onNewNetwork(err, network);
32 });
33 },
34
35
36 onNewNetwork: function(err, network) {
37 // Show any errors if given
38 if (err) {
39 this.view.showError(err);
40 }
41
42 if (network && this.connect_details) {
43 network.auto_join = {
44 channel: this.connect_details.channel,
45 key: this.connect_details.channel_key
46 };
47
48 this.trigger('new_network', network);
49 }
50 }
51 });