Skip to content

Commit

Permalink
Merge pull request #2616 from bitzesty/revert-2615-assessor-form-impr…
Browse files Browse the repository at this point in the history
…ovements-cherry-pick

Revert "Re-work appraisal form submissions"
  • Loading branch information
TheDancingClown authored Sep 28, 2023
2 parents 6d91258 + a4e50f2 commit 91cb03e
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 267 deletions.
34 changes: 28 additions & 6 deletions app/assets/javascripts/admin/form_answers.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,29 @@ ready = ->
if (element)
element.classList.add('form-edit')

$(document).on "click", ".form-save-link:not(.js-form-save-link)", (e) ->
$('.submit-assessment').on 'ajax:error', (e, data, status, xhr) ->
panel = this.closest('.panel-body')
errors = data.responseJSON

removeExistingErrorMessages(panel)

Object.entries(errors).forEach ([key, values]) ->
field = panel.querySelector("[name*='[#{key}]']")
if field and shouldValidateField(field)
showErrorForInvalidField(field, values)

$(".submit-assessment").on "ajax:success", (e, data, status, xhr) ->
panel = this.closest('.panel-body')
message = "Assessment submitted"
if panel.closest(".panel-collapse").classList.contains('section-case-summary')
message = "Case summary submitted"

removeExistingErrorMessages(panel)
panel.insertAdjacentHTML('afterbegin', buildBannerHtml(message, 'success'))

$(this).find('input:submit').remove()

$(document).on "click", ".form-save-link", (e) ->
link = $(this)
e.preventDefault()
formGroup = link.closest(".form-group")
Expand Down Expand Up @@ -371,11 +393,11 @@ ready = ->
input.val(updatedSection)
form.submit()
else
if area.first().val().length
formGroup.find(".form-value p:first").html(area.first().val().replace(/\n/g, '<br />'))
if area.last().val().length
formGroup.find(".form-value p:last").html(area.last().val().replace(/\n/g, '<br />'))
form.submit()
if area.first().val().length
formGroup.find(".form-value p:first").html(area.first().val().replace(/\n/g, '<br />'))
if area.last().val().length
formGroup.find(".form-value p:last").html(area.last().val().replace(/\n/g, '<br />'))
form.submit()

$("#new_review_audit_certificate input[type='radio']").on "change", ->
area = $(".audit-cert-description")
Expand Down
5 changes: 0 additions & 5 deletions app/assets/stylesheets/admin/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1619,11 +1619,6 @@ label.govuk-label.govuk-checkboxes__label.boolean.optional.govuk-label {
}
}

.rag-error {
background-color: #f2dede;
color: #a94442 !important;
}

.rag-blank {
&,
a,
Expand Down
189 changes: 0 additions & 189 deletions app/javascript/controllers/appraisal_form_controller.js

This file was deleted.

27 changes: 3 additions & 24 deletions app/models/assessor_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,7 @@ def not_submitted_or_not_locked?
def award_specific_attributes
struct.diff(form_answer, moderated?).each do |att|
if public_send(att).present?
message = if att.ends_with?("_rate")
"RAG rating for '#{section_name(att)}' cannot be present for this Award Type"
else
"An appraisal comment for '#{section_name(att)}' cannot be present for this Award Type"
end

errors.add(att, message: message)
errors.add(att, "cannot be present for this Award Type")
end
end
end
Expand All @@ -168,13 +162,7 @@ def mandatory_fields_for_submitted

struct.meths_for_award_type(form_answer, moderated?).each do |meth|
if public_send(meth).blank?
message = if meth.ends_with?("_rate")
"RAG rating is required for '#{section_name(meth)}'. Select an option from the dropdown list."
else
"An appraisal comment is required for '#{section_name(meth)}' and must be filled in."
end

errors.add(meth, message: message)
errors.add(meth, "cannot be blank for submitted assessment")
end
end
end
Expand All @@ -186,8 +174,7 @@ def validate_rate(rate_type)
c = "#{rate_type.upcase}_ALLOWED_VALUES"
if val && !struct.const_get(c).include?(val)
sect_name = struct.rate(section)
message = "#{rate_type} field for '#{section_name(section)}' has not permitted value."
errors.add(sect_name, message: message)
errors.add(sect_name, "#{rate_type} field has not permitted value")
end
end
end
Expand All @@ -196,14 +183,6 @@ def section_rate(section)
public_send(struct.rate(section))
end

def section_name(key)
@_sections ||= struct.struct(form_answer).to_h
section_key = key.to_s.gsub(/_desc$/, "").gsub(/_rate$/, "")
if section = @_sections.dig(section_key.to_sym)
section[:label].gsub(/:$/, "")
end
end

def struct
AppraisalForm
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
small
= moderated_assessment.last_editor_info

#section-appraisal-form-moderated.section-appraisal-form.section-appraisal-form-moderated.panel-collapse.collapse[aria-labelledby="appraisal-form-moderated-heading" data-controller="appraisal-form" data-appraisal-form-success-value="Appraisal form (moderated) has been submitted"]
#section-appraisal-form-moderated.section-appraisal-form.section-appraisal-form-moderated.panel-collapse.collapse[aria-labelledby="appraisal-form-moderated-heading"]
.panel-body[data-controller="inline-flash"]
= simple_form_for([namespace_name, moderated_assessment],
remote: true,
authenticity_token: true,
html: { data: { type: "json", inline_flash_target: "form" } }) do |f|
html: { data: { type: "json", inline_flash_target: "form", controller: "html5-form-validation", html5_form_validation_selectors_value: ["textarea"] } }) do |f|

