Show More
@@ -1,623 +1,624 b'' | |||
|
1 | 1 | // # Copyright (C) 2010-2019 RhodeCode GmbH |
|
2 | 2 | // # |
|
3 | 3 | // # This program is free software: you can redistribute it and/or modify |
|
4 | 4 | // # it under the terms of the GNU Affero General Public License, version 3 |
|
5 | 5 | // # (only), as published by the Free Software Foundation. |
|
6 | 6 | // # |
|
7 | 7 | // # This program is distributed in the hope that it will be useful, |
|
8 | 8 | // # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 | 9 | // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 | 10 | // # GNU General Public License for more details. |
|
11 | 11 | // # |
|
12 | 12 | // # You should have received a copy of the GNU Affero General Public License |
|
13 | 13 | // # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
14 | 14 | // # |
|
15 | 15 | // # This program is dual-licensed. If you wish to learn more about the |
|
16 | 16 | // # RhodeCode Enterprise Edition, including its added features, Support services, |
|
17 | 17 | // # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | var prButtonLockChecks = { |
|
21 | 21 | 'compare': false, |
|
22 | 22 | 'reviewers': false |
|
23 | 23 | }; |
|
24 | 24 | |
|
25 | 25 | /** |
|
26 | 26 | * lock button until all checks and loads are made. E.g reviewer calculation |
|
27 | 27 | * should prevent from submitting a PR |
|
28 | 28 | * @param lockEnabled |
|
29 | 29 | * @param msg |
|
30 | 30 | * @param scope |
|
31 | 31 | */ |
|
32 | 32 | var prButtonLock = function(lockEnabled, msg, scope) { |
|
33 | 33 | scope = scope || 'all'; |
|
34 | 34 | if (scope == 'all'){ |
|
35 | 35 | prButtonLockChecks['compare'] = !lockEnabled; |
|
36 | 36 | prButtonLockChecks['reviewers'] = !lockEnabled; |
|
37 | 37 | } else if (scope == 'compare') { |
|
38 | 38 | prButtonLockChecks['compare'] = !lockEnabled; |
|
39 | 39 | } else if (scope == 'reviewers'){ |
|
40 | 40 | prButtonLockChecks['reviewers'] = !lockEnabled; |
|
41 | 41 | } |
|
42 | 42 | var checksMeet = prButtonLockChecks.compare && prButtonLockChecks.reviewers; |
|
43 | 43 | if (lockEnabled) { |
|
44 | 44 | $('#pr_submit').attr('disabled', 'disabled'); |
|
45 | 45 | } |
|
46 | 46 | else if (checksMeet) { |
|
47 | 47 | $('#pr_submit').removeAttr('disabled'); |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | 50 | if (msg) { |
|
51 | 51 | $('#pr_open_message').html(msg); |
|
52 | 52 | } |
|
53 | 53 | }; |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | /** |
|
57 | 57 | Generate Title and Description for a PullRequest. |
|
58 | 58 | In case of 1 commits, the title and description is that one commit |
|
59 | 59 | in case of multiple commits, we iterate on them with max N number of commits, |
|
60 | 60 | and build description in a form |
|
61 | 61 | - commitN |
|
62 | 62 | - commitN+1 |
|
63 | 63 | ... |
|
64 | 64 | |
|
65 | 65 | Title is then constructed from branch names, or other references, |
|
66 | 66 | replacing '-' and '_' into spaces |
|
67 | 67 | |
|
68 | 68 | * @param sourceRef |
|
69 | 69 | * @param elements |
|
70 | 70 | * @param limit |
|
71 | 71 | * @returns {*[]} |
|
72 | 72 | */ |
|
73 | 73 | var getTitleAndDescription = function(sourceRef, elements, limit) { |
|
74 | 74 | var title = ''; |
|
75 | 75 | var desc = ''; |
|
76 | 76 | |
|
77 | 77 | $.each($(elements).get().reverse().slice(0, limit), function(idx, value) { |
|
78 | var rawMessage = $(value).find('td.td-description .message').data('messageRaw'); | |
|
78 | var rawMessage = $(value).find('td.td-description .message').data('messageRaw').toString(); | |
|
79 | 79 | desc += '- ' + rawMessage.split('\n')[0].replace(/\n+$/, "") + '\n'; |
|
80 | 80 | }); |
|
81 | 81 | // only 1 commit, use commit message as title |
|
82 | 82 | if (elements.length === 1) { |
|
83 |
|
|
|
83 | var rawMessage = $(elements[0]).find('td.td-description .message').data('messageRaw').toString(); | |
|
84 | title = rawMessage.split('\n')[0]; | |
|
84 | 85 | } |
|
85 | 86 | else { |
|
86 | 87 | // use reference name |
|
87 | 88 | title = sourceRef.replace(/-/g, ' ').replace(/_/g, ' ').capitalizeFirstLetter(); |
|
88 | 89 | } |
|
89 | 90 | |
|
90 | 91 | return [title, desc] |
|
91 | 92 | }; |
|
92 | 93 | |
|
93 | 94 | |
|
94 | 95 | |
|
95 | 96 | ReviewersController = function () { |
|
96 | 97 | var self = this; |
|
97 | 98 | this.$reviewRulesContainer = $('#review_rules'); |
|
98 | 99 | this.$rulesList = this.$reviewRulesContainer.find('.pr-reviewer-rules'); |
|
99 | 100 | this.forbidReviewUsers = undefined; |
|
100 | 101 | this.$reviewMembers = $('#review_members'); |
|
101 | 102 | this.currentRequest = null; |
|
102 | 103 | |
|
103 | 104 | this.defaultForbidReviewUsers = function() { |
|
104 | 105 | return [ |
|
105 | 106 | {'username': 'default', |
|
106 | 107 | 'user_id': templateContext.default_user.user_id} |
|
107 | 108 | ]; |
|
108 | 109 | }; |
|
109 | 110 | |
|
110 | 111 | this.hideReviewRules = function() { |
|
111 | 112 | self.$reviewRulesContainer.hide(); |
|
112 | 113 | }; |
|
113 | 114 | |
|
114 | 115 | this.showReviewRules = function() { |
|
115 | 116 | self.$reviewRulesContainer.show(); |
|
116 | 117 | }; |
|
117 | 118 | |
|
118 | 119 | this.addRule = function(ruleText) { |
|
119 | 120 | self.showReviewRules(); |
|
120 | 121 | return '<div>- {0}</div>'.format(ruleText) |
|
121 | 122 | }; |
|
122 | 123 | |
|
123 | 124 | this.loadReviewRules = function(data) { |
|
124 | 125 | // reset forbidden Users |
|
125 | 126 | this.forbidReviewUsers = self.defaultForbidReviewUsers(); |
|
126 | 127 | |
|
127 | 128 | // reset state of review rules |
|
128 | 129 | self.$rulesList.html(''); |
|
129 | 130 | |
|
130 | 131 | if (!data || data.rules === undefined || $.isEmptyObject(data.rules)) { |
|
131 | 132 | // default rule, case for older repo that don't have any rules stored |
|
132 | 133 | self.$rulesList.append( |
|
133 | 134 | self.addRule( |
|
134 | 135 | _gettext('All reviewers must vote.')) |
|
135 | 136 | ); |
|
136 | 137 | return self.forbidReviewUsers |
|
137 | 138 | } |
|
138 | 139 | |
|
139 | 140 | if (data.rules.voting !== undefined) { |
|
140 | 141 | if (data.rules.voting < 0) { |
|
141 | 142 | self.$rulesList.append( |
|
142 | 143 | self.addRule( |
|
143 | 144 | _gettext('All individual reviewers must vote.')) |
|
144 | 145 | ) |
|
145 | 146 | } else if (data.rules.voting === 1) { |
|
146 | 147 | self.$rulesList.append( |
|
147 | 148 | self.addRule( |
|
148 | 149 | _gettext('At least {0} reviewer must vote.').format(data.rules.voting)) |
|
149 | 150 | ) |
|
150 | 151 | |
|
151 | 152 | } else { |
|
152 | 153 | self.$rulesList.append( |
|
153 | 154 | self.addRule( |
|
154 | 155 | _gettext('At least {0} reviewers must vote.').format(data.rules.voting)) |
|
155 | 156 | ) |
|
156 | 157 | } |
|
157 | 158 | } |
|
158 | 159 | |
|
159 | 160 | if (data.rules.voting_groups !== undefined) { |
|
160 | 161 | $.each(data.rules.voting_groups, function(index, rule_data) { |
|
161 | 162 | self.$rulesList.append( |
|
162 | 163 | self.addRule(rule_data.text) |
|
163 | 164 | ) |
|
164 | 165 | }); |
|
165 | 166 | } |
|
166 | 167 | |
|
167 | 168 | if (data.rules.use_code_authors_for_review) { |
|
168 | 169 | self.$rulesList.append( |
|
169 | 170 | self.addRule( |
|
170 | 171 | _gettext('Reviewers picked from source code changes.')) |
|
171 | 172 | ) |
|
172 | 173 | } |
|
173 | 174 | if (data.rules.forbid_adding_reviewers) { |
|
174 | 175 | $('#add_reviewer_input').remove(); |
|
175 | 176 | self.$rulesList.append( |
|
176 | 177 | self.addRule( |
|
177 | 178 | _gettext('Adding new reviewers is forbidden.')) |
|
178 | 179 | ) |
|
179 | 180 | } |
|
180 | 181 | if (data.rules.forbid_author_to_review) { |
|
181 | 182 | self.forbidReviewUsers.push(data.rules_data.pr_author); |
|
182 | 183 | self.$rulesList.append( |
|
183 | 184 | self.addRule( |
|
184 | 185 | _gettext('Author is not allowed to be a reviewer.')) |
|
185 | 186 | ) |
|
186 | 187 | } |
|
187 | 188 | if (data.rules.forbid_commit_author_to_review) { |
|
188 | 189 | |
|
189 | 190 | if (data.rules_data.forbidden_users) { |
|
190 | 191 | $.each(data.rules_data.forbidden_users, function(index, member_data) { |
|
191 | 192 | self.forbidReviewUsers.push(member_data) |
|
192 | 193 | }); |
|
193 | 194 | |
|
194 | 195 | } |
|
195 | 196 | |
|
196 | 197 | self.$rulesList.append( |
|
197 | 198 | self.addRule( |
|
198 | 199 | _gettext('Commit Authors are not allowed to be a reviewer.')) |
|
199 | 200 | ) |
|
200 | 201 | } |
|
201 | 202 | |
|
202 | 203 | return self.forbidReviewUsers |
|
203 | 204 | }; |
|
204 | 205 | |
|
205 | 206 | this.loadDefaultReviewers = function(sourceRepo, sourceRef, targetRepo, targetRef) { |
|
206 | 207 | |
|
207 | 208 | if (self.currentRequest) { |
|
208 | 209 | // make sure we cleanup old running requests before triggering this |
|
209 | 210 | // again |
|
210 | 211 | self.currentRequest.abort(); |
|
211 | 212 | } |
|
212 | 213 | |
|
213 | 214 | $('.calculate-reviewers').show(); |
|
214 | 215 | // reset reviewer members |
|
215 | 216 | self.$reviewMembers.empty(); |
|
216 | 217 | |
|
217 | 218 | prButtonLock(true, null, 'reviewers'); |
|
218 | 219 | $('#user').hide(); // hide user autocomplete before load |
|
219 | 220 | |
|
220 | 221 | if (sourceRef.length !== 3 || targetRef.length !== 3) { |
|
221 | 222 | // don't load defaults in case we're missing some refs... |
|
222 | 223 | $('.calculate-reviewers').hide(); |
|
223 | 224 | return |
|
224 | 225 | } |
|
225 | 226 | |
|
226 | 227 | var url = pyroutes.url('repo_default_reviewers_data', |
|
227 | 228 | { |
|
228 | 229 | 'repo_name': templateContext.repo_name, |
|
229 | 230 | 'source_repo': sourceRepo, |
|
230 | 231 | 'source_ref': sourceRef[2], |
|
231 | 232 | 'target_repo': targetRepo, |
|
232 | 233 | 'target_ref': targetRef[2] |
|
233 | 234 | }); |
|
234 | 235 | |
|
235 | 236 | self.currentRequest = $.get(url) |
|
236 | 237 | .done(function(data) { |
|
237 | 238 | self.currentRequest = null; |
|
238 | 239 | |
|
239 | 240 | // review rules |
|
240 | 241 | self.loadReviewRules(data); |
|
241 | 242 | |
|
242 | 243 | for (var i = 0; i < data.reviewers.length; i++) { |
|
243 | 244 | var reviewer = data.reviewers[i]; |
|
244 | 245 | self.addReviewMember( |
|
245 | 246 | reviewer, reviewer.reasons, reviewer.mandatory); |
|
246 | 247 | } |
|
247 | 248 | $('.calculate-reviewers').hide(); |
|
248 | 249 | prButtonLock(false, null, 'reviewers'); |
|
249 | 250 | $('#user').show(); // show user autocomplete after load |
|
250 | 251 | }); |
|
251 | 252 | }; |
|
252 | 253 | |
|
253 | 254 | // check those, refactor |
|
254 | 255 | this.removeReviewMember = function(reviewer_id, mark_delete) { |
|
255 | 256 | var reviewer = $('#reviewer_{0}'.format(reviewer_id)); |
|
256 | 257 | |
|
257 | 258 | if(typeof(mark_delete) === undefined){ |
|
258 | 259 | mark_delete = false; |
|
259 | 260 | } |
|
260 | 261 | |
|
261 | 262 | if(mark_delete === true){ |
|
262 | 263 | if (reviewer){ |
|
263 | 264 | // now delete the input |
|
264 | 265 | $('#reviewer_{0} input'.format(reviewer_id)).remove(); |
|
265 | 266 | // mark as to-delete |
|
266 | 267 | var obj = $('#reviewer_{0}_name'.format(reviewer_id)); |
|
267 | 268 | obj.addClass('to-delete'); |
|
268 | 269 | obj.css({"text-decoration":"line-through", "opacity": 0.5}); |
|
269 | 270 | } |
|
270 | 271 | } |
|
271 | 272 | else{ |
|
272 | 273 | $('#reviewer_{0}'.format(reviewer_id)).remove(); |
|
273 | 274 | } |
|
274 | 275 | }; |
|
275 | 276 | this.reviewMemberEntry = function() { |
|
276 | 277 | |
|
277 | 278 | }; |
|
278 | 279 | this.addReviewMember = function(reviewer_obj, reasons, mandatory) { |
|
279 | 280 | var members = self.$reviewMembers.get(0); |
|
280 | 281 | var id = reviewer_obj.user_id; |
|
281 | 282 | var username = reviewer_obj.username; |
|
282 | 283 | |
|
283 | 284 | var reasons = reasons || []; |
|
284 | 285 | var mandatory = mandatory || false; |
|
285 | 286 | |
|
286 | 287 | // register IDS to check if we don't have this ID already in |
|
287 | 288 | var currentIds = []; |
|
288 | 289 | var _els = self.$reviewMembers.find('li').toArray(); |
|
289 | 290 | for (el in _els){ |
|
290 | 291 | currentIds.push(_els[el].id) |
|
291 | 292 | } |
|
292 | 293 | |
|
293 | 294 | var userAllowedReview = function(userId) { |
|
294 | 295 | var allowed = true; |
|
295 | 296 | $.each(self.forbidReviewUsers, function(index, member_data) { |
|
296 | 297 | if (parseInt(userId) === member_data['user_id']) { |
|
297 | 298 | allowed = false; |
|
298 | 299 | return false // breaks the loop |
|
299 | 300 | } |
|
300 | 301 | }); |
|
301 | 302 | return allowed |
|
302 | 303 | }; |
|
303 | 304 | |
|
304 | 305 | var userAllowed = userAllowedReview(id); |
|
305 | 306 | if (!userAllowed){ |
|
306 | 307 | alert(_gettext('User `{0}` not allowed to be a reviewer').format(username)); |
|
307 | 308 | } else { |
|
308 | 309 | // only add if it's not there |
|
309 | 310 | var alreadyReviewer = currentIds.indexOf('reviewer_'+id) != -1; |
|
310 | 311 | |
|
311 | 312 | if (alreadyReviewer) { |
|
312 | 313 | alert(_gettext('User `{0}` already in reviewers').format(username)); |
|
313 | 314 | } else { |
|
314 | 315 | members.innerHTML += renderTemplate('reviewMemberEntry', { |
|
315 | 316 | 'member': reviewer_obj, |
|
316 | 317 | 'mandatory': mandatory, |
|
317 | 318 | 'allowed_to_update': true, |
|
318 | 319 | 'review_status': 'not_reviewed', |
|
319 | 320 | 'review_status_label': _gettext('Not Reviewed'), |
|
320 | 321 | 'reasons': reasons, |
|
321 | 322 | 'create': true |
|
322 | 323 | }); |
|
323 | 324 | tooltipActivate(); |
|
324 | 325 | } |
|
325 | 326 | } |
|
326 | 327 | |
|
327 | 328 | }; |
|
328 | 329 | |
|
329 | 330 | this.updateReviewers = function(repo_name, pull_request_id){ |
|
330 | 331 | var postData = $('#reviewers input').serialize(); |
|
331 | 332 | _updatePullRequest(repo_name, pull_request_id, postData); |
|
332 | 333 | }; |
|
333 | 334 | |
|
334 | 335 | }; |
|
335 | 336 | |
|
336 | 337 | |
|
337 | 338 | var _updatePullRequest = function(repo_name, pull_request_id, postData) { |
|
338 | 339 | var url = pyroutes.url( |
|
339 | 340 | 'pullrequest_update', |
|
340 | 341 | {"repo_name": repo_name, "pull_request_id": pull_request_id}); |
|
341 | 342 | if (typeof postData === 'string' ) { |
|
342 | 343 | postData += '&csrf_token=' + CSRF_TOKEN; |
|
343 | 344 | } else { |
|
344 | 345 | postData.csrf_token = CSRF_TOKEN; |
|
345 | 346 | } |
|
346 | 347 | |
|
347 | 348 | var success = function(o) { |
|
348 | 349 | var redirectUrl = o['redirect_url']; |
|
349 | 350 | if (redirectUrl !== undefined && redirectUrl !== null && redirectUrl !== '') { |
|
350 | 351 | window.location = redirectUrl; |
|
351 | 352 | } else { |
|
352 | 353 | window.location.reload(); |
|
353 | 354 | } |
|
354 | 355 | }; |
|
355 | 356 | |
|
356 | 357 | ajaxPOST(url, postData, success); |
|
357 | 358 | }; |
|
358 | 359 | |
|
359 | 360 | /** |
|
360 | 361 | * PULL REQUEST update commits |
|
361 | 362 | */ |
|
362 | 363 | var updateCommits = function(repo_name, pull_request_id, force) { |
|
363 | 364 | var postData = { |
|
364 | 365 | 'update_commits': true |
|
365 | 366 | }; |
|
366 | 367 | if (force !== undefined && force === true) { |
|
367 | 368 | postData['force_refresh'] = true |
|
368 | 369 | } |
|
369 | 370 | _updatePullRequest(repo_name, pull_request_id, postData); |
|
370 | 371 | }; |
|
371 | 372 | |
|
372 | 373 | |
|
373 | 374 | /** |
|
374 | 375 | * PULL REQUEST edit info |
|
375 | 376 | */ |
|
376 | 377 | var editPullRequest = function(repo_name, pull_request_id, title, description, renderer) { |
|
377 | 378 | var url = pyroutes.url( |
|
378 | 379 | 'pullrequest_update', |
|
379 | 380 | {"repo_name": repo_name, "pull_request_id": pull_request_id}); |
|
380 | 381 | |
|
381 | 382 | var postData = { |
|
382 | 383 | 'title': title, |
|
383 | 384 | 'description': description, |
|
384 | 385 | 'description_renderer': renderer, |
|
385 | 386 | 'edit_pull_request': true, |
|
386 | 387 | 'csrf_token': CSRF_TOKEN |
|
387 | 388 | }; |
|
388 | 389 | var success = function(o) { |
|
389 | 390 | window.location.reload(); |
|
390 | 391 | }; |
|
391 | 392 | ajaxPOST(url, postData, success); |
|
392 | 393 | }; |
|
393 | 394 | |
|
394 | 395 | |
|
395 | 396 | /** |
|
396 | 397 | * Reviewer autocomplete |
|
397 | 398 | */ |
|
398 | 399 | var ReviewerAutoComplete = function(inputId) { |
|
399 | 400 | $(inputId).autocomplete({ |
|
400 | 401 | serviceUrl: pyroutes.url('user_autocomplete_data'), |
|
401 | 402 | minChars:2, |
|
402 | 403 | maxHeight:400, |
|
403 | 404 | deferRequestBy: 300, //miliseconds |
|
404 | 405 | showNoSuggestionNotice: true, |
|
405 | 406 | tabDisabled: true, |
|
406 | 407 | autoSelectFirst: true, |
|
407 | 408 | params: { user_id: templateContext.rhodecode_user.user_id, user_groups:true, user_groups_expand:true, skip_default_user:true }, |
|
408 | 409 | formatResult: autocompleteFormatResult, |
|
409 | 410 | lookupFilter: autocompleteFilterResult, |
|
410 | 411 | onSelect: function(element, data) { |
|
411 | 412 | var mandatory = false; |
|
412 | 413 | var reasons = [_gettext('added manually by "{0}"').format(templateContext.rhodecode_user.username)]; |
|
413 | 414 | |
|
414 | 415 | // add whole user groups |
|
415 | 416 | if (data.value_type == 'user_group') { |
|
416 | 417 | reasons.push(_gettext('member of "{0}"').format(data.value_display)); |
|
417 | 418 | |
|
418 | 419 | $.each(data.members, function(index, member_data) { |
|
419 | 420 | var reviewer = member_data; |
|
420 | 421 | reviewer['user_id'] = member_data['id']; |
|
421 | 422 | reviewer['gravatar_link'] = member_data['icon_link']; |
|
422 | 423 | reviewer['user_link'] = member_data['profile_link']; |
|
423 | 424 | reviewer['rules'] = []; |
|
424 | 425 | reviewersController.addReviewMember(reviewer, reasons, mandatory); |
|
425 | 426 | }) |
|
426 | 427 | } |
|
427 | 428 | // add single user |
|
428 | 429 | else { |
|
429 | 430 | var reviewer = data; |
|
430 | 431 | reviewer['user_id'] = data['id']; |
|
431 | 432 | reviewer['gravatar_link'] = data['icon_link']; |
|
432 | 433 | reviewer['user_link'] = data['profile_link']; |
|
433 | 434 | reviewer['rules'] = []; |
|
434 | 435 | reviewersController.addReviewMember(reviewer, reasons, mandatory); |
|
435 | 436 | } |
|
436 | 437 | |
|
437 | 438 | $(inputId).val(''); |
|
438 | 439 | } |
|
439 | 440 | }); |
|
440 | 441 | }; |
|
441 | 442 | |
|
442 | 443 | |
|
443 | 444 | VersionController = function () { |
|
444 | 445 | var self = this; |
|
445 | 446 | this.$verSource = $('input[name=ver_source]'); |
|
446 | 447 | this.$verTarget = $('input[name=ver_target]'); |
|
447 | 448 | this.$showVersionDiff = $('#show-version-diff'); |
|
448 | 449 | |
|
449 | 450 | this.adjustRadioSelectors = function (curNode) { |
|
450 | 451 | var getVal = function (item) { |
|
451 | 452 | if (item == 'latest') { |
|
452 | 453 | return Number.MAX_SAFE_INTEGER |
|
453 | 454 | } |
|
454 | 455 | else { |
|
455 | 456 | return parseInt(item) |
|
456 | 457 | } |
|
457 | 458 | }; |
|
458 | 459 | |
|
459 | 460 | var curVal = getVal($(curNode).val()); |
|
460 | 461 | var cleared = false; |
|
461 | 462 | |
|
462 | 463 | $.each(self.$verSource, function (index, value) { |
|
463 | 464 | var elVal = getVal($(value).val()); |
|
464 | 465 | |
|
465 | 466 | if (elVal > curVal) { |
|
466 | 467 | if ($(value).is(':checked')) { |
|
467 | 468 | cleared = true; |
|
468 | 469 | } |
|
469 | 470 | $(value).attr('disabled', 'disabled'); |
|
470 | 471 | $(value).removeAttr('checked'); |
|
471 | 472 | $(value).css({'opacity': 0.1}); |
|
472 | 473 | } |
|
473 | 474 | else { |
|
474 | 475 | $(value).css({'opacity': 1}); |
|
475 | 476 | $(value).removeAttr('disabled'); |
|
476 | 477 | } |
|
477 | 478 | }); |
|
478 | 479 | |
|
479 | 480 | if (cleared) { |
|
480 | 481 | // if we unchecked an active, set the next one to same loc. |
|
481 | 482 | $(this.$verSource).filter('[value={0}]'.format( |
|
482 | 483 | curVal)).attr('checked', 'checked'); |
|
483 | 484 | } |
|
484 | 485 | |
|
485 | 486 | self.setLockAction(false, |
|
486 | 487 | $(curNode).data('verPos'), |
|
487 | 488 | $(this.$verSource).filter(':checked').data('verPos') |
|
488 | 489 | ); |
|
489 | 490 | }; |
|
490 | 491 | |
|
491 | 492 | |
|
492 | 493 | this.attachVersionListener = function () { |
|
493 | 494 | self.$verTarget.change(function (e) { |
|
494 | 495 | self.adjustRadioSelectors(this) |
|
495 | 496 | }); |
|
496 | 497 | self.$verSource.change(function (e) { |
|
497 | 498 | self.adjustRadioSelectors(self.$verTarget.filter(':checked')) |
|
498 | 499 | }); |
|
499 | 500 | }; |
|
500 | 501 | |
|
501 | 502 | this.init = function () { |
|
502 | 503 | |
|
503 | 504 | var curNode = self.$verTarget.filter(':checked'); |
|
504 | 505 | self.adjustRadioSelectors(curNode); |
|
505 | 506 | self.setLockAction(true); |
|
506 | 507 | self.attachVersionListener(); |
|
507 | 508 | |
|
508 | 509 | }; |
|
509 | 510 | |
|
510 | 511 | this.setLockAction = function (state, selectedVersion, otherVersion) { |
|
511 | 512 | var $showVersionDiff = this.$showVersionDiff; |
|
512 | 513 | |
|
513 | 514 | if (state) { |
|
514 | 515 | $showVersionDiff.attr('disabled', 'disabled'); |
|
515 | 516 | $showVersionDiff.addClass('disabled'); |
|
516 | 517 | $showVersionDiff.html($showVersionDiff.data('labelTextLocked')); |
|
517 | 518 | } |
|
518 | 519 | else { |
|
519 | 520 | $showVersionDiff.removeAttr('disabled'); |
|
520 | 521 | $showVersionDiff.removeClass('disabled'); |
|
521 | 522 | |
|
522 | 523 | if (selectedVersion == otherVersion) { |
|
523 | 524 | $showVersionDiff.html($showVersionDiff.data('labelTextShow')); |
|
524 | 525 | } else { |
|
525 | 526 | $showVersionDiff.html($showVersionDiff.data('labelTextDiff')); |
|
526 | 527 | } |
|
527 | 528 | } |
|
528 | 529 | |
|
529 | 530 | }; |
|
530 | 531 | |
|
531 | 532 | this.showVersionDiff = function () { |
|
532 | 533 | var target = self.$verTarget.filter(':checked'); |
|
533 | 534 | var source = self.$verSource.filter(':checked'); |
|
534 | 535 | |
|
535 | 536 | if (target.val() && source.val()) { |
|
536 | 537 | var params = { |
|
537 | 538 | 'pull_request_id': templateContext.pull_request_data.pull_request_id, |
|
538 | 539 | 'repo_name': templateContext.repo_name, |
|
539 | 540 | 'version': target.val(), |
|
540 | 541 | 'from_version': source.val() |
|
541 | 542 | }; |
|
542 | 543 | window.location = pyroutes.url('pullrequest_show', params) |
|
543 | 544 | } |
|
544 | 545 | |
|
545 | 546 | return false; |
|
546 | 547 | }; |
|
547 | 548 | |
|
548 | 549 | this.toggleVersionView = function (elem) { |
|
549 | 550 | |
|
550 | 551 | if (this.$showVersionDiff.is(':visible')) { |
|
551 | 552 | $('.version-pr').hide(); |
|
552 | 553 | this.$showVersionDiff.hide(); |
|
553 | 554 | $(elem).html($(elem).data('toggleOn')) |
|
554 | 555 | } else { |
|
555 | 556 | $('.version-pr').show(); |
|
556 | 557 | this.$showVersionDiff.show(); |
|
557 | 558 | $(elem).html($(elem).data('toggleOff')) |
|
558 | 559 | } |
|
559 | 560 | |
|
560 | 561 | return false |
|
561 | 562 | }; |
|
562 | 563 | |
|
563 | 564 | this.toggleElement = function (elem, target) { |
|
564 | 565 | var $elem = $(elem); |
|
565 | 566 | var $target = $(target); |
|
566 | 567 | |
|
567 | 568 | if ($target.is(':visible')) { |
|
568 | 569 | $target.hide(); |
|
569 | 570 | $elem.html($elem.data('toggleOn')) |
|
570 | 571 | } else { |
|
571 | 572 | $target.show(); |
|
572 | 573 | $elem.html($elem.data('toggleOff')) |
|
573 | 574 | } |
|
574 | 575 | |
|
575 | 576 | return false |
|
576 | 577 | } |
|
577 | 578 | |
|
578 | 579 | }; |
|
579 | 580 | |
|
580 | 581 | |
|
581 | 582 | UpdatePrController = function () { |
|
582 | 583 | var self = this; |
|
583 | 584 | this.$updateCommits = $('#update_commits'); |
|
584 | 585 | this.$updateCommitsSwitcher = $('#update_commits_switcher'); |
|
585 | 586 | |
|
586 | 587 | this.lockUpdateButton = function (label) { |
|
587 | 588 | self.$updateCommits.attr('disabled', 'disabled'); |
|
588 | 589 | self.$updateCommitsSwitcher.attr('disabled', 'disabled'); |
|
589 | 590 | |
|
590 | 591 | self.$updateCommits.addClass('disabled'); |
|
591 | 592 | self.$updateCommitsSwitcher.addClass('disabled'); |
|
592 | 593 | |
|
593 | 594 | self.$updateCommits.removeClass('btn-primary'); |
|
594 | 595 | self.$updateCommitsSwitcher.removeClass('btn-primary'); |
|
595 | 596 | |
|
596 | 597 | self.$updateCommits.text(_gettext(label)); |
|
597 | 598 | }; |
|
598 | 599 | |
|
599 | 600 | this.isUpdateLocked = function () { |
|
600 | 601 | return self.$updateCommits.attr('disabled') !== undefined; |
|
601 | 602 | }; |
|
602 | 603 | |
|
603 | 604 | this.updateCommits = function (curNode) { |
|
604 | 605 | if (self.isUpdateLocked()) { |
|
605 | 606 | return |
|
606 | 607 | } |
|
607 | 608 | self.lockUpdateButton(_gettext('Updating...')); |
|
608 | 609 | updateCommits( |
|
609 | 610 | templateContext.repo_name, |
|
610 | 611 | templateContext.pull_request_data.pull_request_id); |
|
611 | 612 | }; |
|
612 | 613 | |
|
613 | 614 | this.forceUpdateCommits = function () { |
|
614 | 615 | if (self.isUpdateLocked()) { |
|
615 | 616 | return |
|
616 | 617 | } |
|
617 | 618 | self.lockUpdateButton(_gettext('Force updating...')); |
|
618 | 619 | var force = true; |
|
619 | 620 | updateCommits( |
|
620 | 621 | templateContext.repo_name, |
|
621 | 622 | templateContext.pull_request_data.pull_request_id, force); |
|
622 | 623 | }; |
|
623 | 624 | }; No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now