Refactored RosterView
So that it doesn't depend on it's element already being in the DOM
This commit is contained in:
parent
f699fbdbf5
commit
8bb1ee06b6
40
converse.js
40
converse.js
@ -599,8 +599,7 @@
|
||||
'<button type="submit">Search</button>'+
|
||||
'<ul id="found-users"></ul>'+
|
||||
'</form>'+
|
||||
'</div>'+
|
||||
'<dl id="xmppchat-roster"></dl>'
|
||||
'</div>'
|
||||
),
|
||||
|
||||
render: function () {
|
||||
@ -1138,22 +1137,28 @@
|
||||
}
|
||||
}, this);
|
||||
this.views = {};
|
||||
|
||||
// Add the controlbox view and the panels
|
||||
this.views.controlbox = xmppchat.controlbox;
|
||||
this.views.controlbox.$el.appendTo(this.$el);
|
||||
this.views.controlbox.contactspanel = new xmppchat.ContactsPanel().render();
|
||||
// TODO: Only add the rooms panel if the server supports MUC
|
||||
this.views.controlbox.roomspanel = new xmppchat.RoomsPanel().render();
|
||||
var controlbox = xmppchat.controlbox;
|
||||
controlbox.$el.appendTo(this.$el);
|
||||
controlbox.contactspanel = new xmppchat.ContactsPanel().render();
|
||||
controlbox.roomspanel = new xmppchat.RoomsPanel().render(); // TODO: Only add the rooms panel if the server supports MUC
|
||||
|
||||
// Add the roster
|
||||
xmppchat.roster = new xmppchat.RosterItems();
|
||||
xmppchat.rosterview = new xmppchat.RosterView({'model':xmppchat.roster}).render();
|
||||
xmppchat.rosterview.$el.appendTo(controlbox.contactspanel.$el);
|
||||
|
||||
// Rebind events (necessary for click events on tabs inserted via the panels)
|
||||
this.views.controlbox.delegateEvents();
|
||||
controlbox.delegateEvents();
|
||||
// Add the controlbox model to this collection (will trigger showChat)
|
||||
this.options.model.add(xmppchat.controlbox.options.model);
|
||||
|
||||
this.views.controlbox = controlbox;
|
||||
this.restoreOpenChats();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
xmppchat.RosterItem = Backbone.Model.extend({
|
||||
|
||||
initialize: function (jid, subscription, ask, name) {
|
||||
@ -1202,7 +1207,7 @@
|
||||
$(this).dialog( "close" );
|
||||
xmppchat.connection.roster.remove(bare_jid, function (iq) {
|
||||
xmppchat.connection.roster.unauthorize(bare_jid);
|
||||
xmppchat.roster.remove(bare_jid);
|
||||
xmppchat.chatboxesview.controlbox.roster.remove(bare_jid);
|
||||
});
|
||||
},
|
||||
"Cancel": function() {
|
||||
@ -1489,7 +1494,7 @@
|
||||
*/
|
||||
xmppchat.xmppstatus.sendPresence('unsubscribe');
|
||||
if (xmppchat.connection.roster.findItem(bare_jid)) {
|
||||
xmppchat.roster.remove(bare_jid);
|
||||
xmppchat.chatboxesview.controlbox.roster.remove(bare_jid);
|
||||
xmppchat.connection.roster.remove(bare_jid);
|
||||
}
|
||||
} else {
|
||||
@ -1522,10 +1527,9 @@
|
||||
}
|
||||
});
|
||||
|
||||
xmppchat.RosterView= (function (roster, _, $, console) {
|
||||
var View = Backbone.View.extend({
|
||||
el: $('#xmppchat-roster'),
|
||||
model: roster,
|
||||
xmppchat.RosterView = Backbone.View.extend({
|
||||
tagName: 'dl',
|
||||
id: 'xmppchat-roster',
|
||||
rosteritemviews: {},
|
||||
|
||||
initialize: function () {
|
||||
@ -1594,11 +1598,9 @@
|
||||
});
|
||||
$count = $('#online-count');
|
||||
$count.text(this.model.getNumOnlineContacts());
|
||||
return this;
|
||||
}
|
||||
});
|
||||
var view = new View();
|
||||
return view;
|
||||
});
|
||||
|
||||
xmppchat.XMPPStatus = Backbone.Model.extend({
|
||||
|
||||
@ -1789,8 +1791,6 @@
|
||||
this.chatboxes = new this.ChatBoxes();
|
||||
this.chatboxesview = new this.ChatBoxesView({'model': this.chatboxes});
|
||||
|
||||
this.roster = new this.RosterItems();
|
||||
this.rosterview = Backbone.View.extend(this.RosterView(this.roster, _, $, console));
|
||||
|
||||
this.connection.addHandler(
|
||||
$.proxy(this.roster.subscribeToSuggestedItems, this.roster),
|
||||
|
Loading…
Reference in New Issue
Block a user