Move the event handlers on the view instead of registering them in render method of RosterItemView
This commit is contained in:
parent
7daa681ac3
commit
00aba6a9cd
34
converse.js
34
converse.js
@ -1228,8 +1228,16 @@
|
|||||||
xmppchat.RosterItemView = Backbone.View.extend({
|
xmppchat.RosterItemView = Backbone.View.extend({
|
||||||
tagName: 'dd',
|
tagName: 'dd',
|
||||||
|
|
||||||
openChat: function () {
|
events: {
|
||||||
|
"click .accept-xmpp-request": "acceptRequest",
|
||||||
|
"click .decline-xmpp-request": "declineRequest",
|
||||||
|
"click .open-chat": "openChat",
|
||||||
|
"click .remove-xmpp-contact": "removeContact"
|
||||||
|
},
|
||||||
|
|
||||||
|
openChat: function (ev) {
|
||||||
xmppchat.chatboxesview.openChat(this.model.get('jid'));
|
xmppchat.chatboxesview.openChat(this.model.get('jid'));
|
||||||
|
ev.preventDefault();
|
||||||
},
|
},
|
||||||
|
|
||||||
removeContact: function () {
|
removeContact: function () {
|
||||||
@ -1266,18 +1274,20 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
acceptRequest: function () {
|
acceptRequest: function (ev) {
|
||||||
var jid = this.model.get('jid');
|
var jid = this.model.get('jid');
|
||||||
xmppchat.connection.roster.authorize(jid);
|
xmppchat.connection.roster.authorize(jid);
|
||||||
xmppchat.connection.roster.add(jid, this.model.get('fullname'), [], function (iq) {
|
xmppchat.connection.roster.add(jid, this.model.get('fullname'), [], function (iq) {
|
||||||
xmppchat.connection.roster.subscribe(jid);
|
xmppchat.connection.roster.subscribe(jid);
|
||||||
});
|
});
|
||||||
|
ev.preventDefault();
|
||||||
},
|
},
|
||||||
|
|
||||||
declineRequest: function () {
|
declineRequest: function (ev) {
|
||||||
var that = this;
|
var that = this;
|
||||||
xmppchat.connection.roster.unauthorize(this.model.get('jid'));
|
xmppchat.connection.roster.unauthorize(this.model.get('jid'));
|
||||||
that.trigger('decline-request', that.model);
|
that.trigger('decline-request', that.model);
|
||||||
|
ev.preventDefault();
|
||||||
},
|
},
|
||||||
|
|
||||||
template: _.template(
|
template: _.template(
|
||||||
@ -1308,29 +1318,12 @@
|
|||||||
} else if (ask === 'request') {
|
} else if (ask === 'request') {
|
||||||
this.$el.addClass('requesting-xmpp-contact');
|
this.$el.addClass('requesting-xmpp-contact');
|
||||||
this.$el.html(this.request_template(item.toJSON()));
|
this.$el.html(this.request_template(item.toJSON()));
|
||||||
this.$el.delegate('button.accept-xmpp-request', 'click', function (ev) {
|
|
||||||
ev.preventDefault();
|
|
||||||
that.acceptRequest();
|
|
||||||
});
|
|
||||||
this.$el.delegate('button.decline-xmpp-request', 'click', function (ev) {
|
|
||||||
ev.preventDefault();
|
|
||||||
that.declineRequest();
|
|
||||||
});
|
|
||||||
xmppchat.chatboxesview.openChat('controlbox');
|
xmppchat.chatboxesview.openChat('controlbox');
|
||||||
} else if (subscription === 'both') {
|
} else if (subscription === 'both') {
|
||||||
this.$el.addClass('current-xmpp-contact');
|
this.$el.addClass('current-xmpp-contact');
|
||||||
this.$el.html(this.template(item.toJSON()));
|
this.$el.html(this.template(item.toJSON()));
|
||||||
this.$el.delegate('a.open-chat', 'click', function (ev) {
|
|
||||||
ev.preventDefault();
|
|
||||||
that.openChat();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event handlers
|
|
||||||
this.$el.find('.remove-xmpp-contact').one('click', function (ev) {
|
|
||||||
ev.preventDefault();
|
|
||||||
that.removeContact();
|
|
||||||
});
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1926,4 +1919,3 @@
|
|||||||
|
|
||||||
return xmppchat;
|
return xmppchat;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user