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

59 lines
1.6 KiB
Plaintext
Raw Normal View History

import Route from "@ember/routing/route";
2018-06-15 23:03:24 +08:00
import { ajax } from "discourse/lib/ajax";
import Badge from "discourse/models/badge";
import showModal from "discourse/lib/show-modal";
export default Route.extend({
serialize(m) {
2019-01-12 00:54:23 +08:00
return { badge_id: Ember.get(m, "id") || "new" };
},
model(params) {
if (params.badge_id === "new") {
2015-08-19 09:24:09 +08:00
return Badge.create({
2018-06-15 23:03:24 +08:00
name: I18n.t("admin.badges.new_badge")
});
}
2018-06-15 23:03:24 +08:00
return this.modelFor("adminBadges").findBy("id", parseInt(params.badge_id));
},
actions: {
saveError(e) {
let msg = I18n.t("generic_error");
if (e.responseJSON && e.responseJSON.errors) {
2018-06-15 23:03:24 +08:00
msg = I18n.t("generic_error_with_reason", {
error: e.responseJSON.errors.join(". ")
});
}
bootbox.alert(msg);
},
editGroupings() {
2018-06-15 23:03:24 +08:00
const model = this.controllerFor("admin-badges").get("badgeGroupings");
showModal("admin-edit-badge-groupings", { model, admin: true });
},
preview(badge, explain) {
2018-06-15 23:03:24 +08:00
badge.set("preview_loading", true);
ajax("/admin/badges/preview.json", {
method: "post",
data: {
2018-06-15 23:03:24 +08:00
sql: badge.get("query"),
target_posts: !!badge.get("target_posts"),
trigger: badge.get("trigger"),
explain
}
2018-06-15 23:03:24 +08:00
})
.then(function(model) {
badge.set("preview_loading", false);
showModal("admin-badge-preview", { model, admin: true });
})
.catch(function(error) {
badge.set("preview_loading", false);
2019-01-12 00:54:23 +08:00
Ember.Logger.error(error);
2018-06-15 23:03:24 +08:00
bootbox.alert("Network error");
});
}
}
});