Less jquery, more templating in conversation view

`if (foo) then jquery-dom-insert...` is a poor pattern to follow.
Instead, let mustache do the work.
This commit is contained in:
lilia 2015-01-15 22:22:24 -10:00
parent e74cba8a92
commit d470b0eb53
2 changed files with 14 additions and 7 deletions

View file

@ -61,6 +61,13 @@
</div>
</form>
</div>
{{#group}}
<button class='new-group-update'>Update group</button>
<button class='leave-group'>Leave group</button>
{{/group}}
{{^group}}
<button class='end-session'>End Session</button>
{{/group}}
<div class='extension-details'>
<ul>
<li>Signal for Chrome</li>

View file

@ -18,12 +18,17 @@
window.Whisper = window.Whisper || {};
Whisper.ConversationView = Backbone.View.extend({
className: 'conversation',
className: function() {
return [ 'conversation', this.model.get('type') ].join(' ');
},
initialize: function() {
this.listenTo(this.model, 'destroy', this.stopListening); // auto update
this.template = $('#conversation').html();
Mustache.parse(this.template);
this.$el.html(Mustache.render(this.template));
this.$el.html(Mustache.render(this.template,
{ group: this.model.get('type') === 'group' }
));
this.fileInput = new Whisper.FileInputView({
el: this.$el.find('.attachments')
@ -35,11 +40,6 @@
this.$el.find('.discussion-container').append(this.view.el);
this.model.fetchMessages({reset: true});
if (this.model.get('type') === 'group') {
this.$el.addClass('group');
this.$el.find('.send-message-area').append($('<button>').addClass('new-group-update').text('Update group'));
}
},
events: {