post_comment.js, media.html: Add AJAX for posting comments
[mediagoblin.git] / mediagoblin / templates / mediagoblin / user_pages / media.html
1 {#
2 # GNU MediaGoblin -- federated, autonomous media hosting
3 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
14 #
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #}
18 {%- extends "mediagoblin/base.html" %}
19
20 {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %}
21 {% from "mediagoblin/utils/pagination.html" import render_pagination %}
22
23 {% block title %}{{ media.title }} &mdash; {{ super() }}{% endblock %}
24
25 {% block mediagoblin_head %}
26 <!--[if lte IE 8]><link rel="stylesheet"
27 href="{{ request.staticdirect('/extlib/leaflet/leaflet.ie.css') }}" /><![endif]-->
28 <script type="text/javascript"
29 src="{{ request.staticdirect('/js/comment_show.js') }}"></script>
30 <script type="text/javascript"
31 src="{{ request.staticdirect('/js/keyboard_navigation.js') }}"></script>
32 <script type="text/javascript"
33 src="{{ request.staticdirect('/js/post_comment.js') }}"></script>
34
35 {% template_hook("location_head") %}
36 {% template_hook("media_head") %}
37 {% endblock mediagoblin_head %}
38 {% block mediagoblin_content %}
39 <div class="row foot">
40 <p class="eleven columns context">
41 {%- trans user_url=request.urlgen(
42 'mediagoblin.user_pages.user_home',
43 user=media.get_actor.username),
44 username=media.get_actor.username -%}
45 ❖ Browsing media by <a href="{{user_url}}">{{username}}</a>
46 {%- endtrans -%}
47 </p>
48 <div class="five columns">
49 {% include "mediagoblin/utils/prev_next.html" %}
50 </div>
51 </div>
52 <div class="media_pane eleven columns">
53 {% block mediagoblin_media %}
54 <div class="media_image_container">
55 {% set display_media = request.app.public_store.file_url(
56 media.get_display_media()[1]) %}
57 {# if there's a medium file size, that means the medium size
58 # isn't the original... so link to the original!
59 #}
60 {% if media.media_files.has_key('medium') %}
61 <a href="{{ request.app.public_store.file_url(
62 media.media_files['original']) }}">
63 <img class="media_image"
64 src="{{ display_media }}"
65 alt="{% trans media_title=media.title -%}
66 Image for {{ media_title }}{% endtrans %}" />
67 </a>
68 {% else %}
69 <img class="media_image"
70 src="{{ display_media }}"
71 alt="{% trans media_title=media.title -%}
72 Image for {{ media_title }}{% endtrans %}" />
73 {% endif %}
74 </div>
75 {% endblock %}
76 <div class="row head foot">
77 <h2 class="media_title">
78 {{ media.title }}
79 </h2>
80 {% template_hook("media_titleinfo") %}
81 {% if request.user and
82 (media.actor == request.user.id or
83 request.user.has_privilege('admin')) %}
84 <div class="pull-right" style="padding-top:20px;">
85 {% set edit_url = request.urlgen('mediagoblin.edit.edit_media',
86 user= media.get_actor.username,
87 media_id=media.id) %}
88 <a class="button_action" href="{{ edit_url }}">{% trans %}Edit{% endtrans %}</a>
89 {% set delete_url = request.urlgen('mediagoblin.user_pages.media_confirm_delete',
90 user= media.get_actor.username,
91 media_id=media.id) %}
92 <a class="button_action button_warning" href="{{ delete_url }}">{% trans %}Delete{% endtrans %}</a>
93 </div>
94 {% endif %}
95 {% autoescape False %}
96 <p>{{ media.description_html }}</p>
97 {% endautoescape %}
98 </div>
99 {% if request.user and request.user.has_privilege('commenter') %}
100 <div class="media_comments">
101 {% if app_config['allow_comments'] %}
102 <a
103 {% if not request.user %}
104 href="{{ request.urlgen('mediagoblin.auth.login') }}?next={{
105 request.base_url|urlencode }}"
106 {% endif %}
107 class="button_action" id="button_addcomment" title="Add a comment">
108 {% trans %}Add a comment{% endtrans %}
109 </a>
110 {% include "mediagoblin/utils/comment-subscription.html" %}
111
112 {% endif %}
113 {% if request.user %}
114 <form action="{{ request.urlgen('mediagoblin.user_pages.media_post_comment',
115 user= media.get_actor.username,
116 media_id=media.id) }}" method="POST" id="form_comment">
117 {{ wtforms_util.render_divs(comment_form) }}
118 <div class="form_submit_buttons">
119 <input type="submit" value="{% trans %}Add this comment{% endtrans %}" class="button_action" />
120 {{ csrf_token }}
121 </div>
122 <input type="hidden" value="{{ request.urlgen('mediagoblin.user_pages.media_post_comment', user= media.get_actor.username, media_id=media.id) }}" id="postCommentURL" />
123 <input type="hidden" value="{{ request.urlgen('mediagoblin.user_pages.media_preview_comment') }}" id="previewURL" />
124 <input type="hidden" value="{% trans %}Comment Preview{% endtrans %}" id="previewText"/>
125 </form>
126 <div id="comment_preview"></div>
127 {% endif %}
128 <ul style="list-style:none">
129 {% for comment in comments %}
130 {% set comment_object = comment.comment() %}
131 {% set comment_author = comment_object.get_actor %}
132 <li id="comment-{{ comment.id }}"
133 {%- if pagination.active_id == comment.id %}
134 class="comment_wrapper comment_active">
135 <a name="comment" id="comment"></a>
136 {%- else %}
137 class="comment_wrapper">
138 {%- endif %}
139 <div class="comment_author">
140 <img src="{{ request.staticdirect('/images/icon_comment.png') }}" />
141 <a href="{{ request.urlgen('mediagoblin.user_pages.user_home',
142 user=comment_author.username) }}"
143 class="comment_authorlink">
144 {{- comment_author.username -}}
145 </a>
146 <a href="{{ request.urlgen('mediagoblin.user_pages.media_home.view_comment',
147 comment=comment.id,
148 user=media.get_actor.username,
149 media=media.slug_or_id) }}#comment"
150 class="comment_whenlink">
151 <span title='{{- comment_object.created.strftime("%I:%M%p %Y-%m-%d") -}}'>
152 {%- trans formatted_time=timesince(comment_object.created) -%}
153 {{ formatted_time }} ago
154 {%- endtrans -%}
155 </span></a>:
156 </div>
157 <div class="comment_content">
158 {% autoescape False -%}
159 {{ comment_object.content_html }}
160 {%- endautoescape %}
161 </div>
162 <div>
163 {% if app_config.allow_reporting %}
164 <a href="{{ request.urlgen('mediagoblin.user_pages.media_home.report_comment',
165 user=media.get_actor.username,
166 media=media.slug_or_id,
167 comment=comment.id) }}">
168 {% trans %}Report{% endtrans %}</a>
169 {% endif %}
170 </div>
171 </li>
172 {% endfor %}
173 </ul>
174 {{ render_pagination(request, pagination,
175 media.url_for_self(request.urlgen)) }}
176 {% else %}
177 <div class="empty_space no_background">
178 {% endif %}
179 </div>
180
181 </div>
182
183
184 <div class="five columns media_sidebar">
185 <h3>{% trans %}Added{% endtrans %}</h3>
186 <p><span title="{{ media.created.strftime("%I:%M%p %Y-%m-%d") }}">
187 {%- trans formatted_time=timesince(media.created) -%}
188 {{ formatted_time }} ago
189 {%- endtrans -%}
190 </span></p>
191
192 {% block mediagoblin_after_added_sidebar %}
193 {% endblock %}
194
195 {% if media.tags %}
196 {% include "mediagoblin/utils/tags.html" %}
197 {% endif %}
198
199 {% include "mediagoblin/utils/collections.html" %}
200
201 {% if app_config.allow_reporting %}
202 {% include "mediagoblin/utils/report.html" %}
203 {% endif %}
204
205 {% include "mediagoblin/utils/license.html" %}
206
207 {% include "mediagoblin/utils/exif.html" %}
208
209 {%- if media.attachment_files|count %}
210 <h3>{% trans %}Attachments{% endtrans %}</h3>
211 <ul>
212 {%- for attachment in media.attachment_files %}
213 <li>
214 <a href="{{ request.app.public_store.file_url(attachment.filepath) }}">
215 {{- attachment.name -}}
216 </a>
217 </li>
218 {%- endfor %}
219 </ul>
220 {%- endif %}
221 {%- if app_config['allow_attachments']
222 and request.user
223 and (media.actor == request.user.id
224 or request.user.has_privilege('admin')) %}
225 {%- if not media.attachment_files|count %}
226 <h3>{% trans %}Attachments{% endtrans %}</h3>
227 {%- endif %}
228 <p>
229 <a href="{{ request.urlgen('mediagoblin.edit.attachments',
230 user=media.get_actor.username,
231 media_id=media.id) }}">
232 {%- trans %}Add attachment{% endtrans -%}
233 </a>
234 </p>
235 {%- endif %}
236
237 {% block mediagoblin_sidebar %}
238 {% endblock %}
239
240 {%- set model = media %}
241 {% template_hook("location_info") %}
242 {% template_hook("media_sideinfo") %}
243
244 </div><!--end media_sidebar-->
245
246 <div class="clear"></div>
247 {% endblock %}