= render_section(resource, f)
= hidden_field_tag :updated_section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
- if primary_assessment.last_editor_info.present?
small
= primary_assessment.last_editor_info
#section-appraisal-form-primary.section-appraisal-form.section-appraisal-form-primary.panel-collapse.collapse[aria-labelledby="appraisal-form-primary-heading" data-controller="appraisal-form" data-appraisal-form-success-value="Appraisal form (primary) has been submitted"]
#section-appraisal-form-primary.section-appraisal-form.section-appraisal-form-primary.panel-collapse.collapse aria-labelledby="appraisal-form-primary-heading"
.panel-body[data-controller="inline-flash"]
= simple_form_for([namespace_name, primary_assessment],
remote: true,
authenticity_token: true,
html: { data: { type: "json", inline_flash_target: "form" }, id: "primary_appraisal_form" }) do |f|
html: { data: { type: "json", inline_flash_target: "form", html5_form_validation_selectors_value: ["textarea"], controller: "html5-form-validation" }, id: "primary_appraisal_form" }) do |f|

= hidden_field_tag :updated_section, nil, id: "primary_updated_section_hidden_field"
= render_section(resource, f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
- if secondary_assessment.last_editor_info.present?
small
= secondary_assessment.last_editor_info
#section-appraisal-form-secondary.section-appraisal-form.section-appraisal-form-secondary.panel-collapse.collapse[aria-labelledby="appraisal-form-secondary-heading" data-controller="appraisal-form" data-appraisal-form-success-value="Appraisal form (secondary) has been submitted"]
#section-appraisal-form-secondary.section-appraisal-form.section-appraisal-form-secondary.panel-collapse.collapse aria-labelledby="appraisal-form-secondary-heading"
.panel-body[data-controller="inline-flash"]
= simple_form_for([namespace_name, secondary_assessment],
remote: true,
authenticity_token: true,
html: { data: { type: "json", inline_flash_target: "form" }, id: "secondary_appraisal_form"}) do |f|
html: { data: { type: "json", inline_flash_target: "form", controller: "html5-form-validation", html5_form_validation_selectors_value: ["textarea"] }, id: "secondary_appraisal_form"}) do |f|

= hidden_field_tag :updated_section, nil, id: "secondary_updated_section_hidden_field"
= render_section(resource, f)
Expand Down
13 changes: 11 additions & 2 deletions app/views/admin/form_answers/_section_case_summary.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@
- if assessment.editable.present?
small
= "Updated by #{message_author_name(assessment.editable)} - #{format_date(assessment.updated_at)}"
.panel-collapse.collapse[aria-labelledby="case-summary-heading-#{assessment.position}" id="section-case-summary-#{assessment.position}" class="section-case-summary-#{assessment.position}" data-controller="appraisal-form" data-appraisal-form-success-value="Case summary has been submitted"]
.panel-collapse.collapse aria-labelledby="case-summary-heading-#{assessment.position}" id="section-case-summary-#{assessment.position}" class="section-case-summary-#{assessment.position}"

.panel-body[data-controller="inline-flash"]
= simple_form_for([namespace_name, assessment], remote: true, authenticity_token: true, html: { data: { inline_flash_target: "form" } }) do |f|
/.alert.alert-glyphicon.alert-info
span.glyphicon.glyphicon-info-sign
p.todo-placeholder
' Some instructions on how to use this or what this section is about. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Duis mollis, est non commodo luctus.
/ Only show if Moderated Appraisal is submitted
/ For Primary Assessor
/ It becomes read-only for primary assessor after submission
= simple_form_for([namespace_name, assessment], remote: true, authenticity_token: true, html: { data: { inline_flash_target: "form", controller: "html5-form-validation", html5_form_validation_selectors_value: ["textarea"] } }) do |f|
= render partial: "admin/form_answers/appraisal_form_components/application_background_section",
locals: { f: f}
= render_section(resource, f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
= link_to "#", class: "form-edit-link pull-right", data: { element_focus_target: "reveal" }
span.glyphicon.glyphicon-pencil
' Edit
= link_to "Save", "#", class: "btn btn-primary form-save-link js-form-save-link pull-right if-no-js-hide", data: { action: "click->appraisal-form#stash" }
= link_to "Save", "#", class: "btn btn-primary form-save-link pull-right if-no-js-hide", data: { action: "click->html5-form-validation#validate" }
.clear
Loading

0 comments on commit 91cb03e

Please sign in to comment.