2017-06-08 12:15:34 -04:00
|
|
|
import DropLab from './droplab/drop_lab';
|
2017-06-07 06:18:35 -04:00
|
|
|
import ISetter from './droplab/plugins/input_setter';
|
|
|
|
|
|
|
|
// Todo: Remove this when fixing issue in input_setter plugin
|
2020-05-07 17:09:26 -04:00
|
|
|
const InputSetter = { ...ISetter };
|
2017-06-07 06:18:35 -04:00
|
|
|
|
|
|
|
class CloseReopenReportToggle {
|
|
|
|
constructor(opts = {}) {
|
|
|
|
this.dropdownTrigger = opts.dropdownTrigger;
|
|
|
|
this.dropdownList = opts.dropdownList;
|
|
|
|
this.button = opts.button;
|
2017-06-07 15:34:19 -04:00
|
|
|
}
|
2017-06-07 06:18:35 -04:00
|
|
|
|
2017-06-07 15:34:19 -04:00
|
|
|
initDroplab() {
|
2017-06-07 06:18:35 -04:00
|
|
|
this.reopenItem = this.dropdownList.querySelector('.reopen-item');
|
|
|
|
this.closeItem = this.dropdownList.querySelector('.close-item');
|
|
|
|
|
2017-06-08 12:15:34 -04:00
|
|
|
this.droplab = new DropLab();
|
2017-06-07 06:18:35 -04:00
|
|
|
|
|
|
|
const config = this.setConfig();
|
|
|
|
|
|
|
|
this.droplab.init(this.dropdownTrigger, this.dropdownList, [InputSetter], config);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateButton(isClosed) {
|
2017-06-07 09:17:03 -04:00
|
|
|
this.toggleButtonType(isClosed);
|
2017-06-07 06:18:35 -04:00
|
|
|
|
|
|
|
this.button.blur();
|
|
|
|
}
|
|
|
|
|
2017-06-07 09:17:03 -04:00
|
|
|
toggleButtonType(isClosed) {
|
|
|
|
const [showItem, hideItem] = this.getButtonTypes(isClosed);
|
2017-06-07 06:18:35 -04:00
|
|
|
|
2017-06-07 09:17:03 -04:00
|
|
|
showItem.classList.remove('hidden');
|
|
|
|
showItem.classList.add('droplab-item-selected');
|
2017-06-07 06:18:35 -04:00
|
|
|
|
2017-06-07 09:17:03 -04:00
|
|
|
hideItem.classList.add('hidden');
|
|
|
|
hideItem.classList.remove('droplab-item-selected');
|
2017-06-07 06:18:35 -04:00
|
|
|
|
2017-06-07 09:17:03 -04:00
|
|
|
showItem.click();
|
|
|
|
}
|
2017-06-07 06:18:35 -04:00
|
|
|
|
2017-06-07 09:17:03 -04:00
|
|
|
getButtonTypes(isClosed) {
|
|
|
|
return isClosed ? [this.reopenItem, this.closeItem] : [this.closeItem, this.reopenItem];
|
2017-06-07 06:18:35 -04:00
|
|
|
}
|
|
|
|
|
2017-07-04 09:41:26 -04:00
|
|
|
setDisable(shouldDisable = true) {
|
2017-06-07 06:18:35 -04:00
|
|
|
if (shouldDisable) {
|
|
|
|
this.button.setAttribute('disabled', 'true');
|
|
|
|
this.dropdownTrigger.setAttribute('disabled', 'true');
|
|
|
|
} else {
|
|
|
|
this.button.removeAttribute('disabled');
|
|
|
|
this.dropdownTrigger.removeAttribute('disabled');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setConfig() {
|
|
|
|
const config = {
|
|
|
|
InputSetter: [
|
|
|
|
{
|
|
|
|
input: this.button,
|
|
|
|
valueAttribute: 'data-text',
|
|
|
|
inputAttribute: 'data-value',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: this.button,
|
|
|
|
valueAttribute: 'data-text',
|
|
|
|
inputAttribute: 'title',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: this.button,
|
|
|
|
valueAttribute: 'data-button-class',
|
|
|
|
inputAttribute: 'class',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: this.dropdownTrigger,
|
|
|
|
valueAttribute: 'data-toggle-class',
|
|
|
|
inputAttribute: 'class',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: this.button,
|
|
|
|
valueAttribute: 'data-url',
|
2020-06-23 05:08:47 -04:00
|
|
|
inputAttribute: 'data-endpoint',
|
2017-06-07 06:18:35 -04:00
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CloseReopenReportToggle;
|