2015-05-02 13:44:41 +09:00
|
|
|
var getDateURL = function (moment) {
|
|
|
|
return Router.path('postsSingleDay', {
|
|
|
|
year: moment.year(),
|
|
|
|
month: moment.month() + 1,
|
|
|
|
day: moment.date()
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-05-07 15:44:12 +09:00
|
|
|
Template.single_day_nav.onCreated(function(){
|
2015-04-22 07:50:11 +09:00
|
|
|
|
|
|
|
$(document).unbind('keyup'); //remove any potential existing bindings to avoid duplicates
|
|
|
|
|
2015-05-02 13:44:41 +09:00
|
|
|
var currentDate = moment(this.data.terms.date).startOf('day');
|
2015-04-22 07:50:11 +09:00
|
|
|
var today = moment(new Date()).startOf('day');
|
|
|
|
|
2015-06-09 20:59:46 -04:00
|
|
|
$(document).bind('keyup', function(event){
|
|
|
|
switch (event.which) {
|
|
|
|
// left arrow
|
|
|
|
case 37:
|
|
|
|
Router.go($('.prev-link').attr('href'));
|
|
|
|
currentDate.subtract(1, 'day');
|
|
|
|
break;
|
|
|
|
// right arrow
|
|
|
|
case 39:
|
|
|
|
if(Users.is.admin(Meteor.user()) || today.diff(currentDate, 'days') > 0) {
|
|
|
|
Router.go($('.next-link').attr('href'));
|
|
|
|
currentDate.add(1, 'day');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
2015-04-22 07:50:11 +09:00
|
|
|
});
|
|
|
|
|
2015-06-09 20:59:46 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
Template.single_day_nav.onDestroyed(function(){
|
|
|
|
|
|
|
|
$(document).unbind('keyup'); //clean up to prevent errors on other pages
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-05-02 13:44:41 +09:00
|
|
|
});
|
2015-04-22 07:50:11 +09:00
|
|
|
|
2015-05-07 15:44:12 +09:00
|
|
|
Template.single_day_nav.helpers({
|
2015-04-22 07:50:11 +09:00
|
|
|
currentDate: function(){
|
2015-05-02 13:44:41 +09:00
|
|
|
var currentDate = moment(this.terms.date);
|
2015-06-18 09:35:44 -05:00
|
|
|
var today = moment(new Date()).startOf('day');
|
2015-04-22 07:50:11 +09:00
|
|
|
var diff = today.diff(currentDate, 'days');
|
|
|
|
if (diff === 0) {
|
|
|
|
return i18n.t("today");
|
|
|
|
}
|
|
|
|
if (diff === 1) {
|
|
|
|
return i18n.t("yesterday");
|
|
|
|
}
|
|
|
|
return currentDate.format("dddd, MMMM Do YYYY");
|
|
|
|
},
|
|
|
|
previousDateURL: function(){
|
2015-05-02 13:44:41 +09:00
|
|
|
var currentDate = moment(this.terms.date);
|
2015-04-22 07:50:11 +09:00
|
|
|
var newDate = currentDate.subtract(1, 'days');
|
|
|
|
return getDateURL(newDate);
|
|
|
|
},
|
|
|
|
showPreviousDate: function(){
|
|
|
|
// TODO
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
nextDateURL: function(){
|
2015-05-02 13:44:41 +09:00
|
|
|
var currentDate = moment(this.terms.date);
|
2015-04-22 07:50:11 +09:00
|
|
|
var newDate = currentDate.add(1, 'days');
|
|
|
|
return getDateURL(newDate);
|
|
|
|
},
|
|
|
|
showNextDate: function(){
|
2015-05-02 13:44:41 +09:00
|
|
|
var currentDate = moment(this.terms.date).startOf('day');
|
2015-04-22 07:50:11 +09:00
|
|
|
var today = moment(new Date()).startOf('day');
|
2015-04-27 17:14:07 +09:00
|
|
|
return Users.is.admin(Meteor.user()) || (today.diff(currentDate, 'days') > 0);
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
});
|