]> BookStack Code Mirror - bookstack/blob - resources/js/components/user-select.js
Improved user-permissions adding ux
[bookstack] / resources / js / components / user-select.js
1 import {onChildEvent} from "../services/dom";
2 import {Component} from "./component";
3
4 export class UserSelect extends Component {
5
6     setup() {
7         this.container = this.$el;
8         this.input = this.$refs.input;
9         this.userInfoContainer = this.$refs.userInfo;
10
11         this.initialValue = this.input.value;
12         this.initialContent = this.userInfoContainer.innerHTML;
13
14         onChildEvent(this.container, 'a.dropdown-search-item', 'click', this.selectUser.bind(this));
15     }
16
17     selectUser(event, userEl) {
18         event.preventDefault();
19         this.input.value = userEl.getAttribute('data-id');
20         this.userInfoContainer.innerHTML = userEl.innerHTML;
21         this.input.dispatchEvent(new Event('change', {bubbles: true}));
22         this.hide();
23     }
24
25     reset() {
26         this.input.value = this.initialValue;
27         this.userInfoContainer.innerHTML = this.initialContent;
28         this.input.dispatchEvent(new Event('change', {bubbles: true}));
29         this.hide();
30     }
31
32     hide() {
33         /** @var {Dropdown} **/
34         const dropdown = window.$components.firstOnElement(this.container, 'dropdown');
35         dropdown.hide();
36     }
37
38 }