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