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

43 lines
1.1 KiB
JavaScript
Raw Normal View History

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";
2020-02-19 11:56:45 -05:00
import { default as 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", () => {
$("#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() {
2018-09-12 16:16:18 +01:00
if (this.get("sendDisabled")) return;
this.set("loading", true);
2017-10-03 18:11:58 +08:00
2017-08-21 16:46:43 +01:00
ajax("/admin/plugins/chat/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"),
topic_id: this.get("model.topic_id")
2017-10-03 17:42:07 +08:00
},
2018-09-12 16:16:18 +01:00
type: "POST"
})
.then(() => {
this.set("loading", false);
this.flash(I18n.t("chat_integration.test_modal.success"), "success");
})
.catch(popupAjaxError);
2017-08-21 16:46:43 +01:00
}
2017-10-03 18:11:58 +08:00
}
2017-10-03 17:42:07 +08:00
});