diff --git a/app/assets/javascripts/discourse/app/controllers/rename-tag.js b/app/assets/javascripts/discourse/app/controllers/rename-tag.js index 04dc73c7121..1c5f1d618f0 100644 --- a/app/assets/javascripts/discourse/app/controllers/rename-tag.js +++ b/app/assets/javascripts/discourse/app/controllers/rename-tag.js @@ -1,37 +1,33 @@ +import { action } from "@ember/object"; import BufferedContent from "discourse/mixins/buffered-content"; import Controller from "@ember/controller"; import ModalFunctionality from "discourse/mixins/modal-functionality"; import discourseComputed from "discourse-common/utils/decorators"; import { extractError } from "discourse/lib/ajax-error"; -import { oneWay } from "@ember/object/computed"; export default Controller.extend(ModalFunctionality, BufferedContent, { - tagId: oneWay("model.id"), + newTag: null, - @discourseComputed("tagId", "model.id") - renameDisabled(inputTagName, currentTagName) { + @discourseComputed("newTag", "model.id") + renameDisabled(newTag, currentTag) { const filterRegexp = new RegExp(this.site.tags_filter_regexp, "g"); - const newTagName = inputTagName - ? inputTagName.replace(filterRegexp, "").trim() - : ""; - - return newTagName.length === 0 || newTagName === currentTagName; + newTag = newTag ? newTag.replace(filterRegexp, "").trim() : ""; + return newTag.length === 0 || newTag === currentTag; }, - actions: { - performRename() { - this.model - .update({ id: this.get("tagId") }) - .then((result) => { - this.send("closeModal"); + @action + performRename() { + this.model + .update({ id: this.newTag }) + .then((result) => { + this.send("closeModal"); - if (result.responseJson.tag) { - this.transitionToRoute("tag.show", result.responseJson.tag.id); - } else { - this.flash(extractError(result.responseJson.errors[0]), "error"); - } - }) - .catch((error) => this.flash(extractError(error), "error")); - }, + if (result.responseJson.tag) { + this.transitionToRoute("tag.show", result.responseJson.tag.id); + } else { + this.flash(extractError(result.responseJson.errors[0]), "error"); + } + }) + .catch((error) => this.flash(extractError(error), "error")); }, }); diff --git a/app/assets/javascripts/discourse/app/templates/modal/rename-tag.hbs b/app/assets/javascripts/discourse/app/templates/modal/rename-tag.hbs index ed4b9af204d..0ce71cba7d5 100644 --- a/app/assets/javascripts/discourse/app/templates/modal/rename-tag.hbs +++ b/app/assets/javascripts/discourse/app/templates/modal/rename-tag.hbs @@ -3,13 +3,19 @@ {{i18n "tagging.rename_instructions"}}
- {{input value=tagId maxlength=siteSettings.max_tag_length}} + {{input + value=(readonly model.id) + maxlength=siteSettings.max_tag_length + input=(action (mut newTag) value="target.value") + }}
{{/d-modal-body}}