Skip to content

Commit

Permalink
Merge pull request #722 from bitzesty/staging
Browse files Browse the repository at this point in the history
Production < Staging
  • Loading branch information
TheDancingClown authored Aug 29, 2024
2 parents 79edf85 + 7fa4bcd commit 817e010
Show file tree
Hide file tree
Showing 81 changed files with 1,224 additions and 500 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ PLATFORMS
arm64-darwin-21
arm64-darwin-23
x86_64-darwin-22
x86_64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ jQuery ->
height: 200
wordcount:
maxWordCount: $(this).data('word-max')
versionCheck: false

CKEDITOR.on 'instanceCreated', (event) ->
editor = event.editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,48 @@ window.SupportLetters =
init: ->
$('.js-support-letter-attachment').each (idx, el) ->
SupportLetters.fileupload_init(el)
SupportLetters.save_collection_init()

$(document).on 'change', '.js-trigger-autosave', debounce(SupportLetters.submit, 1000)

$(document).on 'click', '.js-remove-support-letter-attachment', (e) ->
e.preventDefault()
SupportLetters.removeFile($(this).closest('.govuk-form-group').find('input:first'), e)

new_item_init: (el) ->
SupportLetters.clean_up_system_tags(el)
SupportLetters.enable_item_fields_and_controls(el)
SupportLetters.fileupload_init(el.find(".js-support-letter-attachment"))
SupportLetters.fileupload_init(el.find('.js-support-letter-attachment'))
el.find('input,textarea,select').first().focus()

fileupload_init: (el) ->
$el = $(el)
parent = $el.closest(".govuk-form-group")
parent = $el.closest('.govuk-form-group')

upload_done = (e, data) ->
SupportLetters.clean_up_system_tags(parent)

if data.result['original_filename']
filename = data.result['original_filename']
else
filename = "File uploaded"
file_title = $("<p class='govuk-body support-letter-attachment-filename'>" + filename + "</p>")
hidden_input = $("<input class='js-support-letter-attachment-id' type='hidden' name='#{$el.attr("name")}' value='#{data.result['id']}' />")

parent.find(".govuk-error-message").html("")
parent.find(".govuk-error-message").closest(".govuk-form-group").removeClass("govuk-form-group--error")
parent.append(file_title)
parent.append(hidden_input)
filename = 'File uploaded'

parent.find('.govuk-error-message').html('')
parent.find('.govuk-error-message').closest('.govuk-form-group').removeClass('govuk-form-group--error')

textContainer = parent.find('.support-letter-attachment-container')
textContainer.removeClass('govuk-!-display-none')
scanningText = '<p class="govuk-hint">(File uploaded and is being scanned for viruses. Preview available once the scan is complete. You may need to refresh this page.)</p>'
textContainer.prepend('<div class="support-letter-attachment-filename"><p class="govuk-body">' + filename + '</p>' + scanningText + '</div>')
hiddenInput = $("<input class='js-support-letter-attachment-id' type='hidden' name='#{$el.attr("name")}' value='#{data.result['id']}' />")
parent.append(hiddenInput)
parent.find('.js-support-letter-attachment').addClass('govuk-!-display-none')
SupportLetters.autosave()
SupportLetters.submit(e)

failed = (error_message) ->
SupportLetters.clean_up_system_tags(parent)
parent.find(".govuk-error-message").html(error_message)
parent.closest(".govuk-form-group").addClass("govuk-form-group--error")
parent.find('.govuk-error-message').html(error_message)
parent.closest('.govuk-form-group').addClass('govuk-form-group--error')

success_or_error = (e, data) ->
errors = data.result.errors
Expand All @@ -44,108 +54,39 @@ window.SupportLetters =
upload_done(e, data)

$el.fileupload(
url: $el.closest(".list-add").data('attachments-url') + ".json"
url: $el.closest('.list-add').data('attachments-url') + '.json'
forceIframeTransport: true
dataType: 'json'
formData: [
{ name: "authenticity_token", value: $("meta[name='csrf-token']").attr("content") }
{ name: 'authenticity_token', value: $('meta[name="csrf-token"]').attr('content') }
]
always: success_or_error
)

clean_up_system_tags: (parent) ->
parent.find("input[type='hidden']").remove()
parent.find(".support-letter-attachment-filename").remove()
parent.find('input[type="hidden"]').remove()
parent.find('.support-letter-attachment-filename').remove()

removeFile: (el, e) ->
$el = $(el)
$el.val('')
$el.siblings('.js-support-letter-attachment-id').first().val('')
$el.siblings('.support-letter-attachment-container').addClass('govuk-!-display-none')
$el.removeClass('govuk-!-display-none')
SupportLetters.autosave()
SupportLetters.submit(e)

