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

41 lines
1.1 KiB
JavaScript
Raw Normal View History

import ModalFunctionality from 'discourse/mixins/modal-functionality';
import { ajax } from 'discourse/lib/ajax';
import { popupAjaxError } from 'discourse/lib/ajax-error';
2017-10-03 18:11:58 +08:00
import { default as computed, on } from "ember-addons/ember-computed-decorators";
export default Ember.Controller.extend(ModalFunctionality, {
2017-10-03 18:11:58 +08:00
@on('init')
2017-10-03 17:42:07 +08:00
setupKeydown() {
2017-07-28 15:09:04 +01:00
Ember.run.schedule('afterRender', () => {
$('#chat_integration_test_modal').keydown(e => {
if (e.keyCode === 13) {
this.send('send');
}
});
});
2017-10-03 18:11:58 +08:00
},
2017-07-28 15:09:04 +01:00
2017-10-03 17:42:07 +08:00
@computed('model.topic_id')
sendDisabled(topicId) {
return !topicId;
},
2017-08-21 16:46:43 +01:00
actions: {
2017-10-03 17:42:07 +08:00
send() {
if (this.get('sendDisabled')) return;
2017-08-21 16:46:43 +01:00
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: {
channel_id: this.get('model.channel.id'),
topic_id: this.get('model.topic_id')
},
type: 'POST'
2017-10-03 17:42:07 +08:00
}).then(() => {
this.set('loading', false);
this.flash(I18n.t('chat_integration.test_modal.success'), 'success');
2017-10-03 18:11:58 +08:00
}).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
});