##// END OF EJS Templates
comments: toggle icon will now mark hidden inline comments as visible for easier switching of outdated comments.
marcink -
r2612:9288dd39 default
parent child Browse files
Show More
@@ -1,809 +1,811 b''
1 // # Copyright (C) 2010-2018 RhodeCode GmbH
1 // # Copyright (C) 2010-2018 RhodeCode GmbH
2 // #
2 // #
3 // # This program is free software: you can redistribute it and/or modify
3 // # This program is free software: you can redistribute it and/or modify
4 // # it under the terms of the GNU Affero General Public License, version 3
4 // # it under the terms of the GNU Affero General Public License, version 3
5 // # (only), as published by the Free Software Foundation.
5 // # (only), as published by the Free Software Foundation.
6 // #
6 // #
7 // # This program is distributed in the hope that it will be useful,
7 // # This program is distributed in the hope that it will be useful,
8 // # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 // # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // # GNU General Public License for more details.
10 // # GNU General Public License for more details.
11 // #
11 // #
12 // # You should have received a copy of the GNU Affero General Public License
12 // # You should have received a copy of the GNU Affero General Public License
13 // # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 // # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 // #
14 // #
15 // # This program is dual-licensed. If you wish to learn more about the
15 // # This program is dual-licensed. If you wish to learn more about the
16 // # RhodeCode Enterprise Edition, including its added features, Support services,
16 // # RhodeCode Enterprise Edition, including its added features, Support services,
17 // # and proprietary license terms, please see https://rhodecode.com/licenses/
17 // # and proprietary license terms, please see https://rhodecode.com/licenses/
18
18
19 var firefoxAnchorFix = function() {
19 var firefoxAnchorFix = function() {
20 // hack to make anchor links behave properly on firefox, in our inline
20 // hack to make anchor links behave properly on firefox, in our inline
21 // comments generation when comments are injected firefox is misbehaving
21 // comments generation when comments are injected firefox is misbehaving
22 // when jumping to anchor links
22 // when jumping to anchor links
23 if (location.href.indexOf('#') > -1) {
23 if (location.href.indexOf('#') > -1) {
24 location.href += '';
24 location.href += '';
25 }
25 }
26 };
26 };
27
27
28 var linkifyComments = function(comments) {
28 var linkifyComments = function(comments) {
29 var firstCommentId = null;
29 var firstCommentId = null;
30 if (comments) {
30 if (comments) {
31 firstCommentId = $(comments[0]).data('comment-id');
31 firstCommentId = $(comments[0]).data('comment-id');
32 }
32 }
33
33
34 if (firstCommentId){
34 if (firstCommentId){
35 $('#inline-comments-counter').attr('href', '#comment-' + firstCommentId);
35 $('#inline-comments-counter').attr('href', '#comment-' + firstCommentId);
36 }
36 }
37 };
37 };
38
38
39 var bindToggleButtons = function() {
39 var bindToggleButtons = function() {
40 $('.comment-toggle').on('click', function() {
40 $('.comment-toggle').on('click', function() {
41 $(this).parent().nextUntil('tr.line').toggle('inline-comments');
41 $(this).parent().nextUntil('tr.line').toggle('inline-comments');
42 });
42 });
43 };
43 };
44
44
45 /* Comment form for main and inline comments */
45 /* Comment form for main and inline comments */
46 (function(mod) {
46 (function(mod) {
47
47
48 if (typeof exports == "object" && typeof module == "object") {
48 if (typeof exports == "object" && typeof module == "object") {
49 // CommonJS
49 // CommonJS
50 module.exports = mod();
50 module.exports = mod();
51 }
51 }
52 else {
52 else {
53 // Plain browser env
53 // Plain browser env
54 (this || window).CommentForm = mod();
54 (this || window).CommentForm = mod();
55 }
55 }
56
56
57 })(function() {
57 })(function() {
58 "use strict";
58 "use strict";
59
59
60 function CommentForm(formElement, commitId, pullRequestId, lineNo, initAutocompleteActions, resolvesCommentId) {
60 function CommentForm(formElement, commitId, pullRequestId, lineNo, initAutocompleteActions, resolvesCommentId) {
61 if (!(this instanceof CommentForm)) {
61 if (!(this instanceof CommentForm)) {
62 return new CommentForm(formElement, commitId, pullRequestId, lineNo, initAutocompleteActions, resolvesCommentId);
62 return new CommentForm(formElement, commitId, pullRequestId, lineNo, initAutocompleteActions, resolvesCommentId);
63 }
63 }
64
64
65 // bind the element instance to our Form
65 // bind the element instance to our Form
66 $(formElement).get(0).CommentForm = this;
66 $(formElement).get(0).CommentForm = this;
67
67
68 this.withLineNo = function(selector) {
68 this.withLineNo = function(selector) {
69 var lineNo = this.lineNo;
69 var lineNo = this.lineNo;
70 if (lineNo === undefined) {
70 if (lineNo === undefined) {
71 return selector
71 return selector
72 } else {
72 } else {
73 return selector + '_' + lineNo;
73 return selector + '_' + lineNo;
74 }
74 }
75 };
75 };
76
76
77 this.commitId = commitId;
77 this.commitId = commitId;
78 this.pullRequestId = pullRequestId;
78 this.pullRequestId = pullRequestId;
79 this.lineNo = lineNo;
79 this.lineNo = lineNo;
80 this.initAutocompleteActions = initAutocompleteActions;
80 this.initAutocompleteActions = initAutocompleteActions;
81
81
82 this.previewButton = this.withLineNo('#preview-btn');
82 this.previewButton = this.withLineNo('#preview-btn');
83 this.previewContainer = this.withLineNo('#preview-container');
83 this.previewContainer = this.withLineNo('#preview-container');
84
84
85 this.previewBoxSelector = this.withLineNo('#preview-box');
85 this.previewBoxSelector = this.withLineNo('#preview-box');
86
86
87 this.editButton = this.withLineNo('#edit-btn');
87 this.editButton = this.withLineNo('#edit-btn');
88 this.editContainer = this.withLineNo('#edit-container');
88 this.editContainer = this.withLineNo('#edit-container');
89 this.cancelButton = this.withLineNo('#cancel-btn');
89 this.cancelButton = this.withLineNo('#cancel-btn');
90 this.commentType = this.withLineNo('#comment_type');
90 this.commentType = this.withLineNo('#comment_type');
91
91
92 this.resolvesId = null;
92 this.resolvesId = null;
93 this.resolvesActionId = null;
93 this.resolvesActionId = null;
94
94
95 this.closesPr = '#close_pull_request';
95 this.closesPr = '#close_pull_request';
96
96
97 this.cmBox = this.withLineNo('#text');
97 this.cmBox = this.withLineNo('#text');
98 this.cm = initCommentBoxCodeMirror(this, this.cmBox, this.initAutocompleteActions);
98 this.cm = initCommentBoxCodeMirror(this, this.cmBox, this.initAutocompleteActions);
99
99
100 this.statusChange = this.withLineNo('#change_status');
100 this.statusChange = this.withLineNo('#change_status');
101
101
102 this.submitForm = formElement;
102 this.submitForm = formElement;
103 this.submitButton = $(this.submitForm).find('input[type="submit"]');
103 this.submitButton = $(this.submitForm).find('input[type="submit"]');
104 this.submitButtonText = this.submitButton.val();
104 this.submitButtonText = this.submitButton.val();
105
105
106 this.previewUrl = pyroutes.url('repo_commit_comment_preview',
106 this.previewUrl = pyroutes.url('repo_commit_comment_preview',
107 {'repo_name': templateContext.repo_name,
107 {'repo_name': templateContext.repo_name,
108 'commit_id': templateContext.commit_data.commit_id});
108 'commit_id': templateContext.commit_data.commit_id});
109
109
110 if (resolvesCommentId){
110 if (resolvesCommentId){
111 this.resolvesId = '#resolve_comment_{0}'.format(resolvesCommentId);
111 this.resolvesId = '#resolve_comment_{0}'.format(resolvesCommentId);
112 this.resolvesActionId = '#resolve_comment_action_{0}'.format(resolvesCommentId);
112 this.resolvesActionId = '#resolve_comment_action_{0}'.format(resolvesCommentId);
113 $(this.commentType).prop('disabled', true);
113 $(this.commentType).prop('disabled', true);
114 $(this.commentType).addClass('disabled');
114 $(this.commentType).addClass('disabled');
115
115
116 // disable select
116 // disable select
117 setTimeout(function() {
117 setTimeout(function() {
118 $(self.statusChange).select2('readonly', true);
118 $(self.statusChange).select2('readonly', true);
119 }, 10);
119 }, 10);
120
120
121 var resolvedInfo = (
121 var resolvedInfo = (
122 '<li class="resolve-action">' +
122 '<li class="resolve-action">' +
123 '<input type="hidden" id="resolve_comment_{0}" name="resolve_comment_{0}" value="{0}">' +
123 '<input type="hidden" id="resolve_comment_{0}" name="resolve_comment_{0}" value="{0}">' +
124 '<button id="resolve_comment_action_{0}" class="resolve-text btn btn-sm" onclick="return Rhodecode.comments.submitResolution({0})">{1} #{0}</button>' +
124 '<button id="resolve_comment_action_{0}" class="resolve-text btn btn-sm" onclick="return Rhodecode.comments.submitResolution({0})">{1} #{0}</button>' +
125 '</li>'
125 '</li>'
126 ).format(resolvesCommentId, _gettext('resolve comment'));
126 ).format(resolvesCommentId, _gettext('resolve comment'));
127 $(resolvedInfo).insertAfter($(this.commentType).parent());
127 $(resolvedInfo).insertAfter($(this.commentType).parent());
128 }
128 }
129
129
130 // based on commitId, or pullRequestId decide where do we submit
130 // based on commitId, or pullRequestId decide where do we submit
131 // out data
131 // out data
132 if (this.commitId){
132 if (this.commitId){
133 this.submitUrl = pyroutes.url('repo_commit_comment_create',
133 this.submitUrl = pyroutes.url('repo_commit_comment_create',
134 {'repo_name': templateContext.repo_name,
134 {'repo_name': templateContext.repo_name,
135 'commit_id': this.commitId});
135 'commit_id': this.commitId});
136 this.selfUrl = pyroutes.url('repo_commit',
136 this.selfUrl = pyroutes.url('repo_commit',
137 {'repo_name': templateContext.repo_name,
137 {'repo_name': templateContext.repo_name,
138 'commit_id': this.commitId});
138 'commit_id': this.commitId});
139
139
140 } else if (this.pullRequestId) {
140 } else if (this.pullRequestId) {
141 this.submitUrl = pyroutes.url('pullrequest_comment_create',
141 this.submitUrl = pyroutes.url('pullrequest_comment_create',
142 {'repo_name': templateContext.repo_name,
142 {'repo_name': templateContext.repo_name,
143 'pull_request_id': this.pullRequestId});
143 'pull_request_id': this.pullRequestId});
144 this.selfUrl = pyroutes.url('pullrequest_show',
144 this.selfUrl = pyroutes.url('pullrequest_show',
145 {'repo_name': templateContext.repo_name,
145 {'repo_name': templateContext.repo_name,
146 'pull_request_id': this.pullRequestId});
146 'pull_request_id': this.pullRequestId});
147
147
148 } else {
148 } else {
149 throw new Error(
149 throw new Error(
150 'CommentForm requires pullRequestId, or commitId to be specified.')
150 'CommentForm requires pullRequestId, or commitId to be specified.')
151 }
151 }
152
152
153 // FUNCTIONS and helpers
153 // FUNCTIONS and helpers
154 var self = this;
154 var self = this;
155
155
156 this.isInline = function(){
156 this.isInline = function(){
157 return this.lineNo && this.lineNo != 'general';
157 return this.lineNo && this.lineNo != 'general';
158 };
158 };
159
159
160 this.getCmInstance = function(){
160 this.getCmInstance = function(){
161 return this.cm
161 return this.cm
162 };
162 };
163
163
164 this.setPlaceholder = function(placeholder) {
164 this.setPlaceholder = function(placeholder) {
165 var cm = this.getCmInstance();
165 var cm = this.getCmInstance();
166 if (cm){
166 if (cm){
167 cm.setOption('placeholder', placeholder);
167 cm.setOption('placeholder', placeholder);
168 }
168 }
169 };
169 };
170
170
171 this.getCommentStatus = function() {
171 this.getCommentStatus = function() {
172 return $(this.submitForm).find(this.statusChange).val();
172 return $(this.submitForm).find(this.statusChange).val();
173 };
173 };
174 this.getCommentType = function() {
174 this.getCommentType = function() {
175 return $(this.submitForm).find(this.commentType).val();
175 return $(this.submitForm).find(this.commentType).val();
176 };
176 };
177
177
178 this.getResolvesId = function() {
178 this.getResolvesId = function() {
179 return $(this.submitForm).find(this.resolvesId).val() || null;
179 return $(this.submitForm).find(this.resolvesId).val() || null;
180 };
180 };
181
181
182 this.getClosePr = function() {
182 this.getClosePr = function() {
183 return $(this.submitForm).find(this.closesPr).val() || null;
183 return $(this.submitForm).find(this.closesPr).val() || null;
184 };
184 };
185
185
186 this.markCommentResolved = function(resolvedCommentId){
186 this.markCommentResolved = function(resolvedCommentId){
187 $('#comment-label-{0}'.format(resolvedCommentId)).find('.resolved').show();
187 $('#comment-label-{0}'.format(resolvedCommentId)).find('.resolved').show();
188 $('#comment-label-{0}'.format(resolvedCommentId)).find('.resolve').hide();
188 $('#comment-label-{0}'.format(resolvedCommentId)).find('.resolve').hide();
189 };
189 };
190
190
191 this.isAllowedToSubmit = function() {
191 this.isAllowedToSubmit = function() {
192 return !$(this.submitButton).prop('disabled');
192 return !$(this.submitButton).prop('disabled');
193 };
193 };
194
194
195 this.initStatusChangeSelector = function(){
195 this.initStatusChangeSelector = function(){
196 var formatChangeStatus = function(state, escapeMarkup) {
196 var formatChangeStatus = function(state, escapeMarkup) {
197 var originalOption = state.element;
197 var originalOption = state.element;
198 return '<div class="flag_status ' + $(originalOption).data('status') + ' pull-left"></div>' +
198 return '<div class="flag_status ' + $(originalOption).data('status') + ' pull-left"></div>' +
199 '<span>' + escapeMarkup(state.text) + '</span>';
199 '<span>' + escapeMarkup(state.text) + '</span>';
200 };
200 };
201 var formatResult = function(result, container, query, escapeMarkup) {
201 var formatResult = function(result, container, query, escapeMarkup) {
202 return formatChangeStatus(result, escapeMarkup);
202 return formatChangeStatus(result, escapeMarkup);
203 };
203 };
204
204
205 var formatSelection = function(data, container, escapeMarkup) {
205 var formatSelection = function(data, container, escapeMarkup) {
206 return formatChangeStatus(data, escapeMarkup);
206 return formatChangeStatus(data, escapeMarkup);
207 };
207 };
208
208
209 $(this.submitForm).find(this.statusChange).select2({
209 $(this.submitForm).find(this.statusChange).select2({
210 placeholder: _gettext('Status Review'),
210 placeholder: _gettext('Status Review'),
211 formatResult: formatResult,
211 formatResult: formatResult,
212 formatSelection: formatSelection,
212 formatSelection: formatSelection,
213 containerCssClass: "drop-menu status_box_menu",
213 containerCssClass: "drop-menu status_box_menu",
214 dropdownCssClass: "drop-menu-dropdown",
214 dropdownCssClass: "drop-menu-dropdown",
215 dropdownAutoWidth: true,
215 dropdownAutoWidth: true,
216 minimumResultsForSearch: -1
216 minimumResultsForSearch: -1
217 });
217 });
218 $(this.submitForm).find(this.statusChange).on('change', function() {
218 $(this.submitForm).find(this.statusChange).on('change', function() {
219 var status = self.getCommentStatus();
219 var status = self.getCommentStatus();
220
220
221 if (status && !self.isInline()) {
221 if (status && !self.isInline()) {
222 $(self.submitButton).prop('disabled', false);
222 $(self.submitButton).prop('disabled', false);
223 }
223 }
224
224
225 var placeholderText = _gettext('Comment text will be set automatically based on currently selected status ({0}) ...').format(status);
225 var placeholderText = _gettext('Comment text will be set automatically based on currently selected status ({0}) ...').format(status);
226 self.setPlaceholder(placeholderText)
226 self.setPlaceholder(placeholderText)
227 })
227 })
228 };
228 };
229
229
230 // reset the comment form into it's original state
230 // reset the comment form into it's original state
231 this.resetCommentFormState = function(content) {
231 this.resetCommentFormState = function(content) {
232 content = content || '';
232 content = content || '';
233
233
234 $(this.editContainer).show();
234 $(this.editContainer).show();
235 $(this.editButton).parent().addClass('active');
235 $(this.editButton).parent().addClass('active');
236
236
237 $(this.previewContainer).hide();
237 $(this.previewContainer).hide();
238 $(this.previewButton).parent().removeClass('active');
238 $(this.previewButton).parent().removeClass('active');
239
239
240 this.setActionButtonsDisabled(true);
240 this.setActionButtonsDisabled(true);
241 self.cm.setValue(content);
241 self.cm.setValue(content);
242 self.cm.setOption("readOnly", false);
242 self.cm.setOption("readOnly", false);
243
243
244 if (this.resolvesId) {
244 if (this.resolvesId) {
245 // destroy the resolve action
245 // destroy the resolve action
246 $(this.resolvesId).parent().remove();
246 $(this.resolvesId).parent().remove();
247 }
247 }
248 // reset closingPR flag
248 // reset closingPR flag
249 $('.close-pr-input').remove();
249 $('.close-pr-input').remove();
250
250
251 $(this.statusChange).select2('readonly', false);
251 $(this.statusChange).select2('readonly', false);
252 };
252 };
253
253
254 this.globalSubmitSuccessCallback = function(){
254 this.globalSubmitSuccessCallback = function(){
255 // default behaviour is to call GLOBAL hook, if it's registered.
255 // default behaviour is to call GLOBAL hook, if it's registered.
256 if (window.commentFormGlobalSubmitSuccessCallback !== undefined){
256 if (window.commentFormGlobalSubmitSuccessCallback !== undefined){
257 commentFormGlobalSubmitSuccessCallback()
257 commentFormGlobalSubmitSuccessCallback()
258 }
258 }
259 };
259 };
260
260
261 this.submitAjaxPOST = function(url, postData, successHandler, failHandler) {
261 this.submitAjaxPOST = function(url, postData, successHandler, failHandler) {
262 failHandler = failHandler || function() {};
262 failHandler = failHandler || function() {};
263 var postData = toQueryString(postData);
263 var postData = toQueryString(postData);
264 var request = $.ajax({
264 var request = $.ajax({
265 url: url,
265 url: url,
266 type: 'POST',
266 type: 'POST',
267 data: postData,
267 data: postData,
268 headers: {'X-PARTIAL-XHR': true}
268 headers: {'X-PARTIAL-XHR': true}
269 })
269 })
270 .done(function(data) {
270 .done(function(data) {
271 successHandler(data);
271 successHandler(data);
272 })
272 })
273 .fail(function(data, textStatus, errorThrown){
273 .fail(function(data, textStatus, errorThrown){
274 alert(
274 alert(
275 "Error while submitting comment.\n" +
275 "Error while submitting comment.\n" +
276 "Error code {0} ({1}).".format(data.status, data.statusText));
276 "Error code {0} ({1}).".format(data.status, data.statusText));
277 failHandler()
277 failHandler()
278 });
278 });
279 return request;
279 return request;
280 };
280 };
281
281
282 // overwrite a submitHandler, we need to do it for inline comments
282 // overwrite a submitHandler, we need to do it for inline comments
283 this.setHandleFormSubmit = function(callback) {
283 this.setHandleFormSubmit = function(callback) {
284 this.handleFormSubmit = callback;
284 this.handleFormSubmit = callback;
285 };
285 };
286
286
287 // overwrite a submitSuccessHandler
287 // overwrite a submitSuccessHandler
288 this.setGlobalSubmitSuccessCallback = function(callback) {
288 this.setGlobalSubmitSuccessCallback = function(callback) {
289 this.globalSubmitSuccessCallback = callback;
289 this.globalSubmitSuccessCallback = callback;
290 };
290 };
291
291
292 // default handler for for submit for main comments
292 // default handler for for submit for main comments
293 this.handleFormSubmit = function() {
293 this.handleFormSubmit = function() {
294 var text = self.cm.getValue();
294 var text = self.cm.getValue();
295 var status = self.getCommentStatus();
295 var status = self.getCommentStatus();
296 var commentType = self.getCommentType();
296 var commentType = self.getCommentType();
297 var resolvesCommentId = self.getResolvesId();
297 var resolvesCommentId = self.getResolvesId();
298 var closePullRequest = self.getClosePr();
298 var closePullRequest = self.getClosePr();
299
299
300 if (text === "" && !status) {
300 if (text === "" && !status) {
301 return;
301 return;
302 }
302 }
303
303
304 var excludeCancelBtn = false;
304 var excludeCancelBtn = false;
305 var submitEvent = true;
305 var submitEvent = true;
306 self.setActionButtonsDisabled(true, excludeCancelBtn, submitEvent);
306 self.setActionButtonsDisabled(true, excludeCancelBtn, submitEvent);
307 self.cm.setOption("readOnly", true);
307 self.cm.setOption("readOnly", true);
308
308
309 var postData = {
309 var postData = {
310 'text': text,
310 'text': text,
311 'changeset_status': status,
311 'changeset_status': status,
312 'comment_type': commentType,
312 'comment_type': commentType,
313 'csrf_token': CSRF_TOKEN
313 'csrf_token': CSRF_TOKEN
314 };
314 };
315
315
316 if (resolvesCommentId) {
316 if (resolvesCommentId) {
317 postData['resolves_comment_id'] = resolvesCommentId;
317 postData['resolves_comment_id'] = resolvesCommentId;
318 }
318 }
319
319
320 if (closePullRequest) {
320 if (closePullRequest) {
321 postData['close_pull_request'] = true;
321 postData['close_pull_request'] = true;
322 }
322 }
323
323
324 var submitSuccessCallback = function(o) {
324 var submitSuccessCallback = function(o) {
325 // reload page if we change status for single commit.
325 // reload page if we change status for single commit.
326 if (status && self.commitId) {
326 if (status && self.commitId) {
327 location.reload(true);
327 location.reload(true);
328 } else {
328 } else {
329 $('#injected_page_comments').append(o.rendered_text);
329 $('#injected_page_comments').append(o.rendered_text);
330 self.resetCommentFormState();
330 self.resetCommentFormState();
331 timeagoActivate();
331 timeagoActivate();
332
332
333 // mark visually which comment was resolved
333 // mark visually which comment was resolved
334 if (resolvesCommentId) {
334 if (resolvesCommentId) {
335 self.markCommentResolved(resolvesCommentId);
335 self.markCommentResolved(resolvesCommentId);
336 }
336 }
337 }
337 }
338
338
339 // run global callback on submit
339 // run global callback on submit
340 self.globalSubmitSuccessCallback();
340 self.globalSubmitSuccessCallback();
341
341
342 };
342 };
343 var submitFailCallback = function(){
343 var submitFailCallback = function(){
344 self.resetCommentFormState(text);
344 self.resetCommentFormState(text);
345 };
345 };
346 self.submitAjaxPOST(
346 self.submitAjaxPOST(
347 self.submitUrl, postData, submitSuccessCallback, submitFailCallback);
347 self.submitUrl, postData, submitSuccessCallback, submitFailCallback);
348 };
348 };
349
349
350 this.previewSuccessCallback = function(o) {
350 this.previewSuccessCallback = function(o) {
351 $(self.previewBoxSelector).html(o);
351 $(self.previewBoxSelector).html(o);
352 $(self.previewBoxSelector).removeClass('unloaded');
352 $(self.previewBoxSelector).removeClass('unloaded');
353
353
354 // swap buttons, making preview active
354 // swap buttons, making preview active
355 $(self.previewButton).parent().addClass('active');
355 $(self.previewButton).parent().addClass('active');
356 $(self.editButton).parent().removeClass('active');
356 $(self.editButton).parent().removeClass('active');
357
357
358 // unlock buttons
358 // unlock buttons
359 self.setActionButtonsDisabled(false);
359 self.setActionButtonsDisabled(false);
360 };
360 };
361
361
362 this.setActionButtonsDisabled = function(state, excludeCancelBtn, submitEvent) {
362 this.setActionButtonsDisabled = function(state, excludeCancelBtn, submitEvent) {
363 excludeCancelBtn = excludeCancelBtn || false;
363 excludeCancelBtn = excludeCancelBtn || false;
364 submitEvent = submitEvent || false;
364 submitEvent = submitEvent || false;
365
365
366 $(this.editButton).prop('disabled', state);
366 $(this.editButton).prop('disabled', state);
367 $(this.previewButton).prop('disabled', state);
367 $(this.previewButton).prop('disabled', state);
368
368
369 if (!excludeCancelBtn) {
369 if (!excludeCancelBtn) {
370 $(this.cancelButton).prop('disabled', state);
370 $(this.cancelButton).prop('disabled', state);
371 }
371 }
372
372
373 var submitState = state;
373 var submitState = state;
374 if (!submitEvent && this.getCommentStatus() && !self.isInline()) {
374 if (!submitEvent && this.getCommentStatus() && !self.isInline()) {
375 // if the value of commit review status is set, we allow
375 // if the value of commit review status is set, we allow
376 // submit button, but only on Main form, isInline means inline
376 // submit button, but only on Main form, isInline means inline
377 submitState = false
377 submitState = false
378 }
378 }
379
379
380 $(this.submitButton).prop('disabled', submitState);
380 $(this.submitButton).prop('disabled', submitState);
381 if (submitEvent) {
381 if (submitEvent) {
382 $(this.submitButton).val(_gettext('Submitting...'));
382 $(this.submitButton).val(_gettext('Submitting...'));
383 } else {
383 } else {
384 $(this.submitButton).val(this.submitButtonText);
384 $(this.submitButton).val(this.submitButtonText);
385 }
385 }
386
386
387 };
387 };
388
388
389 // lock preview/edit/submit buttons on load, but exclude cancel button
389 // lock preview/edit/submit buttons on load, but exclude cancel button
390 var excludeCancelBtn = true;
390 var excludeCancelBtn = true;
391 this.setActionButtonsDisabled(true, excludeCancelBtn);
391 this.setActionButtonsDisabled(true, excludeCancelBtn);
392
392
393 // anonymous users don't have access to initialized CM instance
393 // anonymous users don't have access to initialized CM instance
394 if (this.cm !== undefined){
394 if (this.cm !== undefined){
395 this.cm.on('change', function(cMirror) {
395 this.cm.on('change', function(cMirror) {
396 if (cMirror.getValue() === "") {
396 if (cMirror.getValue() === "") {
397 self.setActionButtonsDisabled(true, excludeCancelBtn)
397 self.setActionButtonsDisabled(true, excludeCancelBtn)
398 } else {
398 } else {
399 self.setActionButtonsDisabled(false, excludeCancelBtn)
399 self.setActionButtonsDisabled(false, excludeCancelBtn)
400 }
400 }
401 });
401 });
402 }
402 }
403
403
404 $(this.editButton).on('click', function(e) {
404 $(this.editButton).on('click', function(e) {
405 e.preventDefault();
405 e.preventDefault();
406
406
407 $(self.previewButton).parent().removeClass('active');
407 $(self.previewButton).parent().removeClass('active');
408 $(self.previewContainer).hide();
408 $(self.previewContainer).hide();
409
409
410 $(self.editButton).parent().addClass('active');
410 $(self.editButton).parent().addClass('active');
411 $(self.editContainer).show();
411 $(self.editContainer).show();
412
412
413 });
413 });
414
414
415 $(this.previewButton).on('click', function(e) {
415 $(this.previewButton).on('click', function(e) {
416 e.preventDefault();
416 e.preventDefault();
417 var text = self.cm.getValue();
417 var text = self.cm.getValue();
418
418
419 if (text === "") {
419 if (text === "") {
420 return;
420 return;
421 }
421 }
422
422
423 var postData = {
423 var postData = {
424 'text': text,
424 'text': text,
425 'renderer': templateContext.visual.default_renderer,
425 'renderer': templateContext.visual.default_renderer,
426 'csrf_token': CSRF_TOKEN
426 'csrf_token': CSRF_TOKEN
427 };
427 };
428
428
429 // lock ALL buttons on preview
429 // lock ALL buttons on preview
430 self.setActionButtonsDisabled(true);
430 self.setActionButtonsDisabled(true);
431
431
432 $(self.previewBoxSelector).addClass('unloaded');
432 $(self.previewBoxSelector).addClass('unloaded');
433 $(self.previewBoxSelector).html(_gettext('Loading ...'));
433 $(self.previewBoxSelector).html(_gettext('Loading ...'));
434
434
435 $(self.editContainer).hide();
435 $(self.editContainer).hide();
436 $(self.previewContainer).show();
436 $(self.previewContainer).show();
437
437
438 // by default we reset state of comment preserving the text
438 // by default we reset state of comment preserving the text
439 var previewFailCallback = function(){
439 var previewFailCallback = function(){
440 self.resetCommentFormState(text)
440 self.resetCommentFormState(text)
441 };
441 };
442 self.submitAjaxPOST(
442 self.submitAjaxPOST(
443 self.previewUrl, postData, self.previewSuccessCallback,
443 self.previewUrl, postData, self.previewSuccessCallback,
444 previewFailCallback);
444 previewFailCallback);
445
445
446 $(self.previewButton).parent().addClass('active');
446 $(self.previewButton).parent().addClass('active');
447 $(self.editButton).parent().removeClass('active');
447 $(self.editButton).parent().removeClass('active');
448 });
448 });
449
449
450 $(this.submitForm).submit(function(e) {
450 $(this.submitForm).submit(function(e) {
451 e.preventDefault();
451 e.preventDefault();
452 var allowedToSubmit = self.isAllowedToSubmit();
452 var allowedToSubmit = self.isAllowedToSubmit();
453 if (!allowedToSubmit){
453 if (!allowedToSubmit){
454 return false;
454 return false;
455 }
455 }
456 self.handleFormSubmit();
456 self.handleFormSubmit();
457 });
457 });
458
458
459 }
459 }
460
460
461 return CommentForm;
461 return CommentForm;
462 });
462 });
463
463
464 /* comments controller */
464 /* comments controller */
465 var CommentsController = function() {
465 var CommentsController = function() {
466 var mainComment = '#text';
466 var mainComment = '#text';
467 var self = this;
467 var self = this;
468
468
469 this.cancelComment = function(node) {
469 this.cancelComment = function(node) {
470 var $node = $(node);
470 var $node = $(node);
471 var $td = $node.closest('td');
471 var $td = $node.closest('td');
472 $node.closest('.comment-inline-form').remove();
472 $node.closest('.comment-inline-form').remove();
473 return false;
473 return false;
474 };
474 };
475
475
476 this.getLineNumber = function(node) {
476 this.getLineNumber = function(node) {
477 var $node = $(node);
477 var $node = $(node);
478 var lineNo = $node.closest('td').attr('data-line-number');
478 var lineNo = $node.closest('td').attr('data-line-number');
479 if (lineNo === undefined && $node.data('commentInline')){
479 if (lineNo === undefined && $node.data('commentInline')){
480 lineNo = $node.data('commentLineNo')
480 lineNo = $node.data('commentLineNo')
481 }
481 }
482
482
483 return lineNo
483 return lineNo
484 };
484 };
485
485
486 this.scrollToComment = function(node, offset, outdated) {
486 this.scrollToComment = function(node, offset, outdated) {
487 if (offset === undefined) {
487 if (offset === undefined) {
488 offset = 0;
488 offset = 0;
489 }
489 }
490 var outdated = outdated || false;
490 var outdated = outdated || false;
491 var klass = outdated ? 'div.comment-outdated' : 'div.comment-current';
491 var klass = outdated ? 'div.comment-outdated' : 'div.comment-current';
492
492
493 if (!node) {
493 if (!node) {
494 node = $('.comment-selected');
494 node = $('.comment-selected');
495 if (!node.length) {
495 if (!node.length) {
496 node = $('comment-current')
496 node = $('comment-current')
497 }
497 }
498 }
498 }
499 $wrapper = $(node).closest('div.comment');
499 $wrapper = $(node).closest('div.comment');
500 $comment = $(node).closest(klass);
500 $comment = $(node).closest(klass);
501 $comments = $(klass);
501 $comments = $(klass);
502
502
503 // show hidden comment when referenced.
503 // show hidden comment when referenced.
504 if (!$wrapper.is(':visible')){
504 if (!$wrapper.is(':visible')){
505 $wrapper.show();
505 $wrapper.show();
506 }
506 }
507
507
508 $('.comment-selected').removeClass('comment-selected');
508 $('.comment-selected').removeClass('comment-selected');
509
509
510 var nextIdx = $(klass).index($comment) + offset;
510 var nextIdx = $(klass).index($comment) + offset;
511 if (nextIdx >= $comments.length) {
511 if (nextIdx >= $comments.length) {
512 nextIdx = 0;
512 nextIdx = 0;
513 }
513 }
514 var $next = $(klass).eq(nextIdx);
514 var $next = $(klass).eq(nextIdx);
515
515
516 var $cb = $next.closest('.cb');
516 var $cb = $next.closest('.cb');
517 $cb.removeClass('cb-collapsed');
517 $cb.removeClass('cb-collapsed');
518
518
519 var $filediffCollapseState = $cb.closest('.filediff').prev();
519 var $filediffCollapseState = $cb.closest('.filediff').prev();
520 $filediffCollapseState.prop('checked', false);
520 $filediffCollapseState.prop('checked', false);
521 $next.addClass('comment-selected');
521 $next.addClass('comment-selected');
522 scrollToElement($next);
522 scrollToElement($next);
523 return false;
523 return false;
524 };
524 };
525
525
526 this.nextComment = function(node) {
526 this.nextComment = function(node) {
527 return self.scrollToComment(node, 1);
527 return self.scrollToComment(node, 1);
528 };
528 };
529
529
530 this.prevComment = function(node) {
530 this.prevComment = function(node) {
531 return self.scrollToComment(node, -1);
531 return self.scrollToComment(node, -1);
532 };
532 };
533
533
534 this.nextOutdatedComment = function(node) {
534 this.nextOutdatedComment = function(node) {
535 return self.scrollToComment(node, 1, true);
535 return self.scrollToComment(node, 1, true);
536 };
536 };
537
537
538 this.prevOutdatedComment = function(node) {
538 this.prevOutdatedComment = function(node) {
539 return self.scrollToComment(node, -1, true);
539 return self.scrollToComment(node, -1, true);
540 };
540 };
541
541
542 this.deleteComment = function(node) {
542 this.deleteComment = function(node) {
543 if (!confirm(_gettext('Delete this comment?'))) {
543 if (!confirm(_gettext('Delete this comment?'))) {
544 return false;
544 return false;
545 }
545 }
546 var $node = $(node);
546 var $node = $(node);
547 var $td = $node.closest('td');
547 var $td = $node.closest('td');
548 var $comment = $node.closest('.comment');
548 var $comment = $node.closest('.comment');
549 var comment_id = $comment.attr('data-comment-id');
549 var comment_id = $comment.attr('data-comment-id');
550 var url = AJAX_COMMENT_DELETE_URL.replace('__COMMENT_ID__', comment_id);
550 var url = AJAX_COMMENT_DELETE_URL.replace('__COMMENT_ID__', comment_id);
551 var postData = {
551 var postData = {
552 'csrf_token': CSRF_TOKEN
552 'csrf_token': CSRF_TOKEN
553 };
553 };
554
554
555 $comment.addClass('comment-deleting');
555 $comment.addClass('comment-deleting');
556 $comment.hide('fast');
556 $comment.hide('fast');
557
557
558 var success = function(response) {
558 var success = function(response) {
559 $comment.remove();
559 $comment.remove();
560 return false;
560 return false;
561 };
561 };
562 var failure = function(data, textStatus, xhr) {
562 var failure = function(data, textStatus, xhr) {
563 alert("error processing request: " + textStatus);
563 alert("error processing request: " + textStatus);
564 $comment.show('fast');
564 $comment.show('fast');
565 $comment.removeClass('comment-deleting');
565 $comment.removeClass('comment-deleting');
566 return false;
566 return false;
567 };
567 };
568 ajaxPOST(url, postData, success, failure);
568 ajaxPOST(url, postData, success, failure);
569 };
569 };
570
570
571 this.toggleWideMode = function (node) {
571 this.toggleWideMode = function (node) {
572 if ($('#content').hasClass('wrapper')) {
572 if ($('#content').hasClass('wrapper')) {
573 $('#content').removeClass("wrapper");
573 $('#content').removeClass("wrapper");
574 $('#content').addClass("wide-mode-wrapper");
574 $('#content').addClass("wide-mode-wrapper");
575 $(node).addClass('btn-success');
575 $(node).addClass('btn-success');
576 } else {
576 } else {
577 $('#content').removeClass("wide-mode-wrapper");
577 $('#content').removeClass("wide-mode-wrapper");
578 $('#content').addClass("wrapper");
578 $('#content').addClass("wrapper");
579 $(node).removeClass('btn-success');
579 $(node).removeClass('btn-success');
580 }
580 }
581 return false;
581 return false;
582 };
582 };
583
583
584 this.toggleComments = function(node, show) {
584 this.toggleComments = function(node, show) {
585 var $filediff = $(node).closest('.filediff');
585 var $filediff = $(node).closest('.filediff');
586 if (show === true) {
586 if (show === true) {
587 $filediff.removeClass('hide-comments');
587 $filediff.removeClass('hide-comments');
588 } else if (show === false) {
588 } else if (show === false) {
589 $filediff.find('.hide-line-comments').removeClass('hide-line-comments');
589 $filediff.find('.hide-line-comments').removeClass('hide-line-comments');
590 $filediff.addClass('hide-comments');
590 $filediff.addClass('hide-comments');
591 } else {
591 } else {
592 $filediff.find('.hide-line-comments').removeClass('hide-line-comments');
592 $filediff.find('.hide-line-comments').removeClass('hide-line-comments');
593 $filediff.toggleClass('hide-comments');
593 $filediff.toggleClass('hide-comments');
594 }
594 }
595 return false;
595 return false;
596 };
596 };
597
597
598 this.toggleLineComments = function(node) {
598 this.toggleLineComments = function(node) {
599 self.toggleComments(node, true);
599 self.toggleComments(node, true);
600 var $node = $(node);
600 var $node = $(node);
601 // mark outdated comments as visible before the toggle;
602 $(node.closest('tr')).find('.comment-outdated').show();
601 $node.closest('tr').toggleClass('hide-line-comments');
603 $node.closest('tr').toggleClass('hide-line-comments');
602 };
604 };
603
605
604 this.createCommentForm = function(formElement, lineno, placeholderText, initAutocompleteActions, resolvesCommentId){
606 this.createCommentForm = function(formElement, lineno, placeholderText, initAutocompleteActions, resolvesCommentId){
605 var pullRequestId = templateContext.pull_request_data.pull_request_id;
607 var pullRequestId = templateContext.pull_request_data.pull_request_id;
606 var commitId = templateContext.commit_data.commit_id;
608 var commitId = templateContext.commit_data.commit_id;
607
609
608 var commentForm = new CommentForm(
610 var commentForm = new CommentForm(
609 formElement, commitId, pullRequestId, lineno, initAutocompleteActions, resolvesCommentId);
611 formElement, commitId, pullRequestId, lineno, initAutocompleteActions, resolvesCommentId);
610 var cm = commentForm.getCmInstance();
612 var cm = commentForm.getCmInstance();
611
613
612 if (resolvesCommentId){
614 if (resolvesCommentId){
613 var placeholderText = _gettext('Leave a comment, or click resolve button to resolve TODO comment #{0}').format(resolvesCommentId);
615 var placeholderText = _gettext('Leave a comment, or click resolve button to resolve TODO comment #{0}').format(resolvesCommentId);
614 }
616 }
615
617
616 setTimeout(function() {
618 setTimeout(function() {
617 // callbacks
619 // callbacks
618 if (cm !== undefined) {
620 if (cm !== undefined) {
619 commentForm.setPlaceholder(placeholderText);
621 commentForm.setPlaceholder(placeholderText);
620 if (commentForm.isInline()) {
622 if (commentForm.isInline()) {
621 cm.focus();
623 cm.focus();
622 cm.refresh();
624 cm.refresh();
623 }
625 }
624 }
626 }
625 }, 10);
627 }, 10);
626
628
627 // trigger scrolldown to the resolve comment, since it might be away
629 // trigger scrolldown to the resolve comment, since it might be away
628 // from the clicked
630 // from the clicked
629 if (resolvesCommentId){
631 if (resolvesCommentId){
630 var actionNode = $(commentForm.resolvesActionId).offset();
632 var actionNode = $(commentForm.resolvesActionId).offset();
631
633
632 setTimeout(function() {
634 setTimeout(function() {
633 if (actionNode) {
635 if (actionNode) {
634 $('body, html').animate({scrollTop: actionNode.top}, 10);
636 $('body, html').animate({scrollTop: actionNode.top}, 10);
635 }
637 }
636 }, 100);
638 }, 100);
637 }
639 }
638
640
639 return commentForm;
641 return commentForm;
640 };
642 };
641
643
642 this.createGeneralComment = function (lineNo, placeholderText, resolvesCommentId) {
644 this.createGeneralComment = function (lineNo, placeholderText, resolvesCommentId) {
643
645
644 var tmpl = $('#cb-comment-general-form-template').html();
646 var tmpl = $('#cb-comment-general-form-template').html();
645 tmpl = tmpl.format(null, 'general');
647 tmpl = tmpl.format(null, 'general');
646 var $form = $(tmpl);
648 var $form = $(tmpl);
647
649
648 var $formPlaceholder = $('#cb-comment-general-form-placeholder');
650 var $formPlaceholder = $('#cb-comment-general-form-placeholder');
649 var curForm = $formPlaceholder.find('form');
651 var curForm = $formPlaceholder.find('form');
650 if (curForm){
652 if (curForm){
651 curForm.remove();
653 curForm.remove();
652 }
654 }
653 $formPlaceholder.append($form);
655 $formPlaceholder.append($form);
654
656
655 var _form = $($form[0]);
657 var _form = $($form[0]);
656 var autocompleteActions = ['approve', 'reject', 'as_note', 'as_todo'];
658 var autocompleteActions = ['approve', 'reject', 'as_note', 'as_todo'];
657 var commentForm = this.createCommentForm(
659 var commentForm = this.createCommentForm(
658 _form, lineNo, placeholderText, autocompleteActions, resolvesCommentId);
660 _form, lineNo, placeholderText, autocompleteActions, resolvesCommentId);
659 commentForm.initStatusChangeSelector();
661 commentForm.initStatusChangeSelector();
660
662
661 return commentForm;
663 return commentForm;
662 };
664 };
663
665
664 this.createComment = function(node, resolutionComment) {
666 this.createComment = function(node, resolutionComment) {
665 var resolvesCommentId = resolutionComment || null;
667 var resolvesCommentId = resolutionComment || null;
666 var $node = $(node);
668 var $node = $(node);
667 var $td = $node.closest('td');
669 var $td = $node.closest('td');
668 var $form = $td.find('.comment-inline-form');
670 var $form = $td.find('.comment-inline-form');
669
671
670 if (!$form.length) {
672 if (!$form.length) {
671
673
672 var $filediff = $node.closest('.filediff');
674 var $filediff = $node.closest('.filediff');
673 $filediff.removeClass('hide-comments');
675 $filediff.removeClass('hide-comments');
674 var f_path = $filediff.attr('data-f-path');
676 var f_path = $filediff.attr('data-f-path');
675 var lineno = self.getLineNumber(node);
677 var lineno = self.getLineNumber(node);
676 // create a new HTML from template
678 // create a new HTML from template
677 var tmpl = $('#cb-comment-inline-form-template').html();
679 var tmpl = $('#cb-comment-inline-form-template').html();
678 tmpl = tmpl.format(escapeHtml(f_path), lineno);
680 tmpl = tmpl.format(escapeHtml(f_path), lineno);
679 $form = $(tmpl);
681 $form = $(tmpl);
680
682
681 var $comments = $td.find('.inline-comments');
683 var $comments = $td.find('.inline-comments');
682 if (!$comments.length) {
684 if (!$comments.length) {
683 $comments = $(
685 $comments = $(
684 $('#cb-comments-inline-container-template').html());
686 $('#cb-comments-inline-container-template').html());
685 $td.append($comments);
687 $td.append($comments);
686 }
688 }
687
689
688 $td.find('.cb-comment-add-button').before($form);
690 $td.find('.cb-comment-add-button').before($form);
689
691
690 var placeholderText = _gettext('Leave a comment on line {0}.').format(lineno);
692 var placeholderText = _gettext('Leave a comment on line {0}.').format(lineno);
691 var _form = $($form[0]).find('form');
693 var _form = $($form[0]).find('form');
692 var autocompleteActions = ['as_note', 'as_todo'];
694 var autocompleteActions = ['as_note', 'as_todo'];
693 var commentForm = this.createCommentForm(
695 var commentForm = this.createCommentForm(
694 _form, lineno, placeholderText, autocompleteActions, resolvesCommentId);
696 _form, lineno, placeholderText, autocompleteActions, resolvesCommentId);
695
697
696 $.Topic('/ui/plugins/code/comment_form_built').prepareOrPublish({
698 $.Topic('/ui/plugins/code/comment_form_built').prepareOrPublish({
697 form: _form,
699 form: _form,
698 parent: $td[0],
700 parent: $td[0],
699 lineno: lineno,
701 lineno: lineno,
700 f_path: f_path}
702 f_path: f_path}
701 );
703 );
702
704
703 // set a CUSTOM submit handler for inline comments.
705 // set a CUSTOM submit handler for inline comments.
704 commentForm.setHandleFormSubmit(function(o) {
706 commentForm.setHandleFormSubmit(function(o) {
705 var text = commentForm.cm.getValue();
707 var text = commentForm.cm.getValue();
706 var commentType = commentForm.getCommentType();
708 var commentType = commentForm.getCommentType();
707 var resolvesCommentId = commentForm.getResolvesId();
709 var resolvesCommentId = commentForm.getResolvesId();
708
710
709 if (text === "") {
711 if (text === "") {
710 return;
712 return;
711 }
713 }
712
714
713 if (lineno === undefined) {
715 if (lineno === undefined) {
714 alert('missing line !');
716 alert('missing line !');
715 return;
717 return;
716 }
718 }
717 if (f_path === undefined) {
719 if (f_path === undefined) {
718 alert('missing file path !');
720 alert('missing file path !');
719 return;
721 return;
720 }
722 }
721
723
722 var excludeCancelBtn = false;
724 var excludeCancelBtn = false;
723 var submitEvent = true;
725 var submitEvent = true;
724 commentForm.setActionButtonsDisabled(true, excludeCancelBtn, submitEvent);
726 commentForm.setActionButtonsDisabled(true, excludeCancelBtn, submitEvent);
725 commentForm.cm.setOption("readOnly", true);
727 commentForm.cm.setOption("readOnly", true);
726 var postData = {
728 var postData = {
727 'text': text,
729 'text': text,
728 'f_path': f_path,
730 'f_path': f_path,
729 'line': lineno,
731 'line': lineno,
730 'comment_type': commentType,
732 'comment_type': commentType,
731 'csrf_token': CSRF_TOKEN
733 'csrf_token': CSRF_TOKEN
732 };
734 };
733 if (resolvesCommentId){
735 if (resolvesCommentId){
734 postData['resolves_comment_id'] = resolvesCommentId;
736 postData['resolves_comment_id'] = resolvesCommentId;
735 }
737 }
736
738
737 var submitSuccessCallback = function(json_data) {
739 var submitSuccessCallback = function(json_data) {
738 $form.remove();
740 $form.remove();
739 try {
741 try {
740 var html = json_data.rendered_text;
742 var html = json_data.rendered_text;
741 var lineno = json_data.line_no;
743 var lineno = json_data.line_no;
742 var target_id = json_data.target_id;
744 var target_id = json_data.target_id;
743
745
744 $comments.find('.cb-comment-add-button').before(html);
746 $comments.find('.cb-comment-add-button').before(html);
745
747
746 //mark visually which comment was resolved
748 //mark visually which comment was resolved
747 if (resolvesCommentId) {
749 if (resolvesCommentId) {
748 commentForm.markCommentResolved(resolvesCommentId);
750 commentForm.markCommentResolved(resolvesCommentId);
749 }
751 }
750
752
751 // run global callback on submit
753 // run global callback on submit
752 commentForm.globalSubmitSuccessCallback();
754 commentForm.globalSubmitSuccessCallback();
753
755
754 } catch (e) {
756 } catch (e) {
755 console.error(e);
757 console.error(e);
756 }
758 }
757
759
758 // re trigger the linkification of next/prev navigation
760 // re trigger the linkification of next/prev navigation
759 linkifyComments($('.inline-comment-injected'));
761 linkifyComments($('.inline-comment-injected'));
760 timeagoActivate();
762 timeagoActivate();
761 commentForm.setActionButtonsDisabled(false);
763 commentForm.setActionButtonsDisabled(false);
762
764
763 };
765 };
764 var submitFailCallback = function(){
766 var submitFailCallback = function(){
765 commentForm.resetCommentFormState(text)
767 commentForm.resetCommentFormState(text)
766 };
768 };
767 commentForm.submitAjaxPOST(
769 commentForm.submitAjaxPOST(
768 commentForm.submitUrl, postData, submitSuccessCallback, submitFailCallback);
770 commentForm.submitUrl, postData, submitSuccessCallback, submitFailCallback);
769 });
771 });
770 }
772 }
771
773
772 $form.addClass('comment-inline-form-open');
774 $form.addClass('comment-inline-form-open');
773 };
775 };
774
776
775 this.createResolutionComment = function(commentId){
777 this.createResolutionComment = function(commentId){
776 // hide the trigger text
778 // hide the trigger text
777 $('#resolve-comment-{0}'.format(commentId)).hide();
779 $('#resolve-comment-{0}'.format(commentId)).hide();
778
780
779 var comment = $('#comment-'+commentId);
781 var comment = $('#comment-'+commentId);
780 var commentData = comment.data();
782 var commentData = comment.data();
781 if (commentData.commentInline) {
783 if (commentData.commentInline) {
782 this.createComment(comment, commentId)
784 this.createComment(comment, commentId)
783 } else {
785 } else {
784 Rhodecode.comments.createGeneralComment('general', "$placeholder", commentId)
786 Rhodecode.comments.createGeneralComment('general', "$placeholder", commentId)
785 }
787 }
786
788
787 return false;
789 return false;
788 };
790 };
789
791
790 this.submitResolution = function(commentId){
792 this.submitResolution = function(commentId){
791 var form = $('#resolve_comment_{0}'.format(commentId)).closest('form');
793 var form = $('#resolve_comment_{0}'.format(commentId)).closest('form');
792 var commentForm = form.get(0).CommentForm;
794 var commentForm = form.get(0).CommentForm;
793
795
794 var cm = commentForm.getCmInstance();
796 var cm = commentForm.getCmInstance();
795 var renderer = templateContext.visual.default_renderer;
797 var renderer = templateContext.visual.default_renderer;
796 if (renderer == 'rst'){
798 if (renderer == 'rst'){
797 var commentUrl = '`#{0} <{1}#comment-{0}>`_'.format(commentId, commentForm.selfUrl);
799 var commentUrl = '`#{0} <{1}#comment-{0}>`_'.format(commentId, commentForm.selfUrl);
798 } else if (renderer == 'markdown') {
800 } else if (renderer == 'markdown') {
799 var commentUrl = '[#{0}]({1}#comment-{0})'.format(commentId, commentForm.selfUrl);
801 var commentUrl = '[#{0}]({1}#comment-{0})'.format(commentId, commentForm.selfUrl);
800 } else {
802 } else {
801 var commentUrl = '{1}#comment-{0}'.format(commentId, commentForm.selfUrl);
803 var commentUrl = '{1}#comment-{0}'.format(commentId, commentForm.selfUrl);
802 }
804 }
803
805
804 cm.setValue(_gettext('TODO from comment {0} was fixed.').format(commentUrl));
806 cm.setValue(_gettext('TODO from comment {0} was fixed.').format(commentUrl));
805 form.submit();
807 form.submit();
806 return false;
808 return false;
807 };
809 };
808
810
809 };
811 };
General Comments 0
You need to be logged in to leave comments. Login now