fixes #50 - summary page progress on saves
This commit is contained in:
parent
76bb21a150
commit
2c7948903d
@ -1,5 +1,5 @@
|
||||
function updateResults(elem) {
|
||||
if ($(elem).length ===0){return false;};
|
||||
if ($(elem).length ===0){return false;}
|
||||
|
||||
var resultsContainer = $(elem).find('[data-id="results"]')[0];
|
||||
var codeHtml = $(elem).find('.code-html')[0].value.trim();
|
||||
|
@ -32,11 +32,22 @@ function updateLocalValues($form){
|
||||
});
|
||||
}
|
||||
|
||||
function updateProgress(data) {
|
||||
$(".progress-bar").attr('aria-valuenow', data.progress)
|
||||
.attr('style','width: '+ data.progress +'%;')
|
||||
.find('span').text(data.progress + '%');
|
||||
if(data.can_submit === true){
|
||||
$('#summary-submit').find('.error').remove();
|
||||
$('#summary-submit').find('.submit-button').prop('disabled', false);
|
||||
}
|
||||
}
|
||||
|
||||
function prepareAjax($form) {
|
||||
$form.on("ajax:success", function(e, data){
|
||||
$form.prepend('<div class="success">' + data.message + '</div>');
|
||||
disableForm($form);
|
||||
updateLocalValues($form);
|
||||
updateProgress(data);
|
||||
}).on("ajax:error", function(e, xhr) {
|
||||
if (xhr.status === 400){
|
||||
$form.prepend('<div class="error">' + xhr.responseJSON.join('<br>') + '</div>');
|
||||
|
@ -29,6 +29,10 @@ label {
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
form.btn-center {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#{$all-text-inputs} {
|
||||
display: block;
|
||||
font-size: $base-font-size;
|
||||
|
@ -11,9 +11,10 @@ class QuizController < ApplicationController
|
||||
|
||||
def update_answer
|
||||
@answer = prep_answer answer_params[:question_id]
|
||||
prep_status
|
||||
send "process_#{prep_question(answer_params[:question_id]).input_type}"
|
||||
route_remote and return if request.xhr?
|
||||
route_answer
|
||||
route_answer_xhr and return if request.xhr?
|
||||
route_answer_html
|
||||
end
|
||||
|
||||
def summary
|
||||
@ -21,11 +22,10 @@ class QuizController < ApplicationController
|
||||
redirect_to :question and return unless prep_status.current_question_id.nil?
|
||||
end
|
||||
|
||||
def update_summary
|
||||
prep_status
|
||||
def submit_summary
|
||||
not_completed_error = 'You must complete all questions to submit your test.'
|
||||
record_error = 'There was a problem with your submission. Please try again later.'
|
||||
redirect_to :summary, flash: { error: not_completed_error } and return unless @status.can_submit
|
||||
redirect_to :summary, flash: { error: not_completed_error } and return unless prep_status.can_submit
|
||||
redirect_to :thankyou and return if current_candidate.complete!
|
||||
redirect_to :summary, flash: { error: record_error }
|
||||
end
|
||||
@ -62,9 +62,8 @@ class QuizController < ApplicationController
|
||||
answer
|
||||
end
|
||||
|
||||
def route_answer
|
||||
def route_answer_html
|
||||
if @answer.errors.present?
|
||||
prep_status
|
||||
prep_question answer_params[:question_id]
|
||||
flash[:error] = answer_params[:question_id].to_i
|
||||
render :question
|
||||
@ -75,11 +74,16 @@ class QuizController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def route_remote
|
||||
def route_answer_xhr
|
||||
if @answer.errors.present?
|
||||
render json: @answer.errors["answer"].to_json, status: 400
|
||||
else
|
||||
render json: { message: "Your answer has been updated successfully!" }.to_json
|
||||
results = {
|
||||
message: "Your answer has been updated successfully!",
|
||||
can_submit: prep_status.can_submit,
|
||||
progress: prep_status.progress
|
||||
}
|
||||
render json: results.to_json
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,11 +43,10 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @status.can_submit %>
|
||||
<%= form_tag post_summary_path, class: "btn-container-right" do %>
|
||||
<input type="submit" class="submit-button" value="Submit all answers" name="submit" />
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= form_tag post_summary_path, id: 'summary-submit', class: "btn-center" do %>
|
||||
<% unless @status.can_submit %>
|
||||
<div class="error">Sorry, you must answer all questions before you can submit.</div>
|
||||
<% end %>
|
||||
<%= submit_tag "Submit all answers", {class: 'submit-button', disabled: !@status.can_submit } %>
|
||||
<% end %>
|
||||
</main>
|
||||
|
@ -9,7 +9,7 @@ Rails.application.routes.draw do
|
||||
|
||||
post "/question(/:answer_id)", to: "quiz#update_answer", as: :post_answer
|
||||
get "/question(/:question_id)", to: "quiz#question", as: :question
|
||||
post "/summary", to: "quiz#update_summary", as: :post_summary
|
||||
post "/summary", to: "quiz#submit_summary", as: :post_summary
|
||||
get "/summary", to: "quiz#summary", as: :summary
|
||||
|
||||
get "/review/logout", to: "review#logout", as: :review_logout
|
||||
|
Loading…
Reference in New Issue
Block a user