generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDPS-710 add spurs and landings to establishment-roll page
- Loading branch information
1 parent
967afbf
commit 5027571
Showing
20 changed files
with
521 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const landingRows = document.querySelectorAll('.establishment-roll__table__landing-row') | ||
const spurRows = document.querySelectorAll('.establishment-roll__table__spur-row') | ||
const wingRows = document.querySelectorAll('.establishment-roll__table__wing-row') | ||
const totalsRow = document.querySelector('#roll-table-totals-row') | ||
|
||
function init() { | ||
;[...landingRows, ...spurRows].forEach(row => { | ||
row.setAttribute('hidden', 'hidden') | ||
}) | ||
|
||
wingRows.forEach((wingRow, index) => { | ||
const wingId = wingRow.getAttribute('id') | ||
const wingNameCell = wingRow.getElementsByTagName('td')[0] | ||
const wingNameText = wingNameCell.innerText | ||
const childRows = document.querySelectorAll('[data-wing-id="' + wingId + '"]') | ||
const childrenIds = [...childRows].map(row => row.getAttribute('id')) | ||
|
||
const wingLink = document.createElement('a') | ||
wingLink.setAttribute('href', '#') | ||
wingLink.setAttribute('class', 'govuk-details__summary govuk-link--no-visited-state') | ||
wingLink.setAttribute('aria-controls', childrenIds.join(' ')) | ||
wingLink.innerHTML = wingNameText | ||
|
||
wingLink.addEventListener('click', function (event) { | ||
event.preventDefault() | ||
const nextRow = wingRows[index + 1] ? wingRows[index + 1] : totalsRow | ||
|
||
childRows.forEach(row => { | ||
const isOpen = !row.getAttribute('hidden') | ||
|
||
if (isOpen) { | ||
row.setAttribute('hidden', 'hidden') | ||
wingLink.setAttribute('aria-expanded', 'false') | ||
wingRow.classList.remove('open') | ||
nextRow.classList.remove('next-wing-to-open') | ||
} else { | ||
row.removeAttribute('hidden') | ||
wingLink.setAttribute('aria-expanded', 'true') | ||
wingRow.classList.add('open') | ||
nextRow.classList.add('next-wing-to-open') | ||
} | ||
}) | ||
}) | ||
|
||
wingNameCell.replaceChildren(wingLink) | ||
}) | ||
} | ||
|
||
init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.