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

61 lines
1.5 KiB
Plaintext
Raw Normal View History

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