add user_like to PostPresenter; use proper inheritance for feedback views
This commit is contained in:
parent
ca8f136cec
commit
2815885bcf
6 changed files with 42 additions and 42 deletions
|
|
@ -11,12 +11,22 @@ class PostPresenter
|
|||
def to_json(options = {})
|
||||
{
|
||||
:post => self.post.as_api_response(:backbone).update(
|
||||
{ :next_post => next_post_url,
|
||||
:previous_post => previous_post_url}),
|
||||
{
|
||||
:user_like => self.user_like,
|
||||
:next_post => self.next_post_url,
|
||||
:previous_post => self.previous_post_url
|
||||
}),
|
||||
:templateName => TemplatePicker.new(self.post).template_name
|
||||
}
|
||||
end
|
||||
|
||||
def user_like
|
||||
return unless self.current_user.present?
|
||||
if like = Like.where(:target_id => self.post.id, :target_type => "Post", :author_id => current_user.person.id).first
|
||||
like.as_api_response(:backbone)
|
||||
end
|
||||
end
|
||||
|
||||
def next_post_url
|
||||
if n = next_post
|
||||
Rails.application.routes.url_helpers.post_path(n)
|
||||
|
|
|
|||
|
|
@ -32,16 +32,15 @@ app.pages.PostViewer = app.views.Base.extend({
|
|||
setKeyMappings : function() {
|
||||
var nextPostLocation = this.model.get("next_post");
|
||||
var previousPostLocation = this.model.get("previous_post");
|
||||
var doc = $(document);
|
||||
|
||||
/* focus modal */
|
||||
doc.keypress(function(){
|
||||
$('#text').focus();
|
||||
$('#comment').modal();
|
||||
});
|
||||
// doc.keypress(function(){
|
||||
// $('#text').focus();
|
||||
// $('#comment').modal();
|
||||
// });
|
||||
|
||||
/* navagation hooks */
|
||||
doc.keydown(function(e){
|
||||
$(document).keydown(function(e){
|
||||
if (e.keyCode == 37 && nextPostLocation) {
|
||||
window.location = nextPostLocation
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
<div id="user-controls">
|
||||
<a href="#" class="label profile" title="{{current_user.name}}">
|
||||
<i class="icon-user icon-white"></i>
|
||||
</a>
|
||||
<a href="#" class="label like" title="Like">
|
||||
<i class="icon-heart icon-white"></i>
|
||||
</a>
|
||||
<a href="#" class="label follow" title="Follow Post">
|
||||
<i class="icon-plus icon-white"></i>
|
||||
</a>
|
||||
<a href="#" class="label profile" title="{{current_user.name}}">
|
||||
<i class="icon-user icon-white"></i>
|
||||
</a>
|
||||
|
||||
<a href="#" class="label like" title="{{#if user_like}} Unlike {{else}} Like {{/if}}">
|
||||
<i class="icon-heart icon-white"></i>
|
||||
</a>
|
||||
|
||||
<a href="#" class="label follow" title="Follow Post">
|
||||
<i class="icon-plus icon-white"></i>
|
||||
</a>
|
||||
|
||||
{{#if userCanReshare}}
|
||||
<a href="#" class="label reshare" title="Reshare">
|
||||
<i class="icon-retweet icon-white"></i>
|
||||
</a>
|
||||
<a href="#" class="label comment" title="Comment">
|
||||
<i class="icon-comment icon-white"></i>
|
||||
</a>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<a href="#" class="label comment" title="Comment">
|
||||
<i class="icon-comment icon-white"></i>
|
||||
</a>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
app.views.Feedback = app.views.StreamObject.extend({
|
||||
app.views.Feedback = app.views.Base.extend({
|
||||
|
||||
templateName: "feedback",
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +1,21 @@
|
|||
app.views.PostViewerFeedback = app.views.Base.extend({
|
||||
app.views.PostViewerFeedback = app.views.Feedback.extend({
|
||||
|
||||
id : "user-controls",
|
||||
className : "",
|
||||
|
||||
templateName: "post-viewer/feedback",
|
||||
|
||||
events : {
|
||||
"click .like" : "toggleLike",
|
||||
"click .follow" : "toggleFollow",
|
||||
"click .reshare" : "reshare",
|
||||
"click .reshare" : "resharePost",
|
||||
"click .comment" : "comment"
|
||||
},
|
||||
|
||||
tooltipSelector : ".label",
|
||||
|
||||
toggleLike : function(evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
this.model.toggleLike()
|
||||
},
|
||||
|
||||
toggleFollow : function(evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
this.model.toggleFollow()
|
||||
},
|
||||
|
||||
reshare : function(evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
this.model.reshare();
|
||||
},
|
||||
|
||||
comment : function(){
|
||||
alert('comment')
|
||||
console.log(this.model)
|
||||
}
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
tooltipSelector : ".delete, .block_user, .post_scope",
|
||||
|
||||
initialize : function(options) {
|
||||
console.log(this.model.attributes)
|
||||
// allow for a custom template name to be passed in via the options hash
|
||||
this.templateName = options.templateName || this.templateName
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue