2020-01-13 09:20:26 -05:00
|
|
|
import Controller from "@ember/controller";
|
2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2020-01-13 09:20:26 -05:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2020-08-26 12:57:13 -04:00
|
|
|
import bootbox from "bootbox";
|
2020-01-13 09:20:26 -05:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
|
|
|
|
export default Controller.extend({
|
|
|
|
saving: false,
|
2020-01-23 12:14:58 -05:00
|
|
|
replaceBadgeOwners: false,
|
2020-01-13 09:20:26 -05:00
|
|
|
|
|
|
|
actions: {
|
|
|
|
massAward() {
|
|
|
|
const file = document.querySelector("#massAwardCSVUpload").files[0];
|
|
|
|
|
|
|
|
if (this.model && file) {
|
|
|
|
const options = {
|
|
|
|
type: "POST",
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
data: new FormData(),
|
|
|
|
};
|
|
|
|
|
|
|
|
options.data.append("file", file);
|
2020-01-23 12:14:58 -05:00
|
|
|
options.data.append("replace_badge_owners", this.replaceBadgeOwners);
|
2020-01-13 09:20:26 -05:00
|
|
|
|
|
|
|
this.set("saving", true);
|
|
|
|
|
|
|
|
ajax(`/admin/badges/award/${this.model.id}`, options)
|
|
|
|
.then(() => {
|
|
|
|
bootbox.alert(I18n.t("admin.badges.mass_award.success"));
|
|
|
|
})
|
|
|
|
.catch(popupAjaxError)
|
|
|
|
.finally(() => this.set("saving", false));
|
|
|
|
} else {
|
|
|
|
bootbox.alert(I18n.t("admin.badges.mass_award.aborted"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|