]> git.openstreetmap.org Git - osqa.git/commitdiff
The convert to answer action now works only if the comment parent is a question or...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 12 Apr 2011 22:05:37 +0000 (22:05 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 12 Apr 2011 22:05:37 +0000 (22:05 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@975 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/user.py
forum/skins/default/media/js/osqa.main.js
forum/skins/default/templates/node/comments.html
forum/views/commands.py

index 523397ef3cd264d2bdf30a49c743bf960b3ab501..afb33d34b03cc579d5473cfa874ecdcf76aa9964 100644 (file)
@@ -292,6 +292,13 @@ class User(BaseModel, DjangoUser):
         return self == comment.author or self.reputation >= int(settings.REP_TO_DELETE_COMMENTS)
 
     def can_convert_comment_to_answer(self, comment):
+        # We need to know what is the comment parent node type.
+        comment_parent_type = comment.parent.node_type
+
+        # If the parent is not a question or an answer this comment cannot be converted to an answer.
+        if comment_parent_type != "question" and comment_parent_type != "answer":
+            return False
+
         return (comment.parent.node_type in ('question', 'answer')) and (self.is_superuser or self.is_staff or (
             self == comment.author) or (self.reputation >= int(settings.REP_TO_CONVERT_COMMENTS_TO_ANSWERS)))
 
index 2de5ecf56dc70bc74b66babf28e0618f96b91b56..274ba388f5e0659b359ff39873c9017c9082a916 100644 (file)
@@ -75,7 +75,7 @@ var response_commands = {
         alert('ok');\r
     },\r
 \r
-    insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url) {\r
+    insert_comment: function(post_id, comment_id, comment, username, profile_url, delete_url, edit_url, convert_url, can_convert) {\r
         var $container = $('#comments-container-' + post_id);\r
         var skeleton = $('#new-comment-skeleton-' + post_id).html().toString();\r
 \r
@@ -89,6 +89,11 @@ var response_commands = {
 \r
         $container.append(skeleton);\r
 \r
+        // Show the convert comment to answer tool only if the current comment can be converted\r
+        if (can_convert == true) {\r
+            $('#comment-' + comment_id + '-convert').show();\r
+        }\r
+\r
         $('#comment-' + comment_id).slideDown('slow');\r
     },\r
 \r
index 1da9a2c149638e1cd28f9f08110471c78f3ebb1b..9105f56872df0122a63d69d86b326021495f3660 100644 (file)
@@ -69,7 +69,7 @@
                         class="comment-edit" rel="nofollow"> </a>\r
                     <a id="comment-%ID%-delete" href="%DELETE_URL%" title="{% trans "Delete comment" %}"\r
                         class="ajax-command comment-delete confirm" rel="nofollow"> </a>\r
-                    <a rel="nofollow" id="comment-%ID%-convert" href="%CONVERT_URL%" title="{% trans "Convert comment to answer" %}"\r
+                    <a rel="nofollow" id="comment-%ID%-convert" style="display:none;" href="%CONVERT_URL%" title="{% trans "Convert comment to answer" %}"\r
                         class="ajax-command comment-convert confirm" rel="nofollow"> </a>\r
 \r
                     <span class="comment-age">({% trans "just now" %})</span>\r
index 175b6d1ec970da150e57283fde721cc7345801d3..0b5412686d2ae558961d2d859fc49bc06c4c8176 100644 (file)
@@ -264,7 +264,8 @@ def comment(request, id):
                 id, comment.id, comment.comment, user.decorated_name, user.get_profile_url(),
                 reverse('delete_comment', kwargs={'id': comment.id}),
                 reverse('node_markdown', kwargs={'id': comment.id}),
-                reverse('convert_comment', kwargs={'id': comment.id}),            
+                reverse('convert_comment', kwargs={'id': comment.id}),
+                user.can_convert_comment_to_answer(comment),
                 ]
         }
         }