b38c46e3fdf6

web: preserve comment bodies when moving line comment forms
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 03 Jul 2010 11:50:51 -0400
parents 83b866324067
children c904a77b6bef
branches/tags (none)
files review/static/comments.js

Changes

--- a/review/static/comments.js	Sat Jul 03 11:46:04 2010 -0400
+++ b/review/static/comments.js	Sat Jul 03 11:50:51 2010 -0400
@@ -11,8 +11,8 @@
                 '<span class="lastlinenumber disabled">{{ currNum }}</span>' +
                 '<div class="field">' +
                     '<label class="infield" for="id_comment-line-form_{{ currNum }}_body">Comment</label>' +
-                    '<textarea id="id_comment-line-form_{{ currNum }}_body"'  +
-                              'name="new-comment-body"></textarea>' +
+                    '<textarea id="id_comment-line-form_{{ currNum }}_body" class="body"'  +
+                              'name="new-comment-body">{{ body }}</textarea>' +
                 '</div>' +
                 
                 '<div class="field cuddly">' +
@@ -30,9 +30,9 @@
     '</tr>'
 );
 
-function RenderLineCommentForm(line, currNum) {
+function RenderLineCommentForm(line, currNum, body) {
     var filename = line.closest(".file").find(".filename h3 a .name").html();
-    return comment_form({ filename: filename, currNum: currNum });
+    return comment_form({ filename: filename, currNum: currNum, body: body });
 }
 
 $(function() {
@@ -116,11 +116,12 @@
             } else {
                 var existing_form = existing_forms.last();
                 var existing_form_line_number = parseInt(existing_form.find(".lastlinenumber").html());
+                var existing_body = existing_form.find(".body").val();
                 
                 if (existing_form_line_number != last_line_number) {
                     existing_forms.remove();
 
-                    var comment_form = RenderLineCommentForm($(this), last_line_number);
+                    var comment_form = RenderLineCommentForm($(this), last_line_number, existing_body);
                     lines_chosen.last().after(comment_form);
                     diff.find("label").inFieldLabels();
                 }
@@ -130,7 +131,7 @@
                 diff.find(".comment-form form .lines").val(newLines);
             }
         } else {
-            var comment_form = RenderLineCommentForm($(this), currNum);
+            var comment_form = RenderLineCommentForm($(this), last_line_number, '');
             $(this).after(comment_form);
             diff.find("label").inFieldLabels();
         }