2014-08-19 05:40:50 +08:00
|
|
|
function entranceDate(dt, showTime) {
|
2014-08-19 05:14:30 +08:00
|
|
|
var today = new Date();
|
2014-08-16 04:39:34 +08:00
|
|
|
|
2014-08-19 05:40:50 +08:00
|
|
|
if (dt.toDateString() === today.toDateString()) {
|
|
|
|
return moment(dt).format(I18n.t("dates.time"));
|
2014-08-16 04:39:34 +08:00
|
|
|
}
|
|
|
|
|
2014-08-19 05:40:50 +08:00
|
|
|
if (dt.getYear() === today.getYear()) {
|
2014-08-19 05:14:30 +08:00
|
|
|
// No year
|
2014-08-19 05:40:50 +08:00
|
|
|
return moment(dt).format(
|
2014-08-30 18:44:00 +08:00
|
|
|
showTime ? I18n.t("dates.long_date_without_year_with_linebreak") : I18n.t("dates.long_no_year_no_time")
|
2014-08-19 05:14:30 +08:00
|
|
|
);
|
2014-08-16 04:39:34 +08:00
|
|
|
}
|
|
|
|
|
2014-08-19 05:40:50 +08:00
|
|
|
return moment(dt).format(
|
2014-08-30 18:44:00 +08:00
|
|
|
showTime ? I18n.t('dates.long_date_with_year_with_linebreak') : I18n.t('dates.long_date_with_year_without_time')
|
2014-08-19 05:14:30 +08:00
|
|
|
);
|
2014-08-16 04:39:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Ember.ObjectController.extend({
|
|
|
|
position: null,
|
|
|
|
|
2014-08-19 05:14:30 +08:00
|
|
|
createdDate: function() {
|
|
|
|
return new Date(this.get('model.created_at'));
|
2014-08-16 04:39:34 +08:00
|
|
|
}.property('model.created_at'),
|
|
|
|
|
2014-08-19 05:14:30 +08:00
|
|
|
bumpedDate: function() {
|
|
|
|
return new Date(this.get('model.bumped_at'));
|
2014-08-16 04:39:34 +08:00
|
|
|
}.property('model.bumped_at'),
|
|
|
|
|
2014-08-19 05:14:30 +08:00
|
|
|
showTime: function() {
|
|
|
|
var diffMs = this.get('bumpedDate').getTime() - this.get('createdDate').getTime();
|
|
|
|
return diffMs < (1000 * 60 * 60 * 24 * 2);
|
|
|
|
}.property('createdDate', 'bumpedDate'),
|
|
|
|
|
|
|
|
topDate: function() {
|
|
|
|
return entranceDate(this.get('createdDate'), this.get('showTime'));
|
|
|
|
}.property('createdDate'),
|
|
|
|
|
|
|
|
bottomDate: function() {
|
|
|
|
return entranceDate(this.get('bumpedDate'), this.get('showTime'));
|
|
|
|
}.property('bumpedDate'),
|
|
|
|
|
2014-08-16 04:39:34 +08:00
|
|
|
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'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|