1 _kiwi
.model
.Application = function () {
2 // Set to a reference to this object within initialize()
6 var model = function () {
7 /** _kiwi.view.Application */
10 /** _kiwi.view.StatusMessage */
13 /* Address for the kiwi server */
14 this.kiwi_server
= null;
16 this.initialize = function (options
) {
19 if (options
[0].container
) {
20 this.set('container', options
[0].container
);
23 // The base url to the kiwi server
24 this.set('base_path', options
[0].base_path
? options
[0].base_path
: '/kiwi');
26 // Path for the settings.json file
27 this.set('settings_path', options
[0].settings_path
?
28 options
[0].settings_path
:
29 this.get('base_path') + '/assets/settings.json'
32 // Any options sent down from the server
33 this.server_settings
= options
[0].server_settings
|| {};
34 this.translations
= options
[0].translations
|| {};
35 this.themes
= options
[0].themes
|| [];
37 // Best guess at where the kiwi server is if not already specified
38 this.kiwi_server
= options
[0].kiwi_server
|| this.detectKiwiServer();
40 // Set any default settings before anything else is applied
41 if (this.server_settings
&& this.server_settings
.client
&& this.server_settings
.client
.settings
) {
42 this.applyDefaultClientSettings(this.server_settings
.client
.settings
);
47 this.start = function () {
49 _kiwi
.gateway
= new _kiwi
.model
.Gateway();
50 this.bindGatewayCommands(_kiwi
.gateway
);
52 this.initializeClient();
53 this.initializeGlobals();
55 this.view
.barsHide(true);
57 this.showIntialConenctionDialog();
61 this.detectKiwiServer = function () {
62 // If running from file, default to localhost:7777 by default
63 if (window
.location
.protocol
=== 'file:') {
64 return 'http://localhost:7778';
66 // Assume the kiwi server is on the same server
67 return window
.location
.protocol
+ '//' + window
.location
.host
;
72 this.showIntialConenctionDialog = function() {
73 var connection_dialog
= new _kiwi
.model
.NewConnection();
74 this.populateDefaultServerSettings(connection_dialog
);
76 connection_dialog
.view
.$el
.addClass('initial');
77 this.view
.$el
.find('.panel_container:first').append(connection_dialog
.view
.$el
);
79 var $info
= $($('#tmpl_new_connection_info').html().trim());
82 connection_dialog
.view
.infoBoxSet($info
);
83 connection_dialog
.view
.infoBoxShow();
86 // TODO: Shouldn't really be here but it's not working in the view.. :/
87 // Hack for firefox browers: Focus is not given on this event loop iteration
88 setTimeout(function(){
89 connection_dialog
.view
.$el
.find('.nick').select();
92 // Once connected, close this dialog and remove its own event
94 connection_dialog
.view
.$el
.slideUp(function() {
95 connection_dialog
.view
.dispose();
96 connection_dialog
= null;
98 _kiwi
.gateway
.off('onconnect', fn
);
102 _kiwi
.gateway
.on('onconnect', fn
);
106 this.initializeClient = function () {
107 this.view
= new _kiwi
.view
.Application({model
: this, el
: this.get('container')});
109 // Takes instances of model_network
110 this.connections
= new _kiwi
.model
.NetworkPanelList();
112 // Applets panel list
113 this.applet_panels
= new _kiwi
.model
.PanelList();
114 this.applet_panels
.view
.$el
.addClass('panellist applets');
115 this.view
.$el
.find('.tabs').append(this.applet_panels
.view
.$el
);
118 * Set the UI components up
120 this.controlbox
= new _kiwi
.view
.ControlBox({el
: $('#kiwi .controlbox')[0]});
121 this.bindControllboxCommands(this.controlbox
);
123 this.topicbar
= new _kiwi
.view
.TopicBar({el
: this.view
.$el
.find('.topic')[0]});
125 new _kiwi
.view
.AppToolbar({el
: _kiwi
.app
.view
.$el
.find('.toolbar .app_tools')[0]});
127 this.message
= new _kiwi
.view
.StatusMessage({el
: this.view
.$el
.find('.status_message')[0]});
129 this.resize_handle
= new _kiwi
.view
.ResizeHandler({el
: this.view
.$el
.find('.memberlists_resize_handle')[0]});
131 // Rejigg the UI sizes
132 this.view
.doLayout();
136 this.initializeGlobals = function () {
137 _kiwi
.global
.connections
= this.connections
;
139 _kiwi
.global
.panels
= this.panels
;
140 _kiwi
.global
.panels
.applets
= this.applet_panels
;
142 _kiwi
.global
.components
.Applet
= _kiwi
.model
.Applet
;
143 _kiwi
.global
.components
.Panel
=_kiwi
.model
.Panel
;
147 this.applyDefaultClientSettings = function (settings
) {
148 _
.each(settings
, function (value
, setting
) {
149 if (typeof _kiwi
.global
.settings
.get(setting
) === 'undefined') {
150 _kiwi
.global
.settings
.set(setting
, value
);
156 this.populateDefaultServerSettings = function (new_connection_dialog
) {
170 * Get any settings set by the server
171 * These settings may be changed in the server selection dialog or via URL parameters
173 if (this.server_settings
.client
) {
174 if (this.server_settings
.client
.nick
)
175 defaults
.nick
= this.server_settings
.client
.nick
;
177 if (this.server_settings
.client
.server
)
178 defaults
.server
= this.server_settings
.client
.server
;
180 if (this.server_settings
.client
.port
)
181 defaults
.port
= this.server_settings
.client
.port
;
183 if (this.server_settings
.client
.ssl
)
184 defaults
.ssl
= this.server_settings
.client
.ssl
;
186 if (this.server_settings
.client
.channel
)
187 defaults
.channel
= this.server_settings
.client
.channel
;
189 if (this.server_settings
.client
.channel_key
)
190 defaults
.channel_key
= this.server_settings
.client
.channel_key
;
196 * Get any settings passed in the URL
197 * These settings may be changed in the server selection dialog
200 // Any query parameters first
201 if (getQueryVariable('nick'))
202 defaults
.nick
= getQueryVariable('nick');
204 if (window
.location
.hash
)
205 defaults
.channel
= window
.location
.hash
;
208 // Process the URL part by part, extracting as we go
209 parts
= window
.location
.pathname
.toString().replace(this.get('base_path'), '').split('/');
211 if (parts
.length
> 0) {
214 if (parts
.length
> 0 && parts
[0]) {
215 // 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.
216 uricheck
= parts
[0].substr(0, 7).toLowerCase();
217 if ((uricheck
=== 'ircs%3a') || (uricheck
.substr(0,6) === 'irc%3a')) {
218 parts
[0] = decodeURIComponent(parts
[0]);
219 // irc[s]://<host>[:<port>]/[<channel>[?<password>]]
220 uricheck
= /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts
[0]);
222 uricheck[1] = ssl (optional)
224 uricheck[3] = port (optional)
225 uricheck[4] = channel (optional)
226 uricheck[5] = channel key (optional, channel must also be set)
229 if (typeof uricheck
[1] !== 'undefined') {
231 if (defaults
.port
=== 6667) {
232 defaults
.port
= 6697;
235 defaults
.server
= uricheck
[2];
236 if (typeof uricheck
[3] !== 'undefined') {
237 defaults
.port
= uricheck
[3];
239 if (typeof uricheck
[4] !== 'undefined') {
240 defaults
.channel
= '#' + uricheck
[4];
241 if (typeof uricheck
[5] !== 'undefined') {
242 defaults
.channel_key
= uricheck
[5];
248 // Extract the port+ssl if we find one
249 if (parts
[0].search(/:/) > 0) {
250 defaults
.port
= parts
[0].substring(parts
[0].search(/:/) + 1);
251 defaults
.server
= parts
[0].substring(0, parts
[0].search(/:/));
252 if (defaults
.port
[0] === '+') {
253 defaults
.port
= parseInt(defaults
.port
.substring(1), 10);
256 defaults
.ssl
= false;
260 defaults
.server
= parts
[0];
267 if (parts
.length
> 0 && parts
[0]) {
268 defaults
.channel
= '#' + parts
[0];
273 // If any settings have been given by the server.. override any auto detected settings
275 * Get any server restrictions as set in the server config
276 * These settings can not be changed in the server selection dialog
278 if (this.server_settings
&& this.server_settings
.connection
) {
279 if (this.server_settings
.connection
.server
) {
280 defaults
.server
= this.server_settings
.connection
.server
;
283 if (this.server_settings
.connection
.port
) {
284 defaults
.port
= this.server_settings
.connection
.port
;
287 if (this.server_settings
.connection
.ssl
) {
288 defaults
.ssl
= this.server_settings
.connection
.ssl
;
291 if (this.server_settings
.connection
.channel
) {
292 defaults
.channel
= this.server_settings
.connection
.channel
;
295 if (this.server_settings
.connection
.channel_key
) {
296 defaults
.channel_key
= this.server_settings
.connection
.channel_key
;
299 if (this.server_settings
.connection
.nick
) {
300 defaults
.nick
= this.server_settings
.connection
.nick
;
304 // Set any random numbers if needed
305 defaults
.nick
= defaults
.nick
.replace('?', Math
.floor(Math
.random() * 100000).toString());
307 if (getQueryVariable('encoding'))
308 defaults
.encoding
= getQueryVariable('encoding');
310 // Populate the server select box with defaults
311 new_connection_dialog
.view
.populateFields(defaults
);
315 this.panels
= (function() {
316 var fn = function(panel_type
) {
319 // Default panel type
320 panel_type
= panel_type
|| 'connections';
322 switch (panel_type
) {
324 panels
= this.connections
.panels();
327 panels
= this.applet_panels
.models
;
331 // Active panels / server
332 panels
.active
= this.connections
.active_panel
;
333 panels
.server
= this.connections
.active_connection
?
334 this.connections
.active_connection
.panels
.server
:
340 _
.extend(fn
, Backbone
.Events
);
346 this.bindGatewayCommands = function (gw
) {
349 gw
.on('onconnect', function (event
) {
350 that
.view
.barsShow();
355 * Handle the reconnections to the kiwi server
358 // 0 = non-reconnecting state. 1 = reconnecting state.
361 // If the current or upcoming disconnect was planned
362 var unplanned_disconnect
= false;
364 gw
.on('disconnect', function (event
) {
365 unplanned_disconnect
= !gw
.disconnect_requested
;
367 if (unplanned_disconnect
) {
368 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnecting').fetch() + '...';
369 that
.message
.text(msg
, {timeout
: 10000});
372 that
.view
.$el
.removeClass('connected');
374 // Mention the disconnection on every channel
375 _kiwi
.app
.connections
.forEach(function(connection
) {
376 connection
.panels
.server
.addMsg('', msg
, 'action quit');
378 connection
.panels
.forEach(function(panel
) {
379 if (!panel
.isChannel())
382 panel
.addMsg('', msg
, 'action quit');
390 gw
.on('reconnecting', function (event
) {
391 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_in_x_seconds').fetch(event
.delay
/1000) + '...';
393 // Only need to mention the repeating re-connection messages on server panels
394 _kiwi
.app
.connections
.forEach(function(connection
) {
395 connection
.panels
.server
.addMsg('', msg
, 'action quit');
400 gw
.on('onconnect', function (event
) {
401 that
.view
.$el
.addClass('connected');
402 if (gw_stat
!== 1) return;
404 if (unplanned_disconnect
) {
405 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_successfully').fetch() + ':)';
406 that
.message
.text(msg
, {timeout
: 5000});
409 // Mention the re-connection on every channel
410 _kiwi
.app
.connections
.forEach(function(connection
) {
411 connection
.panels
.server
.addMsg('', msg
, 'action join');
413 connection
.panels
.forEach(function(panel
) {
414 if (!panel
.isChannel())
417 panel
.addMsg('', msg
, 'action join');
426 gw
.on('kiwi:reconfig', function () {
427 $.getJSON(that
.get('settings_path'), function (data
) {
428 that
.server_settings
= data
.server_settings
|| {};
429 that
.translations
= data
.translations
|| {};
434 gw
.on('kiwi:jumpserver', function (data
) {
436 // No server set? Then nowhere to jump to.
437 if (typeof data
.kiwi_server
=== 'undefined')
440 serv
= data
.kiwi_server
;
442 // Strip any trailing slash from the end
443 if (serv
[serv
.length
-1] === '/')
444 serv
= serv
.substring(0, serv
.length
-1);
446 // Force the jumpserver now?
448 // Get an interval between 5 and 6 minutes so everyone doesn't reconnect it all at once
449 var jump_server_interval
= Math
.random() * (360 - 300) + 300;
451 // Tell the user we are going to disconnect, wait 5 minutes then do the actual reconnect
452 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_prepare').fetch();
453 that
.message
.text(msg
, {timeout
: 10000});
455 setTimeout(function forcedReconnect() {
456 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_reconnect').fetch();
457 that
.message
.text(msg
, {timeout
: 8000});
459 setTimeout(function forcedReconnectPartTwo() {
460 _kiwi
.app
.kiwi_server
= serv
;
462 _kiwi
.gateway
.reconnect(function() {
463 // Reconnect all the IRC connections
464 that
.connections
.forEach(function(con
){ con
.reconnect(); });
468 }, jump_server_interval
* 1000);
476 * Bind to certain commands that may be typed into the control box
478 this.bindControllboxCommands = function (controlbox
) {
480 $.extend(controlbox
.preprocessor
.aliases
, {
483 '/me': '/action $1+',
487 '/raw': '/quote $1+',
489 // Op related aliases
490 '/op': '/quote mode $channel +o $1+',
491 '/deop': '/quote mode $channel -o $1+',
492 '/hop': '/quote mode $channel +h $1+',
493 '/dehop': '/quote mode $channel -h $1+',
494 '/voice': '/quote mode $channel +v $1+',
495 '/devoice': '/quote mode $channel -v $1+',
496 '/k': '/kick $channel $1+',
497 '/ban': '/quote mode $channel +b $1+',
498 '/unban': '/quote mode $channel -b $1+',
501 '/slap': '/me slaps $1 around a bit with a large trout'
504 controlbox
.on('unknown_command', unknownCommand
);
506 controlbox
.on('command', allCommands
);
507 controlbox
.on('command:msg', msgCommand
);
509 controlbox
.on('command:action', actionCommand
);
511 controlbox
.on('command:join', joinCommand
);
513 controlbox
.on('command:part', partCommand
);
515 controlbox
.on('command:nick', function (ev
) {
516 _kiwi
.gateway
.changeNick(null, ev
.params
[0]);
519 controlbox
.on('command:query', queryCommand
);
521 controlbox
.on('command:invite', inviteCommand
);
523 controlbox
.on('command:topic', topicCommand
);
525 controlbox
.on('command:notice', noticeCommand
);
527 controlbox
.on('command:quote', quoteCommand
);
529 controlbox
.on('command:kick', kickCommand
);
531 controlbox
.on('command:clear', clearCommand
);
533 controlbox
.on('command:ctcp', ctcpCommand
);
535 controlbox
.on('command:server', serverCommand
);
537 controlbox
.on('command:whois', whoisCommand
);
539 controlbox
.on('command:whowas', whowasCommand
);
541 controlbox
.on('command:encoding', encodingCommand
);
543 controlbox
.on('command:info', function(ev
) {
544 var active_panel
= _kiwi
.app
.panels().active
;
546 if (!active_panel
.isChannel())
549 new _kiwi
.model
.ChannelInfo({channel
: _kiwi
.app
.panels().active
});
552 controlbox
.on('command:css', function (ev
) {
553 var queryString
= '?reload=' + new Date().getTime();
554 $('link[rel="stylesheet"]').each(function () {
555 this.href
= this.href
.replace(/\?.*|$/, queryString
);
559 controlbox
.on('command:js', function (ev
) {
560 if (!ev
.params
[0]) return;
561 $script(ev
.params
[0] + '?' + (new Date().getTime()));
565 controlbox
.on('command:set', function (ev
) {
566 if (!ev
.params
[0]) return;
568 var setting
= ev
.params
[0],
571 // Do we have a second param to set a value?
575 value
= ev
.params
.join(' ');
577 // If we're setting a true boolean value..
578 if (value
=== 'true')
581 // If we're setting a false boolean value..
582 if (value
=== 'false')
585 // If we're setting a number..
586 if (parseInt(value
, 10).toString() === value
)
587 value
= parseInt(value
, 10);
589 _kiwi
.global
.settings
.set(setting
, value
);
592 // Read the value to the user
593 _kiwi
.app
.panels().active
.addMsg('', setting
+ ' = ' + _kiwi
.global
.settings
.get(setting
).toString());
597 controlbox
.on('command:save', function (ev
) {
598 _kiwi
.global
.settings
.save();
599 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_settings_saved').fetch());
603 controlbox
.on('command:alias', function (ev
) {
606 // No parameters passed so list them
608 $.each(controlbox
.preprocessor
.aliases
, function (name
, rule
) {
609 _kiwi
.app
.panels().server
.addMsg(' ', name
+ ' => ' + rule
);
614 // Deleting an alias?
615 if (ev
.params
[0] === 'del' || ev
.params
[0] === 'delete') {
617 if (name
[0] !== '/') name
= '/' + name
;
618 delete controlbox
.preprocessor
.aliases
[name
];
625 rule
= ev
.params
.join(' ');
627 // Make sure the name starts with a slash
628 if (name
[0] !== '/') name
= '/' + name
;
630 // Now actually add the alias
631 controlbox
.preprocessor
.aliases
[name
] = rule
;
635 controlbox
.on('command:ignore', function (ev
) {
636 var list
= _kiwi
.gateway
.get('ignore_list');
638 // No parameters passed so list them
640 if (list
.length
> 0) {
641 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_title').fetch() + ':');
642 $.each(list
, function (idx
, ignored_pattern
) {
643 _kiwi
.app
.panels().active
.addMsg(' ', ignored_pattern
);
646 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_none').fetch());
651 // We have a parameter, so add it
652 list
.push(ev
.params
[0]);
653 _kiwi
.gateway
.set('ignore_list', list
);
654 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_nick').fetch(ev
.params
[0]));
658 controlbox
.on('command:unignore', function (ev
) {
659 var list
= _kiwi
.gateway
.get('ignore_list');
662 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stop_notice').fetch());
666 list
= _
.reject(list
, function(pattern
) {
667 return pattern
=== ev
.params
[0];
670 _kiwi
.gateway
.set('ignore_list', list
);
672 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stopped').fetch(ev
.params
[0]));
676 controlbox
.on('command:applet', appletCommand
);
677 controlbox
.on('command:settings', settingsCommand
);
678 controlbox
.on('command:script', scriptCommand
);
681 // A fallback action. Send a raw command to the server
682 function unknownCommand (ev
) {
683 var raw_cmd
= ev
.command
+ ' ' + ev
.params
.join(' ');
684 console
.log('RAW: ' + raw_cmd
);
685 _kiwi
.gateway
.raw(null, raw_cmd
);
688 function allCommands (ev
) {}
690 function joinCommand (ev
) {
691 var panels
, channel_names
;
693 channel_names
= ev
.params
.join(' ').split(',');
694 panels
= that
.connections
.active_connection
.createAndJoinChannels(channel_names
);
696 // Show the last channel if we have one
698 panels
[panels
.length
- 1].view
.show();
701 function queryCommand (ev
) {
702 var destination
, message
, panel
;
704 destination
= ev
.params
[0];
707 message
= ev
.params
.join(' ');
709 // Check if we have the panel already. If not, create it
710 panel
= that
.connections
.active_connection
.panels
.getByName(destination
);
712 panel
= new _kiwi
.model
.Query({name
: destination
});
713 that
.connections
.active_connection
.panels
.add(panel
);
716 if (panel
) panel
.view
.show();
719 that
.connections
.active_connection
.gateway
.msg(panel
.get('name'), message
);
720 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
725 function msgCommand (ev
) {
727 destination
= ev
.params
[0],
728 panel
= that
.connections
.active_connection
.panels
.getByName(destination
) || that
.panels().server
;
731 message
= formatToIrcMsg(ev
.params
.join(' '));
733 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
734 _kiwi
.gateway
.privmsg(null, destination
, message
);
737 function actionCommand (ev
) {
738 if (_kiwi
.app
.panels().active
.isServer()) {
742 var panel
= _kiwi
.app
.panels().active
;
743 panel
.addMsg('', '* ' + _kiwi
.app
.connections
.active_connection
.get('nick') + ' ' + ev
.params
.join(' '), 'action');
744 _kiwi
.gateway
.action(null, panel
.get('name'), ev
.params
.join(' '));
747 function partCommand (ev
) {
748 if (ev
.params
.length
=== 0) {
749 _kiwi
.gateway
.part(null, _kiwi
.app
.panels().active
.get('name'));
751 _
.each(ev
.params
, function (channel
) {
752 _kiwi
.gateway
.part(null, channel
);
757 function topicCommand (ev
) {
760 if (ev
.params
.length
=== 0) return;
762 if (that
.isChannelName(ev
.params
[0])) {
763 channel_name
= ev
.params
[0];
766 channel_name
= _kiwi
.app
.panels().active
.get('name');
769 _kiwi
.gateway
.topic(null, channel_name
, ev
.params
.join(' '));
772 function noticeCommand (ev
) {
775 // Make sure we have a destination and some sort of message
776 if (ev
.params
.length
<= 1) return;
778 destination
= ev
.params
[0];
781 _kiwi
.gateway
.notice(null, destination
, ev
.params
.join(' '));
784 function quoteCommand (ev
) {
785 var raw
= ev
.params
.join(' ');
786 _kiwi
.gateway
.raw(null, raw
);
789 function kickCommand (ev
) {
790 var nick
, panel
= _kiwi
.app
.panels().active
;
792 if (!panel
.isChannel()) return;
794 // Make sure we have a nick
795 if (ev
.params
.length
=== 0) return;
800 _kiwi
.gateway
.kick(null, panel
.get('name'), nick
, ev
.params
.join(' '));
803 function clearCommand (ev
) {
804 // Can't clear a server or applet panel
805 if (_kiwi
.app
.panels().active
.isServer() || _kiwi
.app
.panels().active
.isApplet()) {
809 if (_kiwi
.app
.panels().active
.clearMessages
) {
810 _kiwi
.app
.panels().active
.clearMessages();
814 function ctcpCommand(ev
) {
817 // Make sure we have a target and a ctcp type (eg. version, time)
818 if (ev
.params
.length
< 2) return;
820 target
= ev
.params
[0];
826 _kiwi
.gateway
.ctcp(null, true, type
, target
, ev
.params
.join(' '));
829 function settingsCommand (ev
) {
830 var settings
= _kiwi
.model
.Applet
.loadOnce('kiwi_settings');
831 settings
.view
.show();
834 function scriptCommand (ev
) {
835 var editor
= _kiwi
.model
.Applet
.loadOnce('kiwi_script_editor');
839 function appletCommand (ev
) {
840 if (!ev
.params
[0]) return;
842 var panel
= new _kiwi
.model
.Applet();
845 // Url and name given
846 panel
.load(ev
.params
[0], ev
.params
[1]);
848 // Load a pre-loaded applet
849 if (_kiwi
.applets
[ev
.params
[0]]) {
850 panel
.load(new _kiwi
.applets
[ev
.params
[0]]());
852 _kiwi
.app
.panels().server
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_applet_notfound').fetch(ev
.params
[0]));
857 _kiwi
.app
.connections
.active_connection
.panels
.add(panel
);
863 function inviteCommand (ev
) {
866 // A nick must be specified
870 // Can only invite into channels
871 if (!_kiwi
.app
.panels().active
.isChannel())
875 channel
= _kiwi
.app
.panels().active
.get('name');
877 _kiwi
.app
.connections
.active_connection
.gateway
.raw('INVITE ' + nick
+ ' ' + channel
);
879 _kiwi
.app
.panels().active
.addMsg('', '== ' + nick
+ ' has been invited to ' + channel
, 'action');
883 function whoisCommand (ev
) {
888 } else if (_kiwi
.app
.panels().active
.isQuery()) {
889 nick
= _kiwi
.app
.panels().active
.get('name');
893 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOIS ' + nick
+ ' ' + nick
);
897 function whowasCommand (ev
) {
902 } else if (_kiwi
.app
.panels().active
.isQuery()) {
903 nick
= _kiwi
.app
.panels().active
.get('name');
907 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOWAS ' + nick
);
910 function encodingCommand (ev
) {
912 _kiwi
.gateway
.setEncoding(null, ev
.params
[0], function (success
) {
914 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_changed').fetch(ev
.params
[0]));
916 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_invalid').fetch(ev
.params
[0]));
920 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_notspecified').fetch());
921 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_usage').fetch());
925 function serverCommand (ev
) {
926 var server
, port
, ssl
, password
, nick
,
929 // If no server address given, show the new connection dialog
931 tmp
= new _kiwi
.view
.MenuBox(_kiwi
.global
.i18n
.translate('client_models_application_connection_create').fetch());
932 tmp
.addItem('new_connection', new _kiwi
.model
.NewConnection().view
.$el
);
935 // Center screen the dialog
937 top
: (that
.view
.$el
.height() / 2) - (tmp
.$el
.height() / 2),
938 left
: (that
.view
.$el
.width() / 2) - (tmp
.$el
.width() / 2)
944 // Port given in 'host:port' format and no specific port given after a space
945 if (ev
.params
[0].indexOf(':') > 0) {
946 tmp
= ev
.params
[0].split(':');
950 password
= ev
.params
[1] || undefined;
953 // Server + port given as 'host port'
954 server
= ev
.params
[0];
955 port
= ev
.params
[1] || 6667;
957 password
= ev
.params
[2] || undefined;
960 // + in the port means SSL
961 if (port
.toString()[0] === '+') {
963 port
= parseInt(port
.substring(1), 10);
968 // Default port if one wasn't found
971 // Use the same nick as we currently have
972 nick
= _kiwi
.app
.connections
.active_connection
.get('nick');
974 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_connecting').fetch(server
, port
.toString()));
976 _kiwi
.gateway
.newConnection({
982 }, function(err
, new_connection
) {
984 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_error').fetch(server
, port
.toString(), err
.toString()));
992 this.isChannelName = function (channel_name
) {
993 var channel_prefix
= _kiwi
.gateway
.get('channel_prefix');
995 if (!channel_name
|| !channel_name
.length
) return false;
996 return (channel_prefix
.indexOf(channel_name
[0]) > -1);
1003 model
= Backbone
.Model
.extend(new model());
1005 return new model(arguments
);