Skip to content

Commit

Permalink
jl & wth - Redcap API
Browse files Browse the repository at this point in the history
Built form to send data over to RedCap. [#142789871] [#142789881]

Keeping old code of Feedback, adding in constant for testing of new
version.

added js error handling

Changing how we convert the date.
  • Loading branch information
jleonardw9 authored and William Holt committed Apr 20, 2017
1 parent 0cead37 commit 89ac31f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@
//= require surveyor/surveys
//= require sweetalert.min
//= require update_visit_group
//= require feedback
23 changes: 23 additions & 0 deletions app/assets/javascripts/feedback.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$.fn.clear_form_errors = () ->
this.find('.form-group').removeClass('has-error')
this.find('span.help-block').remove()

$.fn.render_form_errors = (model_name, errors) ->
form = this
this.clear_form_errors()

$.each(errors, (field, messages) ->
input = form.find('input, select, textarea').filter(->
name = $(this).attr('name')
if name
name.match(new RegExp(model_name + '\\[' + field + '\\(?'))
)
input.closest('.form-group').addClass('has-error')
input.parent().append('<span class="help-block">' + $.map(messages, (m) -> m.charAt(0).toUpperCase() + m.slice(1)).join('<br />') + '</span>')
)

$ ->

$('#modal_place').on 'shown.bs.modal', ->
$(document).ajaxError (e, data) ->
$('.new_feedback').render_form_errors('feedback', JSON.parse(data.responseText))
13 changes: 8 additions & 5 deletions app/controllers/feedback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ def new

def create
@feedback = Feedback.new(feedback_params)
if @feedback.valid?
emitter = RedcapSurveyEmitter.new(@feedback)
emitter.send_form
else
render :new
respond_to do |format|
if @feedback.valid?
emitter = RedcapSurveyEmitter.new(@feedback)
emitter.send_form
format.js
else
format.json { render json: @feedback.errors, status: :unprocessable_entity }
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/views/feedback/create.js.coffee
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<% if @feedback.valid? %>
$('#modal_place').modal('hide')
<% end %>
2 changes: 1 addition & 1 deletion lib/redcap_survey_emitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def send_form
:letters => Digest::SHA1.hexdigest(Time.now.usec.to_s)[0..16],
:name => @feedback.name,
:email => @feedback.email,
:date => @feedback.date.to_datetime.strftime("%Y/%m/%d").gsub('/', '-'),
:date => Date.strptime(@feedback.date[0..9], '%m/%d/%Y').strftime("%Y/%m/%d").gsub('/', '-'),
:typeofrequest => @feedback.typeofrequest,
:priority => @feedback.priority,
:browser => @feedback.browser,
Expand Down

0 comments on commit 89ac31f

Please sign in to comment.