diff options
Diffstat (limited to 'askbot/skins/default')
9 files changed, 208 insertions, 85 deletions
diff --git a/askbot/skins/default/media/style/style.less b/askbot/skins/default/media/style/style.less index e8e5a5d8..4f096bd0 100644 --- a/askbot/skins/default/media/style/style.less +++ b/askbot/skins/default/media/style/style.less @@ -2034,9 +2034,17 @@ ul#related-tags li { } } + .answer-img-accept { + background: url(../images/vote-accepted.png); + width: 23px; + height: 23px; + } + + .accepted-answer .answer-img-accept, .answer-img-accept:hover { background: url(../images/vote-accepted-on.png) } + .answer-body a { color:@link; } diff --git a/askbot/skins/default/templates/base.html b/askbot/skins/default/templates/base.html index bd19f707..bc0a8d6c 100644 --- a/askbot/skins/default/templates/base.html +++ b/askbot/skins/default/templates/base.html @@ -9,6 +9,7 @@ {% include "meta/html_head_stylesheets.html" %} {% block forestyle %}{% endblock %} {% include "meta/html_head_javascript.html" %} + {% block forejs %}{% endblock %} {% if settings.USE_CUSTOM_HTML_HEAD %} {{ settings.CUSTOM_HTML_HEAD }} {% endif %} diff --git a/askbot/skins/default/templates/macros.html b/askbot/skins/default/templates/macros.html index 93eae41b..e0de6bb6 100644 --- a/askbot/skins/default/templates/macros.html +++ b/askbot/skins/default/templates/macros.html @@ -23,16 +23,10 @@ </div> {%- endmacro -%} -{%- macro post_vote_buttons(post = None, visitor_vote = None) -%} -<div - id="{{post.post_type}}-img-upvote-{{ post.id }}" - class="{{post.post_type}}-img-upvote post-vote{% if visitor_vote == 1 %} on{% endif %}" - {% if post.post_type == 'question' %} - title="{% trans %}i like this question (click again to cancel){% endtrans %}" - {% else %} - title="{% trans %}i like this answer (click again to cancel){% endtrans %}" - {% endif %} -/></div> +{%- macro post_vote_buttons(post = None) -%} +<div id="{{post.post_type}}-img-upvote-{{ post.id }}" + class="{{post.post_type}}-img-upvote post-vote"> +</div> <div id="{{post.post_type}}-vote-number-{{ post.id }}" class="vote-number" @@ -40,13 +34,11 @@ >{{ post.score }}</div> <div id="{{post.post_type}}-img-downvote-{{ post.id }}" - class="{{post.post_type}}-img-downvote post-vote{% if visitor_vote == -1 %} on{% endif %}" - {% if post.post_type == 'question' %} - title="{% trans %}i dont like this question (click again to cancel){% endtrans %}" - {% else %} - title="{% trans %}i dont like this answer (click again to cancel){% endtrans %}" - {% endif %} -/></div> + class="{{post.post_type}}-img-downvote post-vote"> +</div> +<script type="text/javascript"> + askbot['functions']['renderPostVoteButtons']('{{post.post_type}}', '{{post.id}}'); +</script> {%- endmacro -%} {%- macro post_contributor_avatar_and_credentials(post, user) -%} @@ -244,27 +236,22 @@ poor design of the data or methods on data objects #} {# Warning! Any changes to the comment markup here must be duplicated in post.js for the purposes of the AJAX comment editor #} -{%- macro add_or_show_comments_button(post = None, can_post = None, max_comments = None, widget_id = None) -%} +{%- macro add_or_show_comments_button(post = None, max_comments = None, widget_id = None) -%} + {% if post.comment_count > max_comments %} + {% set remaining_comment_count = post.comment_count - max_comments %} + {% else %} + {% set remaining_comment_count = 0 %} + {% endif %} + <a id="add-comment-to-post-{{post.id}}" class="button"></a> <script type="text/javascript"> askbot['data']['{{widget_id}}'] = { - can_post: {% if can_post %}true{% else %}false{% endif %}, truncated: {% if post.comment_count > max_comments %}true{% else %}false{% endif %} }; + askbot['functions']['renderAddCommentButton']( + '{{post.id}}', + {{remaining_comment_count}} + ); </script> - {% if post.comment_count > max_comments %} - {% set remaining_comments = post.comment_count - max_comments %} - <a class="button"> - {% if can_post %} - {% trans %}post a comment{% endtrans %} / - {% trans counter=remaining_comments %}see <strong>{{counter}}</strong> more{% pluralize %}see <strong>{{counter}}</strong> more{% endtrans %} - {% else %} - {% trans counter=remaining_comments %}see <strong>{{counter}}</strong> more comment{% pluralize %}see <strong>{{counter}}</strong> more comments - {% endtrans %} - {% endif %} - </a> - {% elif can_post %} - <a class="button">{% trans %}post a comment{% endtrans %}</a> - {% endif %} {%- endmacro -%} {%- macro post_comments_widget( @@ -285,9 +272,9 @@ for the purposes of the AJAX comment editor #} <div class="comments" id="{{widget_id}}"> <div class="content"> {% if show_post == post and show_comment and show_comment_position > max_comments %} - {% set comments = post._cached_comments[:show_comment_position] %} + {% set comments = post.get_cached_comments()[:show_comment_position] %} {% else %} - {% set comments = post._cached_comments[:max_comments] %} + {% set comments = post.get_cached_comments()[:max_comments] %} {% endif %} {% for comment in comments %} {# Warning! Any changes to the comment markup IN THIS `FOR` LOOP must be duplicated in post.js @@ -295,35 +282,42 @@ for the purposes of the AJAX comment editor #} <div class="comment" id="comment-{{comment.id}}"> <div class="comment-votes"> {% if comment.score > 0 %} - <div class="upvote{% if comment.upvoted_by_user %} upvoted{% endif %}">{{comment.score}}</div> + <div + id="comment-img-upvote-{{comment.id}}" + class="upvote" + >{{comment.score}}</div> + <script type="text/javascript"> + askbot['functions']['renderPostVoteButtons']('comment', '{{comment.id}}'); + </script> {% else %} <div class="upvote"></div> {% endif %} </div> - <div class="comment-delete"> - {% if user|can_delete_comment(comment) %} - <span class="delete-icon" title="{% trans %}delete this comment{% endtrans %}"></span> - {% endif %} + <div + id="post-{{comment.id}}-delete" + class="comment-delete" + > + <span class="delete-icon" title="{% trans %}delete this comment{% endtrans %}"></span> </div> <div class="comment-body"> {{comment.html}} <a class="author" href="{{comment.author.get_profile_url()}}">{{comment.author.username}}</a> <span class="age"> ({{comment.added_at|diff_date}})</span> - {% if user|can_edit_comment(comment) %} - <a class="edit">{% trans %}edit{% endtrans %}</a> - {% endif %} + <a id="post-{{comment.id}}-edit" + class="edit">{% trans %}edit{% endtrans %}</a> </div> </div> + <script type="text/javascript"> + askbot['functions']['renderPostControls']('{{comment.id}}'); + </script> {% endfor %} </div> <div class="controls"> - {% set can_post = user.is_authenticated() and user.can_post_comment(post) %} {% if show_post == post and show_comment %} {% if show_comment_position > max_comments %} {{ add_or_show_comments_button( post = post, - can_post = can_post, max_comments = show_comment_position, widget_id = widget_id ) @@ -332,7 +326,6 @@ for the purposes of the AJAX comment editor #} {{ add_or_show_comments_button( post = post, - can_post = can_post, max_comments = max_comments, widget_id = widget_id ) @@ -342,7 +335,6 @@ for the purposes of the AJAX comment editor #} {{ add_or_show_comments_button( post = post, - can_post = can_post, max_comments = max_comments, widget_id = widget_id ) diff --git a/askbot/skins/default/templates/meta/bottom_scripts.html b/askbot/skins/default/templates/meta/bottom_scripts.html index dd5cb202..244cec21 100644 --- a/askbot/skins/default/templates/meta/bottom_scripts.html +++ b/askbot/skins/default/templates/meta/bottom_scripts.html @@ -12,16 +12,6 @@ var scriptUrl = '/{{settings.ASKBOT_URL}}' var askbotSkin = '{{settings.ASKBOT_DEFAULT_SKIN}}'; var enableMathJax = {% if settings.ENABLE_MATHJAX %}true{% else %}false{% endif %}; - {% if request.user.is_authenticated() %} - askbot['data']['userIsAuthenticated'] = true; - askbot['data']['userId'] = {{request.user.id}}; - askbot['data']['userIsAdminOrMod'] = {% if - request.user.is_administrator() - or request.user.is_moderator() - %}true{% else %}false{% endif %}; - {% else %} - askbot['data']['userIsAuthenticated'] = false; - {% endif %} askbot['urls']['mark_read_message'] = '{% url "read_message" %}'; askbot['urls']['get_tags_by_wildcard'] = '{% url "get_tags_by_wildcard" %}'; askbot['urls']['get_tag_list'] = '{% url "get_tag_list" %}'; diff --git a/askbot/skins/default/templates/meta/html_head_javascript.html b/askbot/skins/default/templates/meta/html_head_javascript.html index 2d453215..65d0bdce 100644 --- a/askbot/skins/default/templates/meta/html_head_javascript.html +++ b/askbot/skins/default/templates/meta/html_head_javascript.html @@ -2,10 +2,20 @@ <script type="text/javascript"> var askbot = {}; askbot['data'] = {}; + {% if request.user.is_authenticated() %} + askbot['data']['userIsAuthenticated'] = true; + askbot['data']['userId'] = {{request.user.id}}; + askbot['data']['userIsAdminOrMod'] = {% if + request.user.is_administrator() + or request.user.is_moderator() + %}true{% else %}false{% endif %}; + askbot['data']['userReputation'] = {{request.user.reputation}}; + {% else %} + askbot['data']['userIsAuthenticated'] = false; + askbot['data']['userReputation'] = 0; + {% endif %} askbot['urls'] = {}; askbot['settings'] = {}; askbot['messages'] = {}; </script> -{% block forejs %} -{% endblock %} {# avoid adding javascript here so that pages load faster #} diff --git a/askbot/skins/default/templates/question.html b/askbot/skins/default/templates/question.html index b2462faf..bc0dbdeb 100644 --- a/askbot/skins/default/templates/question.html +++ b/askbot/skins/default/templates/question.html @@ -9,15 +9,148 @@ <link rel="canonical" href="{{settings.APP_URL|strip_path}}{{question.get_absolute_url()}}" /> <link rel="stylesheet" type="text/css" href="{{'/js/wmd/wmd.css'|media}}" /> {% endblock %} +{% block forejs %} + <script type="text/javascript"> + //below is pure cross-browser javascript, no jQuery + (function(){ + var data = askbot['data']; + if (data['userIsAuthenticated']){ + var votes = {}; + {% for post_id in user_votes %} + votes['{{post_id}}'] = {{user_votes[post_id]}}; + {% endfor %} + data['user_votes'] = votes; + var posts = {}; + {% for post_id in user_post_id_list %} + posts['{{post_id}}'] = 1; + {% endfor %} + data['user_posts'] = posts; + } + + function render_vote_buttons(post_type, post_id){ + var upvote_btn = document.getElementById( + post_type + '-img-upvote-' + post_id + ); + var downvote_btn = document.getElementById( + post_type + '-img-downvote-' + post_id + ); + if (data['userIsAuthenticated']){ + if (post_id in data['user_votes']){ + var vote = data['user_votes'][post_id]; + if (vote == -1){ + var btn = downvote_btn; + } else if (vote == 1){ + var btn = upvote_btn; + } else { + return; + } + if (post_type == 'comment'){ + btn.className = btn.className + ' upvoted'; + } else { + btn.className = btn.className + ' on'; + } + } + } + } + function render_post_controls(post_id){ + if (data['userIsAdminOrMod']){ + return;//all functions on + } + var edit_btn = document.getElementById( + 'post-' + post_id + '-edit' + ) + if (post_id in data['user_posts']){ + //todo: remove edit button from older comments + return;//same here + } + if ( + data['userReputation'] < + {{settings.MIN_REP_TO_DELETE_OTHERS_COMMENTS}} + ) { + var delete_btn = document.getElementById( + 'post-' + post_id + '-delete' + ); + delete_btn.parentNode.removeChild(delete_btn); + } + edit_btn.parentNode.removeChild(edit_btn); + } + function render_add_comment_button(post_id, extra_comment_count){ + var can_add = false; + {% if user_can_post_comment %} + can_add = true; + {% else %} + if (post_id in data['user_posts']){ + can_add = true; + } + {% endif %} + var add_comment_btn = document.getElementById( + 'add-comment-to-post-' + post_id + ); + if (can_add === false){ + add_comment_btn.parentNode.removeChild(add_comment_btn); + return; + } + + var text = ''; + if (extra_comment_count > 0){ + if (can_add){ + text = + "{% trans %}post a comment / <strong>some</strong> more{% endtrans %}"; + } else { + text = + "{% trans %}see <strong>some</strong> more{% endtrans%}"; + } + } else { + if (can_add){ + text = "{% trans %}post a comment{% endtrans %}"; + } + } + add_comment_btn.innerHTML = text; + //add the count + for (node in add_comment_btn.childNodes){ + if (node.nodeName === 'strong'){ + node.innerHTML = extra_comment_count; + break; + } + } + } + askbot['functions'] = askbot['functions'] || {}; + askbot['functions']['renderPostVoteButtons'] = render_vote_buttons; + askbot['functions']['renderPostControls'] = render_post_controls; + askbot['functions']['renderAddCommentButton'] = render_add_comment_button; + })(); + </script> +{% endblock %} {% block content %} - {# ==== BEGIN: question/content.html ==== #} - {% include "question/content.html" %} - {# ==== END: question/content.html ==== #} + {% if is_cacheable %} + {% cache long_time "thread-content-html" thread.id %} + {% include "question/content.html" %} + {% endcache %} + {% else %} + {% include "question/content.html" %} + {% endif %} {% endblock %} {% block sidebar %} - {%include "question/sidebar.html" %} + {% include "question/sidebar.html" %} {% endblock %} {% block endjs %} - {%include "question/javascript.html" %} + {% include "question/javascript.html" %} + {# + <script type="text/javascript"> + var messages = askbot['messages']; + messages['upvote_question'] = gettext( + 'I like this question (click again to cancel)' + ); + messages['upvote_answer'] = gettext( + 'I like this answer (click again to cancel)' + ); + messages['downvote_question'] = gettext( + "I don't like this question (click again to cancel)" + ); + messages['downvote_answer'] = gettext( + "I don't like this answer (click again to cancel)" + ); + </script> + #} {% endblock %} diff --git a/askbot/skins/default/templates/question/answer_card.html b/askbot/skins/default/templates/question/answer_card.html index d71131a8..7161c186 100644 --- a/askbot/skins/default/templates/question/answer_card.html +++ b/askbot/skins/default/templates/question/answer_card.html @@ -7,29 +7,21 @@ id="post-id-{{ answer.id }}" class="{{ macros.answer_classes(answer, question) }}"> <div class="vote-buttons"> - {# ==== START: question/answer_vote_buttons.html ==== #} {% include "question/answer_vote_buttons.html" %} - {# ==== END: question/answer_vote_buttons.html ==== #} </div> <div class="answer-table"> <div class="item-right"> <div class="answer-body"> <div class="post-update-info-container"> - {# ==== START: question/answer_author_info.html ==== #} {% include "question/answer_author_info.html" %} - {# ==== END: question/answer_author_info.html ==== #} </div> {{ answer.html }} </div> <div class="answer-controls post-controls"> - {# ==== START: question/answer_controls.html ==== #} {% include "question/answer_controls.html" %} - {# ==== END: question/answer_controls.html ==== #} </div> - {# ==== START: question/answer_comments.html ==== #} {% include "question/answer_comments.html" %} - {# ==== END: question/answer_comments.html ==== #} </div> </div> <div class="clean"></div> diff --git a/askbot/skins/default/templates/question/javascript.html b/askbot/skins/default/templates/question/javascript.html index 8ad3f09c..3a29579d 100644 --- a/askbot/skins/default/templates/question/javascript.html +++ b/askbot/skins/default/templates/question/javascript.html @@ -42,7 +42,7 @@ var answer_sort_tab = "{{ tab_id }}"; $("#" + answer_sort_tab).attr('className',"on"); - Vote.init({{ question.id }}, '{{ thread.title|slugify }}', '{{ question.author.id }}','{{ request.user.id }}'); + Vote.init({{ question.id }}, '{{ thread.title|slugify }}', '{{ question.author_id }}','{{ request.user.id }}'); {% if not thread.closed and request.user.is_authenticated %}initEditor();{% endif %} @@ -53,7 +53,7 @@ } {% if settings.ENABLE_SHARING_GOOGLE %}$.getScript("http://apis.google.com/js/plusone.js"){% endif %} - {% if request.user == question.author %} + {% if request.user.id == question.author_id %} $("#fmanswer_button").click(function() { $("#fmanswer").show(); $("#fmanswer_button").hide(); diff --git a/askbot/skins/default/templates/question/question_card.html b/askbot/skins/default/templates/question/question_card.html index 7077a8d1..08f7ccee 100644 --- a/askbot/skins/default/templates/question/question_card.html +++ b/askbot/skins/default/templates/question/question_card.html @@ -1,34 +1,31 @@ <div class="vote-buttons"> - {# ==== BEGIN: question/question_vote_buttons.html ==== #} {% include "question/question_vote_buttons.html" %} - {# ==== END: question/question_vote_buttons.html ==== #} - {# ==== BEGIN: question/share_buttons.html ==== #} {% include "question/share_buttons.html" %} - {# ==== END: question/share_buttons.html ==== #} </div> <div id="post-id-{{question.id}}" class="question-content{% if question.deleted %} deleted{% endif %}"> <h1><a href="{{ question.get_absolute_url() }}">{{ thread.get_title(question)|escape }}</a></h1> {% include "question/question_tags.html" %} - {# ==== END: question/question_tags.html" #} <div id="question-table"> <div class="question-body"> <div class="post-update-info-container"> - {# ==== START: "question/question_author_info.html" #} {% include "question/question_author_info.html" %} - {# ==== END: "question/question_author_info.html" #} </div> {{ question.html }} </div> <div id="question-controls" class="post-controls"> - {# ==== START: include "question/question_controls.html" #} {% include "question/question_controls.html" %} - {# ==== END: include "question/question_controls.html" #} </div> - {# ==== START: question/question_comments.html ==== #} + <script type="text/javascript"> + (function(){ + if (askbot['data']['userIsAuthenticated'] === false){ + var ctrl = document.getElementById('question-controls') + ctrl.parentNode.removeChild(ctrl); + } + })(); + </script> {% include "question/question_comments.html" %} - {# ==== END: question/question_comments.html ==== #} </div> </div> |