mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: send digest preview to an email address
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 }
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -19,6 +19,24 @@
|
||||
</div>
|
||||
|
||||
{{#conditional-loading-spinner condition=loading}}
|
||||
|
||||
{{#if showSendEmailForm}}
|
||||
<br/>
|
||||
<div>
|
||||
{{#if sendingEmail}}
|
||||
{{i18n 'admin.email.sending_test'}}
|
||||
{{else}}
|
||||
<label style="display: inline;">{{i18n 'admin.email.send_digest_label'}}</label>
|
||||
{{text-field value=email placeholderKey="admin.email.test_email_address"}}
|
||||
<button class='btn' {{action "sendEmail"}} disabled={{sendEmailDisabled}}>{{i18n 'admin.email.send_digest'}}</button>
|
||||
{{#if sentEmail}}
|
||||
<span class='result-message'>{{i18n 'admin.email.sent_test'}}</span>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
<br/>
|
||||
{{/if}}
|
||||
|
||||
{{#if showHtml}}
|
||||
{{{model.html_content}}}
|
||||
{{else}}
|
||||
|
||||
Reference in New Issue
Block a user