completes #17 - live-coder plus text input type

Squashed commit of the following:

commit d41cbf66eb2a9ee705ab60bb156eed95881fa193
Author: Mark Moser <mark.moser@perficient.com>
Date:   Thu Aug 4 19:58:20 2016 -0500

    live-coder-text validations

commit 866bfeb863516a8656bc26b10f967d0b9b8d8505
Author: Mark Moser <mark.moser@perficient.com>
Date:   Thu Aug 4 11:57:57 2016 -0500

    getting things green again and rebasing develop

commit 28a23200f291e30c690b71e9bcae3e1a69eb3093
Author: Derek Montgomery <montgomerygraphics@gmail.com>
Date:   Thu Aug 4 10:14:23 2016 -0500

    Progress on live coder text field
This commit is contained in:
Mark Moser
2016-08-04 20:01:17 -05:00
parent 635297884d
commit fc784ffcb1
11 changed files with 136 additions and 23 deletions

View File

@ -93,7 +93,7 @@ function indentSelection(e){
}
function loadLiveCoders(){
$.each($('.answer-sec.live_code-type'), function(index, elem){
$.each($('.answer-sec.live_code-type, .answer-sec.live_code_text-type'), function(index, elem){
var qid = $(elem).data('qid');
$(elem).find("[data-id='live-coder-answer']").load("/live-coder-entry/" + qid, function(){
$(elem).find('.js-error').addClass('hidden');
@ -112,7 +112,7 @@ $(function(){
// wait a half second before updating results
// restart the timer if they resume typing
$('html').on('keyup', '.code-input textarea', function(){
var elem = $(this).closest('.answer-sec.live_code-type');
var elem = $(this).closest('.answer-sec.live_code-type, .answer-sec.live_code_text-type');
if (timer) { clearTimeout(timer); }
timer = setTimeout(updateResults(elem), 500);
});

View File

@ -173,7 +173,7 @@ $('.answer-sec')
.on('click', '.button-save', saveClickHandler);
// Dynamically load in coders
$.each($('.answer-sec.live-coder-type'), function(index, elem){
$.each($('.answer-sec.live_code-type, .answer-sec.live_code_text-type'), function(index, elem){
var qid = $(elem).data('qid');
$(elem).find("[data-id='live-coder-answer']").load("/live-coder-entry/" + qid, function(){
$(elem).find('.js-error').addClass('hidden');

View File

@ -42,7 +42,7 @@ class CandidateController < ApplicationController
prep_question params[:question_id]
prep_instance_answer @question
prep_answer params[:question_id]
render layout: false
render @question.input_type, layout: false
end
def summary
@ -95,8 +95,13 @@ class CandidateController < ApplicationController
def answer_params
params.require(:answer).permit(
:question_id, :answer_id,
:radio, :text, checkbox: [], live_code: [:later, :html, :css, :js]
:question_id,
:answer_id,
:radio,
:text,
checkbox: [],
live_code: [:later, :html, :css, :js],
live_code_text: [:later, :html, :css, :js, :text]
)
end
@ -148,4 +153,11 @@ class CandidateController < ApplicationController
submitted: params.key?(:submit))
route_answer
end
def process_live_code_text
@answer.update(answer: answer_params[:live_code_text].to_h,
saved: params.key?(:save),
submitted: params.key?(:submit))
route_answer
end
end

View File

@ -14,7 +14,7 @@ class AnswerFormatValidator < ActiveModel::EachValidator
end
if clean_val.length > 1000
record.errors[attribute] << (options[:message] || "The character limit for a textarea answer is 1000")
record.errors[attribute] << (options[:message] || "The character limit for this answer is 1000.")
end
end
@ -33,11 +33,40 @@ class AnswerFormatValidator < ActiveModel::EachValidator
def live_code record, attribute, value
return unless value.nil? || value.values.join.blank?
msg = if value.present? && value.keys.count == 1
"Please check that you will come back to complete the code example."
else
"You must write code in one of the above textareas to progress."
end
record.errors[attribute] << (options[:message] || msg)
record.errors[attribute] << (options[:message] || live_code_error_message(value))
end
def live_code_text record, attribute, value
return if value.present? && live_code_text_value_check(value)
record.errors[attribute] << (options[:message] || live_code_text_error_message(value))
end
#################################
def live_code_text_error_message value
return 'You must write code in one of the above textareas to progress.' if value.nil?
code_present = value.values_at(:html, :css, :js).join.present?
reason_present = value[:text].present?
later_present = value.keys.count == 1
return 'Please check that you will come back to complete the code example.' if later_present
return 'You must write code in one of the above textareas to progress.' unless code_present
return 'You must provide an answer in the reason field.' unless reason_present
end
def live_code_error_message value
if value.present? && value.keys.count == 1
return "Please check that you will come back to complete the code example."
end
"You must write code in one of the above textareas to progress."
end
def live_code_text_value_check value
later_present = value[:later].present? && value.keys.count == 1
code_present = value.values_at(:html, :css, :js).join.present?
reason_present = value[:text].present?
later_present || (code_present && reason_present)
end
end

View File

@ -0,0 +1 @@
<%= render partial: "candidate/live_code", locals: {question: question, form: form} %>

View File

@ -0,0 +1,21 @@
<% answer = @answer.answer || {} %>
<label for="answer_live_code_text">Reasoning</label>
<%= text_area_tag 'answer[live_code_text][text]', (answer['text']) %>
<div class="code-input">
<label for="answer_live_code_html">HTML</label>
<%= text_area_tag 'answer[live_code_text][html]', (answer['html']), { 'data-id' => 'code-html', class: 'code-answer code-html' } %>
</div>
<div class="code-input">
<label for="answer_live_code_css">CSS</label>
<%= text_area_tag 'answer[live_code_text][css]', (answer['css']), { 'data-id' => 'code-css', class: 'code-answer code-css' } %>
</div>
<div class="code-input">
<label for="answer_live_code_js">JS</label>
<%= text_area_tag 'answer[live_code_text][js]', (answer['js']), { 'data-id' => 'code-js', class: 'code-answer code-js' } %>
</div>
<div class="results" data-id="results"></div>