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