Skip to content

Commit

Permalink
implement cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
releu committed Mar 3, 2013
1 parent 29a1086 commit 764d928
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
5 changes: 1 addition & 4 deletions app/assets/javascripts/cache.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ $ ->
.prop('contenteditable', true)
.html(data.content)
.focus()
false

$comments.on 'ajax:before', 'a.comment-control-save', (e, data) ->
$link = $(@)
Expand All @@ -82,13 +81,11 @@ $ ->
true


$comments.on 'ajax:success', 'a.comment-control-save', (e, data) ->
$link = $(@)
$comments.on 'ajax:success', 'a.comment-control-save, a.comment-control-cancel', (e, data) ->
$comment = $(e.delegateTarget)
$comment.find('li.comment-control-inactive').removeClass('hidden')
$comment.find('li.comment-control-active').addClass('hidden')
$body = $comment.find('div.comment-body')
$body
.prop('contenteditable', false)
.html(data.html)
false
7 changes: 6 additions & 1 deletion app/controllers/posts/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def create
# end
end

def show
@comment = Comment.find(params[:id])
render json: { html: @comment.html }
end

def edit
@comment = Comment.find(params[:id])
authorize! :edit, @comment
Expand All @@ -28,7 +33,7 @@ def update
@comment = Comment.find(params[:id])
authorize! :edit, @comment
@comment.update_attribute(:content, params[:content])
render json: { html: Markdown.markdown(@comment.content, flavored: true) }
render json: { html: @comment.html }
end

def destroy
Expand Down
4 changes: 4 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def decrement_counters
Post.decrement_counter(:comments_count, post_id)
end

def html
Markdown.markdown content, flavored: true
end

protected

def observe_post_to_author
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/_comments.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ section class="comments"
i class="icon-pencil"
span Edit
li class="comment-control-inactive"
= link_to [@post, comment], class: 'comment-control-remove secondary' do
= link_to [@post, comment], class: 'comment-control-remove secondary', data: { confirm: 'Are you sure?' } do
i class="icon-trash"
span Remove
li class="comment-control-active hidden"
Expand Down
7 changes: 1 addition & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@
get :leaderboard
end

resources :comments, only: [:create, :edit, :update, :destroy], module: :posts do
collection do
post :build
post :preview
end
end
resources :comments, except: :index, module: :posts
end

resource :search, only: :create
Expand Down

0 comments on commit 764d928

Please sign in to comment.