c904a77b6bef

web: preserve markdown status when moving line comment forms
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 03 Jul 2010 12:00:24 -0400
parents b38c46e3fdf6
children 96d10fd456cf
branches/tags (none)
files review/static/comments.js

Changes

--- a/review/static/comments.js	Sat Jul 03 11:50:51 2010 -0400
+++ b/review/static/comments.js	Sat Jul 03 12:00:24 2010 -0400
@@ -16,7 +16,7 @@
                 '</div>' +
                 
                 '<div class="field cuddly">' +
-                    '<input type="checkbox" class="checkbox" name="comment-markdown" id="id_comment-line-form_{{ currNum }}_markdown" checked="checked" />' +
+                    '<input type="checkbox" class="checkbox markdown-select" name="comment-markdown" id="id_comment-line-form_{{ currNum }}_markdown" {{ markdown_checked }} />' +
                     '<label for="id_comment-line-form_{{ currNum }}_markdown">Use Markdown to format this comment.</label>' +
                 '</div>' +
                 
@@ -30,9 +30,10 @@
     '</tr>'
 );
 
-function RenderLineCommentForm(line, currNum, body) {
+function RenderLineCommentForm(line, currNum, body, markdown) {
     var filename = line.closest(".file").find(".filename h3 a .name").html();
-    return comment_form({ filename: filename, currNum: currNum, body: body });
+    markdown_checked = markdown ? 'checked="checked"' : '';
+    return comment_form({ filename: filename, currNum: currNum, body: body, markdown_checked: markdown_checked });
 }
 
 $(function() {
@@ -117,11 +118,12 @@
                 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();
+                var markdown = existing_form.find('.markdown-select').is(':checked');
                 
                 if (existing_form_line_number != last_line_number) {
                     existing_forms.remove();
 
-                    var comment_form = RenderLineCommentForm($(this), last_line_number, existing_body);
+                    var comment_form = RenderLineCommentForm($(this), last_line_number, existing_body, markdown);
                     lines_chosen.last().after(comment_form);
                     diff.find("label").inFieldLabels();
                 }
@@ -131,7 +133,7 @@
                 diff.find(".comment-form form .lines").val(newLines);
             }
         } else {
-            var comment_form = RenderLineCommentForm($(this), last_line_number, '');
+            var comment_form = RenderLineCommentForm($(this), last_line_number, '', true);
             $(this).after(comment_form);
             diff.find("label").inFieldLabels();
         }