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.

66 lines
1.7 KiB
JavaScript
Raw Normal View History

import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { empty } from "@ember/object/computed";
import Controller from "@ember/controller";
import I18n from "I18n";
2016-07-01 01:55:44 +08:00
import { ajax } from "discourse/lib/ajax";
import { observes } from "@ember-decorators/object";
import { htmlSafe } from "@ember/template";
import { escapeExpression } from "discourse/lib/utilities";
export default class AdminEmailIndexController extends Controller {
@service dialog;
/**
Is the "send test email" button disabled?
@property sendTestEmailDisabled
**/
@empty("testEmailAddress") sendTestEmailDisabled;
/**
Clears the 'sentTestEmail' property on successful send.
@method testEmailAddressChanged
**/
@observes("testEmailAddress")
testEmailAddressChanged() {
this.set("sentTestEmail", false);
}
/**
Sends a test email to the currently entered email address
2013-09-17 02:08:55 +08:00
@method sendTestEmail
**/
@action
sendTestEmail() {
this.setProperties({
sendingEmail: true,
sentTestEmail: false,
});
2013-09-17 02:08:55 +08:00
ajax("/admin/email/test", {
type: "POST",
data: { email_address: this.testEmailAddress },
})
.then((response) =>
this.set("sentTestEmailMessage", response.sent_test_email_message)
)
.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") });
}
2013-09-17 02:08:55 +08:00
})
.finally(() => this.set("sendingEmail", false));
}
}