From 8640effbfc7c1a759ff59a4404f9a59f806b6b93 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Thu, 4 Aug 2016 22:28:20 -0500 Subject: [PATCH] fixes #40 - summary noJS messages --- app/assets/javascripts/summary-edit.js | 30 +++++++++++---------- app/views/candidate/_answer_errors.html.erb | 2 +- app/views/candidate/_live_code.html.erb | 24 ++++++++++------- app/views/candidate/summary.html.erb | 2 +- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/app/assets/javascripts/summary-edit.js b/app/assets/javascripts/summary-edit.js index a70fcb5..c25153b 100644 --- a/app/assets/javascripts/summary-edit.js +++ b/app/assets/javascripts/summary-edit.js @@ -7,11 +7,11 @@ return this.each(function(){ var lineHeight = parseInt($(this).css('line-height')); var rows = Math.ceil(input / lineHeight); - rows = rows == 0 ? 1 : rows; + rows = rows === 0 ? 1 : rows; $(this).attr('rows', rows); - }) - } + }); + }; $('input[type="radio"]').on('change', function() { var inputName = $(this).attr('name'); @@ -40,7 +40,7 @@ var editClickHandler = function(e) { } else if(thisEd.find('input').attr('type') == 'checkbox') { $(thisEd.find('input')).each(function() { - if($(this).prop('checked')==true) { + if($(this).prop('checked') === true) { existingValue.push($(this).val()); } }); @@ -91,7 +91,8 @@ var saveClickHandler = function(e) { var thisEd = $(e.delegateTarget); var data =[]; var executeQuery; - var questionId = thisEd.find('.button-edit').attr('data-questionid'); + var questionId = thisEd.find('.button-edit').attr('data-questionId'); + var answerId = thisEd.find('.button-edit').attr('data-answerId'); if (thisEd.hasClass('live_code-type')) { var htmlAnswer = $(thisEd.find('textarea.code-html')[0]).val(); @@ -103,27 +104,28 @@ var saveClickHandler = function(e) { 'css': cssAnswer, 'js': jsAnswer } - } + }; } else if(thisEd.hasClass('radio-type')) { $(thisEd.find('input')).each(function() { - if($(this).prop('checked')==true) { + if($(this).prop('checked') === true) { data = ({ 'radio': $(this).val() - }) + }); } }); } else if(thisEd.hasClass('checkbox-type')) { data = {'checkbox': []}; $(thisEd.find('input')).each(function() { - if($(this).prop('checked')==true) { + if($(this).prop('checked') === true) { data.checkbox.push($(this).val()); } }); } else { data = {'text': thisEd.find('textarea').val()}; } - if(data == '') { + + if(data === '') { $(thisEd).before('
Please select or enter a value.
'); } else { thisEd.find('textarea:not(.code-answer)').replaceWith('

' + $.trim(thisEd.find('textarea').val()) + '

'); @@ -133,7 +135,7 @@ var saveClickHandler = function(e) { type: "POST", url: url, data: ({ - 'answer': data, + 'answer': $.extend(data, {'question_id': questionId, 'answer_id': answerId}), 'submit': true }), success: function(data){ @@ -143,12 +145,12 @@ var saveClickHandler = function(e) { executeQuery = false; } }).done(function() { - if(executeQuery == true) { + if(executeQuery === true) { $('.success, .error').remove(); $(thisEd).before('
Your answer has been updated successfully!
'); $(thisEd).find('.code-answer').attr('disabled', true); } - if(executeQuery == false) { + if(executeQuery === false) { $('.error, .success').remove(); $(thisEd).before('
Oops! There was an error processing your request. Please try again.
'); } @@ -167,7 +169,7 @@ $('.answer-block').prop('disabled', true); // Question events $('.answer-sec') .find('.button-cancel, .button-save').hide().end() -// // delegating events + // delegating events .on('click', '.button-edit', editClickHandler) .on('click', '.button-cancel', cancelClickHandler) .on('click', '.button-save', saveClickHandler); diff --git a/app/views/candidate/_answer_errors.html.erb b/app/views/candidate/_answer_errors.html.erb index b69a5f1..fe8d226 100644 --- a/app/views/candidate/_answer_errors.html.erb +++ b/app/views/candidate/_answer_errors.html.erb @@ -1,4 +1,4 @@ -<% if flash[:answer_error] == question.question_id %> +<% if flash[:answer_error] == question.question_id && answer.present? %> <% answer.errors.messages[:answer].each do |message| %>
<%= message %>
<% end %> diff --git a/app/views/candidate/_live_code.html.erb b/app/views/candidate/_live_code.html.erb index 1967e3c..08a51ae 100644 --- a/app/views/candidate/_live_code.html.erb +++ b/app/views/candidate/_live_code.html.erb @@ -11,18 +11,22 @@ Please revisit this page with JavaScript enabled to modify your answer. --> -<% unless params[:action] == 'summary' %> -
-

- This is a question where you will be asked to write code, and it utilizes a JavaScript-enabled - environment. It looks like JavaScript is not loaded. Please check the box below - to acknowledge that you agree to come back at a later time to finish answering this question - before you can submit the test. -

+
+

+ This is a question where you will be asked to write code, and it utilizes a JavaScript-enabled + environment. It looks like JavaScript is not loaded. + <% unless params[:action] == 'summary' %> + Please check the box below to acknowledge that you agree to come back at a later time to finish + answering this question before you can submit the test. + <% else %> + You will need to enable JavaScript and answer this question before you can submit the test. + <% end %> +

+ <% unless params[:action] == 'summary' %> <%= form.check_box(:answer, checkbox_html, true, '') %> <%= form.label(option_id, 'I will come back later to finish this code question') %> -
-<% end %> + <% end %> +
<% # answers inserted dynamically via jQuery .load() diff --git a/app/views/candidate/summary.html.erb b/app/views/candidate/summary.html.erb index 4a1d54c..46558b8 100644 --- a/app/views/candidate/summary.html.erb +++ b/app/views/candidate/summary.html.erb @@ -15,7 +15,7 @@

<%= question.question %>

- Edit + Edit