Normalize views' template fetching pattern
Typically, a view can specify its templateName and then use the default render method on Whisper.View, except in some special cases like message view or message detail where other operations are performed during render. // FREEBIE
This commit is contained in:
parent
0e0994832e
commit
77caa63321
12 changed files with 18 additions and 20 deletions
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
Whisper.AttachmentPreviewView = Whisper.View.extend({
|
Whisper.AttachmentPreviewView = Whisper.View.extend({
|
||||||
className: 'attachment-preview',
|
className: 'attachment-preview',
|
||||||
template: $('#attachment-preview').html(),
|
templateName: 'attachment-preview',
|
||||||
render_attributes: function() {
|
render_attributes: function() {
|
||||||
return {source: this.src};
|
return {source: this.src};
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
Whisper.ConfirmationDialogView = Whisper.View.extend({
|
Whisper.ConfirmationDialogView = Whisper.View.extend({
|
||||||
className: 'confirmation-dialog',
|
className: 'confirmation-dialog',
|
||||||
template: $('#confirmation-dialog').html(),
|
templateName: 'confirmation-dialog',
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.message = options.message;
|
this.message = options.message;
|
||||||
this.resolve = options.resolve;
|
this.resolve = options.resolve;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
itemView: Whisper.View.extend({
|
itemView: Whisper.View.extend({
|
||||||
tagName: 'div',
|
tagName: 'div',
|
||||||
className: 'contact',
|
className: 'contact',
|
||||||
template: Whisper.View.Templates.contact,
|
templateName: 'contact',
|
||||||
render_attributes: function() {
|
render_attributes: function() {
|
||||||
return {
|
return {
|
||||||
title: this.model.getTitle(),
|
title: this.model.getTitle(),
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
Whisper.EndSessionView = Whisper.View.extend({
|
Whisper.EndSessionView = Whisper.View.extend({
|
||||||
tagName: "div",
|
tagName: "div",
|
||||||
className: "end-session",
|
className: "end-session",
|
||||||
template: $('#message').html(),
|
templateName: 'message',
|
||||||
render_attributes: function() {
|
render_attributes: function() {
|
||||||
return { text: 'Secure session ended' };
|
return { text: 'Secure session ended' };
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
|
|
||||||
Whisper.FileSizeToast = Whisper.ToastView.extend({
|
Whisper.FileSizeToast = Whisper.ToastView.extend({
|
||||||
template: $('#file-size-modal').html()
|
templateName: 'file-size-modal'
|
||||||
});
|
});
|
||||||
|
|
||||||
Whisper.FileInputView = Backbone.View.extend({
|
Whisper.FileInputView = Backbone.View.extend({
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
Whisper.GroupMemberList = Whisper.View.extend({
|
Whisper.GroupMemberList = Whisper.View.extend({
|
||||||
className: 'group-member-list',
|
className: 'group-member-list',
|
||||||
template: $('#group-member-list').html(),
|
templateName: 'group-member-list',
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.render();
|
this.render();
|
||||||
this.member_list_view = new Whisper.ContactListView({
|
this.member_list_view = new Whisper.ContactListView({
|
||||||
|
|
|
@ -6,11 +6,10 @@
|
||||||
|
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
|
|
||||||
Whisper.KeyConflictDialogueView = Backbone.View.extend({
|
Whisper.KeyConflictDialogueView = Whisper.View.extend({
|
||||||
className: 'key-conflict-dialogue',
|
className: 'key-conflict-dialogue',
|
||||||
|
templateName: 'key-conflict-dialogue',
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.template = $('#key-conflict-dialogue').html();
|
|
||||||
Mustache.parse(this.template);
|
|
||||||
this.conversation = options.conversation;
|
this.conversation = options.conversation;
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
|
@ -32,9 +31,8 @@
|
||||||
this.remove();
|
this.remove();
|
||||||
this.conversation.resolveConflicts(this.model);
|
this.conversation.resolveConflicts(this.model);
|
||||||
},
|
},
|
||||||
render: function() {
|
render_attributes: function() {
|
||||||
this.$el.html(Mustache.render(this.template, this.model));
|
return this.model;
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
Whisper.KeyVerificationView = Whisper.View.extend({
|
Whisper.KeyVerificationView = Whisper.View.extend({
|
||||||
className: 'key-verification',
|
className: 'key-verification',
|
||||||
template: $('#key-verification').html(),
|
templateName: 'key-verification',
|
||||||
events: {
|
events: {
|
||||||
'click .back': 'goBack'
|
'click .back': 'goBack'
|
||||||
},
|
},
|
||||||
|
|
|
@ -31,9 +31,9 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Whisper.MessageDetailView = Backbone.View.extend({
|
Whisper.MessageDetailView = Whisper.View.extend({
|
||||||
className: 'message-detail',
|
className: 'message-detail',
|
||||||
template: $('#message-detail').html(),
|
templateName: 'message-detail',
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
this.view = new Whisper.MessageView({model: this.model});
|
this.view = new Whisper.MessageView({model: this.model});
|
||||||
this.view.render();
|
this.view.render();
|
||||||
|
@ -107,7 +107,7 @@
|
||||||
return (e.name === 'OutgoingMessageError' ||
|
return (e.name === 'OutgoingMessageError' ||
|
||||||
e.name === 'SendMessageNetworkError');
|
e.name === 'SendMessageNetworkError');
|
||||||
});
|
});
|
||||||
this.$el.html(Mustache.render(this.template, {
|
this.$el.html(Mustache.render(_.result(this, 'template', ''), {
|
||||||
sent_at : moment(this.model.get('sent_at')).toString(),
|
sent_at : moment(this.model.get('sent_at')).toString(),
|
||||||
received_at : moment(this.model.get('received_at')).toString(),
|
received_at : moment(this.model.get('received_at')).toString(),
|
||||||
tofrom : this.model.isIncoming() ? 'From' : 'To',
|
tofrom : this.model.isIncoming() ? 'From' : 'To',
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
Whisper.MessageView = Whisper.View.extend({
|
Whisper.MessageView = Whisper.View.extend({
|
||||||
tagName: "li",
|
tagName: "li",
|
||||||
template: $('#message').html(),
|
templateName: 'message',
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.listenTo(this.model, 'change:errors', this.onErrorsChanged);
|
this.listenTo(this.model, 'change:errors', this.onErrorsChanged);
|
||||||
this.listenTo(this.model, 'change:body', this.render);
|
this.listenTo(this.model, 'change:body', this.render);
|
||||||
|
@ -73,7 +73,7 @@
|
||||||
render: function() {
|
render: function() {
|
||||||
var contact = this.model.getContact();
|
var contact = this.model.getContact();
|
||||||
this.$el.html(
|
this.$el.html(
|
||||||
Mustache.render(this.template, {
|
Mustache.render(_.result(this, 'template', ''), {
|
||||||
message: this.model.get('body'),
|
message: this.model.get('body'),
|
||||||
timestamp: this.model.get('sent_at'),
|
timestamp: this.model.get('sent_at'),
|
||||||
sender: (contact && contact.getTitle()) || '',
|
sender: (contact && contact.getTitle()) || '',
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
Whisper.PhoneInputView = Whisper.View.extend({
|
Whisper.PhoneInputView = Whisper.View.extend({
|
||||||
tagName: 'div',
|
tagName: 'div',
|
||||||
className: 'phone-input',
|
className: 'phone-input',
|
||||||
template: $('#phone-number').html(),
|
templateName: 'phone-number',
|
||||||
render: function() {
|
render: function() {
|
||||||
this.$el.html($(Mustache.render(this.template)));
|
this.$el.html($(Mustache.render(this.template)));
|
||||||
this.$('input.number').intlTelInput();
|
this.$('input.number').intlTelInput();
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
this.$el.html(Mustache.render(this.template, this.model));
|
this.$el.html(Mustache.render(_.result(this, 'template', ''), this.model));
|
||||||
this.$el.show();
|
this.$el.show();
|
||||||
setTimeout(this.close.bind(this), 2000);
|
setTimeout(this.close.bind(this), 2000);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue