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

65 lines
2 KiB
JavaScript
Raw Normal View History

2018-12-13 13:39:08 +05:30
/* eslint-disable no-useless-return */
2017-08-17 22:00:37 +05:30
2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-17 18:26:18 +05:30
import Api from '../api';
2017-08-17 22:00:37 +05:30
import TemplateSelector from '../blob/template_selector';
2019-07-31 22:56:46 +05:30
import { __ } from '~/locale';
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
export default class IssuableTemplateSelector extends TemplateSelector {
constructor(...args) {
super(...args);
2018-03-27 19:54:05 +05:30
this.projectPath = this.dropdown.data('projectPath');
this.namespacePath = this.dropdown.data('namespacePath');
this.issuableType = this.$dropdownContainer.data('issuableType');
2018-03-17 18:26:18 +05:30
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();
2019-07-31 22:56:46 +05:30
$('.dropdown-toggle-text', this.dropdown).text(__('Choose a template'));
2018-03-17 18:26:18 +05:30
});
}
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
requestFile(query) {
this.startLoadingSpinner();
2018-12-13 13:39:08 +05:30
Api.issueTemplate(
this.namespacePath,
this.projectPath,
query.name,
this.issuableType,
(err, currentTemplate) => {
this.currentTemplate = currentTemplate;
this.stopLoadingSpinner();
if (err) return; // Error handled by global AJAX error handler
this.setInputValueToTemplateContent();
},
);
2018-03-17 18:26:18 +05:30
return;
}
2016-09-13 17:45:13 +05:30
2018-03-17 18:26:18 +05:30
setInputValueToTemplateContent() {
// `this.setEditorContent` 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 `setEditorContent`.
this.setEditorContent(this.currentTemplate, { skipFocus: true });
this.titleInput.focus();
} else {
this.setEditorContent(this.currentTemplate, { skipFocus: false });
2016-09-13 17:45:13 +05:30
}
2018-03-17 18:26:18 +05:30
return;
2016-09-13 17:45:13 +05:30
}
2018-03-17 18:26:18 +05:30
}