summaryrefslogtreecommitdiffstats
path: root/askbot/skins/default/templates/question.html
blob: 4374dc8e5fa95bae51f26969966b6a2be2ff25fa (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
{% 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
                }
                if (post_id in data['user_posts']){
                    //todo: remove edit button from older comments
                    return;//same here
                }
                if (//maybe remove "delete" button
                    data['userReputation'] < 
                    {{settings.MIN_REP_TO_DELETE_OTHERS_COMMENTS}}
                ) {
                    var delete_btn = document.getElementById(
                        'post-' + post_id + '-delete'
                    );
                    delete_btn.parentNode.removeChild(delete_btn);
                }
                if (//maybe remove "edit" button
                    data['userReputation'] <
                    {{settings.MIN_REP_TO_EDIT_OTHERS_POSTS}}
                ){
                    var edit_btn = document.getElementById(
                        'post-' + post_id + '-edit'
                    )
                    edit_btn.parentNode.removeChild(edit_btn);
                }
                if (//maybe remove retag button
                    data['userReputation'] <
                    {{settings.MIN_REP_TO_RETAG_OTHERS_QUESTIONS}}
                ){
                    var retag_btn = document.getElementById('retag');
                    retag_btn.parentNode.removeChild(retag_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;
                    }
                }
            }
            function render_add_answer_button(){
                var add_answer_btn = document.getElementById('add-answer-btn');
                if (askbot['data']['userIsAuthenticated']){
                    if (askbot['data']['userId'] == {{question.author_id}}){
                        add_answer_btn.className += ' answer-own-question';
                        add_answer_btn.setAttribute(
                            'value',
                            '{% trans %}Answer Your Own Question{% endtrans %}'
                        )
                    } else {
                        add_answer_btn.setAttribute(
                           'value',
                            '{% trans %}Post Your Answer{% endtrans %}'
                        )
                    }
                } else {
                    add_answer_btn.setAttribute(
                        'value',
                        '{% trans %}Login/Signup to Post{% endtrans %}'
                    );
                }
            }

            function hide_convert_links(){
              if (!askbot['data']['userIsAdminOrMod']){
                var links = document.getElementsByClassName('convert');
                for (i=0; i<links.length; i++){
                  links[i].setAttribute('style', 'display:none;');
                }
              }
            }
            
            askbot['functions'] = askbot['functions'] || {};
            askbot['functions']['renderPostVoteButtons'] = render_vote_buttons;
            askbot['functions']['renderPostControls'] = render_post_controls;
            askbot['functions']['renderAddCommentButton'] = render_add_comment_button;
            askbot['functions']['renderAddAnswerButton'] = render_add_answer_button;
            askbot['functions']['hideConvertLinks'] = hide_convert_links;
        })();
    </script>
{% endblock %}
{% block content %}
    <div>
        {{ settings.QUESTION_PAGE_TOP_BANNER }}
    </div>
    {% 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" %}
{% 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 %}