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>'+
|
'<button type="submit">Search</button>'+
|
||||||
'<ul id="found-users"></ul>'+
|
'<ul id="found-users"></ul>'+
|
||||||
'</form>'+
|
'</form>'+
|
||||||
'</div>'+
|
'</div>'
|
||||||
'<dl id="xmppchat-roster"></dl>'
|
|
||||||
),
|
),
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
@ -1138,22 +1137,28 @@
|
|||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
this.views = {};
|
this.views = {};
|
||||||
|
|
||||||
// Add the controlbox view and the panels
|
// Add the controlbox view and the panels
|
||||||
this.views.controlbox = xmppchat.controlbox;
|
var controlbox = xmppchat.controlbox;
|
||||||
this.views.controlbox.$el.appendTo(this.$el);
|
controlbox.$el.appendTo(this.$el);
|
||||||
this.views.controlbox.contactspanel = new xmppchat.ContactsPanel().render();
|
controlbox.contactspanel = new xmppchat.ContactsPanel().render();
|
||||||
// TODO: Only add the rooms panel if the server supports MUC
|
controlbox.roomspanel = new xmppchat.RoomsPanel().render(); // TODO: Only add the rooms panel if the server supports MUC
|
||||||
this.views.controlbox.roomspanel = new xmppchat.RoomsPanel().render();
|
|
||||||
|
// 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)
|
// 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)
|
// Add the controlbox model to this collection (will trigger showChat)
|
||||||
this.options.model.add(xmppchat.controlbox.options.model);
|
this.options.model.add(xmppchat.controlbox.options.model);
|
||||||
|
|
||||||
|
this.views.controlbox = controlbox;
|
||||||
this.restoreOpenChats();
|
this.restoreOpenChats();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
xmppchat.RosterItem = Backbone.Model.extend({
|
xmppchat.RosterItem = Backbone.Model.extend({
|
||||||
|
|
||||||
initialize: function (jid, subscription, ask, name) {
|
initialize: function (jid, subscription, ask, name) {
|
||||||
@ -1202,7 +1207,7 @@
|
|||||||
$(this).dialog( "close" );
|
$(this).dialog( "close" );
|
||||||
xmppchat.connection.roster.remove(bare_jid, function (iq) {
|
xmppchat.connection.roster.remove(bare_jid, function (iq) {
|
||||||
xmppchat.connection.roster.unauthorize(bare_jid);
|
xmppchat.connection.roster.unauthorize(bare_jid);
|
||||||
xmppchat.roster.remove(bare_jid);
|
xmppchat.chatboxesview.controlbox.roster.remove(bare_jid);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
"Cancel": function() {
|
"Cancel": function() {
|
||||||
@ -1489,7 +1494,7 @@
|
|||||||
*/
|
*/
|
||||||
xmppchat.xmppstatus.sendPresence('unsubscribe');
|
xmppchat.xmppstatus.sendPresence('unsubscribe');
|
||||||
if (xmppchat.connection.roster.findItem(bare_jid)) {
|
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);
|
xmppchat.connection.roster.remove(bare_jid);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1522,10 +1527,9 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
xmppchat.RosterView= (function (roster, _, $, console) {
|
xmppchat.RosterView = Backbone.View.extend({
|
||||||
var View = Backbone.View.extend({
|
tagName: 'dl',
|
||||||
el: $('#xmppchat-roster'),
|
id: 'xmppchat-roster',
|
||||||
model: roster,
|
|
||||||
rosteritemviews: {},
|
rosteritemviews: {},
|
||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
@ -1594,11 +1598,9 @@
|
|||||||
});
|
});
|
||||||
$count = $('#online-count');
|
$count = $('#online-count');
|
||||||
$count.text(this.model.getNumOnlineContacts());
|
$count.text(this.model.getNumOnlineContacts());
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var view = new View();
|
|
||||||
return view;
|
|
||||||
});
|
|
||||||
|
|
||||||
xmppchat.XMPPStatus = Backbone.Model.extend({
|
xmppchat.XMPPStatus = Backbone.Model.extend({
|
||||||
|
|
||||||
@ -1789,8 +1791,6 @@
|
|||||||
this.chatboxes = new this.ChatBoxes();
|
this.chatboxes = new this.ChatBoxes();
|
||||||
this.chatboxesview = new this.ChatBoxesView({'model': 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(
|
this.connection.addHandler(
|
||||||
$.proxy(this.roster.subscribeToSuggestedItems, this.roster),
|
$.proxy(this.roster.subscribeToSuggestedItems, this.roster),
|
||||||
|
Loading…
Reference in New Issue
Block a user