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