Commit d985b7ae authored by JC Brand's avatar JC Brand

More bugfixes.

Specifically handle the case where a chatbox was destroyed, and then opened again.
We still have the view, so we reuse it.
parent efad677f
...@@ -447,7 +447,7 @@ ...@@ -447,7 +447,7 @@
this.model.destroy(); this.model.destroy();
}, },
rosterChanged: function () { rosterChanged: function (item, changed) {
// FIXME: This event handler should go onto the roster itself, then it // FIXME: This event handler should go onto the roster itself, then it
// will be called once (for the roster) and not once per open // will be called once (for the roster) and not once per open
// chatbox // chatbox
...@@ -477,11 +477,7 @@ ...@@ -477,11 +477,7 @@
$('body').append(this.$el.hide()); $('body').append(this.$el.hide());
this.model.messages.on('add', this.showMessage, this); this.model.messages.on('add', this.showMessage, this);
this.model.on('show', function() { this.model.on('show', this.show, this);
this.show();
this.model.save();
}, this);
this.model.on('destroy', function (model, response, options) { this.model.on('destroy', function (model, response, options) {
this.$el.hide('fast'); this.$el.hide('fast');
}, this); }, this);
...@@ -515,10 +511,10 @@ ...@@ -515,10 +511,10 @@
var img_src = 'data:'+this.model.get('image_type')+';base64,'+this.model.get('image'); var img_src = 'data:'+this.model.get('image_type')+';base64,'+this.model.get('image');
var ctx = this.$el.find('canvas').get(0).getContext('2d'); var ctx = this.$el.find('canvas').get(0).getContext('2d');
var img = new Image(); // Create new Image object var img = new Image(); // Create new Image object
img.onload = function(){ img.onload = function() {
var ratio = img.width/img.height; var ratio = img.width/img.height;
ctx.drawImage(img,0,0, 35*ratio, 35); ctx.drawImage(img,0,0, 35*ratio, 35);
} };
img.src = img_src; img.src = img_src;
return this; return this;
}, },
...@@ -533,10 +529,7 @@ ...@@ -533,10 +529,7 @@
}, },
show: function () { show: function () {
this.$el.css({'opacity': 0, this.$el.css({'opacity': 0, 'display': 'inline'}) .animate({opacity: '1'}, 200);
'display': 'inline'})
.animate({opacity: '1'}, 200);
this.model.set({'visible': true});
if (xmppchat.connection) { if (xmppchat.connection) {
// Without a connection, we haven't yet initialized // Without a connection, we haven't yet initialized
// localstorage // localstorage
...@@ -738,9 +731,16 @@ ...@@ -738,9 +731,16 @@
this.model.on('destroy', $.proxy(function (model, response, options) { this.model.on('destroy', $.proxy(function (model, response, options) {
this.$el.hide('fast'); this.$el.hide('fast');
}, this)); }, this));
if (this.model.get('visible')) {
this.show();
}
}, },
setUpRoster: function () { setUpRoster: function () {
if (xmppchat.roster) {
return;
}
xmppchat.roster = new xmppchat.RosterItems(); xmppchat.roster = new xmppchat.RosterItems();
xmppchat.roster.localStorage = new Backbone.LocalStorage( xmppchat.roster.localStorage = new Backbone.LocalStorage(
hex_sha1('converse.rosteritems-'+xmppchat.connection.bare_jid)); hex_sha1('converse.rosteritems-'+xmppchat.connection.bare_jid));
...@@ -1123,14 +1123,24 @@ ...@@ -1123,14 +1123,24 @@
// boxesviewinit // boxesviewinit
this.views = {}; this.views = {};
this.options.model.on("add", function (item) { this.options.model.on("add", function (item) {
var view; var view = this.views[item.get('id')];
if (item.get('box_id') === 'controlbox') { if (!view) {
view = new xmppchat.ControlBoxView({model: item}); if (item.get('box_id') === 'controlbox') {
view = new xmppchat.ControlBoxView({model: item});
view.render();
} else {
view = new xmppchat.ChatBoxView({model: item});
}
this.views[item.get('id')] = view;
view.$el.appendTo(this.$el);
} else { } else {
view = new xmppchat.ChatBoxView({model: item}); view.model = item;
view.initialize();
if (item.get('id') !== 'controlbox') {
// FIXME: Why is it necessary to append chatboxes again?
view.$el.appendTo(this.$el);
}
} }
this.views[item.get('id')] = view;
view.$el.appendTo(this.$el);
}, this); }, this);
} }
}); });
...@@ -1973,10 +1983,8 @@ ...@@ -1973,10 +1983,8 @@
this.chatboxes.get('controlbox').destroy(); this.chatboxes.get('controlbox').destroy();
} else { } else {
var controlbox = this.chatboxes.get('controlbox'); var controlbox = this.chatboxes.get('controlbox');
if (controlbox) { if (!controlbox) {
controlbox.trigger('show'); controlbox = this.chatboxes.create({
} else {
this.chatboxes.create({
id: 'controlbox', id: 'controlbox',
box_id: 'controlbox', box_id: 'controlbox',
visible: true visible: true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment