This change shows a notification number besides the flag icon in the post menu if there is reviewable content associated with the post. Additionally, if there is pending stuff to review, the icon has a red background. We have also removed the list of links below a post with the flag status. A reviewer is meant to click the number beside the flag icon to view the flags. As a consequence of losing those links, we've removed the ability to undo or ignore flags below a post.
89 lines
2.1 KiB
JavaScript
89 lines
2.1 KiB
JavaScript
import { ajax } from "discourse/lib/ajax";
|
|
import RestModel from "discourse/models/rest";
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
export default RestModel.extend({
|
|
canToggle: Ember.computed.or("can_undo", "can_act"),
|
|
|
|
// Remove it
|
|
removeAction: function() {
|
|
this.setProperties({
|
|
acted: false,
|
|
count: this.get("count") - 1,
|
|
can_act: true,
|
|
can_undo: false
|
|
});
|
|
},
|
|
|
|
togglePromise(post) {
|
|
return this.get("acted") ? this.undo(post) : this.act(post);
|
|
},
|
|
|
|
toggle(post) {
|
|
if (!this.get("acted")) {
|
|
this.act(post);
|
|
return true;
|
|
} else {
|
|
this.undo(post);
|
|
return false;
|
|
}
|
|
},
|
|
|
|
// Perform this action
|
|
act(post, opts) {
|
|
if (!opts) opts = {};
|
|
|
|
// Mark it as acted
|
|
this.setProperties({
|
|
acted: true,
|
|
count: this.get("count") + 1,
|
|
can_act: false,
|
|
can_undo: true
|
|
});
|
|
|
|
// Create our post action
|
|
return ajax("/post_actions", {
|
|
type: "POST",
|
|
data: {
|
|
id: this.get("flagTopic") ? this.get("flagTopic.id") : post.get("id"),
|
|
post_action_type_id: this.get("id"),
|
|
message: opts.message,
|
|
is_warning: opts.isWarning,
|
|
take_action: opts.takeAction,
|
|
flag_topic: this.get("flagTopic") ? true : false
|
|
},
|
|
returnXHR: true
|
|
})
|
|
.then(data => {
|
|
if (!this.get("flagTopic")) {
|
|
post.updateActionsSummary(data.result);
|
|
}
|
|
const remaining = parseInt(
|
|
data.xhr.getResponseHeader("Discourse-Actions-Remaining") || 0
|
|
);
|
|
const max = parseInt(
|
|
data.xhr.getResponseHeader("Discourse-Actions-Max") || 0
|
|
);
|
|
return { acted: true, remaining, max };
|
|
})
|
|
.catch(error => {
|
|
popupAjaxError(error);
|
|
this.removeAction(post);
|
|
});
|
|
},
|
|
|
|
// Undo this action
|
|
undo(post) {
|
|
this.removeAction(post);
|
|
|
|
// Remove our post action
|
|
return ajax("/post_actions/" + post.get("id"), {
|
|
type: "DELETE",
|
|
data: { post_action_type_id: this.get("id") }
|
|
}).then(result => {
|
|
post.updateActionsSummary(result);
|
|
return { acted: false };
|
|
});
|
|
}
|
|
});
|