Skip to content

Commit

Permalink
[#411] Prevent redundant GET params when using prev/next date hotkeys.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaragunde committed Sep 14, 2021
1 parent 2e9e9b7 commit eb1abf7
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions web/js/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,31 @@ function isUnTouched(taskRecord) {
}
}

// Navigate to Next day
// Load the tasks page for a certain date.
// Makes sure no GET parameters are added when we load "today" tasks.
function navigateToDate(newDate) {
var url = "tasks.php";
var today = new Date();
today.setHours(0,0,0,0);
newDate.setHours(0,0,0,0);
// we compare getTime() to be able to load the same day on a different
// month or year.
if (today.getTime() !== newDate.getTime()) {
url += "?date=" + newDate.format('Y-m-d');
}
window.location = url;
}

function navigateToNextDay() {
nextDate = new Date();
nextDate.setTime(currentDate.getTime() + 86400000);
window.location = "tasks.php?date=" + nextDate.format('Y-m-d');
navigateToDate(nextDate);
}

// Navigate to Prev day
function navigateToPrevDay() {
previousDate = new Date();
previousDate.setTime(currentDate.getTime() - 86400000);
window.location = "tasks.php?date=" + previousDate.format('Y-m-d');
navigateToDate(previousDate);
}

function updateTasksLength(taskPanel) {
Expand Down Expand Up @@ -1031,16 +1044,11 @@ Ext.onReady(function(){
selectedDates: [currentDate],
value: currentDate,
startDay: 1,
listeners: {'select': function (item, selectedDate) {
var url = "tasks.php";
var today = new Date();
today.setHours(0,0,0,0);
selectedDate.setHours(0,0,0,0);
if (today.getTime() !== selectedDate.getTime()) {
url += "?date=" + selectedDate.format('Y-m-d');
listeners: {
'select': function (item, selectedDate) {
navigateToDate(selectedDate);
}
window.location = url;
}}
}
}),
],
});
Expand Down

0 comments on commit eb1abf7

Please sign in to comment.