Fix plugin after I broke it while refactoring.

This commit is contained in:
Guo Xiang Tan 2017-10-03 22:49:19 +08:00
parent 44ade676e1
commit eb6575fd44
7 changed files with 24 additions and 24 deletions

View File

@ -4,11 +4,10 @@ import InputValidation from 'discourse/models/input-validation';
import { default as computed, observes, on } from 'ember-addons/ember-computed-decorators'; import { default as computed, observes, on } from 'ember-addons/ember-computed-decorators';
export default Ember.Controller.extend(ModalFunctionality, { export default Ember.Controller.extend(ModalFunctionality, {
@on('init') @on('init')
setupKeydown() { setupKeydown() {
Ember.run.schedule('afterRender', () => { Ember.run.schedule('afterRender', () => {
$('#chat_integration_edit_channel_modal').keydown(e => { $('#chat-integration-edit-channel-modal').keydown(e => {
if (e.keyCode === 13) { if (e.keyCode === 13) {
this.send('save'); this.send('save');
} }
@ -19,9 +18,9 @@ export default Ember.Controller.extend(ModalFunctionality, {
// 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
@observes('model') @observes('model')
setupValidations() { setupValidations() {
if(this.get('model.provider')){ if (this.get('model.provider')) {
const theKeys = this.get('model.provider.channel_parameters').map( ( param ) => param['key'] ); const theKeys = this.get('model.provider.channel_parameters').map( ( param ) => param['key'] );
Ember.defineProperty(this,'paramValidation', Ember.computed(`model.channel.data.{${theKeys.join(',')}},this._paramValidation`)); Ember.defineProperty(this,'paramValidation', Ember.computed(`model.channel.data.${theKeys.join(',')}`, this._paramValidation));
} }
}, },
@ -74,11 +73,11 @@ export default Ember.Controller.extend(ModalFunctionality, {
let invalid = false; let invalid = false;
Object.keys(paramValidation).forEach(key =>{ Object.keys(paramValidation).forEach(key =>{
if (!validations[key]) { if (!paramValidation[key]) {
invalid = true; invalid = true;
} }
if (!validations[key]['ok']) { if (!paramValidation[key]['ok']) {
invalid = true; invalid = true;
} }
}); });

View File

@ -8,7 +8,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
@on('init') @on('init')
setupKeydown() { setupKeydown() {
Ember.run.schedule('afterRender', () => { Ember.run.schedule('afterRender', () => {
$('#chat_integration_edit_channel_modal').keydown(e => { $('#chat-integration-edit-channel-modal').keydown(e => {
if (e.keyCode === 13) { if (e.keyCode === 13) {
this.send('save'); this.send('save');
} }

View File

@ -1,5 +1,6 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality'; import ModalFunctionality from 'discourse/mixins/modal-functionality';
import { ajax } from 'discourse/lib/ajax'; import { ajax } from 'discourse/lib/ajax';
import { popupAjaxError } from 'discourse/lib/ajax-error';
import { default as computed, on } from "ember-addons/ember-computed-decorators"; import { default as computed, on } from "ember-addons/ember-computed-decorators";
export default Ember.Controller.extend(ModalFunctionality, { export default Ember.Controller.extend(ModalFunctionality, {

View File

@ -1,4 +1,4 @@
{{#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 {{action "save" on="submit"}}> <form {{action "save" on="submit"}}>
<table> <table>

View File

@ -1,4 +1,4 @@
{{!-- {{#d-modal-body id="chat_integration_edit_rule_modal" title="chat_integration.edit_rule_modal.title"}} {{#d-modal-body id="chat-integration-edit-rule_modal" title="chat_integration.edit_rule_modal.title"}}
<div> <div>
<form {{action "save" on="submit"}}> <form {{action "save" on="submit"}}>
<table> <table>
@ -107,4 +107,4 @@
action="cancel" action="cancel"
title="chat_integration.edit_rule_modal.cancel" title="chat_integration.edit_rule_modal.cancel"
label="chat_integration.edit_rule_modal.cancel"}} label="chat_integration.edit_rule_modal.cancel"}}
</div> --}} </div>

View File

@ -50,9 +50,9 @@
} }
} }
#chat_integration_edit_channel_modal, #chat-integration-edit-channel-modal,
#chat_integration_test_modal, #chat_integration_test_modal,
#chat_integration_edit_rule_modal { #chat-integration-edit-rule_modal {
table { table {
width:100%; width:100%;

View File

@ -72,9 +72,9 @@ test("Create channel works", assert => {
}); });
andThen(() => { andThen(() => {
assert.ok(exists('#chat_integration_edit_channel_modal'), 'it displays the modal'); assert.ok(exists('#chat-integration-edit-channel-modal'), 'it displays the modal');
assert.ok(find('#save-channel').prop('disabled'), 'it disables the save button'); assert.ok(find('#save-channel').prop('disabled'), 'it disables the save button');
fillIn('#chat_integration_edit_channel_modal input', '#general'); fillIn('#chat-integration-edit-channel-modal input', '#general');
}); });
andThen(() => { andThen(() => {
@ -86,7 +86,7 @@ test("Create channel works", assert => {
}); });
andThen(() => { andThen(() => {
assert.ok(!exists('#chat_integration_edit_channel_modal'), 'modal closes on save'); assert.ok(!exists('#chat-integration-edit-channel-modal'), 'modal closes on save');
}); });
}); });
@ -99,9 +99,9 @@ test("Edit channel works", assert => {
}); });
andThen(() => { andThen(() => {
assert.ok(exists('#chat_integration_edit_channel_modal'), 'it displays the modal'); assert.ok(exists('#chat-integration-edit-channel-modal'), 'it displays the modal');
assert.ok(!find('#save-channel').prop('disabled'), 'save is enabled'); assert.ok(!find('#save-channel').prop('disabled'), 'save is enabled');
fillIn('#chat_integration_edit_channel_modal input', ' general'); fillIn('#chat-integration-edit-channel-modal input', ' general');
}); });
andThen(() => { andThen(() => {
@ -109,15 +109,15 @@ test("Edit channel works", assert => {
}); });
andThen(() => { andThen(() => {
fillIn('#chat_integration_edit_channel_modal input', '#random'); fillIn('#chat-integration-edit-channel-modal input', '#random');
}); });
andThen(() => { andThen(() => {
$("#chat_integration_edit_channel_modal input").trigger( $.Event( "keydown", { keyCode: 13 } ) ); // Press enter $("#chat-integration-edit-channel-modal input").trigger( $.Event( "keydown", { keyCode: 13 } ) ); // Press enter
}); });
andThen(() => { andThen(() => {
assert.ok(!exists('#chat_integration_edit_channel_modal'), 'modal saves on enter'); assert.ok(!exists('#chat-integration-edit-channel-modal'), 'modal saves on enter');
}); });
}); });
@ -132,14 +132,14 @@ test("Create rule works", assert => {
click('.channel-footer button:first'); click('.channel-footer button:first');
andThen(() => { andThen(() => {
assert.ok(exists('#chat_integration_edit_rule_modal'), 'modal opens on edit'); assert.ok(exists('#chat-integration-edit-rule_modal'), 'modal opens on edit');
assert.ok(find('#save-rule').prop('disabled') === false, 'save is enabled'); assert.ok(find('#save-rule').prop('disabled') === false, 'save is enabled');
}); });
click('#save-rule'); click('#save-rule');
andThen(() => { andThen(() => {
assert.ok(!exists('#chat_integration_edit_rule_modal'), 'modal closes on save'); assert.ok(!exists('#chat-integration-edit-rule_modal'), 'modal closes on save');
}); });
}); });
@ -153,14 +153,14 @@ test("Edit rule works", assert => {
click('.edit:first'); click('.edit:first');
andThen(() => { andThen(() => {
assert.ok(exists('#chat_integration_edit_rule_modal'), 'modal opens on edit'); assert.ok(exists('#chat-integration-edit-rule_modal'), 'modal opens on edit');
assert.ok(find('#save-rule').prop('disabled') === false, 'it enables the save button'); assert.ok(find('#save-rule').prop('disabled') === false, 'it enables the save button');
}); });
click('#save-rule'); click('#save-rule');
andThen(() => { andThen(() => {
assert.ok(!exists('#chat_integration_edit_rule_modal'), 'modal closes on save'); assert.ok(!exists('#chat-integration-edit-rule_modal'), 'modal closes on save');
}); });
}); });