Allow enter key to submit admin modal forms

This commit is contained in:
David Taylor 2017-07-28 15:09:04 +01:00
parent 092f05d566
commit 11c8817ebd
4 changed files with 25 additions and 7 deletions

View File

@ -6,6 +6,16 @@ import InputValidation from 'discourse/models/input-validation';
export default Ember.Controller.extend(ModalFunctionality, { export default Ember.Controller.extend(ModalFunctionality, {
setupKeydown: function() {
Ember.run.schedule('afterRender', () => {
$('#chat_integration_edit_channel_modal').keydown(e => {
if (e.keyCode === 13) {
this.send('save');
}
});
});
}.on('init'),
// The validation property must be defined at runtime since the possible parameters vary by provider // The validation property must be defined at runtime since the possible parameters vary by provider
setupValidations: function(){ setupValidations: function(){
if(this.get('model.provider')){ if(this.get('model.provider')){
@ -79,6 +89,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
}, },
save: function(){ save: function(){
if(this.get('saveDisabled')){return};
const self = this; const self = this;

View File

@ -2,7 +2,17 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality';
import { ajax } from 'discourse/lib/ajax'; import { ajax } from 'discourse/lib/ajax';
export default Ember.Controller.extend(ModalFunctionality, { export default Ember.Controller.extend(ModalFunctionality, {
sendDisabled: function(){ setupKeydown: function() {
Ember.run.schedule('afterRender', () => {
$('#chat_integration_test_modal').keydown(e => {
if (e.keyCode === 13) {
this.send('send');
}
});
});
}.on('init'),
sendDisabled: function(){
if(this.get('model').topic_id){ if(this.get('model').topic_id){
return false return false
} }
@ -12,6 +22,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
actions: { actions: {
send: function(){ send: function(){
if(this.get('sendDisabled')){return};
self = this; self = this;
this.set('loading', true); this.set('loading', true);
ajax("/admin/plugins/chat/test", { ajax("/admin/plugins/chat/test", {

View File

@ -1,6 +1,6 @@
{{#d-modal-body id="chat_integration_edit_channel_modal" title="chat_integration.edit_channel_modal.title"}} {{#d-modal-body id="chat_integration_edit_channel_modal" title="chat_integration.edit_channel_modal.title"}}
<div> <div>
<form> <form {{action "save" on="submit"}}>
<table> <table>
<tr class="input"> <tr class="input">

View File

@ -1,17 +1,13 @@
{{#d-modal-body id="chat_integration_test_modal" title="chat_integration.test_modal.title"}} {{#d-modal-body id="chat_integration_test_modal" title="chat_integration.test_modal.title"}}
<div> <div>
<form> <form {{action "send" on="submit"}}>
<table> <table>
<tr class="input"> <tr class="input">
<td class="label"><label for='channel'>{{i18n "chat_integration.test_modal.topic"}}</label></td> <td class="label"><label for='channel'>{{i18n "chat_integration.test_modal.topic"}}</label></td>
<td> <td>
{{choose-topic selectedTopicId=model.topic_id}} {{choose-topic selectedTopicId=model.topic_id}}
</td> </td>
</tr> </tr>
</table> </table>
</form> </form>
</div> </div>