discourse-subscriptions/assets/javascripts/discourse/routes/user-subscriptions.js.es6

38 lines
980 B
Plaintext
Raw Normal View History

2019-10-31 22:43:09 -04:00
import UserSubscription from "discourse/plugins/discourse-patrons/discourse/models/user-subscription";
2019-10-28 20:43:32 -04:00
export default Discourse.Route.extend({
model() {
2019-10-31 22:43:09 -04:00
return UserSubscription.findAll();
2019-10-28 20:43:32 -04:00
},
setupController(controller, model) {
if (this.currentUser.id !== this.modelFor("user").id) {
this.replaceWith("userActivity");
} else {
controller.setProperties({ model });
}
2019-10-30 19:01:41 -04:00
},
actions: {
cancelSubscription(subscription) {
bootbox.confirm(
2019-10-30 22:31:24 -04:00
I18n.t(
"discourse_patrons.user.subscriptions.operations.destroy.confirm"
),
2019-10-30 19:01:41 -04:00
I18n.t("no_value"),
I18n.t("yes_value"),
confirmed => {
if (confirmed) {
subscription
.destroy()
2019-10-30 22:31:24 -04:00
.then(result => subscription.set("status", result.status))
2019-10-30 19:01:41 -04:00
.catch(data =>
bootbox.alert(data.jqXHR.responseJSON.errors.join("\n"))
);
}
}
);
}
2019-10-28 20:43:32 -04:00
}
});