diff --git a/app/assets/javascripts/extra/comment.js b/app/assets/javascripts/extra/comment.js index 3b125707f..5bcf3aa20 100644 --- a/app/assets/javascripts/extra/comment.js +++ b/app/assets/javascripts/extra/comment.js @@ -13,6 +13,7 @@ $(document).ready(function() { $('form.edit_comment').live('submit', function() { var form = $(this); + form.parent().find('.flash').remove(); $.ajax({ type: 'POST', url: form.attr("action"), @@ -23,7 +24,7 @@ $(document).ready(function() { $('.buttons a.edit_comment#'+cancel_button.attr('id')).parent().parent().find('.cm-s-default.md_and_cm').html(data).find('code').each(function (code) { CodeMirrorRun(this); }) }, error: function(data){ - alert('error'); // TODO remove + form.before(data.responseText); } }); return false; diff --git a/app/assets/javascripts/extra/tracker.js b/app/assets/javascripts/extra/tracker.js index 356973ed9..24aaf3f2f 100644 --- a/app/assets/javascripts/extra/tracker.js +++ b/app/assets/javascripts/extra/tracker.js @@ -224,6 +224,7 @@ $(document).ready(function() { $('.edit_form.issue').live('submit', function() { var form = $(this); + form.parent().find('.flash').remove(); $.ajax({ type: 'POST', url: form.attr("action"), @@ -235,7 +236,7 @@ $(document).ready(function() { $('.fulltext.view.issue_body').html(data).find('code').each(function (code) { CodeMirrorRun(this); }) }, error: function(data){ - alert('error'); // TODO remove + form.before(data.responseText); } }); return false; diff --git a/app/controllers/projects/comments_controller.rb b/app/controllers/projects/comments_controller.rb index 94c366fb4..003ed166e 100644 --- a/app/controllers/projects/comments_controller.rb +++ b/app/controllers/projects/comments_controller.rb @@ -23,8 +23,12 @@ class Projects::CommentsController < Projects::BaseController end def update - status = @comment.update_attributes(params[:comment]) ? 200 : 500 - render :inline => view_context.markdown(@comment.body), :status => status + status, message = if @comment.update_attributes(params[:comment]) + [200, view_context.markdown(@comment.body)] + else + [400, view_context.local_alert(@comment.errors.full_messages.join('. '))] + end + render :inline => message, :status => status end def destroy diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index 2902f28b6..f82894462 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -51,10 +51,14 @@ class Projects::IssuesController < Projects::BaseController if params[:issue] && status = params[:issue][:status] @issue.set_close(current_user) if status == 'closed' @issue.set_open if status == 'open' - render :partial => 'status', :status => (@issue.save ? 200 : 500) + render :partial => 'status', :status => (@issue.save ? 200 : 400) elsif params[:issue] - status = @issue.update_attributes(params[:issue]) ? 200 : 500 - render :inline => view_context.markdown(@issue.body), :status => status + status, message = if @issue.update_attributes(params[:issue]) + [200, view_context.markdown(@issue.body)] + else + [400, view_context.local_alert(@issue.errors.full_messages.join('. '))] + end + render :inline => message, :status => status else render :nothing => true, :status => 200 end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fe7537c4f..970715327 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -48,4 +48,10 @@ module ApplicationHelper end @redcarpet.render(text).html_safe end + + def local_alert(text, type = 'error') + html = "
#{text}" + html << link_to('×', '#', :class => 'close close-alert', 'data-dismiss' => 'alert') + html << '
' + end end