diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index b59b99a..c804bc7 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -462,14 +462,6 @@ return window.confirm("Are you sure you want to close this requested pull?"); }); - function comment() { - $( ".cancel" ).click( - function() { - $(this).parent().parent().parent().parent().remove(); - } - ); - }; - $( ".code_table tr" ).hover( function() { $( this ).find( "img" ).show().width(13); @@ -502,7 +494,7 @@ $.get( url , function( data ) { next_row.before( '' + data + '' ); - comment(); + cancel_edit_btn(); emoji_complete(json_url, folder); }); } else { @@ -556,6 +548,44 @@ } ); + $(".edit_btn").click(function() { + var commentid = $( this ).attr('data-comment'); + var _url = '{{ request.base_url }}' + '/comment/' + commentid + '/edit'; + $.ajax({ + url: _url + '?js=1', + type: 'GET', + dataType: 'html', + success: function(res) { + var el = $('#comment-' + commentid); + var sec = el.parent().children()[1]; + if (!sec) { + sec = el.parent().parent(); + $(sec).next().hide(); + var row = $(sec).parent().parent().append( + "" + res + ""); + } else { + $(sec).hide(); + $(sec).after(res); + } + cancel_edit_btn(); + }, + error: function() { + alert('Could not make edit work'); + } + }); + return false; + }); + + function cancel_edit_btn() { + $( ".cancel" ).click( + function() { + $(this).parent().parent().parent().parent().parent().find('.comment_body').show(); + $(this).parent().parent().parent().parent().remove(); + return false; + } + ); + }; + var cur_hash = null; highlight_comment = function() { diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index a66e76a..b32668b 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -499,6 +499,13 @@ def pull_request_drop_comment(repo, requestid, username=None): if not request: flask.abort(404, 'Pull-request not found') + if flask.request.form.get('edit_comment'): + commentid = flask.request.form.get('edit_comment') + form = pagure.forms.EditCommentForm() + if form.validate_on_submit(): + return pull_request_edit_comment( + repo.name, requestid, commentid, username=username) + form = pagure.forms.ConfirmationForm() if form.validate_on_submit(): @@ -541,6 +548,8 @@ def pull_request_drop_comment(repo, requestid, username=None): def pull_request_edit_comment(repo, requestid, commentid, username=None): """Edit comment of a pull request """ + is_js = flask.request.args.get('js', False) + project = pagure.lib.get_project(SESSION, repo, user=username) if not project: @@ -599,7 +608,8 @@ def pull_request_edit_comment(repo, requestid, commentid, username=None): repo=project, username=username, form=form, - comment=comment + comment=comment, + is_js=is_js, )