|
|
@ -1,7 +1,7 @@
|
|
|
|
var moment = require('moment');
|
|
|
|
var moment = require('moment');
|
|
|
|
var Backgrid = require('backgrid');
|
|
|
|
var Backgrid = require('backgrid');
|
|
|
|
var UiSettings = require('../Shared/UiSettingsModel');
|
|
|
|
var UiSettings = require('../Shared/UiSettingsModel');
|
|
|
|
require('../Shared/FormatHelpers');
|
|
|
|
var FormatHelpers = require('../Shared/FormatHelpers');
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Backgrid.Cell.extend({
|
|
|
|
module.exports = Backgrid.Cell.extend({
|
|
|
|
className : 'age-cell',
|
|
|
|
className : 'age-cell',
|
|
|
@ -9,27 +9,25 @@ module.exports = Backgrid.Cell.extend({
|
|
|
|
render : function() {
|
|
|
|
render : function() {
|
|
|
|
var age = this.model.get('age');
|
|
|
|
var age = this.model.get('age');
|
|
|
|
var ageHours = this.model.get('ageHours');
|
|
|
|
var ageHours = this.model.get('ageHours');
|
|
|
|
|
|
|
|
var ageMinutes = this.model.get('ageMinutes');
|
|
|
|
var published = moment(this.model.get('publishDate'));
|
|
|
|
var published = moment(this.model.get('publishDate'));
|
|
|
|
var publishedFormatted = published.format('{0} {1}'.format(UiSettings.get('shortDateFormat'), UiSettings.time(true, true)));
|
|
|
|
var publishedFormatted = published.format('{0} {1}'.format(UiSettings.get('shortDateFormat'), UiSettings.time(true, true)));
|
|
|
|
var formatted = age;
|
|
|
|
var formatted = age;
|
|
|
|
var suffix = this.plural(age, 'day');
|
|
|
|
var suffix = FormatHelpers.plural(age, 'day');
|
|
|
|
|
|
|
|
|
|
|
|
if (age === 0) {
|
|
|
|
if (age < 2) {
|
|
|
|
formatted = ageHours.toFixed(1);
|
|
|
|
formatted = ageHours.toFixed(1);
|
|
|
|
suffix = this.plural(Math.round(ageHours), 'hour');
|
|
|
|
suffix = FormatHelpers.plural(Math.round(ageHours), 'hour');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ageHours < 2) {
|
|
|
|
|
|
|
|
formatted = ageMinutes.toFixed(1);
|
|
|
|
|
|
|
|
suffix = FormatHelpers.plural(Math.round(ageMinutes), 'minute');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.$el.html('<div title="{2}">{0} {1}</div>'.format(formatted, suffix, publishedFormatted));
|
|
|
|
this.$el.html('<div title="{2}">{0} {1}</div>'.format(formatted, suffix, publishedFormatted));
|
|
|
|
|
|
|
|
|
|
|
|
this.delegateEvents();
|
|
|
|
this.delegateEvents();
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plural : function(input, unit) {
|
|
|
|
|
|
|
|
if (input === 1) {
|
|
|
|
|
|
|
|
return unit;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return unit + 's';
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|