Make it easier to reference templates

Whisper.Views can now use templateName to reference the id of the
desired template.
This commit is contained in:
lilia 2015-09-04 13:06:17 -07:00
parent 239b87a1fa
commit e402338af7
4 changed files with 11 additions and 5 deletions

View file

@ -19,7 +19,7 @@
var ContactView = Whisper.View.extend({
className: 'contact-detail',
template: $('#contact-detail').html(),
templateName: 'contact-detail',
initialize: function(options) {
this.conflict = options.conflict;
},

View file

@ -20,7 +20,7 @@
Whisper.NewGroupUpdateView = Whisper.View.extend({
tagName: "div",
className: "new-group-update-form",
template: $('#new-group-update-form').html(),
templateName: 'new-group-update',
initialize: function(options) {
this.render();
this.avatarInput = new Whisper.FileInputView({

View file

@ -38,7 +38,7 @@
events: {
'click .remove': 'removeModel'
},
template: $('#contact_pill').html(),
templateName: 'contact_pill',
initialize: function() {
var error = this.model.validate(this.model.attributes);
if (error) {
@ -60,7 +60,7 @@
Whisper.RecipientsInputView = Whisper.View.extend({
className: 'recipients-input',
template: $('#recipients-input').html(),
templateName: 'recipients-input',
initialize: function(options) {
if (options) {
this.placeholder = options.placeholder;

View file

@ -28,6 +28,12 @@
render_partials: function() {
return Whisper.View.Templates;
},
template: function() {
if (this.templateName) {
return Whisper.View.Templates[this.templateName];
}
return '';
},
render: function() {
var attrs = _.result(this, 'render_attributes', {});
var template = _.result(this, 'template', '');
@ -51,7 +57,7 @@
var templates = {};
$('script[type="text/x-tmpl-mustache"]').each(function(i, el) {
var $el = $(el);
var id = $el.attr('id').replace('-','_');
var id = $el.attr('id');
templates[id] = $el.html();
});
return templates;