diff --git a/app/assets/javascripts/conditionalRadios.js b/app/assets/javascripts/conditionalRadios.js index bb337f984..40de0b10e 100644 --- a/app/assets/javascripts/conditionalRadios.js +++ b/app/assets/javascripts/conditionalRadios.js @@ -6,18 +6,35 @@ this.start = function(component) { const $radios = $('[type=radio]', $(component)), - showHidePanels = function() { - $radios.each(function() { - $('#panel-' + $(this).attr('value')) - .toggleClass( - 'js-hidden', - !$(this).is(":checked") - ); - }); - }; + $checkboxes = $('[type=checkbox]', $(component)); - $radios.on('click', showHidePanels); - showHidePanels(); + let clearable = true; + + let clearInvalidSelections = function() { + if (!clearable) { + clearable = true; + return; + } + $radios.each(function() { + let checked = $(this).is(':checked'); + $('#panel-' + $(this).attr('value')) + .each(function() { + if (!checked) { + $('[type=checkbox]', this).removeAttr('checked'); + } + }); + }); + }; + + let selectParent = function() { + clearable = false; + let parentValue = $(this).parents("[id^='panel-']").attr('id').replace('panel-', ''); + $('[value=' + parentValue + ']').trigger('click'); + }; + + $checkboxes.on('click', selectParent); + $radios.on('click', clearInvalidSelections); + clearInvalidSelections(); }; }; diff --git a/app/assets/stylesheets/components/conditional-radios.scss b/app/assets/stylesheets/components/conditional-radios.scss index c5cb2c803..60cec6f32 100644 --- a/app/assets/stylesheets/components/conditional-radios.scss +++ b/app/assets/stylesheets/components/conditional-radios.scss @@ -1,4 +1,5 @@ $border-thickness: 9px; +$top-spacing: $gutter + 5px; .multiple-choice { @@ -6,7 +7,7 @@ $border-thickness: 9px; .block-label { &:before { - box-shadow: 0 4px 0 0 $white; + box-shadow: 0 5px 0 0 $white; } } @@ -16,10 +17,10 @@ $border-thickness: 9px; &-panel { border-left: $border-thickness solid $border-colour; - margin: 0 0 0 ($border-thickness + 6px); - padding: $gutter-one-third 0 0 ($gutter - 3px); + margin: 0 0 (-$top-spacing - $gutter) $gutter-half; + padding: $top-spacing 0 0 ($gutter - 3px); position: relative; - top: -$gutter-one-third; + top: -$top-spacing; z-index: 1; } diff --git a/app/templates/components/radios.html b/app/templates/components/radios.html index f36a4647b..fe05defc0 100644 --- a/app/templates/components/radios.html +++ b/app/templates/components/radios.html @@ -137,7 +137,7 @@ {% endmacro %} {% macro conditional_radio_panel(id) %} -
+
{{ caller() }}
{% endmacro %} diff --git a/app/templates/views/manage-users/permissions.html b/app/templates/views/manage-users/permissions.html index 17b1a2de5..7c8fecd23 100644 --- a/app/templates/views/manage-users/permissions.html +++ b/app/templates/views/manage-users/permissions.html @@ -2,25 +2,21 @@ {% from "components/radios.html" import radio, radios, radios_wrapper, conditional_radio_panel %} {% if 'caseworking' in current_service.permissions %} -
- {% call radios_wrapper(form.user_type, hide_legend=True) %} +
+ {% call radios_wrapper(form.user_type) %} {% for option in form.user_type %} - {{ radio(option) }} + +
+ {{ radio(option, option_hints={ + 'admin': 'See dashboard and team members', + 'caseworker': 'Send messages and see sent messages' + }) }} +
{% if option.data == 'admin' %} - {% call conditional_radio_panel(option.data) %} -
-

- All admin users can see -

-
    -
  • templates
  • -
  • history of sent messages
  • -
  • who the other team members are
  • -
-
+ {% call conditional_radio_panel('admin') %}
- Permissions + Extra permissions {{ checkbox(form.send_messages) }} {{ checkbox(form.manage_templates) }} @@ -29,9 +25,11 @@
{% endcall %} {% endif %} + {% endfor %} {% endcall %}
+ {% else %}