FIX: Email preview with no date caused a server error

This commit is contained in:
Robin Ward 2014-01-06 10:18:20 -05:00
parent c18a6827df
commit 3bba75b052
2 changed files with 9 additions and 8 deletions

View File

@ -9,9 +9,14 @@
Discourse.EmailPreview = Discourse.Model.extend({});
Discourse.EmailPreview.reopenClass({
findDigest: function(last_seen_at) {
findDigest: function(lastSeenAt) {
if (Em.isEmpty(lastSeenAt)) {
lastSeenAt = moment().subtract('days',7).format('YYYY-MM-DD');
}
return Discourse.ajax("/admin/email/preview-digest.json", {
data: {last_seen_at: last_seen_at}
data: {last_seen_at: lastSeenAt}
}).then(function (result) {
return Discourse.EmailPreview.create(result);
});

View File

@ -7,21 +7,17 @@
@module Discourse
**/
var oneWeekAgo = function() {
return moment().subtract('days',7).format('YYYY-MM-DD');
};
Discourse.AdminEmailPreviewDigestRoute = Discourse.Route.extend({
model: function() {
return Discourse.EmailPreview.findDigest(oneWeekAgo());
return Discourse.EmailPreview.findDigest();
},
afterModel: function(model) {
var controller = this.controllerFor('adminEmailPreviewDigest');
controller.setProperties({
model: model,
lastSeen: oneWeekAgo(),
lastSeen: moment().subtract('days',7).format('YYYY-MM-DD'),
showHtml: true
});
}