Files
discourse/app/assets/javascripts/discourse/controllers/group-bulk-add.js
Jarek Radosz 67b34600d5 DEV: Use type instead of method in ajax calls (#8974)
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.
2020-03-26 21:00:10 +01:00

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);
});
}
}
});