mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
67b34600d5
Even though `type` is an alias for `method`, we have custom logic in `/discourse/lib/ajax` that checks only `type`, and ~200 other ajax calls in the codebase already use `type` param.
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
import { not } from "@ember/object/computed";
|
|
import Controller from "@ember/controller";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
|
import { propertyEqual } from "discourse/lib/computed";
|
|
|
|
export default Controller.extend(bufferedProperty("model"), {
|
|
saved: false,
|
|
isSaving: false,
|
|
saveDisabled: propertyEqual("model.robots_txt", "buffered.robots_txt"),
|
|
resetDisbaled: not("model.overridden"),
|
|
|
|
actions: {
|
|
save() {
|
|
this.setProperties({
|
|
isSaving: true,
|
|
saved: false
|
|
});
|
|
|
|
ajax("robots.json", {
|
|
type: "PUT",
|
|
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
|
|
});
|
|
ajax("robots.json", { type: "DELETE" })
|
|
.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));
|
|
}
|
|
}
|
|
});
|