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 // Set any default settings before anything else is applied
36 if (this.server_settings
&& this.server_settings
.client
&& this.server_settings
.client
.settings
) {
37 this.applyDefaultClientSettings(this.server_settings
.client
.settings
);
44 _kiwi
.gateway
= new _kiwi
.model
.Gateway();
45 this.bindGatewayCommands(_kiwi
.gateway
);
47 this.initializeClient();
48 this.initializeGlobals();
50 this.view
.barsHide(true);
52 this.showIntialConenctionDialog();
56 detectKiwiServer: function () {
57 // If running from file, default to localhost:7777 by default
58 if (window
.location
.protocol
=== 'file:') {
59 return 'http://localhost:7778';
61 // Assume the kiwi server is on the same server
62 return window
.location
.protocol
+ '//' + window
.location
.host
;
67 showIntialConenctionDialog: function() {
68 var connection_dialog
= new _kiwi
.model
.NewConnection();
69 this.populateDefaultServerSettings(connection_dialog
);
71 connection_dialog
.view
.$el
.addClass('initial');
72 this.view
.$el
.find('.panel_container:first').append(connection_dialog
.view
.$el
);
74 var $info
= $($('#tmpl_new_connection_info').html().trim());
77 connection_dialog
.view
.infoBoxSet($info
);
78 connection_dialog
.view
.infoBoxShow();
81 // TODO: Shouldn't really be here but it's not working in the view.. :/
82 // Hack for firefox browers: Focus is not given on this event loop iteration
83 setTimeout(function(){
84 connection_dialog
.view
.$el
.find('.nick').select();
87 // Once connected, close this dialog and remove its own event
89 connection_dialog
.view
.$el
.slideUp(function() {
90 connection_dialog
.view
.dispose();
91 connection_dialog
= null;
93 _kiwi
.gateway
.off('onconnect', fn
);
97 _kiwi
.gateway
.on('onconnect', fn
);
101 initializeClient: function () {
102 this.view
= new _kiwi
.view
.Application({model
: this, el
: this.get('container')});
104 // Takes instances of model_network
105 this.connections
= new _kiwi
.model
.NetworkPanelList();
107 // Applets panel list
108 this.applet_panels
= new _kiwi
.model
.PanelList();
109 this.applet_panels
.view
.$el
.addClass('panellist applets');
110 this.view
.$el
.find('.tabs').append(this.applet_panels
.view
.$el
);
113 * Set the UI components up
115 this.controlbox
= new _kiwi
.view
.ControlBox({el
: $('#kiwi .controlbox')[0]});
116 this.bindControllboxCommands(this.controlbox
);
118 this.topicbar
= new _kiwi
.view
.TopicBar({el
: this.view
.$el
.find('.topic')[0]});
120 new _kiwi
.view
.AppToolbar({el
: _kiwi
.app
.view
.$el
.find('.toolbar .app_tools')[0]});
121 new _kiwi
.view
.ChannelTools({el
: _kiwi
.app
.view
.$el
.find('.channel_tools')[0]});
123 this.message
= new _kiwi
.view
.StatusMessage({el
: this.view
.$el
.find('.status_message')[0]});
125 this.resize_handle
= new _kiwi
.view
.ResizeHandler({el
: this.view
.$el
.find('.memberlists_resize_handle')[0]});
127 // Rejigg the UI sizes
128 this.view
.doLayout();
132 initializeGlobals: function () {
133 _kiwi
.global
.connections
= this.connections
;
135 _kiwi
.global
.panels
= this.panels
;
136 _kiwi
.global
.panels
.applets
= this.applet_panels
;
138 _kiwi
.global
.components
.Applet
= _kiwi
.model
.Applet
;
139 _kiwi
.global
.components
.Panel
=_kiwi
.model
.Panel
;
143 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
);
152 populateDefaultServerSettings: function (new_connection_dialog
) {
166 * Get any settings set by the server
167 * These settings may be changed in the server selection dialog or via URL parameters
169 if (this.server_settings
.client
) {
170 if (this.server_settings
.client
.nick
)
171 defaults
.nick
= this.server_settings
.client
.nick
;
173 if (this.server_settings
.client
.server
)
174 defaults
.server
= this.server_settings
.client
.server
;
176 if (this.server_settings
.client
.port
)
177 defaults
.port
= this.server_settings
.client
.port
;
179 if (this.server_settings
.client
.ssl
)
180 defaults
.ssl
= this.server_settings
.client
.ssl
;
182 if (this.server_settings
.client
.channel
)
183 defaults
.channel
= this.server_settings
.client
.channel
;
185 if (this.server_settings
.client
.channel_key
)
186 defaults
.channel_key
= this.server_settings
.client
.channel_key
;
192 * Get any settings passed in the URL
193 * These settings may be changed in the server selection dialog
196 // Any query parameters first
197 if (getQueryVariable('nick'))
198 defaults
.nick
= getQueryVariable('nick');
200 if (window
.location
.hash
)
201 defaults
.channel
= window
.location
.hash
;
204 // Process the URL part by part, extracting as we go
205 parts
= window
.location
.pathname
.toString().replace(this.get('base_path'), '').split('/');
207 if (parts
.length
> 0) {
210 if (parts
.length
> 0 && parts
[0]) {
211 // 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.
212 uricheck
= parts
[0].substr(0, 7).toLowerCase();
213 if ((uricheck
=== 'ircs%3a') || (uricheck
.substr(0,6) === 'irc%3a')) {
214 parts
[0] = decodeURIComponent(parts
[0]);
215 // irc[s]://<host>[:<port>]/[<channel>[?<password>]]
216 uricheck
= /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts
[0]);
218 uricheck[1] = ssl (optional)
220 uricheck[3] = port (optional)
221 uricheck[4] = channel (optional)
222 uricheck[5] = channel key (optional, channel must also be set)
225 if (typeof uricheck
[1] !== 'undefined') {
227 if (defaults
.port
=== 6667) {
228 defaults
.port
= 6697;
231 defaults
.server
= uricheck
[2];
232 if (typeof uricheck
[3] !== 'undefined') {
233 defaults
.port
= uricheck
[3];
235 if (typeof uricheck
[4] !== 'undefined') {
236 defaults
.channel
= '#' + uricheck
[4];
237 if (typeof uricheck
[5] !== 'undefined') {
238 defaults
.channel_key
= uricheck
[5];
244 // Extract the port+ssl if we find one
245 if (parts
[0].search(/:/) > 0) {
246 defaults
.port
= parts
[0].substring(parts
[0].search(/:/) + 1);
247 defaults
.server
= parts
[0].substring(0, parts
[0].search(/:/));
248 if (defaults
.port
[0] === '+') {
249 defaults
.port
= parseInt(defaults
.port
.substring(1), 10);
252 defaults
.ssl
= false;
256 defaults
.server
= parts
[0];
263 if (parts
.length
> 0 && parts
[0]) {
264 defaults
.channel
= '#' + parts
[0];
269 // If any settings have been given by the server.. override any auto detected settings
271 * Get any server restrictions as set in the server config
272 * These settings can not be changed in the server selection dialog
274 if (this.server_settings
&& this.server_settings
.connection
) {
275 if (this.server_settings
.connection
.server
) {
276 defaults
.server
= this.server_settings
.connection
.server
;
279 if (this.server_settings
.connection
.port
) {
280 defaults
.port
= this.server_settings
.connection
.port
;
283 if (this.server_settings
.connection
.ssl
) {
284 defaults
.ssl
= this.server_settings
.connection
.ssl
;
287 if (this.server_settings
.connection
.channel
) {
288 defaults
.channel
= this.server_settings
.connection
.channel
;
291 if (this.server_settings
.connection
.channel_key
) {
292 defaults
.channel_key
= this.server_settings
.connection
.channel_key
;
295 if (this.server_settings
.connection
.nick
) {
296 defaults
.nick
= this.server_settings
.connection
.nick
;
300 // Set any random numbers if needed
301 defaults
.nick
= defaults
.nick
.replace('?', Math
.floor(Math
.random() * 100000).toString());
303 if (getQueryVariable('encoding'))
304 defaults
.encoding
= getQueryVariable('encoding');
306 // Populate the server select box with defaults
307 new_connection_dialog
.view
.populateFields(defaults
);
311 panels
: (function() {
312 var fn = function(panel_type
) {
315 // Default panel type
316 panel_type
= panel_type
|| 'connections';
318 switch (panel_type
) {
320 panels
= this.connections
.panels();
323 panels
= this.applet_panels
.models
;
327 // Active panels / server
328 panels
.active
= this.connections
.active_panel
;
329 panels
.server
= this.connections
.active_connection
?
330 this.connections
.active_connection
.panels
.server
:
336 _
.extend(fn
, Backbone
.Events
);
342 bindGatewayCommands: function (gw
) {
345 gw
.on('onconnect', function (event
) {
346 that
.view
.barsShow();
351 * Handle the reconnections to the kiwi server
354 // 0 = non-reconnecting state. 1 = reconnecting state.
357 // If the current or upcoming disconnect was planned
358 var unplanned_disconnect
= false;
360 gw
.on('disconnect', function (event
) {
361 unplanned_disconnect
= !gw
.disconnect_requested
;
363 if (unplanned_disconnect
) {
364 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnecting').fetch() + '...';
365 that
.message
.text(msg
, {timeout
: 10000});
368 that
.view
.$el
.removeClass('connected');
370 // Mention the disconnection on every channel
371 _kiwi
.app
.connections
.forEach(function(connection
) {
372 connection
.panels
.server
.addMsg('', msg
, 'action quit');
374 connection
.panels
.forEach(function(panel
) {
375 if (!panel
.isChannel())
378 panel
.addMsg('', msg
, 'action quit');
386 gw
.on('reconnecting', function (event
) {
387 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_in_x_seconds').fetch(event
.delay
/1000) + '...';
389 // Only need to mention the repeating re-connection messages on server panels
390 _kiwi
.app
.connections
.forEach(function(connection
) {
391 connection
.panels
.server
.addMsg('', msg
, 'action quit');
396 gw
.on('onconnect', function (event
) {
397 that
.view
.$el
.addClass('connected');
398 if (gw_stat
!== 1) return;
400 if (unplanned_disconnect
) {
401 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_successfully').fetch() + ':)';
402 that
.message
.text(msg
, {timeout
: 5000});
405 // Mention the re-connection on every channel
406 _kiwi
.app
.connections
.forEach(function(connection
) {
407 connection
.panels
.server
.addMsg('', msg
, 'action join');
409 connection
.panels
.forEach(function(panel
) {
410 if (!panel
.isChannel())
413 panel
.addMsg('', msg
, 'action join');
422 gw
.on('kiwi:reconfig', function () {
423 $.getJSON(that
.get('settings_path'), function (data
) {
424 that
.server_settings
= data
.server_settings
|| {};
425 that
.translations
= data
.translations
|| {};
430 gw
.on('kiwi:jumpserver', function (data
) {
432 // No server set? Then nowhere to jump to.
433 if (typeof data
.kiwi_server
=== 'undefined')
436 serv
= data
.kiwi_server
;
438 // Strip any trailing slash from the end
439 if (serv
[serv
.length
-1] === '/')
440 serv
= serv
.substring(0, serv
.length
-1);
442 // Force the jumpserver now?
444 // Get an interval between 5 and 6 minutes so everyone doesn't reconnect it all at once
445 var jump_server_interval
= Math
.random() * (360 - 300) + 300;
447 // Tell the user we are going to disconnect, wait 5 minutes then do the actual reconnect
448 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_prepare').fetch();
449 that
.message
.text(msg
, {timeout
: 10000});
451 setTimeout(function forcedReconnect() {
452 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_reconnect').fetch();
453 that
.message
.text(msg
, {timeout
: 8000});
455 setTimeout(function forcedReconnectPartTwo() {
456 _kiwi
.app
.kiwi_server
= serv
;
458 _kiwi
.gateway
.reconnect(function() {
459 // Reconnect all the IRC connections
460 that
.connections
.forEach(function(con
){ con
.reconnect(); });
464 }, jump_server_interval
* 1000);
472 * Bind to certain commands that may be typed into the control box
474 bindControllboxCommands: function (controlbox
) {
478 $.extend(controlbox
.preprocessor
.aliases
, {
481 '/me': '/action $1+',
485 '/raw': '/quote $1+',
487 // Op related aliases
488 '/op': '/quote mode $channel +o $1+',
489 '/deop': '/quote mode $channel -o $1+',
490 '/hop': '/quote mode $channel +h $1+',
491 '/dehop': '/quote mode $channel -h $1+',
492 '/voice': '/quote mode $channel +v $1+',
493 '/devoice': '/quote mode $channel -v $1+',
494 '/k': '/kick $channel $1+',
495 '/ban': '/quote mode $channel +b $1+',
496 '/unban': '/quote mode $channel -b $1+',
499 '/slap': '/me slaps $1 around a bit with a large trout'
502 // Functions to bind to controlbox events
504 'unknown_command': unknownCommand
,
505 'command': allCommands
,
506 'command:msg': msgCommand
,
507 'command:action': actionCommand
,
508 'command:join': joinCommand
,
509 'command:part': partCommand
,
510 'command:nick': nickCommand
,
511 'command:query': queryCommand
,
512 'command:invite': inviteCommand
,
513 'command:topic': topicCommand
,
514 'command:notice': noticeCommand
,
515 'command:quote': quoteCommand
,
516 'command:kick': kickCommand
,
517 'command:clear': clearCommand
,
518 'command:ctcp': ctcpCommand
,
519 'command:server': serverCommand
,
520 'command:whois': whoisCommand
,
521 'command:whowas': whowasCommand
,
522 'command:encoding': encodingCommand
,
523 'command:channel': channelCommand
,
524 'command:applet': appletCommand
,
525 'command:settings': settingsCommand
,
526 'command:script': scriptCommand
529 fn_to_bind
['command:css'] = function (ev
) {
530 var queryString
= '?reload=' + new Date().getTime();
531 $('link[rel="stylesheet"]').each(function () {
532 this.href
= this.href
.replace(/\?.*|$/, queryString
);
536 fn_to_bind
['command:js'] = function (ev
) {
537 if (!ev
.params
[0]) return;
538 $script(ev
.params
[0] + '?' + (new Date().getTime()));
542 fn_to_bind
['command:set'] = function (ev
) {
543 if (!ev
.params
[0]) return;
545 var setting
= ev
.params
[0],
548 // Do we have a second param to set a value?
552 value
= ev
.params
.join(' ');
554 // If we're setting a true boolean value..
555 if (value
=== 'true')
558 // If we're setting a false boolean value..
559 if (value
=== 'false')
562 // If we're setting a number..
563 if (parseInt(value
, 10).toString() === value
)
564 value
= parseInt(value
, 10);
566 _kiwi
.global
.settings
.set(setting
, value
);
569 // Read the value to the user
570 _kiwi
.app
.panels().active
.addMsg('', setting
+ ' = ' + _kiwi
.global
.settings
.get(setting
).toString());
574 fn_to_bind
['command:save'] = function (ev
) {
575 _kiwi
.global
.settings
.save();
576 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_settings_saved').fetch());
580 fn_to_bind
['command:alias'] = function (ev
) {
583 // No parameters passed so list them
585 $.each(controlbox
.preprocessor
.aliases
, function (name
, rule
) {
586 _kiwi
.app
.panels().server
.addMsg(' ', name
+ ' => ' + rule
);
591 // Deleting an alias?
592 if (ev
.params
[0] === 'del' || ev
.params
[0] === 'delete') {
594 if (name
[0] !== '/') name
= '/' + name
;
595 delete controlbox
.preprocessor
.aliases
[name
];
602 rule
= ev
.params
.join(' ');
604 // Make sure the name starts with a slash
605 if (name
[0] !== '/') name
= '/' + name
;
607 // Now actually add the alias
608 controlbox
.preprocessor
.aliases
[name
] = rule
;
612 fn_to_bind
['command:ignore'] = function (ev
) {
613 var list
= this.connections
.active_connection
.get('ignore_list');
615 // No parameters passed so list them
617 if (list
.length
> 0) {
618 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_title').fetch() + ':');
619 $.each(list
, function (idx
, ignored_pattern
) {
620 _kiwi
.app
.panels().active
.addMsg(' ', ignored_pattern
);
623 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_none').fetch());
628 // We have a parameter, so add it
629 list
.push(ev
.params
[0]);
630 this.connections
.active_connection
.set('ignore_list', list
);
631 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_nick').fetch(ev
.params
[0]));
635 fn_to_bind
['command:unignore'] = function (ev
) {
636 var list
= this.connections
.active_connection
.get('ignore_list');
639 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stop_notice').fetch());
643 list
= _
.reject(list
, function(pattern
) {
644 return pattern
=== ev
.params
[0];
647 this.connections
.active_connection
.set('ignore_list', list
);
649 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stopped').fetch(ev
.params
[0]));
653 _
.each(fn_to_bind
, function(fn
, event_name
) {
654 controlbox
.on(event_name
, _
.bind(fn
, that
));
659 isChannelName: function (channel_name
) {
660 var channel_prefix
= _kiwi
.gateway
.get('channel_prefix');
662 if (!channel_name
|| !channel_name
.length
) return false;
663 return (channel_prefix
.indexOf(channel_name
[0]) > -1);
670 // A fallback action. Send a raw command to the server
671 function unknownCommand (ev
) {
672 var raw_cmd
= ev
.command
+ ' ' + ev
.params
.join(' ');
673 console
.log('RAW: ' + raw_cmd
);
674 this.connections
.active_connection
.gateway
.raw(raw_cmd
);
677 function allCommands (ev
) {}
679 function joinCommand (ev
) {
680 var panels
, channel_names
;
682 channel_names
= ev
.params
.join(' ').split(',');
683 panels
= this.connections
.active_connection
.createAndJoinChannels(channel_names
);
685 // Show the last channel if we have one
687 panels
[panels
.length
- 1].view
.show();
690 function queryCommand (ev
) {
691 var destination
, message
, panel
;
693 destination
= ev
.params
[0];
696 message
= ev
.params
.join(' ');
698 // Check if we have the panel already. If not, create it
699 panel
= this.connections
.active_connection
.panels
.getByName(destination
);
701 panel
= new _kiwi
.model
.Query({name
: destination
});
702 this.connections
.active_connection
.panels
.add(panel
);
705 if (panel
) panel
.view
.show();
708 this.connections
.active_connection
.gateway
.msg(panel
.get('name'), message
);
709 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
714 function msgCommand (ev
) {
716 destination
= ev
.params
[0],
717 panel
= this.connections
.active_connection
.panels
.getByName(destination
) || this.panels().server
;
720 message
= formatToIrcMsg(ev
.params
.join(' '));
722 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
723 this.connections
.active_connection
.gateway
.privmsg(destination
, message
);
726 function actionCommand (ev
) {
727 if (_kiwi
.app
.panels().active
.isServer()) {
731 var panel
= _kiwi
.app
.panels().active
;
732 panel
.addMsg('', '* ' + _kiwi
.app
.connections
.active_connection
.get('nick') + ' ' + ev
.params
.join(' '), 'action');
733 this.connections
.active_connection
.gateway
.action(panel
.get('name'), ev
.params
.join(' '));
736 function partCommand (ev
) {
737 if (ev
.params
.length
=== 0) {
738 this.connections
.active_connection
.gateway
.part(_kiwi
.app
.panels().active
.get('name'));
740 _
.each(ev
.params
, function (channel
) {
741 this.connections
.active_connection
.gateway
.part(channel
);
746 function nickCommand (ev
) {
747 this.connections
.active_connection
.gateway
.changeNick(ev
.params
[0]);
750 function topicCommand (ev
) {
753 if (ev
.params
.length
=== 0) return;
755 if (this.isChannelName(ev
.params
[0])) {
756 channel_name
= ev
.params
[0];
759 channel_name
= _kiwi
.app
.panels().active
.get('name');
762 this.connections
.active_connection
.gateway
.topic(channel_name
, ev
.params
.join(' '));
765 function noticeCommand (ev
) {
768 // Make sure we have a destination and some sort of message
769 if (ev
.params
.length
<= 1) return;
771 destination
= ev
.params
[0];
774 this.connections
.active_connection
.gateway
.notice(destination
, ev
.params
.join(' '));
777 function quoteCommand (ev
) {
778 var raw
= ev
.params
.join(' ');
779 this.connections
.active_connection
.gateway
.raw(raw
);
782 function kickCommand (ev
) {
783 var nick
, panel
= _kiwi
.app
.panels().active
;
785 if (!panel
.isChannel()) return;
787 // Make sure we have a nick
788 if (ev
.params
.length
=== 0) return;
793 this.connections
.active_connection
.gateway
.kick(panel
.get('name'), nick
, ev
.params
.join(' '));
796 function clearCommand (ev
) {
797 // Can't clear a server or applet panel
798 if (_kiwi
.app
.panels().active
.isServer() || _kiwi
.app
.panels().active
.isApplet()) {
802 if (_kiwi
.app
.panels().active
.clearMessages
) {
803 _kiwi
.app
.panels().active
.clearMessages();
807 function ctcpCommand(ev
) {
810 // Make sure we have a target and a ctcp type (eg. version, time)
811 if (ev
.params
.length
< 2) return;
813 target
= ev
.params
[0];
819 this.connections
.active_connection
.gateway
.ctcp(true, type
, target
, ev
.params
.join(' '));
822 function settingsCommand (ev
) {
823 var settings
= _kiwi
.model
.Applet
.loadOnce('kiwi_settings');
824 settings
.view
.show();
827 function scriptCommand (ev
) {
828 var editor
= _kiwi
.model
.Applet
.loadOnce('kiwi_script_editor');
832 function appletCommand (ev
) {
833 if (!ev
.params
[0]) return;
835 var panel
= new _kiwi
.model
.Applet();
838 // Url and name given
839 panel
.load(ev
.params
[0], ev
.params
[1]);
841 // Load a pre-loaded applet
842 if (_kiwi
.applets
[ev
.params
[0]]) {
843 panel
.load(new _kiwi
.applets
[ev
.params
[0]]());
845 _kiwi
.app
.panels().server
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_applet_notfound').fetch(ev
.params
[0]));
850 _kiwi
.app
.connections
.active_connection
.panels
.add(panel
);
856 function inviteCommand (ev
) {
859 // A nick must be specified
863 // Can only invite into channels
864 if (!_kiwi
.app
.panels().active
.isChannel())
868 channel
= _kiwi
.app
.panels().active
.get('name');
870 _kiwi
.app
.connections
.active_connection
.gateway
.raw('INVITE ' + nick
+ ' ' + channel
);
872 _kiwi
.app
.panels().active
.addMsg('', '== ' + nick
+ ' has been invited to ' + channel
, 'action');
876 function whoisCommand (ev
) {
881 } else if (_kiwi
.app
.panels().active
.isQuery()) {
882 nick
= _kiwi
.app
.panels().active
.get('name');
886 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOIS ' + nick
+ ' ' + nick
);
890 function whowasCommand (ev
) {
895 } else if (_kiwi
.app
.panels().active
.isQuery()) {
896 nick
= _kiwi
.app
.panels().active
.get('name');
900 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOWAS ' + nick
);
903 function encodingCommand (ev
) {
905 _kiwi
.gateway
.setEncoding(null, ev
.params
[0], function (success
) {
907 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_changed').fetch(ev
.params
[0]));
909 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_invalid').fetch(ev
.params
[0]));
913 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_notspecified').fetch());
914 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_usage').fetch());
918 function channelCommand (ev
) {
919 var active_panel
= _kiwi
.app
.panels().active
;
921 if (!active_panel
.isChannel())
924 new _kiwi
.model
.ChannelInfo({channel
: _kiwi
.app
.panels().active
});
927 function serverCommand (ev
) {
928 var server
, port
, ssl
, password
, nick
,
931 // If no server address given, show the new connection dialog
933 tmp
= new _kiwi
.view
.MenuBox(_kiwi
.global
.i18n
.translate('client_models_application_connection_create').fetch());
934 tmp
.addItem('new_connection', new _kiwi
.model
.NewConnection().view
.$el
);
937 // Center screen the dialog
939 top
: (this.view
.$el
.height() / 2) - (tmp
.$el
.height() / 2),
940 left
: (this.view
.$el
.width() / 2) - (tmp
.$el
.width() / 2)
946 // Port given in 'host:port' format and no specific port given after a space
947 if (ev
.params
[0].indexOf(':') > 0) {
948 tmp
= ev
.params
[0].split(':');
952 password
= ev
.params
[1] || undefined;
955 // Server + port given as 'host port'
956 server
= ev
.params
[0];
957 port
= ev
.params
[1] || 6667;
959 password
= ev
.params
[2] || undefined;
962 // + in the port means SSL
963 if (port
.toString()[0] === '+') {
965 port
= parseInt(port
.substring(1), 10);
970 // Default port if one wasn't found
973 // Use the same nick as we currently have
974 nick
= _kiwi
.app
.connections
.active_connection
.get('nick');
976 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_connecting').fetch(server
, port
.toString()));
978 _kiwi
.gateway
.newConnection({
984 }, function(err
, new_connection
) {
986 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_error').fetch(server
, port
.toString(), err
.toString()));