Dry up new contact init and handling
This commit is contained in:
parent
63d232dedb
commit
af49ad9b90
2 changed files with 22 additions and 16 deletions
|
@ -69,7 +69,7 @@
|
||||||
<button class='create'>Next</button>
|
<button class='create'>Next</button>
|
||||||
</div>
|
</div>
|
||||||
<div class='results'>
|
<div class='results'>
|
||||||
<div class='new-contact'></div>
|
<div class='new-contact contact'></div>
|
||||||
<div class='contacts'></div>
|
<div class='contacts'></div>
|
||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -70,6 +70,7 @@ var Whisper = Whisper || {};
|
||||||
this.$group_update = this.$el.find('.new-group-update-form');
|
this.$group_update = this.$el.find('.new-group-update-form');
|
||||||
this.$buttons = this.$el.find('.buttons');
|
this.$buttons = this.$el.find('.buttons');
|
||||||
this.$input = this.$el.find('input.new-message');
|
this.$input = this.$el.find('input.new-message');
|
||||||
|
this.$new_contact = this.$el.find('.new-contact');
|
||||||
|
|
||||||
// Collection of contacts to match user input against
|
// Collection of contacts to match user input against
|
||||||
this.typeahead = new ContactsTypeahead();
|
this.typeahead = new ContactsTypeahead();
|
||||||
|
@ -83,14 +84,7 @@ var Whisper = Whisper || {};
|
||||||
});
|
});
|
||||||
this.$el.find('.contacts').append(this.typeahead_view.el);
|
this.$el.find('.contacts').append(this.typeahead_view.el);
|
||||||
|
|
||||||
// View to display a new contact
|
this.initNewContact();
|
||||||
this.new_contact = new Whisper.ConversationListItemView({
|
|
||||||
model: new Whisper.Conversation({
|
|
||||||
active_at: null,
|
|
||||||
type: 'private'
|
|
||||||
})
|
|
||||||
}).render();
|
|
||||||
this.$el.find('.new-contact').append(this.new_contact.el);
|
|
||||||
|
|
||||||
// Group avatar file input
|
// Group avatar file input
|
||||||
this.avatarInput = new Whisper.FileInputView({
|
this.avatarInput = new Whisper.FileInputView({
|
||||||
|
@ -117,13 +111,21 @@ var Whisper = Whisper || {};
|
||||||
'click .create': 'create'
|
'click .create': 'create'
|
||||||
},
|
},
|
||||||
|
|
||||||
addNewRecipient: function(e, data) {
|
initNewContact: function() {
|
||||||
this.new_contact.model.newContact = true; // hack
|
// Creates a view to display a new contact
|
||||||
this.recipients.add(this.new_contact.model);
|
this.new_contact = new Whisper.ConversationListItemView({
|
||||||
this.new_contact.model = new Whisper.Conversation({
|
el: this.$new_contact,
|
||||||
|
model: new Whisper.Conversation({
|
||||||
active_at: null,
|
active_at: null,
|
||||||
type: 'private'
|
type: 'private',
|
||||||
});
|
newContact: true
|
||||||
|
})
|
||||||
|
}).render();
|
||||||
|
},
|
||||||
|
|
||||||
|
addNewRecipient: function(e, data) {
|
||||||
|
this.recipients.add(this.new_contact.model);
|
||||||
|
this.initNewContact();
|
||||||
this.resetTypeahead();
|
this.resetTypeahead();
|
||||||
this.updateControls();
|
this.updateControls();
|
||||||
},
|
},
|
||||||
|
@ -136,7 +138,7 @@ var Whisper = Whisper || {};
|
||||||
|
|
||||||
removeRecipient: function(e, data) {
|
removeRecipient: function(e, data) {
|
||||||
var model = this.recipients.remove(data.modelId);
|
var model = this.recipients.remove(data.modelId);
|
||||||
if (!model.newContact) { // hack
|
if (!model.get('newContact')) {
|
||||||
this.typeahead.add(model);
|
this.typeahead.add(model);
|
||||||
}
|
}
|
||||||
this.filterContacts();
|
this.filterContacts();
|
||||||
|
@ -215,7 +217,11 @@ var Whisper = Whisper || {};
|
||||||
reset: function() {
|
reset: function() {
|
||||||
this.$buttons.hide();
|
this.$buttons.hide();
|
||||||
this.$group_update.hide();
|
this.$group_update.hide();
|
||||||
this.typeahead.add(this.recipients.models);
|
this.typeahead.add(
|
||||||
|
this.recipients.filter(function(model) {
|
||||||
|
return !model.get('newContact');
|
||||||
|
})
|
||||||
|
);
|
||||||
this.recipients.reset([]);
|
this.recipients.reset([]);
|
||||||
this.resetTypeahead();
|
this.resetTypeahead();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue