2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2019-03-18 16:09:13 -04:00
|
|
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend(ModalFunctionality, {
|
2019-03-18 16:09:13 -04:00
|
|
|
loading: true,
|
|
|
|
reseeding: false,
|
|
|
|
categories: null,
|
|
|
|
topics: null,
|
|
|
|
|
|
|
|
onShow() {
|
|
|
|
ajax("/admin/customize/reseed")
|
|
|
|
.then(result => {
|
|
|
|
this.setProperties({
|
|
|
|
categories: result.categories,
|
|
|
|
topics: result.topics
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.finally(() => this.set("loading", false));
|
|
|
|
},
|
|
|
|
|
|
|
|
_extractSelectedIds(items) {
|
|
|
|
return items.filter(item => item.selected).map(item => item.id);
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
reseed() {
|
|
|
|
this.set("reseeding", true);
|
|
|
|
ajax("/admin/customize/reseed", {
|
|
|
|
data: {
|
|
|
|
category_ids: this._extractSelectedIds(this.categories),
|
|
|
|
topic_ids: this._extractSelectedIds(this.topics)
|
|
|
|
},
|
2020-03-26 16:00:10 -04:00
|
|
|
type: "POST"
|
2019-03-18 16:09:13 -04:00
|
|
|
})
|
|
|
|
.then(
|
|
|
|
() => this.send("closeModal"),
|
|
|
|
() => bootbox.alert(I18n.t("generic_error"))
|
|
|
|
)
|
|
|
|
.finally(() => this.set("reseeding", false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|