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 this.panel_access
= new Array();
133 // Rejigg the UI sizes
134 this.view
.doLayout();
138 this.initializeGlobals = function () {
139 _kiwi
.global
.connections
= this.connections
;
141 _kiwi
.global
.panels
= this.panels
;
142 _kiwi
.global
.panels
.applets
= this.applet_panels
;
144 _kiwi
.global
.components
.Applet
= _kiwi
.model
.Applet
;
145 _kiwi
.global
.components
.Panel
=_kiwi
.model
.Panel
;
149 this.applyDefaultClientSettings = function (settings
) {
150 _
.each(settings
, function (value
, setting
) {
151 if (typeof _kiwi
.global
.settings
.get(setting
) === 'undefined') {
152 _kiwi
.global
.settings
.set(setting
, value
);
158 this.populateDefaultServerSettings = function (new_connection_dialog
) {
172 * Get any settings set by the server
173 * These settings may be changed in the server selection dialog or via URL parameters
175 if (this.server_settings
.client
) {
176 if (this.server_settings
.client
.nick
)
177 defaults
.nick
= this.server_settings
.client
.nick
;
179 if (this.server_settings
.client
.server
)
180 defaults
.server
= this.server_settings
.client
.server
;
182 if (this.server_settings
.client
.port
)
183 defaults
.port
= this.server_settings
.client
.port
;
185 if (this.server_settings
.client
.ssl
)
186 defaults
.ssl
= this.server_settings
.client
.ssl
;
188 if (this.server_settings
.client
.channel
)
189 defaults
.channel
= this.server_settings
.client
.channel
;
191 if (this.server_settings
.client
.channel_key
)
192 defaults
.channel_key
= this.server_settings
.client
.channel_key
;
198 * Get any settings passed in the URL
199 * These settings may be changed in the server selection dialog
202 // Any query parameters first
203 if (getQueryVariable('nick'))
204 defaults
.nick
= getQueryVariable('nick');
206 if (window
.location
.hash
)
207 defaults
.channel
= window
.location
.hash
;
210 // Process the URL part by part, extracting as we go
211 parts
= window
.location
.pathname
.toString().replace(this.get('base_path'), '').split('/');
213 if (parts
.length
> 0) {
216 if (parts
.length
> 0 && parts
[0]) {
217 // 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.
218 uricheck
= parts
[0].substr(0, 7).toLowerCase();
219 if ((uricheck
=== 'ircs%3a') || (uricheck
.substr(0,6) === 'irc%3a')) {
220 parts
[0] = decodeURIComponent(parts
[0]);
221 // irc[s]://<host>[:<port>]/[<channel>[?<password>]]
222 uricheck
= /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts
[0]);
224 uricheck[1] = ssl (optional)
226 uricheck[3] = port (optional)
227 uricheck[4] = channel (optional)
228 uricheck[5] = channel key (optional, channel must also be set)
231 if (typeof uricheck
[1] !== 'undefined') {
233 if (defaults
.port
=== 6667) {
234 defaults
.port
= 6697;
237 defaults
.server
= uricheck
[2];
238 if (typeof uricheck
[3] !== 'undefined') {
239 defaults
.port
= uricheck
[3];
241 if (typeof uricheck
[4] !== 'undefined') {
242 defaults
.channel
= '#' + uricheck
[4];
243 if (typeof uricheck
[5] !== 'undefined') {
244 defaults
.channel_key
= uricheck
[5];
250 // Extract the port+ssl if we find one
251 if (parts
[0].search(/:/) > 0) {
252 defaults
.port
= parts
[0].substring(parts
[0].search(/:/) + 1);
253 defaults
.server
= parts
[0].substring(0, parts
[0].search(/:/));
254 if (defaults
.port
[0] === '+') {
255 defaults
.port
= parseInt(defaults
.port
.substring(1), 10);
258 defaults
.ssl
= false;
262 defaults
.server
= parts
[0];
269 if (parts
.length
> 0 && parts
[0]) {
270 defaults
.channel
= '#' + parts
[0];
275 // If any settings have been given by the server.. override any auto detected settings
277 * Get any server restrictions as set in the server config
278 * These settings can not be changed in the server selection dialog
280 if (this.server_settings
&& this.server_settings
.connection
) {
281 if (this.server_settings
.connection
.server
) {
282 defaults
.server
= this.server_settings
.connection
.server
;
285 if (this.server_settings
.connection
.port
) {
286 defaults
.port
= this.server_settings
.connection
.port
;
289 if (this.server_settings
.connection
.ssl
) {
290 defaults
.ssl
= this.server_settings
.connection
.ssl
;
293 if (this.server_settings
.connection
.channel
) {
294 defaults
.channel
= this.server_settings
.connection
.channel
;
297 if (this.server_settings
.connection
.channel_key
) {
298 defaults
.channel_key
= this.server_settings
.connection
.channel_key
;
301 if (this.server_settings
.connection
.nick
) {
302 defaults
.nick
= this.server_settings
.connection
.nick
;
306 // Set any random numbers if needed
307 defaults
.nick
= defaults
.nick
.replace('?', Math
.floor(Math
.random() * 100000).toString());
309 if (getQueryVariable('encoding'))
310 defaults
.encoding
= getQueryVariable('encoding');
312 // Populate the server select box with defaults
313 new_connection_dialog
.view
.populateFields(defaults
);
317 this.panels
= (function() {
318 var fn = function(panel_type
) {
321 // Default panel type
322 panel_type
= panel_type
|| 'connections';
324 switch (panel_type
) {
326 panels
= this.connections
.panels();
329 panels
= this.applet_panels
.models
;
333 // Active panels / server
334 panels
.active
= this.connections
.active_panel
;
335 panels
.server
= this.connections
.active_connection
?
336 this.connections
.active_connection
.panels
.server
:
342 _
.extend(fn
, Backbone
.Events
);
348 this.bindGatewayCommands = function (gw
) {
351 gw
.on('onconnect', function (event
) {
352 that
.view
.barsShow();
357 * Handle the reconnections to the kiwi server
360 // 0 = non-reconnecting state. 1 = reconnecting state.
363 // If the current or upcoming disconnect was planned
364 var unplanned_disconnect
= false;
366 gw
.on('disconnect', function (event
) {
367 unplanned_disconnect
= !gw
.disconnect_requested
;
369 if (unplanned_disconnect
) {
370 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnecting').fetch() + '...';
371 that
.message
.text(msg
, {timeout
: 10000});
374 that
.view
.$el
.removeClass('connected');
376 // Mention the disconnection on every channel
377 _kiwi
.app
.connections
.forEach(function(connection
) {
378 connection
.panels
.server
.addMsg('', msg
, 'action quit');
380 connection
.panels
.forEach(function(panel
) {
381 if (!panel
.isChannel())
384 panel
.addMsg('', msg
, 'action quit');
392 gw
.on('reconnecting', function (event
) {
393 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_in_x_seconds').fetch(event
.delay
/1000) + '...';
395 // Only need to mention the repeating re-connection messages on server panels
396 _kiwi
.app
.connections
.forEach(function(connection
) {
397 connection
.panels
.server
.addMsg('', msg
, 'action quit');
402 gw
.on('onconnect', function (event
) {
403 that
.view
.$el
.addClass('connected');
404 if (gw_stat
!== 1) return;
406 if (unplanned_disconnect
) {
407 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_successfully').fetch() + ':)';
408 that
.message
.text(msg
, {timeout
: 5000});
411 // Mention the re-connection on every channel
412 _kiwi
.app
.connections
.forEach(function(connection
) {
413 connection
.panels
.server
.addMsg('', msg
, 'action join');
415 connection
.panels
.forEach(function(panel
) {
416 if (!panel
.isChannel())
419 panel
.addMsg('', msg
, 'action join');
428 gw
.on('kiwi:reconfig', function () {
429 $.getJSON(that
.get('settings_path'), function (data
) {
430 that
.server_settings
= data
.server_settings
|| {};
431 that
.translations
= data
.translations
|| {};
436 gw
.on('kiwi:jumpserver', function (data
) {
438 // No server set? Then nowhere to jump to.
439 if (typeof data
.kiwi_server
=== 'undefined')
442 serv
= data
.kiwi_server
;
444 // Strip any trailing slash from the end
445 if (serv
[serv
.length
-1] === '/')
446 serv
= serv
.substring(0, serv
.length
-1);
448 // Force the jumpserver now?
450 // Get an interval between 5 and 6 minutes so everyone doesn't reconnect it all at once
451 var jump_server_interval
= Math
.random() * (360 - 300) + 300;
453 // Tell the user we are going to disconnect, wait 5 minutes then do the actual reconnect
454 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_prepare').fetch();
455 that
.message
.text(msg
, {timeout
: 10000});
457 setTimeout(function forcedReconnect() {
458 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_reconnect').fetch();
459 that
.message
.text(msg
, {timeout
: 8000});
461 setTimeout(function forcedReconnectPartTwo() {
462 _kiwi
.app
.kiwi_server
= serv
;
464 _kiwi
.gateway
.reconnect(function() {
465 // Reconnect all the IRC connections
466 that
.connections
.forEach(function(con
){ con
.reconnect(); });
470 }, jump_server_interval
* 1000);
478 * Bind to certain commands that may be typed into the control box
480 this.bindControllboxCommands = function (controlbox
) {
482 $.extend(controlbox
.preprocessor
.aliases
, {
485 '/me': '/action $1+',
489 '/raw': '/quote $1+',
491 // Op related aliases
492 '/op': '/quote mode $channel +o $1+',
493 '/deop': '/quote mode $channel -o $1+',
494 '/hop': '/quote mode $channel +h $1+',
495 '/dehop': '/quote mode $channel -h $1+',
496 '/voice': '/quote mode $channel +v $1+',
497 '/devoice': '/quote mode $channel -v $1+',
498 '/k': '/kick $channel $1+',
499 '/ban': '/quote mode $channel +b $1+',
500 '/unban': '/quote mode $channel -b $1+',
503 '/slap': '/me slaps $1 around a bit with a large trout'
506 controlbox
.on('unknown_command', unknownCommand
);
508 controlbox
.on('command', allCommands
);
509 controlbox
.on('command:msg', msgCommand
);
511 controlbox
.on('command:action', actionCommand
);
513 controlbox
.on('command:join', joinCommand
);
515 controlbox
.on('command:part', partCommand
);
517 controlbox
.on('command:nick', function (ev
) {
518 _kiwi
.gateway
.changeNick(null, ev
.params
[0]);
521 controlbox
.on('command:query', queryCommand
);
523 controlbox
.on('command:invite', inviteCommand
);
525 controlbox
.on('command:topic', topicCommand
);
527 controlbox
.on('command:notice', noticeCommand
);
529 controlbox
.on('command:quote', quoteCommand
);
531 controlbox
.on('command:kick', kickCommand
);
533 controlbox
.on('command:clear', clearCommand
);
535 controlbox
.on('command:ctcp', ctcpCommand
);
537 controlbox
.on('command:server', serverCommand
);
539 controlbox
.on('command:whois', whoisCommand
);
541 controlbox
.on('command:whowas', whowasCommand
);
543 controlbox
.on('command:encoding', encodingCommand
);
545 controlbox
.on('command:info', function(ev
) {
546 var active_panel
= _kiwi
.app
.panels().active
;
548 if (!active_panel
.isChannel())
551 new _kiwi
.model
.ChannelInfo({channel
: _kiwi
.app
.panels().active
});
554 controlbox
.on('command:css', function (ev
) {
555 var queryString
= '?reload=' + new Date().getTime();
556 $('link[rel="stylesheet"]').each(function () {
557 this.href
= this.href
.replace(/\?.*|$/, queryString
);
561 controlbox
.on('command:js', function (ev
) {
562 if (!ev
.params
[0]) return;
563 $script(ev
.params
[0] + '?' + (new Date().getTime()));
567 controlbox
.on('command:set', function (ev
) {
568 if (!ev
.params
[0]) return;
570 var setting
= ev
.params
[0],
573 // Do we have a second param to set a value?
577 value
= ev
.params
.join(' ');
579 // If we're setting a true boolean value..
580 if (value
=== 'true')
583 // If we're setting a false boolean value..
584 if (value
=== 'false')
587 // If we're setting a number..
588 if (parseInt(value
, 10).toString() === value
)
589 value
= parseInt(value
, 10);
591 _kiwi
.global
.settings
.set(setting
, value
);
594 // Read the value to the user
595 _kiwi
.app
.panels().active
.addMsg('', setting
+ ' = ' + _kiwi
.global
.settings
.get(setting
).toString());
599 controlbox
.on('command:save', function (ev
) {
600 _kiwi
.global
.settings
.save();
601 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_settings_saved').fetch());
605 controlbox
.on('command:alias', function (ev
) {
608 // No parameters passed so list them
610 $.each(controlbox
.preprocessor
.aliases
, function (name
, rule
) {
611 _kiwi
.app
.panels().server
.addMsg(' ', name
+ ' => ' + rule
);
616 // Deleting an alias?
617 if (ev
.params
[0] === 'del' || ev
.params
[0] === 'delete') {
619 if (name
[0] !== '/') name
= '/' + name
;
620 delete controlbox
.preprocessor
.aliases
[name
];
627 rule
= ev
.params
.join(' ');
629 // Make sure the name starts with a slash
630 if (name
[0] !== '/') name
= '/' + name
;
632 // Now actually add the alias
633 controlbox
.preprocessor
.aliases
[name
] = rule
;
637 controlbox
.on('command:ignore', function (ev
) {
638 var list
= _kiwi
.gateway
.get('ignore_list');
640 // No parameters passed so list them
642 if (list
.length
> 0) {
643 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_title').fetch() + ':');
644 $.each(list
, function (idx
, ignored_pattern
) {
645 _kiwi
.app
.panels().active
.addMsg(' ', ignored_pattern
);
648 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_none').fetch());
653 // We have a parameter, so add it
654 list
.push(ev
.params
[0]);
655 _kiwi
.gateway
.set('ignore_list', list
);
656 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_nick').fetch(ev
.params
[0]));
660 controlbox
.on('command:unignore', function (ev
) {
661 var list
= _kiwi
.gateway
.get('ignore_list');
664 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stop_notice').fetch());
668 list
= _
.reject(list
, function(pattern
) {
669 return pattern
=== ev
.params
[0];
672 _kiwi
.gateway
.set('ignore_list', list
);
674 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stopped').fetch(ev
.params
[0]));
678 controlbox
.on('command:applet', appletCommand
);
679 controlbox
.on('command:settings', settingsCommand
);
680 controlbox
.on('command:script', scriptCommand
);
683 // A fallback action. Send a raw command to the server
684 function unknownCommand (ev
) {
685 var raw_cmd
= ev
.command
+ ' ' + ev
.params
.join(' ');
686 console
.log('RAW: ' + raw_cmd
);
687 _kiwi
.gateway
.raw(null, raw_cmd
);
690 function allCommands (ev
) {}
692 function joinCommand (ev
) {
693 var panels
, channel_names
;
695 channel_names
= ev
.params
.join(' ').split(',');
696 panels
= that
.connections
.active_connection
.createAndJoinChannels(channel_names
);
698 // Show the last channel if we have one
700 panels
[panels
.length
- 1].view
.show();
703 function queryCommand (ev
) {
704 var destination
, message
, panel
;
706 destination
= ev
.params
[0];
709 message
= ev
.params
.join(' ');
711 // Check if we have the panel already. If not, create it
712 panel
= that
.connections
.active_connection
.panels
.getByName(destination
);
714 panel
= new _kiwi
.model
.Query({name
: destination
});
715 that
.connections
.active_connection
.panels
.add(panel
);
718 if (panel
) panel
.view
.show();
721 that
.connections
.active_connection
.gateway
.msg(panel
.get('name'), message
);
722 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
727 function msgCommand (ev
) {
729 destination
= ev
.params
[0],
730 panel
= that
.connections
.active_connection
.panels
.getByName(destination
) || that
.panels().server
;
733 message
= formatToIrcMsg(ev
.params
.join(' '));
735 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
736 _kiwi
.gateway
.privmsg(null, destination
, message
);
739 function actionCommand (ev
) {
740 if (_kiwi
.app
.panels().active
.isServer()) {
744 var panel
= _kiwi
.app
.panels().active
;
745 panel
.addMsg('', '* ' + _kiwi
.app
.connections
.active_connection
.get('nick') + ' ' + ev
.params
.join(' '), 'action');
746 _kiwi
.gateway
.action(null, panel
.get('name'), ev
.params
.join(' '));
749 function partCommand (ev
) {
750 if (ev
.params
.length
=== 0) {
751 _kiwi
.gateway
.part(null, _kiwi
.app
.panels().active
.get('name'));
753 _
.each(ev
.params
, function (channel
) {
754 _kiwi
.gateway
.part(null, channel
);
759 function topicCommand (ev
) {
762 if (ev
.params
.length
=== 0) return;
764 if (that
.isChannelName(ev
.params
[0])) {
765 channel_name
= ev
.params
[0];
768 channel_name
= _kiwi
.app
.panels().active
.get('name');
771 _kiwi
.gateway
.topic(null, 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 _kiwi
.gateway
.notice(null, destination
, ev
.params
.join(' '));
786 function quoteCommand (ev
) {
787 var raw
= ev
.params
.join(' ');
788 _kiwi
.gateway
.raw(null, 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 _kiwi
.gateway
.kick(null, 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 _kiwi
.gateway
.ctcp(null, 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 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
: (that
.view
.$el
.height() / 2) - (tmp
.$el
.height() / 2),
940 left
: (that
.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()));
994 this.isChannelName = function (channel_name
) {
995 var channel_prefix
= _kiwi
.gateway
.get('channel_prefix');
997 if (!channel_name
|| !channel_name
.length
) return false;
998 return (channel_prefix
.indexOf(channel_name
[0]) > -1);
1005 model
= Backbone
.Model
.extend(new model());
1007 return new model(arguments
);