2022-06-17 15:01:34 +02:00
|
|
|
import Component from "@ember/component";
|
|
|
|
|
import discourseComputed, { on } from "discourse-common/utils/decorators";
|
2022-01-26 14:13:05 +00:00
|
|
|
import getURL from "discourse-common/lib/get-url";
|
2022-06-17 07:18:36 -05:00
|
|
|
import { bind } from "@ember/runloop";
|
2019-10-28 14:32:09 -05:00
|
|
|
|
2022-06-17 15:01:34 +02:00
|
|
|
export default Component.extend({
|
2019-10-28 14:32:09 -05:00
|
|
|
classNames: ["share-report"],
|
|
|
|
|
|
|
|
|
|
group: null,
|
|
|
|
|
query: null,
|
|
|
|
|
visible: false,
|
|
|
|
|
|
2022-06-17 15:01:34 +02:00
|
|
|
@discourseComputed("group", "query")
|
2019-10-28 14:32:09 -05:00
|
|
|
link() {
|
2022-01-26 14:13:05 +00:00
|
|
|
return getURL(`/g/${this.group}/reports/${this.query.id}`);
|
2019-10-28 14:32:09 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_mouseDownHandler(event) {
|
|
|
|
|
if (!this.element || this.isDestroying || this.isDestroyed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ($(this.element).has(event.target).length !== 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.send("close");
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_keydownHandler(event) {
|
|
|
|
|
if (!this.element || this.isDestroying || this.isDestroyed) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.keyCode === 27) {
|
|
|
|
|
this.send("close");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
@on("init")
|
|
|
|
|
_setupHandlers() {
|
2022-06-17 07:18:36 -05:00
|
|
|
this._boundMouseDownHandler = bind(this, this._mouseDownHandler);
|
|
|
|
|
this._boundKeydownHandler = bind(this, this._keydownHandler);
|
2019-10-28 14:32:09 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
|
|
$("html")
|
|
|
|
|
.on("mousedown.outside-share-link", this._boundMouseDownHandler)
|
|
|
|
|
.on("keydown.share-view", this._boundKeydownHandler);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
willDestroyElement() {
|
|
|
|
|
this._super(...arguments);
|
|
|
|
|
|
|
|
|
|
$("html")
|
|
|
|
|
.off("mousedown.outside-share-link", this._boundMouseDownHandler)
|
|
|
|
|
.off("keydown.share-view", this._boundKeydownHandler);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
actions: {
|
2019-10-28 16:13:43 -05:00
|
|
|
open() {
|
2019-10-28 14:32:09 -05:00
|
|
|
this.set("visible", true);
|
|
|
|
|
window.setTimeout(
|
2020-09-04 13:23:11 +02:00
|
|
|
() => $(this.element).find("input").select().focus(),
|
2019-10-28 14:32:09 -05:00
|
|
|
160
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
2019-10-28 16:13:43 -05:00
|
|
|
close() {
|
2019-10-28 14:32:09 -05:00
|
|
|
this.set("visible", false);
|
2020-09-04 13:23:11 +02:00
|
|
|
},
|
|
|
|
|
},
|
2019-10-28 14:32:09 -05:00
|
|
|
});
|