summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorDavid Lawrence <dkl@mozilla.com>2014-12-22 20:18:01 +0100
committerDavid Lawrence <dkl@mozilla.com>2014-12-22 20:18:01 +0100
commitbe26c119991e5e4e6ec28a881bc0860a4cd9aefc (patch)
tree419eb01f943babf2b6b86f1daa8ef5bce0bfb1bd /js
parent0bc389f1ea11fac82b3c783e03408900eddf269d (diff)
downloadbugzilla-be26c119991e5e4e6ec28a881bc0860a4cd9aefc.tar.gz
bugzilla-be26c119991e5e4e6ec28a881bc0860a4cd9aefc.tar.xz
Bug 1093924: Move replyToMarkdownComment() and replyToComment() out of templates
r=LpSolit,a=glob
Diffstat (limited to 'js')
-rw-r--r--js/comments.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/js/comments.js b/js/comments.js
index 43e6fe96e..30baf53f4 100644
--- a/js/comments.js
+++ b/js/comments.js
@@ -6,6 +6,69 @@
* defined by the Mozilla Public License, v. 2.0.
*/
+/* Adds the reply text to the 'comment' textarea */
+function replyToComment(id, real_id, replyto_header, text) {
+ var replytext = "";
+ if (replyCommentConfig.quote_replies == 'quoted_reply') {
+ /* pre id="comment_name_N" */
+ if (text == null) {
+ var text_elem = document.getElementById('comment_text_'+id);
+ text = getText(text_elem);
+ }
+ replytext = replyto_header + "\n" + wrapReplyText(text);
+ } else if (replyCommentConfig.quote_replies == 'simple_reply') {
+ replytext = replyto_header + "\n";
+ }
+
+ if (replyCommentConfig.is_insider) {
+ if (document.getElementById('isprivate_' + real_id).checked) {
+ document.getElementById('newcommentprivacy').checked = 'checked';
+ updateCommentTagControl(document.getElementById('newcommentprivacy'), 'comment');
+ }
+ }
+
+ /* <textarea id="comment"> */
+ var textarea = document.getElementById('comment');
+ if (textarea.value != replytext) {
+ textarea.value += replytext;
+ }
+
+ textarea.focus();
+}
+
+function replyToMarkdownComment(id, real_id, replyto_header) {
+ var textarea = document.getElementById('comment');
+ var comment = textarea.value;
+ textarea.value += replyCommentConfig.markdown_fetching_comment;
+ YAHOO.util.Connect.setDefaultPostHeader('application/json', true);
+ YAHOO.util.Connect.asyncRequest('POST', 'jsonrpc.cgi',
+ {
+ success: function(res) {
+ var data = YAHOO.lang.JSON.parse(res.responseText);
+ if (!data.error) {
+ textarea.value = comment;
+ var text = data.result.comments[real_id].text;
+ replyToComment(id, real_id, replyto_header, text);
+ } else {
+ replyToComment(id, real_id, replyto_header);
+ }
+ },
+ failure: function(res) {
+ /* On failure, quote the comment as plain-text */
+ replyToComment(id, real_id, replyto_header);
+ }
+ },
+ YAHOO.lang.JSON.stringify({
+ version: "1.1",
+ method: "Bug.comments",
+ params: {
+ Bugzilla_api_token: BUGZILLA.api_token,
+ comment_ids: [real_id],
+ }
+ })
+ );
+}
+
function updateCommentPrivacy(checkbox, id) {
var comment_elem = document.getElementById('comment_text_'+id).parentNode;
if (checkbox.checked) {