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