014df093430e

web: add review-level comment editing support
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sat, 03 Jul 2010 10:51:25 -0400
parents d90c957b5b1a
children 2fd6ee8c3ced
branches/tags (none)
files review/static/comments.js review/static/style.css review/static/style.less review/templates/pieces/comment.html review/templates/pieces/forms/comment-change.html review/web.py

Changes

--- a/review/static/comments.js	Thu Jul 01 19:47:48 2010 -0400
+++ b/review/static/comments.js	Sat Jul 03 10:51:25 2010 -0400
@@ -36,12 +36,26 @@
         return false;
     });
 
+    $(".activate-edit a").click(function(event) {
+        $(event.target).closest(".activate-edit").hide();
+        $(event.target).closest(".comment").find(".message").hide();
+        $(event.target).closest("div").children("form").fadeIn("fast");
+        return false;
+    });
+
     $("a.cancel").click(function(event) {
         $(event.target).closest(".togglebox").children(".activate").show();
         $(event.target).parents("form").hide();
         return false;
     });
 
+    $("a.cancel-edit").click(function(event) {
+        $(event.target).closest(".toggleinline").children(".activate-edit").show();
+        $(event.target).closest(".comment").find(".message").show();
+        $(event.target).parents("form").hide();
+        return false;
+    });
+
     $("a.cancel-line").live('click', function(event) {
         $(event.target).closest(".diff").find(".chosen").removeClass("chosen");
         $(event.target).closest("tr.comment-form").remove();
--- a/review/static/style.css	Thu Jul 01 19:47:48 2010 -0400
+++ b/review/static/style.css	Sat Jul 03 10:51:25 2010 -0400
@@ -306,7 +306,7 @@
 #changeset .content a.submit:hover span {
   background-color: #eaeaea;
 }
-#changeset .content a.cancel, #changeset .content a.cancel-line {
+#changeset .content a.cancel, #changeset .content a.cancel-line, #changeset .content a.cancel-edit {
   cursor: pointer;
   font: bold 12px "Helvetica Neue", HelveticaNeue, Arial, Helvetica, sans-serif;
   color: #1e1e1e;
@@ -326,12 +326,12 @@
   border-left: 1px solid #a6a6a6;
   border-bottom: 1px solid #959595;
 }
-#changeset .content a.cancel:focus, #changeset .content a.cancel-line:focus {
+#changeset .content a.cancel:focus, #changeset .content a.cancel-line:focus, #changeset .content a.cancel-edit:focus {
   box-shadow: 0px 0px 4px rgba(100, 100, 100, 0.9);
   -moz-box-shadow: 0px 0px 4px rgba(100, 100, 100, 0.9);
   -webkit-box-shadow: 0px 0px 4px rgba(100, 100, 100, 0.9);
 }
-#changeset .content a.cancel span, #changeset .content a.cancel-line span {
+#changeset .content a.cancel span, #changeset .content a.cancel-line span, #changeset .content a.cancel-edit span {
   display: inline-block;
   padding: 0 6px;
   text-shadow: 0px 1px 1px #e2e2e2;
@@ -339,14 +339,14 @@
   -moz-border-radius: 3px;
   border-radius: 3px;
 }
-#changeset .content a.cancel:hover, #changeset .content a.cancel-line:hover {
+#changeset .content a.cancel:hover, #changeset .content a.cancel-line:hover, #changeset .content a.cancel-edit:hover {
   border-top: 1px solid #d3d3d3;
   border-right: 1px solid #bbbbbb;
   border-left: 1px solid #bbbbbb;
   border-bottom: 1px solid #a4a4a4;
   background-color: #eaeaea;
 }
-#changeset .content a.cancel:hover span, #changeset .content a.cancel-line:hover span {
+#changeset .content a.cancel:hover span, #changeset .content a.cancel-line:hover span, #changeset .content a.cancel-edit:hover span {
   background-color: #eaeaea;
 }
 #changeset .content .navigation .middle {
@@ -407,6 +407,9 @@
 #changeset .content .review-level-comments {
   margin-top: 30px;
 }
