Files
discourse-chat-integration/assets/javascripts/admin/controllers/modals/admin-plugins-chat-integration-test.js
T

46 lines
1.1 KiB
JavaScript
Raw Normal View History

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";
import computed, { on } from "discourse-common/utils/decorators";
export default Ember.Controller.extend(ModalFunctionality, {
2018-09-12 16:16:18 +01:00
@on("init")
2017-10-03 17:42:07 +08:00
setupKeydown() {
2018-09-12 16:16:18 +01:00
Ember.run.schedule("afterRender", () => {
2020-09-04 13:23:28 +02:00
$("#chat_integration_test_modal").keydown((e) => {
2017-07-28 15:09:04 +01:00
if (e.keyCode === 13) {
2018-09-12 16:16:18 +01:00
this.send("send");
2017-07-28 15:09:04 +01:00
}
});
});
2017-10-03 18:11:58 +08:00
},
2017-07-28 15:09:04 +01:00
2018-09-12 16:16:18 +01:00
@computed("model.topic_id")
2017-10-03 17:42:07 +08:00
sendDisabled(topicId) {
return !topicId;
},
2017-08-21 16:46:43 +01:00
actions: {
2017-10-03 17:42:07 +08:00
send() {
2020-09-22 17:11:12 +02:00
if (this.get("sendDisabled")) {
return;
}
2018-09-12 16:16:18 +01:00
this.set("loading", true);
2017-10-03 18:11:58 +08:00
2021-08-26 08:52:53 -05:00
ajax("/admin/plugins/chat-integration/test", {
2017-10-03 17:42:07 +08:00
data: {
2018-09-12 16:16:18 +01:00
channel_id: this.get("model.channel.id"),
2020-09-04 13:23:28 +02:00
topic_id: this.get("model.topic_id"),
2017-10-03 17:42:07 +08:00
},
2020-09-04 13:23:28 +02:00
type: "POST",
2018-09-12 16:16:18 +01:00
})
.then(() => {
this.set("loading", false);
this.flash(I18n.t("chat_integration.test_modal.success"), "success");
})
.catch(popupAjaxError);
2020-09-04 13:23:28 +02:00
},
},
2017-10-03 17:42:07 +08:00
});