diff --git a/app/assets/javascripts/admin/controllers/admin-email-preview-digest.js.es6 b/app/assets/javascripts/admin/controllers/admin-email-preview-digest.js.es6
index 160f998365b..b46fc4c2804 100644
--- a/app/assets/javascripts/admin/controllers/admin-email-preview-digest.js.es6
+++ b/app/assets/javascripts/admin/controllers/admin-email-preview-digest.js.es6
@@ -1,7 +1,12 @@
import EmailPreview from 'admin/models/email-preview';
+import { popupAjaxError } from 'discourse/lib/ajax-error';
export default Ember.Controller.extend({
+ emailEmpty: Em.computed.empty('email'),
+ sendEmailDisabled: Em.computed.or('emailEmpty', 'sendingEmail'),
+ showSendEmailForm: Em.computed.notEmpty('model.html_content'),
+
actions: {
refresh() {
const model = this.get('model');
@@ -15,6 +20,23 @@ export default Ember.Controller.extend({
toggleShowHtml() {
this.toggleProperty('showHtml');
+ },
+
+ sendEmail() {
+ this.set('sendingEmail', true);
+ this.set('sentEmail', false);
+
+ const self = this;
+
+ EmailPreview.sendDigest(this.get('lastSeen'), this.get('username'), this.get('email')).then(result => {
+ if (result.errors) {
+ bootbox.alert(result.errors);
+ } else {
+ self.set('sentEmail', true);
+ }
+ }).catch(popupAjaxError).finally(function() {
+ self.set('sendingEmail', false);
+ });
}
}
diff --git a/app/assets/javascripts/admin/models/email-preview.js.es6 b/app/assets/javascripts/admin/models/email-preview.js.es6
index f992bf250d8..cfe96c6e0d5 100644
--- a/app/assets/javascripts/admin/models/email-preview.js.es6
+++ b/app/assets/javascripts/admin/models/email-preview.js.es6
@@ -17,6 +17,20 @@ EmailPreview.reopenClass({
}).then(function (result) {
return EmailPreview.create(result);
});
+ },
+
+ sendDigest: function(lastSeenAt, username, email) {
+ if (Em.isEmpty(lastSeenAt)) {
+ lastSeenAt = moment().subtract(7, 'days').format('YYYY-MM-DD');
+ }
+
+ if (Em.isEmpty(username)) {
+ username = Discourse.User.current().username;
+ }
+
+ return ajax("/admin/email/send-digest.json", {
+ data: { last_seen_at: lastSeenAt, username: username, email: email }
+ });
}
});
diff --git a/app/assets/javascripts/admin/templates/email-preview-digest.hbs b/app/assets/javascripts/admin/templates/email-preview-digest.hbs
index 7bd2a4455f1..f64245c154c 100644
--- a/app/assets/javascripts/admin/templates/email-preview-digest.hbs
+++ b/app/assets/javascripts/admin/templates/email-preview-digest.hbs
@@ -19,6 +19,24 @@
{{#conditional-loading-spinner condition=loading}}
+
+ {{#if showSendEmailForm}}
+
+