2022-03-06 21:18:46 +01:00
|
|
|
import Controller from "@ember/controller";
|
2023-01-23 10:30:48 -08:00
|
|
|
import { not } from "@ember/object/computed";
|
2020-09-04 13:23:28 +02:00
|
|
|
import I18n from "I18n";
|
2018-09-12 16:16:18 +01:00
|
|
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2023-01-23 10:30:48 -08:00
|
|
|
import { action } from "@ember/object";
|
|
|
|
|
import { tracked } from "@glimmer/tracking";
|
2017-07-04 23:35:45 +01:00
|
|
|
|
2023-01-23 10:30:48 -08:00
|
|
|
export default class AdminPluginsChatIntegrationTest extends Controller.extend(
|
|
|
|
|
ModalFunctionality
|
|
|
|
|
) {
|
|
|
|
|
@tracked loading = false;
|
|
|
|
|
@not("model.topic_id") sendDisabled;
|
2017-07-28 15:09:04 +01:00
|
|
|
|
2023-01-23 10:30:48 -08:00
|
|
|
@action
|
|
|
|
|
handleKeyUp(e) {
|
|
|
|
|
if (e.code === "Enter" && !this.sendDisabled) {
|
|
|
|
|
this.send();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-04 23:35:45 +01:00
|
|
|
|
2023-01-23 10:30:48 -08:00
|
|
|
@action
|
|
|
|
|
send() {
|
|
|
|
|
if (this.sendDisabled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.loading = true;
|
2017-10-03 18:11:58 +08:00
|
|
|
|
2023-01-23 10:30:48 -08:00
|
|
|
ajax("/admin/plugins/chat-integration/test", {
|
|
|
|
|
data: {
|
|
|
|
|
channel_id: this.model.channel.id,
|
|
|
|
|
topic_id: this.model.topic_id,
|
|
|
|
|
},
|
|
|
|
|
type: "POST",
|
|
|
|
|
})
|
|
|
|
|
.then(() => {
|
|
|
|
|
this.loading = false;
|
|
|
|
|
this.flash(I18n.t("chat_integration.test_modal.success"), "success");
|
2018-09-12 16:16:18 +01:00
|
|
|
})
|
2023-01-23 10:30:48 -08:00
|
|
|
.catch(popupAjaxError);
|
|
|
|
|
}
|
|
|
|
|
}
|