69e4072f89
* master: (389 commits)
Document "No gems fetched from git repositories" policy [ci skip]
Typos
Small gramatical tweaks
Typos
Added PHP & NPM doc
Use `:empty_project` where possible in request specs
Add caching of droplab ajax requests
Use `:empty_project` where possible in model specs
Revert 3f17f29a
Remove unused js response from refs controller
Add MR id to changelog entry
fixed small mini pipeline graph line glitch
Prevent form to be submitted twice
Fix Error 500 when repositories contain annotated tags pointing to blobs
Fix /explore sorting (trending)
Simplify wording in "adding an image" docs
Remove "official merge window" from CONTRIBUTING.md [ci skip]
Update repository check documentation
Fixed flexbox and wrap issues
Update two_factor_authentication.md
...
60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
/* eslint-disable comma-dangle, max-len, no-useless-return, no-param-reassign, max-len */
|
|
/* global Api */
|
|
|
|
require('../blob/template_selector');
|
|
|
|
((global) => {
|
|
class IssuableTemplateSelector extends gl.TemplateSelector {
|
|
constructor(...args) {
|
|
super(...args);
|
|
this.projectPath = this.dropdown.data('project-path');
|
|
this.namespacePath = this.dropdown.data('namespace-path');
|
|
this.issuableType = this.wrapper.data('issuable-type');
|
|
this.titleInput = $(`#${this.issuableType}_title`);
|
|
|
|
const initialQuery = {
|
|
name: this.dropdown.data('selected')
|
|
};
|
|
|
|
if (initialQuery.name) this.requestFile(initialQuery);
|
|
|
|
$('.reset-template', this.dropdown.parent()).on('click', () => {
|
|
this.setInputValueToTemplateContent();
|
|
});
|
|
|
|
$('.no-template', this.dropdown.parent()).on('click', () => {
|
|
this.currentTemplate.content = '';
|
|
this.setInputValueToTemplateContent();
|
|
$('.dropdown-toggle-text', this.dropdown).text('Choose a template');
|
|
});
|
|
}
|
|
|
|
requestFile(query) {
|
|
this.startLoadingSpinner();
|
|
Api.issueTemplate(this.namespacePath, this.projectPath, query.name, this.issuableType, (err, currentTemplate) => {
|
|
this.currentTemplate = currentTemplate;
|
|
if (err) return; // Error handled by global AJAX error handler
|
|
this.stopLoadingSpinner();
|
|
this.setInputValueToTemplateContent();
|
|
});
|
|
return;
|
|
}
|
|
|
|
setInputValueToTemplateContent() {
|
|
// `this.requestFileSuccess` sets the value of the description input field
|
|
// to the content of the template selected.
|
|
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
|
|
// `skipFocus` option to `requestFileSuccess`.
|
|
this.requestFileSuccess(this.currentTemplate, { skipFocus: true });
|
|
this.titleInput.focus();
|
|
} else {
|
|
this.requestFileSuccess(this.currentTemplate, { skipFocus: false });
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
global.IssuableTemplateSelector = IssuableTemplateSelector;
|
|
})(window.gl || (window.gl = {}));
|