put date formatting in a mixin
This commit is contained in:
parent
f6a9fad9ad
commit
9562adaa10
4 changed files with 21 additions and 20 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
//= require_self
|
//= require_self
|
||||||
//= require_tree ./helpers
|
//= require_tree ./helpers
|
||||||
//= require ./router
|
//= require ./router
|
||||||
|
//= require ./models
|
||||||
//= require ./views
|
//= require ./views
|
||||||
//= require_tree ./models
|
//= require_tree ./models
|
||||||
//= require_tree ./pages
|
//= require_tree ./pages
|
||||||
|
|
|
||||||
16
app/assets/javascripts/app/models.js
Normal file
16
app/assets/javascripts/app/models.js
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
// Mixin to provide date formatting and "createdAt" method
|
||||||
|
// other attributes can be accessed by calling this.timeOf("timestamp-field")
|
||||||
|
// Requires:
|
||||||
|
// this = model with "created_at" attribute
|
||||||
|
app.models.formatDateMixin = {
|
||||||
|
|
||||||
|
timeOf: function(field) {
|
||||||
|
return app.helpers.dateFormatter.parse(this.get(field)) / 1000;
|
||||||
|
},
|
||||||
|
|
||||||
|
createdAt: function() {
|
||||||
|
return this.timeOf("created_at");
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
@ -1,14 +1,6 @@
|
||||||
app.models.Photo = Backbone.Model.extend({
|
app.models.Photo = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, {
|
||||||
urlRoot : "/photos",
|
urlRoot : "/photos",
|
||||||
|
|
||||||
initialize : function() {},
|
initialize : function() {},
|
||||||
|
|
||||||
createdAt : function() {
|
}));
|
||||||
return this.timeOf("created_at");
|
|
||||||
},
|
|
||||||
|
|
||||||
timeOf: function(field) {
|
|
||||||
return app.helpers.dateFormatter.parse(this.get(field)) / 1000;
|
|
||||||
},
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
app.models.Post = Backbone.Model.extend({
|
app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin, {
|
||||||
urlRoot : "/posts",
|
urlRoot : "/posts",
|
||||||
|
|
||||||
initialize : function() {
|
initialize : function() {
|
||||||
|
|
@ -17,18 +17,10 @@ app.models.Post = Backbone.Model.extend({
|
||||||
this.set({frame_name : templatePicker.getFrameName()})
|
this.set({frame_name : templatePicker.getFrameName()})
|
||||||
},
|
},
|
||||||
|
|
||||||
createdAt : function() {
|
|
||||||
return this.timeOf("created_at");
|
|
||||||
},
|
|
||||||
|
|
||||||
interactedAt : function() {
|
interactedAt : function() {
|
||||||
return this.timeOf("interacted_at");
|
return this.timeOf("interacted_at");
|
||||||
},
|
},
|
||||||
|
|
||||||
timeOf: function(field) {
|
|
||||||
return app.helpers.dateFormatter.parse(this.get(field)) / 1000;
|
|
||||||
},
|
|
||||||
|
|
||||||
createReshareUrl : "/reshares",
|
createReshareUrl : "/reshares",
|
||||||
|
|
||||||
reshare : function(){
|
reshare : function(){
|
||||||
|
|
@ -121,7 +113,7 @@ app.models.Post = Backbone.Model.extend({
|
||||||
, newlineIdx = body.indexOf("\n")
|
, newlineIdx = body.indexOf("\n")
|
||||||
return (newlineIdx > 0 ) ? body.substr(newlineIdx+1, body.length) : ""
|
return (newlineIdx > 0 ) ? body.substr(newlineIdx+1, body.length) : ""
|
||||||
}
|
}
|
||||||
}, {
|
}), {
|
||||||
headlineLimit : 118,
|
headlineLimit : 118,
|
||||||
|
|
||||||
frameMoods : [
|
frameMoods : [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue