This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/controllers/review-settings.js
2020-12-01 15:31:26 -03:00

42 lines
1.0 KiB
JavaScript

import Controller from "@ember/controller";
import I18n from "I18n";
import { ajax } from "discourse/lib/ajax";
import discourseComputed from "discourse-common/utils/decorators";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Controller.extend({
saving: false,
saved: false,
actions: {
save() {
let priorities = {};
this.scoreTypes.forEach((st) => {
priorities[st.id] = parseFloat(st.reviewable_priority);
});
this.set("saving", true);
ajax("/review/settings", {
type: "PUT",
data: { reviewable_priorities: priorities },
})
.then(() => {
this.set("saved", true);
})
.catch(popupAjaxError)
.finally(() => this.set("saving", false));
},
},
@discourseComputed("settings.reviewable_score_types")
scoreTypes(types) {
const username = I18n.t("review.example_username");
return types.map((type) =>
Object.assign({}, type, {
title: type.title.replace("%{username}", username),
})
);
},
});