Refactor contact rendering in message detail view
DRY // FREEBIE
This commit is contained in:
parent
b8536679b3
commit
0f8aff12c5
1 changed files with 10 additions and 12 deletions
|
@ -76,6 +76,12 @@
|
|||
this.render();
|
||||
});
|
||||
},
|
||||
renderContact: function(contact) {
|
||||
var v = new ContactView({
|
||||
model: contact,
|
||||
conflict: this.model.getKeyConflict(contact.id)
|
||||
}).render().$el.appendTo(this.$('.contacts'));
|
||||
},
|
||||
render: function() {
|
||||
this.$el.html(Mustache.render(this.template, {
|
||||
sent_at : moment(this.model.get('sent_at')).toString(),
|
||||
|
@ -85,19 +91,11 @@
|
|||
this.view.render().$el.prependTo(this.$('.message-container'));
|
||||
|
||||
if (this.model.isOutgoing()) {
|
||||
this.conversation.contactCollection.each(function(contact) {
|
||||
var v = new ContactView({
|
||||
model: contact,
|
||||
conflict: this.model.getKeyConflict(contact.id)
|
||||
}).render().$el.appendTo(this.$('.contacts'));
|
||||
}.bind(this));
|
||||
this.conversation.contactCollection.each(this.renderContact.bind(this));
|
||||
} else {
|
||||
var number = this.model.get('source');
|
||||
var contact = this.conversation.contactCollection.get(number);
|
||||
var v = new ContactView({
|
||||
model: contact,
|
||||
conflict: this.model.getKeyConflict(number)
|
||||
}).render().$el.appendTo(this.$('.contacts'));
|
||||
this.renderContact(
|
||||
this.conversation.contactCollection.get(this.model.get('source'))
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue