This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/controllers/topic-entrance.js.es6
2014-08-15 16:39:57 -04:00

45 lines
1.1 KiB
JavaScript

function entranceDate(dt) {
var bumpedAt = new Date(dt),
today = new Date();
if (bumpedAt.getDate() === today.getDate()) {
return moment(bumpedAt).format(I18n.t("dates.time"));
}
if (bumpedAt.getYear() === today.getYear()) {
return moment(bumpedAt).format(I18n.t("dates.long_no_year"));
}
return moment(bumpedAt).format(I18n.t('dates.long_with_year'));
}
export default Ember.ObjectController.extend({
position: null,
topDate: function() {
return entranceDate(this.get('created_at'));
}.property('model.created_at'),
bottomDate: function() {
return entranceDate(this.get('bumped_at'));
}.property('model.bumped_at'),
actions: {
show: function(data) {
// Show the chooser but only if the model changes
if (this.get('model') !== data.topic) {
this.set('model', data.topic);
this.set('position', data.position);
}
},
enterTop: function() {
Discourse.URL.routeTo(this.get('url'));
},
enterBottom: function() {
Discourse.URL.routeTo(this.get('lastPostUrl'));
}
}
});