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/models/reviewable.js.es6
Robin Ward 0fc798c2ef UX: Show the score status
If a review review score has been Approved/Rejected/Ignored then show it
2019-04-08 12:08:18 -04:00

46 lines
1.2 KiB
JavaScript

import { ajax } from "discourse/lib/ajax";
import RestModel from "discourse/models/rest";
import computed from "ember-addons/ember-computed-decorators";
import Category from "discourse/models/category";
export const PENDING = 0;
export const APPROVED = 1;
export const REJECTED = 2;
export const IGNORED = 3;
export const DELETED = 4;
export default RestModel.extend({
@computed("type")
humanType(type) {
return I18n.t(`review.types.${type.underscore()}.title`, {
defaultValue: ""
});
},
update(updates) {
// If no changes, do nothing
if (Object.keys(updates).length === 0) {
return Ember.RSVP.resolve();
}
let adapter = this.store.adapterFor("reviewable");
return ajax(
`/review/${this.get("id")}?version=${this.get("version")}`,
adapter.getPayload("PUT", { reviewable: updates })
).then(updated => {
updated.payload = Object.assign(
{},
this.get("payload") || {},
updated.payload || {}
);
if (updated.category_id) {
updated.category = Category.findById(updated.category_id);
delete updated.category_id;
}
this.setProperties(updated);
});
}
});