mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 11:48:28 +08:00
d69c5eebcf
* UI: Mass grant a badge from the admin ui * Send the uploaded CSV and badge ID to the backend * Read the CSV and grant badge in batches * UX: Communicate the result to the user * Don't award if badge is disabled * Create a 'send_notification' method to remove duplicated code, slightly shrink badge image. Replace router transition with href. * Dynamically discover current route
36 lines
929 B
JavaScript
36 lines
929 B
JavaScript
import Controller from "@ember/controller";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
export default Controller.extend({
|
|
saving: false,
|
|
|
|
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);
|
|
|
|
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"));
|
|
}
|
|
}
|
|
}
|
|
});
|