discourse/app/assets/javascripts/admin/addon/routes/admin-badges-show.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
1.8 KiB
JavaScript
Raw Normal View History

2015-08-18 21:24:09 -04:00
import Badge from "discourse/models/badge";
import I18n from "I18n";
import Route from "@ember/routing/route";
2016-06-30 13:55:44 -04:00
import { ajax } from "discourse/lib/ajax";
import bootbox from "bootbox";
2019-10-31 16:28:10 -04:00
import { get } from "@ember/object";
import showModal from "discourse/lib/show-modal";
export default Route.extend({
serialize(m) {
2019-10-31 16:28:10 -04:00
return { badge_id: get(m, "id") || "new" };
},
model(params) {
if (params.badge_id === "new") {
2015-08-18 21:24:09 -04:00
return Badge.create({
name: I18n.t("admin.badges.new_badge"),
});
}
2019-11-12 05:49:31 -05:00
return this.modelFor("adminBadges").findBy(
"id",
parseInt(params.badge_id, 10)
);
},
actions: {
saveError(e) {
let msg = I18n.t("generic_error");
if (e.responseJSON && e.responseJSON.errors) {
msg = I18n.t("generic_error_with_reason", {
error: e.responseJSON.errors.join(". "),
});
}
bootbox.alert(msg);
},
editGroupings() {
const model = this.controllerFor("admin-badges").get("badgeGroupings");
2016-11-15 17:09:55 -05:00
showModal("admin-edit-badge-groupings", { model, admin: true });
},
preview(badge, explain) {
badge.set("preview_loading", true);
2016-06-30 13:55:44 -04:00
ajax("/admin/badges/preview.json", {
type: "POST",
data: {
sql: badge.get("query"),
target_posts: !!badge.get("target_posts"),
trigger: badge.get("trigger"),
explain,
},
})
.then(function (model) {
badge.set("preview_loading", false);
2016-11-15 17:09:55 -05:00
showModal("admin-badge-preview", { model, admin: true });
})
.catch(function (error) {
badge.set("preview_loading", false);
// eslint-disable-next-line no-console
console.error(error);
bootbox.alert("Network error");
});
},
},
});