2017-09-10 17:25:29 +05:30
|
|
|
import DropLab from './droplab/drop_lab';
|
|
|
|
import ISetter from './droplab/plugins/input_setter';
|
|
|
|
|
|
|
|
// Todo: Remove this when fixing issue in input_setter plugin
|
2020-05-24 23:13:21 +05:30
|
|
|
const InputSetter = { ...ISetter };
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
class CloseReopenReportToggle {
|
|
|
|
constructor(opts = {}) {
|
|
|
|
this.dropdownTrigger = opts.dropdownTrigger;
|
|
|
|
this.dropdownList = opts.dropdownList;
|
|
|
|
this.button = opts.button;
|
|
|
|
}
|
|
|
|
|
|
|
|
initDroplab() {
|
|
|
|
this.reopenItem = this.dropdownList.querySelector('.reopen-item');
|
|
|
|
this.closeItem = this.dropdownList.querySelector('.close-item');
|
|
|
|
|
|
|
|
this.droplab = new DropLab();
|
|
|
|
|
|
|
|
const config = this.setConfig();
|
|
|
|
|
|
|
|
this.droplab.init(this.dropdownTrigger, this.dropdownList, [InputSetter], config);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateButton(isClosed) {
|
|
|
|
this.toggleButtonType(isClosed);
|
|
|
|
|
|
|
|
this.button.blur();
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleButtonType(isClosed) {
|
|
|
|
const [showItem, hideItem] = this.getButtonTypes(isClosed);
|
|
|
|
|
|
|
|
showItem.classList.remove('hidden');
|
|
|
|
showItem.classList.add('droplab-item-selected');
|
|
|
|
|
|
|
|
hideItem.classList.add('hidden');
|
|
|
|
hideItem.classList.remove('droplab-item-selected');
|
|
|
|
|
|
|
|
showItem.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
getButtonTypes(isClosed) {
|
|
|
|
return isClosed ? [this.reopenItem, this.closeItem] : [this.closeItem, this.reopenItem];
|
|
|
|
}
|
|
|
|
|
|
|
|
setDisable(shouldDisable = true) {
|
|
|
|
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-07-28 23:09:34 +05:30
|
|
|
inputAttribute: 'data-endpoint',
|
2017-09-10 17:25:29 +05:30
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CloseReopenReportToggle;
|