From 72b7105b032fe501d0b4d8183850a51dff1f5c09 Mon Sep 17 00:00:00 2001 From: Adolfo Fitoria Date: Fri, 7 Sep 2012 16:02:33 -0600 Subject: Convert answer to comment. --- askbot/skins/common/media/js/post.js | 6 ++-- askbot/skins/common/media/js/utils.js | 10 +++--- .../common/templates/question/answer_controls.html | 8 +++++ askbot/skins/default/media/style/style.css | 40 ++++++++++++++++++++-- askbot/skins/default/media/style/style.less | 35 +++++++++++++++++-- askbot/skins/default/templates/macros.html | 2 +- askbot/skins/default/templates/question.html | 17 +++++++++ .../default/templates/question/javascript.html | 1 + askbot/urls.py | 5 +++ askbot/views/writers.py | 31 ++++++++++++++++- 10 files changed, 139 insertions(+), 16 deletions(-) diff --git a/askbot/skins/common/media/js/post.js b/askbot/skins/common/media/js/post.js index 63548409..f495d03b 100644 --- a/askbot/skins/common/media/js/post.js +++ b/askbot/skins/common/media/js/post.js @@ -1475,9 +1475,9 @@ Comment.prototype.decorate = function(element){ this._edit_link.decorate(edit_link); } - var convert_link = this._element.find('form.convert'); + var convert_link = this._element.find('form.convert-comment'); if (this._is_convertible){ - this._convert_link = new ConvertLink(comment_id); + this._convert_link = new CommentConvertLink(comment_id); this._convert_link.decorate(convert_link); } @@ -1566,7 +1566,7 @@ Comment.prototype.setContent = function(data){ } if (this._is_convertible){ - this._convert_link = new ConvertLink(this._data['id']); + this._convert_link = new CommentConvertLink(this._data['id']); this._comment_body.append(this._convert_link.getElement()); } this._element.append(this._comment_body); diff --git a/askbot/skins/common/media/js/utils.js b/askbot/skins/common/media/js/utils.js index aa7a3829..c8e0a085 100644 --- a/askbot/skins/common/media/js/utils.js +++ b/askbot/skins/common/media/js/utils.js @@ -462,15 +462,15 @@ EditLink.prototype.decorate = function(element){ this.setHandlerInternal(); }; -var ConvertLink = function(comment_id){ +var CommentConvertLink = function(comment_id){ WrappedElement.call(this) this._comment_id = comment_id; }; -inherits(ConvertLink, WrappedElement); +inherits(CommentConvertLink, WrappedElement); -ConvertLink.prototype.createDom = function(){ +CommentConvertLink.prototype.createDom = function(){ var element = this.makeElement('form'); - element.addClass('convert'); + element.addClass('convert-comment'); element.attr('method', 'POST'); element.attr('action', askbot['urls']['convertComment']); var hidden_input = this.makeElement('input'); @@ -488,7 +488,7 @@ ConvertLink.prototype.createDom = function(){ }; -ConvertLink.prototype.decorate = function(element){ +CommentConvertLink.prototype.decorate = function(element){ this._element = element; }; diff --git a/askbot/skins/common/templates/question/answer_controls.html b/askbot/skins/common/templates/question/answer_controls.html index 50f40144..42fa9820 100644 --- a/askbot/skins/common/templates/question/answer_controls.html +++ b/askbot/skins/common/templates/question/answer_controls.html @@ -40,6 +40,14 @@ {% trans %}edit{% endtrans %} + +
+ {% csrf_token %} + + +
+
diff --git a/askbot/skins/default/media/style/style.css b/askbot/skins/default/media/style/style.css index d787977d..238a9fa1 100644 --- a/askbot/skins/default/media/style/style.css +++ b/askbot/skins/default/media/style/style.css @@ -1803,6 +1803,40 @@ ul#related-tags li { .question-page .answer-controls .permant-link { background: url(../images/link.png) no-repeat center left; } +.question-page .post-controls .answer-convert, +.question-page .answer-controls .answer-convert { + float: right; + clear: left; + /*background: url(../images/link.png) no-repeat center left;*/ + +} +.question-page .post-controls .answer-convert input, +.question-page .answer-controls .answer-convert input { + font-size: 12px; + color: #777; + font-family: Arial; + text-decoration: none; + display: inline; + white-space: nowrap; + padding-left: 0px; + background: none; + border: none; + padding: 0px 7px 3px 18px; + float: right; + height: 18px; + line-height: 18px; + margin-top: -2px; + margin-left: 4px; +} +.question-page .post-controls .answer-convert input:hover, +.question-page .answer-controls .answer-convert input:hover { + background-color: #f5f0c9; + border-radius: 3px; + -ms-border-radius: 3px; + -moz-border-radius: 3px; + -webkit-border-radius: 3px; + -khtml-border-radius: 3px; +} .question-page .tabBar { width: 100%; } @@ -2033,12 +2067,12 @@ ul#related-tags li { .question-page .comments .comment-body .edit { padding-left: 6px; } -.question-page .comments .comment-body .convert { +.question-page .comments .comment-body .convert-comment { display: inline; white-space: nowrap; padding-left: 0px; } -.question-page .comments .comment-body .convert input { +.question-page .comments .comment-body .convert-comment input { background: none; padding: 0px; color: #1B79BD; @@ -2049,7 +2083,7 @@ ul#related-tags li { margin-left: 6px; font-size: 13px; } -.question-page .comments .comment-body .convert input:hover { +.question-page .comments .comment-body .convert-comment input:hover { text-decoration: underline; cursor: pointer; } diff --git a/askbot/skins/default/media/style/style.less b/askbot/skins/default/media/style/style.less index 062ccd36..c311e53f 100644 --- a/askbot/skins/default/media/style/style.less +++ b/askbot/skins/default/media/style/style.less @@ -1753,6 +1753,35 @@ ul#related-tags li { .permant-link{ background: url(../images/link.png) no-repeat center left; } + + .answer-convert{ + float:right; + clear: left; + /*background: url(../images/link.png) no-repeat center left;*/ + } + + .answer-convert input{ + font-size:12px; + color: #777; + font-family:@body-font; + text-decoration: none; + display:inline; + white-space:nowrap; + padding-left: 0px; + background: none; + border: none; + padding: 0px 7px 3px 18px; + float:right; + height:18px; + line-height:18px; + margin-top:-2px; + margin-left:4px; + } + + .answer-convert input:hover{ + background-color: #f5f0c9; + .rounded-corners(3px); + } } .tabBar{ width:100%; @@ -1949,13 +1978,13 @@ ul#related-tags li { padding-left:6px; } - .convert { + .convert-comment{ display: inline; white-space: nowrap; padding-left: 0px; } - .convert input{ + .convert-comment input{ background: none; padding: 0px; color: #1B79BD; @@ -1967,7 +1996,7 @@ ul#related-tags li { font-size: 13px; } - .convert input:hover{ + .convert-comment input:hover{ text-decoration:underline; cursor:pointer; } diff --git a/askbot/skins/default/templates/macros.html b/askbot/skins/default/templates/macros.html index 06366ebb..ac7e6474 100644 --- a/askbot/skins/default/templates/macros.html +++ b/askbot/skins/default/templates/macros.html @@ -389,7 +389,7 @@ for the purposes of the AJAX comment editor #}  ({{ timeago(comment.added_at) }}) {% trans %}edit{% endtrans %} -
+ {% csrf_token %} diff --git a/askbot/skins/default/templates/question.html b/askbot/skins/default/templates/question.html index 4374dc8e..4d43afa2 100644 --- a/askbot/skins/default/templates/question.html +++ b/askbot/skins/default/templates/question.html @@ -52,6 +52,22 @@ } } } + + function hide_convert_answer_links(post_id){ + var answer_convert_id = 'post-' + post_id + '-convert'; + var convert_answer = document.getElementById(answer_convert_id); + if (data['userIsAdminOrMod']){ + var answer_id = 'post-id-' + post_id; + var answer_container = document.getElementById(answer_id); + var answer_element= answer_container.getElementsByClassName('answer-body')[0].children[1]; + if (answer_element.textContent.length > 300){ + convert_answer.parentNode.removeChild(convert_answer); + } + } else{ + convert_answer.parentNode.removeChild(convert_answer); + } + } + function render_post_controls(post_id){ if (data['userIsAdminOrMod']){ return;//all functions on @@ -164,6 +180,7 @@ askbot['functions']['renderAddCommentButton'] = render_add_comment_button; askbot['functions']['renderAddAnswerButton'] = render_add_answer_button; askbot['functions']['hideConvertLinks'] = hide_convert_links; + askbot['functions']['hideConvertAnswerLinks'] = hide_convert_answer_links; })(); {% endblock %} diff --git a/askbot/skins/default/templates/question/javascript.html b/askbot/skins/default/templates/question/javascript.html index 5b73854e..b9904ba4 100644 --- a/askbot/skins/default/templates/question/javascript.html +++ b/askbot/skins/default/templates/question/javascript.html @@ -10,6 +10,7 @@ askbot['urls']['editComment'] = '{% url edit_comment %}'; askbot['urls']['deleteComment'] = '{% url delete_comment %}'; askbot['urls']['convertComment'] = '{% url comment_to_answer %}'; + askbot['urls']['convertAnswer'] = '{% url answer_to_comment %}'; askbot['urls']['getComment'] = '{% url get_comment %}'; askbot['urls']['question_url_template'] = scriptUrl + '{{ 'question/'|transurl }}{{ "{{QuestionID}}/{{questionSlug}}" }}';{# yes it needs to be that whacky #} askbot['urls']['vote_url_template'] = scriptUrl + '{{ 'questions/'|transurl }}{{ "{{QuestionID}}/" }}{{ 'vote/'|transurl }}'; diff --git a/askbot/urls.py b/askbot/urls.py index 7fd0bb1f..02592cfd 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -164,6 +164,11 @@ urlpatterns = patterns('', views.writers.comment_to_answer, name='comment_to_answer' ), + url(#post only + r'^answer/convert/$', + views.writers.answer_to_comment, + name='answer_to_comment' + ), url( r'^%s$' % _('tags/'), views.readers.tags, diff --git a/askbot/views/writers.py b/askbot/views/writers.py index 4640a66d..23c8a2f6 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -674,11 +674,40 @@ def comment_to_answer(request): comment_id = request.POST.get('comment_id') if comment_id: comment_id = int(comment_id) - comment = get_object_or_404(models.Post, post_type = 'comment', id=comment_id) + comment = get_object_or_404(models.Post, + post_type='comment', id=comment_id) comment.post_type = 'answer' comment.save() + comment.thread.update_answer_count() comment.thread.invalidate_cached_data() return HttpResponseRedirect(comment.get_absolute_url()) else: raise Http404 + +@decorators.admins_only +@decorators.post_only +def answer_to_comment(request): + answer_id = request.POST.get('answer_id') + if answer_id: + answer_id = int(answer_id) + answer = get_object_or_404(models.Post, + post_type = 'answer', id=answer_id) + if len(answer.text) <= 300: + answer.post_type = 'comment' + answer.parent = answer.thread._question_post() + answer_comments = models.Post.objects.get_comments().filter(parent=answer) + + for comment in answer_comments: + comment.parent = answer.parent + comment.save() + + answer.parse_and_save(author=answer.author) + answer.thread.update_answer_count() + answer.thread.invalidate_cached_data() + else: + request.user.message_set.create(message = _("the selected answer cannot be a comment")) + + return HttpResponseRedirect(answer.get_absolute_url()) + else: + raise Http404 -- cgit v1.2.3-1-g7c22