diff options
author | Joseph Frazier <1212jtraceur@gmail.com> | 2016-09-01 07:58:09 -0400 |
---|---|---|
committer | Joseph Frazier <1212jtraceur@gmail.com> | 2016-10-03 12:16:02 -0400 |
commit | ad2b6cae0b299868eba9f8acf76bafe919408ccd (patch) | |
tree | 988c97e3bc4b52a547f25671e59fee56a24f5dae /app/assets | |
parent | a1aea3266e4b90869d5a9bcc334272996ab80fda (diff) | |
download | gitlab-ce-ad2b6cae0b299868eba9f8acf76bafe919408ccd.tar.gz |
Append issue template to existing description
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/21733
Add two newlines before the template if the existing description isn't
empty. This makes it easier to see where the template begins.
Don't append the template when "Reset template" is selected, of course.
Don't append template if it equals the existing description. This makes
it so that selecting a template twice doesn't duplicate it.
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/blob/template_selector.js | 9 | ||||
-rw-r--r-- | app/assets/javascripts/templates/issuable_template_selector.js.es6 | 14 |
2 files changed, 15 insertions, 8 deletions
diff --git a/app/assets/javascripts/blob/template_selector.js b/app/assets/javascripts/blob/template_selector.js index 95352164d76..26852aadea5 100644 --- a/app/assets/javascripts/blob/template_selector.js +++ b/app/assets/javascripts/blob/template_selector.js @@ -72,8 +72,13 @@ // To be implemented on the extending class // e.g. // Api.gitignoreText item.name, @requestFileSuccess.bind(@) - TemplateSelector.prototype.requestFileSuccess = function(file, skipFocus) { - this.editor.setValue(file.content, 1); + TemplateSelector.prototype.requestFileSuccess = function(file, skipFocus, append) { + var oldValue = this.editor.getValue(); + var newValue = file.content; + if (append && oldValue.length && oldValue !== newValue) { + newValue = oldValue + '\n\n' + newValue; + } + this.editor.setValue(newValue, 1); if (!skipFocus) this.editor.focus(); if (this.editor instanceof jQuery) { diff --git a/app/assets/javascripts/templates/issuable_template_selector.js.es6 b/app/assets/javascripts/templates/issuable_template_selector.js.es6 index c32ddf80219..a1ca1c1941c 100644 --- a/app/assets/javascripts/templates/issuable_template_selector.js.es6 +++ b/app/assets/javascripts/templates/issuable_template_selector.js.es6 @@ -16,7 +16,7 @@ if (initialQuery.name) this.requestFile(initialQuery); $('.reset-template', this.dropdown.parent()).on('click', () => { - if (this.currentTemplate) this.setInputValueToTemplateContent(); + if (this.currentTemplate) this.setInputValueToTemplateContent(false); }); } @@ -26,22 +26,24 @@ this.currentTemplate = currentTemplate; if (err) return; // Error handled by global AJAX error handler this.stopLoadingSpinner(); - this.setInputValueToTemplateContent(); + this.setInputValueToTemplateContent(true); }); return; } - setInputValueToTemplateContent() { + setInputValueToTemplateContent(append) { // `this.requestFileSuccess` sets the value of the description input field - // to the content of the template selected. + // to the content of the template selected. If `append` is true, the + // template content will be appended to the previous value of the field, + // separated by a blank line if the previous value is non-empty. if (this.titleInput.val() === '') { // If the title has not yet been set, focus the title input and // skip focusing the description input by setting `true` as the 2nd // argument to `requestFileSuccess`. - this.requestFileSuccess(this.currentTemplate, true); + this.requestFileSuccess(this.currentTemplate, true, append); this.titleInput.focus(); } else { - this.requestFileSuccess(this.currentTemplate); + this.requestFileSuccess(this.currentTemplate, false, append); } return; } |