]> BookStack Code Mirror - bookstack/blob - resources/assets/js/components/entity-selector-popup.js
Added support for Pascal language
[bookstack] / resources / assets / js / components / entity-selector-popup.js
1
2 class EntitySelectorPopup {
3
4     constructor(elem) {
5         this.elem = elem;
6         window.EntitySelectorPopup = this;
7
8         this.callback = null;
9         this.selection = null;
10
11         this.selectButton = elem.querySelector('.entity-link-selector-confirm');
12         this.selectButton.addEventListener('click', this.onSelectButtonClick.bind(this));
13
14         window.$events.listen('entity-select-change', this.onSelectionChange.bind(this));
15         window.$events.listen('entity-select-confirm', this.onSelectionConfirm.bind(this));
16     }
17
18     show(callback) {
19         this.callback = callback;
20         this.elem.components.overlay.show();
21     }
22
23     hide() {
24         this.elem.components.overlay.hide();
25     }
26
27     onSelectButtonClick() {
28         this.hide();
29         if (this.selection !== null && this.callback) this.callback(this.selection);
30     }
31
32     onSelectionConfirm(entity) {
33         this.hide();
34         if (this.callback && entity) this.callback(entity);
35     }
36
37     onSelectionChange(entity) {
38         this.selection = entity;
39         if (entity === null) {
40             this.selectButton.setAttribute('disabled', 'true');
41         } else {
42             this.selectButton.removeAttribute('disabled');
43         }
44     }
45 }
46
47 export default EntitySelectorPopup;