574ce25b891f84be9ae5ec6c869e48991c7484cf
3 _kiwi
.model
.Application
= Backbone
.Model
.extend({
4 /** _kiwi.view.Application */
7 /** _kiwi.view.StatusMessage */
10 /* Address for the kiwi server */
13 initialize: function (options
) {
14 if (options
.container
) {
15 this.set('container', options
.container
);
18 // The base url to the kiwi server
19 this.set('base_path', options
.base_path
? options
.base_path
: '/kiwi');
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'
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
|| [];
32 // Best guess at where the kiwi server is if not already specified
33 this.kiwi_server
= options
.kiwi_server
|| this.detectKiwiServer();
35 // The applet to initially load
36 this.startup_applet_name
= options
.startup
|| 'kiwi_startup';
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
);
45 initializeInterfaces: function () {
47 _kiwi
.gateway
= new _kiwi
.model
.Gateway();
48 this.bindGatewayCommands(_kiwi
.gateway
);
50 this.initializeClient();
51 this.initializeGlobals();
53 this.view
.barsHide(true);
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';
62 // Assume the kiwi server is on the same server
63 return window
.location
.protocol
+ '//' + window
.location
.host
;
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();
75 initializeClient: function () {
76 this.view
= new _kiwi
.view
.Application({model
: this, el
: this.get('container')});
78 // Takes instances of model_network
79 this.connections
= new _kiwi
.model
.NetworkPanelList();
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
);
87 * Set the UI components up
89 this.controlbox
= new _kiwi
.view
.ControlBox({el
: $('#kiwi .controlbox')[0]});
90 this.bindControllboxCommands(this.controlbox
);
92 this.topicbar
= new _kiwi
.view
.TopicBar({el
: this.view
.$el
.find('.topic')[0]});
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]});
97 this.message
= new _kiwi
.view
.StatusMessage({el
: this.view
.$el
.find('.status_message')[0]});
99 this.resize_handle
= new _kiwi
.view
.ResizeHandler({el
: this.view
.$el
.find('.memberlists_resize_handle')[0]});
101 // Rejigg the UI sizes
102 this.view
.doLayout();
106 initializeGlobals: function () {
107 _kiwi
.global
.connections
= this.connections
;
109 _kiwi
.global
.panels
= this.panels
;
110 _kiwi
.global
.panels
.applets
= this.applet_panels
;
112 _kiwi
.global
.components
.Applet
= _kiwi
.model
.Applet
;
113 _kiwi
.global
.components
.Panel
=_kiwi
.model
.Panel
;
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
);
126 panels
: (function() {
129 var fn = function(panel_type
) {
132 // Default panel type
133 panel_type
= panel_type
|| 'connections';
135 switch (panel_type
) {
137 panels
= this.connections
.panels();
140 panels
= this.applet_panels
.models
;
144 // Active panels / server
145 panels
.active
= active_panel
;
146 panels
.server
= this.connections
.active_connection
?
147 this.connections
.active_connection
.panels
.server
:
153 _
.extend(fn
, Backbone
.Events
);
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
;
164 defaultServerSettings: function () {
178 * Get any settings set by the server
179 * These settings may be changed in the server selection dialog or via URL parameters
181 if (this.server_settings
.client
) {
182 if (this.server_settings
.client
.nick
)
183 defaults
.nick
= this.server_settings
.client
.nick
;
185 if (this.server_settings
.client
.server
)
186 defaults
.server
= this.server_settings
.client
.server
;
188 if (this.server_settings
.client
.port
)
189 defaults
.port
= this.server_settings
.client
.port
;
191 if (this.server_settings
.client
.ssl
)
192 defaults
.ssl
= this.server_settings
.client
.ssl
;
194 if (this.server_settings
.client
.channel
)
195 defaults
.channel
= this.server_settings
.client
.channel
;
197 if (this.server_settings
.client
.channel_key
)
198 defaults
.channel_key
= this.server_settings
.client
.channel_key
;
204 * Get any settings passed in the URL
205 * These settings may be changed in the server selection dialog
208 // Any query parameters first
209 if (getQueryVariable('nick'))
210 defaults
.nick
= getQueryVariable('nick');
212 if (window
.location
.hash
)
213 defaults
.channel
= window
.location
.hash
;
216 // Process the URL part by part, extracting as we go
217 parts
= window
.location
.pathname
.toString().replace(this.get('base_path'), '').split('/');
219 if (parts
.length
> 0) {
222 if (parts
.length
> 0 && parts
[0]) {
223 // 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.
224 uricheck
= parts
[0].substr(0, 7).toLowerCase();
225 if ((uricheck
=== 'ircs%3a') || (uricheck
.substr(0,6) === 'irc%3a')) {
226 parts
[0] = decodeURIComponent(parts
[0]);
227 // irc[s]://<host>[:<port>]/[<channel>[?<password>]]
228 uricheck
= /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts
[0]);
230 uricheck[1] = ssl (optional)
232 uricheck[3] = port (optional)
233 uricheck[4] = channel (optional)
234 uricheck[5] = channel key (optional, channel must also be set)
237 if (typeof uricheck
[1] !== 'undefined') {
239 if (defaults
.port
=== 6667) {
240 defaults
.port
= 6697;
243 defaults
.server
= uricheck
[2];
244 if (typeof uricheck
[3] !== 'undefined') {
245 defaults
.port
= uricheck
[3];
247 if (typeof uricheck
[4] !== 'undefined') {
248 defaults
.channel
= '#' + uricheck
[4];
249 if (typeof uricheck
[5] !== 'undefined') {
250 defaults
.channel_key
= uricheck
[5];
256 // Extract the port+ssl if we find one
257 if (parts
[0].search(/:/) > 0) {
258 defaults
.port
= parts
[0].substring(parts
[0].search(/:/) + 1);
259 defaults
.server
= parts
[0].substring(0, parts
[0].search(/:/));
260 if (defaults
.port
[0] === '+') {
261 defaults
.port
= parseInt(defaults
.port
.substring(1), 10);
264 defaults
.ssl
= false;
268 defaults
.server
= parts
[0];
275 if (parts
.length
> 0 && parts
[0]) {
276 defaults
.channel
= '#' + parts
[0];
281 // If any settings have been given by the server.. override any auto detected settings
283 * Get any server restrictions as set in the server config
284 * These settings can not be changed in the server selection dialog
286 if (this.server_settings
&& this.server_settings
.connection
) {
287 if (this.server_settings
.connection
.server
) {
288 defaults
.server
= this.server_settings
.connection
.server
;
291 if (this.server_settings
.connection
.port
) {
292 defaults
.port
= this.server_settings
.connection
.port
;
295 if (this.server_settings
.connection
.ssl
) {
296 defaults
.ssl
= this.server_settings
.connection
.ssl
;
299 if (this.server_settings
.connection
.channel
) {
300 defaults
.channel
= this.server_settings
.connection
.channel
;
303 if (this.server_settings
.connection
.channel_key
) {
304 defaults
.channel_key
= this.server_settings
.connection
.channel_key
;
307 if (this.server_settings
.connection
.nick
) {
308 defaults
.nick
= this.server_settings
.connection
.nick
;
312 // Set any random numbers if needed
313 defaults
.nick
= defaults
.nick
.replace('?', Math
.floor(Math
.random() * 100000).toString());
315 if (getQueryVariable('encoding'))
316 defaults
.encoding
= getQueryVariable('encoding');
322 bindGatewayCommands: function (gw
) {
325 gw
.on('onconnect', function (event
) {
326 that
.view
.barsShow();
331 * Handle the reconnections to the kiwi server
334 // 0 = non-reconnecting state. 1 = reconnecting state.
337 // If the current or upcoming disconnect was planned
338 var unplanned_disconnect
= false;
340 gw
.on('disconnect', function (event
) {
341 unplanned_disconnect
= !gw
.disconnect_requested
;
343 if (unplanned_disconnect
) {
344 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnecting').fetch() + '...';
345 that
.message
.text(msg
, {timeout
: 10000});
348 that
.view
.$el
.removeClass('connected');
350 // Mention the disconnection on every channel
351 _kiwi
.app
.connections
.forEach(function(connection
) {
352 connection
.panels
.server
.addMsg('', msg
, 'action quit');
354 connection
.panels
.forEach(function(panel
) {
355 if (!panel
.isChannel())
358 panel
.addMsg('', msg
, 'action quit');
366 gw
.on('reconnecting', function (event
) {
367 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_in_x_seconds').fetch(event
.delay
/1000) + '...';
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');
376 gw
.on('onconnect', function (event
) {
377 that
.view
.$el
.addClass('connected');
378 if (gw_stat
!== 1) return;
380 if (unplanned_disconnect
) {
381 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_successfully').fetch() + ':)';
382 that
.message
.text(msg
, {timeout
: 5000});
385 // Mention the re-connection on every channel
386 _kiwi
.app
.connections
.forEach(function(connection
) {
387 connection
.panels
.server
.addMsg('', msg
, 'action join');
389 connection
.panels
.forEach(function(panel
) {
390 if (!panel
.isChannel())
393 panel
.addMsg('', msg
, 'action join');
402 gw
.on('kiwi:reconfig', function () {
403 $.getJSON(that
.get('settings_path'), function (data
) {
404 that
.server_settings
= data
.server_settings
|| {};
405 that
.translations
= data
.translations
|| {};
410 gw
.on('kiwi:jumpserver', function (data
) {
412 // No server set? Then nowhere to jump to.
413 if (typeof data
.kiwi_server
=== 'undefined')
416 serv
= data
.kiwi_server
;
418 // Strip any trailing slash from the end
419 if (serv
[serv
.length
-1] === '/')
420 serv
= serv
.substring(0, serv
.length
-1);
422 // Force the jumpserver now?
424 // Get an interval between 5 and 6 minutes so everyone doesn't reconnect it all at once
425 var jump_server_interval
= Math
.random() * (360 - 300) + 300;
427 // Tell the user we are going to disconnect, wait 5 minutes then do the actual reconnect
428 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_prepare').fetch();
429 that
.message
.text(msg
, {timeout
: 10000});
431 setTimeout(function forcedReconnect() {
432 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_reconnect').fetch();
433 that
.message
.text(msg
, {timeout
: 8000});
435 setTimeout(function forcedReconnectPartTwo() {
436 _kiwi
.app
.kiwi_server
= serv
;
438 _kiwi
.gateway
.reconnect(function() {
439 // Reconnect all the IRC connections
440 that
.connections
.forEach(function(con
){ con
.reconnect(); });
444 }, jump_server_interval
* 1000);
452 * Bind to certain commands that may be typed into the control box
454 bindControllboxCommands: function (controlbox
) {
458 $.extend(controlbox
.preprocessor
.aliases
, {
461 '/me': '/action $1+',
465 '/raw': '/quote $1+',
467 // Op related aliases
468 '/op': '/quote mode $channel +o $1+',
469 '/deop': '/quote mode $channel -o $1+',
470 '/hop': '/quote mode $channel +h $1+',
471 '/dehop': '/quote mode $channel -h $1+',
472 '/voice': '/quote mode $channel +v $1+',
473 '/devoice': '/quote mode $channel -v $1+',
474 '/k': '/kick $channel $1+',
475 '/ban': '/quote mode $channel +b $1+',
476 '/unban': '/quote mode $channel -b $1+',
479 '/slap': '/me slaps $1 around a bit with a large trout'
482 // Functions to bind to controlbox events
484 'unknown_command': unknownCommand
,
485 'command': allCommands
,
486 'command:msg': msgCommand
,
487 'command:action': actionCommand
,
488 'command:join': joinCommand
,
489 'command:part': partCommand
,
490 'command:nick': nickCommand
,
491 'command:query': queryCommand
,
492 'command:invite': inviteCommand
,
493 'command:topic': topicCommand
,
494 'command:notice': noticeCommand
,
495 'command:quote': quoteCommand
,
496 'command:kick': kickCommand
,
497 'command:clear': clearCommand
,
498 'command:ctcp': ctcpCommand
,
499 'command:server': serverCommand
,
500 'command:whois': whoisCommand
,
501 'command:whowas': whowasCommand
,
502 'command:encoding': encodingCommand
,
503 'command:channel': channelCommand
,
504 'command:applet': appletCommand
,
505 'command:settings': settingsCommand
,
506 'command:script': scriptCommand
509 fn_to_bind
['command:css'] = function (ev
) {
510 var queryString
= '?reload=' + new Date().getTime();
511 $('link[rel="stylesheet"]').each(function () {
512 this.href
= this.href
.replace(/\?.*|$/, queryString
);
516 fn_to_bind
['command:js'] = function (ev
) {
517 if (!ev
.params
[0]) return;
518 $script(ev
.params
[0] + '?' + (new Date().getTime()));
522 fn_to_bind
['command:set'] = function (ev
) {
523 if (!ev
.params
[0]) return;
525 var setting
= ev
.params
[0],
528 // Do we have a second param to set a value?
532 value
= ev
.params
.join(' ');
534 // If we're setting a true boolean value..
535 if (value
=== 'true')
538 // If we're setting a false boolean value..
539 if (value
=== 'false')
542 // If we're setting a number..
543 if (parseInt(value
, 10).toString() === value
)
544 value
= parseInt(value
, 10);
546 _kiwi
.global
.settings
.set(setting
, value
);
549 // Read the value to the user
550 _kiwi
.app
.panels().active
.addMsg('', setting
+ ' = ' + _kiwi
.global
.settings
.get(setting
).toString());
554 fn_to_bind
['command:save'] = function (ev
) {
555 _kiwi
.global
.settings
.save();
556 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_settings_saved').fetch());
560 fn_to_bind
['command:alias'] = function (ev
) {
563 // No parameters passed so list them
565 $.each(controlbox
.preprocessor
.aliases
, function (name
, rule
) {
566 _kiwi
.app
.panels().server
.addMsg(' ', name
+ ' => ' + rule
);
571 // Deleting an alias?
572 if (ev
.params
[0] === 'del' || ev
.params
[0] === 'delete') {
574 if (name
[0] !== '/') name
= '/' + name
;
575 delete controlbox
.preprocessor
.aliases
[name
];
582 rule
= ev
.params
.join(' ');
584 // Make sure the name starts with a slash
585 if (name
[0] !== '/') name
= '/' + name
;
587 // Now actually add the alias
588 controlbox
.preprocessor
.aliases
[name
] = rule
;
592 fn_to_bind
['command:ignore'] = function (ev
) {
593 var list
= this.connections
.active_connection
.get('ignore_list');
595 // No parameters passed so list them
597 if (list
.length
> 0) {
598 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_title').fetch() + ':');
599 $.each(list
, function (idx
, ignored_pattern
) {
600 _kiwi
.app
.panels().active
.addMsg(' ', ignored_pattern
);
603 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_none').fetch());
608 // We have a parameter, so add it
609 list
.push(ev
.params
[0]);
610 this.connections
.active_connection
.set('ignore_list', list
);
611 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_nick').fetch(ev
.params
[0]));
615 fn_to_bind
['command:unignore'] = function (ev
) {
616 var list
= this.connections
.active_connection
.get('ignore_list');
619 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stop_notice').fetch());
623 list
= _
.reject(list
, function(pattern
) {
624 return pattern
=== ev
.params
[0];
627 this.connections
.active_connection
.set('ignore_list', list
);
629 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stopped').fetch(ev
.params
[0]));
633 _
.each(fn_to_bind
, function(fn
, event_name
) {
634 controlbox
.on(event_name
, _
.bind(fn
, that
));
639 isChannelName: function (channel_name
) {
640 var channel_prefix
= _kiwi
.gateway
.get('channel_prefix');
642 if (!channel_name
|| !channel_name
.length
) return false;
643 return (channel_prefix
.indexOf(channel_name
[0]) > -1);
650 // A fallback action. Send a raw command to the server
651 function unknownCommand (ev
) {
652 var raw_cmd
= ev
.command
+ ' ' + ev
.params
.join(' ');
653 console
.log('RAW: ' + raw_cmd
);
654 this.connections
.active_connection
.gateway
.raw(raw_cmd
);
657 function allCommands (ev
) {}
659 function joinCommand (ev
) {
660 var panels
, channel_names
;
662 channel_names
= ev
.params
.join(' ').split(',');
663 panels
= this.connections
.active_connection
.createAndJoinChannels(channel_names
);
665 // Show the last channel if we have one
667 panels
[panels
.length
- 1].view
.show();
670 function queryCommand (ev
) {
671 var destination
, message
, panel
;
673 destination
= ev
.params
[0];
676 message
= ev
.params
.join(' ');
678 // Check if we have the panel already. If not, create it
679 panel
= this.connections
.active_connection
.panels
.getByName(destination
);
681 panel
= new _kiwi
.model
.Query({name
: destination
});
682 this.connections
.active_connection
.panels
.add(panel
);
685 if (panel
) panel
.view
.show();
688 this.connections
.active_connection
.gateway
.msg(panel
.get('name'), message
);
689 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
694 function msgCommand (ev
) {
696 destination
= ev
.params
[0],
697 panel
= this.connections
.active_connection
.panels
.getByName(destination
) || this.panels().server
;
700 message
= formatToIrcMsg(ev
.params
.join(' '));
702 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
703 this.connections
.active_connection
.gateway
.msg(destination
, message
);
706 function actionCommand (ev
) {
707 if (_kiwi
.app
.panels().active
.isServer()) {
711 var panel
= _kiwi
.app
.panels().active
;
712 panel
.addMsg('', '* ' + _kiwi
.app
.connections
.active_connection
.get('nick') + ' ' + ev
.params
.join(' '), 'action');
713 this.connections
.active_connection
.gateway
.action(panel
.get('name'), ev
.params
.join(' '));
716 function partCommand (ev
) {
719 if (ev
.params
.length
=== 0) {
720 this.connections
.active_connection
.gateway
.part(_kiwi
.app
.panels().active
.get('name'));
722 _
.each(ev
.params
, function (channel
) {
723 that
.connections
.active_connection
.gateway
.part(channel
);
728 function nickCommand (ev
) {
729 this.connections
.active_connection
.gateway
.changeNick(ev
.params
[0]);
732 function topicCommand (ev
) {
735 if (ev
.params
.length
=== 0) return;
737 if (this.isChannelName(ev
.params
[0])) {
738 channel_name
= ev
.params
[0];
741 channel_name
= _kiwi
.app
.panels().active
.get('name');
744 this.connections
.active_connection
.gateway
.topic(channel_name
, ev
.params
.join(' '));
747 function noticeCommand (ev
) {
750 // Make sure we have a destination and some sort of message
751 if (ev
.params
.length
<= 1) return;
753 destination
= ev
.params
[0];
756 this.connections
.active_connection
.gateway
.notice(destination
, ev
.params
.join(' '));
759 function quoteCommand (ev
) {
760 var raw
= ev
.params
.join(' ');
761 this.connections
.active_connection
.gateway
.raw(raw
);
764 function kickCommand (ev
) {
765 var nick
, panel
= _kiwi
.app
.panels().active
;
767 if (!panel
.isChannel()) return;
769 // Make sure we have a nick
770 if (ev
.params
.length
=== 0) return;
775 this.connections
.active_connection
.gateway
.kick(panel
.get('name'), nick
, ev
.params
.join(' '));
778 function clearCommand (ev
) {
779 // Can't clear a server or applet panel
780 if (_kiwi
.app
.panels().active
.isServer() || _kiwi
.app
.panels().active
.isApplet()) {
784 if (_kiwi
.app
.panels().active
.clearMessages
) {
785 _kiwi
.app
.panels().active
.clearMessages();
789 function ctcpCommand(ev
) {
792 // Make sure we have a target and a ctcp type (eg. version, time)
793 if (ev
.params
.length
< 2) return;
795 target
= ev
.params
[0];
801 this.connections
.active_connection
.gateway
.ctcp(true, type
, target
, ev
.params
.join(' '));
804 function settingsCommand (ev
) {
805 var settings
= _kiwi
.model
.Applet
.loadOnce('kiwi_settings');
806 settings
.view
.show();
809 function scriptCommand (ev
) {
810 var editor
= _kiwi
.model
.Applet
.loadOnce('kiwi_script_editor');
814 function appletCommand (ev
) {
815 if (!ev
.params
[0]) return;
817 var panel
= new _kiwi
.model
.Applet();
820 // Url and name given
821 panel
.load(ev
.params
[0], ev
.params
[1]);
823 // Load a pre-loaded applet
824 if (_kiwi
.applets
[ev
.params
[0]]) {
825 panel
.load(new _kiwi
.applets
[ev
.params
[0]]());
827 _kiwi
.app
.panels().server
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_applet_notfound').fetch(ev
.params
[0]));
832 _kiwi
.app
.connections
.active_connection
.panels
.add(panel
);
838 function inviteCommand (ev
) {
841 // A nick must be specified
845 // Can only invite into channels
846 if (!_kiwi
.app
.panels().active
.isChannel())
850 channel
= _kiwi
.app
.panels().active
.get('name');
852 _kiwi
.app
.connections
.active_connection
.gateway
.raw('INVITE ' + nick
+ ' ' + channel
);
854 _kiwi
.app
.panels().active
.addMsg('', '== ' + nick
+ ' has been invited to ' + channel
, 'action');
858 function whoisCommand (ev
) {
863 } else if (_kiwi
.app
.panels().active
.isQuery()) {
864 nick
= _kiwi
.app
.panels().active
.get('name');
868 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOIS ' + nick
+ ' ' + nick
);
872 function whowasCommand (ev
) {
877 } else if (_kiwi
.app
.panels().active
.isQuery()) {
878 nick
= _kiwi
.app
.panels().active
.get('name');
882 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOWAS ' + nick
);
885 function encodingCommand (ev
) {
887 _kiwi
.gateway
.setEncoding(null, ev
.params
[0], function (success
) {
889 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_changed').fetch(ev
.params
[0]));
891 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_invalid').fetch(ev
.params
[0]));
895 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_notspecified').fetch());
896 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_usage').fetch());
900 function channelCommand (ev
) {
901 var active_panel
= _kiwi
.app
.panels().active
;
903 if (!active_panel
.isChannel())
906 new _kiwi
.model
.ChannelInfo({channel
: _kiwi
.app
.panels().active
});
909 function serverCommand (ev
) {
910 var server
, port
, ssl
, password
, nick
,
913 // If no server address given, show the new connection dialog
915 tmp
= new _kiwi
.view
.MenuBox(_kiwi
.global
.i18n
.translate('client_models_application_connection_create').fetch());
916 tmp
.addItem('new_connection', new _kiwi
.model
.NewConnection().view
.$el
);
919 // Center screen the dialog
921 top
: (this.view
.$el
.height() / 2) - (tmp
.$el
.height() / 2),
922 left
: (this.view
.$el
.width() / 2) - (tmp
.$el
.width() / 2)
928 // Port given in 'host:port' format and no specific port given after a space
929 if (ev
.params
[0].indexOf(':') > 0) {
930 tmp
= ev
.params
[0].split(':');
934 password
= ev
.params
[1] || undefined;
937 // Server + port given as 'host port'
938 server
= ev
.params
[0];
939 port
= ev
.params
[1] || 6667;
941 password
= ev
.params
[2] || undefined;
944 // + in the port means SSL
945 if (port
.toString()[0] === '+') {
947 port
= parseInt(port
.substring(1), 10);
952 // Default port if one wasn't found
955 // Use the same nick as we currently have
956 nick
= _kiwi
.app
.connections
.active_connection
.get('nick');
958 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_connecting').fetch(server
, port
.toString()));
960 _kiwi
.gateway
.newConnection({
966 }, function(err
, new_connection
) {
968 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_error').fetch(server
, port
.toString(), err
.toString()));