diaspora/public/javascripts/app/views.js
Dennis Collinson b28508ecbc MS DC show last post and show page works unauthenticated
phasing out app.user() for app.currentUser
2012-02-24 19:09:00 -08:00

62 lines
1.6 KiB
JavaScript

app.views.Base = Backbone.View.extend({
initialize : function(options) {
this.setupRenderEvents();
},
presenter : function(){
return this.defaultPresenter()
},
setupRenderEvents : function(){
this.model.bind('remove', this.remove, this);
// this line is too generic. we usually only want to re-render on
// feedback changes as the post content, author, and time do not change.
//
// this.model.bind('change', this.render, this);
},
defaultPresenter : function(){
var modelJson = this.model ? this.model.toJSON() : {}
return _.extend(modelJson, {current_user: app.currentUser.attributes});
},
render : function() {
this.renderTemplate()
this.renderSubviews()
this.renderPluginWidgets()
this.removeTooltips()
return this
},
renderTemplate : function(){
var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter
this.template = JST[this.templateName]
$(this.el).html(this.template(presenter));
this.postRenderTemplate();
},
postRenderTemplate : $.noop, //hella callbax yo
renderSubviews : function(){
var self = this;
_.each(this.subviews, function(property, selector){
var view = _.isFunction(self[property]) ? self[property]() : self[property]
if(view) {
self.$(selector).html(view.render().el)
view.delegateEvents();
}
})
},
renderPluginWidgets : function() {
this.$(this.tooltipSelector).twipsy();
this.$("time").timeago();
},
removeTooltips : function() {
$(".twipsy").remove();
}
})