2019-10-30 16:28:29 -04:00
|
|
|
import { not } from "@ember/object/computed";
|
2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2019-07-15 13:47:44 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
|
|
|
import { propertyEqual } from "discourse/lib/computed";
|
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend(bufferedProperty("model"), {
|
2019-07-15 13:47:44 -04:00
|
|
|
saved: false,
|
|
|
|
isSaving: false,
|
|
|
|
saveDisabled: propertyEqual("model.robots_txt", "buffered.robots_txt"),
|
2019-10-30 16:28:29 -04:00
|
|
|
resetDisbaled: not("model.overridden"),
|
2019-07-15 13:47:44 -04:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
save() {
|
|
|
|
this.setProperties({
|
|
|
|
isSaving: true,
|
|
|
|
saved: false
|
|
|
|
});
|
|
|
|
|
|
|
|
ajax("robots.json", {
|
2020-03-26 16:00:10 -04:00
|
|
|
type: "PUT",
|
2019-07-15 13:47:44 -04: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-26 16:00:10 -04:00
|
|
|
ajax("robots.json", { type: "DELETE" })
|
2019-07-15 13:47:44 -04: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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|