Move roster change listener to a seprate method.
Move render, show and message fetching from ChatBoxesViews to ChatBoxView
This commit is contained in:
parent
1e3427adcf
commit
75cb595d50
72
converse.js
72
converse.js
@ -448,29 +448,13 @@
|
||||
},
|
||||
|
||||
closeChat: function () {
|
||||
this.model.set({'visible': false})
|
||||
this.model.destroy();
|
||||
},
|
||||
|
||||
initialize: function (){
|
||||
$('body').append(this.$el.hide());
|
||||
this.model.messages.on('add', function (item) {
|
||||
this.messageReceived(item);
|
||||
}, this);
|
||||
|
||||
this.model.on('change', $.proxy(function (item, changed) {
|
||||
if (_.has(item.changed, 'visible')) {
|
||||
if (item.changed['visible'] === true) {
|
||||
this.show();
|
||||
} else {
|
||||
this.$el.hide('fast', function () {
|
||||
this.remove();
|
||||
item.destroy();
|
||||
});
|
||||
}
|
||||
}
|
||||
}, this));
|
||||
|
||||
xmppchat.roster.on('change', function (item, changed) {
|
||||
rosterChanged: function () {
|
||||
// FIXME: This event handler should go onto the roster itself, then it
|
||||
// will be called once (for the roster) and not once per open
|
||||
// chatbox
|
||||
var fullname = this.model.get('fullname'),
|
||||
chat_status = item.get('chat_status');
|
||||
if (item.get('jid') === this.model.get('jid')) {
|
||||
@ -490,7 +474,20 @@
|
||||
this.$el.find('p.user-custom-message').text(item.get('status')).attr('title', item.get('status'));
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
},
|
||||
|
||||
initialize: function (){
|
||||
// boxviewinit
|
||||
$('body').append(this.$el.hide());
|
||||
this.model.messages.on('add', this.messageReceived, this);
|
||||
|
||||
this.model.on('destroy', $.proxy(function (model, response, options) {
|
||||
this.$el.hide('fast');
|
||||
}, this));
|
||||
|
||||
xmppchat.roster.on('change', this.rosterChanged, this);
|
||||
|
||||
this.render().show().model.messages.fetch({add: true});
|
||||
},
|
||||
|
||||
template: _.template(
|
||||
@ -731,14 +728,13 @@
|
||||
if (_.has(item.changed, 'visible')) {
|
||||
if (item.changed['visible'] === true) {
|
||||
this.show();
|
||||
} else {
|
||||
this.$el.hide('fast', function () {
|
||||
this.remove();
|
||||
item.destroy();
|
||||
});
|
||||
}
|
||||
}
|
||||
}, this));
|
||||
|
||||
this.model.on('destroy', $.proxy(function (model, response, options) {
|
||||
this.$el.hide('fast');
|
||||
}, this));
|
||||
},
|
||||
|
||||
setUpRoster: function () {
|
||||
@ -1047,7 +1043,6 @@
|
||||
add: true, success:
|
||||
$.proxy(function (collection, resp) {
|
||||
if (_.include(_.pluck(resp, 'id'), 'controlbox')) {
|
||||
// FIXME:
|
||||
// If the controlbox was saved in localstorage, it must be visible
|
||||
this.get('controlbox').set({visible:true})
|
||||
}
|
||||
@ -1089,13 +1084,6 @@
|
||||
return model;
|
||||
},
|
||||
|
||||
closeChat: function (jid) {
|
||||
var view = this.views[jid];
|
||||
if (view) {
|
||||
view.closeChat();
|
||||
}
|
||||
},
|
||||
|
||||
openControlBox: function () {
|
||||
if (this.model.get('controlbox')) {
|
||||
this.showChat('controlbox');
|
||||
@ -1192,23 +1180,17 @@
|
||||
},
|
||||
|
||||
initialize: function () {
|
||||
// boxesviewinit
|
||||
this.views = {};
|
||||
this.options.model.on("add", function (item) {
|
||||
var view;
|
||||
if (item.get('box_id') === 'controlbox') {
|
||||
view = new xmppchat.ControlBoxView({model: item});
|
||||
this.views['controlbox'] = view.render();
|
||||
view.$el.appendTo(this.$el);
|
||||
} else {
|
||||
view = new xmppchat.ChatBoxView({model: item});
|
||||
// Fetch messages from localstorage
|
||||
this.views[item.get('id')] = view.render();
|
||||
}
|
||||
this.views[item.get('id')] = view;
|
||||
view.$el.appendTo(this.$el);
|
||||
view.model.messages.fetch({add: true});
|
||||
if (item.get('visible')) {
|
||||
this.showChat(item.get('id'));
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
});
|
||||
@ -2036,7 +2018,7 @@
|
||||
$toggle.bind('click', $.proxy(function (e) {
|
||||
e.preventDefault();
|
||||
if ($("div#controlbox").is(':visible')) {
|
||||
this.chatboxesview.closeChat('controlbox');
|
||||
this.chatboxes.get('controlbox').destroy();
|
||||
} else {
|
||||
this.chatboxesview.openControlBox();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user