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/app/assets/javascripts/discourse/app/controllers/change-owner.js

66 lines
1.8 KiB
JavaScript

import Controller, { inject as controller } from "@ember/controller";
import DiscourseURL from "discourse/lib/url";
import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import Topic from "discourse/models/topic";
import { alias } from "@ember/object/computed";
import discourseComputed from "discourse-common/utils/decorators";
import { isEmpty } from "@ember/utils";
import { next } from "@ember/runloop";
export default Controller.extend(ModalFunctionality, {
topicController: controller("topic"),
saving: false,
newOwner: null,
selectedPostsCount: alias("topicController.selectedPostsCount"),
selectedPostsUsername: alias("topicController.selectedPostsUsername"),
@discourseComputed("saving", "newOwner")
buttonDisabled(saving, newUser) {
return saving || isEmpty(newUser);
},
onShow() {
this.setProperties({
saving: false,
newOwner: null,
});
},
actions: {
changeOwnershipOfPosts() {
this.set("saving", true);
const options = {
post_ids: this.get("topicController.selectedPostIds"),
username: this.newOwner,
};
Topic.changeOwners(this.get("topicController.model.id"), options).then(
() => {
this.send("closeModal");
this.topicController.send("deselectAll");
if (this.get("topicController.multiSelect")) {
this.topicController.send("toggleMultiSelect");
}
next(() =>
DiscourseURL.routeTo(this.get("topicController.model.url"))
);
},
() => {
this.flash(I18n.t("topic.change_owner.error"), "alert-error");
this.set("saving", false);
}
);
return false;
},
updateNewOwner(selected) {
this.set("newOwner", selected.firstObject);
},
},
});