diff options
author | Dave Lawrence <dlawrence@mozilla.com> | 2014-01-11 18:12:42 +0100 |
---|---|---|
committer | Dave Lawrence <dlawrence@mozilla.com> | 2014-01-11 18:12:42 +0100 |
commit | 01db31261bcaa73dfeb6c287c1a22ece47d119eb (patch) | |
tree | 46c51ec369b81d2b13dc5a58dee9400ad7d8234e /extensions/EditComments/web | |
parent | 86f6ac8e6f57e2355691f95935330e5b1040f096 (diff) | |
download | bugzilla-01db31261bcaa73dfeb6c287c1a22ece47d119eb.tar.gz bugzilla-01db31261bcaa73dfeb6c287c1a22ece47d119eb.tar.xz |
Bug 936165 - Allow for privileged users to edit past comments and preserve comment history (BMO extension)
r=glob
Diffstat (limited to 'extensions/EditComments/web')
-rw-r--r-- | extensions/EditComments/web/js/editcomments.js | 90 | ||||
-rw-r--r-- | extensions/EditComments/web/styles/editcomments.css | 10 |
2 files changed, 100 insertions, 0 deletions
diff --git a/extensions/EditComments/web/js/editcomments.js b/extensions/EditComments/web/js/editcomments.js new file mode 100644 index 000000000..91763fa62 --- /dev/null +++ b/extensions/EditComments/web/js/editcomments.js @@ -0,0 +1,90 @@ +/* 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. + */ + +function editComment(comment_count, comment_id) { + if (!comment_count || !comment_id) return; + + 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 ] } + }) + ); +} + +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'); + + 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'); + } +} + diff --git a/extensions/EditComments/web/styles/editcomments.css b/extensions/EditComments/web/styles/editcomments.css new file mode 100644 index 000000000..911896ac8 --- /dev/null +++ b/extensions/EditComments/web/styles/editcomments.css @@ -0,0 +1,10 @@ +/* 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. */ + +.edit_comment_textarea { + width: 845px; +} |