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
2019-05-27 10:15:39 +02:00

46 lines
1.1 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.id}?version=${this.version}`,
adapter.getPayload("PUT", { reviewable: updates })
).then(updated => {
updated.payload = Object.assign(
{},
this.payload || {},
updated.payload || {}
);
if (updated.category_id) {
updated.category = Category.findById(updated.category_id);
delete updated.category_id;
}
this.setProperties(updated);
});
}
});