debian-mirror-gitlab/app/assets/javascripts/templates/issuable_template_selector.js

61 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* eslint-disable comma-dangle, max-len, no-useless-return, no-param-reassign, max-len */
/* global Api */
import TemplateSelector from '../blob/template_selector';
2016-09-13 17:45:13 +05:30
((global) => {
2017-08-17 22:00:37 +05:30
class IssuableTemplateSelector extends TemplateSelector {
2016-09-13 17:45:13 +05:30
constructor(...args) {
super(...args);
this.projectPath = this.dropdown.data('project-path');
this.namespacePath = this.dropdown.data('namespace-path');
2017-08-17 22:00:37 +05:30
this.issuableType = this.$dropdownContainer.data('issuable-type');
2016-09-13 17:45:13 +05:30
this.titleInput = $(`#${this.issuableType}_title`);
2017-08-17 22:00:37 +05:30
const initialQuery = {
2016-09-13 17:45:13 +05:30
name: this.dropdown.data('selected')
};
if (initialQuery.name) this.requestFile(initialQuery);
$('.reset-template', this.dropdown.parent()).on('click', () => {
2016-11-03 12:29:30 +05:30
this.setInputValueToTemplateContent();
});
$('.no-template', this.dropdown.parent()).on('click', () => {
2017-08-17 22:00:37 +05:30
this.currentTemplate.content = '';
2016-11-03 12:29:30 +05:30
this.setInputValueToTemplateContent();
$('.dropdown-toggle-text', this.dropdown).text('Choose a template');
2016-09-13 17:45:13 +05:30
});
}
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() {
2017-08-17 22:00:37 +05:30
// `this.setEditorContent` sets the value of the description input field
2016-09-13 17:45:13 +05:30
// to the content of the template selected.
if (this.titleInput.val() === '') {
// If the title has not yet been set, focus the title input and
2016-11-03 12:29:30 +05:30
// skip focusing the description input by setting `true` as the
2017-08-17 22:00:37 +05:30
// `skipFocus` option to `setEditorContent`.
this.setEditorContent(this.currentTemplate, { skipFocus: true });
2016-09-13 17:45:13 +05:30
this.titleInput.focus();
} else {
2017-08-17 22:00:37 +05:30
this.setEditorContent(this.currentTemplate, { skipFocus: false });
2016-09-13 17:45:13 +05:30
}
return;
}
}
global.IssuableTemplateSelector = IssuableTemplateSelector;
2016-11-03 12:29:30 +05:30
})(window.gl || (window.gl = {}));