]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Fix for bug 207754 aka bugreplies: It should be possible to produce a
authorkiko%async.com.br <>
Tue, 2 Sep 2003 07:11:25 +0000 (07:11 +0000)
committerkiko%async.com.br <>
Tue, 2 Sep 2003 07:11:25 +0000 (07:11 +0000)
quoted reply to a comment. Adds a reply link that uses JS to paste in
a quoted comment into the comment textarea. Patch by me, r=caillon,
preed, bbaetz a=justdave

template/en/default/bug/comments.html.tmpl
template/en/default/bug/edit.html.tmpl

index 98d7ae3869a84d6e8954993f902fe81535b1d860..0ea28ef3b4dce3fc93240cb2924dc36ea9e4902f 100644 (file)
     <div [% "class=\"bz_private\"" IF comment.isprivate %]>
       [% IF count > 0 %]
         <br>
-        <i>------- Additional Comment
+        ------- <i>Additional Comment
         <a name="c[% count %]" href="#c[% count %]">#[% count %]</a> From 
-        <a href="mailto:[% comment.email FILTER html %]">[% comment.name FILTER html %]</a>
+        <a href="mailto:[% comment.email FILTER html %]">
+          [% comment.name FILTER html %]</a>
         [%+ comment.time FILTER time %] 
-        -------
         </i>
+        [% IF mode == "edit" %]
+        <script type="text/javascript" language="JavaScript"><!-- 
+          addReplyLink([% count %]); //--></script>
+        [% END %]
+        -------
       [% END %]
         
       [% IF mode == "edit" && isinsider %]
          Additional hours worked: 
          [% PROCESS formattimeunit time_unit=comment.work_time %]
       [% END %]
+
 [%# Don't indent the <pre> block, since then the spaces are displayed in the
   # generated HTML
   #%]
-<pre>
+<pre[% ' id="comment_text_' _ count _ '"' IF mode == "edit" %]>
   [%- comment.body FILTER quoteUrls -%]
 </pre>
     </div>
index 259362074ab19767d68a0590479c7b21fa551adf..5b02d23b84b0907e6f65a5e97f472189ae8f623b 100644 (file)
 
 [% PROCESS bug/time.html.tmpl %]
 
-[% IF UserInGroup(Param('timetrackinggroup')) %]
   <script type="text/javascript" language="JavaScript">
   <!--
+
+  /* Outputs a link to call replyToComment(); used to reduce HTML output */
+  function addReplyLink(id) {
+    /* XXX this should really be updated to use the DOM Core's
+     * createElement, but finding a container isn't trivial */
+    document.write('[<a href="#add_comment" onclick="replyToComment(' + 
+        id + ');">reply<' + '/a>]');
+  }
+
+  /* Adds the reply text to the `comment' textarea */
+  function replyToComment(id) {
+    /* pre id="comment_name_N" */
+    var text_elem = document.getElementById('comment_text_'+id);
+    var text = getText(text_elem);
+
+    /* make sure we split on all newlines -- IE or Moz use \r and \n
+     * respectively */
+    text = text.split(/\r|\n/);
+
+    var replytext = "";
+    for (var i=0; i < text.length; i++) {
+        replytext += "> " + text[i] + "\n"; 
+    }
+
+    replytext = "(In reply to comment #" + id + ")\n" + replytext + "\n";
+
+    /* <textarea id="comment"> */
+    var textarea = document.getElementById('comment');
+    textarea.value += replytext;
+
+    textarea.focus();
+  }
+
+  if (!Node) {
+    /* MSIE doesn't define Node, so provide a compatibility array */
+    var Node = {
+        TEXT_NODE: 3,
+        ENTITY_REFERENCE_NODE: 5
+    };
+  }
+
+  /* Concatenates all text from element's childNodes. This is used
+   * instead of innerHTML because we want the actual text (and
+   * innerText is non-standard) */
+  function getText(element) {
+    var child, text = "";
+    for (var i=0; i < element.childNodes.length; i++) {
+        child = element.childNodes[i];
+        var type = child.nodeType;
+        if (type == Node.TEXT_NODE || type == Node.ENTITY_REFERENCE_NODE) {
+            text += child.nodeValue;
+        } else {
+            /* recurse into nodes of other types */
+            text += getText(child);
+        }
+    }
+    return text;
+  }
+
+[% IF UserInGroup(Param('timetrackinggroup')) %]
   var fRemainingTime = [% bug.remaining_time %]; // holds the original value
   function adjustRemainingTime() {
      // subtracts time spent from remaining time
      fRemainingTime = document.changeform.remaining_time.value;
   }
 
+[% END %]
+
   //-->
   </script>
-[% END %]
 
 <form name="changeform" method="post" action="process_bug.cgi">
 
     <input type="checkbox" name="commentprivacy" value="1"> Private
   [% END %]
   <br>
-  <textarea wrap="hard" name="comment" rows="10" cols="80"
+  <a name="add_comment"></a>
+  <textarea wrap="hard" name="comment" id="comment" rows="10" cols="80"
             accesskey="c"></textarea>
   <br>
 
 
 [%# *** Additional Comments *** %]
 
+<hr>
 <table>
   <tr>
     <td align="left">
-      <b>
-        <a name="c0" href="#c0">Description</a>:
-      </b>
+      <b><a name="c0" href="#c0">Description</a>:</b>&nbsp;&nbsp;<script 
+        type="text/javascript" language="JavaScript"><!-- 
+          addReplyLink(0);
+        //--></script>
     </td>
     <td align="right" width="100%">
       Opened: [% bug.creation_ts FILTER time %]
     </td>
   </tr>
 </table>
-<hr>
 
 [% PROCESS bug/comments.html.tmpl
    comments = bug.longdescs