summaryrefslogtreecommitdiffstats
path: root/askbot/skins/default/templates/question.html
blob: e241b9b2dbfc3b190118cddde53aa72c3fabaa2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{% extends "two_column_body.html" %}
<!-- question.html -->
{% block title %}{% spaceless %}{{ question.get_question_title()|escape }}{% endspaceless %}{% endblock %}
{% block meta_description %}
        <meta name="description" content="{{question.summary|striptags|escape}}" />
{% endblock %}
{% block keywords %}{{thread.tagname_meta_generator()}}{% endblock %}
{% block forestyle %}
    <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 %}
    {% if is_cacheable %}
        {% cache 1000 "thread" thread.id %}
            {% include "question/content.html" %}
        {% endcache %}
    {% else %}
        {% include "question/content.html" %}
    {% endif %}
{% endblock %}
{% block sidebar %}
    {% include "question/sidebar.html" %}
{% endblock %}
{% block endjs %}
    {% 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 %}