Fix tests and simplify code for showing controlbox

This commit is contained in:
JC Brand 2014-03-01 08:21:36 +02:00
parent 4f2125c20e
commit c030494ef0

View File

@ -644,7 +644,7 @@
this.ChatBox = Backbone.Model.extend({ this.ChatBox = Backbone.Model.extend({
initialize: function () { initialize: function () {
var height; var height = converse.applyHeightResistance(this.get('height'));
if (this.get('box_id') !== 'controlbox') { if (this.get('box_id') !== 'controlbox') {
this.messages = new converse.Messages(); this.messages = new converse.Messages();
this.messages.localStorage = new Backbone.LocalStorage( this.messages.localStorage = new Backbone.LocalStorage(
@ -654,8 +654,10 @@
'box_id' : hex_sha1(this.get('jid')), 'box_id' : hex_sha1(this.get('jid')),
'otr_status': this.get('otr_status') || UNENCRYPTED, 'otr_status': this.get('otr_status') || UNENCRYPTED,
'minimized': this.get('minimized') || false, 'minimized': this.get('minimized') || false,
'height': converse.applyHeightResistance(this.get('height')) 'height': height
}); });
} else {
this.set({'height': height});
} }
}, },
@ -1786,18 +1788,10 @@
this.featureAdded(feature); this.featureAdded(feature);
} }
} }
if (_.has(item.changed, 'visible')) {
if (item.changed.visible === true) {
this.show();
}
}
}, this)); }, this));
this.model.on('show', this.show, this); this.model.on('show', this.show, this);
this.model.on('destroy', this.hide, this); this.model.on('destroy', this.hide, this);
this.model.on('hide', this.hide, this); this.model.on('hide', this.hide, this);
if (this.model.get('visible')) {
this.show();
}
}, },
render: function () { render: function () {
@ -2402,7 +2396,7 @@
} }
this.get('controlbox').fetch(); this.get('controlbox').fetch();
// This line below will make sure the Roster is set up // This line below will make sure the Roster is set up
this.get('controlbox').save({connected:true}); this.get('controlbox').set({connected:true});
this.registerMessageHandler(); this.registerMessageHandler();
// Get cached chatboxes from localstorage // Get cached chatboxes from localstorage
this.fetch({ this.fetch({
@ -2410,7 +2404,7 @@
success: $.proxy(function (collection, resp) { success: $.proxy(function (collection, resp) {
if (_.include(_.pluck(resp, 'id'), 'controlbox')) { if (_.include(_.pluck(resp, 'id'), 'controlbox')) {
// If the controlbox was saved in localstorage, it must be visible // If the controlbox was saved in localstorage, it must be visible
this.get('controlbox').set({visible:true}).save(); this.get('controlbox').trigger('show');
} }
}, this) }, this)
}); });
@ -3437,15 +3431,14 @@
converse.chatboxes.add({ converse.chatboxes.add({
id: 'controlbox', id: 'controlbox',
box_id: 'controlbox', box_id: 'controlbox',
visible: true,
height: converse.default_box_height height: converse.default_box_height
}); });
controlbox = converse.chatboxes.get('controlbox');
if (converse.connection) { if (converse.connection) {
converse.chatboxes.get('controlbox').save(); converse.chatboxes.get('controlbox').save();
} }
} else {
controlbox.trigger('show');
} }
controlbox.trigger('show');
}, },
onClick: function (e) { onClick: function (e) {