\r
\r
var model = function () {\r
- /** Instance of _kiwi.model.PanelList */\r
- this.panels = null;\r
-\r
/** _kiwi.view.Application */\r
this.view = null;\r
\r
\r
// Takes instances of model_network\r
this.connections = new _kiwi.model.NetworkPanelList();\r
- this.connections.on('active', this.onPanelActive, this);\r
-\r
- // The active network (reference to a this.connections element)\r
- this.active_connection = null;\r
};\r
\r
\r
\r
this.view.barsHide(true);\r
\r
- this.panels.server.server_login.bind('server_connect', function (event) {\r
+ this.connections.getByConnectionId(0).panels.server.server_login.bind('server_connect', function (event) {\r
var server_login = this,\r
transport_path = '';\r
auto_connect_details = event;\r
// TODO: Shouldn't really be here but it's not working in the view.. :/\r
// Hack for firefox browers: Focus is not given on this event loop iteration\r
setTimeout(function(){\r
- _kiwi.app.panels.server.server_login.$el.find('.nick').select();\r
+ _kiwi.app.connections.getByConnectionId(0).panels.server.server_login.$el.find('.nick').select();\r
}, 0);\r
};\r
\r
\r
function kiwiServerNotFound (e) {\r
- that.panels.server.server_login.showError();\r
+ that.connections.getByConnectionId(0).panels.server.server_login.showError();\r
}\r
\r
\r
* It all gets moved over\r
*/\r
var connection = new _kiwi.model.Network({connection_id: 0});\r
- _kiwi.app.connections.add(connection);\r
- this.panels = connection.panels;\r
+ this.connections.add(connection);\r
\r
/**\r
* Set the UI components up\r
\r
this.resize_handle = new _kiwi.view.ResizeHandler({el: $('#memberlists_resize_handle')[0]});\r
\r
- this.panels.server.view.show();\r
+ this.connections.getByConnectionId(0).panels.server.view.show();\r
\r
// Rejigg the UI sizes\r
this.view.doLayout();\r
\r
\r
this.initializeGlobals = function () {\r
- _kiwi.global.panels = this.panels;\r
+ _kiwi.global.connections = this.connections;\r
\r
_kiwi.global.components.Applet = _kiwi.model.Applet;\r
_kiwi.global.components.Panel =_kiwi.model.Panel;\r
defaults.nick = defaults.nick.replace('?', Math.floor(Math.random() * 100000).toString());\r
\r
// Populate the server select box with defaults\r
- this.panels.server.server_login.populateFields(defaults);\r
+ this.connections.getByConnectionId(0).panels.server.server_login.populateFields(defaults);\r
};\r
\r
\r
- // Clicking a tab\r
- this.onPanelActive = function (panel, connection) {\r
- this.panels = connection.panels;\r
- this.active_connection = connection;\r
- console.log('Active connection:', connection.get('connection_id'), 'Active panel:', panel.get('name'));\r
- };\r
+ this.panels = (function() {\r
+ var fn = function() {\r
+ // Get a complete list of panels\r
+ var panels = this.connections.panels();\r
+\r
+ // Active panels / server\r
+ panels.active = this.connections.active_panel;\r
+ panels.server = this.connections.active_connection.panels.server;\r
+\r
+ return panels;\r
+ };\r
+\r
+ _.extend(fn, Backbone.Events);\r
+\r
+ return fn;\r
+ })();\r
\r
\r
this.bindGatewayCommands = function (gw) {\r
that.view.$el.removeClass('connected');\r
\r
// Mention the disconnection on every channel\r
- $.each(_kiwi.app.panels.models, function (idx, panel) {\r
+ $.each(_kiwi.app.connections.getByConnectionId(0).panels.models, function (idx, panel) {\r
if (!panel || !panel.isChannel()) return;\r
panel.addMsg('', msg, 'action quit');\r
});\r
- _kiwi.app.panels.server.addMsg('', msg, 'action quit');\r
+ _kiwi.app.connections.getByConnectionId(0).panels.server.addMsg('', msg, 'action quit');\r
\r
gw_stat = 1;\r
});\r
gw.on('reconnecting', function (event) {\r
msg = 'You have been disconnected. Attempting to reconnect again in ' + (event.delay/1000) + ' seconds..';\r
- _kiwi.app.panels.server.addMsg('', msg, 'action quit');\r
+ _kiwi.app.connections.getByConnectionId(0).panels.server.addMsg('', msg, 'action quit');\r
});\r
gw.on('onconnect', function (event) {\r
that.view.$el.addClass('connected');\r
that.message.text(msg, {timeout: 5000});\r
\r
// Mention the disconnection on every channel\r
- $.each(_kiwi.app.panels.models, function (idx, panel) {\r
+ $.each(_kiwi.app.connections.getByConnectionId(0).panels.models, function (idx, panel) {\r
if (!panel || !panel.isChannel()) return;\r
panel.addMsg('', msg, 'action join');\r
});\r
- _kiwi.app.panels.server.addMsg('', msg, 'action join');\r
+ _kiwi.app.connections.getByConnectionId(0).panels.server.addMsg('', msg, 'action join');\r
\r
gw_stat = 0;\r
});\r
}\r
\r
// Read the value to the user\r
- _kiwi.app.panels.active.addMsg('', setting + ' = ' + _kiwi.global.settings.get(setting).toString());\r
+ _kiwi.app.panels().active.addMsg('', setting + ' = ' + _kiwi.global.settings.get(setting).toString());\r
});\r
\r
\r
controlbox.on('command:save', function (ev) {\r
_kiwi.global.settings.save();\r
- _kiwi.app.panels.active.addMsg('', 'Settings have been saved');\r
+ _kiwi.app.panels().active.addMsg('', 'Settings have been saved');\r
});\r
\r
\r
// No parameters passed so list them\r
if (!ev.params[1]) {\r
$.each(controlbox.preprocessor.aliases, function (name, rule) {\r
- _kiwi.app.panels.server.addMsg(' ', name + ' => ' + rule);\r
+ _kiwi.app.panels().server.addMsg(' ', name + ' => ' + rule);\r
});\r
return;\r
}\r
// No parameters passed so list them\r
if (!ev.params[0]) {\r
if (list.length > 0) {\r
- _kiwi.app.panels.active.addMsg(' ', 'Ignored nicks:');\r
+ _kiwi.app.panels().active.addMsg(' ', 'Ignored nicks:');\r
$.each(list, function (idx, ignored_pattern) {\r
- _kiwi.app.panels.active.addMsg(' ', ignored_pattern);\r
+ _kiwi.app.panels().active.addMsg(' ', ignored_pattern);\r
});\r
} else {\r
- _kiwi.app.panels.active.addMsg(' ', 'Not ignoring anybody');\r
+ _kiwi.app.panels().active.addMsg(' ', 'Not ignoring anybody');\r
}\r
return;\r
}\r
// We have a parameter, so add it\r
list.push(ev.params[0]);\r
_kiwi.gateway.set('ignore_list', list);\r
- _kiwi.app.panels.active.addMsg(' ', 'Ignoring ' + ev.params[0]);\r
+ _kiwi.app.panels().active.addMsg(' ', 'Ignoring ' + ev.params[0]);\r
});\r
\r
\r
var list = _kiwi.gateway.get('ignore_list');\r
\r
if (!ev.params[0]) {\r
- _kiwi.app.panels.active.addMsg(' ', 'Specifiy which nick you wish to stop ignoring');\r
+ _kiwi.app.panels().active.addMsg(' ', 'Specifiy which nick you wish to stop ignoring');\r
return;\r
}\r
\r
\r
_kiwi.gateway.set('ignore_list', list);\r
\r
- _kiwi.app.panels.active.addMsg(' ', 'Stopped ignoring ' + ev.params[0]);\r
+ _kiwi.app.panels().active.addMsg(' ', 'Stopped ignoring ' + ev.params[0]);\r
});\r
\r
\r
\r
// If not a valid channel name, display a warning\r
if (!that.isChannelName(channel_name)) {\r
- _kiwi.app.panels.server.addMsg('', channel_name + ' is not a valid channel name');\r
+ _kiwi.app.panels().server.addMsg('', channel_name + ' is not a valid channel name');\r
_kiwi.app.message.text(channel_name + ' is not a valid channel name', {timeout: 5000});\r
return;\r
}\r
\r
// Check if we have the panel already. If not, create it\r
- channel = that.panels.getByName(channel_name);\r
+ channel = that.connections.active_connection.panels.getByName(channel_name);\r
if (!channel) {\r
channel = new _kiwi.model.Channel({name: channel_name});\r
- _kiwi.app.panels.add(channel);\r
+ _kiwi.app.connections.active_connection.panels.add(channel);\r
}\r
\r
_kiwi.gateway.join(channel_name, channel_key);\r
destination = ev.params[0];\r
\r
// Check if we have the panel already. If not, create it\r
- panel = that.panels.getByName(destination);\r
+ panel = that.connections.active_connection.panels.getByName(destination);\r
if (!panel) {\r
panel = new _kiwi.model.Query({name: destination});\r
- _kiwi.app.panels.add(panel);\r
+ that.connections.active_connection.panels.add(panel);\r
}\r
\r
if (panel) panel.view.show();\r
\r
function msgCommand (ev) {\r
var destination = ev.params[0],\r
- panel = that.panels.getByName(destination) || that.panels.server;\r
+ panel = that.connections.active_connection.panels.getByName(destination) || that.panels().server;\r
\r
ev.params.shift();\r
\r
}\r
\r
function actionCommand (ev) {\r
- if (_kiwi.app.panels.active === _kiwi.app.panels.server) {\r
+ if (_kiwi.app.panels().active.isServer()) {\r
return;\r
}\r
\r
- var panel = _kiwi.app.panels.active;\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(panel.get('name'), ev.params.join(' '));\r
}\r
\r
function partCommand (ev) {\r
if (ev.params.length === 0) {\r
- _kiwi.gateway.part(_kiwi.app.panels.active.get('name'));\r
+ _kiwi.gateway.part(_kiwi.app.panels().active.get('name'));\r
} else {\r
_.each(ev.params, function (channel) {\r
_kiwi.gateway.part(channel);\r
});\r
}\r
- // TODO: More responsive = close tab now, more accurate = leave until part event\r
- //_kiwi.app.panels.remove(_kiwi.app.panels.active);\r
}\r
\r
function topicCommand (ev) {\r
channel_name = ev.params[0];\r
ev.params.shift();\r
} else {\r
- channel_name = _kiwi.app.panels.active.get('name');\r
+ channel_name = _kiwi.app.panels().active.get('name');\r
}\r
\r
_kiwi.gateway.topic(channel_name, ev.params.join(' '));\r
}\r
\r
function kickCommand (ev) {\r
- var nick, panel = _kiwi.app.panels.active;\r
+ var nick, panel = _kiwi.app.panels().active;\r
\r
if (!panel.isChannel()) return;\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
+ if (_kiwi.app.panels().active.isServer() || _kiwi.app.panels().active.isApplet()) {\r
return;\r
}\r
\r
- if (_kiwi.app.panels.active.clearMessages) {\r
- _kiwi.app.panels.active.clearMessages();\r
+ if (_kiwi.app.panels().active.clearMessages) {\r
+ _kiwi.app.panels().active.clearMessages();\r
}\r
}\r
\r
if (_kiwi.applets[ev.params[0]]) {\r
panel.load(new _kiwi.applets[ev.params[0]]());\r
} else {\r
- _kiwi.app.panels.server.addMsg('', 'Applet "' + ev.params[0] + '" does not exist');\r
+ _kiwi.app.panels().server.addMsg('', 'Applet "' + ev.params[0] + '" does not exist');\r
return;\r
}\r
}\r
\r
- _kiwi.app.panels.add(panel);\r
+ _kiwi.app.connections.active_connection.panels.add(panel);\r
panel.view.show();\r
}\r
\r
\r
\r
this.eachPanel = function (fn) {\r
+ alert('Switch this call with _kiwi.app.panels! location in console.log');\r
+ console.log('Switch this call with _kiwi.app.panels! location in console.log');\r
if (typeof fn !== 'function')\r
return;\r
\r
\r
queryClick: function (event) {\r
var panel = new _kiwi.model.Query({name: this.member.get('nick')});\r
- _kiwi.app.panels.add(panel);\r
+ _kiwi.app.connections.active_connection.panels.add(panel);\r
panel.view.show();\r
},\r
\r
(function () {\r
// Only inrement the counters if we're not the active panel\r
if (this.model.isActive()) return;\r
-console.log('Updating activity');\r
+\r
var $act = this.model.tab.find('.activity');\r
$act.text((parseInt($act.text(), 10) || 0) + 1);\r
if ($act.text() === '0') {\r
this.alert('none');\r
this.model.tab.find('.activity').text('0').addClass('zero');\r
\r
- this.trigger('active', this.model);\r
- _kiwi.app.panels.trigger('active', this.model, _kiwi.app.panels.active);\r
+ _kiwi.app.panels.trigger('active', this.model, _kiwi.app.panels().active);\r
+ this.model.trigger('active', this.model);\r
\r
this.scrollToBottom(true);\r
},\r
\r
alert: function (level) {\r
// No need to highlight if this si the active panel\r
- if (this.model == _kiwi.app.panels.active) return;\r
+ if (this.model == _kiwi.app.panels().active) return;\r
\r
var types, type_idx;\r
types = ['none', 'action', 'activity', 'highlight'];\r
// Scroll to the bottom of the panel\r
scrollToBottom: function (force_down) {\r
// If this isn't the active panel, don't scroll\r
- if (this.model !== _kiwi.app.panels.active) return;\r
+ if (this.model !== _kiwi.app.panels().active) return;\r
\r
// Don't scroll down if we're scrolled up the panel a little\r
if (force_down || this.$container.scrollTop() + this.$container.height() > this.$el.outerHeight() - 150) {\r
this.model.addMsg('', '== Topic for ' + this.model.get('name') + ' is: ' + topic, 'topic');\r
\r
// If this is the active channel then update the topic bar\r
- if (_kiwi.app.panels.active === this) {\r
+ if (_kiwi.app.panels().active === this) {\r
_kiwi.app.topicbar.setCurrentTopic(this.model.get("topic"));\r
}\r
}\r
inp_val = inp.text();\r
\r
// Only allow topic editing if this is a channel panel\r
- if (!_kiwi.app.panels.active.isChannel()) {\r
+ if (!_kiwi.app.panels().active.isChannel()) {\r
return false;\r
}\r
\r
// If hit return key, update the current topic\r
if (ev.keyCode === 13) {\r
- _kiwi.gateway.topic(_kiwi.app.panels.active.get('name'), inp_val);\r
+ _kiwi.gateway.topic(_kiwi.app.panels().active.get('name'), inp_val);\r
return false;\r
}\r
},\r
this.tabcomplete.active = true;\r
if (_.isEqual(this.tabcomplete.data, [])) {\r
// Get possible autocompletions\r
- var ac_data = [];\r
- $.each(_kiwi.app.panels.active.get('members').models, function (i, member) {\r
+ var ac_data = [],\r
+ members = _kiwi.app.panels().active.get('members');\r
+\r
+ // If we have a members list, get the models. Otherwise empty array\r
+ members = members ? members.models : [];\r
+\r
+ $.each(members, function (i, member) {\r
if (!member) return;\r
ac_data.push(member.get('nick'));\r
});\r
+\r
+ ac_data.push(_kiwi.app.panels().active.get('name'));\r
+\r
ac_data = _.sortBy(ac_data, function (nick) {\r
return nick;\r
});\r
command_raw = command_raw.replace(/^\/\//, '/');\r
\r
// Prepend the default command\r
- command_raw = '/msg ' + _kiwi.app.panels.active.get('name') + ' ' + command_raw;\r
+ command_raw = '/msg ' + _kiwi.app.panels().active.get('name') + ' ' + command_raw;\r
}\r
\r
// Process the raw command for any aliases\r
this.preprocessor.vars.server = _kiwi.app.connections.active_connection.get('name');\r
- this.preprocessor.vars.channel = _kiwi.app.panels.active.get('name');\r
+ this.preprocessor.vars.channel = _kiwi.app.panels().active.get('name');\r
this.preprocessor.vars.destination = this.preprocessor.vars.channel;\r
command_raw = this.preprocessor.process(command_raw);\r
\r
} else {\r
// Default command\r
command = 'msg';\r
- params.unshift(_kiwi.app.panels.active.get('name'));\r
+ params.unshift(_kiwi.app.panels().active.get('name'));\r
}\r
\r
// Trigger the command events\r