Skip to content

Commit

Permalink
Merge pull request #72 from m1x0n/related-time
Browse files Browse the repository at this point in the history
Related time
  • Loading branch information
m1x0n committed Aug 14, 2015
2 parents 088242b + 3f0d10c commit 3708171
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 27 deletions.
16 changes: 13 additions & 3 deletions public/js/models/answer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['app'], function(App) {
define(['app', 'moment'], function(App, moment) {
App.module('Answer', function(Answer, App, Backbone, Marionette, $, _) {
Answer.Model = Backbone.Model.extend({
defaults: {
Expand All @@ -11,8 +11,17 @@ define(['app'], function(App) {
},
initialize: function (options) {
this.urlRoot = App.prefix + '/api/v1/questions/'
+ options.question_id
+ '/answers';
+ options.question_id
+ '/answers';

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 @@ -46,6 +55,7 @@ define(['app'], function(App) {

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
24 changes: 10 additions & 14 deletions public/js/models/comment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['app'], function(App) {
define(['app', 'moment'], function(App, moment) {
App.module('Comment', function(Comment, App, Backbone, Marionette, $, _) {
Comment.Model = Backbone.Model.extend({
defaults: {
Expand All @@ -13,6 +13,14 @@ define(['app'], function(App) {
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 @@ -31,21 +39,9 @@ define(['app'], function(App) {
});

var API = {
//getAnswers: function (question_id) {
// var answers = new Answer.Collection({question_id: question_id});
// var defer = $.Deferred();
//
// answers.fetch({
// success: function (data) {
// defer.resolve(data);
// }
// });
//
// return defer.promise();
//},

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
13 changes: 12 additions & 1 deletion public/js/models/question.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(['app', 'paginator'], function(App, PageableCollection) {
define(['app', 'paginator', 'moment'], function(App, PageableCollection, moment) {
App.module('Question', function(Question, App, Backbone, Marionette, $, _) {
Question.Model = Backbone.Model.extend({
urlRoot: App.prefix + '/api/v1/questions',
Expand All @@ -11,6 +11,16 @@ define(['app', 'paginator'], function(App, PageableCollection) {
required: true,
msg: 'Please enter a description'
}
},
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 @@ -50,6 +60,7 @@ define(['app', 'paginator'], function(App, PageableCollection) {
sortedBy: 'desc'
},
initialize: function(options) {
debugger;
this.searchQuery = options.searchQuery;
this.searchTag = options.searchTag;
this.sort();
Expand Down
3 changes: 2 additions & 1 deletion public/js/require-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ requirejs.config({
ckeditor: 'vendor/ckeditor/ckeditor',
'ckeditor.custom.settings': 'vendor/ckeditor/custom-instance-settings',
'ckeditor.adapter': 'vendor/ckeditor/adapters/jquery',
'highlight': 'vendor/ckeditor/plugins/codesnippet/lib/highlight/highlight.pack'
'highlight': 'vendor/ckeditor/plugins/codesnippet/lib/highlight/highlight.pack',
'moment': 'vendor/moment/moment-with-locales.min'
},
shim: {
underscore: {
Expand Down
80 changes: 80 additions & 0 deletions public/js/vendor/moment/moment-with-locales.min.js

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions public/js/views/comment/composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ define(['app',
], function (App, CommentsTpl, SingleCommentTpl) {
App.module('Comment.Views', function (View, App, Backbone, Marionette, $, _) {
View.SingleCommentCompositeView = Marionette.CompositeView.extend({
template: SingleCommentTpl,
initialize: function(){
},
template: SingleCommentTpl
});


View.CommentsCompositeView = Marionette.CompositeView.extend({
tagName: 'section',
className: 'comment-list',
Expand Down
2 changes: 1 addition & 1 deletion public/js/views/templates/answer/single-answer.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="votes"></div>

<!-- Text -->
<time>Answered at <%- created_at %></time>
<time>Answered at <%- created_local %></time>
<div class="description"><%= description %></div>

<!-- Comments -->
Expand Down
2 changes: 1 addition & 1 deletion public/js/views/templates/comment/single-comment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="col-md-10">

<!-- Text -->
<time>Commented at <%- created_at %></time>
<time>Commented at <%- created_local %></time>
<p><%- text %></p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion public/js/views/templates/question/question-layout.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="row">
<!-- Time, title, folder -->
<div class="col-md-10">
<time>Asked at <%- created_at %></time>
<time>Asked at <%- created_local %></time>
<h2><%- title %></h2>
<div class="folder"><span class="icon glyphicon glyphicon-folder-open"></span> <%- folder.title %></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion public/js/views/templates/question/row.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="col-md-10">
<div class="row">
<div class="col-md-10 question-header">
<div class="asked_time">Asked at <%- created_at %></div>
<div class="asked_time">Asked at <%- created_local %></div>
<div><a class="question" href="#questions/<%- id %>"><b><%- title %></b></a></div>
<div class="folder">
<span class="icon glyphicon glyphicon-folder-close" aria-hidden="true"></span>
Expand Down

0 comments on commit 3708171

Please sign in to comment.