var punches, punchList, listLength, object;
function isItArray(object) {
console.log(`is ${object} Array = ${Array.isArray(object)}`);
// return Array.isArray(object);
}
function putJson(data) {
let req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (req.readyState == XMLHttpRequest.DONE) {
document.getElementById("result").innerHTML = new Date().getTime() + " - " + req.status;
getJson(genList);
}
};
req.open("PUT", jsonUrl, true);
req.setRequestHeader("Content-type", "application/json");
req.send(data);
}
function getJson(callback) {
displayMeta();
console.log(`getJson`);
let req = new XMLHttpRequest();
req.onreadystatechange = () => {
if (req.readyState == XMLHttpRequest.DONE) {
window.punches = JSON.parse(req.responseText);
window.punches.sort(function(a, b){return a.priority - b.priority});
callback(window.punches);
}
};
req.open("GET", jsonUrl, true);
req.send();
}
function genList(punchList) {
document.getElementById("showDone").innerHTML = "Show Done: " + showDone + "";
disableElement("punchDetail");
enableElement("punchList");
var itemStyle = "punches";
isItArray(punchList);
// punchList.sort(function(a, b){return new Date(a.date).getTime() - new Date(b.date).getTime()});
listLength = punchList.length;
// list = "
Punch Item
Status
Priority
Action
";
list = "
"; //
//prioritize in-progress
for (i = 0; i < listLength; i++) {
if (punchList[i].progress.toLowerCase() === "in progress") {
console.log(`in progress`);
// list += "
";
list += "
"; //
list += "
";
list += "
" + punchList[i].subject + "
"; //
list += "
Status: " + punchList[i].progress + "
";
list += "
Priority: " + punchList[i].priority + "
";
list += "
Need By: " + punchList[i].nDate + "
";
list += "
";
list += "
";
list += "
";
list += "";
list += "
";
list += "start";
list += "done";
list += "edit";
list += "delete";
list += "
";
list += "
";
list += "
";
list += "
";
}
}
// then !done
for (i = 0; i < listLength; i++) {
if (punchList[i].progress.toLowerCase() != "in progress") {
if (punchList[i].progress.toLowerCase() != "done") {
console.log(`not in progress or not done`);
list += "
"; //
list += "
";
list += "
" + punchList[i].subject + "
"; //
list += "
Status: " + punchList[i].progress + "
";
list += "
Priority: " + punchList[i].priority + "
";
list += "
Need By: " + punchList[i].nDate + "
";
list += "
";
list += "
";
list += "
";
list += "";
list += "
";
list += "start";
list += "done";
list += "edit";
list += "delete";
list += "
";
list += "
";
list += "
";
list += "
";
}
}
}
// then done
for (i = 0; i < listLength; i++) {
if (showDone === true) {
if (punchList[i].progress.toLowerCase() === "done") {
console.log(`show done.`);
list += "
"; //
list += "
";
list += "
" + punchList[i].subject + "
"; //
list += "
Status: " + punchList[i].progress + "
";
list += "
Priority: " + punchList[i].priority + "
";
list += "
Need By: " + punchList[i].nDate + "
";
list += "
";
list += "
";
list += "
";
list += "";
list += "
";
list += "start";
list += "done";
list += "edit";
list += "delete";
list += "
";
list += "
";
list += "
";
list += "
";
}
}
}
list += "";
document.getElementById("punchList").innerHTML = list;
}
function startPunch(item) {
var punchList = window.punches;
punchList[item].progress = "In Progress";
jsonStr = JSON.stringify(punchList);
putJson(jsonStr);
}
function completePunch(item) {
var punchList = window.punches;
punchList[item].progress = "Done";
jsonStr = JSON.stringify(punchList);
putJson(jsonStr);
}
function enablePunchDetail(item) {
var punchList = window.punches;
console.log(`inside enablePunchDetail`);
disableElement("punchList");
console.log(`punchList Disabled`);
enableElement("punchDetail");
console.log(`punchDetail Enabled`);
// html = "";
html = "