discourse/app/assets/javascripts/admin/controllers/admin-email-preview-digest.js

Failed to ignore revisions in .git-blame-ignore-revs.

59 lines
1.5 KiB
JavaScript
Raw Normal View History

import { empty, or, notEmpty } from "@ember/object/computed";
import Controller from "@ember/controller";
2018-06-15 23:03:24 +08:00
import EmailPreview from "admin/models/email-preview";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Controller.extend({
username: null,
lastSeen: null,
emailEmpty: empty("email"),
sendEmailDisabled: or("emailEmpty", "sendingEmail"),
showSendEmailForm: notEmpty("model.html_content"),
htmlEmpty: empty("model.html_content"),
2013-09-17 02:08:55 +08:00
actions: {
2015-08-16 17:51:31 +08:00
refresh() {
const model = this.model;
2013-09-17 02:08:55 +08:00
2018-06-15 23:03:24 +08:00
this.set("loading", true);
this.set("sentEmail", false);
let username = this.username;
if (!username) {
2018-06-15 23:03:24 +08:00
username = this.currentUser.get("username");
this.set("username", username);
}
EmailPreview.findDigest(username, this.lastSeen).then(email => {
2018-06-15 23:03:24 +08:00
model.setProperties(
email.getProperties("html_content", "text_content")
);
this.set("loading", false);
2013-09-17 02:08:55 +08:00
});
},
2015-08-16 17:51:31 +08:00
toggleShowHtml() {
2018-06-15 23:03:24 +08:00
this.toggleProperty("showHtml");
},
sendEmail() {
2018-06-15 23:03:24 +08:00
this.set("sendingEmail", true);
this.set("sentEmail", false);
EmailPreview.sendDigest(this.username, this.lastSeen, this.email)
2018-06-15 23:03:24 +08:00
.then(result => {
if (result.errors) {
bootbox.alert(result.errors);
} else {
this.set("sentEmail", true);
}
})
.catch(popupAjaxError)
.finally(() => {
this.set("sendingEmail", false);
});
2013-09-17 02:08:55 +08:00
}
}
});