discourse/app/assets/javascripts/admin/addon/controllers/admin-email-index.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
1.8 KiB
JavaScript
Raw Normal View History

import Controller from "@ember/controller";
import I18n from "I18n";
2016-06-30 13:55:44 -04:00
import { ajax } from "discourse/lib/ajax";
import { empty } from "@ember/object/computed";
import { observes } from "discourse-common/utils/decorators";
import { inject as service } from "@ember/service";
import { htmlSafe } from "@ember/template";
import { escapeExpression } from "discourse/lib/utilities";
export default Controller.extend({
dialog: service(),
/**
Is the "send test email" button disabled?
@property sendTestEmailDisabled
**/
sendTestEmailDisabled: empty("testEmailAddress"),
/**
Clears the 'sentTestEmail' property on successful send.
@method testEmailAddressChanged
**/
@observes("testEmailAddress")
testEmailAddressChanged() {
this.set("sentTestEmail", false);
},
2013-09-16 14:08:55 -04:00
actions: {
/**
Sends a test email to the currently entered email address
@method sendTestEmail
**/
sendTestEmail() {
this.setProperties({
sendingEmail: true,
sentTestEmail: false,
});
2013-09-16 14:08:55 -04:00
2016-06-30 13:55:44 -04:00
ajax("/admin/email/test", {
2013-09-16 14:08:55 -04:00
type: "POST",
data: { email_address: this.testEmailAddress },
2013-09-16 14:08:55 -04:00
})
.then((response) =>
this.set("sentTestEmailMessage", response.sent_test_email_message)
2018-06-15 11:03:24 -04:00
)
.catch((e) => {
if (e.jqXHR.responseJSON?.errors) {
this.dialog.alert({
message: htmlSafe(
I18n.t("admin.email.error", {
server_error: escapeExpression(
e.jqXHR.responseJSON.errors[0]
),
})
),
});
} else {
this.dialog.alert({ message: I18n.t("admin.email.test_error") });
}
})
.finally(() => this.set("sendingEmail", false));
2013-09-16 14:08:55 -04:00
},
},
});