From: Darren Date: Sun, 2 Sep 2012 01:32:38 +0000 (+0100) Subject: Panel container refactor X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=48d660e691a549057262a955f09592c8b1d9f83f;p=KiwiIRC.git Panel container refactor --- diff --git a/client_backbone/index.html b/client_backbone/index.html index c506825..b9acb3b 100644 --- a/client_backbone/index.html +++ b/client_backbone/index.html @@ -82,6 +82,7 @@ $(function () { kiwi.app = new kiwi.model.Application({container: $('#kiwi')}); + kiwi.app.start(); }); diff --git a/client_backbone/model.js b/client_backbone/model.js index db18689..59af6d3 100644 --- a/client_backbone/model.js +++ b/client_backbone/model.js @@ -162,6 +162,10 @@ kiwi.model.Member = Backbone.Model.extend({ kiwi.model.PanelList = Backbone.Collection.extend({ model: kiwi.model.Panel, + + // Holds the active panel + active: null, + comparator: function (chan) { return chan.get("name"); }, @@ -173,8 +177,9 @@ kiwi.model.PanelList = Backbone.Collection.extend({ kiwi.gateway.on('change:name', this.view.render, this.view); this.add(this.server); - // Set the default view to the server tab - kiwi.current_panel = this.server; + this.bind('active', function (active_panel) { + this.active = active_panel; + }, this); }, getByName: function (name) { @@ -260,7 +265,8 @@ kiwi.model.Panel = Backbone.Model.extend({ this.destroy(); - if (this.cid === kiwi.current_panel.cid) { + // If closing the active panel, switch to the server panel + if (this.cid === kiwi.app.panels.active.cid) { kiwi.app.panels.server.view.show(); } }, diff --git a/client_backbone/model_application.js b/client_backbone/model_application.js index 2f508e3..0743b0b 100644 --- a/client_backbone/model_application.js +++ b/client_backbone/model_application.js @@ -10,7 +10,9 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { this.initialize = function () { // Update `that` with this new Model object that = this; + }; + this.start = function () { // Set the gateway up kiwi.gateway = new kiwi.model.Gateway(); this.bindGatewayCommands(kiwi.gateway); @@ -207,7 +209,7 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { c.set('topic', event.topic); // If this is the active channel, update the topic bar too - if (c.get('name') === kiwi.current_panel.get('name')) { + if (c.get('name') === kiwi.app.panels.active.get('name')) { that.topicbar.setCurrentTopic(event.topic); } }); @@ -389,25 +391,25 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { }; this.actionCommand = function (ev) { - if (kiwi.current_panel === kiwi.app.panels.server) { + if (kiwi.app.panels.active === kiwi.app.panels.server) { return; } - var panel = kiwi.current_panel; + var panel = kiwi.app.panels.active; panel.addMsg('', '* ' + kiwi.gateway.get('nick') + ' ' + ev.params.join(' '), 'action'); kiwi.gateway.action(panel.get('name'), ev.params.join(' ')); }; this.partCommand = function (ev) { if (ev.params.length === 0) { - kiwi.gateway.part(kiwi.current_panel.get('name')); + kiwi.gateway.part(kiwi.app.panels.active.get('name')); } else { _.each(ev.params, function (channel) { kiwi.gateway.part(channel); }); } // TODO: More responsive = close tab now, more accurate = leave until part event - //kiwi.app.panels.remove(kiwi.current_panel); + //kiwi.app.panels.remove(kiwi.app.panels.active); }; this.topicCommand = function (ev) { @@ -419,7 +421,7 @@ kiwi.model.Application = Backbone.Model.extend(new (function () { channel_name = ev.params[0]; ev.params.shift(); } else { - channel_name = kiwi.current_panel.get('name'); + channel_name = kiwi.app.panels.active.get('name'); } kiwi.gateway.topic(channel_name, ev.params.join(' ')); diff --git a/client_backbone/view.js b/client_backbone/view.js index e2de6e5..6a17376 100644 --- a/client_backbone/view.js +++ b/client_backbone/view.js @@ -220,16 +220,12 @@ kiwi.view.Panel = Backbone.View.extend({ this.$container.parent().css('right', '0'); } - // TODO: Why is kiwi.app not defined when this is fist called :/ - if (kiwi.app) { - kiwi.app.topicbar.setCurrentTopic(this.model.get("topic") || ""); - } + kiwi.app.topicbar.setCurrentTopic(this.model.get("topic") || ""); this.scrollToBottom(); - kiwi.current_panel = this.model; - this.trigger('active', this.model); + kiwi.app.panels.trigger('active', this.model); }, @@ -254,7 +250,7 @@ kiwi.view.Channel = kiwi.view.Panel.extend({ this.model.addMsg('', '=== Topic for ' + this.model.get('name') + ' is: ' + topic, 'topic'); // If this is the active channel then update the topic bar - if (kiwi.current_panel === this) { + if (kiwi.app.panels.active === this) { kiwi.app.topicbar.setCurrentTopic(this.model.get("topic")); } } @@ -352,8 +348,8 @@ kiwi.view.TopicBar = Backbone.View.extend({ if (ev.keyCode !== 13) return; - if (kiwi.current_panel.isChannel && kiwi.current_panel.isChannel()) { - kiwi.gateway.topic(kiwi.current_panel.get('name'), inp_val); + if (kiwi.app.panels.active.isChannel()) { + kiwi.gateway.topic(kiwi.app.panels.active.get('name'), inp_val); } }, @@ -427,7 +423,7 @@ kiwi.view.ControlBox = Backbone.View.extend({ } else { // Default command command = 'msg'; - params.unshift(kiwi.current_panel.get('name')); + params.unshift(kiwi.app.panels.active.get('name')); } // Trigger the command events