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/controllers/ignore-duration-with-username.js.es6
2019-05-27 10:15:39 +02:00

32 lines
956 B
JavaScript

import ModalFunctionality from "discourse/mixins/modal-functionality";
import { popupAjaxError } from "discourse/lib/ajax-error";
import User from "discourse/models/user";
export default Ember.Controller.extend(ModalFunctionality, {
loading: false,
ignoredUntil: null,
ignoredUsername: null,
actions: {
ignore() {
if (!this.ignoredUntil || !this.ignoredUsername) {
this.flash(
I18n.t("user.user_notifications.ignore_duration_time_frame_required"),
"alert-error"
);
return;
}
this.set("loading", true);
User.findByUsername(this.ignoredUsername).then(user => {
user
.updateNotificationLevel("ignore", this.ignoredUntil)
.then(() => {
this.onUserIgnored(this.ignoredUsername);
this.send("closeModal");
})
.catch(popupAjaxError)
.finally(() => this.set("loading", false));
});
}
}
});