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/mixins/bulk-topic-selection.js.es6
2019-01-11 17:54:23 +01:00

57 lines
1.4 KiB
JavaScript

import { NotificationLevels } from "discourse/lib/notification-levels";
export default Ember.Mixin.create({
bulkSelectEnabled: false,
selected: null,
canBulkSelect: Ember.computed.alias("currentUser.staff"),
resetSelected: function() {
this.set("selected", []);
}.on("init"),
actions: {
toggleBulkSelect() {
this.toggleProperty("bulkSelectEnabled");
this.get("selected").clear();
},
dismissRead(operationType) {
const self = this,
selected = this.get("selected");
let operation;
if (operationType === "posts") {
operation = { type: "dismiss_posts" };
} else {
operation = {
type: "change_notification_level",
notification_level_id: NotificationLevels.REGULAR
};
}
let promise;
if (selected.length > 0) {
promise = Discourse.Topic.bulkOperation(selected, operation);
} else {
promise = Discourse.Topic.bulkOperationByFilter(
"unread",
operation,
this.get("category.id")
);
}
promise.then(function(result) {
if (result && result.topic_ids) {
const tracker = self.topicTrackingState;
result.topic_ids.forEach(function(t) {
tracker.removeTopic(t);
});
tracker.incrementMessageCount();
}
self.send("closeModal");
self.send("refresh");
});
}
}
});