2019-10-31 04:28:29 +08:00
|
|
|
import { empty, notEmpty, or } from "@ember/object/computed";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2015-11-21 09:27:06 +08:00
|
|
|
import EmailPreview from "admin/models/email-preview";
|
2020-08-27 00:57:13 +08:00
|
|
|
import bootbox from "bootbox";
|
2016-11-24 06:46:57 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2015-11-21 09:27:06 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2017-06-29 03:36:34 +08:00
|
|
|
username: null,
|
|
|
|
lastSeen: null,
|
2013-06-04 04:12:24 +08:00
|
|
|
|
2019-10-31 04:28:29 +08:00
|
|
|
emailEmpty: empty("email"),
|
|
|
|
sendEmailDisabled: or("emailEmpty", "sendingEmail"),
|
|
|
|
showSendEmailForm: notEmpty("model.html_content"),
|
|
|
|
htmlEmpty: empty("model.html_content"),
|
2016-11-25 04:38:22 +08:00
|
|
|
|
2013-09-17 02:08:55 +08:00
|
|
|
actions: {
|
2015-08-16 17:51:31 +08:00
|
|
|
refresh() {
|
2019-05-27 16:15:39 +08:00
|
|
|
const model = this.model;
|
2013-09-17 02:08:55 +08:00
|
|
|
|
2015-08-16 18:01:04 +08:00
|
|
|
this.set("loading", true);
|
2016-11-25 04:05:33 +08:00
|
|
|
this.set("sentEmail", false);
|
2017-06-29 03:36:34 +08:00
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
let username = this.username;
|
2017-06-29 03:36:34 +08:00
|
|
|
if (!username) {
|
|
|
|
username = this.currentUser.get("username");
|
|
|
|
this.set("username", username);
|
|
|
|
}
|
|
|
|
|
2019-05-27 16:15:39 +08:00
|
|
|
EmailPreview.findDigest(username, this.lastSeen).then((email) => {
|
2013-09-17 02:08:55 +08:00
|
|
|
model.setProperties(
|
|
|
|
email.getProperties("html_content", "text_content")
|
|
|
|
);
|
2015-08-16 17:51:31 +08:00
|
|
|
this.set("loading", false);
|
2013-09-17 02:08:55 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-08-16 17:51:31 +08:00
|
|
|
toggleShowHtml() {
|
2013-09-17 02:08:55 +08:00
|
|
|
this.toggleProperty("showHtml");
|
2016-11-24 06:46:57 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
sendEmail() {
|
|
|
|
this.set("sendingEmail", true);
|
|
|
|
this.set("sentEmail", false);
|
2018-06-15 23:03:24 +08:00
|
|
|
|
2019-05-27 16:42:53 +08:00
|
|
|
EmailPreview.sendDigest(this.username, this.lastSeen, this.email)
|
2017-06-29 03:36:34 +08:00
|
|
|
.then((result) => {
|
2016-11-24 06:46:57 +08:00
|
|
|
if (result.errors) {
|
|
|
|
bootbox.alert(result.errors);
|
|
|
|
} else {
|
2017-06-29 03:36:34 +08:00
|
|
|
this.set("sentEmail", true);
|
2016-11-24 06:46:57 +08:00
|
|
|
}
|
2017-06-29 03:36:34 +08:00
|
|
|
})
|
|
|
|
.catch(popupAjaxError)
|
|
|
|
.finally(() => {
|
|
|
|
this.set("sendingEmail", false);
|
2016-11-24 06:46:57 +08:00
|
|
|
});
|
2013-09-17 02:08:55 +08:00
|
|
|
},
|
2013-06-04 04:12:24 +08:00
|
|
|
},
|
|
|
|
});
|