Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: case court report modal ui changes #6185

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion app/assets/stylesheets/pages/casa_cases.scss
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,27 @@ body.casa_cases-show {
flex-direction: column;
gap: .2rem;
}
}
}

// are these styles scoped specifically to "/case_court_reports"
// or are there other pages that use them?
#case-selection:required, .select2.select2-container {
background: transparent;
border: 1px solid #e5e5e5;
border-radius: 10px;
padding: 8px;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
}

.select-wrapper {
display: flex;
flex-direction: column;
gap: 8px;
}

span[role=combobox] {
padding-top: 2px;
}

39 changes: 38 additions & 1 deletion app/javascript/src/casa_case.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,25 @@ function showAlert (html) {
flashContainer && flashContainer.replaceWith(alertEl)
}

function validateForm (formEl, errorEl) {
if (!formEl) {
return
}

// check html validations, checkValidity returns false if doesn't pass validation
if (errorEl && !formEl.checkValidity()) {
errorEl.classList.remove('d-none')
}
}

function handleGenerateReport (e) {
e.preventDefault()

const formData = Object.fromEntries(new FormData(e.currentTarget.form))
const form = e.currentTarget.form

const formData = Object.fromEntries(new FormData(form))
const errorEl = document.querySelector('.select-required-error')
validateForm(form, errorEl ?? null)
if (formData.case_number.length === 0) return

const generateBtn = e.currentTarget
Expand Down Expand Up @@ -127,20 +141,43 @@ function handleGenerateReport (e) {
})
}

function clearSelectErrors () {
const errorEl = document.querySelector('.select-required-error')

if (!errorEl) return

errorEl.classList.add('d-none')
}

function handleModalClose () {
const selectEl = document.querySelector('#case-selection')

if (!selectEl) return

clearSelectErrors()
// this line taken from docs https://select2.org/programmatic-control/add-select-clear-items
$('#case-selection').val(null).trigger('change')
}

$(() => { // JQuery's callback for the DOM loading
$('button.copy-court-button').on('click', copyOrdersFromCaseWithConfirmation)

if ($('button.copy-court-button').length) {
disableBtn($('button.copy-court-button')[0])
}

$('#case-selection').on('change', clearSelectErrors)

$('select.siblings-casa-cases').on('change', () => {
if ($('select.siblings-casa-cases').find(':selected').text()) {
enableBtn($('button.copy-court-button')[0])
} else {
disableBtn($('button.copy-court-button')[0])
}
})
// modal id is defined in _generate_docx.html.erb so would like to be able to implement modal close logic in that file
// but not sure how to
$('#generate-docx-report-modal').on('hidden.bs.modal', () => handleModalClose())

$('#btnGenerateReport').on('click', handleGenerateReport)

Expand Down
19 changes: 11 additions & 8 deletions app/views/case_court_reports/_generate_docx.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@

<% select_case_prompt = show_search ? "Search by volunteer name or case number" : "Select case number" %>
<% select2_class = show_search ? " select2" : "" %>
<%= select_tag :case_number,
options_for_select(select_options),
prompt: select_case_prompt,
include_blank: false,
id: "case-selection",
class: "custom-select#{select2_class}",
data: { dropdown_parent: "##{id}" } %>

<div class="select-wrapper">
<%= select_tag :case_number,
options_for_select(select_options),
prompt: select_case_prompt,
include_blank: false,
id: "case-selection",
class: "custom-select#{select2_class}",
required: true,
data: { dropdown_parent: "##{id}", width: "100%" } %>
<p class="select-required-error text-danger d-none">Case selection is required.</p>
</div>
<%= form.hidden_field :time_zone, id: "user-time-zone" %>
</div>
<div class="dates-container">
Expand Down
Loading