-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
114 lines (94 loc) · 3.23 KB
/
index.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//import { Document, Packer, TextRun, Paragraph } from 'docx'
//import { saveAs } from 'file-saver'
//import * as fs from "fs";
//cleanup the json so it's ISO compatible
function dateFixup (workingString) {
workingString.replace(/\//,'-');
}
// Populate the pay period dropdown
let dropdown = document.getElementById('periodDropdown');
dropdown.length = 0;
let defaultOption = document.createElement('option');
defaultOption.text = 'Select Period';
dropdown.add(defaultOption);
dropdown.selectedIndex = 0;
const url = 'data/2022-periods.json';
const request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = function() {
if (request.status === 200) {
const data = JSON.parse(request.responseText);
let option;
for (let i = 0; i < data.length; i++) {
option = document.createElement('option');
let stuffHere = data[i].End.replaceAll(/\//g,'-')
option.text = stuffHere;
option.value = stuffHere;
dropdown.add(option);
}
} else {
// Reached the server, but it returned an error
}
}
request.onerror = function() {
console.error('An error occurred fetching the JSON from ' + url);
};
request.send();
//Fill in the dayWorked values based on the selection from the dropDown
function periodSelect() {
let dropPeriod = document.getElementById('periodDropdown').value;
// Trying this out: https://stackoverflow.com/questions/3871547/js-iterating-over-result-of-getelementsbyclassname-using-array-foreach
var elements = document.getElementsByClassName('workDay')
if(dropPeriod != 'Select Period'){
for (let i=0; i>15, i++;) {
unixDate = Date.parse(dropPeriod)
console.log(unixDate)
Array.from(elements).forEach(
(element) => {
element.value = unixDate+i-14;
console.log(element.value)
}
);
// ;
// for (let i=14; i>0; i--){
// }
// )
// }
//This next line actual;ly puts the dropdown value into Day 14
// document.getElementById('hwd14').value = dropPeriod;
// console.log(document.getElementsByClassName("workDay"))
// for (let i = 0; i < 15 ; i++) {
// targetDate = string('hwd', string(i+1));
//console.log
//document.getElementById(targetDate).val
// }
}
}
}
// document.querySelectorAll('#allInputs')
// Documents contain sections, you can have multiple sections per document, go here to learn more about sections
// const doc = new Document({
// sections: [{
// properties: {},
// children: [
// new Paragraph({
// children: [
// new TextRun("Hello World"),
// new TextRun({
// text: fname,
// bold: true,
// }),
// new TextRun({
// text: lname,
// bold: true,
// }),
// ],
// }),
// ],
// }],
// });
// Used to export the file into a .docx file
//Packer.toBuffer(doc).then((buffer) => {
// fs.writeFileSync("Timesheet.docx", buffer);
// });
// Done! A file called 'My Document.docx' will be in your file system.