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]});
126 new _kiwi
.view
.ChannelTools({el
: _kiwi
.app
.view
.$el
.find('.channel_tools')[0]});
128 this.message
= new _kiwi
.view
.StatusMessage({el
: this.view
.$el
.find('.status_message')[0]});
130 this.resize_handle
= new _kiwi
.view
.ResizeHandler({el
: this.view
.$el
.find('.memberlists_resize_handle')[0]});
132 // Rejigg the UI sizes
133 this.view
.doLayout();
137 this.initializeGlobals = function () {
138 _kiwi
.global
.connections
= this.connections
;
140 _kiwi
.global
.panels
= this.panels
;
141 _kiwi
.global
.panels
.applets
= this.applet_panels
;
143 _kiwi
.global
.components
.Applet
= _kiwi
.model
.Applet
;
144 _kiwi
.global
.components
.Panel
=_kiwi
.model
.Panel
;
148 this.applyDefaultClientSettings = function (settings
) {
149 _
.each(settings
, function (value
, setting
) {
150 if (typeof _kiwi
.global
.settings
.get(setting
) === 'undefined') {
151 _kiwi
.global
.settings
.set(setting
, value
);
157 this.populateDefaultServerSettings = function (new_connection_dialog
) {
171 * Get any settings set by the server
172 * These settings may be changed in the server selection dialog or via URL parameters
174 if (this.server_settings
.client
) {
175 if (this.server_settings
.client
.nick
)
176 defaults
.nick
= this.server_settings
.client
.nick
;
178 if (this.server_settings
.client
.server
)
179 defaults
.server
= this.server_settings
.client
.server
;
181 if (this.server_settings
.client
.port
)
182 defaults
.port
= this.server_settings
.client
.port
;
184 if (this.server_settings
.client
.ssl
)
185 defaults
.ssl
= this.server_settings
.client
.ssl
;
187 if (this.server_settings
.client
.channel
)
188 defaults
.channel
= this.server_settings
.client
.channel
;
190 if (this.server_settings
.client
.channel_key
)
191 defaults
.channel_key
= this.server_settings
.client
.channel_key
;
197 * Get any settings passed in the URL
198 * These settings may be changed in the server selection dialog
201 // Any query parameters first
202 if (getQueryVariable('nick'))
203 defaults
.nick
= getQueryVariable('nick');
205 if (window
.location
.hash
)
206 defaults
.channel
= window
.location
.hash
;
209 // Process the URL part by part, extracting as we go
210 parts
= window
.location
.pathname
.toString().replace(this.get('base_path'), '').split('/');
212 if (parts
.length
> 0) {
215 if (parts
.length
> 0 && parts
[0]) {
216 // 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.
217 uricheck
= parts
[0].substr(0, 7).toLowerCase();
218 if ((uricheck
=== 'ircs%3a') || (uricheck
.substr(0,6) === 'irc%3a')) {
219 parts
[0] = decodeURIComponent(parts
[0]);
220 // irc[s]://<host>[:<port>]/[<channel>[?<password>]]
221 uricheck
= /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts
[0]);
223 uricheck[1] = ssl (optional)
225 uricheck[3] = port (optional)
226 uricheck[4] = channel (optional)
227 uricheck[5] = channel key (optional, channel must also be set)
230 if (typeof uricheck
[1] !== 'undefined') {
232 if (defaults
.port
=== 6667) {
233 defaults
.port
= 6697;
236 defaults
.server
= uricheck
[2];
237 if (typeof uricheck
[3] !== 'undefined') {
238 defaults
.port
= uricheck
[3];
240 if (typeof uricheck
[4] !== 'undefined') {
241 defaults
.channel
= '#' + uricheck
[4];
242 if (typeof uricheck
[5] !== 'undefined') {
243 defaults
.channel_key
= uricheck
[5];
249 // Extract the port+ssl if we find one
250 if (parts
[0].search(/:/) > 0) {
251 defaults
.port
= parts
[0].substring(parts
[0].search(/:/) + 1);
252 defaults
.server
= parts
[0].substring(0, parts
[0].search(/:/));
253 if (defaults
.port
[0] === '+') {
254 defaults
.port
= parseInt(defaults
.port
.substring(1), 10);
257 defaults
.ssl
= false;
261 defaults
.server
= parts
[0];
268 if (parts
.length
> 0 && parts
[0]) {
269 defaults
.channel
= '#' + parts
[0];
274 // If any settings have been given by the server.. override any auto detected settings
276 * Get any server restrictions as set in the server config
277 * These settings can not be changed in the server selection dialog
279 if (this.server_settings
&& this.server_settings
.connection
) {
280 if (this.server_settings
.connection
.server
) {
281 defaults
.server
= this.server_settings
.connection
.server
;
284 if (this.server_settings
.connection
.port
) {
285 defaults
.port
= this.server_settings
.connection
.port
;
288 if (this.server_settings
.connection
.ssl
) {
289 defaults
.ssl
= this.server_settings
.connection
.ssl
;
292 if (this.server_settings
.connection
.channel
) {
293 defaults
.channel
= this.server_settings
.connection
.channel
;
296 if (this.server_settings
.connection
.channel_key
) {
297 defaults
.channel_key
= this.server_settings
.connection
.channel_key
;
300 if (this.server_settings
.connection
.nick
) {
301 defaults
.nick
= this.server_settings
.connection
.nick
;
305 // Set any random numbers if needed
306 defaults
.nick
= defaults
.nick
.replace('?', Math
.floor(Math
.random() * 100000).toString());
308 if (getQueryVariable('encoding'))
309 defaults
.encoding
= getQueryVariable('encoding');
311 // Populate the server select box with defaults
312 new_connection_dialog
.view
.populateFields(defaults
);
316 this.panels
= (function() {
317 var fn = function(panel_type
) {
320 // Default panel type
321 panel_type
= panel_type
|| 'connections';
323 switch (panel_type
) {
325 panels
= this.connections
.panels();
328 panels
= this.applet_panels
.models
;
332 // Active panels / server
333 panels
.active
= this.connections
.active_panel
;
334 panels
.server
= this.connections
.active_connection
?
335 this.connections
.active_connection
.panels
.server
:
341 _
.extend(fn
, Backbone
.Events
);
347 this.bindGatewayCommands = function (gw
) {
350 gw
.on('onconnect', function (event
) {
351 that
.view
.barsShow();
356 * Handle the reconnections to the kiwi server
359 // 0 = non-reconnecting state. 1 = reconnecting state.
362 // If the current or upcoming disconnect was planned
363 var unplanned_disconnect
= false;
365 gw
.on('disconnect', function (event
) {
366 unplanned_disconnect
= !gw
.disconnect_requested
;
368 if (unplanned_disconnect
) {
369 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnecting').fetch() + '...';
370 that
.message
.text(msg
, {timeout
: 10000});
373 that
.view
.$el
.removeClass('connected');
375 // Mention the disconnection on every channel
376 _kiwi
.app
.connections
.forEach(function(connection
) {
377 connection
.panels
.server
.addMsg('', msg
, 'action quit');
379 connection
.panels
.forEach(function(panel
) {
380 if (!panel
.isChannel())
383 panel
.addMsg('', msg
, 'action quit');
391 gw
.on('reconnecting', function (event
) {
392 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_in_x_seconds').fetch(event
.delay
/1000) + '...';
394 // Only need to mention the repeating re-connection messages on server panels
395 _kiwi
.app
.connections
.forEach(function(connection
) {
396 connection
.panels
.server
.addMsg('', msg
, 'action quit');
401 gw
.on('onconnect', function (event
) {
402 that
.view
.$el
.addClass('connected');
403 if (gw_stat
!== 1) return;
405 if (unplanned_disconnect
) {
406 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_successfully').fetch() + ':)';
407 that
.message
.text(msg
, {timeout
: 5000});
410 // Mention the re-connection on every channel
411 _kiwi
.app
.connections
.forEach(function(connection
) {
412 connection
.panels
.server
.addMsg('', msg
, 'action join');
414 connection
.panels
.forEach(function(panel
) {
415 if (!panel
.isChannel())
418 panel
.addMsg('', msg
, 'action join');
427 gw
.on('kiwi:reconfig', function () {
428 $.getJSON(that
.get('settings_path'), function (data
) {
429 that
.server_settings
= data
.server_settings
|| {};
430 that
.translations
= data
.translations
|| {};
435 gw
.on('kiwi:jumpserver', function (data
) {
437 // No server set? Then nowhere to jump to.
438 if (typeof data
.kiwi_server
=== 'undefined')
441 serv
= data
.kiwi_server
;
443 // Strip any trailing slash from the end
444 if (serv
[serv
.length
-1] === '/')
445 serv
= serv
.substring(0, serv
.length
-1);
447 // Force the jumpserver now?
449 // Get an interval between 5 and 6 minutes so everyone doesn't reconnect it all at once
450 var jump_server_interval
= Math
.random() * (360 - 300) + 300;
452 // Tell the user we are going to disconnect, wait 5 minutes then do the actual reconnect
453 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_prepare').fetch();
454 that
.message
.text(msg
, {timeout
: 10000});
456 setTimeout(function forcedReconnect() {
457 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_jumpserver_reconnect').fetch();
458 that
.message
.text(msg
, {timeout
: 8000});
460 setTimeout(function forcedReconnectPartTwo() {
461 _kiwi
.app
.kiwi_server
= serv
;
463 _kiwi
.gateway
.reconnect(function() {
464 // Reconnect all the IRC connections
465 that
.connections
.forEach(function(con
){ con
.reconnect(); });
469 }, jump_server_interval
* 1000);
477 * Bind to certain commands that may be typed into the control box
479 this.bindControllboxCommands = function (controlbox
) {
481 $.extend(controlbox
.preprocessor
.aliases
, {
484 '/me': '/action $1+',
488 '/raw': '/quote $1+',
490 // Op related aliases
491 '/op': '/quote mode $channel +o $1+',
492 '/deop': '/quote mode $channel -o $1+',
493 '/hop': '/quote mode $channel +h $1+',
494 '/dehop': '/quote mode $channel -h $1+',
495 '/voice': '/quote mode $channel +v $1+',
496 '/devoice': '/quote mode $channel -v $1+',
497 '/k': '/kick $channel $1+',
498 '/ban': '/quote mode $channel +b $1+',
499 '/unban': '/quote mode $channel -b $1+',
502 '/slap': '/me slaps $1 around a bit with a large trout'
505 controlbox
.on('unknown_command', unknownCommand
);
507 controlbox
.on('command', allCommands
);
508 controlbox
.on('command:msg', msgCommand
);
510 controlbox
.on('command:action', actionCommand
);
512 controlbox
.on('command:join', joinCommand
);
514 controlbox
.on('command:part', partCommand
);
516 controlbox
.on('command:nick', function (ev
) {
517 _kiwi
.gateway
.changeNick(null, ev
.params
[0]);
520 controlbox
.on('command:query', queryCommand
);
522 controlbox
.on('command:invite', inviteCommand
);
524 controlbox
.on('command:topic', topicCommand
);
526 controlbox
.on('command:notice', noticeCommand
);
528 controlbox
.on('command:quote', quoteCommand
);
530 controlbox
.on('command:kick', kickCommand
);
532 controlbox
.on('command:clear', clearCommand
);
534 controlbox
.on('command:ctcp', ctcpCommand
);
536 controlbox
.on('command:server', serverCommand
);
538 controlbox
.on('command:whois', whoisCommand
);
540 controlbox
.on('command:whowas', whowasCommand
);
542 controlbox
.on('command:encoding', encodingCommand
);
544 controlbox
.on('command:channel', function(ev
) {
545 var active_panel
= _kiwi
.app
.panels().active
;
547 if (!active_panel
.isChannel())
550 new _kiwi
.model
.ChannelInfo({channel
: _kiwi
.app
.panels().active
});
553 controlbox
.on('command:css', function (ev
) {
554 var queryString
= '?reload=' + new Date().getTime();
555 $('link[rel="stylesheet"]').each(function () {
556 this.href
= this.href
.replace(/\?.*|$/, queryString
);
560 controlbox
.on('command:js', function (ev
) {
561 if (!ev
.params
[0]) return;
562 $script(ev
.params
[0] + '?' + (new Date().getTime()));
566 controlbox
.on('command:set', function (ev
) {
567 if (!ev
.params
[0]) return;
569 var setting
= ev
.params
[0],
572 // Do we have a second param to set a value?
576 value
= ev
.params
.join(' ');
578 // If we're setting a true boolean value..
579 if (value
=== 'true')
582 // If we're setting a false boolean value..
583 if (value
=== 'false')
586 // If we're setting a number..
587 if (parseInt(value
, 10).toString() === value
)
588 value
= parseInt(value
, 10);
590 _kiwi
.global
.settings
.set(setting
, value
);
593 // Read the value to the user
594 _kiwi
.app
.panels().active
.addMsg('', setting
+ ' = ' + _kiwi
.global
.settings
.get(setting
).toString());
598 controlbox
.on('command:save', function (ev
) {
599 _kiwi
.global
.settings
.save();
600 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_settings_saved').fetch());
604 controlbox
.on('command:alias', function (ev
) {
607 // No parameters passed so list them
609 $.each(controlbox
.preprocessor
.aliases
, function (name
, rule
) {
610 _kiwi
.app
.panels().server
.addMsg(' ', name
+ ' => ' + rule
);
615 // Deleting an alias?
616 if (ev
.params
[0] === 'del' || ev
.params
[0] === 'delete') {
618 if (name
[0] !== '/') name
= '/' + name
;
619 delete controlbox
.preprocessor
.aliases
[name
];
626 rule
= ev
.params
.join(' ');
628 // Make sure the name starts with a slash
629 if (name
[0] !== '/') name
= '/' + name
;
631 // Now actually add the alias
632 controlbox
.preprocessor
.aliases
[name
] = rule
;
636 controlbox
.on('command:ignore', function (ev
) {
637 var list
= _kiwi
.gateway
.get('ignore_list');
639 // No parameters passed so list them
641 if (list
.length
> 0) {
642 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_title').fetch() + ':');
643 $.each(list
, function (idx
, ignored_pattern
) {
644 _kiwi
.app
.panels().active
.addMsg(' ', ignored_pattern
);
647 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_none').fetch());
652 // We have a parameter, so add it
653 list
.push(ev
.params
[0]);
654 _kiwi
.gateway
.set('ignore_list', list
);
655 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_nick').fetch(ev
.params
[0]));
659 controlbox
.on('command:unignore', function (ev
) {
660 var list
= _kiwi
.gateway
.get('ignore_list');
663 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stop_notice').fetch());
667 list
= _
.reject(list
, function(pattern
) {
668 return pattern
=== ev
.params
[0];
671 _kiwi
.gateway
.set('ignore_list', list
);
673 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stopped').fetch(ev
.params
[0]));
677 controlbox
.on('command:applet', appletCommand
);
678 controlbox
.on('command:settings', settingsCommand
);
679 controlbox
.on('command:script', scriptCommand
);
682 // A fallback action. Send a raw command to the server
683 function unknownCommand (ev
) {
684 var raw_cmd
= ev
.command
+ ' ' + ev
.params
.join(' ');
685 console
.log('RAW: ' + raw_cmd
);
686 _kiwi
.gateway
.raw(null, raw_cmd
);
689 function allCommands (ev
) {}
691 function joinCommand (ev
) {
692 var panels
, channel_names
;
694 channel_names
= ev
.params
.join(' ').split(',');
695 panels
= that
.connections
.active_connection
.createAndJoinChannels(channel_names
);
697 // Show the last channel if we have one
699 panels
[panels
.length
- 1].view
.show();
702 function queryCommand (ev
) {
703 var destination
, message
, panel
;
705 destination
= ev
.params
[0];
708 message
= ev
.params
.join(' ');
710 // Check if we have the panel already. If not, create it
711 panel
= that
.connections
.active_connection
.panels
.getByName(destination
);
713 panel
= new _kiwi
.model
.Query({name
: destination
});
714 that
.connections
.active_connection
.panels
.add(panel
);
717 if (panel
) panel
.view
.show();
720 that
.connections
.active_connection
.gateway
.msg(panel
.get('name'), message
);
721 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
726 function msgCommand (ev
) {
728 destination
= ev
.params
[0],
729 panel
= that
.connections
.active_connection
.panels
.getByName(destination
) || that
.panels().server
;
732 message
= formatToIrcMsg(ev
.params
.join(' '));
734 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), message
);
735 _kiwi
.gateway
.privmsg(null, destination
, message
);
738 function actionCommand (ev
) {
739 if (_kiwi
.app
.panels().active
.isServer()) {
743 var panel
= _kiwi
.app
.panels().active
;
744 panel
.addMsg('', '* ' + _kiwi
.app
.connections
.active_connection
.get('nick') + ' ' + ev
.params
.join(' '), 'action');
745 _kiwi
.gateway
.action(null, panel
.get('name'), ev
.params
.join(' '));
748 function partCommand (ev
) {
749 if (ev
.params
.length
=== 0) {
750 _kiwi
.gateway
.part(null, _kiwi
.app
.panels().active
.get('name'));
752 _
.each(ev
.params
, function (channel
) {
753 _kiwi
.gateway
.part(null, channel
);
758 function topicCommand (ev
) {
761 if (ev
.params
.length
=== 0) return;
763 if (that
.isChannelName(ev
.params
[0])) {
764 channel_name
= ev
.params
[0];
767 channel_name
= _kiwi
.app
.panels().active
.get('name');
770 _kiwi
.gateway
.topic(null, channel_name
, ev
.params
.join(' '));
773 function noticeCommand (ev
) {
776 // Make sure we have a destination and some sort of message
777 if (ev
.params
.length
<= 1) return;
779 destination
= ev
.params
[0];
782 _kiwi
.gateway
.notice(null, destination
, ev
.params
.join(' '));
785 function quoteCommand (ev
) {
786 var raw
= ev
.params
.join(' ');
787 _kiwi
.gateway
.raw(null, raw
);
790 function kickCommand (ev
) {
791 var nick
, panel
= _kiwi
.app
.panels().active
;
793 if (!panel
.isChannel()) return;
795 // Make sure we have a nick
796 if (ev
.params
.length
=== 0) return;
801 _kiwi
.gateway
.kick(null, panel
.get('name'), nick
, ev
.params
.join(' '));
804 function clearCommand (ev
) {
805 // Can't clear a server or applet panel
806 if (_kiwi
.app
.panels().active
.isServer() || _kiwi
.app
.panels().active
.isApplet()) {
810 if (_kiwi
.app
.panels().active
.clearMessages
) {
811 _kiwi
.app
.panels().active
.clearMessages();
815 function ctcpCommand(ev
) {
818 // Make sure we have a target and a ctcp type (eg. version, time)
819 if (ev
.params
.length
< 2) return;
821 target
= ev
.params
[0];
827 _kiwi
.gateway
.ctcp(null, true, type
, target
, ev
.params
.join(' '));
830 function settingsCommand (ev
) {
831 var settings
= _kiwi
.model
.Applet
.loadOnce('kiwi_settings');
832 settings
.view
.show();
835 function scriptCommand (ev
) {
836 var editor
= _kiwi
.model
.Applet
.loadOnce('kiwi_script_editor');
840 function appletCommand (ev
) {
841 if (!ev
.params
[0]) return;
843 var panel
= new _kiwi
.model
.Applet();
846 // Url and name given
847 panel
.load(ev
.params
[0], ev
.params
[1]);
849 // Load a pre-loaded applet
850 if (_kiwi
.applets
[ev
.params
[0]]) {
851 panel
.load(new _kiwi
.applets
[ev
.params
[0]]());
853 _kiwi
.app
.panels().server
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_applet_notfound').fetch(ev
.params
[0]));
858 _kiwi
.app
.connections
.active_connection
.panels
.add(panel
);
864 function inviteCommand (ev
) {
867 // A nick must be specified
871 // Can only invite into channels
872 if (!_kiwi
.app
.panels().active
.isChannel())
876 channel
= _kiwi
.app
.panels().active
.get('name');
878 _kiwi
.app
.connections
.active_connection
.gateway
.raw('INVITE ' + nick
+ ' ' + channel
);
880 _kiwi
.app
.panels().active
.addMsg('', '== ' + nick
+ ' has been invited to ' + channel
, 'action');
884 function whoisCommand (ev
) {
889 } else if (_kiwi
.app
.panels().active
.isQuery()) {
890 nick
= _kiwi
.app
.panels().active
.get('name');
894 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOIS ' + nick
+ ' ' + nick
);
898 function whowasCommand (ev
) {
903 } else if (_kiwi
.app
.panels().active
.isQuery()) {
904 nick
= _kiwi
.app
.panels().active
.get('name');
908 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOWAS ' + nick
);
911 function encodingCommand (ev
) {
913 _kiwi
.gateway
.setEncoding(null, ev
.params
[0], function (success
) {
915 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_changed').fetch(ev
.params
[0]));
917 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_invalid').fetch(ev
.params
[0]));
921 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_notspecified').fetch());
922 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_usage').fetch());
926 function serverCommand (ev
) {
927 var server
, port
, ssl
, password
, nick
,
930 // If no server address given, show the new connection dialog
932 tmp
= new _kiwi
.view
.MenuBox(_kiwi
.global
.i18n
.translate('client_models_application_connection_create').fetch());
933 tmp
.addItem('new_connection', new _kiwi
.model
.NewConnection().view
.$el
);
936 // Center screen the dialog
938 top
: (that
.view
.$el
.height() / 2) - (tmp
.$el
.height() / 2),
939 left
: (that
.view
.$el
.width() / 2) - (tmp
.$el
.width() / 2)
945 // Port given in 'host:port' format and no specific port given after a space
946 if (ev
.params
[0].indexOf(':') > 0) {
947 tmp
= ev
.params
[0].split(':');
951 password
= ev
.params
[1] || undefined;
954 // Server + port given as 'host port'
955 server
= ev
.params
[0];
956 port
= ev
.params
[1] || 6667;
958 password
= ev
.params
[2] || undefined;
961 // + in the port means SSL
962 if (port
.toString()[0] === '+') {
964 port
= parseInt(port
.substring(1), 10);
969 // Default port if one wasn't found
972 // Use the same nick as we currently have
973 nick
= _kiwi
.app
.connections
.active_connection
.get('nick');
975 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_connecting').fetch(server
, port
.toString()));
977 _kiwi
.gateway
.newConnection({
983 }, function(err
, new_connection
) {
985 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_error').fetch(server
, port
.toString(), err
.toString()));
993 this.isChannelName = function (channel_name
) {
994 var channel_prefix
= _kiwi
.gateway
.get('channel_prefix');
996 if (!channel_name
|| !channel_name
.length
) return false;
997 return (channel_prefix
.indexOf(channel_name
[0]) > -1);
1004 model
= Backbone
.Model
.extend(new model());
1006 return new model(arguments
);