##// END OF EJS Templates
comments: fixed compare view comments.
marcink -
r1331:350c3c75 default
parent child Browse files
Show More
@@ -342,11 +342,14 b' class ChangesetController(BaseRepoContro'
342 % {'transition_icon': '>',
342 % {'transition_icon': '>',
343 'status': ChangesetStatus.get_status_lbl(status)})
343 'status': ChangesetStatus.get_status_lbl(status)})
344
344
345 multi_commit_ids = filter(
345 multi_commit_ids = []
346 lambda s: s not in ['', None],
346 for _commit_id in request.POST.get('commit_ids', '').split(','):
347 request.POST.get('commit_ids', '').split(','),)
347 if _commit_id not in ['', None, EmptyCommit.raw_id]:
348 if _commit_id not in multi_commit_ids:
349 multi_commit_ids.append(_commit_id)
348
350
349 commit_ids = multi_commit_ids or [commit_id]
351 commit_ids = multi_commit_ids or [commit_id]
352
350 comment = None
353 comment = None
351 for current_id in filter(None, commit_ids):
354 for current_id in filter(None, commit_ids):
352 c.co = comment = CommentsModel().create(
355 c.co = comment = CommentsModel().create(
@@ -43,12 +43,16 b' var bindToggleButtons = function() {'
43 };
43 };
44
44
45 /* Comment form for main and inline comments */
45 /* Comment form for main and inline comments */
46 (function(mod) {
46
47
47 (function(mod) {
48 if (typeof exports == "object" && typeof module == "object") {
48 if (typeof exports == "object" && typeof module == "object") // CommonJS
49 // CommonJS
49 module.exports = mod();
50 module.exports = mod();
50 else // Plain browser env
51 }
51 (this || window).CommentForm = mod();
52 else {
53 // Plain browser env
54 (this || window).CommentForm = mod();
55 }
52
56
53 })(function() {
57 })(function() {
54 "use strict";
58 "use strict";
@@ -236,6 +240,8 b' var bindToggleButtons = function() {'
236 $(this.statusChange).select2('readonly', false);
240 $(this.statusChange).select2('readonly', false);
237 };
241 };
238
242
243 this.globalSubmitSuccessCallback = function(){};
244
239 this.submitAjaxPOST = function(url, postData, successHandler, failHandler) {
245 this.submitAjaxPOST = function(url, postData, successHandler, failHandler) {
240 failHandler = failHandler || function() {};
246 failHandler = failHandler || function() {};
241 var postData = toQueryString(postData);
247 var postData = toQueryString(postData);
@@ -262,6 +268,11 b' var bindToggleButtons = function() {'
262 this.handleFormSubmit = callback;
268 this.handleFormSubmit = callback;
263 };
269 };
264
270
271 // overwrite a submitSuccessHandler
272 this.setGlobalSubmitSuccessCallback = function(callback) {
273 this.globalSubmitSuccessCallback = callback;
274 };
275
265 // default handler for for submit for main comments
276 // default handler for for submit for main comments
266 this.handleFormSubmit = function() {
277 this.handleFormSubmit = function() {
267 var text = self.cm.getValue();
278 var text = self.cm.getValue();
@@ -287,6 +298,7 b' var bindToggleButtons = function() {'
287 if (resolvesCommentId){
298 if (resolvesCommentId){
288 postData['resolves_comment_id'] = resolvesCommentId;
299 postData['resolves_comment_id'] = resolvesCommentId;
289 }
300 }
301
290 var submitSuccessCallback = function(o) {
302 var submitSuccessCallback = function(o) {
291 if (status) {
303 if (status) {
292 location.reload(true);
304 location.reload(true);
@@ -300,6 +312,10 b' var bindToggleButtons = function() {'
300 self.markCommentResolved(resolvesCommentId);
312 self.markCommentResolved(resolvesCommentId);
301 }
313 }
302 }
314 }
315
316 // run global callback on submit
317 self.globalSubmitSuccessCallback();
318
303 };
319 };
304 var submitFailCallback = function(){
320 var submitFailCallback = function(){
305 self.resetCommentFormState(text);
321 self.resetCommentFormState(text);
@@ -585,22 +601,25 b' var CommentsController = function() {'
585 return commentForm;
601 return commentForm;
586 };
602 };
587
603
588 this.createGeneralComment = function(lineNo, placeholderText, resolvesCommentId){
604 this.createGeneralComment = function (lineNo, placeholderText, resolvesCommentId) {
589
605
590 var tmpl = $('#cb-comment-general-form-template').html();
606 var tmpl = $('#cb-comment-general-form-template').html();
591 tmpl = tmpl.format(null, 'general');
607 tmpl = tmpl.format(null, 'general');
592 var $form = $(tmpl);
608 var $form = $(tmpl);
593
609
594 var curForm = $('#cb-comment-general-form-placeholder').find('form');
610 var $formPlaceholder = $('#cb-comment-general-form-placeholder');
611 var curForm = $formPlaceholder.find('form');
595 if (curForm){
612 if (curForm){
596 curForm.remove();
613 curForm.remove();
597 }
614 }
598 $('#cb-comment-general-form-placeholder').append($form);
615 $formPlaceholder.append($form);
599
616
600 var _form = $($form[0]);
617 var _form = $($form[0]);
601 var commentForm = this.createCommentForm(
618 var commentForm = this.createCommentForm(
602 _form, lineNo, placeholderText, true, resolvesCommentId);
619 _form, lineNo, placeholderText, true, resolvesCommentId);
603 commentForm.initStatusChangeSelector();
620 commentForm.initStatusChangeSelector();
621
622 return commentForm;
604 };
623 };
605
624
606 this.createComment = function(node, resolutionComment) {
625 this.createComment = function(node, resolutionComment) {
@@ -690,6 +709,9 b' var CommentsController = function() {'
690 commentForm.markCommentResolved(resolvesCommentId);
709 commentForm.markCommentResolved(resolvesCommentId);
691 }
710 }
692
711
712 // run global callback on submit
713 commentForm.globalSubmitSuccessCallback();
714
693 } catch (e) {
715 } catch (e) {
694 console.error(e);
716 console.error(e);
695 }
717 }
@@ -190,7 +190,7 b''
190 if is_pull_request:
190 if is_pull_request:
191 placeholder = _('Leave a comment on this Pull Request.')
191 placeholder = _('Leave a comment on this Pull Request.')
192 elif is_compare:
192 elif is_compare:
193 placeholder = _('Leave a comment on all commits in this range.')
193 placeholder = _('Leave a comment on {} commits in this range.').format(len(form_extras))
194 else:
194 else:
195 placeholder = _('Leave a comment on this Commit.')
195 placeholder = _('Leave a comment on this Commit.')
196 %>
196 %>
@@ -207,7 +207,59 b''
207 <script type="text/javascript">
207 <script type="text/javascript">
208 var lineNo = 'general';
208 var lineNo = 'general';
209 var resolvesCommentId = null;
209 var resolvesCommentId = null;
210 Rhodecode.comments.createGeneralComment(lineNo, "${placeholder}", resolvesCommentId)
210 var generalCommentForm = Rhodecode.comments.createGeneralComment(
211 lineNo, "${placeholder}", resolvesCommentId);
212
213 // set custom success callback on rangeCommit
214 % if is_compare:
215 generalCommentForm.setHandleFormSubmit(function(o) {
216 var self = generalCommentForm;
217
218 var text = self.cm.getValue();
219 var status = self.getCommentStatus();
220 var commentType = self.getCommentType();
221
222 if (text === "" && !status) {
223 return;
224 }
225
226 // we can pick which commits we want to make the comment by
227 // selecting them via click on preview pane, this will alter the hidden inputs
228 var cherryPicked = $('#changeset_compare_view_content .compare_select.hl').length > 0;
229
230 var commitIds = [];
231 $('#changeset_compare_view_content .compare_select').each(function(el) {
232 var commitId = this.id.replace('row-', '');
233 if ($(this).hasClass('hl') || !cherryPicked) {
234 $("input[data-commit-id='{0}']".format(commitId)).val(commitId);
235 commitIds.push(commitId);
236 } else {
237 $("input[data-commit-id='{0}']".format(commitId)).val('')
238 }
239 });
240
241 self.setActionButtonsDisabled(true);
242 self.cm.setOption("readOnly", true);
243 var postData = {
244 'text': text,
245 'changeset_status': status,
246 'comment_type': commentType,
247 'commit_ids': commitIds,
248 'csrf_token': CSRF_TOKEN
249 };
250
251 var submitSuccessCallback = function(o) {
252 location.reload(true);
253 };
254 var submitFailCallback = function(){
255 self.resetCommentFormState(text)
256 };
257 self.submitAjaxPOST(
258 self.submitUrl, postData, submitSuccessCallback, submitFailCallback);
259 });
260 % endif
261
262
211 </script>
263 </script>
212 % else:
264 % else:
213 ## form state when not logged in
265 ## form state when not logged in
@@ -171,50 +171,6 b''
171 %>
171 %>
172 <div>
172 <div>
173 ${comment.comments(h.url('changeset_comment', repo_name=c.repo_name, revision='0'*16), None, is_compare=True, form_extras=revs(c.commit_ranges))}
173 ${comment.comments(h.url('changeset_comment', repo_name=c.repo_name, revision='0'*16), None, is_compare=True, form_extras=revs(c.commit_ranges))}
174 <script type="text/javascript">
175
176 mainCommentForm.setHandleFormSubmit(function(o) {
177 var text = mainCommentForm.cm.getValue();
178 var status = mainCommentForm.getCommentStatus();
179
180 if (text === "" && !status) {
181 return;
182 }
183
184 // we can pick which commits we want to make the comment by
185 // selecting them via click on preview pane, this will alter the hidden inputs
186 var cherryPicked = $('#changeset_compare_view_content .compare_select.hl').length > 0;
187
188 var commitIds = [];
189 $('#changeset_compare_view_content .compare_select').each(function(el) {
190 var commitId = this.id.replace('row-', '');
191 if ($(this).hasClass('hl') || !cherryPicked) {
192 $("input[data-commit-id='{0}']".format(commitId)).val(commitId)
193 commitIds.push(commitId);
194 } else {
195 $("input[data-commit-id='{0}']".format(commitId)).val('')
196 }
197 });
198
199 mainCommentForm.setActionButtonsDisabled(true);
200 mainCommentForm.cm.setOption("readOnly", true);
201 var postData = {
202 'text': text,
203 'changeset_status': status,
204 'commit_ids': commitIds,
205 'csrf_token': CSRF_TOKEN
206 };
207
208 var submitSuccessCallback = function(o) {
209 location.reload(true);
210 };
211 var submitFailCallback = function(){
212 mainCommentForm.resetCommentFormState(text)
213 };
214 mainCommentForm.submitAjaxPOST(
215 mainCommentForm.submitUrl, postData, submitSuccessCallback, submitFailCallback);
216 });
217 </script>
218 </div>
174 </div>
219 </div>
175 </div>
220 </div>
176 </div>
General Comments 0
You need to be logged in to leave comments. Login now