cb804d453f50e7e491ab4937f370fa8314ef1e1c
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 // Any options sent down from the server
27 this.server_settings
= options
[0].server_settings
|| {};
28 this.translations
= options
[0].translations
|| {};
30 // Best guess at where the kiwi server is
31 this.detectKiwiServer();
33 // Takes instances of model_network
34 this.connections
= new _kiwi
.model
.NetworkPanelList();
36 // Set any default settings before anything else is applied
37 if (this.server_settings
&& this.server_settings
.client
&& this.server_settings
.client
.settings
) {
38 this.applyDefaultClientSettings(this.server_settings
.client
.settings
);
43 this.start = function () {
44 // Only debug if set in the querystring
45 if (!getQueryVariable('debug')) {
52 _kiwi
.gateway
= new _kiwi
.model
.Gateway();
53 this.bindGatewayCommands(_kiwi
.gateway
);
55 this.initializeClient();
56 this.initializeGlobals();
58 this.view
.barsHide(true);
60 this.showIntialConenctionDialog();
64 this.detectKiwiServer = function () {
65 // If running from file, default to localhost:7777 by default
66 if (window
.location
.protocol
=== 'file:') {
67 this.kiwi_server
= 'http://localhost:7778';
69 // Assume the kiwi server is on the same server
70 this.kiwi_server
= window
.location
.protocol
+ '//' + window
.location
.host
;
75 this.showIntialConenctionDialog = function() {
76 var connection_dialog
= new _kiwi
.model
.NewConnection();
77 this.populateDefaultServerSettings(connection_dialog
);
79 connection_dialog
.view
.$el
.addClass('initial');
80 this.view
.$el
.find('.panel_container:first').append(connection_dialog
.view
.$el
);
82 var $info
= $($('#tmpl_new_connection_info').html().trim());
85 connection_dialog
.view
.infoBoxSet($info
);
86 connection_dialog
.view
.infoBoxShow();
89 // TODO: Shouldn't really be here but it's not working in the view.. :/
90 // Hack for firefox browers: Focus is not given on this event loop iteration
91 setTimeout(function(){
92 connection_dialog
.view
.$el
.find('.nick').select();
95 // Once connected, close this dialog and remove its own event
97 connection_dialog
.view
.$el
.slideUp(function() {
98 connection_dialog
.view
.dispose();
99 connection_dialog
= null;
101 _kiwi
.gateway
.off('onconnect', fn
);
105 _kiwi
.gateway
.on('onconnect', fn
);
109 this.initializeClient = function () {
110 this.view
= new _kiwi
.view
.Application({model
: this, el
: this.get('container')});
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 // Populate the server select box with defaults
308 new_connection_dialog
.view
.populateFields(defaults
);
312 this.panels
= (function() {
313 var fn = function(panel_type
) {
316 // Default panel type
317 panel_type
= panel_type
|| 'connections';
319 switch (panel_type
) {
321 panels
= this.connections
.panels();
324 panels
= this.applet_panels
.models
;
328 // Active panels / server
329 panels
.active
= this.connections
.active_panel
;
330 panels
.server
= this.connections
.active_connection
?
331 this.connections
.active_connection
.panels
.server
:
337 _
.extend(fn
, Backbone
.Events
);
343 this.bindGatewayCommands = function (gw
) {
346 gw
.on('onconnect', function (event
) {
347 that
.view
.barsShow();
352 * Handle the reconnections to the kiwi server
356 var unplanned_disconnect
= false;
358 gw
.on('disconnect', function (event
) {
359 unplanned_disconnect
= !gw
.disconnect_requested
;
361 if (unplanned_disconnect
) {
362 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnecting').fetch() + '...';
363 that
.message
.text(msg
, {timeout
: 10000});
366 that
.view
.$el
.removeClass('connected');
368 // Mention the disconnection on every channel
369 _kiwi
.app
.connections
.forEach(function(connection
) {
370 connection
.panels
.server
.addMsg('', msg
, 'action quit');
372 connection
.panels
.forEach(function(panel
) {
373 if (!panel
.isChannel())
376 panel
.addMsg('', msg
, 'action quit');
384 gw
.on('reconnecting', function (event
) {
385 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_in_x_seconds').fetch(event
.delay
/1000) + '...';
387 // Only need to mention the repeating re-connection messages on server panels
388 _kiwi
.app
.connections
.forEach(function(connection
) {
389 connection
.panels
.server
.addMsg('', msg
, 'action quit');
394 gw
.on('onconnect', function (event
) {
395 that
.view
.$el
.addClass('connected');
396 if (gw_stat
!== 1) return;
398 if (unplanned_disconnect
) {
399 var msg
= _kiwi
.global
.i18n
.translate('client_models_application_reconnect_successfully').fetch() + ':)';
400 that
.message
.text(msg
, {timeout
: 5000});
403 // Mention the disconnection on every channel
404 _kiwi
.app
.connections
.forEach(function(connection
) {
405 connection
.panels
.server
.addMsg('', msg
, 'action join');
407 connection
.panels
.forEach(function(panel
) {
408 if (!panel
.isChannel())
411 panel
.addMsg('', msg
, 'action join');
420 gw
.on('kiwi:reconfig', function () {
421 $.getJSON(that
.get('base_path') + '/assets/settings.json', function (data
) {
422 that
.server_settings
= data
.server_settings
|| {};
423 that
.translations
= data
.translations
|| {};
428 gw
.on('kiwi:jumpserver', function (data
) {
429 // Switching kiwi server?
430 if (typeof data
.kiwi_server
!== 'undefined') {
431 _kiwi
.app
.kiwi_server
= data
.kiwi_server
;
432 _kiwi
.gateway
.set('kiwi_server', data
.kiwi_server
);
435 // Force the jumpserver now?
437 // Get an interval around 1 minute so everyone doesn't reconnect it all at once
438 var jump_server_interval
= Math
.random() * (90 - 60) + 60;
440 var msg
= 'In 1 minutes time you will be reconnected to a more stable server. Get ready!';
441 that
.message
.text(msg
, {timeout
: 10000});
443 setTimeout(function forcedReconnect() {
444 var msg
= 'Safely reconnecting you now..';
445 that
.message
.text(msg
, {timeout
: 8000});
447 setTimeout(function forcedReconnectPartTwo() {
448 _kiwi
.gateway
.reconnect();
451 }, jump_server_interval
* 1000);
459 * Bind to certain commands that may be typed into the control box
461 this.bindControllboxCommands = function (controlbox
) {
463 $.extend(controlbox
.preprocessor
.aliases
, {
466 '/me': '/action $1+',
470 '/raw': '/quote $1+',
472 // Op related aliases
473 '/op': '/quote mode $channel +o $1+',
474 '/deop': '/quote mode $channel -o $1+',
475 '/hop': '/quote mode $channel +h $1+',
476 '/dehop': '/quote mode $channel -h $1+',
477 '/voice': '/quote mode $channel +v $1+',
478 '/devoice': '/quote mode $channel -v $1+',
479 '/k': '/kick $channel $1+',
482 '/slap': '/me slaps $1 around a bit with a large trout'
485 controlbox
.on('unknown_command', unknownCommand
);
487 controlbox
.on('command', allCommands
);
488 controlbox
.on('command:msg', msgCommand
);
490 controlbox
.on('command:action', actionCommand
);
492 controlbox
.on('command:join', joinCommand
);
494 controlbox
.on('command:part', partCommand
);
496 controlbox
.on('command:nick', function (ev
) {
497 _kiwi
.gateway
.changeNick(null, ev
.params
[0]);
500 controlbox
.on('command:query', queryCommand
);
502 controlbox
.on('command:invite', inviteCommand
);
504 controlbox
.on('command:topic', topicCommand
);
506 controlbox
.on('command:notice', noticeCommand
);
508 controlbox
.on('command:quote', quoteCommand
);
510 controlbox
.on('command:kick', kickCommand
);
512 controlbox
.on('command:clear', clearCommand
);
514 controlbox
.on('command:ctcp', ctcpCommand
);
516 controlbox
.on('command:server', serverCommand
);
518 controlbox
.on('command:whois', whoisCommand
);
520 controlbox
.on('command:whowas', whowasCommand
);
522 controlbox
.on('command:encoding', encodingCommand
);
524 controlbox
.on('command:css', function (ev
) {
525 var queryString
= '?reload=' + new Date().getTime();
526 $('link[rel="stylesheet"]').each(function () {
527 this.href
= this.href
.replace(/\?.*|$/, queryString
);
531 controlbox
.on('command:js', function (ev
) {
532 if (!ev
.params
[0]) return;
533 $script(ev
.params
[0] + '?' + (new Date().getTime()));
537 controlbox
.on('command:set', function (ev
) {
538 if (!ev
.params
[0]) return;
540 var setting
= ev
.params
[0],
543 // Do we have a second param to set a value?
547 value
= ev
.params
.join(' ');
549 // If we're setting a true boolean value..
550 if (value
=== 'true')
553 // If we're setting a false boolean value..
554 if (value
=== 'false')
557 // If we're setting a number..
558 if (parseInt(value
, 10).toString() === value
)
559 value
= parseInt(value
, 10);
561 _kiwi
.global
.settings
.set(setting
, value
);
564 // Read the value to the user
565 _kiwi
.app
.panels().active
.addMsg('', setting
+ ' = ' + _kiwi
.global
.settings
.get(setting
).toString());
569 controlbox
.on('command:save', function (ev
) {
570 _kiwi
.global
.settings
.save();
571 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_settings_saved').fetch());
575 controlbox
.on('command:alias', function (ev
) {
578 // No parameters passed so list them
580 $.each(controlbox
.preprocessor
.aliases
, function (name
, rule
) {
581 _kiwi
.app
.panels().server
.addMsg(' ', name
+ ' => ' + rule
);
586 // Deleting an alias?
587 if (ev
.params
[0] === 'del' || ev
.params
[0] === 'delete') {
589 if (name
[0] !== '/') name
= '/' + name
;
590 delete controlbox
.preprocessor
.aliases
[name
];
597 rule
= ev
.params
.join(' ');
599 // Make sure the name starts with a slash
600 if (name
[0] !== '/') name
= '/' + name
;
602 // Now actually add the alias
603 controlbox
.preprocessor
.aliases
[name
] = rule
;
607 controlbox
.on('command:ignore', function (ev
) {
608 var list
= _kiwi
.gateway
.get('ignore_list');
610 // No parameters passed so list them
612 if (list
.length
> 0) {
613 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_title').fetch() + ':');
614 $.each(list
, function (idx
, ignored_pattern
) {
615 _kiwi
.app
.panels().active
.addMsg(' ', ignored_pattern
);
618 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_none').fetch());
623 // We have a parameter, so add it
624 list
.push(ev
.params
[0]);
625 _kiwi
.gateway
.set('ignore_list', list
);
626 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_nick').fetch(ev
.params
[0]));
630 controlbox
.on('command:unignore', function (ev
) {
631 var list
= _kiwi
.gateway
.get('ignore_list');
634 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stop_notice').fetch());
638 list
= _
.reject(list
, function(pattern
) {
639 return pattern
=== ev
.params
[0];
642 _kiwi
.gateway
.set('ignore_list', list
);
644 _kiwi
.app
.panels().active
.addMsg(' ', _kiwi
.global
.i18n
.translate('client_models_application_ignore_stopped').fetch(ev
.params
[0]));
648 controlbox
.on('command:applet', appletCommand
);
649 controlbox
.on('command:settings', settingsCommand
);
650 controlbox
.on('command:script', scriptCommand
);
653 // A fallback action. Send a raw command to the server
654 function unknownCommand (ev
) {
655 var raw_cmd
= ev
.command
+ ' ' + ev
.params
.join(' ');
656 console
.log('RAW: ' + raw_cmd
);
657 _kiwi
.gateway
.raw(null, raw_cmd
);
660 function allCommands (ev
) {}
662 function joinCommand (ev
) {
663 var panels
, channel_names
;
665 channel_names
= ev
.params
.join(' ').split(',');
666 panels
= that
.connections
.active_connection
.createAndJoinChannels(channel_names
);
668 // Show the last channel if we have one
670 panels
[panels
.length
- 1].view
.show();
673 function queryCommand (ev
) {
674 var destination
, panel
;
676 destination
= ev
.params
[0];
678 // Check if we have the panel already. If not, create it
679 panel
= that
.connections
.active_connection
.panels
.getByName(destination
);
681 panel
= new _kiwi
.model
.Query({name
: destination
});
682 that
.connections
.active_connection
.panels
.add(panel
);
685 if (panel
) panel
.view
.show();
689 function msgCommand (ev
) {
690 var destination
= ev
.params
[0],
691 panel
= that
.connections
.active_connection
.panels
.getByName(destination
) || that
.panels().server
;
695 panel
.addMsg(_kiwi
.app
.connections
.active_connection
.get('nick'), ev
.params
.join(' '));
696 _kiwi
.gateway
.privmsg(null, destination
, ev
.params
.join(' '));
699 function actionCommand (ev
) {
700 if (_kiwi
.app
.panels().active
.isServer()) {
704 var panel
= _kiwi
.app
.panels().active
;
705 panel
.addMsg('', '* ' + _kiwi
.app
.connections
.active_connection
.get('nick') + ' ' + ev
.params
.join(' '), 'action');
706 _kiwi
.gateway
.action(null, panel
.get('name'), ev
.params
.join(' '));
709 function partCommand (ev
) {
710 if (ev
.params
.length
=== 0) {
711 _kiwi
.gateway
.part(null, _kiwi
.app
.panels().active
.get('name'));
713 _
.each(ev
.params
, function (channel
) {
714 _kiwi
.gateway
.part(null, channel
);
719 function topicCommand (ev
) {
722 if (ev
.params
.length
=== 0) return;
724 if (that
.isChannelName(ev
.params
[0])) {
725 channel_name
= ev
.params
[0];
728 channel_name
= _kiwi
.app
.panels().active
.get('name');
731 _kiwi
.gateway
.topic(null, channel_name
, ev
.params
.join(' '));
734 function noticeCommand (ev
) {
737 // Make sure we have a destination and some sort of message
738 if (ev
.params
.length
<= 1) return;
740 destination
= ev
.params
[0];
743 _kiwi
.gateway
.notice(null, destination
, ev
.params
.join(' '));
746 function quoteCommand (ev
) {
747 var raw
= ev
.params
.join(' ');
748 _kiwi
.gateway
.raw(null, raw
);
751 function kickCommand (ev
) {
752 var nick
, panel
= _kiwi
.app
.panels().active
;
754 if (!panel
.isChannel()) return;
756 // Make sure we have a nick
757 if (ev
.params
.length
=== 0) return;
762 _kiwi
.gateway
.kick(null, panel
.get('name'), nick
, ev
.params
.join(' '));
765 function clearCommand (ev
) {
766 // Can't clear a server or applet panel
767 if (_kiwi
.app
.panels().active
.isServer() || _kiwi
.app
.panels().active
.isApplet()) {
771 if (_kiwi
.app
.panels().active
.clearMessages
) {
772 _kiwi
.app
.panels().active
.clearMessages();
776 function ctcpCommand(ev
) {
779 // Make sure we have a target and a ctcp type (eg. version, time)
780 if (ev
.params
.length
< 2) return;
782 target
= ev
.params
[0];
788 _kiwi
.gateway
.ctcp(null, true, type
, target
, ev
.params
.join(' '));
791 function settingsCommand (ev
) {
792 var settings
= _kiwi
.model
.Applet
.loadOnce('kiwi_settings');
793 settings
.view
.show();
796 function scriptCommand (ev
) {
797 var editor
= _kiwi
.model
.Applet
.loadOnce('kiwi_script_editor');
801 function appletCommand (ev
) {
802 if (!ev
.params
[0]) return;
804 var panel
= new _kiwi
.model
.Applet();
807 // Url and name given
808 panel
.load(ev
.params
[0], ev
.params
[1]);
810 // Load a pre-loaded applet
811 if (_kiwi
.applets
[ev
.params
[0]]) {
812 panel
.load(new _kiwi
.applets
[ev
.params
[0]]());
814 _kiwi
.app
.panels().server
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_applet_notfound').fetch(ev
.params
[0]));
819 _kiwi
.app
.connections
.active_connection
.panels
.add(panel
);
825 function inviteCommand (ev
) {
828 // A nick must be specified
832 // Can only invite into channels
833 if (!_kiwi
.app
.panels().active
.isChannel())
837 channel
= _kiwi
.app
.panels().active
.get('name');
839 _kiwi
.app
.connections
.active_connection
.gateway
.raw('INVITE ' + nick
+ ' ' + channel
);
841 _kiwi
.app
.panels().active
.addMsg('', '== ' + nick
+ ' has been invited to ' + channel
, 'action');
845 function whoisCommand (ev
) {
850 } else if (_kiwi
.app
.panels().active
.isQuery()) {
851 nick
= _kiwi
.app
.panels().active
.get('name');
855 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOIS ' + nick
+ ' ' + nick
);
859 function whowasCommand (ev
) {
864 } else if (_kiwi
.app
.panels().active
.isQuery()) {
865 nick
= _kiwi
.app
.panels().active
.get('name');
869 _kiwi
.app
.connections
.active_connection
.gateway
.raw('WHOWAS ' + nick
);
872 function encodingCommand (ev
) {
874 _kiwi
.gateway
.setEncoding(null, ev
.params
[0], function (success
) {
876 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_changed').fetch(ev
.params
[0]));
878 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_invalid').fetch(ev
.params
[0]));
882 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_notspecified').fetch());
883 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_encoding_usage').fetch());
887 function serverCommand (ev
) {
888 var server
, port
, ssl
, password
, nick
,
891 // If no server address given, show the new connection dialog
893 tmp
= new _kiwi
.view
.MenuBox(_kiwi
.global
.i18n
.translate('client_models_application_connection_create').fetch());
894 tmp
.addItem('new_connection', new _kiwi
.model
.NewConnection().view
.$el
);
897 // Center screen the dialog
899 top
: (that
.view
.$el
.height() / 2) - (tmp
.$el
.height() / 2),
900 left
: (that
.view
.$el
.width() / 2) - (tmp
.$el
.width() / 2)
906 // Port given in 'host:port' format and no specific port given after a space
907 if (ev
.params
[0].indexOf(':') > 0) {
908 tmp
= ev
.params
[0].split(':');
912 password
= ev
.params
[1] || undefined;
915 // Server + port given as 'host port'
916 server
= ev
.params
[0];
917 port
= ev
.params
[1] || 6667;
919 password
= ev
.params
[2] || undefined;
922 // + in the port means SSL
923 if (port
.toString()[0] === '+') {
925 port
= parseInt(port
.substring(1), 10);
930 // Default port if one wasn't found
933 // Use the same nick as we currently have
934 nick
= _kiwi
.app
.connections
.active_connection
.get('nick');
936 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_connecting').fetch(server
, port
.toString()));
938 _kiwi
.gateway
.newConnection({
944 }, function(err
, new_connection
) {
946 _kiwi
.app
.panels().active
.addMsg('', _kiwi
.global
.i18n
.translate('client_models_application_connection_error').fetch(server
, port
.toString(), err
.toString()));
954 this.isChannelName = function (channel_name
) {
955 var channel_prefix
= _kiwi
.gateway
.get('channel_prefix');
957 if (!channel_name
|| !channel_name
.length
) return false;
958 return (channel_prefix
.indexOf(channel_name
[0]) > -1);
965 model
= Backbone
.Model
.extend(new model());
967 return new model(arguments
);