REFACTOR: build-topic-selection mixin (#7635)

This commit is contained in:
Joffrey JAFFEUX 2019-05-29 16:09:19 +02:00 committed by GitHub
parent 468cfa39f7
commit b2fc80e4b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
import { NotificationLevels } from "discourse/lib/notification-levels"; import { NotificationLevels } from "discourse/lib/notification-levels";
import { on } from "ember-addons/ember-computed-decorators";
export default Ember.Mixin.create({ export default Ember.Mixin.create({
bulkSelectEnabled: false, bulkSelectEnabled: false,
@ -6,9 +7,10 @@ export default Ember.Mixin.create({
canBulkSelect: Ember.computed.alias("currentUser.staff"), canBulkSelect: Ember.computed.alias("currentUser.staff"),
resetSelected: function() { @on("init")
resetSelected() {
this.set("selected", []); this.set("selected", []);
}.on("init"), },
actions: { actions: {
toggleBulkSelect() { toggleBulkSelect() {
@ -17,9 +19,6 @@ export default Ember.Mixin.create({
}, },
dismissRead(operationType) { dismissRead(operationType) {
const self = this,
selected = this.selected;
let operation; let operation;
if (operationType === "posts") { if (operationType === "posts") {
operation = { type: "dismiss_posts" }; operation = { type: "dismiss_posts" };
@ -31,8 +30,8 @@ export default Ember.Mixin.create({
} }
let promise; let promise;
if (selected.length > 0) { if (this.selected.length > 0) {
promise = Discourse.Topic.bulkOperation(selected, operation); promise = Discourse.Topic.bulkOperation(this.selected, operation);
} else { } else {
promise = Discourse.Topic.bulkOperationByFilter( promise = Discourse.Topic.bulkOperationByFilter(
"unread", "unread",
@ -40,16 +39,16 @@ export default Ember.Mixin.create({
this.get("category.id") this.get("category.id")
); );
} }
promise.then(function(result) {
promise.then(result => {
if (result && result.topic_ids) { if (result && result.topic_ids) {
const tracker = self.topicTrackingState; const tracker = this.topicTrackingState;
result.topic_ids.forEach(function(t) { result.topic_ids.forEach(t => tracker.removeTopic(t));
tracker.removeTopic(t);
});
tracker.incrementMessageCount(); tracker.incrementMessageCount();
} }
self.send("closeModal");
self.send("refresh"); this.send("closeModal");
this.send("refresh");
}); });
} }
} }