2022-12-13 09:49:39 -05:00
|
|
|
import Component from "@glimmer/component";
|
2023-12-01 10:47:54 -05:00
|
|
|
import { tracked } from "@glimmer/tracking";
|
|
|
|
import { action } from "@ember/object";
|
2022-01-26 09:13:05 -05:00
|
|
|
import getURL from "discourse-common/lib/get-url";
|
2022-12-13 09:49:39 -05:00
|
|
|
import { bind } from "discourse-common/utils/decorators";
|
|
|
|
|
|
|
|
export default class ShareReport extends Component {
|
|
|
|
@tracked visible = false;
|
|
|
|
element;
|
|
|
|
|
|
|
|
get link() {
|
|
|
|
return getURL(`/g/${this.args.group}/reports/${this.args.query.id}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
@bind
|
|
|
|
mouseDownHandler(e) {
|
|
|
|
if (!this.element.contains(e.target)) {
|
|
|
|
this.close();
|
2019-10-28 15:32:09 -04:00
|
|
|
}
|
2022-12-13 09:49:39 -05:00
|
|
|
}
|
2019-10-28 15:32:09 -04:00
|
|
|
|
2022-12-13 09:49:39 -05:00
|
|
|
@bind
|
|
|
|
keyDownHandler(e) {
|
|
|
|
if (e.keyCode === 27) {
|
|
|
|
this.close();
|
2019-10-28 15:32:09 -04:00
|
|
|
}
|
2022-12-13 09:49:39 -05:00
|
|
|
}
|
2019-10-28 15:32:09 -04:00
|
|
|
|
2022-12-13 09:49:39 -05:00
|
|
|
@action
|
|
|
|
registerListeners(element) {
|
|
|
|
if (!element || this.isDestroying || this.isDestroyed) {
|
|
|
|
return;
|
2019-10-28 15:32:09 -04:00
|
|
|
}
|
|
|
|
|
2022-12-13 09:49:39 -05:00
|
|
|
this.element = element;
|
|
|
|
document.addEventListener("mousedown", this.mouseDownHandler);
|
|
|
|
element.addEventListener("keydown", this.keyDownHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
unregisterListeners(element) {
|
|
|
|
this.element = element;
|
|
|
|
document.removeEventListener("mousedown", this.mouseDownHandler);
|
|
|
|
element.removeEventListener("keydown", this.keyDownHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
focusInput(e) {
|
|
|
|
e.select();
|
|
|
|
e.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
open(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
close() {
|
|
|
|
this.visible = false;
|
|
|
|
}
|
|
|
|
}
|