From 404bba9d518271533d5e4c83dabd8541726bf248 Mon Sep 17 00:00:00 2001 From: stilbruch Date: Sat, 23 Apr 2022 14:15:35 -0500 Subject: Move routes into seperate folder --- app/static/js/record.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/static/js/record.js (limited to 'app/static/js/record.js') diff --git a/app/static/js/record.js b/app/static/js/record.js new file mode 100644 index 0000000..fedbdd7 --- /dev/null +++ b/app/static/js/record.js @@ -0,0 +1,9 @@ + +// Called when the check at the end of a set line is clicked +function onClickSetCheck(elem) { + if (elem.classList.contains('is-success')) { + elem.classList.remove('is-success'); + } else { + elem.classList.add('is-success'); + } +} -- cgit v1.2.3 From 3d0202b4faaef7ff0900bcfefca4c88907a2b6d4 Mon Sep 17 00:00:00 2001 From: stilbruch Date: Sat, 23 Apr 2022 15:08:27 -0500 Subject: Update record workout page --- app/static/js/record.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'app/static/js/record.js') diff --git a/app/static/js/record.js b/app/static/js/record.js index fedbdd7..75aa148 100644 --- a/app/static/js/record.js +++ b/app/static/js/record.js @@ -1,9 +1,42 @@ +// Register 'Enter' listeners on all inputs +Array.from(document.getElementsByClassName('input')) + .filter(e => e.type == 'number') + .forEach(e => e.addEventListener('keyup', function(event) { + if (event.key == 'Enter') { + console.log("ENTER"); + } + })) + +function checkSet(row) { + // Disable input editing + row.children[1].firstChild.disabled = true; + row.children[2].firstChild.disabled = true; + + // Add is-success to inputs + row.children[1].firstChild.classList.add('is-success') + row.children[2].firstChild.classList.add('is-success') +} + +function uncheckSet(row) { + // Re-enable input editing + row.children[1].firstChild.disabled = false; + row.children[2].firstChild.disabled = false; + + // Remove is-success from inputs + row.children[1].firstChild.classList.remove('is-success') + row.children[2].firstChild.classList.remove('is-success') +} + // Called when the check at the end of a set line is clicked function onClickSetCheck(elem) { if (elem.classList.contains('is-success')) { elem.classList.remove('is-success'); + + uncheckSet(elem.parentElement.parentElement); } else { elem.classList.add('is-success'); + + checkSet(elem.parentElement.parentElement); } } -- cgit v1.2.3 From 4f1e55112138a1f3b4be3bf23e3740ae3effac35 Mon Sep 17 00:00:00 2001 From: stilbruch Date: Sat, 23 Apr 2022 15:48:45 -0500 Subject: Add javascript to add sets while recording workout --- app/static/js/record.js | 64 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 16 deletions(-) (limited to 'app/static/js/record.js') diff --git a/app/static/js/record.js b/app/static/js/record.js index 75aa148..aba6785 100644 --- a/app/static/js/record.js +++ b/app/static/js/record.js @@ -4,11 +4,44 @@ Array.from(document.getElementsByClassName('input')) .filter(e => e.type == 'number') .forEach(e => e.addEventListener('keyup', function(event) { if (event.key == 'Enter') { - console.log("ENTER"); + // TODO implement + console.log("ENTER") } })) -function checkSet(row) { +function setReset(row, values=true) { + let lbsInput = row.children[1].children[0]; + let repsInput = row.children[2].children[0]; + let doneButton = row.children[3].children[0]; + + // Enable inputs + lbsInput.disabled = false; + repsInput.disabled = false; + + // Remove classes + lbsInput.classList.remove('is-success'); + lbsInput.classList.remove('is-danger'); + repsInput.classList.remove('is-success'); + repsInput.classList.remove('is-danger'); + + doneButton.classList.remove('is-success'); + + if (values) { + lbsInput.value = ''; + repsInput.value = ''; + } +} + +function setSetid(row, id) { + let setNumber = row.children[0]; + let lbsInput = row.children[1].children[0]; + let repsInput = row.children[2].children[0]; + let doneButton = row.children[3].children[0]; + + setNumber.textContent = id + 1; +} + +function setCheck(row) { // Disable input editing row.children[1].firstChild.disabled = true; row.children[2].firstChild.disabled = true; @@ -18,25 +51,24 @@ function checkSet(row) { row.children[2].firstChild.classList.add('is-success') } -function uncheckSet(row) { - // Re-enable input editing - row.children[1].firstChild.disabled = false; - row.children[2].firstChild.disabled = false; - - // Remove is-success from inputs - row.children[1].firstChild.classList.remove('is-success') - row.children[2].firstChild.classList.remove('is-success') -} - // Called when the check at the end of a set line is clicked function onClickSetCheck(elem) { if (elem.classList.contains('is-success')) { - elem.classList.remove('is-success'); - - uncheckSet(elem.parentElement.parentElement); + setReset(elem.parentElement.parentElement, false); } else { elem.classList.add('is-success'); - checkSet(elem.parentElement.parentElement); + setCheck(elem.parentElement.parentElement); } } + +function onClickAddSet(elem) { + // Create the new row + let tableBody = elem.parentElement.parentElement.children[1].children[1]; + let row = tableBody.children[0].cloneNode(true); + + // Add new row to table + setReset(row); + setSetid(row, tableBody.children.length) + tableBody.appendChild(row) +} -- cgit v1.2.3