-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
35 lines (28 loc) · 1.25 KB
/
Copy pathmain.js
File metadata and controls
35 lines (28 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Date.prototype.incDays = function(days) {
this.setDate(this.getDate() + days);
}
document.getElementById('employees').value = localStorage.getItem('employees') || '';
document.getElementById('print').onclick = function(e) {
if (!document.getElementById('start-date').value) {
alert('You must provide a starting date');
return;
}
const names = document.getElementById('employees').value.trim().split('\n');
const date = new Date(document.getElementById('start-date').valueAsDate.valueOf());
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
if (!(date.getDay() === 1 || date.getDay() === 5) && !confirm(`You entered a ${date.toLocaleDateString('en-US', { weekday: 'long' })}. Are you sure you want this?`)) {
document.getElementById('start-date').reset();
return;
}
localStorage.setItem('employees', names.join('\n'));
const newwin = window.open('./timesheet-template.html');
if (newwin === null) {
alert('Please allow popups for this website.');
return;
}
newwin.onload = function() {
newwin.makeTimesheets(date, names);
if (document.getElementById('auto-close').checked) newwin.onblur = newwin.close;
newwin.print();
};
}