2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2019-07-16 01:47:44 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
2019-10-31 04:28:29 +08:00
|
|
|
import { not } from "@ember/object/computed";
|
2019-07-16 01:47:44 +08:00
|
|
|
import { propertyEqual } from "discourse/lib/computed";
|
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend(bufferedProperty("model"), {
|
2019-07-16 01:47:44 +08:00
|
|
|
saved: false,
|
|
|
|
isSaving: false,
|
|
|
|
saveDisabled: propertyEqual("model.robots_txt", "buffered.robots_txt"),
|
2019-10-31 04:28:29 +08:00
|
|
|
resetDisbaled: not("model.overridden"),
|
2019-07-16 01:47:44 +08:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
save() {
|
|
|
|
this.setProperties({
|
|
|
|
isSaving: true,
|
|
|
|
saved: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
ajax("robots.json", {
|
2020-03-27 04:00:10 +08:00
|
|
|
type: "PUT",
|
2019-07-16 01:47:44 +08:00
|
|
|
data: { robots_txt: this.buffered.get("robots_txt") },
|
|
|
|
})
|
|
|
|
.then((data) => {
|
|
|
|
this.commitBuffer();
|
|
|
|
this.set("saved", true);
|
|
|
|
this.set("model.overridden", data.overridden);
|
|
|
|
})
|
|
|
|
.finally(() => this.set("isSaving", false));
|
|
|
|
},
|
|
|
|
|
|
|
|
reset() {
|
|
|
|
this.setProperties({
|
|
|
|
isSaving: true,
|
|
|
|
saved: false,
|
|
|
|
});
|
2020-03-27 04:00:10 +08:00
|
|
|
ajax("robots.json", { type: "DELETE" })
|
2019-07-16 01:47:44 +08:00
|
|
|
.then((data) => {
|
|
|
|
this.buffered.set("robots_txt", data.robots_txt);
|
|
|
|
this.commitBuffer();
|
|
|
|
this.set("saved", true);
|
|
|
|
this.set("model.overridden", false);
|
|
|
|
})
|
|
|
|
.finally(() => this.set("isSaving", false));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|