extract creating a post with templates to a static post view method. Legacy templates extracted, day view day mood shows photos and has variable text size
44 lines
No EOL
1.2 KiB
JavaScript
44 lines
No EOL
1.2 KiB
JavaScript
app.views.Post = app.views.StreamObject.extend({
|
|
presenter : function() {
|
|
return _.extend(this.defaultPresenter(), {
|
|
authorIsCurrentUser : this.authorIsCurrentUser(),
|
|
showPost : this.showPost(),
|
|
text : app.helpers.textFormatter(this.model)
|
|
})
|
|
},
|
|
|
|
authorIsCurrentUser : function() {
|
|
return app.currentUser.authenticated() && this.model.get("author").id == app.user().id
|
|
},
|
|
|
|
showPost : function() {
|
|
return (app.currentUser.get("showNsfw")) || !this.model.get("nsfw")
|
|
}
|
|
}, { //static methods below
|
|
|
|
showFactory : function(model) {
|
|
var frameName = model.get("frame_name");
|
|
|
|
if(_.include(app.models.Post.legacyTemplateNames, frameName)){
|
|
return legacyShow(model)
|
|
} else {
|
|
return new app.views.Post[frameName]({
|
|
model : model
|
|
})
|
|
}
|
|
|
|
function legacyShow(model) {
|
|
return new app.views.Post.Legacy({
|
|
model : model,
|
|
className : frameName + " post loaded",
|
|
templateName : "post-viewer/content/" + frameName
|
|
});
|
|
}
|
|
}
|
|
});
|
|
|
|
app.views.Post.Legacy = app.views.Post.extend({
|
|
initialize : function(options) {
|
|
this.templateName = options.templateName || this.templateName
|
|
}
|
|
}) |