[refs #616] comment update

This commit is contained in:
Alexander Machehin 2012-09-19 00:42:22 +06:00
parent a492367a17
commit daf845705a
4 changed files with 46 additions and 9 deletions

View File

@ -0,0 +1,35 @@
$(document).ready(function() {
$('.buttons a.edit_comment').live('click', function() {
$(this).parent().parent().parent().hide();
$('#open-comment'+'.comment.'+$(this).attr('id')).show();
return false;
});
$('.cancel_edit_comment.button').live('click', function() {
$(this).parent().parent().parent().hide();
$('.buttons a.edit_comment#'+$(this).attr('id')).parent().parent().parent().show();
return false;
});
$('form.edit_comment').live('submit', function() {
var form = $(this);
$.ajax({
type: 'POST',
url: form.attr("action"),
data: form.serialize(),
success: function(data){
var cancel_button = form.find('.cancel_edit_comment.button');
cancel_button.click();
$('.buttons a.edit_comment#'+cancel_button.attr('id')).parent().parent().find('.cm-s-default.md_and_cm').html(data).find('code').each(function (code) {
CodeMirror.runMode(this.innerHTML.replace(/&/gi, '&'), this.className, this);
});
},
error: function(data){
alert('error'); // TODO remove
}
});
return false;
});
});

View File

@ -22,13 +22,8 @@ class Projects::CommentsController < Projects::BaseController
end end
def update def update
if @comment.update_attributes(params[:comment]) status = @comment.update_attributes(params[:comment]) ? 200 : 500
flash[:notice] = I18n.t("flash.comment.saved") render :inline => view_context.markdown(@comment.body), :status => status
redirect_to project_commentable_path(@project, @commentable)
else
flash[:error] = I18n.t("flash.comment.save_error")
render :action => 'new'
end
end end
def destroy def destroy

View File

@ -40,7 +40,7 @@ class CommentPresenter < ApplicationPresenter
res = [] res = []
if controller.can? :update, @comment if controller.can? :update, @comment
res << link_to(t("layout.edit"), ep).html_safe res << link_to(t("layout.edit"), ep, html_options = {:id => "comment-#{comment.id}", :class => "edit_comment"}).html_safe
end end
if controller.can? :delete, @comment if controller.can? :delete, @comment
res << link_to(t("layout.delete"), dp, :method => "delete", res << link_to(t("layout.delete"), dp, :method => "delete",

View File

@ -4,3 +4,10 @@
- list.each do |comment| - list.each do |comment|
- CommentPresenter.present(comment, :project => project, :commentable => commentable) do |presenter| - CommentPresenter.present(comment, :project => project, :commentable => commentable) do |presenter|
= render 'shared/feed_message', :presenter => presenter = render 'shared/feed_message', :presenter => presenter
#open-comment.comment.hidden{:class => "comment-#{comment.id}"}
%h3.tmargin0= t("layout.comments.edit_header")
= form_for comment, :url => project_commentable_comment_path(project, commentable, comment), :html => { :class => 'form edit_comment' } do |f|
= render "projects/comments/form", :f => f, :id => "edit_#{comment.id}"
.comment-left{:style => 'margin-top: 0;'}
=link_to t('layout.cancel'), '#', :id => "comment-#{comment.id}", :class => 'cancel_edit_comment button'
.both