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

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

65 lines
1.7 KiB
JavaScript
Raw Normal View History

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