X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/58fa7679bccafd00f9a50bcd4a87e96876331b03..refs/pull/3908/head:/resources/js/components/user-select.js diff --git a/resources/js/components/user-select.js b/resources/js/components/user-select.js index c2c1f97c3..b383d7a6f 100644 --- a/resources/js/components/user-select.js +++ b/resources/js/components/user-select.js @@ -1,26 +1,38 @@ import {onChildEvent} from "../services/dom"; +import {Component} from "./component"; -class UserSelect { +export class UserSelect extends Component { setup() { - + this.container = this.$el; this.input = this.$refs.input; this.userInfoContainer = this.$refs.userInfo; - this.hide = this.$el.components.dropdown.hide; + this.initialValue = this.input.value; + this.initialContent = this.userInfoContainer.innerHTML; - onChildEvent(this.$el, 'a.dropdown-search-item', 'click', this.selectUser.bind(this)); + onChildEvent(this.container, 'a.dropdown-search-item', 'click', this.selectUser.bind(this)); } selectUser(event, userEl) { event.preventDefault(); - const id = userEl.getAttribute('data-id'); - this.input.value = id; + this.input.value = userEl.getAttribute('data-id'); this.userInfoContainer.innerHTML = userEl.innerHTML; this.input.dispatchEvent(new Event('change', {bubbles: true})); this.hide(); } -} + reset() { + this.input.value = this.initialValue; + this.userInfoContainer.innerHTML = this.initialContent; + this.input.dispatchEvent(new Event('change', {bubbles: true})); + this.hide(); + } + + hide() { + /** @var {Dropdown} **/ + const dropdown = window.$components.firstOnElement(this.container, 'dropdown'); + dropdown.hide(); + } -export default UserSelect; \ No newline at end of file +} \ No newline at end of file