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