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