From 6736ac5e8cac6ac582d1dc56f10955a0b80b2a6f Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 14 2015 16:08:54 +0000 Subject: Support inline editing of issue comment --- diff --git a/pagure/templates/comment_update.html b/pagure/templates/comment_update.html index 7023226..ecd590f 100644 --- a/pagure/templates/comment_update.html +++ b/pagure/templates/comment_update.html @@ -1,8 +1,12 @@ +{% if not is_js %} {% extends "repo_master.html" %} +{% endif %} {% block repo %}
+ {% if not is_js %}
+ {% endif %}
@@ -15,9 +19,12 @@ {{ form.csrf_token }}
- + +
+ {% if not is_js %} + {% endif %}
{% endblock %} diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 7046503..ddef187 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -326,6 +326,25 @@ $(function() { $(obj).html(preview); }); + $(".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]; + $(sec).html(res); + }, + error: function() { + alert('Could not make edit work'); + } + }); + return false; + }) + }); diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index 6cae750..64618ce 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -65,6 +65,13 @@ def update_issue(repo, issueid, username=None): flask.abort( 403, 'This issue is private and you are not allowed to view it') + if flask.request.form.get('edit_comment'): + commentid = flask.request.form.get('edit_comment') + form = pagure.forms.EditCommentForm() + if form.validate_on_submit(): + return edit_comment_issue( + repo.name, issueid, commentid, username=username) + status = pagure.lib.get_issue_statuses(SESSION) form = pagure.forms.UpdateIssueForm(status=status) @@ -781,6 +788,8 @@ def view_issue_raw_file(repo, filename=None, username=None): def edit_comment_issue(repo, issueid, commentid, username=None): """Edit comment of an issue """ + is_js = flask.request.args.get('js', False) + project = pagure.lib.get_project(SESSION, repo, user=username) if not project: @@ -838,5 +847,6 @@ def edit_comment_issue(repo, issueid, commentid, username=None): repo=project, username=username, form=form, - comment=comment + comment=comment, + is_js=is_js, )