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

61 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-04-07 18:37:12 +00:00
import DropLab from './droplab/drop_lab';
import InputSetter from './droplab/plugins/input_setter';
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 = {
InputSetter: [{
input: this.noteTypeInput,
valueAttribute: 'data-value',
},
{
input: this.submitButton,
valueAttribute: 'data-submit-text',
}],
};
2017-04-07 14:31:14 +00:00
if (this.closeButton) {
config.InputSetter.push({
input: this.closeButton,
valueAttribute: 'data-close-text',
}, {
input: this.closeButton,
valueAttribute: 'data-close-text',
inputAttribute: 'data-alternative-text',
});
}
if (this.reopenButton) {
config.InputSetter.push({
input: this.reopenButton,
valueAttribute: 'data-reopen-text',
}, {
input: this.reopenButton,
valueAttribute: 'data-reopen-text',
inputAttribute: 'data-alternative-text',
});
}
2017-04-07 13:09:15 +00:00
return config;
2017-04-05 15:58:01 +00:00
}
}
export default CommentTypeToggle;