enable_item_fields_and_controls: (parent) ->
parent.find(".js-save-collection").removeClass("govuk-!-display-none")
parent.find(".visible-read-only").hide()
fields = parent.find("input")
fields.removeClass("read-only")
parent.find(".govuk-error-message").html("")
form_name_prefix = parent.find(".js-system-tag").data("new-hidden-input-name")
letter_id_hidden_input = $("<input class='js-support-entry-id'>").prop('type', 'hidden').
prop('name', form_name_prefix)
parent.append(letter_id_hidden_input)

disable_item_fields_and_controls: (parent) ->
parent.find(".js-save-collection").addClass("govuk-!-display-none")
parent.find(".visible-read-only").show()
fields = parent.find("input")
fields.addClass("read-only")

save_collection_init: () ->
$(document).on 'click', '.js-save-collection', (e) ->
e.preventDefault()
e.stopPropagation()

button = $(this)
parent = $(this).closest("li")

if !button.hasClass("govuk-!-display-none")
save_url = button.data 'save-collection-url'

first_name = parent.find(".js-support-letter-first-name").val()
last_name = parent.find(".js-support-letter-last-name").val()
email = parent.find(".js-support-letter-email").val()
relationship_to_nominee = parent.find(".js-support-letter-relationship-to-nominee").val()
attachment_id = parent.find(".js-support-letter-attachment-id").val()

data = {
"support_letter": {
"first_name": first_name,
"last_name": last_name,
"relationship_to_nominee": relationship_to_nominee
}
}

if attachment_id
data["support_letter"]["attachment"] = attachment_id

if email
data["support_letter"]["email"] = email

if save_url
$.ajax
url: save_url
type: 'post'
data: data
dataType: 'json'
success: (response) ->
parent.find(".js-support-entry-id").prop('value', response)
parent.find(".govuk-error-message").html("")
parent.removeClass("govuk-form-group--error")
parent.addClass("read-only")
parent.addClass("js-support-letter-received")
parent.closest('li').find("input[type='text']").each ->
show_el = $(this).closest(".govuk-form-group").find(".visible-read-only")
show_el.text($(this).val())
SupportLetters.disable_item_fields_and_controls(parent)
window.FormValidation.validateStep()
SupportLetters.autosave()
SupportLetters.showRemoveLink(parent, data, response)

return
error: (response) ->
parent.find(".govuk-error-message").html("")
parent.removeClass("govuk-form-group--error")
error_message = response.responseText
$.each $.parseJSON(response.responseText), (question_key, error_message) ->
key_selector = ".js-support-letter-" + question_key.replace(/_/g, "-")
field_error_container = parent.find(key_selector).
closest(".govuk-form-group").
find(".govuk-error-message")
field_error_container.html(error_message[0])
field_error_container.closest(".govuk-form-group").addClass("govuk-form-group--error")
button.removeClass("govuk-visually-hidden")

return
parent.find('.govuk-error-message').html('')
prefixed = parent.find('.js-system-tag').data('new-hidden-input-name')
hiddenInput = $('<input class="js-support-entry-id">').prop('type', 'hidden').prop('name', prefixed)
parent.append(hiddenInput)

autosave: () ->
url = $('form.qae-form').data('autosave-url')
if url
# Setting current_step_id to form as we updating only current section form_data (not whole form)
$("#current_step_id").val($(".js-step-condition.step-current").attr("data-step"))
$('#current_step_id').val($('.js-step-condition.step-current').attr('data-step'))

form_data = $('form.qae-form').serialize()
$.ajax({
Expand All @@ -155,8 +96,71 @@ window.SupportLetters =
dataType: 'json'
})

showRemoveLink: (parent, data, response) ->
removeLink = $(".remove-supporter", parent)
removeLink.data("url", "/users/form_answers/#{response['form_answer_id']}/support_letters/#{response['id']}")
removeLink.attr("aria-label", "Delete support letter from #{data['support_letter']['first_name']} #{data['support_letter']['last_name']}")
removeLink.removeClass("govuk-!-display-none")
submit: (e) ->
e.preventDefault()
e.stopPropagation()

target = $(e.target)
parent = target.closest("li")

data = {'support_letter': {}}
data['support_letter']['first_name'] = parent.find('.js-support-letter-first-name').val()
data['support_letter']['last_name'] = parent.find('.js-support-letter-last-name').val()
data['support_letter']['relationship_to_nominee'] = parent.find('.js-support-letter-relationship-to-nominee').val()

attachmentId = parent.find('.js-support-letter-attachment-id').val()
if attachmentId
data['support_letter']['attachment'] = attachmentId

email = parent.find('.js-support-letter-email').val()
if email
data['support_letter']['email'] = email

createUrl = parent.data('create-url')
updateUrl = parent.data('update-url')
persistUrl = updateUrl || createUrl

type = if !!updateUrl
'put'
else
'post'

