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-05-29 16:09:19 +02:00

56 lines
1.4 KiB
JavaScript

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