Fixed events for RosterItemView. Subscribing/unsubscribing now works.
This commit is contained in:
parent
f333968dd9
commit
944cca81e3
35
chat.js
35
chat.js
@ -654,24 +654,15 @@ xmppchat.RosterItem = Backbone.Model.extend({
|
|||||||
|
|
||||||
|
|
||||||
xmppchat.RosterItemView = Backbone.View.extend({
|
xmppchat.RosterItemView = Backbone.View.extend({
|
||||||
|
|
||||||
tagName: 'dd',
|
tagName: 'dd',
|
||||||
events: {
|
|
||||||
'click a.open-chat': 'openChat',
|
|
||||||
'click a.remove-xmpp-contact': 'removeContact',
|
|
||||||
'click button.accept-xmpp-request': 'acceptRequest',
|
|
||||||
'click button.decline-xmpp-request': 'declineRequest'
|
|
||||||
},
|
|
||||||
|
|
||||||
openChat: function (e) {
|
openChat: function () {
|
||||||
e.preventDefault();
|
|
||||||
var jid = this.model.get('jid');
|
var jid = this.model.get('jid');
|
||||||
xmppchat.chatboxesview.openChat(jid);
|
xmppchat.chatboxesview.openChat(jid);
|
||||||
},
|
},
|
||||||
|
|
||||||
removeContact: function (e) {
|
removeContact: function () {
|
||||||
var that = this;
|
var that = this;
|
||||||
e.preventDefault();
|
|
||||||
$("<span></span>").dialog({
|
$("<span></span>").dialog({
|
||||||
title: 'Are you sure you want to remove this contact?',
|
title: 'Are you sure you want to remove this contact?',
|
||||||
dialogClass: 'remove-xmpp-contact-dialog',
|
dialogClass: 'remove-xmpp-contact-dialog',
|
||||||
@ -686,7 +677,9 @@ xmppchat.RosterItemView = Backbone.View.extend({
|
|||||||
buttons: {
|
buttons: {
|
||||||
"Remove": function() {
|
"Remove": function() {
|
||||||
$(this).dialog( "close" );
|
$(this).dialog( "close" );
|
||||||
xmppchat.roster.unsubscribe(that.model.get('jid'));
|
xmppchat.connection.roster.unauthorize(that.model.get('jid'));
|
||||||
|
xmppchat.roster.remove(bare_jid);
|
||||||
|
xmppchat.connection.roster.remove(bare_jid);
|
||||||
},
|
},
|
||||||
"Cancel": function() {
|
"Cancel": function() {
|
||||||
$(this).dialog( "close" );
|
$(this).dialog( "close" );
|
||||||
@ -720,6 +713,7 @@ xmppchat.RosterItemView = Backbone.View.extend({
|
|||||||
render: function () {
|
render: function () {
|
||||||
var item = this.model,
|
var item = this.model,
|
||||||
ask = item.get('ask'),
|
ask = item.get('ask'),
|
||||||
|
that = this,
|
||||||
subscription = item.get('subscription');
|
subscription = item.get('subscription');
|
||||||
|
|
||||||
$(this.el).addClass(item.get('status')).attr('id', 'online-users-'+item.get('user_id'));
|
$(this.el).addClass(item.get('status')).attr('id', 'online-users-'+item.get('user_id'));
|
||||||
@ -730,15 +724,30 @@ xmppchat.RosterItemView = Backbone.View.extend({
|
|||||||
} 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.find('button.accept-xmpp-request').on('click', function (ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
that.acceptRequest();
|
||||||
|
});
|
||||||
|
this.$el.find('button.decline-xmpp-request').on('click', function (ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
that.declineRequest();
|
||||||
|
});
|
||||||
} 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.find('a.open-chat').on('click', function (ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
that.openChat();
|
||||||
|
});
|
||||||
|
this.$el.find('a.remove-xmpp-contact').on('click', function (ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
that.removeContact();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
var that = this;
|
|
||||||
this.options.model.on('change', function (item, changed) {
|
this.options.model.on('change', function (item, changed) {
|
||||||
if (_.has(changed.changes, 'status')) {
|
if (_.has(changed.changes, 'status')) {
|
||||||
$(this.el).attr('class', item.changed.status);
|
$(this.el).attr('class', item.changed.status);
|
||||||
|
Loading…
Reference in New Issue
Block a user