Files
discourse-chat-integration/assets/javascripts/admin/controllers/modals/admin-plugins-chat-test.js.es6
T
2017-10-03 18:11:58 +08:00

40 lines
1.0 KiB
JavaScript

import ModalFunctionality from 'discourse/mixins/modal-functionality';
import { ajax } from 'discourse/lib/ajax';
import { default as computed, on } from "ember-addons/ember-computed-decorators";
export default Ember.Controller.extend(ModalFunctionality, {
@on('init')
setupKeydown() {
Ember.run.schedule('afterRender', () => {
$('#chat_integration_test_modal').keydown(e => {
if (e.keyCode === 13) {
this.send('send');
}
});
});
},
@computed('model.topic_id')
sendDisabled(topicId) {
return !topicId;
},
actions: {
send() {
if (this.get('sendDisabled')) return;
this.set('loading', true);
ajax("/admin/plugins/chat/test", {
data: {
channel_id: this.get('model.channel.id'),
topic_id: this.get('model.topic_id')
},
type: 'POST'
}).then(() => {
this.set('loading', false);
this.flash(I18n.t('chat_integration.test_modal.success'), 'success');
}).catch(popupAjaxError);
}
}
});