forked from publiclab/spectral-workbench
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Viduranga Wijesooriya <vpowerrc@gmail.com>
- Loading branch information
1 parent
0eebb32
commit e1637f2
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<a name="comments"></a> | ||
<h3>Comments (<%= @spectrum.comments.length %>)</h3> | ||
|
||
<% if @spectrum.comments.length == 0 %><p><i>No comments</i></p><% end %> | ||
|
||
<div id="commentlist"> | ||
<% @spectrum.comments.each do |comment| %> | ||
<div class="comment"> | ||
<a name="comment_<%= comment.id %>"></a> | ||
<b><%= time_ago_in_words(comment.created_at) %> ago, | ||
<% if User.find_by_login(comment.author) %><a href="<%= user_path(comment.author) %>"><%= comment.author %></a> wrote:</b> | ||
<% else %><%=h comment.author %> wrote:</b> | ||
<% end %> | ||
<p><%= raw RDiscount.new(comment.body).to_html %></p> | ||
<% if logged_in? && (current_user.role == "admin" || current_user.login == comment.author) %><p><small><%= link_to '<i class="icon icon-remove-sign"></i> Delete'.html_safe, "/comments/delete/"+comment.id.to_s, :confirm => 'Are you sure?' %></small></p><% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
|
||
<br /> | ||
|
||
<% if logged_in? %> | ||
<form action="/comment/create/<%= @spectrum.id %>" class="well form" id="commentform" method="post"> | ||
|
||
<h3 style="margin-top:0;">Post a comment</h3> | ||
<textarea name="comment[body]" id="commentbody" cols="8" rows="6"></textarea> | ||
|
||
<br /> | ||
<input type='hidden' name='authenticity_token' value="<%= form_authenticity_token %>"/> | ||
<input type='hidden' name='goto' value="analyze"/> | ||
<input id="commentsubmit" class="btn btn-primary" type="submit" value="Post" /> | ||
|
||
</form> | ||
<script> | ||
jQuery(document).ready(function() { | ||
$('#commentform').bind('submit', function(e){ | ||
e.preventDefault() | ||
$.ajax({ | ||
url: "/comment/create/<%= @spectrum.id %>", | ||
type: "POST", | ||
data: { | ||
authenticity_token: "<%= form_authenticity_token %>", | ||
comment: { | ||
body:$('#commentbody').val() | ||
} | ||
}, | ||
beforeSend: function() { | ||
$("#commentbody").prop('disabled',true) | ||
$("#commentsubmit").prop('disabled',true) | ||
}, | ||
success: function(response) { | ||
$('#commentlist').append('<div class="comment"><a name="comment_'+response+'"></a><b>Just now, <a href="/users/<%= current_user.login %>"><%= current_user.login %></a> wrote:</b><p>'+$('#commentbody').val()+'</p><p><small><a href="/comments/delete/'+response+'" onclick="return confirm(\'Are you sure?\');"><i class="icon icon-remove-sign"></i> Delete</a></small></p></div>') | ||
$('#commentbody').prop('disabled',false) | ||
$('#commentbody').val('') | ||
$("#commentsubmit").prop('disabled',false) | ||
}, | ||
error: function(response) { | ||
alert("There was an error and your comment couldn't be posted.") | ||
} | ||
}) | ||
}); | ||
|
||
}); | ||
</script> | ||
|
||
<% else %> | ||
<p><i>You must be logged in to comment.</i></p> | ||
<% end %> |