if persistUrl
$.ajax
url: persistUrl
type: type
data: data
dataType: 'json'
success: (response) ->
parent.find('.js-support-entry-id').prop('value', response['id'])
parent.find('.govuk-error-message').html('')
parent.removeClass('govuk-form-group--error')
parent.addClass('js-support-letter-received')
parent.attr('data-update-url', response['update_url'])
window.FormValidation.validateStep()
SupportLetters.autosave()

return
error: (response) ->
parent.find('.govuk-error-message').html('')
parent.removeClass('govuk-form-group--error')
msg = response.responseText
$.each $.parseJSON(response.responseText), (key, msg) ->
selector = '.js-support-letter-' + key.replace(/_/g, '-')

errorContainer = parent.find(selector).closest('.govuk-form-group').find('.govuk-error-message')
errorContainer.html(msg[0])
errorContainer.closest('.govuk-form-group').addClass('govuk-form-group--error')

return

debounce = (fn, wait = 500) ->
last = (new Date) - wait
->
now = new Date

# Return if we haven't waited long enough
return if wait > (now - last)

fn.apply null, arguments
last = now
21 changes: 7 additions & 14 deletions app/assets/javascripts/frontend/form-validation.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ window.FormValidation =
clearErrors: (container) ->
if container.closest(".question-financial").length > 0
container.closest("label").find(".govuk-error-message").empty()
else if container.closest('.question-block').data('answer').indexOf('address') > -1
else if container.closest('.question-block').data('answer') && container.closest('.question-block').data('answer').indexOf('address') > -1
container.closest(".govuk-form-group").find(".govuk-error-message").empty()
else
container.closest(".question-block").find(".govuk-error-message").empty()
Expand Down Expand Up @@ -56,6 +56,9 @@ window.FormValidation =
isCheckboxQuestion: (question) ->
question.find("input[type='checkbox']").length

isSupportLetterAttachment: (question) ->
question.find(".js-support-letter-attachment").length

toDate: (str) ->
moment(str, "DD/MM/YYYY")

Expand All @@ -81,6 +84,9 @@ window.FormValidation =
if @isCheckboxQuestion(question)
return question.find("input[type='checkbox']").filter(":checked").length

if @isSupportLetterAttachment(question)
return (question.find(".js-support-letter-attachment-id").val() || '').toString().trim().length

validateRequiredQuestion: (question) ->
# if it's a conditional question, but condition was not satisfied
conditional = true
Expand Down Expand Up @@ -352,13 +358,6 @@ window.FormValidation =
@addErrorMessage(question, errorMessage)
return

validateSupportLetters: (question) ->
lettersReceived = $(".js-support-letter-received").length
if lettersReceived < 2
@logThis(question, "validateSupportLetters", "Upload two letters of support")
@appendMessage(question, "Upload two letters of support")
@addErrorClass(question)

validateSelectionLimit: (question) ->
selection_limit = question.data("selection-limit")
current_selection_count = question.find("input[type=checkbox]:checked").length
Expand Down Expand Up @@ -455,11 +454,6 @@ window.FormValidation =
# console.log "validateDropBlockCondition"
@validateDropBlockCondition(question)

if question.hasClass("question-support-requests") ||
question.hasClass("question-support-uploads")
# console.log "validateSupportLetters"
@validateSupportLetters(question)

if question.hasClass("question-limited-selections")
@validateSelectionLimit(question)

Expand Down Expand Up @@ -489,7 +483,6 @@ window.FormValidation =
stepContainer.find(".govuk-form-group--error").removeClass("govuk-form-group--error")
stepContainer.find(".govuk-error-message").empty()
$(".steps-progress-bar .js-step-link[data-step='" + currentStep + "']").removeClass("step-errors")

for question in stepContainer.find(".question-block")
question = $(question)
@validateIndividualQuestion(question)
41 changes: 41 additions & 0 deletions app/assets/stylesheets/admin/tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,44 @@
[role="region"][aria-labelledby][tabindex]:focus {
outline: .1em solid rgba(0,0,0,.1);
}

.kavs-table {
border-top: 1px solid #b1b4b6;
border-bottom: 1px solid #b1b4b6;
width: max-content;

.text-center {
text-align: center;
}

thead {
background-color: #f2f2f2;

.govuk-table__header:last-child,
.govuk-table__cell:last-child,
.govuk-table__footer:last-child {
padding-right: 10px;
}
}

tfoot {
&.govuk-table__footer {
background-color: #f2f2f2;
font-weight: 700;
text-align: left;
}
}
}

.kavs-table__header--dense,
.kavs-table__cell--dense,
.kavs-table__footer--dense {
font-size: 1rem;
padding: 10px
}

.kavs-table__header--border-right,
.kavs-table__cell--border-right,
.kavs-table__footer--border-right {
border-right: 1px solid #b1b4b6;
}
Loading

0 comments on commit 817e010

Please sign in to comment.