1 _kiwi
.model
.Application = function () {
2 // Set to a reference to this object within initialize()
5 // The auto connect details entered into the server select box
6 var auto_connect_details
= {};
9 var model = function () {
10 /** Instance of _kiwi.model.PanelList */
13 /** _kiwi.view.Application */
16 /** _kiwi.view.StatusMessage */
19 /* Address for the kiwi server */
20 this.kiwi_server
= null;
22 this.initialize = function (options
) {
25 if (options
[0].container
) {
26 this.set('container', options
[0].container
);
29 // The base url to the kiwi server
30 this.set('base_path', options
[0].base_path
? options
[0].base_path
: '/kiwi');
32 // Best guess at where the kiwi server is
33 this.detectKiwiServer();
36 this.start = function () {
37 // Only debug if set in the querystring
38 if (!getQueryVariable('debug')) {
45 _kiwi
.gateway
= new _kiwi
.model
.Gateway();
46 this.bindGatewayCommands(_kiwi
.gateway
);
48 this.initializeClient();
49 this.initializeGlobals();
51 this.view
.barsHide(true);
53 this.panels
.server
.server_login
.bind('server_connect', function (event
) {
54 var server_login
= this,
56 auto_connect_details
= event
;
58 server_login
.networkConnecting();
60 // Path to get the socket.io transport code
61 transport_path
= that
.kiwi_server
+ that
.get('base_path') + '/transport/socket.io.js?ts='+(new Date().getTime());
63 $script(transport_path
, function () {
68 _kiwi
.gateway
.set('kiwi_server', that
.kiwi_server
+ '/kiwi');
69 _kiwi
.gateway
.set('nick', event
.nick
);
71 _kiwi
.gateway
.connect(event
.server
, event
.port
, event
.ssl
, event
.password
, function (error
) {
79 // TODO: Shouldn't really be here but it's not working in the view.. :/
80 // Hack for firefox browers: Focus is not given on this event loop iteration
81 setTimeout(function(){
82 _kiwi
.app
.panels
.server
.server_login
.$el
.find('.nick').select();
87 function kiwiServerNotFound (e
) {
88 that
.panels
.server
.server_login
.showError();
92 this.detectKiwiServer = function () {
93 // If running from file, default to localhost:7777 by default
94 if (window
.location
.protocol
=== 'file:') {
95 this.kiwi_server
= 'http://localhost:7778';
97 // Assume the kiwi server is on the same server
98 this.kiwi_server
= window
.location
.protocol
+ '//' + window
.location
.host
;
103 this.initializeClient = function () {
104 this.view
= new _kiwi
.view
.Application({model
: this, el
: this.get('container')});
107 * Set the UI components up
109 this.panels
= new _kiwi
.model
.PanelList();
111 this.controlbox
= new _kiwi
.view
.ControlBox({el
: $('#controlbox')[0]});
112 this.bindControllboxCommands(this.controlbox
);
114 this.topicbar
= new _kiwi
.view
.TopicBar({el
: $('#topic')[0]});
116 new _kiwi
.view
.AppToolbar({el
: $('#toolbar .app_tools')[0]});
118 this.message
= new _kiwi
.view
.StatusMessage({el
: $('#status_message')[0]});
120 this.resize_handle
= new _kiwi
.view
.ResizeHandler({el
: $('#memberlists_resize_handle')[0]});
122 this.panels
.server
.view
.show();
124 // Rejigg the UI sizes
125 this.view
.doLayout();
127 this.populateDefaultServerSettings();
131 this.initializeGlobals = function () {
132 _kiwi
.global
.control
= this.controlbox
;
133 _kiwi
.global
.gateway
= _kiwi
.gateway
;
134 _kiwi
.global
.panels
= this.panels
;
136 _kiwi
.global
.components
= {
137 Applet
: _kiwi
.model
.Applet
,
138 Panel
: _kiwi
.model
.Panel
143 this.populateDefaultServerSettings = function () {
146 nick
: getQueryVariable('nick') || 'kiwi_' + Math
.ceil(Math
.random() * 10000).toString(),
147 server
: 'irc.kiwiirc.com',
150 channel
: window
.location
.hash
|| '#kiwiirc',
155 // Process the URL part by part, extracting as we go
156 parts
= window
.location
.pathname
.toString().replace(this.get('base_path'), '').split('/');
158 if (parts
.length
> 0) {
161 if (parts
.length
> 0 && parts
[0]) {
162 // 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.
163 uricheck
= parts
[0].substr(0, 7).toLowerCase();
164 if ((uricheck
=== 'ircs%3a') || (uricheck
.substr(0,6) === 'irc%3a')) {
165 parts
[0] = decodeURIComponent(parts
[0]);
166 // irc[s]://<host>[:<port>]/[<channel>[?<password>]]
167 uricheck
= /^irc(s)?:(?:\/\/?)?([^:\/]+)(?::([0-9]+))?(?:(?:\/)([^\?]*)(?:(?:\?)(.*))?)?$/.exec(parts
[0]);
169 uricheck[1] = ssl (optional)
171 uricheck[3] = port (optional)
172 uricheck[4] = channel (optional)
173 uricheck[5] = channel key (optional, channel must also be set)
176 if (typeof uricheck
[1] !== 'undefined') {
178 if (defaults
.port
=== 6667) {
179 defaults
.port
= 6697;
182 defaults
.server
= uricheck
[2];
183 if (typeof uricheck
[3] !== 'undefined') {
184 defaults
.port
= uricheck
[3];
186 if (typeof uricheck
[4] !== 'undefined') {
187 defaults
.channel
= '#' + uricheck
[4];
188 if (typeof uricheck
[5] !== 'undefined') {
189 defaults
.channel_key
= uricheck
[5];
195 // Extract the port+ssl if we find one
196 if (parts
[0].search(/:/) > 0) {
197 defaults
.port
= parts
[0].substring(parts
[0].search(/:/) + 1);
198 defaults
.server
= parts
[0].substring(0, parts
[0].search(/:/));
199 if (defaults
.port
[0] === '+') {
200 defaults
.port
= parseInt(defaults
.port
.substring(1), 10);
203 defaults
.ssl
= false;
207 defaults
.server
= parts
[0];
214 if (parts
.length
> 0 && parts
[0]) {
215 defaults
.channel
= '#' + parts
[0];
220 // Set any random numbers if needed
221 defaults
.nick
= defaults
.nick
.replace('?', Math
.floor(Math
.random() * 100000).toString());
223 // Populate the server select box with defaults
224 this.panels
.server
.server_login
.populateFields(defaults
);
228 this.bindGatewayCommands = function (gw
) {
229 gw
.on('onmotd', function (event
) {
230 that
.panels
.server
.addMsg(_kiwi
.gateway
.get('name'), event
.msg
, 'motd');
234 gw
.on('onconnect', function (event
) {
235 that
.view
.barsShow();
237 if (auto_connect_details
.channel
) {
238 that
.controlbox
.processInput('/JOIN ' + auto_connect_details
.channel
+ ' ' + auto_connect_details
.channel_key
);
246 gw
.on('disconnect', function (event
) {
247 var msg
= 'You have been disconnected. Attempting to reconnect for you..';
248 that
.message
.text(msg
, {timeout
: 10000});
250 // Mention the disconnection on every channel
251 $.each(_kiwi
.app
.panels
.models
, function (idx
, panel
) {
252 if (!panel
|| !panel
.isChannel()) return;
253 panel
.addMsg('', msg
, 'action quit');
255 _kiwi
.app
.panels
.server
.addMsg('', msg
, 'action quit');
259 gw
.on('reconnecting', function (event
) {
260 msg
= 'You have been disconnected. Attempting to reconnect again in ' + (event
.delay
/1000) + ' seconds..';
261 _kiwi
.app
.panels
.server
.addMsg('', msg
, 'action quit');
263 gw
.on('connect', function (event
) {
264 if (gw_stat
!== 1) return;
266 var msg
= 'It\'s OK, you\'re connected again :)';
267 that
.message
.text(msg
, {timeout
: 5000});
269 // Mention the disconnection on every channel
270 $.each(_kiwi
.app
.panels
.models
, function (idx
, panel
) {
271 if (!panel
|| !panel
.isChannel()) return;
272 panel
.addMsg('', msg
, 'action join');
274 _kiwi
.app
.panels
.server
.addMsg('', msg
, 'action join');
281 gw
.on('onjoin', function (event
) {
282 var c
, members
, user
;
283 c
= that
.panels
.getByName(event
.channel
);
285 c
= new _kiwi
.model
.Channel({name
: event
.channel
});
289 members
= c
.get('members');
290 if (!members
) return;
292 user
= new _kiwi
.model
.Member({nick
: event
.nick
, ident
: event
.ident
, hostname
: event
.hostname
});
294 // TODO: highlight the new channel in some way
298 gw
.on('onpart', function (event
) {
299 var channel
, members
, user
,
302 part_options
.type
= 'part';
303 part_options
.message
= event
.message
|| '';
305 channel
= that
.panels
.getByName(event
.channel
);
306 if (!channel
) return;
308 // If this is us, close the panel
309 if (event
.nick
=== _kiwi
.gateway
.get('nick')) {
314 members
= channel
.get('members');
315 if (!members
) return;
317 user
= members
.getByNick(event
.nick
);
320 members
.remove(user
, part_options
);
324 gw
.on('onquit', function (event
) {
328 quit_options
.type
= 'quit';
329 quit_options
.message
= event
.message
|| '';
331 $.each(that
.panels
.models
, function (index
, panel
) {
332 if (!panel
.isChannel()) return;
334 member
= panel
.get('members').getByNick(event
.nick
);
336 panel
.get('members').remove(member
, quit_options
);
342 gw
.on('onkick', function (event
) {
343 var channel
, members
, user
,
346 part_options
.type
= 'kick';
347 part_options
.by
= event
.nick
;
348 part_options
.message
= event
.message
|| '';
350 channel
= that
.panels
.getByName(event
.channel
);
351 if (!channel
) return;
353 members
= channel
.get('members');
354 if (!members
) return;
356 user
= members
.getByNick(event
.kicked
);
359 members
.remove(user
, part_options
);
361 if (event
.kicked
=== _kiwi
.gateway
.get('nick')) {
368 gw
.on('onmsg', function (event
) {
370 is_pm
= (event
.channel
== _kiwi
.gateway
.get('nick'));
373 // If a panel isn't found for this PM, create one
374 panel
= that
.panels
.getByName(event
.nick
);
376 panel
= new _kiwi
.model
.Query({name
: event
.nick
});
377 that
.panels
.add(panel
);
381 // If a panel isn't found for this channel, reroute to the
383 panel
= that
.panels
.getByName(event
.channel
);
385 panel
= that
.panels
.server
;
389 panel
.addMsg(event
.nick
, event
.msg
);
393 gw
.on('onnotice', function (event
) {
396 // Find a panel for the destination(channel) or who its from
397 panel
= that
.panels
.getByName(event
.target
) || that
.panels
.getByName(event
.nick
);
399 panel
= that
.panels
.server
;
402 panel
.addMsg('[' + (event
.nick
||'') + ']', event
.msg
);
406 gw
.on('onaction', function (event
) {
408 is_pm
= (event
.channel
== _kiwi
.gateway
.get('nick'));
411 // If a panel isn't found for this PM, create one
412 panel
= that
.panels
.getByName(event
.nick
);
414 panel
= new _kiwi
.model
.Channel({name
: event
.nick
});
415 that
.panels
.add(panel
);
419 // If a panel isn't found for this channel, reroute to the
421 panel
= that
.panels
.getByName(event
.channel
);
423 panel
= that
.panels
.server
;
427 panel
.addMsg('', '* ' + event
.nick
+ ' ' + event
.msg
, 'action');
431 gw
.on('ontopic', function (event
) {
433 c
= that
.panels
.getByName(event
.channel
);
436 // Set the channels topic
437 c
.set('topic', event
.topic
);
439 // If this is the active channel, update the topic bar too
440 if (c
.get('name') === _kiwi
.app
.panels
.active
.get('name')) {
441 that
.topicbar
.setCurrentTopic(event
.topic
);
446 gw
.on('ontopicsetby', function (event
) {
448 c
= that
.panels
.getByName(event
.channel
);
451 when
= formatDate(new Date(event
.when
* 1000));
452 c
.addMsg('', 'Topic set by ' + event
.nick
+ ' at ' + when
, 'topic');
456 gw
.on('onuserlist', function (event
) {
458 channel
= that
.panels
.getByName(event
.channel
);
460 // If we didn't find a channel for this, may aswell leave
461 if (!channel
) return;
463 channel
.temp_userlist
= channel
.temp_userlist
|| [];
464 _
.each(event
.users
, function (item
) {
465 var user
= new _kiwi
.model
.Member({nick
: item
.nick
, modes
: item
.modes
});
466 channel
.temp_userlist
.push(user
);
471 gw
.on('onuserlist_end', function (event
) {
473 channel
= that
.panels
.getByName(event
.channel
);
475 // If we didn't find a channel for this, may aswell leave
476 if (!channel
) return;
478 // Update the members list with the new list
479 channel
.get('members').reset(channel
.temp_userlist
|| []);
481 // Clear the temporary userlist
482 delete channel
.temp_userlist
;
486 gw
.on('onmode', function (event
) {
487 var channel
, i
, prefixes
, members
, member
, find_prefix
;
489 // Build a nicely formatted string to be displayed to a regular human
490 function friendlyModeString (event_modes
, alt_target
) {
491 var modes
= {}, return_string
;
493 // If no default given, use the main event info
495 event_modes
= event
.modes
;
496 alt_target
= event
.target
;
499 // Reformat the mode object to make it easier to work with
500 _
.each(event_modes
, function (mode
){
501 var param
= mode
.param
|| alt_target
|| '';
503 // Make sure we have some modes for this param
505 modes
[param
] = {'+':'', '-':''};
508 modes
[param
][mode
.mode
[0]] += mode
.mode
.substr(1);
511 // Put the string together from each mode
513 _
.each(modes
, function (modeset
, param
) {
515 if (modeset
['+']) str
+= '+' + modeset
['+'];
516 if (modeset
['-']) str
+= '-' + modeset
['-'];
517 return_string
.push(str
+ ' ' + param
);
519 return_string
= return_string
.join(', ');
521 return return_string
;
525 channel
= that
.panels
.getByName(event
.target
);
527 prefixes
= _kiwi
.gateway
.get('user_prefixes');
528 find_prefix = function (p
) {
529 return event
.modes
[i
].mode
[1] === p
.mode
;
531 for (i
= 0; i
< event
.modes
.length
; i
++) {
532 if (_
.any(prefixes
, find_prefix
)) {
534 members
= channel
.get('members');
536 member
= members
.getByNick(event
.modes
[i
].param
);
538 console
.log('MODE command recieved for unknown member %s on channel %s', event
.modes
[i
].param
, event
.target
);
541 if (event
.modes
[i
].mode
[0] === '+') {
542 member
.addMode(event
.modes
[i
].mode
[1]);
543 } else if (event
.modes
[i
].mode
[0] === '-') {
544 member
.removeMode(event
.modes
[i
].mode
[1]);
547 //channel.addMsg('', '== ' + event.nick + ' set mode ' + event.modes[i].mode + ' ' + event.modes[i].param, 'action mode');
550 // Channel mode being set
551 // TODO: Store this somewhere?
552 //channel.addMsg('', 'CHANNEL === ' + event.nick + ' set mode ' + event.modes[i].mode + ' on ' + event.target, 'action mode');
556 channel
.addMsg('', '== ' + event
.nick
+ ' sets mode ' + friendlyModeString(), 'action mode');
558 // This is probably a mode being set on us.
559 if (event
.target
.toLowerCase() === _kiwi
.gateway
.get("nick").toLowerCase()) {
560 that
.panels
.server
.addMsg('', '== ' + event
.nick
+ ' set mode ' + friendlyModeString(), 'action mode');
562 console
.log('MODE command recieved for unknown target %s: ', event
.target
, event
);
568 gw
.on('onnick', function (event
) {
571 $.each(that
.panels
.models
, function (index
, panel
) {
572 if (!panel
.isChannel()) return;
574 member
= panel
.get('members').getByNick(event
.nick
);
576 member
.set('nick', event
.newnick
);
577 panel
.addMsg('', '== ' + event
.nick
+ ' is now known as ' + event
.newnick
, 'action nick');
583 gw
.on('onwhois', function (event
) {
584 /*globals secondsToTime */
585 var logon_date
, idle_time
= '', panel
;
591 if (typeof event
.idle
!== 'undefined') {
592 idle_time
= secondsToTime(parseInt(event
.idle
, 10));
593 idle_time
= idle_time
.h
.toString().lpad(2, "0") + ':' + idle_time
.m
.toString().lpad(2, "0") + ':' + idle_time
.s
.toString().lpad(2, "0");
596 panel
= _kiwi
.app
.panels
.active
;
598 panel
.addMsg(event
.nick
, 'is ' + event
.nick
+ '!' + event
.ident
+ '@' + event
.host
+ ' * ' + event
.msg
, 'whois');
599 } else if (event
.chans
) {
600 panel
.addMsg(event
.nick
, 'on ' + event
.chans
, 'whois');
601 } else if (event
.irc_server
) {
602 panel
.addMsg(event
.nick
, 'using ' + event
.server
, 'whois');
603 } else if (event
.msg
) {
604 panel
.addMsg(event
.nick
, event
.msg
, 'whois');
605 } else if (event
.logon
) {
606 logon_date
= new Date();
607 logon_date
.setTime(event
.logon
* 1000);
608 logon_date
= formatDate(logon_date
);
610 panel
.addMsg(event
.nick
, 'idle for ' + idle_time
+ ', signed on ' + logon_date
, 'whois');
612 panel
.addMsg(event
.nick
, 'idle for ' + idle_time
, 'whois');
617 gw
.on('onlist_start', function (data
) {
618 if (_kiwi
.app
.channel_list
) {
619 _kiwi
.app
.channel_list
.close();
620 delete _kiwi
.app
.channel_list
;
623 var panel
= new _kiwi
.model
.Applet(),
624 applet
= new _kiwi
.applets
.Chanlist();
628 _kiwi
.app
.panels
.add(panel
);
631 _kiwi
.app
.channel_list
= applet
;
635 gw
.on('onlist_channel', function (data
) {
636 // TODO: Put this listener within the applet itself
637 _kiwi
.app
.channel_list
.addChannel(data
.chans
);
641 gw
.on('onlist_end', function (data
) {
642 // TODO: Put this listener within the applet itself
643 delete _kiwi
.app
.channel_list
;
647 gw
.on('onirc_error', function (data
) {
650 if (data
.channel
!== undefined && !(panel
= _kiwi
.app
.panels
.getByName(data
.channel
))) {
651 panel
= _kiwi
.app
.panels
.server
;
654 switch (data
.error
) {
655 case 'banned_from_channel':
656 panel
.addMsg(' ', '== You are banned from ' + data
.channel
+ '. ' + data
.reason
, 'status');
657 _kiwi
.app
.message
.text('You are banned from ' + data
.channel
+ '. ' + data
.reason
);
659 case 'bad_channel_key':
660 panel
.addMsg(' ', '== Bad channel key for ' + data
.channel
, 'status');
661 _kiwi
.app
.message
.text('Bad channel key or password for ' + data
.channel
);
663 case 'invite_only_channel':
664 panel
.addMsg(' ', '== ' + data
.channel
+ ' is invite only.', 'status');
665 _kiwi
.app
.message
.text(data
.channel
+ ' is invite only');
667 case 'channel_is_full':
668 panel
.addMsg(' ', '== ' + data
.channel
+ ' is full.', 'status');
669 _kiwi
.app
.message
.text(data
.channel
+ ' is full');
671 case 'chanop_privs_needed':
672 panel
.addMsg(' ', '== ' + data
.reason
, 'status');
673 _kiwi
.app
.message
.text(data
.reason
+ ' (' + data
.channel
+ ')');
676 tmp
= _kiwi
.app
.panels
.getByName(data
.nick
);
678 tmp
.addMsg(' ', '== ' + data
.nick
+ ': ' + data
.reason
, 'status');
680 _kiwi
.app
.panels
.server
.addMsg(' ', '== ' + data
.nick
+ ': ' + data
.reason
, 'status');
683 case 'nickname_in_use':
684 _kiwi
.app
.panels
.server
.addMsg(' ', '== The nickname ' + data
.nick
+ ' is already in use. Please select a new nickname', 'status');
685 if (_kiwi
.app
.panels
.server
!== _kiwi
.app
.panels
.active
) {
686 _kiwi
.app
.message
.text('The nickname "' + data
.nick
+ '" is already in use. Please select a new nickname');
689 // Only show the nickchange component if the controlbox is open
690 if (that
.controlbox
.$el
.css('display') !== 'none') {
691 (new _kiwi
.view
.NickChangeBox()).render();
696 // We don't know what data contains, so don't do anything with it.
697 //_kiwi.front.tabviews.server.addMsg(null, ' ', '== ' + data, 'status');
705 * Bind to certain commands that may be typed into the control box
707 this.bindControllboxCommands = function (controlbox
) {
709 $.extend(controlbox
.preprocessor
.aliases
, {
712 '/me': '/action $1+',
716 // Op related aliases
717 '/op': '/quote mode $channel +o $1+',
718 '/deop': '/quote mode $channel -o $1+',
719 '/hop': '/quote mode $channel +h $1+',
720 '/dehop': '/quote mode $channel -h $1+',
721 '/voice': '/quote mode $channel +v $1+',
722 '/devoice': '/quote mode $channel -v $1+',
723 '/k': '/kick $channel $1+',
726 '/slap': '/me slaps $1 around a bit with a large trout'
729 controlbox
.on('unknown_command', unknownCommand
);
731 controlbox
.on('command', allCommands
);
732 controlbox
.on('command_msg', msgCommand
);
734 controlbox
.on('command_action', actionCommand
);
736 controlbox
.on('command_join', joinCommand
);
738 controlbox
.on('command_part', partCommand
);
740 controlbox
.on('command_nick', function (ev
) {
741 _kiwi
.gateway
.changeNick(ev
.params
[0]);
744 controlbox
.on('command_query', queryCommand
);
746 controlbox
.on('command_topic', topicCommand
);
748 controlbox
.on('command_notice', noticeCommand
);
750 controlbox
.on('command_quote', quoteCommand
);
752 controlbox
.on('command_kick', kickCommand
);
755 controlbox
.on('command_css', function (ev
) {
756 var queryString
= '?reload=' + new Date().getTime();
757 $('link[rel="stylesheet"]').each(function () {
758 this.href
= this.href
.replace(/\?.*|$/, queryString
);
762 controlbox
.on('command_js', function (ev
) {
763 if (!ev
.params
[0]) return;
764 $script(ev
.params
[0] + '?' + (new Date().getTime()));
768 controlbox
.on('command_set', function (ev
) {
769 if (!ev
.params
[0]) return;
771 var setting
= ev
.params
[0],
774 // Do we have a second param to set a value?
778 value
= ev
.params
.join(' ');
779 _kiwi
.global
.settings
.set(setting
, value
);
782 // Read the value to the user
783 _kiwi
.app
.panels
.active
.addMsg('', setting
+ ' = ' + _kiwi
.global
.settings
.get(setting
));
787 controlbox
.on('command_save', function (ev
) {
788 _kiwi
.global
.settings
.save();
789 _kiwi
.app
.panels
.active
.addMsg('', 'Settings have been saved');
793 controlbox
.on('command_alias', function (ev
) {
796 // No parameters passed so list them
798 $.each(controlbox
.preprocessor
.aliases
, function (name
, rule
) {
799 _kiwi
.app
.panels
.server
.addMsg(' ', name
+ ' => ' + rule
);
804 // Deleting an alias?
805 if (ev
.params
[0] === 'del' || ev
.params
[0] === 'delete') {
807 if (name
[0] !== '/') name
= '/' + name
;
808 delete controlbox
.preprocessor
.aliases
[name
];
815 rule
= ev
.params
.join(' ');
817 // Make sure the name starts with a slash
818 if (name
[0] !== '/') name
= '/' + name
;
820 // Now actually add the alias
821 controlbox
.preprocessor
.aliases
[name
] = rule
;
824 controlbox
.on('command_applet', appletCommand
);
825 controlbox
.on('command_settings', settingsCommand
);
828 // A fallback action. Send a raw command to the server
829 function unknownCommand (ev
) {
830 var raw_cmd
= ev
.command
+ ' ' + ev
.params
.join(' ');
831 console
.log('RAW: ' + raw_cmd
);
832 _kiwi
.gateway
.raw(raw_cmd
);
835 function allCommands (ev
) {}
837 function joinCommand (ev
) {
838 var channel
, channel_names
;
840 channel_names
= ev
.params
.join(' ').split(',');
842 $.each(channel_names
, function (index
, channel_name
) {
843 // Trim any whitespace off the name
844 channel_name
= channel_name
.trim();
846 // Check if we have the panel already. If not, create it
847 channel
= that
.panels
.getByName(channel_name
);
849 channel
= new _kiwi
.model
.Channel({name
: channel_name
});
850 _kiwi
.app
.panels
.add(channel
);
853 _kiwi
.gateway
.join(channel_name
);
856 if (channel
) channel
.view
.show();
860 function queryCommand (ev
) {
861 var destination
, panel
;
863 destination
= ev
.params
[0];
865 // Check if we have the panel already. If not, create it
866 panel
= that
.panels
.getByName(destination
);
868 panel
= new _kiwi
.model
.Query({name
: destination
});
869 _kiwi
.app
.panels
.add(panel
);
872 if (panel
) panel
.view
.show();
876 function msgCommand (ev
) {
877 var destination
= ev
.params
[0],
878 panel
= that
.panels
.getByName(destination
) || that
.panels
.server
;
882 panel
.addMsg(_kiwi
.gateway
.get('nick'), ev
.params
.join(' '));
883 _kiwi
.gateway
.privmsg(destination
, ev
.params
.join(' '));
886 function actionCommand (ev
) {
887 if (_kiwi
.app
.panels
.active
=== _kiwi
.app
.panels
.server
) {
891 var panel
= _kiwi
.app
.panels
.active
;
892 panel
.addMsg('', '* ' + _kiwi
.gateway
.get('nick') + ' ' + ev
.params
.join(' '), 'action');
893 _kiwi
.gateway
.action(panel
.get('name'), ev
.params
.join(' '));
896 function partCommand (ev
) {
897 if (ev
.params
.length
=== 0) {
898 _kiwi
.gateway
.part(_kiwi
.app
.panels
.active
.get('name'));
900 _
.each(ev
.params
, function (channel
) {
901 _kiwi
.gateway
.part(channel
);
904 // TODO: More responsive = close tab now, more accurate = leave until part event
905 //_kiwi.app.panels.remove(_kiwi.app.panels.active);
908 function topicCommand (ev
) {
911 if (ev
.params
.length
=== 0) return;
913 if (that
.isChannelName(ev
.params
[0])) {
914 channel_name
= ev
.params
[0];
917 channel_name
= _kiwi
.app
.panels
.active
.get('name');
920 _kiwi
.gateway
.topic(channel_name
, ev
.params
.join(' '));
923 function noticeCommand (ev
) {
926 // Make sure we have a destination and some sort of message
927 if (ev
.params
.length
<= 1) return;
929 destination
= ev
.params
[0];
932 _kiwi
.gateway
.notice(destination
, ev
.params
.join(' '));
935 function quoteCommand (ev
) {
936 var raw
= ev
.params
.join(' ');
937 _kiwi
.gateway
.raw(raw
);
940 function kickCommand (ev
) {
941 var nick
, panel
= _kiwi
.app
.panels
.active
;
943 if (!panel
.isChannel()) return;
945 // Make sure we have a nick
946 if (ev
.params
.length
=== 0) return;
951 _kiwi
.gateway
.kick(panel
.get('name'), nick
, ev
.params
.join(' '));
954 function settingsCommand (ev
) {
955 var panel
= new _kiwi
.model
.Applet();
956 panel
.load(new _kiwi
.applets
.Settings());
958 _kiwi
.app
.panels
.add(panel
);
962 function appletCommand (ev
) {
963 if (!ev
.params
[0]) return;
965 var panel
= new _kiwi
.model
.Applet();
968 // Url and name given
969 panel
.load(ev
.params
[0], ev
.params
[1]);
971 // Load a pre-loaded applet
972 if (_kiwi
.applets
[ev
.params
[0]]) {
973 panel
.load(new _kiwi
.applets
[ev
.params
[0]]());
975 _kiwi
.app
.panels
.server
.addMsg('', 'Applet "' + ev
.params
[0] + '" does not exist');
980 _kiwi
.app
.panels
.add(panel
);
988 this.isChannelName = function (channel_name
) {
989 var channel_prefix
= _kiwi
.gateway
.get('channel_prefix');
991 if (!channel_name
|| !channel_name
.length
) return false;
992 return (channel_prefix
.indexOf(channel_name
[0]) > -1);
998 model
= Backbone
.Model
.extend(new model());
1000 return new model(arguments
);