adding comments work for one of two comment add buttons; added info on

posts; post show page.
This commit is contained in:
danielgrippi 2011-09-26 23:17:09 -07:00
parent 3b08fc8406
commit 744ab579bd
10 changed files with 113 additions and 32 deletions

View file

@ -6,7 +6,7 @@ class CommentsController < ApplicationController
include ApplicationHelper
before_filter :authenticate_user!
respond_to :html, :mobile, :only => [:new, :create, :destroy, :index]
respond_to :html, :mobile, :except => :show
respond_to :js, :only => [:index]
rescue_from ActiveRecord::RecordNotFound do
@ -28,7 +28,7 @@ class CommentsController < ApplicationController
respond_to do |format|
format.js{ render(:create, :status => 201)}
format.html{ render :nothing => true, :status => 201 }
format.mobile{ redirect_to post_url(@comment.post) }
format.mobile{ render :partial => 'comment', :locals => {:post => @comment.post, :comment => @comment} }
end
else
render :nothing => true, :status => 422
@ -65,7 +65,6 @@ class CommentsController < ApplicationController
end
def new
puts params.inspect
render :layout => false
end
end

View file

@ -2,7 +2,7 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
= form_tag( post_comments_path(post_id), :id => "new_comment_on_#{post_id}", :class => 'new_comment', :remote => true) do
= form_tag( post_comments_path(post_id), :id => "new_comment_on_#{post_id}", :class => 'new_comment') do
= hidden_field_tag :post_id, post_id, :id => "post_id_on_#{post_id}"
= text_area_tag :text, nil, :rows => 2, :class => "comment_box",:id => "comment_text_on_#{post_id}"

View file

@ -1,4 +1,12 @@
%ul.comments
.comment_container
.post_stats
%span.comment_count
= @post.comments.size
%span.like_count
= @post.likes.size
%ul.comments
= render :partial => 'comments/comment', :collection => @comments, :locals => {:post => @post}
%li.comment.add_comment_bottom_link_container

View file

@ -2,7 +2,8 @@
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
= render :partial => 'shared/stream_element',
.stream
= render :partial => 'shared/stream_element',
:locals => {:post => @post, :commenting_disabled => defined?(@commenting_disabled),
:expanded_info => true}

View file

@ -10,10 +10,11 @@
= hidden_field_tag 'aspect_ids[]', aspect_id.to_s
%fieldset
- unless aspect == :all
%input{:type => 'checkbox', :name => 'status_message[public]', :id => 'public', :class => 'custom', :value => 'true'}
%label{:for => 'public'}
= t('.make_public')
%div{:style => 'float:right;'}
= select_tag 'aspect_ids[]', options_from_collection_for_select(current_user.aspects, "id", "name")
/%input{:type => 'checkbox', :name => 'status_message[public]', :id => 'public', :class => 'custom', :value => 'true'}
/%label{:for => 'public'}
/ = t('.make_public')
- unless current_user.services.empty?
%div{:data => {:role => 'fieldcontain'}}
%label{:for => 'services', :class => 'select'}
@ -22,5 +23,5 @@
%label{:for => "#{service.provider}"}
= "#{service.provider}"
= status.submit t('.share')
= status.submit t('.share'), :class => 'action'

View file

@ -43,3 +43,18 @@
%span.show_comments
= "#{t('reactions', :count => (post.comments.length + post.likes_count))}"
- if defined?(expanded_info) && expanded_info
.comment_container
.post_stats
%span.comment_count
= @post.comments.size
%span.like_count
= @post.likes.size
%ul.comments
= render :partial => 'comments/comment', :collection => @comments, :locals => {:post => @post}
%li.comment.add_comment_bottom_link_container
= link_to "Add a comment", new_post_comment_path(@post), :class => 'add_comment_bottom_link btn comment_action inactive'

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 455 B

View file

@ -1,7 +1,9 @@
$(document).ready(function(){
$(".like_action.inactive").live('tap click', function(evt){
evt.preventDefault();
var link = $(this);
var link = $(this),
likeCounter = $(this).closest(".stream_element").find("like_count"),
postId = link.closest(".stream_element").data("post-guid");
$.ajax({
url: link.attr("href"),
@ -16,6 +18,10 @@ $(document).ready(function(){
.removeClass('inactive')
.addClass('active')
.data('post-id', postId);
if(likeCounter){
likeCounter.text(parseInt(likeCounter.text) + 1);
}
}
});
});
@ -23,6 +29,7 @@ $(document).ready(function(){
$(".like_action.active").live('tap click', function(evt){
evt.preventDefault();
var link = $(this);
likeCounter = $(this).closest(".stream_element").find("like_count");
$.ajax({
url: link.attr("href"),
@ -37,6 +44,10 @@ $(document).ready(function(){
.removeClass('active')
.addClass('inactive')
.data('like-id', '');
if(likeCounter){
likeCounter.text(parseInt(likeCounter.text) - 1);
}
}
});
});
@ -45,7 +56,7 @@ $(document).ready(function(){
evt.preventDefault();
var link = $(this),
parent = link.closest(".bottom_bar").first(),
commentsContainer = parent.find(".comments");
commentsContainer = parent.find(".comment_container");
if( link.hasClass('active') ) {
commentsContainer.first().hide();
@ -80,13 +91,18 @@ $(document).ready(function(){
link.addClass('loading');
},
success: function(data){
var textarea = parent.find('textarea').first();
lineHeight = 14;
link.removeClass('loading')
.removeClass('inactive');
container.first().hide();
parent.append(data);
parent.find('textarea').first().focus();
textarea.focus();
new MBP.autogrow(textarea, lineHeight);
}
});
}
@ -106,4 +122,19 @@ $(document).ready(function(){
commentActionLink.addClass("inactive");
form.remove();
});
$(".new_comment").live("submit", function(evt){
evt.preventDefault();
var form = $(this);
$.post(form.attr('action')+"?format=mobile", form.serialize(), function(data){
var container = form.closest('.bottom_bar').find('.add_comment_bottom_link_container');
container.before(data);
form.remove();
container.show();
}, 'html');
});
});

View file

@ -84,7 +84,7 @@ body {
.stream_element .comments {
padding: 0;
margin: 0;
margin-top: 18px;
top: 8px;
width: 100%;
.content {
padding: 0;
@ -278,6 +278,7 @@ footer {
.bottom_bar {
@include border-radius(0, 0, 3px, 3px);
display: block;
position: relative;
padding: 10px;
background: #eeeeee;
margin: {
@ -306,6 +307,14 @@ footer {
&.active {
color: #444;
padding: {
right: 14px;
}
background: {
image: url("/images/icons/arrow_down_small.png");
position: center right;
repeat: no-repeat;
}
}
}
@ -436,6 +445,7 @@ form {
}
.btn,
select,
input[type=submit] {
@include border-radius(3px);
background-color: #ddd;
@ -469,6 +479,22 @@ input[type=submit] {
.comment.add_comment_bottom_link_container {
text-align: center;
padding: 15px !important;
padding-top: 25px !important;
padding: 25px !important;
}
.post_stats {
position: absolute;
font-size: larger;
right: 11px;
top: 38px;
z-index: 2;
span {
color: #666;
font-weight: bold;
padding: 2px 7px;
margin: 5px 5px;
background: {
color: #eee;
}
}
}