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() {
314 var fn = function(panel_type
) {
317 // Default panel type
318 panel_type
= panel_type
|| 'connections';
320 switch (panel_type
) {
322 panels
= this.connections
.panels();
325 panels
= this.applet_panels
.models
;
329 // Active panels / server
330 panels
.active
= active_panel
;
331 panels
.server
= this.connections
.active_connection
?
332 this.connections
.active_connection
.panels
.server
:
338 _
.extend(fn
, Backbone
.Events
);
340 // Keep track of the active panel. Channel/query/server or applet
341 fn
.bind('active', function (new_active_panel
) {
342 active_panel
= new_active_panel
;
349 bindGatewayCommands: function (gw
) {
352 gw
.on('onconnect', function (event
) {
353 that
.view
.barsShow();
358 * Handle the reconnections to the kiwi server
361 // 0 = non-reconnecting state. 1 = reconnecting state.
364 // If the current or upcoming disconnect was planned
365 var unplanned_disconnect
= false;
367 gw
.on('disconnect', function (event
) {
368 unplanned_disconnect
= !gw
.disconnect_requested
;
370 if (unplanned_disconnect
) {
371 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnecting').fetch() + '...';
372 that
.message
.text(msg
, {timeout
: 10000});
375 that
.view
.$el
.removeClass('connected');
377 // Mention the disconnection on every channel
378 _kiwi
.app
.connections
.forEach(function(connection
) {
379 connection
.panels
.server
.addMsg('', msg
, 'action quit');
381 connection
.panels
.forEach(function(panel
) {
382 if (!panel
.isChannel())
385 panel
.addMsg('', msg
, 'action quit');
393 gw
.on('reconnecting', function (event
) {
394 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_in_x_seconds').fetch(event
.delay
/1000) + '...';
396 // Only need to mention the repeating re-connection messages on server panels
397 _kiwi
.app
.connections
.forEach(function(connection
) {
398 connection
.panels
.server
.addMsg('', msg
, 'action quit');
403 gw
.on('onconnect', function (event
) {
404 that
.view
.$el
.addClass('connected');
405 if (gw_stat
!== 1) return;
407 if (unplanned_disconnect
) {
408 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_successfully').fetch() + ':)';
409 that
.message
.text(msg
, {timeout
: 5000});
412 // Mention the re-connection on every channel
413 _kiwi
.app
.connections
.forEach(function(connection
) {
414 connection
.panels
.server
.addMsg('', msg
, 'action join');
416 connection
.panels
.forEach(function(panel
) {
417 if (!panel
.isChannel())
420 panel
.addMsg('', msg
, 'action join');
429 gw
.on('kiwi:reconfig', function () {
430 $.getJSON(that
.get('settings_path'), function (data
) {
431 that
.server_settings
= data
.server_settings
|| {};
432 that
.translations
= data
.translations
|| {};
437 gw
.on('kiwi:jumpserver', function (data
) {
439 // No server set? Then nowhere to jump to.
440 if (typeof data
.kiwi_server
=== 'undefined')
443 serv
= data
.kiwi_server
;
445 // Strip any trailing slash from the end
446 if (serv
[serv
.length
-1] === '/')
447 serv
= serv
.substring(0, serv
.length
-1);
449 // Force the jumpserver now?
451 // Get an interval between 5 and 6 minutes so everyone doesn't reconnect it all at once
452 var jump_server_interval
= Math
.random() * (360 - 300) + 300;
454 // Tell the user we are going to disconnect, wait 5 minutes then do the actual reconnect
455 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_prepare').fetch();
456 that
.message
.text(msg
, {timeout
: 10000});
458 setTimeout(function forcedReconnect() {
459 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_reconnect').fetch();
460 that
.message
.text(msg
, {timeout
: 8000});
462 setTimeout(function forcedReconnectPartTwo() {
463 _kiwi
.app
.kiwi_server
= serv
;
465 _kiwi
.gateway
.reconnect(function() {
466 // Reconnect all the IRC connections
467 that
.connections
.forEach(function(con
){ con
.reconnect(); });
471 }, jump_server_interval
* 1000);
479 * Bind to certain commands that may be typed into the control box
481 bindControllboxCommands: function (controlbox
) {
485 $.extend(controlbox
.preprocessor
.aliases
, {
488 '/me': '/action $1+',
492 '/raw': '/quote $1+',
494 // Op related aliases
495 '/op': '/quote mode $channel +o $1+',
496 '/deop': '/quote mode $channel -o $1+',
497 '/hop': '/quote mode $channel +h $1+',
498 '/dehop': '/quote mode $channel -h $1+',
499 '/voice': '/quote mode $channel +v $1+',
500 '/devoice': '/quote mode $channel -v $1+',
501 '/k': '/kick $channel $1+',
502 '/ban': '/quote mode $channel +b $1+',
503 '/unban': '/quote mode $channel -b $1+',
506 '/slap': '/me slaps $1 around a bit with a large trout'
509 // Functions to bind to controlbox events
511 'unknown_command': unknownCommand
,
512 'command': allCommands
,
513 'command:msg': msgCommand
,
514 'command:action': actionCommand
,
515 'command:join': joinCommand
,
516 'command:part': partCommand
,
517 'command:nick': nickCommand
,
518 'command:query': queryCommand
,
519 'command:invite': inviteCommand
,
520 'command:topic': topicCommand
,
521 'command:notice': noticeCommand
,
522 'command:quote': quoteCommand
,
523 'command:kick': kickCommand
,
524 'command:clear': clearCommand
,
525 'command:ctcp': ctcpCommand
,
526 'command:server': serverCommand
,
527 'command:whois': whoisCommand
,
528 'command:whowas': whowasCommand
,
529 'command:encoding': encodingCommand
,
530 'command:channel': channelCommand
,
531 'command:applet': appletCommand
,
532 'command:settings': settingsCommand
,
533 'command:script': scriptCommand
536 fn_to_bind
['command:css'] = function (ev
) {
537 var queryString
= '?reload=' + new Date().getTime();
538 $('link[rel="stylesheet"]').each(function () {
539 this.href
= this.href
.replace(/\?.*|$/, queryString
);
543 fn_to_bind
['command:js'] = function (ev
) {
544 if (!ev
.params
[0]) return;
545 $script(ev
.params
[0] + '?' + (new Date().getTime()));
549 fn_to_bind
['command:set'] = function (ev
) {
550 if (!ev
.params
[0]) return;
552 var setting
= ev
.params
[0],
555 // Do we have a second param to set a value?
559 value
= ev
.params
.join(' ');
561 // If we're setting a true boolean value..
562 if (value
=== 'true')
565 // If we're setting a false boolean value..
566 if (value
=== 'false')
569 // If we're setting a number..
570 if (parseInt(value
, 10).toString() === value
)
571 value
= parseInt(value
, 10);
573 _kiwi
.global
.settings
.set(setting
, value
);
576 // Read the value to the user
577 _kiwi
.app
.panels().active
.addMsg('', setting
+ ' = ' + _kiwi
.global
.settings
.get(setting
).toString());
581 fn_to_bind
['command:save'] = function (ev
) {
582 _kiwi
.global
.settings
.save();
583 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_settings_saved').fetch());
587 fn_to_bind
['command:alias'] = function (ev
) {
590 // No parameters passed so list them
592 $.each(controlbox
.preprocessor
.aliases
, function (name
, rule
) {
593 _kiwi
.app
.panels().server
.addMsg(' ', name
+ ' => ' + rule
);
598 // Deleting an alias?
599 if (ev
.params
[0] === 'del' || ev
.params
[0] === 'delete') {
601 if (name
[0] !== '/') name
= '/' + name
;
602 delete controlbox
.preprocessor
.aliases
[name
];
609 rule
= ev
.params
.join(' ');
611 // Make sure the name starts with a slash
612 if (name
[0] !== '/') name
= '/' + name
;
614 // Now actually add the alias
615 controlbox
.preprocessor
.aliases
[name
] = rule
;
619 fn_to_bind
['command:ignore'] = function (ev
) {
620 var list
= this.connections
.active_connection
.get('ignore_list');
622 // No parameters passed so list them
624 if (list
.length
> 0) {
625 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_title').fetch() + ':');
626 $.each(list
, function (idx
, ignored_pattern
) {
627 _kiwi
.app
.panels().active
.addMsg(' ', ignored_pattern
);
630 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_none').fetch());
635 // We have a parameter, so add it
636 list
.push(ev
.params
[0]);
637 this.connections
.active_connection
.set('ignore_list', list
);
638 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_nick').fetch(ev
.params
[0]));
642 fn_to_bind
['command:unignore'] = function (ev
) {
643 var list
= this.connections
.active_connection
.get('ignore_list');
646 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stop_notice').fetch());
650 list
= _
.reject(list
, function(pattern
) {
651 return pattern
=== ev
.params
[0];
654 this.connections
.active_connection
.set('ignore_list', list
);
656 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stopped').fetch(ev
.params
[0]));
660 _
.each(fn_to_bind
, function(fn
, event_name
) {
661 controlbox
.on(event_name
, _
.bind(fn
, that
));
666 isChannelName: function (channel_name
) {
667 var channel_prefix
= _kiwi
.gateway
.get('channel_prefix');
669 if (!channel_name
|| !channel_name
.length
) return false;
670 return (channel_prefix
.indexOf(channel_name
[0]) > -1);
677 // A fallback action. Send a raw command to the server
678 function unknownCommand (ev
) {
679 var raw_cmd
= ev
.command
+ ' ' + ev
.params
.join(' ');
680 console
.log('RAW: ' + raw_cmd
);
681 this.connections
.active_connection
.gateway
.raw(raw_cmd
);
684 function allCommands (ev
) {}
686 function joinCommand (ev
) {
687 var panels
, channel_names
;
689 channel_names
= ev
.params
.join(' ').split(',');
690 panels
= this.connections
.active_connection
.createAndJoinChannels(channel_names
);
692 // Show the last channel if we have one
694 panels
[panels
.length
- 1].view
.show();
697 function queryCommand (ev
) {
698 var destination
, message
, panel
;
700 destination
= ev
.params
[0];
703 message
= ev
.params
.join(' ');
705 // Check if we have the panel already. If not, create it
706 panel
= this.connections
.active_connection
.panels
.getByName(destination
);
708 panel
= new _kiwi
.model
.Query({name
: destination
});
709 this.connections
.active_connection
.panels
.add(panel
);
712 if (panel
) panel
.view
.show();
715 this.connections
.active_connection
.gateway
.msg(panel
.get('name'), message
);
716 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
721 function msgCommand (ev
) {
723 destination
= ev
.params
[0],
724 panel
= this.connections
.active_connection
.panels
.getByName(destination
) || this.panels().server
;
727 message
= formatToIrcMsg(ev
.params
.join(' '));
729 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
730 this.connections
.active_connection
.gateway
.msg(destination
, message
);
733 function actionCommand (ev
) {
734 if (_kiwi
.app
.panels().active
.isServer()) {
738 var panel
= _kiwi
.app
.panels().active
;
739 panel
.addMsg('', '* ' + _kiwi
.app
.connections
.active_connection
.get('nick') + ' ' + ev
.params
.join(' '), 'action');
740 this.connections
.active_connection
.gateway
.action(panel
.get('name'), ev
.params
.join(' '));
743 function partCommand (ev
) {
746 if (ev
.params
.length
=== 0) {
747 this.connections
.active_connection
.gateway
.part(_kiwi
.app
.panels().active
.get('name'));
749 _
.each(ev
.params
, function (channel
) {
750 that
.connections
.active_connection
.gateway
.part(channel
);
755 function nickCommand (ev
) {
756 this.connections
.active_connection
.gateway
.changeNick(ev
.params
[0]);
759 function topicCommand (ev
) {
762 if (ev
.params
.length
=== 0) return;
764 if (this.isChannelName(ev
.params
[0])) {
765 channel_name
= ev
.params
[0];
768 channel_name
= _kiwi
.app
.panels().active
.get('name');
771 this.connections
.active_connection
.gateway
.topic(channel_name
, ev
.params
.join(' '));
774 function noticeCommand (ev
) {
777 // Make sure we have a destination and some sort of message
778 if (ev
.params
.length
<= 1) return;
780 destination
= ev
.params
[0];
783 this.connections
.active_connection
.gateway
.notice(destination
, ev
.params
.join(' '));
786 function quoteCommand (ev
) {
787 var raw
= ev
.params
.join(' ');
788 this.connections
.active_connection
.gateway
.raw(raw
);
791 function kickCommand (ev
) {
792 var nick
, panel
= _kiwi
.app
.panels().active
;
794 if (!panel
.isChannel()) return;
796 // Make sure we have a nick
797 if (ev
.params
.length
=== 0) return;
802 this.connections
.active_connection
.gateway
.kick(panel
.get('name'), nick
, ev
.params
.join(' '));
805 function clearCommand (ev
) {
806 // Can't clear a server or applet panel
807 if (_kiwi
.app
.panels().active
.isServer() || _kiwi
.app
.panels().active
.isApplet()) {
811 if (_kiwi
.app
.panels().active
.clearMessages
) {
812 _kiwi
.app
.panels().active
.clearMessages();
816 function ctcpCommand(ev
) {
819 // Make sure we have a target and a ctcp type (eg. version, time)
820 if (ev
.params
.length
< 2) return;
822 target
= ev
.params
[0];
828 this.connections
.active_connection
.gateway
.ctcp(true, type
, target
, ev
.params
.join(' '));
831 function settingsCommand (ev
) {
832 var settings
= _kiwi
.model
.Applet
.loadOnce('kiwi_settings');
833 settings
.view
.show();
836 function scriptCommand (ev
) {
837 var editor
= _kiwi
.model
.Applet
.loadOnce('kiwi_script_editor');
841 function appletCommand (ev
) {
842 if (!ev
.params
[0]) return;
844 var panel
= new _kiwi
.model
.Applet();
847 // Url and name given
848 panel
.load(ev
.params
[0], ev
.params
[1]);
850 // Load a pre-loaded applet
851 if (_kiwi
.applets
[ev
.params
[0]]) {
852 panel
.load(new _kiwi
.applets
[ev
.params
[0]]());
854 _kiwi
.app
.panels().server
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_applet_notfound').fetch(ev
.params
[0]));
859 _kiwi
.app
.connections
.active_connection
.panels
.add(panel
);
865 function inviteCommand (ev
) {
868 // A nick must be specified
872 // Can only invite into channels
873 if (!_kiwi
.app
.panels().active
.isChannel())
877 channel
= _kiwi
.app
.panels().active
.get('name');
879 _kiwi
.app
.connections
.active_connection
.gateway
.raw('INVITE ' + nick
+ ' ' + channel
);
881 _kiwi
.app
.panels().active
.addMsg('', '== ' + nick
+ ' has been invited to ' + channel
, 'action');
885 function whoisCommand (ev
) {
890 } else if (_kiwi
.app
.panels().active
.isQuery()) {
891 nick
= _kiwi
.app
.panels().active
.get('name');
895 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOIS ' + nick
+ ' ' + nick
);
899 function whowasCommand (ev
) {
904 } else if (_kiwi
.app
.panels().active
.isQuery()) {
905 nick
= _kiwi
.app
.panels().active
.get('name');
909 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOWAS ' + nick
);
912 function encodingCommand (ev
) {
914 _kiwi
.gateway
.setEncoding(null, ev
.params
[0], function (success
) {
916 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_changed').fetch(ev
.params
[0]));
918 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_invalid').fetch(ev
.params
[0]));
922 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_notspecified').fetch());
923 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_usage').fetch());
927 function channelCommand (ev
) {
928 var active_panel
= _kiwi
.app
.panels().active
;
930 if (!active_panel
.isChannel())
933 new _kiwi
.model
.ChannelInfo({channel
: _kiwi
.app
.panels().active
});
936 function serverCommand (ev
) {
937 var server
, port
, ssl
, password
, nick
,
940 // If no server address given, show the new connection dialog
942 tmp
= new _kiwi
.view
.MenuBox(_kiwi
.global
.i18n
.translate('client_models_application_connection_create').fetch());
943 tmp
.addItem('new_connection', new _kiwi
.model
.NewConnection().view
.$el
);
946 // Center screen the dialog
948 top
: (this.view
.$el
.height() / 2) - (tmp
.$el
.height() / 2),
949 left
: (this.view
.$el
.width() / 2) - (tmp
.$el
.width() / 2)
955 // Port given in 'host:port' format and no specific port given after a space
956 if (ev
.params
[0].indexOf(':') > 0) {
957 tmp
= ev
.params
[0].split(':');
961 password
= ev
.params
[1] || undefined;
964 // Server + port given as 'host port'
965 server
= ev
.params
[0];
966 port
= ev
.params
[1] || 6667;
968 password
= ev
.params
[2] || undefined;
971 // + in the port means SSL
972 if (port
.toString()[0] === '+') {
974 port
= parseInt(port
.substring(1), 10);
979 // Default port if one wasn't found
982 // Use the same nick as we currently have
983 nick
= _kiwi
.app
.connections
.active_connection
.get('nick');
985 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_connecting').fetch(server
, port
.toString()));
987 _kiwi
.gateway
.newConnection({
993 }, function(err
, new_connection
) {
995 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_error').fetch(server
, port
.toString(), err
.toString()));