mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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'],
|
classNames: ['watched-word-form'],
|
||||||
formSubmitted: false,
|
formSubmitted: false,
|
||||||
actionKey: null,
|
actionKey: null,
|
||||||
showSuccessMessage: false,
|
showMessage: false,
|
||||||
|
|
||||||
@computed('regularExpressions')
|
@computed('regularExpressions')
|
||||||
placeholderKey(regularExpressions) {
|
placeholderKey(regularExpressions) {
|
||||||
@ -14,21 +14,33 @@ export default Ember.Component.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
@observes('word')
|
@observes('word')
|
||||||
removeSuccessMessage() {
|
removeMessage() {
|
||||||
if (this.get('showSuccessMessage') && !Ember.isEmpty(this.get('word'))) {
|
if (this.get('showMessage') && !Ember.isEmpty(this.get('word'))) {
|
||||||
this.set('showSuccessMessage', false);
|
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: {
|
actions: {
|
||||||
submit() {
|
submit() {
|
||||||
|
if (!this.get("isUniqueWord")) {
|
||||||
|
this.setProperties({ showMessage: true, message: I18n.t('admin.watched_words.form.exists') });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.get('formSubmitted')) {
|
if (!this.get('formSubmitted')) {
|
||||||
this.set('formSubmitted', true);
|
this.set('formSubmitted', true);
|
||||||
|
|
||||||
const watchedWord = WatchedWord.create({ word: this.get('word'), action: this.get('actionKey') });
|
const watchedWord = WatchedWord.create({ word: this.get('word'), action: this.get('actionKey') });
|
||||||
|
|
||||||
watchedWord.save().then(result => {
|
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));
|
this.sendAction('action', WatchedWord.create(result));
|
||||||
Ember.run.schedule('afterRender', () => this.$('.watched-word-input').focus());
|
Ember.run.schedule('afterRender', () => this.$('.watched-word-input').focus());
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
{{text-field value=word disabled=formSubmitted class="watched-word-input" autocorrect="off" autocapitalize="off" placeholderKey=placeholderKey}}
|
{{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"}}
|
{{d-button action="submit" disabled=formSubmitted label="admin.watched_words.form.add"}}
|
||||||
|
|
||||||
{{#if showSuccessMessage}}
|
{{#if showMessage}}
|
||||||
<span class="success-message">{{i18n 'admin.watched_words.form.success'}}</span>
|
<span class="success-message">{{message}}</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
{{watched-word-form
|
{{watched-word-form
|
||||||
actionKey=actionNameKey
|
actionKey=actionNameKey
|
||||||
action="recordAdded"
|
action="recordAdded"
|
||||||
|
filteredContent=filteredContent
|
||||||
regularExpressions=adminWatchedWords.regularExpressions}}
|
regularExpressions=adminWatchedWords.regularExpressions}}
|
||||||
|
|
||||||
{{watched-word-uploader uploading=uploading actionKey=actionNameKey done="uploadComplete"}}
|
{{watched-word-uploader uploading=uploading actionKey=actionNameKey done="uploadComplete"}}
|
||||||
|
@ -3474,6 +3474,7 @@ en:
|
|||||||
placeholder_regexp: "regular expression"
|
placeholder_regexp: "regular expression"
|
||||||
add: 'Add'
|
add: 'Add'
|
||||||
success: 'Success'
|
success: 'Success'
|
||||||
|
exists: 'Already exists'
|
||||||
upload: "Upload"
|
upload: "Upload"
|
||||||
upload_successful: "Upload successful. Words have been added."
|
upload_successful: "Upload successful. Words have been added."
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user