Merge branch 'text_themes' of https://github.com/CoryChaplin/KiwiIRC into CoryChaplin...
[KiwiIRC.git] / client / src / models / application.js
1 (function () {
2
3 _kiwi.model.Application = Backbone.Model.extend({
4 /** _kiwi.view.Application */
5 view: null,
6
7 /** _kiwi.view.StatusMessage */
8 message: null,
9
10 /* Address for the kiwi server */
11 kiwi_server: null,
12
13 initialize: function (options) {
14 if (options.container) {
15 this.set('container', options.container);
16 }
17
18 // The base url to the kiwi server
19 this.set('base_path', options.base_path ? options.base_path : '/kiwi');
20
21 // Path for the settings.json file
22 this.set('settings_path', options.settings_path ?
23 options.settings_path :
24 this.get('base_path') + '/assets/settings.json'
25 );
26
27 // Any options sent down from the server
28 this.server_settings = options.server_settings || {};
29 this.translations = options.translations || {};
30 this.themes = options.themes || [];
31
32 // Best guess at where the kiwi server is if not already specified
33 this.kiwi_server = options.kiwi_server || this.detectKiwiServer();
34
35 // The applet to initially load
36 this.startup_applet_name = options.startup || 'kiwi_startup';
37
38 // Set any default settings before anything else is applied
39 if (this.server_settings && this.server_settings.client && this.server_settings.client.settings) {
40 this.applyDefaultClientSettings(this.server_settings.client.settings);
41 }
42 },
43
44
45 initializeInterfaces: function () {
46 // Set the gateway up
47 _kiwi.gateway = new _kiwi.model.Gateway();
48 this.bindGatewayCommands(_kiwi.gateway);
49
50 this.initializeClient();
51 this.initializeGlobals();
52
53 this.view.barsHide(true);
54 },
55
56
57 detectKiwiServer: function () {
58 // If running from file, default to localhost:7777 by default
59 if (window.location.protocol === 'file:') {
60 return 'http://localhost:7778';
61 } else {
62 // Assume the kiwi server is on the same server
63 return window.location.protocol + '//' + window.location.host;
64 }
65 },
66
67
68 showStartup: function() {
69 this.startup_applet = _kiwi.model.Applet.load(this.startup_applet_name, {no_tab: true});
70 this.startup_applet.tab = this.view.$('.console');
71 this.startup_applet.view.show();
72 },
73
74
75 initializeClient: function () {
76 this.view = new _kiwi.view.Application({model: this, el: this.get('container')});
77
78 // Takes instances of model_network
79 this.connections = new _kiwi.model.NetworkPanelList();
80
81 // Applets panel list
82 this.applet_panels = new _kiwi.model.PanelList();
83 this.applet_panels.view.$el.addClass('panellist applets');
84 this.view.$el.find('.tabs').append(this.applet_panels.view.$el);
85
86 /**
87 * Set the UI components up
88 */
89 this.controlbox = new _kiwi.view.ControlBox({el: $('#kiwi .controlbox')[0]});
90 this.bindControllboxCommands(this.controlbox);
91
92 this.topicbar = new _kiwi.view.TopicBar({el: this.view.$el.find('.topic')[0]});
93
94 new _kiwi.view.AppToolbar({el: _kiwi.app.view.$el.find('.toolbar .app_tools')[0]});
95 new _kiwi.view.ChannelTools({el: _kiwi.app.view.$el.find('.channel_tools')[0]});
96
97 this.message = new _kiwi.view.StatusMessage({el: this.view.$el.find('.status_message')[0]});
98
99 this.resize_handle = new _kiwi.view.ResizeHandler({el: this.view.$el.find('.memberlists_resize_handle')[0]});
100
101 // Rejigg the UI sizes
102 this.view.doLayout();
103 },
104
105
106 initializeGlobals: function () {
107 _kiwi.global.connections = this.connections;
108
109 _kiwi.global.panels = this.panels;
110 _kiwi.global.panels.applets = this.applet_panels;
111
112 _kiwi.global.components.Applet = _kiwi.model.Applet;
113 _kiwi.global.components.Panel =_kiwi.model.Panel;
114 },
115
116
117 applyDefaultClientSettings: function (settings) {
118 _.each(settings, function (value, setting) {
119 if (typeof _kiwi.global.settings.get(setting) === 'undefined') {
120 _kiwi.global.settings.set(setting, value);
121 }
122 });
123 },
124
125
126 panels: (function() {
127 var active_panel;
128
129 var fn = function(panel_type) {
130 var panels;
131
132 // Default panel type
133 panel_type = panel_type || 'connections';
134
135 switch (panel_type) {
136 case 'connections':
137 panels = this.connections.panels();
138 break;
139 case 'applets':
140 panels = this.applet_panels.models;
141 break;
142 }
143
144 // Active panels / server
145 panels.active = active_panel;
146 panels.server = this.connections.active_connection ?
147 this.connections.active_connection.panels.server :
148 null;
149
150 return panels;
151 };
152
153 _.extend(fn, Backbone.Events);
154
155 // Keep track of the active panel. Channel/query/server or applet
156 fn.bind('active', function (new_active_panel) {
157 active_panel = new_active_panel;
158 });
159
160 return fn;
161 })(),
162
163
164 bindGatewayCommands: function (gw) {
165 var that = this;
166
167 gw.on('onconnect', function (event) {
168 that.view.barsShow();
169 });
170
171
172 /**
173 * Handle the reconnections to the kiwi server
174 */
175 (function () {
176 // 0 = non-reconnecting state. 1 = reconnecting state.
177 var gw_stat = 0;
178
179 // If the current or upcoming disconnect was planned
180 var unplanned_disconnect = false;
181
182 gw.on('disconnect', function (event) {
183 unplanned_disconnect = !gw.disconnect_requested;
184
185 if (unplanned_disconnect) {
186 var msg = _kiwi.global.i18n.translate('client_models_application_reconnecting').fetch() + '...';
187 that.message.text(msg, {timeout: 10000});
188 }
189
190 that.view.$el.removeClass('connected');
191
192 // Mention the disconnection on every channel
193 _kiwi.app.connections.forEach(function(connection) {
194 connection.panels.server.addMsg('', styleText('quit', {'%T': msg}), 'action quit');
195
196 connection.panels.forEach(function(panel) {
197 if (!panel.isChannel())
198 return;
199
200 panel.addMsg('', styleText('quit', {'%T': msg}), 'action quit');
201 });
202 });
203
204 gw_stat = 1;
205 });
206
207
208 gw.on('reconnecting', function (event) {
209 var msg = _kiwi.global.i18n.translate('client_models_application_reconnect_in_x_seconds').fetch(event.delay/1000) + '...';
210
211 // Only need to mention the repeating re-connection messages on server panels
212 _kiwi.app.connections.forEach(function(connection) {
213 connection.panels.server.addMsg('', styleText('quit', {'%T': msg}), 'action quit');
214 });
215 });
216
217
218 gw.on('onconnect', function (event) {
219 that.view.$el.addClass('connected');
220 if (gw_stat !== 1) return;
221
222 if (unplanned_disconnect) {
223 var msg = _kiwi.global.i18n.translate('client_models_application_reconnect_successfully').fetch() + ':)';
224 that.message.text(msg, {timeout: 5000});
225 }
226
227 // Mention the re-connection on every channel
228 _kiwi.app.connections.forEach(function(connection) {
229 connection.panels.server.addMsg('', styleText('rejoin', {'%T': msg}), 'action join');
230
231 connection.panels.forEach(function(panel) {
232 if (!panel.isChannel())
233 return;
234
235 panel.addMsg('', styleText('rejoin', {'%T': msg}), 'action join');
236 });
237 });
238
239 gw_stat = 0;
240 });
241 })();
242
243
244 gw.on('kiwi:reconfig', function () {
245 $.getJSON(that.get('settings_path'), function (data) {
246 that.server_settings = data.server_settings || {};
247 that.translations = data.translations || {};
248 });
249 });
250
251
252 gw.on('kiwi:jumpserver', function (data) {
253 var serv;
254 // No server set? Then nowhere to jump to.
255 if (typeof data.kiwi_server === 'undefined')
256 return;
257
258 serv = data.kiwi_server;
259
260 // Strip any trailing slash from the end
261 if (serv[serv.length-1] === '/')
262 serv = serv.substring(0, serv.length-1);
263
264 // Force the jumpserver now?
265 if (data.force) {
266 // Get an interval between 5 and 6 minutes so everyone doesn't reconnect it all at once
267 var jump_server_interval = Math.random() * (360 - 300) + 300;
268
269 // Tell the user we are going to disconnect, wait 5 minutes then do the actual reconnect
270 var msg = _kiwi.global.i18n.translate('client_models_application_jumpserver_prepare').fetch();
271 that.message.text(msg, {timeout: 10000});
272
273 setTimeout(function forcedReconnect() {
274 var msg = _kiwi.global.i18n.translate('client_models_application_jumpserver_reconnect').fetch();
275 that.message.text(msg, {timeout: 8000});
276
277 setTimeout(function forcedReconnectPartTwo() {
278 _kiwi.app.kiwi_server = serv;
279
280 _kiwi.gateway.reconnect(function() {
281 // Reconnect all the IRC connections
282 that.connections.forEach(function(con){ con.reconnect(); });
283 });
284 }, 5000);
285
286 }, jump_server_interval * 1000);
287 }
288 });
289 },
290
291
292
293 /**
294 * Bind to certain commands that may be typed into the control box
295 */
296 bindControllboxCommands: function (controlbox) {
297 var that = this;
298
299 // Default aliases
300 $.extend(controlbox.preprocessor.aliases, {
301 // General aliases
302 '/p': '/part $1+',
303 '/me': '/action $1+',
304 '/j': '/join $1+',
305 '/q': '/query $1+',
306 '/w': '/whois $1+',
307 '/raw': '/quote $1+',
308
309 // Op related aliases
310 '/op': '/quote mode $channel +o $1+',
311 '/deop': '/quote mode $channel -o $1+',
312 '/hop': '/quote mode $channel +h $1+',
313 '/dehop': '/quote mode $channel -h $1+',
314 '/voice': '/quote mode $channel +v $1+',
315 '/devoice': '/quote mode $channel -v $1+',
316 '/k': '/kick $channel $1+',
317 '/ban': '/quote mode $channel +b $1+',
318 '/unban': '/quote mode $channel -b $1+',
319
320 // Misc aliases
321 '/slap': '/me slaps $1 around a bit with a large trout'
322 });
323
324 // Functions to bind to controlbox events
325 var fn_to_bind = {
326 'unknown_command': unknownCommand,
327 'command': allCommands,
328 'command:msg': msgCommand,
329 'command:action': actionCommand,
330 'command:join': joinCommand,
331 'command:part': partCommand,
332 'command:nick': nickCommand,
333 'command:query': queryCommand,
334 'command:invite': inviteCommand,
335 'command:topic': topicCommand,
336 'command:notice': noticeCommand,
337 'command:quote': quoteCommand,
338 'command:kick': kickCommand,
339 'command:clear': clearCommand,
340 'command:ctcp': ctcpCommand,
341 'command:server': serverCommand,
342 'command:whois': whoisCommand,
343 'command:whowas': whowasCommand,
344 'command:encoding': encodingCommand,
345 'command:channel': channelCommand,
346 'command:applet': appletCommand,
347 'command:settings': settingsCommand,
348 'command:script': scriptCommand
349 };
350
351 fn_to_bind['command:css'] = function (ev) {
352 var queryString = '?reload=' + new Date().getTime();
353 $('link[rel="stylesheet"]').each(function () {
354 this.href = this.href.replace(/\?.*|$/, queryString);
355 });
356 };
357
358 fn_to_bind['command:js'] = function (ev) {
359 if (!ev.params[0]) return;
360 $script(ev.params[0] + '?' + (new Date().getTime()));
361 };
362
363
364 fn_to_bind['command:set'] = function (ev) {
365 if (!ev.params[0]) return;
366
367 var setting = ev.params[0],
368 value;
369
370 // Do we have a second param to set a value?
371 if (ev.params[1]) {
372 ev.params.shift();
373
374 value = ev.params.join(' ');
375
376 // If we're setting a true boolean value..
377 if (value === 'true')
378 value = true;
379
380 // If we're setting a false boolean value..
381 if (value === 'false')
382 value = false;
383
384 // If we're setting a number..
385 if (parseInt(value, 10).toString() === value)
386 value = parseInt(value, 10);
387
388 _kiwi.global.settings.set(setting, value);
389 }
390
391 // Read the value to the user
392 _kiwi.app.panels().active.addMsg('', styleText('set_setting', {'%T': setting + ' = ' + _kiwi.global.settings.get(setting).toString()}));
393 };
394
395
396 fn_to_bind['command:save'] = function (ev) {
397 _kiwi.global.settings.save();
398 _kiwi.app.panels().active.addMsg('', styleText('client_models_application_settings_saved', {'%T': translateText('client_models_application_settings_saved')}));
399 };
400
401
402 fn_to_bind['command:alias'] = function (ev) {
403 var name, rule;
404
405 // No parameters passed so list them
406 if (!ev.params[1]) {
407 $.each(controlbox.preprocessor.aliases, function (name, rule) {
408 _kiwi.app.panels().server.addMsg(' ', styleText('list_aliases', {'%T': name + ' => ' + rule}));
409 });
410 return;
411 }
412
413 // Deleting an alias?
414 if (ev.params[0] === 'del' || ev.params[0] === 'delete') {
415 name = ev.params[1];
416 if (name[0] !== '/') name = '/' + name;
417 delete controlbox.preprocessor.aliases[name];
418 return;
419 }
420
421 // Add the alias
422 name = ev.params[0];
423 ev.params.shift();
424 rule = ev.params.join(' ');
425
426 // Make sure the name starts with a slash
427 if (name[0] !== '/') name = '/' + name;
428
429 // Now actually add the alias
430 controlbox.preprocessor.aliases[name] = rule;
431 };
432
433
434 fn_to_bind['command:ignore'] = function (ev) {
435 var list = this.connections.active_connection.get('ignore_list');
436
437 // No parameters passed so list them
438 if (!ev.params[0]) {
439 if (list.length > 0) {
440 _kiwi.app.panels().active.addMsg(' ', styleText('client_models_application_ignore_title', {'%T': translateText('client_models_application_ignore_title')}));
441 $.each(list, function (idx, ignored_pattern) {
442 _kiwi.app.panels().active.addMsg(' ', styleText('ignored_pattern', {'%T': ignored_pattern}));
443 });
444 } else {
445 _kiwi.app.panels().active.addMsg(' ', styleText('client_models_application_ignore_none', {'%T': translateText('client_models_application_ignore_none')}));
446 }
447 return;
448 }
449
450 // We have a parameter, so add it
451 list.push(ev.params[0]);
452 this.connections.active_connection.set('ignore_list', list);
453 _kiwi.app.panels().active.addMsg(' ', styleText('client_models_application_ignore_nick', {'%T': translateText('client_models_application_ignore_nick', [ev.params[0]])}));
454 };
455
456
457 fn_to_bind['command:unignore'] = function (ev) {
458 var list = this.connections.active_connection.get('ignore_list');
459
460 if (!ev.params[0]) {
461 _kiwi.app.panels().active.addMsg(' ', styleText('client_models_application_ignore_stop_notice', {'%T': translateText('client_models_application_ignore_stop_notice')}));
462 return;
463 }
464
465 list = _.reject(list, function(pattern) {
466 return pattern === ev.params[0];
467 });
468
469 this.connections.active_connection.set('ignore_list', list);
470
471 _kiwi.app.panels().active.addMsg(' ', styleText('client_models_application_ignore_stopped', {'%T': translateText('client_models_application_ignore_stopped', [ev.params[0]])}));
472 };
473
474
475 _.each(fn_to_bind, function(fn, event_name) {
476 controlbox.on(event_name, _.bind(fn, that));
477 });
478 },
479
480
481 isChannelName: function (channel_name) {
482 var channel_prefix = _kiwi.gateway.get('channel_prefix');
483
484 if (!channel_name || !channel_name.length) return false;
485 return (channel_prefix.indexOf(channel_name[0]) > -1);
486 }
487 });
488
489
490
491
492 // A fallback action. Send a raw command to the server
493 function unknownCommand (ev) {
494 var raw_cmd = ev.command + ' ' + ev.params.join(' ');
495 console.log('RAW: ' + raw_cmd);
496 this.connections.active_connection.gateway.raw(raw_cmd);
497 }
498
499 function allCommands (ev) {}
500
501 function joinCommand (ev) {
502 var panels, channel_names;
503
504 channel_names = ev.params.join(' ').split(',');
505 panels = this.connections.active_connection.createAndJoinChannels(channel_names);
506
507 // Show the last channel if we have one
508 if (panels.length)
509 panels[panels.length - 1].view.show();
510 }
511
512 function queryCommand (ev) {
513 var destination, message, panel;
514
515 destination = ev.params[0];
516 ev.params.shift();
517
518 message = ev.params.join(' ');
519
520 // Check if we have the panel already. If not, create it
521 panel = this.connections.active_connection.panels.getByName(destination);
522 if (!panel) {
523 panel = new _kiwi.model.Query({name: destination});
524 this.connections.active_connection.panels.add(panel);
525 }
526
527 if (panel) panel.view.show();
528
529 if (message) {
530 this.connections.active_connection.gateway.msg(panel.get('name'), message);
531 panel.addMsg(_kiwi.app.connections.active_connection.get('nick'), styleText('query', {'%T': message}));
532 }
533
534 }
535
536 function msgCommand (ev) {
537 var message,
538 destination = ev.params[0],
539 panel = this.connections.active_connection.panels.getByName(destination) || this.panels().server;
540
541 ev.params.shift();
542 message = formatToIrcMsg(ev.params.join(' '));
543
544 panel.addMsg(_kiwi.app.connections.active_connection.get('nick'), styleText('msg', {'%T': message}));
545 this.connections.active_connection.gateway.msg(destination, message);
546 }
547
548 function actionCommand (ev) {
549 if (_kiwi.app.panels().active.isServer()) {
550 return;
551 }
552
553 var panel = _kiwi.app.panels().active;
554 panel.addMsg('', styleText('action', {'%N': _kiwi.app.connections.active_connection.get('nick'), '%T': ev.params.join(' ')}), 'action');
555 this.connections.active_connection.gateway.action(panel.get('name'), ev.params.join(' '));
556 }
557
558 function partCommand (ev) {
559 var that = this;
560
561 if (ev.params.length === 0) {
562 this.connections.active_connection.gateway.part(_kiwi.app.panels().active.get('name'));
563 } else {
564 _.each(ev.params, function (channel) {
565 that.connections.active_connection.gateway.part(channel);
566 });
567 }
568 }
569
570 function nickCommand (ev) {
571 this.connections.active_connection.gateway.changeNick(ev.params[0]);
572 }
573
574 function topicCommand (ev) {
575 var channel_name;
576
577 if (ev.params.length === 0) return;
578
579 if (this.isChannelName(ev.params[0])) {
580 channel_name = ev.params[0];
581 ev.params.shift();
582 } else {
583 channel_name = _kiwi.app.panels().active.get('name');
584 }
585
586 this.connections.active_connection.gateway.topic(channel_name, ev.params.join(' '));
587 }
588
589 function noticeCommand (ev) {
590 var destination;
591
592 // Make sure we have a destination and some sort of message
593 if (ev.params.length <= 1) return;
594
595 destination = ev.params[0];
596 ev.params.shift();
597
598 this.connections.active_connection.gateway.notice(destination, ev.params.join(' '));
599 }
600
601 function quoteCommand (ev) {
602 var raw = ev.params.join(' ');
603 this.connections.active_connection.gateway.raw(raw);
604 }
605
606 function kickCommand (ev) {
607 var nick, panel = _kiwi.app.panels().active;
608
609 if (!panel.isChannel()) return;
610
611 // Make sure we have a nick
612 if (ev.params.length === 0) return;
613
614 nick = ev.params[0];
615 ev.params.shift();
616
617 this.connections.active_connection.gateway.kick(panel.get('name'), nick, ev.params.join(' '));
618 }
619
620 function clearCommand (ev) {
621 // Can't clear a server or applet panel
622 if (_kiwi.app.panels().active.isServer() || _kiwi.app.panels().active.isApplet()) {
623 return;
624 }
625
626 if (_kiwi.app.panels().active.clearMessages) {
627 _kiwi.app.panels().active.clearMessages();
628 }
629 }
630
631 function ctcpCommand(ev) {
632 var target, type;
633
634 // Make sure we have a target and a ctcp type (eg. version, time)
635 if (ev.params.length < 2) return;
636
637 target = ev.params[0];
638 ev.params.shift();
639
640 type = ev.params[0];
641 ev.params.shift();
642
643 this.connections.active_connection.gateway.ctcp(true, type, target, ev.params.join(' '));
644 }
645
646 function settingsCommand (ev) {
647 var settings = _kiwi.model.Applet.loadOnce('kiwi_settings');
648 settings.view.show();
649 }
650
651 function scriptCommand (ev) {
652 var editor = _kiwi.model.Applet.loadOnce('kiwi_script_editor');
653 editor.view.show();
654 }
655
656 function appletCommand (ev) {
657 if (!ev.params[0]) return;
658
659 var panel = new _kiwi.model.Applet();
660
661 if (ev.params[1]) {
662 // Url and name given
663 panel.load(ev.params[0], ev.params[1]);
664 } else {
665 // Load a pre-loaded applet
666 if (_kiwi.applets[ev.params[0]]) {
667 panel.load(new _kiwi.applets[ev.params[0]]());
668 } else {
669 _kiwi.app.panels().server.addMsg('', styleText('client_models_application_applet_notfound', {'%T': translateText('client_models_application_applet_notfound', [ev.params[0]])}));
670 return;
671 }
672 }
673
674 _kiwi.app.connections.active_connection.panels.add(panel);
675 panel.view.show();
676 }
677
678
679
680 function inviteCommand (ev) {
681 var nick, channel;
682
683 // A nick must be specified
684 if (!ev.params[0])
685 return;
686
687 // Can only invite into channels
688 if (!_kiwi.app.panels().active.isChannel())
689 return;
690
691 nick = ev.params[0];
692 channel = _kiwi.app.panels().active.get('name');
693
694 _kiwi.app.connections.active_connection.gateway.raw('INVITE ' + nick + ' ' + channel);
695
696 _kiwi.app.panels().active.addMsg('', styleText('client_models_application_has_been_invited', {'%N': nick, '%T': translateText('client_models_application_has_been_invited', [channel])}), 'action');
697 }
698
699
700 function whoisCommand (ev) {
701 var nick;
702
703 if (ev.params[0]) {
704 nick = ev.params[0];
705 } else if (_kiwi.app.panels().active.isQuery()) {
706 nick = _kiwi.app.panels().active.get('name');
707 }
708
709 if (nick)
710 _kiwi.app.connections.active_connection.gateway.raw('WHOIS ' + nick + ' ' + nick);
711 }
712
713
714 function whowasCommand (ev) {
715 var nick;
716
717 if (ev.params[0]) {
718 nick = ev.params[0];
719 } else if (_kiwi.app.panels().active.isQuery()) {
720 nick = _kiwi.app.panels().active.get('name');
721 }
722
723 if (nick)
724 _kiwi.app.connections.active_connection.gateway.raw('WHOWAS ' + nick);
725 }
726
727 function encodingCommand (ev) {
728 if (ev.params[0]) {
729 _kiwi.gateway.setEncoding(null, ev.params[0], function (success) {
730 if (success) {
731 _kiwi.app.panels().active.addMsg('', styleText('client_models_application_encoding_changed', {'%T': translateText('client_models_application_encoding_changed', [ev.params[0]])}));
732 } else {
733 _kiwi.app.panels().active.addMsg('', styleText('client_models_application_encoding_invalid', {'%T': translateText('client_models_application_encoding_invalid', [ev.params[0]])}));
734 }
735 });
736 } else {
737 _kiwi.app.panels().active.addMsg('', styleText('client_models_application_encoding_notspecified', {'%T': translateText('client_models_application_encoding_notspecified')}));
738 _kiwi.app.panels().active.addMsg('', styleText('client_models_application_encoding_usage', {'%T': translateText('client_models_application_encoding_usage')}));
739 }
740 }
741
742 function channelCommand (ev) {
743 var active_panel = _kiwi.app.panels().active;
744
745 if (!active_panel.isChannel())
746 return;
747
748 new _kiwi.model.ChannelInfo({channel: _kiwi.app.panels().active});
749 }
750
751 function serverCommand (ev) {
752 var server, port, ssl, password, nick,
753 tmp;
754
755 // If no server address given, show the new connection dialog
756 if (!ev.params[0]) {
757 tmp = new _kiwi.view.MenuBox(_kiwi.global.i18n.translate('client_models_application_connection_create').fetch());
758 tmp.addItem('new_connection', new _kiwi.model.NewConnection().view.$el);
759 tmp.show();
760
761 // Center screen the dialog
762 tmp.$el.offset({
763 top: (this.view.$el.height() / 2) - (tmp.$el.height() / 2),
764 left: (this.view.$el.width() / 2) - (tmp.$el.width() / 2)
765 });
766
767 return;
768 }
769
770 // Port given in 'host:port' format and no specific port given after a space
771 if (ev.params[0].indexOf(':') > 0) {
772 tmp = ev.params[0].split(':');
773 server = tmp[0];
774 port = tmp[1];
775
776 password = ev.params[1] || undefined;
777
778 } else {
779 // Server + port given as 'host port'
780 server = ev.params[0];
781 port = ev.params[1] || 6667;
782
783 password = ev.params[2] || undefined;
784 }
785
786 // + in the port means SSL
787 if (port.toString()[0] === '+') {
788 ssl = true;
789 port = parseInt(port.substring(1), 10);
790 } else {
791 ssl = false;
792 }
793
794 // Default port if one wasn't found
795 port = port || 6667;
796
797 // Use the same nick as we currently have
798 nick = _kiwi.app.connections.active_connection.get('nick');
799
800 _kiwi.app.panels().active.addMsg('', styleText('client_models_application_connection_connecting', {'%T': translateText('client_models_application_connection_connecting', [server, port.toString()])}));
801
802 _kiwi.gateway.newConnection({
803 nick: nick,
804 host: server,
805 port: port,
806 ssl: ssl,
807 password: password
808 }, function(err, new_connection) {
809 if (err)
810 _kiwi.app.panels().active.addMsg('', styleText('client_models_application_connection_error', {'%T': translateText('client_models_application_connection_error', [server, port.toString(), err.toString()])}));
811 });
812 }
813
814 })();