##// END OF EJS Templates
templates: fix JS error for comment form in anonymous mode.
marcink -
r1288:2eefb284 default
parent child Browse files
Show More
@@ -1,297 +1,299 b''
1 1 ## -*- coding: utf-8 -*-
2 2 ## usage:
3 3 ## <%namespace name="comment" file="/changeset/changeset_file_comment.mako"/>
4 4 ## ${comment.comment_block(comment)}
5 5 ##
6 6 <%namespace name="base" file="/base/base.mako"/>
7 7
8 8 <%def name="comment_block(comment, inline=False)">
9 9 <% outdated_at_ver = comment.outdated_at_version(getattr(c, 'at_version', None)) %>
10 10 <% pr_index_ver = comment.get_index_version(getattr(c, 'versions', [])) %>
11 11
12 12 <div class="comment
13 13 ${'comment-inline' if inline else 'comment-general'}
14 14 ${'comment-outdated' if outdated_at_ver else 'comment-current'}"
15 15 id="comment-${comment.comment_id}"
16 16 line="${comment.line_no}"
17 17 data-comment-id="${comment.comment_id}"
18 18 style="${'display: none;' if outdated_at_ver else ''}">
19 19
20 20 <div class="meta">
21 21 <div class="author ${'author-inline' if inline else 'author-general'}">
22 22 ${base.gravatar_with_user(comment.author.email, 20)}
23 23 </div>
24 24 <div class="date">
25 25 ${h.age_component(comment.modified_at, time_is_local=True)}
26 26 </div>
27 27 % if inline:
28 28 <span></span>
29 29 % else:
30 30 <div class="status-change">
31 31 % if comment.pull_request:
32 32 <a href="${h.url('pullrequest_show',repo_name=comment.pull_request.target_repo.repo_name,pull_request_id=comment.pull_request.pull_request_id)}">
33 33 % if comment.status_change:
34 34 ${_('Vote on pull request #%s') % comment.pull_request.pull_request_id}:
35 35 % else:
36 36 ${_('Comment on pull request #%s') % comment.pull_request.pull_request_id}
37 37 % endif
38 38 </a>
39 39 % else:
40 40 % if comment.status_change:
41 41 ${_('Status change on commit')}:
42 42 % else:
43 43 ${_('Comment on commit')}
44 44 % endif
45 45 % endif
46 46 </div>
47 47 % endif
48 48
49 49 % if comment.status_change:
50 50 <div class="${'flag_status %s' % comment.status_change[0].status}"></div>
51 51 <div title="${_('Commit status')}" class="changeset-status-lbl">
52 52 ${comment.status_change[0].status_lbl}
53 53 </div>
54 54 % endif
55 55
56 56 <a class="permalink" href="#comment-${comment.comment_id}"> &para;</a>
57 57
58 58 <div class="comment-links-block">
59 59
60 60 % if inline:
61 61 % if outdated_at_ver:
62 62 <div class="pr-version-inline">
63 63 <a href="${h.url.current(version=comment.pull_request_version_id, anchor='comment-{}'.format(comment.comment_id))}">
64 64 <code class="pr-version-num">
65 65 outdated ${'v{}'.format(pr_index_ver)}
66 66 </code>
67 67 </a>
68 68 </div>
69 69 |
70 70 % endif
71 71 % else:
72 72 % if comment.pull_request_version_id and pr_index_ver:
73 73 |
74 74 <div class="pr-version">
75 75 % if comment.outdated:
76 76 <a href="?version=${comment.pull_request_version_id}#comment-${comment.comment_id}">
77 77 ${_('Outdated comment from pull request version {}').format(pr_index_ver)}
78 78 </a>
79 79 % else:
80 80 <div class="tooltip" title="${_('Comment from pull request version {0}').format(pr_index_ver)}">
81 81 <a href="${h.url('pullrequest_show',repo_name=comment.pull_request.target_repo.repo_name,pull_request_id=comment.pull_request.pull_request_id, version=comment.pull_request_version_id)}">
82 82 <code class="pr-version-num">
83 83 ${'v{}'.format(pr_index_ver)}
84 84 </code>
85 85 </a>
86 86 </div>
87 87 % endif
88 88 </div>
89 89 % endif
90 90 % endif
91 91
92 92 ## show delete comment if it's not a PR (regular comments) or it's PR that is not closed
93 93 ## only super-admin, repo admin OR comment owner can delete, also hide delete if currently viewed comment is outdated
94 94 %if not outdated_at_ver and (not comment.pull_request or (comment.pull_request and not comment.pull_request.is_closed())):
95 95 ## permissions to delete
96 96 %if h.HasPermissionAny('hg.admin')() or h.HasRepoPermissionAny('repository.admin')(c.repo_name) or comment.author.user_id == c.rhodecode_user.user_id:
97 97 ## TODO: dan: add edit comment here
98 98 <a onclick="return Rhodecode.comments.deleteComment(this);" class="delete-comment"> ${_('Delete')}</a>
99 99 %else:
100 100 <button class="btn-link" disabled="disabled"> ${_('Delete')}</button>
101 101 %endif
102 102 %else:
103 103 <button class="btn-link" disabled="disabled"> ${_('Delete')}</button>
104 104 %endif
105 105
106 106 %if not outdated_at_ver:
107 107 | <a onclick="return Rhodecode.comments.prevComment(this);" class="prev-comment"> ${_('Prev')}</a>
108 108 | <a onclick="return Rhodecode.comments.nextComment(this);" class="next-comment"> ${_('Next')}</a>
109 109 %endif
110 110
111 111 </div>
112 112 </div>
113 113 <div class="text">
114 114 ${comment.render(mentions=True)|n}
115 115 </div>
116 116
117 117 </div>
118 118 </%def>
119 119 ## generate main comments
120 120 <%def name="generate_comments(include_pull_request=False, is_pull_request=False)">
121 121 <div id="comments">
122 122 %for comment in c.comments:
123 123 <div id="comment-tr-${comment.comment_id}">
124 124 ## only render comments that are not from pull request, or from
125 125 ## pull request and a status change
126 126 %if not comment.pull_request or (comment.pull_request and comment.status_change) or include_pull_request:
127 127 ${comment_block(comment)}
128 128 %endif
129 129 </div>
130 130 %endfor
131 131 ## to anchor ajax comments
132 132 <div id="injected_page_comments"></div>
133 133 </div>
134 134 </%def>
135 135
136 136 ## MAIN COMMENT FORM
137 137 <%def name="comments(post_url, cur_status, is_pull_request=False, is_compare=False, change_status=True, form_extras=None)">
138 138
139 139 %if is_compare:
140 140 <% form_id = "comments_form_compare" %>
141 141 %else:
142 142 <% form_id = "comments_form" %>
143 143 %endif
144 144
145 145
146 146 %if is_pull_request:
147 147 <div class="pull-request-merge">
148 148 %if c.allowed_to_merge:
149 149 <div class="pull-request-wrap">
150 150 <div class="pull-right">
151 151 ${h.secure_form(url('pullrequest_merge', repo_name=c.repo_name, pull_request_id=c.pull_request.pull_request_id), id='merge_pull_request_form')}
152 152 <span data-role="merge-message">${c.pr_merge_msg} ${c.approval_msg if c.approval_msg else ''}</span>
153 153 <% merge_disabled = ' disabled' if c.pr_merge_status is False else '' %>
154 154 <input type="submit" id="merge_pull_request" value="${_('Merge Pull Request')}" class="btn${merge_disabled}"${merge_disabled}>
155 155 ${h.end_form()}
156 156 </div>
157 157 </div>
158 158 %else:
159 159 <div class="pull-request-wrap">
160 160 <div class="pull-right">
161 161 <span>${c.pr_merge_msg} ${c.approval_msg if c.approval_msg else ''}</span>
162 162 </div>
163 163 </div>
164 164 %endif
165 165 </div>
166 166 %endif
167 167 <div class="comments">
168 168 <%
169 169 if is_pull_request:
170 170 placeholder = _('Leave a comment on this Pull Request.')
171 171 elif is_compare:
172 172 placeholder = _('Leave a comment on all commits in this range.')
173 173 else:
174 174 placeholder = _('Leave a comment on this Commit.')
175 175 %>
176 176 % if c.rhodecode_user.username != h.DEFAULT_USER:
177 177 <div class="comment-form ac">
178 178 ${h.secure_form(post_url, id_=form_id)}
179 179 <div class="comment-area">
180 180 <div class="comment-area-header">
181 181 <ul class="nav-links clearfix">
182 182 <li class="active">
183 183 <a href="#edit-btn" tabindex="-1" id="edit-btn">${_('Write')}</a>
184 184 </li>
185 185 <li class="">
186 186 <a href="#preview-btn" tabindex="-1" id="preview-btn">${_('Preview')}</a>
187 187 </li>
188 188 </ul>
189 189 </div>
190 190
191 191 <div class="comment-area-write" style="display: block;">
192 192 <div id="edit-container">
193 193 <textarea id="text" name="text" class="comment-block-ta ac-input"></textarea>
194 194 </div>
195 195 <div id="preview-container" class="clearfix" style="display: none;">
196 196 <div id="preview-box" class="preview-box"></div>
197 197 </div>
198 198 </div>
199 199
200 200 <div class="comment-area-footer">
201 201 <div class="toolbar">
202 202 <div class="toolbar-text">
203 203 ${(_('Comments parsed using %s syntax with %s support.') % (
204 204 ('<a href="%s">%s</a>' % (h.url('%s_help' % c.visual.default_renderer), c.visual.default_renderer.upper())),
205 205 ('<span class="tooltip" title="%s">@mention</span>' % _('Use @username inside this text to send notification to this RhodeCode user'))
206 206 )
207 207 )|n}
208 208 </div>
209 209 </div>
210 210 </div>
211 211 </div>
212 212
213 213 <div id="comment_form_extras">
214 214 %if form_extras and isinstance(form_extras, (list, tuple)):
215 215 % for form_ex_el in form_extras:
216 216 ${form_ex_el|n}
217 217 % endfor
218 218 %endif
219 219 </div>
220 220 <div class="comment-footer">
221 221 %if change_status:
222 222 <div class="status_box">
223 223 <select id="change_status" name="changeset_status">
224 224 <option></option> # Placeholder
225 225 %for status,lbl in c.commit_statuses:
226 226 <option value="${status}" data-status="${status}">${lbl}</option>
227 227 %if is_pull_request and change_status and status in ('approved', 'rejected'):
228 228 <option value="${status}_closed" data-status="${status}">${lbl} & ${_('Closed')}</option>
229 229 %endif
230 230 %endfor
231 231 </select>
232 232 </div>
233 233 %endif
234 234 <div class="action-buttons">
235 235 <div class="comment-button">${h.submit('save', _('Comment'), class_="btn btn-success comment-button-input")}</div>
236 236 </div>
237 237 </div>
238 238 ${h.end_form()}
239 239 </div>
240 240 % else:
241 241 <div class="comment-form ac">
242 242
243 243 <div class="comment-area">
244 244 <div class="comment-area-header">
245 245 <ul class="nav-links clearfix">
246 246 <li class="active">
247 247 <a class="disabled" href="#edit-btn" disabled="disabled" onclick="return false">${_('Write')}</a>
248 248 </li>
249 249 <li class="">
250 250 <a class="disabled" href="#preview-btn" disabled="disabled" onclick="return false">${_('Preview')}</a>
251 251 </li>
252 252 </ul>
253 253 </div>
254 254
255 255 <div class="comment-area-write" style="display: block;">
256 256 <div id="edit-container">
257 257 <div style="padding: 40px 0">
258 258 ${_('You need to be logged in to leave comments.')}
259 259 <a href="${h.route_path('login', _query={'came_from': h.url.current()})}">${_('Login now')}</a>
260 260 </div>
261 261 </div>
262 262 <div id="preview-container" class="clearfix" style="display: none;">
263 263 <div id="preview-box" class="preview-box"></div>
264 264 </div>
265 265 </div>
266 266
267 267 <div class="comment-area-footer">
268 268 <div class="toolbar">
269 269 <div class="toolbar-text">
270 270 </div>
271 271 </div>
272 272 </div>
273 273 </div>
274 274
275 275 <div class="comment-footer">
276 276 </div>
277 277
278 278 </div>
279 279 % endif
280 280
281 281 </div>
282 282
283 283 <script>
284 284 // init active elements of commentForm
285 285 var commitId = templateContext.commit_data.commit_id;
286 286 var pullRequestId = templateContext.pull_request_data.pull_request_id;
287 287 var lineNo;
288 288
289 289 var mainCommentForm = new CommentForm(
290 290 "#${form_id}", commitId, pullRequestId, lineNo, true);
291 291
292 if (mainCommentForm.cm){
292 293 mainCommentForm.cm.setOption('placeholder', "${placeholder}");
294 }
293 295
294 296 mainCommentForm.initStatusChangeSelector();
295 297 bindToggleButtons();
296 298 </script>
297 299 </%def>
General Comments 0
You need to be logged in to leave comments. Login now