mirror of
https://github.com/discourse/discourse.git
synced 2025-05-26 11:02:18 +08:00

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.
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import discourseComputed from "discourse-common/utils/decorators";
|
|
import { isEmpty } from "@ember/utils";
|
|
import Controller from "@ember/controller";
|
|
import { extractError } from "discourse/lib/ajax-error";
|
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
export default Controller.extend(ModalFunctionality, {
|
|
loading: false,
|
|
|
|
@discourseComputed("input", "loading", "result")
|
|
disableAddButton(input, loading, result) {
|
|
return loading || isEmpty(input) || input.length <= 0 || result;
|
|
},
|
|
|
|
actions: {
|
|
cancel() {
|
|
this.set("result", null);
|
|
},
|
|
|
|
add() {
|
|
this.setProperties({
|
|
loading: true,
|
|
result: null
|
|
});
|
|
|
|
const users = this.input
|
|
.split("\n")
|
|
.uniq()
|
|
.reject(x => x.length === 0);
|
|
|
|
ajax("/admin/groups/bulk", {
|
|
data: { users, group_id: this.get("model.id") },
|
|
type: "PUT"
|
|
})
|
|
.then(result => {
|
|
this.set("result", result);
|
|
|
|
if (result.users_not_added) {
|
|
this.set("result.invalidUsers", result.users_not_added.join(", "));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
this.flash(extractError(error), "error");
|
|
})
|
|
.finally(() => {
|
|
this.set("loading", false);
|
|
});
|
|
}
|
|
}
|
|
});
|