mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
import { isEmpty } from "@ember/utils";
|
|
import { alias } from "@ember/object/computed";
|
|
import { next } from "@ember/runloop";
|
|
import { inject } from "@ember/controller";
|
|
import Controller from "@ember/controller";
|
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
import DiscourseURL from "discourse/lib/url";
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
export default Controller.extend(ModalFunctionality, {
|
|
topicController: inject("topic"),
|
|
|
|
saving: false,
|
|
new_user: null,
|
|
|
|
selectedPostsCount: alias("topicController.selectedPostsCount"),
|
|
selectedPostsUsername: alias("topicController.selectedPostsUsername"),
|
|
|
|
@computed("saving", "new_user")
|
|
buttonDisabled(saving, newUser) {
|
|
return saving || isEmpty(newUser);
|
|
},
|
|
|
|
@computed("saving")
|
|
buttonTitle(saving) {
|
|
return saving ? I18n.t("saving") : I18n.t("topic.change_owner.action");
|
|
},
|
|
|
|
onShow() {
|
|
this.setProperties({
|
|
saving: false,
|
|
new_user: ""
|
|
});
|
|
},
|
|
|
|
actions: {
|
|
changeOwnershipOfPosts() {
|
|
this.set("saving", true);
|
|
|
|
const options = {
|
|
post_ids: this.get("topicController.selectedPostIds"),
|
|
username: this.new_user
|
|
};
|
|
|
|
Discourse.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;
|
|
}
|
|
}
|
|
});
|