This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/plugins/chat/assets/javascripts/discourse/controllers/chat-channel-edit-name.js
Martin Brennan 31f6811a93
FIX: Change wording from title -> name in channel about page (#19889)
We refer to the channel name rather than title elsewhere
(including the new channel modal), so we should be consistent.
Title is an internal abstraction, since DM channels cannot have
names (currently).

Also change the name field on channel edit to a input type="text"
rather than a textarea, since we don't want a huge input here.
2023-01-18 09:13:33 +10:00

51 lines
1.2 KiB
JavaScript

import Controller from "@ember/controller";
import { action, computed } from "@ember/object";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { inject as service } from "@ember/service";
export default class ChatChannelEditTitleController extends Controller.extend(
ModalFunctionality
) {
@service chatApi;
editedName = "";
@computed("model.title", "editedName")
get isSaveDisabled() {
return (
this.model.title === this.editedName ||
this.editedName?.length > this.siteSettings.max_topic_title_length
);
}
onShow() {
this.set("editedName", this.model.title || "");
}
onClose() {
this.set("editedName", "");
this.clearFlash();
}
@action
onSaveChatChannelName() {
return this.chatApi
.updateChannel(this.model.id, {
name: this.editedName,
})
.then((result) => {
this.model.set("title", result.channel.title);
this.send("closeModal");
})
.catch((event) => {
if (event.jqXHR?.responseJSON?.errors) {
this.flash(event.jqXHR.responseJSON.errors.join("\n"), "error");
}
});
}
@action
onChangeChatChannelName(title) {
this.clearFlash();
this.set("editedName", title);
}
}