-_kiwi.model.Application = function () {\r
- // Set to a reference to this object within initialize()\r
- var that = null;\r
+(function () {\r
\r
-\r
- var model = function () {\r
+ _kiwi.model.Application = Backbone.Model.extend({\r
/** _kiwi.view.Application */\r
- this.view = null;\r
+ view: null,\r
\r
/** _kiwi.view.StatusMessage */\r
- this.message = null;\r
+ message: null,\r
\r
/* Address for the kiwi server */\r
- this.kiwi_server = null;\r
-\r
- this.initialize = function (options) {\r
- that = this;\r
+ kiwi_server: null,\r
\r
- if (options[0].container) {\r
- this.set('container', options[0].container);\r
+ initialize: function (options) {\r
+ if (options.container) {\r
+ this.set('container', options.container);\r
}\r
\r
// The base url to the kiwi server\r
- this.set('base_path', options[0].base_path ? options[0].base_path : '/kiwi');\r
+ this.set('base_path', options.base_path ? options.base_path : '/kiwi');\r
\r
// Path for the settings.json file\r
- this.set('settings_path', options[0].settings_path ?\r
- options[0].settings_path :\r
+ this.set('settings_path', options.settings_path ?\r
+ options.settings_path :\r
this.get('base_path') + '/assets/settings.json'\r
);\r
\r
// Any options sent down from the server\r
- this.server_settings = options[0].server_settings || {};\r
- this.translations = options[0].translations || {};\r
- this.themes = options[0].themes || [];\r
+ this.server_settings = options.server_settings || {};\r
+ this.translations = options.translations || {};\r
+ this.themes = options.themes || [];\r
\r
// Best guess at where the kiwi server is if not already specified\r
- this.kiwi_server = options[0].kiwi_server || this.detectKiwiServer();\r
+ this.kiwi_server = options.kiwi_server || this.detectKiwiServer();\r
\r
// Set any default settings before anything else is applied\r
if (this.server_settings && this.server_settings.client && this.server_settings.client.settings) {\r
this.applyDefaultClientSettings(this.server_settings.client.settings);\r
}\r
- };\r
+ },\r
\r
\r
- this.start = function () {\r
+ start: function () {\r
// Set the gateway up\r
_kiwi.gateway = new _kiwi.model.Gateway();\r
this.bindGatewayCommands(_kiwi.gateway);\r
this.view.barsHide(true);\r
\r
this.showIntialConenctionDialog();\r
- };\r
+ },\r
\r
\r
- this.detectKiwiServer = function () {\r
+ detectKiwiServer: function () {\r
// If running from file, default to localhost:7777 by default\r
if (window.location.protocol === 'file:') {\r
return 'http://localhost:7778';\r
// Assume the kiwi server is on the same server\r
return window.location.protocol + '//' + window.location.host;\r
}\r
- };\r
+ },\r
\r
\r
- this.showIntialConenctionDialog = function() {\r
+ showIntialConenctionDialog: function() {\r
var connection_dialog = new _kiwi.model.NewConnection();\r
this.populateDefaultServerSettings(connection_dialog);\r
\r
\r
};\r
_kiwi.gateway.on('onconnect', fn);\r
- };\r
+ },\r
\r
\r
- this.initializeClient = function () {\r
+ initializeClient: function () {\r
this.view = new _kiwi.view.Application({model: this, el: this.get('container')});\r
\r
// Takes instances of model_network\r
\r
// Rejigg the UI sizes\r
this.view.doLayout();\r
- };\r
+ },\r
\r
\r
- this.initializeGlobals = function () {\r
+ initializeGlobals: function () {\r
_kiwi.global.connections = this.connections;\r
\r
_kiwi.global.panels = this.panels;\r
\r
_kiwi.global.components.Applet = _kiwi.model.Applet;\r
_kiwi.global.components.Panel =_kiwi.model.Panel;\r
- };\r
+ },\r
\r
\r
- this.applyDefaultClientSettings = function (settings) {\r
+ applyDefaultClientSettings: function (settings) {\r
_.each(settings, function (value, setting) {\r
if (typeof _kiwi.global.settings.get(setting) === 'undefined') {\r
_kiwi.global.settings.set(setting, value);\r
}\r
});\r
- };\r
+ },\r
\r
\r
- this.populateDefaultServerSettings = function (new_connection_dialog) {\r
+ populateDefaultServerSettings: function (new_connection_dialog) {\r
var parts;\r
var defaults = {\r
nick: '',\r
\r
// Populate the server select box with defaults\r
new_connection_dialog.view.populateFields(defaults);\r
- };\r
+ },\r
\r
\r
- this.panels = (function() {\r
+ panels: (function() {\r
var fn = function(panel_type) {\r
var panels;\r
\r
_.extend(fn, Backbone.Events);\r
\r
return fn;\r
- })();\r
+ })(),\r
\r
\r
- this.bindGatewayCommands = function (gw) {\r
+ bindGatewayCommands: function (gw) {\r
var that = this;\r
\r
gw.on('onconnect', function (event) {\r
}, jump_server_interval * 1000);\r
}\r
});\r
- };\r
+ },\r
\r
\r
\r
/**\r
* Bind to certain commands that may be typed into the control box\r
*/\r
- this.bindControllboxCommands = function (controlbox) {\r
+ bindControllboxCommands: function (controlbox) {\r
+ var that = this;\r
+\r
// Default aliases\r
$.extend(controlbox.preprocessor.aliases, {\r
// General aliases\r
- '/p': '/part $1+',\r
- '/me': '/action $1+',\r
- '/j': '/join $1+',\r
- '/q': '/query $1+',\r
- '/w': '/whois $1+',\r
- '/raw': '/quote $1+',\r
+ '/p': '/part $1+',\r
+ '/me': '/action $1+',\r
+ '/j': '/join $1+',\r
+ '/q': '/query $1+',\r
+ '/w': '/whois $1+',\r
+ '/raw': '/quote $1+',\r
\r
// Op related aliases\r
- '/op': '/quote mode $channel +o $1+',\r
- '/deop': '/quote mode $channel -o $1+',\r
- '/hop': '/quote mode $channel +h $1+',\r
- '/dehop': '/quote mode $channel -h $1+',\r
- '/voice': '/quote mode $channel +v $1+',\r
- '/devoice': '/quote mode $channel -v $1+',\r
- '/k': '/kick $channel $1+',\r
- '/ban': '/quote mode $channel +b $1+',\r
- '/unban': '/quote mode $channel -b $1+',\r
+ '/op': '/quote mode $channel +o $1+',\r
+ '/deop': '/quote mode $channel -o $1+',\r
+ '/hop': '/quote mode $channel +h $1+',\r
+ '/dehop': '/quote mode $channel -h $1+',\r
+ '/voice': '/quote mode $channel +v $1+',\r
+ '/devoice': '/quote mode $channel -v $1+',\r
+ '/k': '/kick $channel $1+',\r
+ '/ban': '/quote mode $channel +b $1+',\r
+ '/unban': '/quote mode $channel -b $1+',\r
\r
// Misc aliases\r
- '/slap': '/me slaps $1 around a bit with a large trout'\r
- });\r
-\r
- controlbox.on('unknown_command', unknownCommand);\r
-\r
- controlbox.on('command', allCommands);\r
- controlbox.on('command:msg', msgCommand);\r
-\r
- controlbox.on('command:action', actionCommand);\r
-\r
- controlbox.on('command:join', joinCommand);\r
-\r
- controlbox.on('command:part', partCommand);\r
-\r
- controlbox.on('command:nick', function (ev) {\r
- _kiwi.gateway.changeNick(null, ev.params[0]);\r
+ '/slap': '/me slaps $1 around a bit with a large trout'\r
});\r
\r
- controlbox.on('command:query', queryCommand);\r
-\r
- controlbox.on('command:invite', inviteCommand);\r
-\r
- controlbox.on('command:topic', topicCommand);\r
-\r
- controlbox.on('command:notice', noticeCommand);\r
-\r
- controlbox.on('command:quote', quoteCommand);\r
-\r
- controlbox.on('command:kick', kickCommand);\r
-\r
- controlbox.on('command:clear', clearCommand);\r
-\r
- controlbox.on('command:ctcp', ctcpCommand);\r
-\r
- controlbox.on('command:server', serverCommand);\r
-\r
- controlbox.on('command:whois', whoisCommand);\r
-\r
- controlbox.on('command:whowas', whowasCommand);\r
-\r
- controlbox.on('command:encoding', encodingCommand);\r
-\r
- controlbox.on('command:channel', function(ev) {\r
- var active_panel = _kiwi.app.panels().active;\r
-\r
- if (!active_panel.isChannel())\r
- return;\r
-\r
- new _kiwi.model.ChannelInfo({channel: _kiwi.app.panels().active});\r
- });\r
+ // Functions to bind to controlbox events\r
+ var fn_to_bind = {\r
+ 'unknown_command': unknownCommand,\r
+ 'command': allCommands,\r
+ 'command:msg': msgCommand,\r
+ 'command:action': actionCommand,\r
+ 'command:join': joinCommand,\r
+ 'command:part': partCommand,\r
+ 'command:nick': nickCommand,\r
+ 'command:query': queryCommand,\r
+ 'command:invite': inviteCommand,\r
+ 'command:topic': topicCommand,\r
+ 'command:notice': noticeCommand,\r
+ 'command:quote': quoteCommand,\r
+ 'command:kick': kickCommand,\r
+ 'command:clear': clearCommand,\r
+ 'command:ctcp': ctcpCommand,\r
+ 'command:server': serverCommand,\r
+ 'command:whois': whoisCommand,\r
+ 'command:whowas': whowasCommand,\r
+ 'command:encoding': encodingCommand,\r
+ 'command:channel': channelCommand,\r
+ 'command:applet': appletCommand,\r
+ 'command:settings': settingsCommand,\r
+ 'command:script': scriptCommand\r
+ };\r
\r
- controlbox.on('command:css', function (ev) {\r
+ fn_to_bind['command:css'] = function (ev) {\r
var queryString = '?reload=' + new Date().getTime();\r
$('link[rel="stylesheet"]').each(function () {\r
this.href = this.href.replace(/\?.*|$/, queryString);\r
});\r
- });\r
+ };\r
\r
- controlbox.on('command:js', function (ev) {\r
+ fn_to_bind['command:js'] = function (ev) {\r
if (!ev.params[0]) return;\r
$script(ev.params[0] + '?' + (new Date().getTime()));\r
- });\r
+ };\r
\r
\r
- controlbox.on('command:set', function (ev) {\r
+ fn_to_bind['command:set'] = function (ev) {\r
if (!ev.params[0]) return;\r
\r
var setting = ev.params[0],\r
\r
// Read the value to the user\r
_kiwi.app.panels().active.addMsg('', setting + ' = ' + _kiwi.global.settings.get(setting).toString());\r
- });\r
+ };\r
\r
\r
- controlbox.on('command:save', function (ev) {\r
+ fn_to_bind['command:save'] = function (ev) {\r
_kiwi.global.settings.save();\r
_kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_settings_saved').fetch());\r
- });\r
+ };\r
\r
\r
- controlbox.on('command:alias', function (ev) {\r
+ fn_to_bind['command:alias'] = function (ev) {\r
var name, rule;\r
\r
// No parameters passed so list them\r
\r
// Now actually add the alias\r
controlbox.preprocessor.aliases[name] = rule;\r
- });\r
+ };\r
\r
\r
- controlbox.on('command:ignore', function (ev) {\r
+ fn_to_bind['command:ignore'] = function (ev) {\r
var list = _kiwi.gateway.get('ignore_list');\r
\r
// No parameters passed so list them\r
list.push(ev.params[0]);\r
_kiwi.gateway.set('ignore_list', list);\r
_kiwi.app.panels().active.addMsg(' ', _kiwi.global.i18n.translate('client_models_application_ignore_nick').fetch(ev.params[0]));\r
- });\r
+ };\r
\r
\r
- controlbox.on('command:unignore', function (ev) {\r
+ fn_to_bind['command:unignore'] = function (ev) {\r
var list = _kiwi.gateway.get('ignore_list');\r
\r
if (!ev.params[0]) {\r
_kiwi.gateway.set('ignore_list', list);\r
\r
_kiwi.app.panels().active.addMsg(' ', _kiwi.global.i18n.translate('client_models_application_ignore_stopped').fetch(ev.params[0]));\r
+ };\r
+\r
+\r
+ _.each(fn_to_bind, function(fn, event_name) {\r
+ controlbox.on(event_name, _.bind(fn, that));\r
});\r
+ },\r
\r
\r
- controlbox.on('command:applet', appletCommand);\r
- controlbox.on('command:settings', settingsCommand);\r
- controlbox.on('command:script', scriptCommand);\r
- };\r
+ isChannelName: function (channel_name) {\r
+ var channel_prefix = _kiwi.gateway.get('channel_prefix');\r
\r
- // A fallback action. Send a raw command to the server\r
- function unknownCommand (ev) {\r
- var raw_cmd = ev.command + ' ' + ev.params.join(' ');\r
- console.log('RAW: ' + raw_cmd);\r
- _kiwi.gateway.raw(null, raw_cmd);\r
+ if (!channel_name || !channel_name.length) return false;\r
+ return (channel_prefix.indexOf(channel_name[0]) > -1);\r
}\r
+ });\r
\r
- function allCommands (ev) {}\r
\r
- function joinCommand (ev) {\r
- var panels, channel_names;\r
\r
- channel_names = ev.params.join(' ').split(',');\r
- panels = that.connections.active_connection.createAndJoinChannels(channel_names);\r
\r
- // Show the last channel if we have one\r
- if (panels.length)\r
- panels[panels.length - 1].view.show();\r
- }\r
+ // A fallback action. Send a raw command to the server\r
+ function unknownCommand (ev) {\r
+ var raw_cmd = ev.command + ' ' + ev.params.join(' ');\r
+ console.log('RAW: ' + raw_cmd);\r
+ _kiwi.gateway.raw(null, raw_cmd);\r
+ }\r
\r
- function queryCommand (ev) {\r
- var destination, message, panel;\r
+ function allCommands (ev) {}\r
\r
- destination = ev.params[0];\r
- ev.params.shift();\r
+ function joinCommand (ev) {\r
+ var panels, channel_names;\r
\r
- message = ev.params.join(' ');\r
+ channel_names = ev.params.join(' ').split(',');\r
+ panels = this.connections.active_connection.createAndJoinChannels(channel_names);\r
\r
- // Check if we have the panel already. If not, create it\r
- panel = that.connections.active_connection.panels.getByName(destination);\r
- if (!panel) {\r
- panel = new _kiwi.model.Query({name: destination});\r
- that.connections.active_connection.panels.add(panel);\r
- }\r
+ // Show the last channel if we have one\r
+ if (panels.length)\r
+ panels[panels.length - 1].view.show();\r
+ }\r
\r
- if (panel) panel.view.show();\r
+ function queryCommand (ev) {\r
+ var destination, message, panel;\r
\r
- if (message) {\r
- that.connections.active_connection.gateway.msg(panel.get('name'), message);\r
- panel.addMsg(_kiwi.app.connections.active_connection.get('nick'), message);\r
- }\r
+ destination = ev.params[0];\r
+ ev.params.shift();\r
\r
- }\r
+ message = ev.params.join(' ');\r
\r
- function msgCommand (ev) {\r
- var message,\r
- destination = ev.params[0],\r
- panel = that.connections.active_connection.panels.getByName(destination) || that.panels().server;\r
+ // Check if we have the panel already. If not, create it\r
+ panel = this.connections.active_connection.panels.getByName(destination);\r
+ if (!panel) {\r
+ panel = new _kiwi.model.Query({name: destination});\r
+ this.connections.active_connection.panels.add(panel);\r
+ }\r
\r
- ev.params.shift();\r
- message = formatToIrcMsg(ev.params.join(' '));\r
+ if (panel) panel.view.show();\r
\r
+ if (message) {\r
+ this.connections.active_connection.gateway.msg(panel.get('name'), message);\r
panel.addMsg(_kiwi.app.connections.active_connection.get('nick'), message);\r
- _kiwi.gateway.privmsg(null, destination, message);\r
}\r
\r
- function actionCommand (ev) {\r
- if (_kiwi.app.panels().active.isServer()) {\r
- return;\r
- }\r
+ }\r
\r
- var panel = _kiwi.app.panels().active;\r
- panel.addMsg('', '* ' + _kiwi.app.connections.active_connection.get('nick') + ' ' + ev.params.join(' '), 'action');\r
- _kiwi.gateway.action(null, panel.get('name'), ev.params.join(' '));\r
- }\r
+ function msgCommand (ev) {\r
+ var message,\r
+ destination = ev.params[0],\r
+ panel = this.connections.active_connection.panels.getByName(destination) || this.panels().server;\r
\r
- function partCommand (ev) {\r
- if (ev.params.length === 0) {\r
- _kiwi.gateway.part(null, _kiwi.app.panels().active.get('name'));\r
- } else {\r
- _.each(ev.params, function (channel) {\r
- _kiwi.gateway.part(null, channel);\r
- });\r
- }\r
- }\r
-\r
- function topicCommand (ev) {\r
- var channel_name;\r
+ ev.params.shift();\r
+ message = formatToIrcMsg(ev.params.join(' '));\r
\r
- if (ev.params.length === 0) return;\r
+ panel.addMsg(_kiwi.app.connections.active_connection.get('nick'), message);\r
+ _kiwi.gateway.privmsg(null, destination, message);\r
+ }\r
\r
- if (that.isChannelName(ev.params[0])) {\r
- channel_name = ev.params[0];\r
- ev.params.shift();\r
- } else {\r
- channel_name = _kiwi.app.panels().active.get('name');\r
- }\r
+ function actionCommand (ev) {\r
+ if (_kiwi.app.panels().active.isServer()) {\r
+ return;\r
+ }\r
\r
- _kiwi.gateway.topic(null, channel_name, ev.params.join(' '));\r
+ var panel = _kiwi.app.panels().active;\r
+ panel.addMsg('', '* ' + _kiwi.app.connections.active_connection.get('nick') + ' ' + ev.params.join(' '), 'action');\r
+ _kiwi.gateway.action(null, panel.get('name'), ev.params.join(' '));\r
+ }\r
+\r
+ function partCommand (ev) {\r
+ if (ev.params.length === 0) {\r
+ _kiwi.gateway.part(null, _kiwi.app.panels().active.get('name'));\r
+ } else {\r
+ _.each(ev.params, function (channel) {\r
+ _kiwi.gateway.part(null, channel);\r
+ });\r
}\r
+ }\r
\r
- function noticeCommand (ev) {\r
- var destination;\r
+ function nickCommand (ev) {\r
+ _kiwi.gateway.changeNick(null, ev.params[0]);\r
+ }\r
\r
- // Make sure we have a destination and some sort of message\r
- if (ev.params.length <= 1) return;\r
+ function topicCommand (ev) {\r
+ var channel_name;\r
\r
- destination = ev.params[0];\r
- ev.params.shift();\r
+ if (ev.params.length === 0) return;\r
\r
- _kiwi.gateway.notice(null, destination, ev.params.join(' '));\r
+ if (this.isChannelName(ev.params[0])) {\r
+ channel_name = ev.params[0];\r
+ ev.params.shift();\r
+ } else {\r
+ channel_name = _kiwi.app.panels().active.get('name');\r
}\r
\r
- function quoteCommand (ev) {\r
- var raw = ev.params.join(' ');\r
- _kiwi.gateway.raw(null, raw);\r
- }\r
+ _kiwi.gateway.topic(null, channel_name, ev.params.join(' '));\r
+ }\r
\r
- function kickCommand (ev) {\r
- var nick, panel = _kiwi.app.panels().active;\r
+ function noticeCommand (ev) {\r
+ var destination;\r
\r
- if (!panel.isChannel()) return;\r
+ // Make sure we have a destination and some sort of message\r
+ if (ev.params.length <= 1) return;\r
\r
- // Make sure we have a nick\r
- if (ev.params.length === 0) return;\r
+ destination = ev.params[0];\r
+ ev.params.shift();\r
\r
- nick = ev.params[0];\r
- ev.params.shift();\r
+ _kiwi.gateway.notice(null, destination, ev.params.join(' '));\r
+ }\r
\r
- _kiwi.gateway.kick(null, panel.get('name'), nick, ev.params.join(' '));\r
- }\r
+ function quoteCommand (ev) {\r
+ var raw = ev.params.join(' ');\r
+ _kiwi.gateway.raw(null, raw);\r
+ }\r
\r
- function clearCommand (ev) {\r
- // Can't clear a server or applet panel\r
- if (_kiwi.app.panels().active.isServer() || _kiwi.app.panels().active.isApplet()) {\r
- return;\r
- }\r
+ function kickCommand (ev) {\r
+ var nick, panel = _kiwi.app.panels().active;\r
\r
- if (_kiwi.app.panels().active.clearMessages) {\r
- _kiwi.app.panels().active.clearMessages();\r
- }\r
- }\r
+ if (!panel.isChannel()) return;\r
\r
- function ctcpCommand(ev) {\r
- var target, type;\r
+ // Make sure we have a nick\r
+ if (ev.params.length === 0) return;\r
\r
- // Make sure we have a target and a ctcp type (eg. version, time)\r
- if (ev.params.length < 2) return;\r
+ nick = ev.params[0];\r
+ ev.params.shift();\r
\r
- target = ev.params[0];\r
- ev.params.shift();\r
+ _kiwi.gateway.kick(null, panel.get('name'), nick, ev.params.join(' '));\r
+ }\r
\r
- type = ev.params[0];\r
- ev.params.shift();\r
-\r
- _kiwi.gateway.ctcp(null, true, type, target, ev.params.join(' '));\r
+ function clearCommand (ev) {\r
+ // Can't clear a server or applet panel\r
+ if (_kiwi.app.panels().active.isServer() || _kiwi.app.panels().active.isApplet()) {\r
+ return;\r
}\r
\r
- function settingsCommand (ev) {\r
- var settings = _kiwi.model.Applet.loadOnce('kiwi_settings');\r
- settings.view.show();\r
+ if (_kiwi.app.panels().active.clearMessages) {\r
+ _kiwi.app.panels().active.clearMessages();\r
}\r
+ }\r
\r
- function scriptCommand (ev) {\r
- var editor = _kiwi.model.Applet.loadOnce('kiwi_script_editor');\r
- editor.view.show();\r
- }\r
+ function ctcpCommand(ev) {\r
+ var target, type;\r
\r
- function appletCommand (ev) {\r
- if (!ev.params[0]) return;\r
+ // Make sure we have a target and a ctcp type (eg. version, time)\r
+ if (ev.params.length < 2) return;\r
\r
- var panel = new _kiwi.model.Applet();\r
+ target = ev.params[0];\r
+ ev.params.shift();\r
\r
- if (ev.params[1]) {\r
- // Url and name given\r
- panel.load(ev.params[0], ev.params[1]);\r
- } else {\r
- // Load a pre-loaded applet\r
- if (_kiwi.applets[ev.params[0]]) {\r
- panel.load(new _kiwi.applets[ev.params[0]]());\r
- } else {\r
- _kiwi.app.panels().server.addMsg('', _kiwi.global.i18n.translate('client_models_application_applet_notfound').fetch(ev.params[0]));\r
- return;\r
- }\r
- }\r
+ type = ev.params[0];\r
+ ev.params.shift();\r
\r
- _kiwi.app.connections.active_connection.panels.add(panel);\r
- panel.view.show();\r
- }\r
+ _kiwi.gateway.ctcp(null, true, type, target, ev.params.join(' '));\r
+ }\r
\r
+ function settingsCommand (ev) {\r
+ var settings = _kiwi.model.Applet.loadOnce('kiwi_settings');\r
+ settings.view.show();\r
+ }\r
\r
+ function scriptCommand (ev) {\r
+ var editor = _kiwi.model.Applet.loadOnce('kiwi_script_editor');\r
+ editor.view.show();\r
+ }\r
\r
- function inviteCommand (ev) {\r
- var nick, channel;\r
+ function appletCommand (ev) {\r
+ if (!ev.params[0]) return;\r
\r
- // A nick must be specified\r
- if (!ev.params[0])\r
- return;\r
+ var panel = new _kiwi.model.Applet();\r
\r
- // Can only invite into channels\r
- if (!_kiwi.app.panels().active.isChannel())\r
+ if (ev.params[1]) {\r
+ // Url and name given\r
+ panel.load(ev.params[0], ev.params[1]);\r
+ } else {\r
+ // Load a pre-loaded applet\r
+ if (_kiwi.applets[ev.params[0]]) {\r
+ panel.load(new _kiwi.applets[ev.params[0]]());\r
+ } else {\r
+ _kiwi.app.panels().server.addMsg('', _kiwi.global.i18n.translate('client_models_application_applet_notfound').fetch(ev.params[0]));\r
return;\r
+ }\r
+ }\r
\r
- nick = ev.params[0];\r
- channel = _kiwi.app.panels().active.get('name');\r
+ _kiwi.app.connections.active_connection.panels.add(panel);\r
+ panel.view.show();\r
+ }\r
\r
- _kiwi.app.connections.active_connection.gateway.raw('INVITE ' + nick + ' ' + channel);\r
\r
- _kiwi.app.panels().active.addMsg('', '== ' + nick + ' has been invited to ' + channel, 'action');\r
- }\r
\r
+ function inviteCommand (ev) {\r
+ var nick, channel;\r
\r
- function whoisCommand (ev) {\r
- var nick;\r
+ // A nick must be specified\r
+ if (!ev.params[0])\r
+ return;\r
\r
- if (ev.params[0]) {\r
- nick = ev.params[0];\r
- } else if (_kiwi.app.panels().active.isQuery()) {\r
- nick = _kiwi.app.panels().active.get('name');\r
- }\r
+ // Can only invite into channels\r
+ if (!_kiwi.app.panels().active.isChannel())\r
+ return;\r
\r
- if (nick)\r
- _kiwi.app.connections.active_connection.gateway.raw('WHOIS ' + nick + ' ' + nick);\r
- }\r
+ nick = ev.params[0];\r
+ channel = _kiwi.app.panels().active.get('name');\r
\r
+ _kiwi.app.connections.active_connection.gateway.raw('INVITE ' + nick + ' ' + channel);\r
\r
- function whowasCommand (ev) {\r
- var nick;\r
+ _kiwi.app.panels().active.addMsg('', '== ' + nick + ' has been invited to ' + channel, 'action');\r
+ }\r
\r
- if (ev.params[0]) {\r
- nick = ev.params[0];\r
- } else if (_kiwi.app.panels().active.isQuery()) {\r
- nick = _kiwi.app.panels().active.get('name');\r
- }\r
\r
- if (nick)\r
- _kiwi.app.connections.active_connection.gateway.raw('WHOWAS ' + nick);\r
- }\r
+ function whoisCommand (ev) {\r
+ var nick;\r
\r
- function encodingCommand (ev) {\r
- if (ev.params[0]) {\r
- _kiwi.gateway.setEncoding(null, ev.params[0], function (success) {\r
- if (success) {\r
- _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_changed').fetch(ev.params[0]));\r
- } else {\r
- _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_invalid').fetch(ev.params[0]));\r
- }\r
- });\r
- } else {\r
- _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_notspecified').fetch());\r
- _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_usage').fetch());\r
- }\r
+ if (ev.params[0]) {\r
+ nick = ev.params[0];\r
+ } else if (_kiwi.app.panels().active.isQuery()) {\r
+ nick = _kiwi.app.panels().active.get('name');\r
}\r
\r
- function serverCommand (ev) {\r
- var server, port, ssl, password, nick,\r
- tmp;\r
+ if (nick)\r
+ _kiwi.app.connections.active_connection.gateway.raw('WHOIS ' + nick + ' ' + nick);\r
+ }\r
\r
- // If no server address given, show the new connection dialog\r
- if (!ev.params[0]) {\r
- tmp = new _kiwi.view.MenuBox(_kiwi.global.i18n.translate('client_models_application_connection_create').fetch());\r
- tmp.addItem('new_connection', new _kiwi.model.NewConnection().view.$el);\r
- tmp.show();\r
\r
- // Center screen the dialog\r
- tmp.$el.offset({\r
- top: (that.view.$el.height() / 2) - (tmp.$el.height() / 2),\r
- left: (that.view.$el.width() / 2) - (tmp.$el.width() / 2)\r
- });\r
+ function whowasCommand (ev) {\r
+ var nick;\r
\r
- return;\r
- }\r
-\r
- // Port given in 'host:port' format and no specific port given after a space\r
- if (ev.params[0].indexOf(':') > 0) {\r
- tmp = ev.params[0].split(':');\r
- server = tmp[0];\r
- port = tmp[1];\r
+ if (ev.params[0]) {\r
+ nick = ev.params[0];\r
+ } else if (_kiwi.app.panels().active.isQuery()) {\r
+ nick = _kiwi.app.panels().active.get('name');\r
+ }\r
\r
- password = ev.params[1] || undefined;\r
+ if (nick)\r
+ _kiwi.app.connections.active_connection.gateway.raw('WHOWAS ' + nick);\r
+ }\r
\r
- } else {\r
- // Server + port given as 'host port'\r
- server = ev.params[0];\r
- port = ev.params[1] || 6667;\r
+ function encodingCommand (ev) {\r
+ if (ev.params[0]) {\r
+ _kiwi.gateway.setEncoding(null, ev.params[0], function (success) {\r
+ if (success) {\r
+ _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_changed').fetch(ev.params[0]));\r
+ } else {\r
+ _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_invalid').fetch(ev.params[0]));\r
+ }\r
+ });\r
+ } else {\r
+ _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_notspecified').fetch());\r
+ _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_encoding_usage').fetch());\r
+ }\r
+ }\r
\r
- password = ev.params[2] || undefined;\r
- }\r
+ function channelCommand (ev) {\r
+ var active_panel = _kiwi.app.panels().active;\r
\r
- // + in the port means SSL\r
- if (port.toString()[0] === '+') {\r
- ssl = true;\r
- port = parseInt(port.substring(1), 10);\r
- } else {\r
- ssl = false;\r
- }\r
+ if (!active_panel.isChannel())\r
+ return;\r
\r
- // Default port if one wasn't found\r
- port = port || 6667;\r
+ new _kiwi.model.ChannelInfo({channel: _kiwi.app.panels().active});\r
+ }\r
\r
- // Use the same nick as we currently have\r
- nick = _kiwi.app.connections.active_connection.get('nick');\r
+ function serverCommand (ev) {\r
+ var server, port, ssl, password, nick,\r
+ tmp;\r
\r
- _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_connection_connecting').fetch(server, port.toString()));\r
+ // If no server address given, show the new connection dialog\r
+ if (!ev.params[0]) {\r
+ tmp = new _kiwi.view.MenuBox(_kiwi.global.i18n.translate('client_models_application_connection_create').fetch());\r
+ tmp.addItem('new_connection', new _kiwi.model.NewConnection().view.$el);\r
+ tmp.show();\r
\r
- _kiwi.gateway.newConnection({\r
- nick: nick,\r
- host: server,\r
- port: port,\r
- ssl: ssl,\r
- password: password\r
- }, function(err, new_connection) {\r
- if (err)\r
- _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_connection_error').fetch(server, port.toString(), err.toString()));\r
+ // Center screen the dialog\r
+ tmp.$el.offset({\r
+ top: (this.view.$el.height() / 2) - (tmp.$el.height() / 2),\r
+ left: (this.view.$el.width() / 2) - (tmp.$el.width() / 2)\r
});\r
- }\r
\r
+ return;\r
+ }\r
\r
+ // Port given in 'host:port' format and no specific port given after a space\r
+ if (ev.params[0].indexOf(':') > 0) {\r
+ tmp = ev.params[0].split(':');\r
+ server = tmp[0];\r
+ port = tmp[1];\r
\r
+ password = ev.params[1] || undefined;\r
\r
+ } else {\r
+ // Server + port given as 'host port'\r
+ server = ev.params[0];\r
+ port = ev.params[1] || 6667;\r
\r
- this.isChannelName = function (channel_name) {\r
- var channel_prefix = _kiwi.gateway.get('channel_prefix');\r
+ password = ev.params[2] || undefined;\r
+ }\r
\r
- if (!channel_name || !channel_name.length) return false;\r
- return (channel_prefix.indexOf(channel_name[0]) > -1);\r
- };\r
+ // + in the port means SSL\r
+ if (port.toString()[0] === '+') {\r
+ ssl = true;\r
+ port = parseInt(port.substring(1), 10);\r
+ } else {\r
+ ssl = false;\r
+ }\r
\r
+ // Default port if one wasn't found\r
+ port = port || 6667;\r
\r
- };\r
+ // Use the same nick as we currently have\r
+ nick = _kiwi.app.connections.active_connection.get('nick');\r
\r
+ _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_connection_connecting').fetch(server, port.toString()));\r
\r
- model = Backbone.Model.extend(new model());\r
+ _kiwi.gateway.newConnection({\r
+ nick: nick,\r
+ host: server,\r
+ port: port,\r
+ ssl: ssl,\r
+ password: password\r
+ }, function(err, new_connection) {\r
+ if (err)\r
+ _kiwi.app.panels().active.addMsg('', _kiwi.global.i18n.translate('client_models_application_connection_error').fetch(server, port.toString(), err.toString()));\r
+ });\r
+ }\r
\r
- return new model(arguments);\r
-};\r
+})();\r