diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index 6c9532e..5bec287 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -455,5 +455,35 @@ {% endif %} }); + +{% if authenticated %} +function try_async_comment(form) { + $.post( form.action + "?js=1", $(form).serialize() ) + .done(function(data) { + if(data == 'ok') { + // We have submitted the comment correctly + var comment_fld = $(form).find("#comment")[0]; + var comment = comment_fld.value; + var comment_view = "" + + ""; + $(form).closest('tr').before($(comment_view)).remove(); + } else { + // Make the browser submit the form sync + $(form).off('submit'); + form.submit(); + } + }) + .fail(function() { + // Make the browser submit the form sync + $(form).off('submit'); + form.submit(); + }) + return false; +}; +{% endif %} + {% endblock %} diff --git a/pagure/templates/pull_request_comment.html b/pagure/templates/pull_request_comment.html index 0d23134..b2c71c3 100644 --- a/pagure/templates/pull_request_comment.html +++ b/pagure/templates/pull_request_comment.html @@ -3,7 +3,7 @@ + method="post" onsubmit="return try_async_comment(this)">
diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 85f871d..49d685b 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -345,6 +345,8 @@ def pull_request_add_comment( if not request: flask.abort(404, 'Pull-request not found') + is_js = flask.request.args.get('js', False) + repo = request.project_from form = pagure.forms.AddPullRequestCommentForm() @@ -373,11 +375,17 @@ def pull_request_add_comment( SESSION.rollback() APP.logger.exception(err) flask.flash(str(err), 'error') + if is_js: + return 'error' + if is_js: + return 'ok' return flask.redirect(flask.url_for( 'request_pull', username=username, repo=repo.name, requestid=requestid)) + if is_js: + return 'failed' return flask.render_template( 'pull_request_comment.html', select='requests',
" + + "{{ g.fas_user.username }}" + + "Now

" + + comment + "