Skip to content

Commit

Permalink
Merge pull request #73 from m1x0n/related-time
Browse files Browse the repository at this point in the history
related-time: Changed timestamps to relative. Separating an updating …
  • Loading branch information
m1x0n committed Aug 14, 2015
2 parents 3708171 + dc8f85c commit e8dd775
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
14 changes: 5 additions & 9 deletions public/js/models/answer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
define(['app', 'moment'], function(App, moment) {
define([
'app',
'models/related-timestamps-model',
], function(App, RelatedTimestampsModel) {
App.module('Answer', function(Answer, App, Backbone, Marionette, $, _) {
Answer.Model = Backbone.Model.extend({
Answer.Model = RelatedTimestampsModel.extend({
defaults: {
'description': ''
},
Expand All @@ -16,12 +19,6 @@ define(['app', 'moment'], function(App, moment) {

this.attachLocalDates();
this.on('sync', this.attachLocalDates);
},
attachLocalDates: function () {
var updatedLocal = moment.utc(this.get('updated_at')).toDate();
this.set('updated_local', moment(updatedLocal).format('MMMM Do YYYY, h:mm:ss a'));
var createdLocal = moment.utc(this.get('created_at')).toDate();
this.set('created_local', moment(createdLocal).format('MMMM Do YYYY, h:mm:ss a'));
}
});

Expand Down Expand Up @@ -55,7 +52,6 @@ define(['app', 'moment'], function(App, moment) {

addAnswer: function (model) {
var defer = $.Deferred();
model.set('created_at', moment().format('MMMM Do YYYY, h:mm:ss a'));

if (!model.save([], {
wait: true,
Expand Down
15 changes: 6 additions & 9 deletions public/js/models/comment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
define(['app', 'moment'], function(App, moment) {
define([
'app',
'models/related-timestamps-model'
], function(App, RelatedTimestampsModel) {
App.module('Comment', function(Comment, App, Backbone, Marionette, $, _) {
Comment.Model = Backbone.Model.extend({
Comment.Model = RelatedTimestampsModel.extend({
defaults: {
'text': ''
},
Expand All @@ -13,14 +16,9 @@ define(['app', 'moment'], function(App, moment) {
this.urlRoot = App.prefix + '/api/v1/questions/'
+ options.question_id
+ '/comments';

this.attachLocalDates();
this.on('sync', this.attachLocalDates);
},
attachLocalDates: function () {
var updatedLocal = moment.utc(this.get('updated_at')).toDate();
this.set('updated_local', moment(updatedLocal).format('MMMM Do YYYY, h:mm:ss a'));
var createdLocal = moment.utc(this.get('created_at')).toDate();
this.set('created_local', moment(createdLocal).format('MMMM Do YYYY, h:mm:ss a'));
}
});

Expand All @@ -41,7 +39,6 @@ define(['app', 'moment'], function(App, moment) {
var API = {
addComment: function (model) {
var defer = $.Deferred();
model.set('created_at', moment().format('MMMM Do YYYY, h:mm:ss a'));

if (!model.save([], {
wait: true,
Expand Down
15 changes: 7 additions & 8 deletions public/js/models/question.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
define(['app', 'paginator', 'moment'], function(App, PageableCollection, moment) {
define([
'app',
'paginator',
'models/related-timestamps-model',
], function(App, PageableCollection, RelatedTimestampsModel) {
App.module('Question', function(Question, App, Backbone, Marionette, $, _) {
Question.Model = Backbone.Model.extend({
Question.Model = RelatedTimestampsModel.extend({
urlRoot: App.prefix + '/api/v1/questions',
validation: {
title: {
Expand All @@ -15,12 +19,6 @@ define(['app', 'paginator', 'moment'], function(App, PageableCollection, moment)
initialize: function (options) {
this.attachLocalDates();
this.on('sync', this.attachLocalDates);
},
attachLocalDates: function () {
var updatedLocal = moment.utc(this.get('updated_at')).toDate();
this.set('updated_local', moment(updatedLocal).format('MMMM Do YYYY, h:mm:ss a'));
var createdLocal = moment.utc(this.get('created_at')).toDate();
this.set('created_local', moment(createdLocal).format('MMMM Do YYYY, h:mm:ss a'));
}
});

Expand Down Expand Up @@ -95,6 +93,7 @@ define(['app', 'paginator', 'moment'], function(App, PageableCollection, moment)
questionAdd: function (data) {
var question = new Question.Model();
var defer = $.Deferred();

if (!question.save(data, {
wait: true,
success: function (data) {
Expand Down
14 changes: 14 additions & 0 deletions public/js/models/related-timestamps-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
define(['app', 'moment'], function(App, moment) {
App.module('App', function(Answer, App, Backbone, Marionette, $, _) {
App.RelatedTimestampsModel = Backbone.Model.extend({
attachLocalDates: function () {
var updatedRelative = moment.utc(this.get('updated_at')).toDate();
this.set('updated_local', moment(updatedRelative).fromNow());

var createdRelative = moment.utc(this.get('created_at')).toDate();
this.set('created_local', moment(createdRelative).fromNow());
}
});
});
return App.RelatedTimestampsModel;
});
1 change: 0 additions & 1 deletion public/js/views/comment/composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ define(['app',
childView: View.SingleCommentCompositeView,
childViewContainer: '.comments-region',


events: {
'submit .comments-form': 'submit'
},
Expand Down

0 comments on commit e8dd775

Please sign in to comment.