[refs #616] add error messages to ajax
This commit is contained in:
parent
f4bbeaaa46
commit
2c6d4bae9e
|
@ -13,6 +13,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
$('form.edit_comment').live('submit', function() {
|
$('form.edit_comment').live('submit', function() {
|
||||||
var form = $(this);
|
var form = $(this);
|
||||||
|
form.parent().find('.flash').remove();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: form.attr("action"),
|
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); })
|
$('.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){
|
error: function(data){
|
||||||
alert('error'); // TODO remove
|
form.before(data.responseText);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -224,6 +224,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
$('.edit_form.issue').live('submit', function() {
|
$('.edit_form.issue').live('submit', function() {
|
||||||
var form = $(this);
|
var form = $(this);
|
||||||
|
form.parent().find('.flash').remove();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: form.attr("action"),
|
url: form.attr("action"),
|
||||||
|
@ -235,7 +236,7 @@ $(document).ready(function() {
|
||||||
$('.fulltext.view.issue_body').html(data).find('code').each(function (code) { CodeMirrorRun(this); })
|
$('.fulltext.view.issue_body').html(data).find('code').each(function (code) { CodeMirrorRun(this); })
|
||||||
},
|
},
|
||||||
error: function(data){
|
error: function(data){
|
||||||
alert('error'); // TODO remove
|
form.before(data.responseText);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -23,8 +23,12 @@ class Projects::CommentsController < Projects::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
status = @comment.update_attributes(params[:comment]) ? 200 : 500
|
status, message = if @comment.update_attributes(params[:comment])
|
||||||
render :inline => view_context.markdown(@comment.body), :status => status
|
[200, view_context.markdown(@comment.body)]
|
||||||
|
else
|
||||||
|
[400, view_context.local_alert(@comment.errors.full_messages.join('. '))]
|
||||||
|
end
|
||||||
|
render :inline => message, :status => status
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
@ -51,10 +51,14 @@ class Projects::IssuesController < Projects::BaseController
|
||||||
if params[:issue] && status = params[:issue][:status]
|
if params[:issue] && status = params[:issue][:status]
|
||||||
@issue.set_close(current_user) if status == 'closed'
|
@issue.set_close(current_user) if status == 'closed'
|
||||||
@issue.set_open if status == 'open'
|
@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]
|
elsif params[:issue]
|
||||||
status = @issue.update_attributes(params[:issue]) ? 200 : 500
|
status, message = if @issue.update_attributes(params[:issue])
|
||||||
render :inline => view_context.markdown(@issue.body), :status => status
|
[200, view_context.markdown(@issue.body)]
|
||||||
|
else
|
||||||
|
[400, view_context.local_alert(@issue.errors.full_messages.join('. '))]
|
||||||
|
end
|
||||||
|
render :inline => message, :status => status
|
||||||
else
|
else
|
||||||
render :nothing => true, :status => 200
|
render :nothing => true, :status => 200
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,4 +48,10 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
@redcarpet.render(text).html_safe
|
@redcarpet.render(text).html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def local_alert(text, type = 'error')
|
||||||
|
html = "<div class='flash'><div class='alert #{type}'> #{text}"
|
||||||
|
html << link_to('×', '#', :class => 'close close-alert', 'data-dismiss' => 'alert')
|
||||||
|
html << '</div></div>'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue