From 2e2981d25c185fde56f29c7aed4e3e6bba50039e Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Thu, 15 Oct 2015 23:59:10 +0800 Subject: Bug 1153101 - add hooks for edit-comments extension --- .../hook/bug/comments-a_comment-end.html.tmpl | 52 -------- .../en/default/hook/bug/show-header-end.html.tmpl | 12 -- .../activity_stream-comment_action.html.tmpl | 26 ++++ .../en/default/hook/bug_modal/header-end.html.tmpl | 14 +++ .../en/default/pages/editcomments.html.tmpl | 127 +++++--------------- extensions/EditComments/web/js/editcomments.js | 132 ++++++++------------- .../EditComments/web/styles/editcomments.css | 22 +++- 7 files changed, 139 insertions(+), 246 deletions(-) delete mode 100644 extensions/EditComments/template/en/default/hook/bug/comments-a_comment-end.html.tmpl delete mode 100644 extensions/EditComments/template/en/default/hook/bug/show-header-end.html.tmpl create mode 100644 extensions/EditComments/template/en/default/hook/bug_modal/activity_stream-comment_action.html.tmpl create mode 100644 extensions/EditComments/template/en/default/hook/bug_modal/header-end.html.tmpl (limited to 'extensions/EditComments') diff --git a/extensions/EditComments/template/en/default/hook/bug/comments-a_comment-end.html.tmpl b/extensions/EditComments/template/en/default/hook/bug/comments-a_comment-end.html.tmpl deleted file mode 100644 index cf54c71ed..000000000 --- a/extensions/EditComments/template/en/default/hook/bug/comments-a_comment-end.html.tmpl +++ /dev/null @@ -1,52 +0,0 @@ -[%# This Source Code Form is subject to the terms of the Mozilla Public - # License, v. 2.0. If a copy of the MPL was not distributed with this - # file, You can obtain one at http://mozilla.org/MPL/2.0/. - # - # This Source Code Form is "Incompatible With Secondary Licenses", as - # defined by the Mozilla Public License, v. 2.0. - #%] - -[% IF comment.body != '' - && Param('edit_comments_group') - && user.in_group(Param('edit_comments_group')) - && (comment.type == constants.CMT_NORMAL - || comment.type == constants.CMT_DUPE_OF - || comment.type == constants.CMT_ATTACHMENT_CREATED - || comment.type == constants.CMT_ATTACHMENT_UPDATED) -%] - - [edit - [% IF comment.edit_count %] - | history - ([% comment.edit_count FILTER html %]) - [% END %]] - -
-
Loading...
- [% INCLUDE global/textarea.html.tmpl - name = "edit_comment_textarea_${comment.id}" - id = "edit_comment_textarea_${comment.count}" - minrows = 10 - maxrows = 25 - classes = "edit_comment_textarea bz_default_hidden" - cols = constants.COMMENT_COLS - disabled = 1 - %] -
- -[% END %] diff --git a/extensions/EditComments/template/en/default/hook/bug/show-header-end.html.tmpl b/extensions/EditComments/template/en/default/hook/bug/show-header-end.html.tmpl deleted file mode 100644 index 331d7e6df..000000000 --- a/extensions/EditComments/template/en/default/hook/bug/show-header-end.html.tmpl +++ /dev/null @@ -1,12 +0,0 @@ -[%# This Source Code Form is subject to the terms of the Mozilla Public - # License, v. 2.0. If a copy of the MPL was not distributed with this - # file, You can obtain one at http://mozilla.org/MPL/2.0/. - # - # This Source Code Form is "Incompatible With Secondary Licenses", as - # defined by the Mozilla Public License, v. 2.0. - #%] - -[% IF Param('edit_comments_group') && user.in_group(Param('edit_comments_group')) %] - [% style_urls.push('extensions/EditComments/web/styles/editcomments.css') %] - [% javascript_urls.push('extensions/EditComments/web/js/editcomments.js') %] -[% END %] diff --git a/extensions/EditComments/template/en/default/hook/bug_modal/activity_stream-comment_action.html.tmpl b/extensions/EditComments/template/en/default/hook/bug_modal/activity_stream-comment_action.html.tmpl new file mode 100644 index 000000000..358359243 --- /dev/null +++ b/extensions/EditComments/template/en/default/hook/bug_modal/activity_stream-comment_action.html.tmpl @@ -0,0 +1,26 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + +[% + RETURN IF comment.body == ''; + RETURN UNLESS Param('edit_comments_group') && user.in_group(Param('edit_comments_group')); + RETURN UNLESS + comment.type == constants.CMT_NORMAL + || comment.type == constants.CMT_DUPE_OF + || comment.type == constants.CMT_ATTACHMENT_CREATED + || comment.type == constants.CMT_ATTACHMENT_UPDATED; +%] + +[% IF comment.edit_count %] + (Edited) +[% END %] + + diff --git a/extensions/EditComments/template/en/default/hook/bug_modal/header-end.html.tmpl b/extensions/EditComments/template/en/default/hook/bug_modal/header-end.html.tmpl new file mode 100644 index 000000000..68597bcb0 --- /dev/null +++ b/extensions/EditComments/template/en/default/hook/bug_modal/header-end.html.tmpl @@ -0,0 +1,14 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + +[% + IF Param('edit_comments_group') && user.in_group(Param('edit_comments_group')); + style_urls.push('extensions/EditComments/web/styles/editcomments.css'); + javascript_urls.push('extensions/EditComments/web/js/editcomments.js'); + END; +%] diff --git a/extensions/EditComments/template/en/default/pages/editcomments.html.tmpl b/extensions/EditComments/template/en/default/pages/editcomments.html.tmpl index 8b3b90c9e..13364f5b1 100644 --- a/extensions/EditComments/template/en/default/pages/editcomments.html.tmpl +++ b/extensions/EditComments/template/en/default/pages/editcomments.html.tmpl @@ -6,117 +6,44 @@ # defined by the Mozilla Public License, v. 2.0. #%] -[% PROCESS global/variables.none.tmpl %] - -[% PROCESS global/header.html.tmpl - title = "Comment changes made to $terms.bug $bug.id, comment $comment.id" - header = "Activity log for $terms.bug $bug.id, comment $comment.id" - %] - - +[% + PROCESS global/variables.none.tmpl; + PROCESS global/header.html.tmpl + title = "$bug.id comment $comment.count Activity" + style_urls = ['extensions/EditComments/web/styles/editcomments.css'] +%] + +

+ Comment changes made to + [%= "$terms.bug $bug.id comment $comment.count" + FILTER bug_link(bug, { comment_num => comment.count }) + FILTER none %] +

- [% "Back to $terms.bug $bug.id" FILTER bug_link(bug.id) FILTER none %] + Note: The actual edited comment in the [% terms.bug %] view + page will always show the original commentor's name and original timestamp.

-

- Note: The actual edited comment in the [% terms.bug %] view page will always show the original commentor's name and original timestamp. -

- -

- Collapse All Changes - - Expand All Changes -

- -[% count = 0 %] [% FOREACH a = comment.activity %] -
-
- - [% IF a.original %] - Original comment by [% (a.author.name || "Need Real Name") FILTER html %] - - () - - on [%+ a.time FILTER time %] - [% ELSE %] - Revision by [% (a.author.name || "Need Real Name") FILTER html %] - - () - - on [%+ a.time FILTER time %] - [% END %] - - [-] +
+
+ [% a.original ? "Original comment" : "Revision" %] + by [% INCLUDE bug_modal/user.html.tmpl u=a.author %] + on [% a.time FILTER time %]
- [% IF a.original %] - [% wrapped_comment = a.body FILTER wrap_comment %] - [% ELSE %] - [% wrapped_comment = a.new FILTER wrap_comment %] - [% END %] -[%# Don't indent the
 block, since then the spaces are displayed in the
-  # generated HTML %]
-
-  [%- wrapped_comment FILTER quoteUrls(bug) -%]
-
- [% count = count + 1 %] +
+    [%- a.original ? a.body : a.new FILTER quoteUrls(bug) -%]
+  
[% END %] -[% IF comment.activity.size > 0 %] +[% IF comment.activity.size %]

- [% "Back to $terms.bug $bug.id" FILTER bug_link(bug.id) FILTER none %] + [%= "Back to $terms.bug $bug.id comment $comment.count" + FILTER bug_link(bug, { comment_num => comment.count }) + FILTER none %]

[% END %] [% PROCESS global/footer.html.tmpl %] - diff --git a/extensions/EditComments/web/js/editcomments.js b/extensions/EditComments/web/js/editcomments.js index a4e3014d5..222c081cf 100644 --- a/extensions/EditComments/web/js/editcomments.js +++ b/extensions/EditComments/web/js/editcomments.js @@ -6,87 +6,59 @@ * defined by the Mozilla Public License, v. 2.0. */ -function editComment(comment_count, comment_id) { - if (!comment_count || !comment_id) return; +$(function() { + $('.edit-comment-btn') + .click(function(event) { + event.preventDefault(); + var that = $(this); + var id = that.data('id'); + var no = that.data('no'); - var edit_comment_textarea = YAHOO.util.Dom.get('edit_comment_textarea_' + comment_count); - if (!YAHOO.util.Dom.hasClass(edit_comment_textarea, 'bz_default_hidden')) { - hideEditCommentField(comment_count); - return; - } - - // Show the loading indicator - toggleCommentLoading(comment_count); - - YAHOO.util.Connect.setDefaultPostHeader('application/json', true); - YAHOO.util.Connect.asyncRequest( - 'POST', - 'jsonrpc.cgi', - { - success: function(res) { - // Hide the loading indicator - toggleCommentLoading(comment_count); - data = YAHOO.lang.JSON.parse(res.responseText); - if (data.error) { - alert("Get [% comment failed: " + data.error.message); - } - else if (data.result.comments[comment_id]) { - var comment_text = data.result.comments[comment_id]; - showEditCommentField(comment_count, comment_text); - } - }, - failure: function(res) { - // Hide the loading indicator - toggleCommentLoading(comment_count); - if (res.responseText) { - alert("Get comment failed: " + res.responseText); - } - } - }, - YAHOO.lang.JSON.stringify({ - version: "1.1", - method: "EditComments.comments", - id: comment_id, - params: { comment_ids: [ comment_id ], - Bugzilla_api_token : (BUGZILLA.api_token ? BUGZILLA.api_token : '') + // cancel editing + if (that.data('editing')) { + that.data('editing', false).text('Edit'); + $('#edit_comment_textarea_' + id).remove(); + $('#ct-' + no).show(); + return; } - }) - ); -} - -function hideEditCommentField(comment_count) { - var comment_text_pre = YAHOO.util.Dom.get('comment_text_' + comment_count); - YAHOO.util.Dom.removeClass(comment_text_pre, 'bz_default_hidden'); + that.text('Unedit'); - var edit_comment_textarea = YAHOO.util.Dom.get('edit_comment_textarea_' + comment_count); - YAHOO.util.Dom.addClass(edit_comment_textarea, 'bz_default_hidden'); - edit_comment_textarea.disabled = true; - - YAHOO.util.Dom.get("edit_comment_edit_link_" + comment_count).innerHTML = "edit"; -} - -function showEditCommentField(comment_count, comment_text) { - var comment_text_pre = YAHOO.util.Dom.get('comment_text_' + comment_count); - YAHOO.util.Dom.addClass(comment_text_pre, 'bz_default_hidden'); - - var edit_comment_textarea = YAHOO.util.Dom.get('edit_comment_textarea_' + comment_count); - YAHOO.util.Dom.removeClass(edit_comment_textarea, 'bz_default_hidden'); - edit_comment_textarea.disabled = false; - edit_comment_textarea.value = comment_text; - - YAHOO.util.Dom.get("edit_comment_edit_link_" + comment_count).innerHTML = "unedit"; -} - -function toggleCommentLoading(comment_count, hide) { - var comment_div = 'comment_text_' + comment_count; - var loading_div = 'edit_comment_loading_' + comment_count; - if (YAHOO.util.Dom.hasClass(loading_div, 'bz_default_hidden')) { - YAHOO.util.Dom.addClass(comment_div, 'bz_default_hidden'); - YAHOO.util.Dom.removeClass(loading_div, 'bz_default_hidden'); - } - else { - YAHOO.util.Dom.removeClass(comment_div, 'bz_default_hidden'); - YAHOO.util.Dom.addClass(loading_div, 'bz_default_hidden'); - } -} + // replace comment
 with loading message
+            $('#ct-' + no)
+                .hide()
+                .after(
+                    $('
')
+                        .attr('id', 'edit-comment-loading-' + id)
+                        .addClass('edit-comment-loading')
+                        .text('Loading...')
+                );
 
+            // load original comment text
+            bugzilla_ajax(
+                {
+                    url: 'rest/editcomments/comment/' + id,
+                    hideError: true
+                },
+                function(data) {
+                    // create editing textarea
+                    $('#edit-comment-loading-' + id).remove();
+                    that.data('editing', true);
+                    $('#ct-' + no)
+                        .after(
+                            $('