* errors sorted

This commit is contained in:
Seth Call 2016-02-08 12:31:45 -06:00
parent fa9aabed55
commit 0707c9054b
2 changed files with 15 additions and 5 deletions

View File

@ -132,21 +132,31 @@ proficiencyDescriptionMap = {
else
context.location = '/client#/jamclass/payment'
resetErrors: () ->
@setState({generalErrors:null, slot1Errors:null, slot2Errors:null, descriptionError:null})
failedBooking: (jqXHR) ->
if jqXHR.status == 422
body = JSON.parse(jqXHR.responseText)
logger.debug("BODY", body)
generalErrors = []
for errorType, errors of body.errors
if errorType == 'description'
@setState({descriptionError: errors})
else if errorType == 'lesson_booking_slots'
@setState({})
else
error = {}
error[errorType] = errors
generalErrors.push(errors)
for childErrorType, childErrors of body._children
if childErrorType == 'lesson_booking_slots'
slot1Errors = childErrors[0]
slot2Errors = childErrors[1]
if Object.keys(slot1Errors["errors"]).length > 0
@setState({slot1Errors: slot1Errors["errors"]})
if Object.keys(slot2Errors["errors"]).length > 0
@setState({slot2Errors: slot2Errors["errors"]})
if childErrors.length > 0
@setState({childErrorType, childErrors})
@setState({generalErrors: generalErrors})
onCancel: (e) ->

View File

@ -40,14 +40,14 @@ class ApiController < ApplicationController
protected
def recursive_errors(model, children)
response = {errors:model.errors.to_json, _children:{}}
response = {errors:model.errors, _children:{}}
children_response = response[:_children]
children.each do |child|
child_response = []
associations = model.send(child)
if associations
associations.each do |association|
child_response << {errors: association.errors.to_json}
child_response << {errors: association.errors}
end
end
children_response[child] = child_response