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