gitlab-org--gitlab-foss/app/assets/javascripts/comment_type_toggle.js

72 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-04-07 18:37:12 +00:00
import DropLab from './droplab/drop_lab';
2017-06-07 10:18:35 +00:00
import ISetter from './droplab/plugins/input_setter';
// Todo: Remove this when fixing issue in input_setter plugin
const InputSetter = { ...ISetter };
2017-04-05 15:58:01 +00:00
class CommentTypeToggle {
2017-04-07 13:09:15 +00:00
constructor(opts = {}) {
this.dropdownTrigger = opts.dropdownTrigger;
this.dropdownList = opts.dropdownList;
this.noteTypeInput = opts.noteTypeInput;
this.submitButton = opts.submitButton;
this.closeButton = opts.closeButton;
this.reopenButton = opts.reopenButton;
2017-04-05 15:58:01 +00:00
}
initDroplab() {
this.droplab = new DropLab();
2017-04-07 13:09:15 +00:00
const config = this.setConfig();
this.droplab.init(this.dropdownTrigger, this.dropdownList, [InputSetter], config);
}
setConfig() {
const config = {
2018-10-24 19:17:03 +00:00
InputSetter: [
{
input: this.noteTypeInput,
valueAttribute: 'data-value',
},
{
input: this.submitButton,
valueAttribute: 'data-submit-text',
},
],
2017-04-07 13:09:15 +00:00
};
2017-04-07 14:31:14 +00:00
if (this.closeButton) {
2018-10-24 19:17:03 +00:00
config.InputSetter.push(
{
input: this.closeButton,
valueAttribute: 'data-close-text',
},
{
input: this.closeButton,
valueAttribute: 'data-close-text',
inputAttribute: 'data-alternative-text',
},
);
2017-04-07 14:31:14 +00:00
}
if (this.reopenButton) {
2018-10-24 19:17:03 +00:00
config.InputSetter.push(
{
input: this.reopenButton,
valueAttribute: 'data-reopen-text',
},
{
input: this.reopenButton,
valueAttribute: 'data-reopen-text',
inputAttribute: 'data-alternative-text',
},
);
2017-04-07 14:31:14 +00:00
}
2017-04-07 13:09:15 +00:00
return config;
2017-04-05 15:58:01 +00:00
}
}
export default CommentTypeToggle;