comment editing, looks weird for now but it works
This commit is contained in:
parent
cd568eaa38
commit
f8dd75fde4
|
@ -145,8 +145,8 @@ var _Lobsters = Class.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
previewComment: function(form) {
|
previewComment: function(form) {
|
||||||
$(form).parent().load($(form).attr("action").replace(/^\/comments/,
|
$(form).parent().load($(form).attr("action").replace(/(post|update)/,
|
||||||
"/comments/preview"), $(form).serializeArray());
|
"preview"), $(form).serializeArray());
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchURLTitle: function(button, url_field, title_field) {
|
fetchURLTitle: function(button, url_field, title_field) {
|
||||||
|
@ -224,6 +224,12 @@ $(document).ready(function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("a.comment_editor").live("click", function() {
|
||||||
|
var li = $(this).parents("li.comment").first();
|
||||||
|
li.load("/comments/" + $(li).attr("data-shortid") + "/edit",
|
||||||
|
{ "edit": 1 });
|
||||||
|
});
|
||||||
|
|
||||||
$("#story_tags_a").select2({
|
$("#story_tags_a").select2({
|
||||||
formatSelection: function(what) {
|
formatSelection: function(what) {
|
||||||
return what.id;
|
return what.id;
|
||||||
|
|
|
@ -49,12 +49,63 @@ class CommentsController < ApplicationController
|
||||||
:comment => comment, :show_comment => comment }
|
:comment => comment, :show_comment => comment }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview
|
def preview_new
|
||||||
params[:preview] = true
|
params[:preview] = true
|
||||||
return create
|
return create
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
if !((comment = Comment.find_by_short_id(params[:comment_id])) &&
|
||||||
|
comment.is_editable_by_user?(@user))
|
||||||
|
return render :text => "can't find comment", :status => 400
|
||||||
|
end
|
||||||
|
|
||||||
|
render :partial => "commentbox", :layout => false,
|
||||||
|
:content_type => "text/html", :locals => { :story => comment.story,
|
||||||
|
:comment => comment }
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if !((comment = Comment.find_by_short_id(params[:comment_id])) &&
|
||||||
|
comment.is_editable_by_user?(@user))
|
||||||
|
return render :text => "can't find comment", :status => 400
|
||||||
|
end
|
||||||
|
|
||||||
|
comment.comment = params[:comment]
|
||||||
|
|
||||||
|
if comment.save
|
||||||
|
# TODO: render the comment again properly, it's indented wrong
|
||||||
|
|
||||||
|
render :partial => "postedreply", :layout => false,
|
||||||
|
:content_type => "text/html", :locals => { :story => comment.story,
|
||||||
|
:show_comment => comment }
|
||||||
|
else
|
||||||
|
comment.previewing = true
|
||||||
|
comment.current_vote = { :vote => 1 }
|
||||||
|
|
||||||
|
render :partial => "commentbox", :layout => false,
|
||||||
|
:content_type => "text/html", :locals => { :story => comment.story,
|
||||||
|
:comment => comment, :show_comment => comment }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def preview
|
||||||
|
if !((comment = Comment.find_by_short_id(params[:comment_id])) &&
|
||||||
|
comment.is_editable_by_user?(@user))
|
||||||
|
return render :text => "can't find comment", :status => 400
|
||||||
|
end
|
||||||
|
|
||||||
|
comment.comment = params[:comment]
|
||||||
|
|
||||||
|
comment.previewing = true
|
||||||
|
comment.current_vote = { :vote => 1 }
|
||||||
|
|
||||||
|
render :partial => "commentbox", :layout => false,
|
||||||
|
:content_type => "text/html", :locals => { :story => comment.story,
|
||||||
|
:comment => comment, :show_comment => comment }
|
||||||
|
end
|
||||||
|
|
||||||
def unvote
|
def unvote
|
||||||
if !(comment = Comment.find_by_short_id(params[:comment_id]))
|
if !(comment = Comment.find_by_short_id(params[:comment_id]))
|
||||||
return render :text => "can't find comment", :status => 400
|
return render :text => "can't find comment", :status => 400
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<div class="comment_form_container">
|
<div class="comment_form_container">
|
||||||
<%= form_tag("/comments/#{story.short_id}", { :id => "comment_form" }) do |f| %>
|
<%= form_tag((comment.new_record? ? "/comments/post_to/#{story.short_id}" :
|
||||||
|
"/comments/#{comment.short_id}/update"), { :id => "comment_form" }) do |f| %>
|
||||||
<% if comment.parent_comment_short_id.present? %>
|
<% if comment.parent_comment_short_id.present? %>
|
||||||
<%= hidden_field_tag "parent_comment_short_id",
|
<%= hidden_field_tag "parent_comment_short_id",
|
||||||
comment.parent_comment_short_id %>
|
comment.parent_comment_short_id %>
|
||||||
|
@ -16,8 +17,8 @@
|
||||||
<span class="fakea">Markdown formatting available</span>
|
<span class="fakea">Markdown formatting available</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= button_tag "Post Comment", :class => "comment-post",
|
<%= button_tag "#{comment.new_record?? "Post" : "Update"} Comment",
|
||||||
:type => "button" %>
|
:class => "comment-post", :type => "button" %>
|
||||||
|
|
||||||
<%= button_tag "Preview Comment", :class => "comment-preview",
|
<%= button_tag "Preview Comment", :class => "comment-preview",
|
||||||
:type => "button" %>
|
:type => "button" %>
|
||||||
|
|
|
@ -29,14 +29,18 @@ Lobsters::Application.routes.draw do
|
||||||
post "undelete"
|
post "undelete"
|
||||||
end
|
end
|
||||||
post "/stories/fetch_url_title" => "stories#fetch_url_title"
|
post "/stories/fetch_url_title" => "stories#fetch_url_title"
|
||||||
|
|
||||||
resources :comments do
|
resources :comments do
|
||||||
post "upvote"
|
post "upvote"
|
||||||
post "downvote"
|
post "downvote"
|
||||||
post "unvote"
|
post "unvote"
|
||||||
|
|
||||||
|
post "edit"
|
||||||
|
post "preview"
|
||||||
|
post "update"
|
||||||
end
|
end
|
||||||
post "/comments/:story_id" => "comments#create"
|
post "/comments/post_to/:story_id" => "comments#create"
|
||||||
post "/comments/preview/:story_id" => "comments#preview"
|
post "/comments/preview_to/:story_id" => "comments#preview_new"
|
||||||
|
|
||||||
resources :messages do
|
resources :messages do
|
||||||
post "keep_as_new"
|
post "keep_as_new"
|
||||||
|
|
Loading…
Reference in a new issue