Show More
@@ -1,548 +1,548 b'' | |||
|
1 | 1 | <%inherit file="/base/base.mako"/> |
|
2 | 2 | <%namespace name="dt" file="/data_table/_dt_elements.mako"/> |
|
3 | 3 | |
|
4 | 4 | <%def name="title()"> |
|
5 | 5 | ${c.repo_name} ${_('New pull request')} |
|
6 | 6 | </%def> |
|
7 | 7 | |
|
8 | 8 | <%def name="breadcrumbs_links()"> |
|
9 | 9 | ${_('New pull request')} |
|
10 | 10 | </%def> |
|
11 | 11 | |
|
12 | 12 | <%def name="menu_bar_nav()"> |
|
13 | 13 | ${self.menu_items(active='repositories')} |
|
14 | 14 | </%def> |
|
15 | 15 | |
|
16 | 16 | <%def name="menu_bar_subnav()"> |
|
17 | 17 | ${self.repo_menu(active='showpullrequest')} |
|
18 | 18 | </%def> |
|
19 | 19 | |
|
20 | 20 | <%def name="main()"> |
|
21 | 21 | <div class="box"> |
|
22 | 22 | <div class="title"> |
|
23 | 23 | ${self.repo_page_title(c.rhodecode_db_repo)} |
|
24 | 24 | </div> |
|
25 | 25 | |
|
26 | 26 | ${h.secure_form(h.route_path('pullrequest_create', repo_name=c.repo_name, _query=request.GET.mixed()), id='pull_request_form', request=request)} |
|
27 | 27 | |
|
28 | 28 | ${self.breadcrumbs()} |
|
29 | 29 | |
|
30 | 30 | <div class="box pr-summary"> |
|
31 | 31 | |
|
32 | 32 | <div class="summary-details block-left"> |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | <div class="pr-details-title"> |
|
36 | 36 | ${_('Pull request summary')} |
|
37 | 37 | </div> |
|
38 | 38 | |
|
39 | 39 | <div class="form" style="padding-top: 10px"> |
|
40 | 40 | <!-- fields --> |
|
41 | 41 | |
|
42 | 42 | <div class="fields" > |
|
43 | 43 | |
|
44 | 44 | <div class="field"> |
|
45 | 45 | <div class="label"> |
|
46 | 46 | <label for="pullrequest_title">${_('Title')}:</label> |
|
47 | 47 | </div> |
|
48 | 48 | <div class="input"> |
|
49 | 49 | ${h.text('pullrequest_title', c.default_title, class_="medium autogenerated-title")} |
|
50 | 50 | </div> |
|
51 | 51 | </div> |
|
52 | 52 | |
|
53 | 53 | <div class="field"> |
|
54 | 54 | <div class="label label-textarea"> |
|
55 | 55 | <label for="pullrequest_desc">${_('Description')}:</label> |
|
56 | 56 | </div> |
|
57 | 57 | <div class="textarea text-area editor"> |
|
58 | 58 | <input id="pr-renderer-input" type="hidden" name="description_renderer" value="${c.visual.default_renderer}"> |
|
59 | 59 | ${dt.markup_form('pullrequest_desc')} |
|
60 | 60 | </div> |
|
61 | 61 | </div> |
|
62 | 62 | |
|
63 | 63 | <div class="field"> |
|
64 | 64 | <div class="label label-textarea"> |
|
65 | 65 | <label for="commit_flow">${_('Commit flow')}:</label> |
|
66 | 66 | </div> |
|
67 | 67 | |
|
68 | 68 | ## TODO: johbo: Abusing the "content" class here to get the |
|
69 | 69 | ## desired effect. Should be replaced by a proper solution. |
|
70 | 70 | |
|
71 | 71 | ##ORG |
|
72 | 72 | <div class="content"> |
|
73 | 73 | <strong>${_('Source repository')}:</strong> |
|
74 | 74 | ${c.rhodecode_db_repo.description} |
|
75 | 75 | </div> |
|
76 | 76 | <div class="content"> |
|
77 | 77 | ${h.hidden('source_repo')} |
|
78 | 78 | ${h.hidden('source_ref')} |
|
79 | 79 | </div> |
|
80 | 80 | |
|
81 | 81 | ##OTHER, most Probably the PARENT OF THIS FORK |
|
82 | 82 | <div class="content"> |
|
83 | 83 | ## filled with JS |
|
84 | 84 | <div id="target_repo_desc"></div> |
|
85 | 85 | </div> |
|
86 | 86 | |
|
87 | 87 | <div class="content"> |
|
88 | 88 | ${h.hidden('target_repo')} |
|
89 | 89 | ${h.hidden('target_ref')} |
|
90 | 90 | <span id="target_ref_loading" style="display: none"> |
|
91 | 91 | ${_('Loading refs...')} |
|
92 | 92 | </span> |
|
93 | 93 | </div> |
|
94 | 94 | </div> |
|
95 | 95 | |
|
96 | 96 | <div class="field"> |
|
97 | 97 | <div class="label label-textarea"> |
|
98 | 98 | <label for="pullrequest_submit"></label> |
|
99 | 99 | </div> |
|
100 | 100 | <div class="input"> |
|
101 | 101 | <div class="pr-submit-button"> |
|
102 | 102 | <input id="pr_submit" class="btn" name="save" type="submit" value="${_('Submit Pull Request')}"> |
|
103 | 103 | </div> |
|
104 | 104 | <div id="pr_open_message"></div> |
|
105 | 105 | </div> |
|
106 | 106 | </div> |
|
107 | 107 | |
|
108 | 108 | <div class="pr-spacing-container"></div> |
|
109 | 109 | </div> |
|
110 | 110 | </div> |
|
111 | 111 | </div> |
|
112 | 112 | <div> |
|
113 | 113 | ## AUTHOR |
|
114 | 114 | <div class="reviewers-title block-right"> |
|
115 | 115 | <div class="pr-details-title"> |
|
116 | 116 | ${_('Author of this pull request')} |
|
117 | 117 | </div> |
|
118 | 118 | </div> |
|
119 | 119 | <div class="block-right pr-details-content reviewers"> |
|
120 | 120 | <ul class="group_members"> |
|
121 | 121 | <li> |
|
122 | 122 | ${self.gravatar_with_user(c.rhodecode_user.email, 16)} |
|
123 | 123 | </li> |
|
124 | 124 | </ul> |
|
125 | 125 | </div> |
|
126 | 126 | |
|
127 | 127 | ## REVIEW RULES |
|
128 | 128 | <div id="review_rules" style="display: none" class="reviewers-title block-right"> |
|
129 | 129 | <div class="pr-details-title"> |
|
130 | 130 | ${_('Reviewer rules')} |
|
131 | 131 | </div> |
|
132 | 132 | <div class="pr-reviewer-rules"> |
|
133 | 133 | ## review rules will be appended here, by default reviewers logic |
|
134 | 134 | </div> |
|
135 | 135 | </div> |
|
136 | 136 | |
|
137 | 137 | ## REVIEWERS |
|
138 | 138 | <div class="reviewers-title block-right"> |
|
139 | 139 | <div class="pr-details-title"> |
|
140 | 140 | ${_('Pull request reviewers')} |
|
141 | 141 | <span class="calculate-reviewers"> - ${_('loading...')}</span> |
|
142 | 142 | </div> |
|
143 | 143 | </div> |
|
144 | 144 | <div id="reviewers" class="block-right pr-details-content reviewers"> |
|
145 | 145 | ## members goes here, filled via JS based on initial selection ! |
|
146 | 146 | <input type="hidden" name="__start__" value="review_members:sequence"> |
|
147 | 147 | <ul id="review_members" class="group_members"></ul> |
|
148 | 148 | <input type="hidden" name="__end__" value="review_members:sequence"> |
|
149 | 149 | <div id="add_reviewer_input" class='ac'> |
|
150 | 150 | <div class="reviewer_ac"> |
|
151 | 151 | ${h.text('user', class_='ac-input', placeholder=_('Add reviewer or reviewer group'))} |
|
152 | 152 | <div id="reviewers_container"></div> |
|
153 | 153 | </div> |
|
154 | 154 | </div> |
|
155 | 155 | </div> |
|
156 | 156 | </div> |
|
157 | 157 | </div> |
|
158 | 158 | <div class="box"> |
|
159 | 159 | <div> |
|
160 | 160 | ## overview pulled by ajax |
|
161 | 161 | <div id="pull_request_overview"></div> |
|
162 | 162 | </div> |
|
163 | 163 | </div> |
|
164 | 164 | ${h.end_form()} |
|
165 | 165 | </div> |
|
166 | 166 | |
|
167 | 167 | <script type="text/javascript"> |
|
168 | 168 | $(function(){ |
|
169 | 169 | var defaultSourceRepo = '${c.default_repo_data['source_repo_name']}'; |
|
170 | 170 | var defaultSourceRepoData = ${c.default_repo_data['source_refs_json']|n}; |
|
171 | 171 | var defaultTargetRepo = '${c.default_repo_data['target_repo_name']}'; |
|
172 | 172 | var defaultTargetRepoData = ${c.default_repo_data['target_refs_json']|n}; |
|
173 | 173 | |
|
174 | 174 | var $pullRequestForm = $('#pull_request_form'); |
|
175 | 175 | var $pullRequestSubmit = $('#pr_submit', $pullRequestForm); |
|
176 | 176 | var $sourceRepo = $('#source_repo', $pullRequestForm); |
|
177 | 177 | var $targetRepo = $('#target_repo', $pullRequestForm); |
|
178 | 178 | var $sourceRef = $('#source_ref', $pullRequestForm); |
|
179 | 179 | var $targetRef = $('#target_ref', $pullRequestForm); |
|
180 | 180 | |
|
181 | 181 | var sourceRepo = function() { return $sourceRepo.eq(0).val() }; |
|
182 | 182 | var sourceRef = function() { return $sourceRef.eq(0).val().split(':') }; |
|
183 | 183 | |
|
184 | 184 | var targetRepo = function() { return $targetRepo.eq(0).val() }; |
|
185 | 185 | var targetRef = function() { return $targetRef.eq(0).val().split(':') }; |
|
186 | 186 | |
|
187 | 187 | var calculateContainerWidth = function() { |
|
188 | 188 | var maxWidth = 0; |
|
189 | 189 | var repoSelect2Containers = ['#source_repo', '#target_repo']; |
|
190 | 190 | $.each(repoSelect2Containers, function(idx, value) { |
|
191 | 191 | $(value).select2('container').width('auto'); |
|
192 | 192 | var curWidth = $(value).select2('container').width(); |
|
193 | 193 | if (maxWidth <= curWidth) { |
|
194 | 194 | maxWidth = curWidth; |
|
195 | 195 | } |
|
196 | 196 | $.each(repoSelect2Containers, function(idx, value) { |
|
197 | 197 | $(value).select2('container').width(maxWidth + 10); |
|
198 | 198 | }); |
|
199 | 199 | }); |
|
200 | 200 | }; |
|
201 | 201 | |
|
202 | 202 | var initRefSelection = function(selectedRef) { |
|
203 | 203 | return function(element, callback) { |
|
204 | 204 | // translate our select2 id into a text, it's a mapping to show |
|
205 | 205 | // simple label when selecting by internal ID. |
|
206 | 206 | var id, refData; |
|
207 | 207 | if (selectedRef === undefined || selectedRef === null) { |
|
208 | 208 | id = element.val(); |
|
209 | 209 | refData = element.val().split(':'); |
|
210 | 210 | |
|
211 | 211 | if (refData.length !== 3){ |
|
212 | 212 | refData = ["", "", ""] |
|
213 | 213 | } |
|
214 | 214 | } else { |
|
215 | 215 | id = selectedRef; |
|
216 | 216 | refData = selectedRef.split(':'); |
|
217 | 217 | } |
|
218 | 218 | |
|
219 | 219 | var text = refData[1]; |
|
220 | 220 | if (refData[0] === 'rev') { |
|
221 | 221 | text = text.substring(0, 12); |
|
222 | 222 | } |
|
223 | 223 | |
|
224 | 224 | var data = {id: id, text: text}; |
|
225 | 225 | callback(data); |
|
226 | 226 | }; |
|
227 | 227 | }; |
|
228 | 228 | |
|
229 |
var formatRefSelection = function( |
|
|
229 | var formatRefSelection = function(data, container, escapeMarkup) { | |
|
230 | 230 | var prefix = ''; |
|
231 |
var refData = |
|
|
231 | var refData = data.id.split(':'); | |
|
232 | 232 | if (refData[0] === 'branch') { |
|
233 | 233 | prefix = '<i class="icon-branch"></i>'; |
|
234 | 234 | } |
|
235 | 235 | else if (refData[0] === 'book') { |
|
236 | 236 | prefix = '<i class="icon-bookmark"></i>'; |
|
237 | 237 | } |
|
238 | 238 | else if (refData[0] === 'tag') { |
|
239 | 239 | prefix = '<i class="icon-tag"></i>'; |
|
240 | 240 | } |
|
241 | 241 | |
|
242 |
var originalOption = |
|
|
243 |
return prefix + |
|
|
244 | }; | |
|
242 | var originalOption = data.element; | |
|
243 | return prefix + escapeMarkup(data.text); | |
|
244 | };formatSelection: | |
|
245 | 245 | |
|
246 | 246 | // custom code mirror |
|
247 | 247 | var codeMirrorInstance = $('#pullrequest_desc').get(0).MarkupForm.cm; |
|
248 | 248 | |
|
249 | 249 | reviewersController = new ReviewersController(); |
|
250 | 250 | |
|
251 | 251 | var queryTargetRepo = function(self, query) { |
|
252 | 252 | // cache ALL results if query is empty |
|
253 | 253 | var cacheKey = query.term || '__'; |
|
254 | 254 | var cachedData = self.cachedDataSource[cacheKey]; |
|
255 | 255 | |
|
256 | 256 | if (cachedData) { |
|
257 | 257 | query.callback({results: cachedData.results}); |
|
258 | 258 | } else { |
|
259 | 259 | $.ajax({ |
|
260 | 260 | url: pyroutes.url('pullrequest_repo_destinations', {'repo_name': templateContext.repo_name}), |
|
261 | 261 | data: {query: query.term}, |
|
262 | 262 | dataType: 'json', |
|
263 | 263 | type: 'GET', |
|
264 | 264 | success: function(data) { |
|
265 | 265 | self.cachedDataSource[cacheKey] = data; |
|
266 | 266 | query.callback({results: data.results}); |
|
267 | 267 | }, |
|
268 | 268 | error: function(data, textStatus, errorThrown) { |
|
269 | 269 | alert( |
|
270 | 270 | "Error while fetching entries.\nError code {0} ({1}).".format(data.status, data.statusText)); |
|
271 | 271 | } |
|
272 | 272 | }); |
|
273 | 273 | } |
|
274 | 274 | }; |
|
275 | 275 | |
|
276 | 276 | var queryTargetRefs = function(initialData, query) { |
|
277 | 277 | var data = {results: []}; |
|
278 | 278 | // filter initialData |
|
279 | 279 | $.each(initialData, function() { |
|
280 | 280 | var section = this.text; |
|
281 | 281 | var children = []; |
|
282 | 282 | $.each(this.children, function() { |
|
283 | 283 | if (query.term.length === 0 || |
|
284 | 284 | this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0 ) { |
|
285 | 285 | children.push({'id': this.id, 'text': this.text}) |
|
286 | 286 | } |
|
287 | 287 | }); |
|
288 | 288 | data.results.push({'text': section, 'children': children}) |
|
289 | 289 | }); |
|
290 | 290 | query.callback({results: data.results}); |
|
291 | 291 | }; |
|
292 | 292 | |
|
293 | 293 | var loadRepoRefDiffPreview = function() { |
|
294 | 294 | |
|
295 | 295 | var url_data = { |
|
296 | 296 | 'repo_name': targetRepo(), |
|
297 | 297 | 'target_repo': sourceRepo(), |
|
298 | 298 | 'source_ref': targetRef()[2], |
|
299 | 299 | 'source_ref_type': 'rev', |
|
300 | 300 | 'target_ref': sourceRef()[2], |
|
301 | 301 | 'target_ref_type': 'rev', |
|
302 | 302 | 'merge': true, |
|
303 | 303 | '_': Date.now() // bypass browser caching |
|
304 | 304 | }; // gather the source/target ref and repo here |
|
305 | 305 | |
|
306 | 306 | if (sourceRef().length !== 3 || targetRef().length !== 3) { |
|
307 | 307 | prButtonLock(true, "${_('Please select source and target')}"); |
|
308 | 308 | return; |
|
309 | 309 | } |
|
310 | 310 | var url = pyroutes.url('repo_compare', url_data); |
|
311 | 311 | |
|
312 | 312 | // lock PR button, so we cannot send PR before it's calculated |
|
313 | 313 | prButtonLock(true, "${_('Loading compare ...')}", 'compare'); |
|
314 | 314 | |
|
315 | 315 | if (loadRepoRefDiffPreview._currentRequest) { |
|
316 | 316 | loadRepoRefDiffPreview._currentRequest.abort(); |
|
317 | 317 | } |
|
318 | 318 | |
|
319 | 319 | loadRepoRefDiffPreview._currentRequest = $.get(url) |
|
320 | 320 | .error(function(data, textStatus, errorThrown) { |
|
321 | 321 | if (textStatus !== 'abort') { |
|
322 | 322 | alert( |
|
323 | 323 | "Error while processing request.\nError code {0} ({1}).".format( |
|
324 | 324 | data.status, data.statusText)); |
|
325 | 325 | } |
|
326 | 326 | |
|
327 | 327 | }) |
|
328 | 328 | .done(function(data) { |
|
329 | 329 | loadRepoRefDiffPreview._currentRequest = null; |
|
330 | 330 | $('#pull_request_overview').html(data); |
|
331 | 331 | |
|
332 | 332 | var commitElements = $(data).find('tr[commit_id]'); |
|
333 | 333 | |
|
334 | 334 | var prTitleAndDesc = getTitleAndDescription( |
|
335 | 335 | sourceRef()[1], commitElements, 5); |
|
336 | 336 | |
|
337 | 337 | var title = prTitleAndDesc[0]; |
|
338 | 338 | var proposedDescription = prTitleAndDesc[1]; |
|
339 | 339 | |
|
340 | 340 | var useGeneratedTitle = ( |
|
341 | 341 | $('#pullrequest_title').hasClass('autogenerated-title') || |
|
342 | 342 | $('#pullrequest_title').val() === ""); |
|
343 | 343 | |
|
344 | 344 | if (title && useGeneratedTitle) { |
|
345 | 345 | // use generated title if we haven't specified our own |
|
346 | 346 | $('#pullrequest_title').val(title); |
|
347 | 347 | $('#pullrequest_title').addClass('autogenerated-title'); |
|
348 | 348 | |
|
349 | 349 | } |
|
350 | 350 | |
|
351 | 351 | var useGeneratedDescription = ( |
|
352 | 352 | !codeMirrorInstance._userDefinedValue || |
|
353 | 353 | codeMirrorInstance.getValue() === ""); |
|
354 | 354 | |
|
355 | 355 | if (proposedDescription && useGeneratedDescription) { |
|
356 | 356 | // set proposed content, if we haven't defined our own, |
|
357 | 357 | // or we don't have description written |
|
358 | 358 | codeMirrorInstance._userDefinedValue = false; // reset state |
|
359 | 359 | codeMirrorInstance.setValue(proposedDescription); |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | // refresh our codeMirror so events kicks in and it's change aware |
|
363 | 363 | codeMirrorInstance.refresh(); |
|
364 | 364 | |
|
365 | 365 | var msg = ''; |
|
366 | 366 | if (commitElements.length === 1) { |
|
367 | 367 | msg = "${_ungettext('This pull request will consist of __COMMITS__ commit.', 'This pull request will consist of __COMMITS__ commits.', 1)}"; |
|
368 | 368 | } else { |
|
369 | 369 | msg = "${_ungettext('This pull request will consist of __COMMITS__ commit.', 'This pull request will consist of __COMMITS__ commits.', 2)}"; |
|
370 | 370 | } |
|
371 | 371 | |
|
372 | 372 | msg += ' <a id="pull_request_overview_url" href="{0}" target="_blank">${_('Show detailed compare.')}</a>'.format(url); |
|
373 | 373 | |
|
374 | 374 | if (commitElements.length) { |
|
375 | 375 | var commitsLink = '<a href="#pull_request_overview"><strong>{0}</strong></a>'.format(commitElements.length); |
|
376 | 376 | prButtonLock(false, msg.replace('__COMMITS__', commitsLink), 'compare'); |
|
377 | 377 | } |
|
378 | 378 | else { |
|
379 | 379 | prButtonLock(true, "${_('There are no commits to merge.')}", 'compare'); |
|
380 | 380 | } |
|
381 | 381 | |
|
382 | 382 | |
|
383 | 383 | }); |
|
384 | 384 | }; |
|
385 | 385 | |
|
386 | 386 | var Select2Box = function(element, overrides) { |
|
387 | 387 | var globalDefaults = { |
|
388 | 388 | dropdownAutoWidth: true, |
|
389 | 389 | containerCssClass: "drop-menu", |
|
390 | 390 | dropdownCssClass: "drop-menu-dropdown" |
|
391 | 391 | }; |
|
392 | 392 | |
|
393 | 393 | var initSelect2 = function(defaultOptions) { |
|
394 | 394 | var options = jQuery.extend(globalDefaults, defaultOptions, overrides); |
|
395 | 395 | element.select2(options); |
|
396 | 396 | }; |
|
397 | 397 | |
|
398 | 398 | return { |
|
399 | 399 | initRef: function() { |
|
400 | 400 | var defaultOptions = { |
|
401 | 401 | minimumResultsForSearch: 5, |
|
402 | 402 | formatSelection: formatRefSelection |
|
403 | 403 | }; |
|
404 | 404 | |
|
405 | 405 | initSelect2(defaultOptions); |
|
406 | 406 | }, |
|
407 | 407 | |
|
408 | 408 | initRepo: function(defaultValue, readOnly) { |
|
409 | 409 | var defaultOptions = { |
|
410 | 410 | initSelection : function (element, callback) { |
|
411 | 411 | var data = {id: defaultValue, text: defaultValue}; |
|
412 | 412 | callback(data); |
|
413 | 413 | } |
|
414 | 414 | }; |
|
415 | 415 | |
|
416 | 416 | initSelect2(defaultOptions); |
|
417 | 417 | |
|
418 | 418 | element.select2('val', defaultSourceRepo); |
|
419 | 419 | if (readOnly === true) { |
|
420 | 420 | element.select2('readonly', true); |
|
421 | 421 | } |
|
422 | 422 | } |
|
423 | 423 | }; |
|
424 | 424 | }; |
|
425 | 425 | |
|
426 | 426 | var initTargetRefs = function(refsData, selectedRef) { |
|
427 | 427 | |
|
428 | 428 | Select2Box($targetRef, { |
|
429 | 429 | placeholder: "${_('Select commit reference')}", |
|
430 | 430 | query: function(query) { |
|
431 | 431 | queryTargetRefs(refsData, query); |
|
432 | 432 | }, |
|
433 | 433 | initSelection : initRefSelection(selectedRef) |
|
434 | 434 | }).initRef(); |
|
435 | 435 | |
|
436 | 436 | if (!(selectedRef === undefined)) { |
|
437 | 437 | $targetRef.select2('val', selectedRef); |
|
438 | 438 | } |
|
439 | 439 | }; |
|
440 | 440 | |
|
441 | 441 | var targetRepoChanged = function(repoData) { |
|
442 | 442 | // generate new DESC of target repo displayed next to select |
|
443 | 443 | var prLink = pyroutes.url('pullrequest_new', {'repo_name': repoData['name']}); |
|
444 | 444 | $('#target_repo_desc').html( |
|
445 | 445 | "<strong>${_('Target repository')}</strong>: {0}. <a href=\"{1}\">Switch base, and use as source.</a>".format(repoData['description'], prLink) |
|
446 | 446 | ); |
|
447 | 447 | |
|
448 | 448 | // generate dynamic select2 for refs. |
|
449 | 449 | initTargetRefs(repoData['refs']['select2_refs'], |
|
450 | 450 | repoData['refs']['selected_ref']); |
|
451 | 451 | |
|
452 | 452 | }; |
|
453 | 453 | |
|
454 | 454 | var sourceRefSelect2 = Select2Box($sourceRef, { |
|
455 | 455 | placeholder: "${_('Select commit reference')}", |
|
456 | 456 | query: function(query) { |
|
457 | 457 | var initialData = defaultSourceRepoData['refs']['select2_refs']; |
|
458 | 458 | queryTargetRefs(initialData, query) |
|
459 | 459 | }, |
|
460 | 460 | initSelection: initRefSelection() |
|
461 | 461 | } |
|
462 | 462 | ); |
|
463 | 463 | |
|
464 | 464 | var sourceRepoSelect2 = Select2Box($sourceRepo, { |
|
465 | 465 | query: function(query) {} |
|
466 | 466 | }); |
|
467 | 467 | |
|
468 | 468 | var targetRepoSelect2 = Select2Box($targetRepo, { |
|
469 | 469 | cachedDataSource: {}, |
|
470 | 470 | query: $.debounce(250, function(query) { |
|
471 | 471 | queryTargetRepo(this, query); |
|
472 | 472 | }), |
|
473 | 473 | formatResult: formatRepoResult |
|
474 | 474 | }); |
|
475 | 475 | |
|
476 | 476 | sourceRefSelect2.initRef(); |
|
477 | 477 | |
|
478 | 478 | sourceRepoSelect2.initRepo(defaultSourceRepo, true); |
|
479 | 479 | |
|
480 | 480 | targetRepoSelect2.initRepo(defaultTargetRepo, false); |
|
481 | 481 | |
|
482 | 482 | $sourceRef.on('change', function(e){ |
|
483 | 483 | loadRepoRefDiffPreview(); |
|
484 | 484 | reviewersController.loadDefaultReviewers( |
|
485 | 485 | sourceRepo(), sourceRef(), targetRepo(), targetRef()); |
|
486 | 486 | }); |
|
487 | 487 | |
|
488 | 488 | $targetRef.on('change', function(e){ |
|
489 | 489 | loadRepoRefDiffPreview(); |
|
490 | 490 | reviewersController.loadDefaultReviewers( |
|
491 | 491 | sourceRepo(), sourceRef(), targetRepo(), targetRef()); |
|
492 | 492 | }); |
|
493 | 493 | |
|
494 | 494 | $targetRepo.on('change', function(e){ |
|
495 | 495 | var repoName = $(this).val(); |
|
496 | 496 | calculateContainerWidth(); |
|
497 | 497 | $targetRef.select2('destroy'); |
|
498 | 498 | $('#target_ref_loading').show(); |
|
499 | 499 | |
|
500 | 500 | $.ajax({ |
|
501 | 501 | url: pyroutes.url('pullrequest_repo_refs', |
|
502 | 502 | {'repo_name': templateContext.repo_name, 'target_repo_name':repoName}), |
|
503 | 503 | data: {}, |
|
504 | 504 | dataType: 'json', |
|
505 | 505 | type: 'GET', |
|
506 | 506 | success: function(data) { |
|
507 | 507 | $('#target_ref_loading').hide(); |
|
508 | 508 | targetRepoChanged(data); |
|
509 | 509 | loadRepoRefDiffPreview(); |
|
510 | 510 | }, |
|
511 | 511 | error: function(data, textStatus, errorThrown) { |
|
512 | 512 | alert("Error while fetching entries.\nError code {0} ({1}).".format(data.status, data.statusText)); |
|
513 | 513 | } |
|
514 | 514 | }) |
|
515 | 515 | |
|
516 | 516 | }); |
|
517 | 517 | |
|
518 | 518 | $pullRequestForm.on('submit', function(e){ |
|
519 | 519 | // Flush changes into textarea |
|
520 | 520 | codeMirrorInstance.save(); |
|
521 | 521 | prButtonLock(true, null, 'all'); |
|
522 | 522 | }); |
|
523 | 523 | |
|
524 | 524 | prButtonLock(true, "${_('Please select source and target')}", 'all'); |
|
525 | 525 | |
|
526 | 526 | // auto-load on init, the target refs select2 |
|
527 | 527 | calculateContainerWidth(); |
|
528 | 528 | targetRepoChanged(defaultTargetRepoData); |
|
529 | 529 | |
|
530 | 530 | $('#pullrequest_title').on('keyup', function(e){ |
|
531 | 531 | $(this).removeClass('autogenerated-title'); |
|
532 | 532 | }); |
|
533 | 533 | |
|
534 | 534 | % if c.default_source_ref: |
|
535 | 535 | // in case we have a pre-selected value, use it now |
|
536 | 536 | $sourceRef.select2('val', '${c.default_source_ref}'); |
|
537 | 537 | // diff preview load |
|
538 | 538 | loadRepoRefDiffPreview(); |
|
539 | 539 | // default reviewers |
|
540 | 540 | reviewersController.loadDefaultReviewers( |
|
541 | 541 | sourceRepo(), sourceRef(), targetRepo(), targetRef()); |
|
542 | 542 | % endif |
|
543 | 543 | |
|
544 | 544 | ReviewerAutoComplete('#user'); |
|
545 | 545 | }); |
|
546 | 546 | </script> |
|
547 | 547 | |
|
548 | 548 | </%def> |
General Comments 0
You need to be logged in to leave comments.
Login now