+#changeset .content .edit-review-comment {
+  margin-top: 3px;
+}
 #changeset .content .activate a {
   cursor: pointer;
   font: bold 12px "Helvetica Neue", HelveticaNeue, Arial, Helvetica, sans-serif;
--- a/review/static/style.less	Thu Jul 01 19:47:48 2010 -0400
+++ b/review/static/style.less	Sat Jul 03 10:51:25 2010 -0400
@@ -329,7 +329,7 @@
         &:hover { .button-hover(@c-metal, #000, 12px, 1.45); }
         &:hover span { .button-hover-span(@c-metal, #000, 12px, 1.45); }
     }
-    a.cancel, a.cancel-line {
+    a.cancel, a.cancel-line, a.cancel-edit {
         .button(@c-metal, #000, 12px, 1.45);
         span { .button-span(@c-metal, #000, 12px, 1.45); }
         &:hover { .button-hover(@c-metal, #000, 12px, 1.45); }
@@ -396,6 +396,9 @@
     .review-level-comments {
         margin-top: 30px;
     }
+    .edit-review-comment {
+        margin-top: 3px;
+    }
     .activate a {
         .button(@c-metal, #000, 12px, 1.45);
         span { .button-span(@c-metal, #000, 12px, 1.45); }
--- a/review/templates/pieces/comment.html	Thu Jul 01 19:47:48 2010 -0400
+++ b/review/templates/pieces/comment.html	Sat Jul 03 10:51:25 2010 -0400
@@ -45,4 +45,7 @@
             <div class="message">{{ comment.message }}</div>
         </div>
     </div>
+    {% if not read_only %}
+        {% include "pieces/forms/comment-change.html" %}
+    {% endif %}
 </div>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/review/templates/pieces/forms/comment-change.html	Sat Jul 03 10:51:25 2010 -0400
@@ -0,0 +1,29 @@
+<div class="edit-review-comment toggleinline group">
+    <span class="activate-edit"><a href="#">Edit</a></span>
+    <form class="disabled" id="comment-review-form" method="POST" action="">
+        <div class="field">
+            <label class="infield"
+                   for="id_comment-{{ comment.identifier }}-review-form_body"
+            >Comment</label>
+
+            <textarea autocomplete="off"
+                      id="id_comment-{{ comment.identifier }}-review-form_body"
+                      cols="60" rows="6" name="new-comment-body"
+            >{{ comment.message }}</textarea>
+        </div>
+        <div class="field cuddly">
+            <input type="checkbox" class="checkbox"
+                   name="comment-markdown"
+                   id="id_comment-{{ comment.identifier }}-review-form_markdown"
+                   {% if comment.style == "markdown" %}checked="checked"{% endif %}
+            />
+            <label for="id_comment-{{ comment.identifier }}-review-form_markdown">
+                Use Markdown to format this comment.
+            </label>
+
+        </div>
+        <input type="hidden" name="current" value="{{ comment.identifier }}"/>
+        <a class="submit button" href="#"><span>Edit Comment</span></a>
+        <a class="cancel-edit button" href="#"><span>Cancel</span></a>
+    </form>
+</div>
--- a/review/web.py	Thu Jul 01 19:47:48 2010 -0400
+++ b/review/web.py	Sat Jul 03 10:51:25 2010 -0400
@@ -38,6 +38,7 @@
 
 LOG_PAGE_LEN = 15
 
+
 def _item_gravatar(item, size=30):
     return 'http://www.gravatar.com/avatar/%s?s=%d' % (md5(email(item.author)).hexdigest(), size)
 
@@ -135,8 +136,12 @@
     style = 'markdown' if request.form.get('comment-markdown') else ''
     
     if body:
-        rcset = g.datastore[revhash]
-        rcset.add_comment(body, filename, lines, style=style)
+        current = request.form.get('current')
+        if current:
+            g.datastore.edit_comment(current, body, filename, lines, style)
+        else:
+            rcset = g.datastore[revhash]
+            rcset.add_comment(body, filename, lines, style)
     
     return redirect("%s/changeset/%s/" % (app.site_root, revhash))