2015-11-20 20:27:06 -05:00
|
|
|
import EmailPreview from 'admin/models/email-preview';
|
2016-11-23 17:46:57 -05:00
|
|
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
2015-11-20 20:27:06 -05:00
|
|
|
|
2015-08-11 12:27:07 -04:00
|
|
|
export default Ember.Controller.extend({
|
2013-06-03 16:12:24 -04:00
|
|
|
|
2016-11-23 17:46:57 -05:00
|
|
|
emailEmpty: Em.computed.empty('email'),
|
|
|
|
sendEmailDisabled: Em.computed.or('emailEmpty', 'sendingEmail'),
|
|
|
|
showSendEmailForm: Em.computed.notEmpty('model.html_content'),
|
2016-11-24 15:38:22 -05:00
|
|
|
htmlEmpty: Em.computed.empty('model.html_content'),
|
|
|
|
|
2013-09-16 14:08:55 -04:00
|
|
|
actions: {
|
2015-08-16 05:51:31 -04:00
|
|
|
refresh() {
|
|
|
|
const model = this.get('model');
|
2013-09-16 14:08:55 -04:00
|
|
|
|
2015-08-16 06:01:04 -04:00
|
|
|
this.set('loading', true);
|
2016-11-24 15:05:33 -05:00
|
|
|
this.set('sentEmail', false);
|
2015-11-20 20:27:06 -05:00
|
|
|
EmailPreview.findDigest(this.get('lastSeen'), this.get('username')).then(email => {
|
2013-09-16 14:08:55 -04:00
|
|
|
model.setProperties(email.getProperties('html_content', 'text_content'));
|
2015-08-16 05:51:31 -04:00
|
|
|
this.set('loading', false);
|
2013-09-16 14:08:55 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-08-16 05:51:31 -04:00
|
|
|
toggleShowHtml() {
|
2013-09-16 14:08:55 -04:00
|
|
|
this.toggleProperty('showHtml');
|
2016-11-23 17:46:57 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2013-09-16 14:08:55 -04:00
|
|
|
}
|
2013-06-03 16:12:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|