2019-10-30 16:28:29 -04:00
|
|
|
import { empty, or, notEmpty } from "@ember/object/computed";
|
2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2018-06-15 11:03:24 -04:00
|
|
|
import EmailPreview from "admin/models/email-preview";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2015-11-20 20:27:06 -05:00
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend({
|
2017-06-28 15:36:34 -04:00
|
|
|
username: null,
|
|
|
|
lastSeen: null,
|
2013-06-03 16:12:24 -04:00
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
emailEmpty: empty("email"),
|
|
|
|
sendEmailDisabled: or("emailEmpty", "sendingEmail"),
|
|
|
|
showSendEmailForm: notEmpty("model.html_content"),
|
|
|
|
htmlEmpty: empty("model.html_content"),
|
2016-11-24 15:38:22 -05:00
|
|
|
|
2013-09-16 14:08:55 -04:00
|
|
|
actions: {
|
2015-08-16 05:51:31 -04:00
|
|
|
refresh() {
|
2019-05-27 04:15:39 -04:00
|
|
|
const model = this.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);
|
2017-06-28 15:36:34 -04:00
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
let username = this.username;
|
2017-06-28 15:36:34 -04:00
|
|
|
if (!username) {
|
2018-06-15 11:03:24 -04:00
|
|
|
username = this.currentUser.get("username");
|
|
|
|
this.set("username", username);
|
2017-06-28 15:36:34 -04:00
|
|
|
}
|
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
EmailPreview.findDigest(username, this.lastSeen).then(email => {
|
2018-06-15 11:03:24 -04:00
|
|
|
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");
|
2016-11-23 17:46:57 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
sendEmail() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.set("sendingEmail", true);
|
|
|
|
this.set("sentEmail", false);
|
|
|
|
|
2019-05-27 04:42:53 -04:00
|
|
|
EmailPreview.sendDigest(this.username, this.lastSeen, this.email)
|
2018-06-15 11:03:24 -04:00
|
|
|
.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
|
|
|
}
|
2013-06-03 16:12:24 -04:00
|
|
|
}
|
|
|
|
});
|