2023-04-18 17:20:02 -04:00
|
|
|
import {onChildEvent} from '../services/dom';
|
|
|
|
import {Component} from './component';
|
2020-12-31 12:25:20 -05:00
|
|
|
|
2022-11-15 11:04:46 -05:00
|
|
|
export class UserSelect extends Component {
|
2020-12-31 12:25:20 -05:00
|
|
|
|
|
|
|
setup() {
|
2022-11-16 10:46:41 -05:00
|
|
|
this.container = this.$el;
|
2020-12-31 12:25:20 -05:00
|
|
|
this.input = this.$refs.input;
|
|
|
|
this.userInfoContainer = this.$refs.userInfo;
|
|
|
|
|
2022-11-16 10:46:41 -05:00
|
|
|
onChildEvent(this.container, 'a.dropdown-search-item', 'click', this.selectUser.bind(this));
|
2020-12-31 12:25:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
selectUser(event, userEl) {
|
2021-03-21 11:04:32 -04:00
|
|
|
event.preventDefault();
|
2022-11-15 11:04:46 -05:00
|
|
|
this.input.value = userEl.getAttribute('data-id');
|
2020-12-31 12:25:20 -05:00
|
|
|
this.userInfoContainer.innerHTML = userEl.innerHTML;
|
2021-03-21 11:04:32 -04:00
|
|
|
this.input.dispatchEvent(new Event('change', {bubbles: true}));
|
2020-12-31 12:25:20 -05:00
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
|
2022-11-16 10:46:41 -05:00
|
|
|
hide() {
|
2023-04-18 17:20:02 -04:00
|
|
|
/** @var {Dropdown} * */
|
2022-11-16 10:46:41 -05:00
|
|
|
const dropdown = window.$components.firstOnElement(this.container, 'dropdown');
|
|
|
|
dropdown.hide();
|
|
|
|
}
|
|
|
|
|
2023-04-18 17:20:02 -04:00
|
|
|
}
|