Files
discourse/app/assets/javascripts/discourse/controllers/user-private-messages.js.es6
Joffrey JAFFEUX 0431942f3d DEV: select-kit 2 (#7998)
This new iteration of select-kit focuses on following best principales and disallowing mutations inside select-kit components. A best effort has been made to avoid breaking changes, however if you content was a flat array, eg: ["foo", "bar"] You will need to set valueProperty=null and nameProperty=null on the component.

Also almost every component should have an `onChange` handler now to decide what to do with the updated data. **select-kit will not mutate your data by itself anymore**
2020-02-03 14:22:14 +01:00

79 lines
2.3 KiB
JavaScript

import discourseComputed from "discourse-common/utils/decorators";
import { alias, equal, and } from "@ember/object/computed";
import { inject as service } from "@ember/service";
import { inject } from "@ember/controller";
import Controller from "@ember/controller";
import Topic from "discourse/models/topic";
export default Controller.extend({
router: service(),
userTopicsList: inject("user-topics-list"),
user: inject(),
pmView: false,
viewingSelf: alias("user.viewingSelf"),
isGroup: equal("pmView", "groups"),
currentPath: alias("router._router.currentPath"),
selected: alias("userTopicsList.selected"),
bulkSelectEnabled: alias("userTopicsList.bulkSelectEnabled"),
showToggleBulkSelect: true,
pmTaggingEnabled: alias("site.can_tag_pms"),
tagId: null,
showNewPM: and("user.viewingSelf", "currentUser.can_send_private_messages"),
@discourseComputed("selected.[]", "bulkSelectEnabled")
hasSelection(selected, bulkSelectEnabled) {
return bulkSelectEnabled && selected && selected.length > 0;
},
@discourseComputed("hasSelection", "pmView", "archive")
canMoveToInbox(hasSelection, pmView, archive) {
return hasSelection && (pmView === "archive" || archive);
},
@discourseComputed("hasSelection", "pmView", "archive")
canArchive(hasSelection, pmView, archive) {
return hasSelection && pmView !== "archive" && !archive;
},
bulkOperation(operation) {
const selected = this.selected;
var params = { type: operation };
if (this.isGroup) {
params.group = this.groupFilter;
}
Topic.bulkOperation(selected, params).then(
() => {
const model = this.get("userTopicsList.model");
const topics = model.get("topics");
topics.removeObjects(selected);
selected.clear();
model.loadMore();
},
() => {
bootbox.alert(I18n.t("user.messages.failed_to_move"));
}
);
},
actions: {
changeGroupNotificationLevel(notificationLevel) {
this.group.setNotification(notificationLevel, this.get("user.id"));
},
archive() {
this.bulkOperation("archive_messages");
},
toInbox() {
this.bulkOperation("move_messages_to_inbox");
},
toggleBulkSelect() {
this.toggleProperty("bulkSelectEnabled");
},
selectAll() {
$("input.bulk-select:not(checked)").click();
}
}
});