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

Change award year switch to submit form on change #2993

Merged
merged 3 commits into from
Jul 4, 2024
Merged
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
20 changes: 14 additions & 6 deletions app/assets/javascripts/admin/applications-filter.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,27 @@ filterApplicationsDropdowns = () ->
.length
$(this).closest(".applications-filter").find("label[data-value='select_all'] input").prop("checked", unselected is 0)

# On clicking the award year radio
# On clicking the award year radios
$(document).on "click", ".applications-filter .input__award-years input[type='radio']", (e) ->
e.stopPropagation()
# if other selected, show dropdown of years, otherwise get form answers for current year or all years
# if other selected, show dropdown of years, otherwise submit form
if $(this).attr('id') == "other"
dropdownWrapper = $(this).closest(".applications-filter").find(".other-years-dropdown")
dropdownWrapper.removeClass("hide")
dropdown = dropdownWrapper.find(".dropdown-toggle")
dropdown.focus().click()
else
search_query = $(this).closest(".new_search").find("#search_query").val()
url = new URL($(this).data('url'), document.baseURI)
url.searchParams.set('[search][query]', search_query)
window.location = url
selected_year = $(this).val()
$(this).closest(".input__award-years").find("select option[value='#{selected_year}']").attr('selected', true).change()
$(this).closest('form').submit()

# On clicking the award year from the other year dropdown
$(document).on "click", ".applications-filter .other-years-dropdown .dropdown-menu li", (e) ->
e.stopPropagation()
e.preventDefault()
# Set value of other radio button to selected year and submit
selected_year = $(this).attr('id')
$(this).closest(".input__award-years").find("select option[value='#{selected_year}']").attr('selected', true).change()
$(this).closest('form').submit()

$(document).ready(ready)
1 change: 0 additions & 1 deletion app/views/admin/form_answers/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ h1.admin-page-heading
= f.label :query, "Search", class: "search-input__label"
= f.hint "By company name, reference number or category", class: "search-input__hint"
.form-group.search-input
= text_field_tag :year, params[:year] || @award_year.year, class: "visuallyhidden", aria: { hidden: true }
= f.input :query, label: false, input_html: { class: "form-control", type: "search", aria: { label: 'Search applications' }}
= submit_tag :submit, class: 'search-submit'

Expand Down
1 change: 0 additions & 1 deletion app/views/assessor/form_answers/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ h1.admin-page-heading
= f.label :query, "Search", class: "search-input__label"
= f.hint "By company name, reference number or category", class: "search-input__hint"
.form-group.search-input
= text_field_tag :year, params[:year] || @award_year.year, class: "visuallyhidden", aria: { hidden: true }, id: "award_year", tabindex: "-1"
= text_field_tag :award_type, params[:award_type], class: "visuallyhidden", aria: { hidden: true }, tabindex: "-1"
= f.input :query, label: false, input_html: { class: "form-control", type: "search", aria: {label: 'Search applications'} }
= submit_tag :submit, class: 'search-submit'
Expand Down
54 changes: 32 additions & 22 deletions app/views/shared/form_answers/_admin_award_year.html.slim
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
- current_year = AwardYear.current.year
- selected_year = params[:year] ? params[:year].to_i : current_year
- other_years = AwardYear.admin_switch.keys
- other_years = AwardYear.admin_switch.keys.select{ |year| year <= current_year }

fieldset.award-year-z-index.applications-filter.award-year-radios
label.applications-filter__label
' Award year
.input__award-years
input type="radio" id="current_year" name="year" value="#{current_year}" data-url="#{url_for(params.permit(:controller, :action).merge(year: current_year, search: params[:search]))}" checked=(current_year == params[:year].to_i || (namespace_name == :assessor && !params[:year]))
label for="current_year"
| Current year
input type="radio" id="all_years" name="year" value="all_years" data-url="#{url_for(params.permit(:controller, :action).merge(year: :all_years, search: params[:search]))}" checked=(params[:year].to_s == 'all_years' || (namespace_name == :admin && !params[:year]))
label for="all_years"
| All years
input type="radio" id="other" name="year" value="#{selected_year}" checked=(current_year != selected_year && other_years.include?(params[:year].to_i))
label for="other"
| Other
.if-no-js-hide
input type="radio" id="current_year" name="award_year" value="#{current_year}" checked=(current_year == params[:year].to_i || (namespace_name == :assessor && other_years.exclude?(params[:year].to_i)))
label for="current_year"
| Current year
input type="radio" id="all_years" name="award_year" value="all_years" checked=(params[:year].to_s == 'all_years' || (namespace_name == :admin && other_years.exclude?(params[:year].to_i)))
label for="all_years"
| All years
input type="radio" id="other" name="award_year" value="#{selected_year}" checked=(current_year != selected_year && other_years.include?(params[:year].to_i))
label for="other"
| Other

.dropdown.other-years-dropdown class="#{(current_year != selected_year && other_years.include?(params[:year].to_i) ? '' : 'hide')}"
a.dropdown-toggle.btn.btn-block.btn-default href="#" data-toggle="dropdown" role="button" aria-expanded="false"
- current_year_text = params[:year].to_s == "all_years" || !params[:year] || !other_years.include?(params[:year].to_i) ? "All Years" : "#{selected_year - 1} - #{selected_year}"
.dropdown.other-years-dropdown class="#{(current_year != selected_year && other_years.include?(params[:year].to_i) ? '' : 'hide')}"
a.dropdown-toggle.btn.btn-block.btn-default href="#" data-toggle="dropdown" role="button" aria-expanded="false"
- current_year_text = params[:year].to_s == "all_years" || !params[:year] || !other_years.include?(params[:year].to_i) ? "All Years" : "#{selected_year - 1} - #{selected_year}"

= current_year_text
span.caret-container
span.caret
ul.dropdown-menu.dropdown-menu-right
li class="#{'active' if params[:year].to_s == 'all_years' || !params[:year]}"
= link_to "All Years", url_for(params.permit(:controller, :action).merge(year: :all_years, search: params[:search]))
= current_year_text
span.caret-container
span.caret
ul.dropdown-menu.dropdown-menu-right
li class="#{'active' if params[:year].to_s == 'all_years' || !params[:year]}" id="all_years"
= link_to "All Years", "#"

- AwardYear.admin_switch.each do |year, label|
li class="#{'active' if label == current_year_text}"
= link_to label, url_for(params.permit(:controller, :action).merge(year: year, search: params[:search]))
- AwardYear.admin_switch.each do |year, label|
- if year <= current_year
li class="#{'active' if label == current_year_text}" id="#{year}"
= link_to label, "#"

select name="year" id="award_year" class="form-control if-js-hide"
option value="all_years" selected=(params[:year].to_s == 'all_years' || (namespace_name == :admin && other_years.exclude?(params[:year].to_i)))
| All years
- AwardYear.admin_switch.each do |year, label|
- if year <= current_year
option value="#{year}" selected=(year == selected_year)
= label
Loading