FIX: don't allow duplicate watched words (#5844)
We already have logic in place for server side, this'll just display a little message that says the word already exists
This commit is contained in:
parent
c168639be2
commit
0800098f1a
|
@ -5,7 +5,7 @@ export default Ember.Component.extend({
|
|||
classNames: ['watched-word-form'],
|
||||
formSubmitted: false,
|
||||
actionKey: null,
|
||||
showSuccessMessage: false,
|
||||
showMessage: false,
|
||||
|
||||
@computed('regularExpressions')
|
||||
placeholderKey(regularExpressions) {
|
||||
|
@ -14,21 +14,33 @@ export default Ember.Component.extend({
|
|||
},
|
||||
|
||||
@observes('word')
|
||||
removeSuccessMessage() {
|
||||
if (this.get('showSuccessMessage') && !Ember.isEmpty(this.get('word'))) {
|
||||
this.set('showSuccessMessage', false);
|
||||
removeMessage() {
|
||||
if (this.get('showMessage') && !Ember.isEmpty(this.get('word'))) {
|
||||
this.set('showMessage', false);
|
||||
}
|
||||
},
|
||||
|
||||
@computed('word')
|
||||
isUniqueWord(word) {
|
||||
const words = this.get("filteredContent") || [];
|
||||
const filtered = words.filter(content => content.action === this.get("actionKey"));
|
||||
return filtered.every(content => content.word.toLowerCase() !== word.toLowerCase());
|
||||
},
|
||||
|
||||
actions: {
|
||||
submit() {
|
||||
if (!this.get("isUniqueWord")) {
|
||||
this.setProperties({ showMessage: true, message: I18n.t('admin.watched_words.form.exists') });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.get('formSubmitted')) {
|
||||
this.set('formSubmitted', true);
|
||||
|
||||
const watchedWord = WatchedWord.create({ word: this.get('word'), action: this.get('actionKey') });
|
||||
|
||||
watchedWord.save().then(result => {
|
||||
this.setProperties({ word: '', formSubmitted: false, showSuccessMessage: true });
|
||||
this.setProperties({ word: '', formSubmitted: false, showMessage: true, message: I18n.t('admin.watched_words.form.success') });
|
||||
this.sendAction('action', WatchedWord.create(result));
|
||||
Ember.run.schedule('afterRender', () => this.$('.watched-word-input').focus());
|
||||
}).catch(e => {
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
{{text-field value=word disabled=formSubmitted class="watched-word-input" autocorrect="off" autocapitalize="off" placeholderKey=placeholderKey}}
|
||||
{{d-button action="submit" disabled=formSubmitted label="admin.watched_words.form.add"}}
|
||||
|
||||
{{#if showSuccessMessage}}
|
||||
<span class="success-message">{{i18n 'admin.watched_words.form.success'}}</span>
|
||||
{{#if showMessage}}
|
||||
<span class="success-message">{{message}}</span>
|
||||
{{/if}}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
{{watched-word-form
|
||||
actionKey=actionNameKey
|
||||
action="recordAdded"
|
||||
filteredContent=filteredContent
|
||||
regularExpressions=adminWatchedWords.regularExpressions}}
|
||||
|
||||
{{watched-word-uploader uploading=uploading actionKey=actionNameKey done="uploadComplete"}}
|
||||
|
|
|
@ -3474,6 +3474,7 @@ en:
|
|||
placeholder_regexp: "regular expression"
|
||||
add: 'Add'
|
||||
success: 'Success'
|
||||
exists: 'Already exists'
|
||||
upload: "Upload"
|
||||
upload_successful: "Upload successful. Words have been added."
|
||||
|
||||
|
|
Loading…
Reference in New Issue